android - Best Practice: Defining a large database using SQLiteOpenHelper? -


i have class extends sqliteopenhelper, in have defined database tables , columns created. these strings 1 shown below:

public string as_column_a_btn5 = "a_btn5"; 

i have defined string each create table statement. these tables created in oncreate() method.

the problem have on 50 columns, file getting long , unmanageable.

what best practice defining large number of columns?

  1. write create-database.sql script in file , save /assets folder.
  2. use following in sqliteopenhelper:

oncreate

@override public void oncreate( sqlitedatabase db ) {     inputstream in_stream = null;     try {         in_stream = mcontext.getresources().getassets().open( create_script );         string[] statements = parsesqlfile( in_stream );         ( string statement : statements ) {             db.execsql( statement );         }     } catch ( ioexception e ) {         e.printstacktrace();     } {         try {             if ( in_stream != null ) {                 in_stream.close();             }         } catch ( exception e ) {         }     } } 

on line 8 find method called parsesqlfile(). method takes sql script , splits sql statements. can download here (i used blog read long ago. unfortunately, don't remember more).

this way can make use of editor's syntax highlighting spot typos in sql script.

let me know if had problem.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -