Android SQLite database save
So I have an issue because of two databases:
The first database is just a bunch of values being read in, so that's not the problem. I can pull values from the database and then make it appear on the android device as intended. The problem that I run into is that when I try to save the results to a secondary table, every time I run the program, it re-creates the table EVEN if it exists.
It saves it correctly and the single result will pull through when I go to the saved results screen but if I go back to save another row to this Results table, it re-creates the table and adds that to the first row. Any idea how to fix or circumvent this problem?
My Code:
MyDataBaseHelper dbCon = new MyDataBaseHelper(this);
dbCon.open();
dbCon.pushToDatabase(uniqueName, date, time, wingType, nozzle, orifice, angle, speed, pressure, dv1, dv5, dv9, sprayVolume1, sprayVolume2, droplet, tableExist);
dbCon.close();
MyDataBaseHelper
public void pushToDatabase(String uniqueName, String date, String time, String wingType, String nozzle, String orifice, String angle, String speed, String pressure,
String dv1, String dv5, String dv9, String sprayVolume1, String sprayVolume2, String droplet, String tableExist)
{
final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS Results("
+ "uniqueName TEXT,"
+ "date TEXT,"
+ "time TEXT,"
+ "wingType TEXT,"
+ "nozzle TEXT,"
+ "orifice TEXT,"
+ "angle TEXT,"
+ "pressure TEXT,"
+ "speed TEXT,"
+ "dv1 TEXT,"
+ "dv5 TEXT,"
开发者_Go百科 + "dv9 TEXT,"
+ "sprayvolume1 TEXT,"
+ "sprayvolume2 TEXT,"
+ "droplet TEXT);";
myDB.execSQL(CREATE_TABLE);
ContentValues values = new ContentValues();
values.put("uniqueName", uniqueName);
values.put("date", date);
values.put("time", time);
values.put("wingType", wingType);
values.put("nozzle", nozzle);
values.put("orifice", orifice);
values.put("angle", angle);
values.put("pressure", pressure);
values.put("speed", speed);
values.put("dv1", dv1);
values.put("dv5", dv5);
values.put("dv9", dv9);
values.put("sprayvolume1", sprayVolume1);
values.put("sprayvolume2", sprayVolume2);
values.put("droplet", droplet);
myDB.insert("Results", null, values);
myDB.close();
//Cursor mCursor;
//mCursor = myDB.rawQuery(data, null);
//mCursor.moveToFirst();*/
}
I did not compile anything, but what is clearly visible, is that you dont have a Primary Key
set on any of the table fields
final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS Results("
+ "uniqueName TEXT,"
+ "date TEXT,"
+ "time TEXT,"
+ "wingType TEXT,"
+ "nozzle TEXT,"
+ "orifice TEXT,"
+ "angle TEXT,"
+ "pressure TEXT,"
+ "speed TEXT,"
+ "dv1 TEXT,"
+ "dv5 TEXT,"
+ "dv9 TEXT,"
+ "sprayvolume1 TEXT,"
+ "sprayvolume2 TEXT,"
+ "droplet TEXT, PRIMARY KEY(uniqueName));";
精彩评论