static public void createDbFromSqlStatements ( Context context , String dbName , int dbVersion , String sqlStatements ) { File f = context . getDatabasePath ( dbName ) ; f . getParentFile ( ) . mkdirs ( ) ; SQLiteDatabase db = SQLiteDatabase . openOrCreateDatabase ( f , null ) ; // TODO: this is not quite safe since it assumes that all semicolons at the end of a line // terminate statements. It is possible that a text field contains ;\n. We will have to fix // this if that turns out to be a problem. String [ ] statements = TextUtils . split ( sqlStatements , ";\n" ) ; for ( String statement : statements ) { if ( TextUtils . isEmpty ( statement ) ) continue ; db . execSQL ( statement ) ; } db . setVersion ( dbVersion ) ; db . close ( ) ; }
Creates a db and populates it with the sql statements in sqlStatements .