Reading a .sql file for sqlite database

Hi

I am developing an andriod app and I have my data in .sql file downloaded via phpmyadmin.

Now there are some format difference in sql and sqlite3 commands. so I have performed the following steps to read the file in the format that is understandable by sqlite3 database

however make sure when you download the sql file from phpmyadmin, it should be MAXDB sql compatiblity mode. I have tested this, however it should also work on ANSI and DB2 compatiblity mode, but I have not used that
Also the settings shown in the image should be there when downloading the sql file

 

Here is the code which I used to read the sql file and populate it in sqlite3 database

private void fillData() {
DbHelper dh = new DbHelper(this);
SQLiteDatabase d = dh.getWritableDatabase();
String line;
String incompleteLine="";

try {
InputStream in = this.getAssets().open(“data.sql”);
if (in != null) {
// prepare the file for reading
InputStreamReader input = new InputStreamReader(in);
BufferedReader buffreader = new BufferedReader(input);

while ((line = buffreader.readLine()) != null) {
// Toast.makeText(this, line,Toast.LENGTH_LONG).show();
// d.execSQL(“INSERT INTO brand (_id,name,info) VALUES (‘2′,’AMICA’,’amica’);”);
// Print the content on the console
if (line.indexOf(“-“)==0 || line.indexOf(“/”)==0 || line.indexOf(“SET”)==0)
{
continue;
}

if (line.contains(“;”))
{
incompleteLine=incompleteLine+line;
System.out.println (incompleteLine);
d.execSQL(incompleteLine);
incompleteLine=””;

}
else
{
incompleteLine=incompleteLine+line;
}

}
in.close();
// Toast.makeText(this, res, Toast.LENGTH_LONG).show();
} else {
}
} catch (Exception e) {
Toast.makeText(this, e.toString() + e.getMessage(), 50000000).show();
}

d.close();

Intent selectBrandIntent = new Intent(this, SelectBrand.class);
startActivity(selectBrandIntent);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s