de.greenrobot.dao
Class DbUtils

java.lang.Object
  extended by de.greenrobot.dao.DbUtils

public class DbUtils
extends java.lang.Object

    

Database utils, for example to execute SQL scripts


Constructor Summary
DbUtils()
           
 
Method Summary
static int copyAllBytes(java.io.InputStream in, java.io.OutputStream out)
          Copies all available data from in to out without closing any stream.
static int executeSqlScript(Context context, SQLiteDatabase db, java.lang.String assetFilename)
          Calls executeSqlScript(Context, SQLiteDatabase, String, boolean) with transactional set to true.
static int executeSqlScript(Context context, SQLiteDatabase db, java.lang.String assetFilename, boolean transactional)
          Executes the given SQL asset in the given database (SQL file should be UTF-8).
static int executeSqlStatements(SQLiteDatabase db, java.lang.String[] statements)
           
static int executeSqlStatementsInTx(SQLiteDatabase db, java.lang.String[] statements)
           
static byte[] readAllBytes(java.io.InputStream in)
           
static byte[] readAsset(Context context, java.lang.String filename)
           
static void vacuum(SQLiteDatabase db)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbUtils

public DbUtils()
Method Detail

vacuum

public static void vacuum(SQLiteDatabase db)

executeSqlScript

public static int executeSqlScript(Context context,
                                   SQLiteDatabase db,
                                   java.lang.String assetFilename)
                            throws java.io.IOException
Calls executeSqlScript(Context, SQLiteDatabase, String, boolean) with transactional set to true.

Returns:
number of statements executed.
Throws:
java.io.IOException

executeSqlScript

public static int executeSqlScript(Context context,
                                   SQLiteDatabase db,
                                   java.lang.String assetFilename,
                                   boolean transactional)
                            throws java.io.IOException
Executes the given SQL asset in the given database (SQL file should be UTF-8). The database file may contain multiple SQL statements. Statements are split using a simple regular expression (something like "semicolon before a line break"), not by analyzing the SQL syntax. This will work for many SQL files, but check yours.

Returns:
number of statements executed.
Throws:
java.io.IOException

executeSqlStatementsInTx

public static int executeSqlStatementsInTx(SQLiteDatabase db,
                                           java.lang.String[] statements)

executeSqlStatements

public static int executeSqlStatements(SQLiteDatabase db,
                                       java.lang.String[] statements)

copyAllBytes

public static int copyAllBytes(java.io.InputStream in,
                               java.io.OutputStream out)
                        throws java.io.IOException
Copies all available data from in to out without closing any stream.

Returns:
number of bytes copied
Throws:
java.io.IOException

readAllBytes

public static byte[] readAllBytes(java.io.InputStream in)
                           throws java.io.IOException
Throws:
java.io.IOException

readAsset

public static byte[] readAsset(Context context,
                               java.lang.String filename)
                        throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2011-2012 greenrobot.de. All Rights Reserved.