我正在尝试将数据插入数据库,它在模拟器中工作,但是当我尝试在设备上工作时,它没有插入数据。
数据库助手类
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
public class DataBaseHelper {
SQLiteDatabase dbe;
public DataBaseHelper(Context mycontext, String getPackageName) {
copyDB(mycontext, getPackageName);// This method helps to copy the database from asserts to mobile
}
void copyDB(Context mycontext, String getPackageName) {
try {
String destPath = "data/data/" + getPackageName + "/databases";//this is the path for the database to save
Log.v("opendb", "destPath: " + destPath);
File f3 = new File(destPath);// initiating new file in destination path
if (!f3.exists()) { // this loop helps to create file if the file if does't not exist
Boolean flag = f3.mkdir();
Log.v("opendb", "mkdir flag: " + flag);
destPath = destPath + "/AuditDb.sqlite";//It gives the destination path to copy the sqlite file from assert
File f2 = new File(destPath);
if (!f2.exists()) {
Log.v("opendb", "File Not Exist");
flag = f2.createNewFile();
Log.v("opendb", "create file flag: " + flag);
}
AssetManager assetManager = mycontext.getAssets();// getting the path of actual saved in asserts
String[] files = null;
files = assetManager.list("");// listing all files in assert
for (String filename : files) {// choosing the database file among other files
Log.i("opendb", filename);
InputStream in = null; // to take stream of values from Source file
OutputStream out = null; // to write the value from source to destination file
if (filename.equals("HealthDb.sqlite")) {
in = assetManager.open(filename);
Log.i("opendb", filename + " opened Successfully");
out = new FileOutputStream(destPath);
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
in.close();// terminating inputstream
out.close();// terminating outputstream
}
}
}
} catch (FileNotFoundException e) {
Log.v("opendb", "FileNotFoundexeption: " + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
Log.v("opendb", "ioexeption: " + e.getMessage());
e.printStackTrace();
}
Log.v("opendb", "Success!!!!!!!!!!!!!!!!");
}
public SQLiteDatabase checkDB() { // this method helps to check whether the data base is exist or not
try {
dbe = SQLiteDatabase.openDatabase(
"data/data/com.healthmonitor/databases/AuditDb.sqlite",
null, 0);
Log.d("opendb", "EXIST");
} catch (Exception e) {
Log.d("opendb", e.getMessage());
}
return dbe;
}
public SQLiteDatabase createOrOpenDB(String dbName) { // this method helps to check whether the data base is exist or not
try {
System.out.println("comming4");
if(!dbName.equals("")){
dbe = SQLiteDatabase.openDatabase(
"data/data/com.healthmonitor/databases/"+dbName+".sqlite",
null,0);// it opens the exist database
System.out.println("comming5");
}
} catch (Exception e) {
System.out.println("comming44");
Log.d("opendb", e.getMessage());
dbe = SQLiteDatabase.openOrCreateDatabase(
"data/data/com.healthmonitor/databases/"+dbName+".sqlite",
null);// it creates the database if it does not exists
}
return dbe;
}
}
数据库适配器类
public class DbAdapter {
public static final String KEY_ID = "_id";
public static final String KEY_COMP_ID = "compID";
public static final String KEY_DBASE = "dbase";
public static final String KEY_DTABLE = "dtable";
public static final String KEY_DTFITELD = "dtfield";
public static final String KEY_ACTION = "action";
public static final String KEY_ORIGINATION = "origination";
public static final String KEY_TERMINATION = "termination";
public static final String KEY_INDEX = "fieldIndex";
private static final String TAG = "DbAdapter";
private DatabaseHelper mDbHelper;
private static SQLiteDatabase mDb;
private static final String DATABASE_NAME = "HealthDb.sqlite";
private static final String FTS_AUDIT_TABLE = "audit_table";
private static final int DATABASE_VERSION = 2;// Version of sqlite database
private static Context mCtx;
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
mDb = cb.checkDB();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
}
}
public DbAdapter(Context ctx) {
this.mCtx = ctx;
}
public DbAdapter open() throws SQLException {
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
mDb = cb.checkDB();
return this;
}
public DbAdapter createOrOpenDb(String dbName) throws SQLException {
//system.out.println("comming3");
if (!dbName.equals("")) {
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
mDb = cb.createOrOpenDB(dbName);
//system.out.println("comming4");
return this;
}
return null;
}
public void close() {
mDb.close();
}
public void DatabaseAdd(String databaseName) {
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss")
.format(Calendar.getInstance().getTime());
//system.out.println("data is " + timeStamp);
createOrOpenDb(databaseName);// creates the database with the specified
// name
open();
ContentValues initialValues = new ContentValues();// Initializes the
// content value
initialValues.put(KEY_DBASE, databaseName);
initialValues.put(KEY_ACTION, "Database created");
initialValues.put(KEY_ORIGINATION, timeStamp);
long done = mDb.insert(FTS_AUDIT_TABLE, null, initialValues);
//system.out.println("done " + done);
String query = "UPDATE " + FTS_AUDIT_TABLE + " SET " + KEY_COMP_ID
+ "=(SELECT " + KEY_ID + " FROM " + FTS_AUDIT_TABLE + " WHERE "
+ KEY_ORIGINATION + " =" + timeStamp + ") WHERE "
+ KEY_ORIGINATION + " =" + timeStamp;
mDb.execSQL(query);
close();
}
public boolean DatabaseDelete(String databaseName) {
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss")
.format(Calendar.getInstance().getTime());
//system.out.println("time stamp in delete " + timeStamp);
File file = new File("data/data/com.healthmonitor/databases/"
+ databaseName + ".sqlite");// selects the db file from the
// system
new File("data/data/com.healthmonitor/databases/" + databaseName
+ "-journal").delete();
if (file.delete()) {
open();
String query2 = "UPDATE " + FTS_AUDIT_TABLE + " SET "
+ KEY_TERMINATION + "='" + timeStamp + "' WHERE "
+ KEY_DBASE + " = '" + databaseName + "' and "
+ KEY_TERMINATION + " is null;";
mDb.execSQL(query2);
close();
return true;
}
return false;
}
public boolean DatabaseExistOrNot(String databaseName) {
File file = new File("data/data/com.healthmonitor/databases/"
+ databaseName + ".sqlite");
return file.exists();
}
public boolean DatabaseEdit(String oldDatabaseName, String newDatabseNAme) {
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss")
.format(Calendar.getInstance().getTime());
File filefrom = new File("data/data/com.healthmonitor/databases/"
+ oldDatabaseName + ".sqlite");
File fileto = new File("data/data/com.healthmonitor/databases/"
+ newDatabseNAme + ".sqlite");
if (filefrom.renameTo(fileto)) {
open();
String query3 = "Select " + KEY_COMP_ID + "," + KEY_DTFITELD + ","
+ KEY_INDEX + "," + KEY_TERMINATION + "," + KEY_DTABLE
+ " from " + FTS_AUDIT_TABLE + " where " + KEY_DBASE
+ "= '" + oldDatabaseName + "' and " + KEY_TERMINATION
+ " is null";
Cursor cursor1 = mDb.rawQuery(query3, null);
ContentValues initialValues = new ContentValues();
if (cursor1 != null) {
cursor1.moveToFirst();
do {
initialValues.put(KEY_COMP_ID, cursor1.getString(0));
initialValues.put(KEY_DBASE, newDatabseNAme);
initialValues.put(KEY_DTABLE, cursor1.getString(4));
initialValues.put(KEY_DTFITELD, cursor1.getString(1));
initialValues.put(KEY_INDEX, cursor1.getString(2));
initialValues.put(KEY_ACTION, "Database is renamed from"
+ oldDatabaseName);
initialValues.put(KEY_ORIGINATION, timeStamp);
initialValues.put(KEY_TERMINATION, cursor1.getString(3));
long done1 = mDb.insert(FTS_AUDIT_TABLE, null,
initialValues);
} while (cursor1.moveToNext());
}
String query4 = "UPDATE " + FTS_AUDIT_TABLE + " SET "
+ KEY_TERMINATION + "='" + timeStamp + "' WHERE "
+ KEY_DBASE + " = '" + oldDatabaseName + "'";
mDb.execSQL(query4);
close();
return true;
}
return false;
}
public void TableAdd(String selectedDb, String Tablename) {
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
mDb = cb.createOrOpenDB(selectedDb);
String query = "CREATE TABLE IF NOT EXISTS '" + Tablename
+ "' (_Id INTEGER PRIMARY KEY AUTOINCREMENT)";
mDb.execSQL(query);
mDb.close();
open();
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss")
.format(Calendar.getInstance().getTime());
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_DBASE, selectedDb);
initialValues.put(KEY_DTABLE, Tablename);
initialValues.put(KEY_ACTION, "Table Created");
initialValues.put(KEY_ORIGINATION, timeStamp);
long done = mDb.insert(FTS_AUDIT_TABLE, null, initialValues);
String query1 = "UPDATE " + FTS_AUDIT_TABLE + " SET " + KEY_COMP_ID
+ "=(SELECT " + KEY_ID + " FROM " + FTS_AUDIT_TABLE + " WHERE "
+ KEY_ORIGINATION + " =" + timeStamp + ") WHERE "
+ KEY_ORIGINATION + " =" + timeStamp;
mDb.execSQL(query1);
AddField(selectedDb, Tablename, "_Id", "Text", "NO");
AddField(selectedDb, Tablename, "Orgination", "Text", "NO");
AddField(selectedDb, Tablename, "Termination", "Text", "NO");
close();
}
public Cursor TableNames(String selectedDb) {
if (!selectedDb.equals("")) {
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
mDb = cb.createOrOpenDB(selectedDb);
String query = "SELECT * FROM sqlite_master WHERE type='table'";
Cursor cursor = mDb.rawQuery(query, null);
if (cursor != null) {
cursor.moveToFirst();
}
mDb.close();
return cursor;
}
return null;
}
public boolean TableDelete(String selectedDb, String selectedTable) {
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss")
.format(Calendar.getInstance().getTime());
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
mDb = cb.createOrOpenDB(selectedDb);
String query = "Drop table '" + selectedTable + "'";
mDb.execSQL(query);
mDb.close();
open();
String query2 = "UPDATE " + FTS_AUDIT_TABLE + " SET " + KEY_TERMINATION
+ "='" + timeStamp + "' WHERE " + KEY_DBASE + " = '"
+ selectedDb + "' and " + KEY_DTABLE + " ='" + selectedTable
+ "' and " + KEY_TERMINATION + " is null";
mDb.execSQL(query2);
close();
return true;
}
public void TableEdit(String selectedDb, String selectedTable,
String newTableName) {
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
mDb = cb.createOrOpenDB(selectedDb);
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss")
.format(Calendar.getInstance().getTime());
try {
String query = "ALTER TABLE '" + selectedTable + "' RENAME TO '"
+ newTableName + "'";
mDb.execSQL(query);
mDb.close();
open();
String query3 = "Select " + KEY_COMP_ID + "," + KEY_DTFITELD + ","
+ KEY_INDEX + "," + KEY_TERMINATION + " from "
+ FTS_AUDIT_TABLE + " where " + KEY_DBASE + "= '"
+ selectedDb + "' and " + KEY_DTABLE + "='" + selectedTable
+ "' and " + KEY_TERMINATION + " is null";
Cursor cursor1 = mDb.rawQuery(query3, null);
ContentValues initialValues = new ContentValues();// Initializes
if (cursor1 != null) {
cursor1.moveToFirst();
do {
initialValues.put(KEY_COMP_ID, cursor1.getString(0));
initialValues.put(KEY_DBASE, selectedDb);
initialValues.put(KEY_DTABLE, newTableName);
initialValues.put(KEY_DTFITELD, cursor1.getString(1));
initialValues.put(KEY_INDEX, cursor1.getString(2));
initialValues.put(KEY_ACTION, "Table is renamed from"
+ selectedTable);
initialValues.put(KEY_ORIGINATION, timeStamp);
initialValues.put(KEY_TERMINATION, cursor1.getString(3));
long done1 = mDb.insert(FTS_AUDIT_TABLE, null,
initialValues);
//system.out.println("done " + done1);
} while (cursor1.moveToNext());
}
String query4 = "UPDATE " + FTS_AUDIT_TABLE + " SET "
+ KEY_TERMINATION + "='" + timeStamp + "' WHERE "
+ KEY_DBASE + " = '" + selectedDb + "' and " + KEY_DTABLE
+ " ='" + selectedTable + "' and " + KEY_TERMINATION
+ " is null";
//system.out.println("query4" + query4);
mDb.execSQL(query4);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
close();
}
public Cursor TableView(String selectedDb, String selectedTable, int check) {
Cursor cursor;
if (!selectedTable.equals(FTS_AUDIT_TABLE)) {
open();
String query1 = "select " + KEY_DTFITELD + " from "
+ FTS_AUDIT_TABLE + " where " + KEY_DBASE + " = '"
+ selectedDb + "' and " + KEY_DTABLE + " = '"
+ selectedTable + "' and " + KEY_TERMINATION + " is null;";
//system.out.println(query1);
Cursor cursor1 = mDb.rawQuery(query1, null);
String deletedField = "";
try {
if (cursor1 != null) {
cursor1.moveToFirst();
do {
if (cursor1.getString(cursor1
.getColumnIndex(DbAdapter.KEY_DTFITELD)) != null) {
deletedField = deletedField
+ cursor1
.getString(cursor1
.getColumnIndex(DbAdapter.KEY_DTFITELD))
+ ",";
}
} while (cursor1.moveToNext());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//system.out.println("not removed fields" + deletedField);
close();
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
mDb = cb.createOrOpenDB(selectedDb);
String query;
if (check == 0) {
query = "SELECT "
+ deletedField.substring(0, deletedField.length() - 1)
+ " FROM '" + selectedTable
+ "' where Termination is null";
} else {
query = "SELECT "
+ deletedField.substring(0, deletedField.length() - 1)
+ " FROM '" + selectedTable + "'";
}
cursor = mDb.rawQuery(query, null);
if (cursor != null) {
cursor.moveToFirst();
}
mDb.close();
return cursor;
}
else {
if (check == 0) {
DataBaseHelper cb = new DataBaseHelper(mCtx,
mCtx.getPackageName());
mDb = cb.createOrOpenDB(selectedDb);
String query = "SELECT * FROM '" + selectedTable + "' where "
+ KEY_TERMINATION + " is null";
cursor = mDb.rawQuery(query, null);
if (cursor != null) {
cursor.moveToFirst();
}
mDb.close();
return cursor;
} else {
DataBaseHelper cb = new DataBaseHelper(mCtx,
mCtx.getPackageName());
mDb = cb.createOrOpenDB(selectedDb);
String query = "SELECT * FROM '" + selectedTable + "'";
cursor = mDb.rawQuery(query, null);
if (cursor != null) {
cursor.moveToFirst();
}
mDb.close();
return cursor;
}
}
}
public void DeleteRow(String selectedDb, String selectedTable, String rowid) {
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
mDb = cb.createOrOpenDB(selectedDb);
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss")
.format(Calendar.getInstance().getTime());
String query2 = "UPDATE " + selectedTable + " SET " + "Termination = '"
+ timeStamp + "' where _Id =" + Integer.parseInt(rowid);
mDb.execSQL(query2);
mDb.close();
}
public boolean AddRow(String selectedDb, String selectedTable,
String[] fieldvalue, Cursor cursor) {
// TODO Auto-generated method stub
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
mDb = cb.createOrOpenDB(selectedDb);
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss")
.format(Calendar.getInstance().getTime());
String columnname="Orgination";
String values="'"+timeStamp+"'";
for (int i = 3; i < cursor.getColumnCount(); i++) {
fieldvalue[i]);
columnname=columnname+","+cursor.getColumnName(i);
values=values+",'"+fieldvalue[i]+"'";
}
String query="INSERT INTO "+selectedTable+" ("+columnname+") VALUES ("+values+")";
try {
mDb.execSQL(query);
mDb.close();
return true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
mDb.close();
return false;
}
}
public boolean EditRow(String selectedDb, String selectedTable,
String[] fieldvalue, Cursor cursor, String selectedRowId) {
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
mDb = cb.createOrOpenDB(selectedDb);
ContentValues initialValues = new ContentValues();
for (int i = 3; i < cursor.getColumnCount(); i++) {
initialValues.put(cursor.getColumnName(i), fieldvalue[i]);
}
long done = mDb.update(selectedTable, initialValues,
cursor.getColumnName(0) + "=" + selectedRowId, null);
mDb.close();
if (done != -1)
return true;
return false;
}
public Cursor TableValues(String selectedDb, String selectedTable) {
// TODO Auto-generated method stub
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
mDb = cb.createOrOpenDB(selectedDb);
String query = "PRAGMA table_info ('" + selectedTable + "')";
Cursor cursor = mDb.rawQuery(query, null);
if (cursor != null) {
cursor.moveToFirst();
}
mDb.close();
return cursor;
}
public boolean AddField(String selectedDb, String selectedTable,
String fieldName, String fieldType, String index) {
try {
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
if (!fieldName.equals("_Id")) {
mDb = cb.createOrOpenDB(selectedDb);
String query = "ALTER TABLE '" + selectedTable
+ "' ADD COLUMN '" + fieldName + "' '" + fieldType
+ "';";
mDb.execSQL(query);
mDb.close();
}
open();
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss")
.format(Calendar.getInstance().getTime());
//system.out.println("data is " + timeStamp);
ContentValues initialValues = new ContentValues();// Initializes
initialValues.put(KEY_DBASE, selectedDb);
initialValues.put(KEY_DTABLE, selectedTable);
initialValues.put(KEY_DTFITELD, fieldName);
initialValues.put(KEY_ACTION, "field is created ");
initialValues.put(KEY_ORIGINATION, timeStamp);
initialValues.put(KEY_INDEX, index);
long done = mDb.insert(FTS_AUDIT_TABLE, null, initialValues);
//system.out.println("done " + done);
String query2 = "UPDATE " + FTS_AUDIT_TABLE + " SET " + KEY_COMP_ID
+ "=(SELECT " + KEY_ID + " FROM " + FTS_AUDIT_TABLE
+ " WHERE " + KEY_ORIGINATION + " ='" + timeStamp
+ "' ORDER BY " + KEY_ID + " DESC) WHERE "
+ KEY_ORIGINATION + " ='" + timeStamp + "' and "
+ KEY_DTFITELD + "='" + fieldName + "' ;";
mDb.execSQL(query2);
close();
return true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
public Cursor IndexValues(String selectedDb, String selectedTable) {
// TODO Auto-generated method stub
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
try {
open();
String query = "select " + KEY_DTFITELD + "," + KEY_INDEX
+ " from " + FTS_AUDIT_TABLE + " where " + KEY_DBASE + "='"
+ selectedDb + "' and " + KEY_DTABLE + " ='"
+ selectedTable + "' and " + KEY_DTFITELD
+ " not NULL and " + KEY_TERMINATION + " is null";
//system.out.println(query);
Cursor cursor = mDb.rawQuery(query, null);
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
close();
return null;
}
public boolean DeleteField(String selectedDb, String selectedTable,
String fieldName) {
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss")
.format(Calendar.getInstance().getTime());
//system.out.println("data is " + timeStamp);
open();
try {
String query1 = "UPDATE " + FTS_AUDIT_TABLE + " SET "
+ KEY_TERMINATION + "='" + timeStamp + "' where "
+ KEY_DBASE + "='" + selectedDb + "' and " + KEY_DTABLE
+ "='" + selectedTable + "' and " + KEY_DTFITELD + "='"
+ fieldName + "' and " + KEY_TERMINATION + " is null;";
//system.out.println(query1);
mDb.execSQL(query1);
mDb.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
close();
return true;
}
public String GetDeleteField(String selectedDb, String selectedTable) {
open();
String query1 = "select " + KEY_DTFITELD + " from " + FTS_AUDIT_TABLE
+ " where " + KEY_DBASE + " = '" + selectedDb + "' and "
+ KEY_DTABLE + " = '" + selectedTable + "' and "
+ KEY_TERMINATION + " not null and " + KEY_ID + ">= (Select "
+ KEY_ID + " from " + FTS_AUDIT_TABLE + " where " + KEY_DBASE
+ " = '" + selectedDb + "' and " + KEY_DTABLE + " = '"
+ selectedTable + "' and " + KEY_TERMINATION
+ " is null Order By " + KEY_ID + " desc );";
//system.out.println(query1);
Cursor cursor = mDb.rawQuery(query1, null);
String deletedField = "";
try {
if (cursor != null) {
cursor.moveToFirst();
do {
deletedField = deletedField
+ cursor.getString(cursor
.getColumnIndex(DbAdapter.KEY_DTFITELD));
} while (cursor.moveToNext());
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
close();
//system.out.println("deleted fields" + deletedField);
return deletedField;
}
public boolean EditField(String selectedDb, String selectedTable,
String OldfieldName, String NewfieldName, String fieldType,
String index) {
try {
DeleteField(selectedDb, selectedTable, OldfieldName);
DataBaseHelper cb = new DataBaseHelper(mCtx, mCtx.getPackageName());
mDb = cb.createOrOpenDB(selectedDb);
String query = "ALTER TABLE '" + selectedTable + "' ADD COLUMN '"
+ NewfieldName + "' '" + fieldType + "';";
mDb.execSQL(query);
mDb.close();
open();
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmss")
.format(Calendar.getInstance().getTime());
ContentValues initialValues = new ContentValues();// Initializes
initialValues.put(KEY_DBASE, selectedDb);
initialValues.put(KEY_DTABLE, selectedTable);
initialValues.put(KEY_DTFITELD, NewfieldName);
initialValues.put(KEY_ACTION, "field is Edited from "
+ OldfieldName);
initialValues.put(KEY_ORIGINATION, timeStamp);
initialValues.put(KEY_INDEX, index);
long done = mDb.insert(FTS_AUDIT_TABLE, null, initialValues);
//system.out.println("done " + done);
String query2 = "UPDATE " + FTS_AUDIT_TABLE + " SET " + KEY_COMP_ID
+ "=(SELECT " + KEY_COMP_ID + " FROM " + FTS_AUDIT_TABLE
+ " WHERE " + KEY_DTFITELD + " ='" + OldfieldName
+ "' ORDER BY " + KEY_ID + " DESC) WHERE "
+ KEY_ORIGINATION + " ='" + timeStamp + "' and "
+ KEY_DTFITELD + "='" + NewfieldName + "' ;";
mDb.execSQL(query2);
close();
return true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
}
我正在使用“AddRow”方法来添加值