I'm developing an android application that store sql files to update the sqlite database. And that sql script will run when user push certain button. This is where i put my sql files
So far i've been using this solution to run my script:
First, mapping my update to resource as update.xml
<resources>
<string name="update_list">
v2_9_11
</string>
<string-array name="v2_9_11">
<item>1_AlterTable_wapactivity</item>
</string-array>
</resources>
And get the sql script inside the file with this method :
private void runScript(String version_name){
try{
String[] sql_list = mGap.getResources().getStringArray(getArrayIdentifier(mGap, version_name));
for (String sql : sql_list) {
InputStream in = getClass().getResourceAsStream("/com/ods/scm/script/update/"+version_name+"/"+sql+".sql");
Reader fr = new InputStreamReader(in, "utf-8");
BufferedReader br = new BufferedReader(fr);
String s="";
String baris;
while((baris=br.readLine())!=null){
s+=baris;
}
mDbHelper.executeStatement(s);
}
insertUpdate(version_name);
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
I get the String version_name and String[ ] sql_list file name from update.xml.
The problem is, i want to get version_name ( in this case v2_9_11 as subfolder name from folder update ) and sql file name ( in this case 1_AlterTable_wapactivity.sql ) without mapping it in update.xml. Can ayone help me?
EDIT
Or can anyone direct me how to automatically mapping it to update.xml when build the application?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…