Created
December 9, 2011 22:16
-
-
Save onlyangel/1453556 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.onlyangel.sclbits.rosh.database; | |
import java.io.BufferedReader; | |
import java.io.DataInputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import android.content.Context; | |
import android.database.sqlite.SQLiteDatabase; | |
import android.database.sqlite.SQLiteOpenHelper; | |
import android.util.Log; | |
import com.onlyangel.sclbits.rosh.tools.Generales; | |
public class RoshDatabaseHelper extends SQLiteOpenHelper { | |
private static final String DATABASE_NAME = "rosh"; | |
private static final int DATABASE_VERSION = 1; | |
public RoshDatabaseHelper(Context context) { | |
super(context, DATABASE_NAME, null, DATABASE_VERSION); | |
} | |
@Override | |
public void onCreate(SQLiteDatabase db) { | |
String createDatabase = getDatabaseQueryAtPath(DATABASE_VERSION+"/rosh.sql"); | |
String strings[] =createDatabase.split(";"); | |
for (int n=0;n<strings.length;n++){ | |
db.execSQL(strings[n]); | |
} | |
} | |
@Override | |
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | |
Log.w(RoshDatabaseHelper.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); | |
//db.execSQL("DROP TABLE IF EXISTS todo"); | |
//onCreate(db); | |
} | |
public String getDatabaseQueryAtPath (String path){ | |
InputStream fstream; | |
StringBuffer str = new StringBuffer(); | |
try { | |
fstream = Generales.CONTEXT.getAssets().open("database/"+path); | |
DataInputStream in = new DataInputStream(fstream); | |
BufferedReader br = new BufferedReader(new InputStreamReader(in)); | |
String strLine; | |
//Read File Line By Line | |
while ((strLine = br.readLine()) != null) { | |
// Print the content on the console | |
System.out.println (strLine); | |
str.append(strLine); | |
} | |
//Close the input stream | |
in.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return str.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment