我正在将同一数据库中的所有记录(备份)从 table1 复制到 table2。这是我的第一个数据库应用程序。
这是表1结构:
private static final String CREATE_SELECTED_CAND_TABLE = " CREATE TABLE if not exists "
+ TABLE_SELECTED_CAND
+ "("
+ KEY_ID
+ " integer PRIMARY KEY autoincrement,"
+ KEY_NAME1
+ " TEXT,"
+ KEY_NAME2
+ " TEXT,"
+ KEY_NAME3
+ " TEXT,"
+ KEY_NAME4
+ " TEXT," + KEY_NAME5 + " TEXT" + ")";
表2结构:
private static final String CREATE_SELECTED_CAND_RECOUNT1 = " CREATE TABLE if not exists "
+ TABLE_RECOUNT1
+ "("
+ KEY_ID
+ " integer PRIMARY KEY autoincrement,"
+ KEY_NAME1
+ " TEXT,"
+ KEY_NAME2
+ " TEXT,"
+ KEY_NAME3
+ " TEXT,"
+ KEY_NAME4
+ " TEXT," + KEY_NAME5 + " TEXT" + ")";
我正在像这样复制:
mDb.execSQL(" INSERT INTO " + TABLE_RECOUNT1 + " SELECT * FROM "
+ TABLE_SELECTED_CAND);
现在的问题是,只有当所有列都不为空时才复制 我有一些列为空,但我也想复制它们。我该如何实现这一目标。?任何帮助将是非常可观的..!
这些是堆栈跟踪:
E/AndroidRuntime(30294): android.database.sqlite.SQLiteConstraintException:错误代码 19: 约束失败
E/AndroidRuntime(30294): at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
E/AndroidRuntime(30294): at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:92)
E/AndroidRuntime(30294):在 android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:2028)
E/AndroidRuntime(30294):在 android. database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1968)
E/AndroidRuntime(30294):在 com.dana.db.SelectedCandidatesDB.copyToRecount1(SelectedCandidatesDB.java:257)
E/AndroidRuntime(30294):在 com.dana.votecount.VoteRecount.fetchAllFromRecount1(VoteRecount.java:161) E/AndroidRuntime(30294):在 com.dana.votecount.VoteRecount.access$1(VoteRecount.java:158)
E /AndroidRuntime(30294):在 com.dana.votecount.VoteRecount$2$1.onClick(VoteRecount.java:107)