可能得到的Andr​​oid SQLiteConstraintException特定错误的详细信息? [英] Possible to get specific error details from Android SQLiteConstraintException?

查看:575
本文介绍了可能得到的Andr​​oid SQLiteConstraintException特定错误的详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误某些数据,而概念是清楚不过了:

 android.database.sqlite.SQLiteConstraintException:外键约束失败(code 787)

不过,这并不能帮助我找到哪个特定记录有无效的FK。而不是鞭打我的code和尝试找出每一次插入一个新的事务,有没有什么办法打开(或摘录)记录了一些有用的信息,如表中的问题,甚至是FK值在作祟?

另外,我使用SqlBrite,并且已经打开调试日志记录(即只记录的操作,我仍然没有获得有关错误的详细信息)

更新: 下面是上述所有我自己的code中的logcat的的;基本异常被捕获试图关闭交易时(BriteDatabase.Transaction)previously打开(在BriteDatabase.Transaction对象是新增加的,我只是迁移从SqlBrite 0.1.0至0.4.1)。

  android.database.sqlite.SQLiteConstraintException:外键约束失败(code 787)
    在android.database.sqlite.SQLiteConnection.nativeExecute(本机方法)
    在android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:555)
    在android.database.sqlite.SQLiteSession.endTransactionUnchecked(SQLiteSession.java:437)
    在android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:401)
    在android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:522)
    在com.squareup.sqlbrite.BriteDatabase $ 1.end(BriteDatabase.java:85)
 

解决方案

解决方案1:

您可以使用亚行外壳dumpsys DBINFO -v 命令来查看有关数据库的一些信息。

在我的情况,我创建了一个小例子中插入相同的记录两次强迫 SQLiteConstraintException

 的MyDB DB =新的MyDB(本);

//插入相同的记录两次强行SQLiteConstraintException
db.insertIntoMyTable(1,MYNAME);
db.insertIntoMyTable(1,MYNAME);
 

这是亚行外壳dumpsys的DBINFO -v 命令,在我的Nexus 4的输出(我不知道,但我认为输出信息可以在设备之间的差异):

 连接池/data/data/com.your.package.name/databases/MyDB:
开放:真
最大连接数:1
可用的主连接:
连接#0:
  connectionPtr:0xffffffffb883aaf0
  isPrimaryConnection:真
  onlyAllowReadOnlyOperations:假的
  最近执行的操作:
    0:[2015年11月13号17:59:16.227] executeForLastInsertedRowId了1ms的 - 失败,SQL =INSERT INTO MyTable的(名字,_id)VALUES(?,?),bindArgs = [MYNAME,1] ,异常=UNIQUE约束失败:MyTable._id(code 1555)
    1:2015年11月13号17:59:16.227] prepare了0毫秒 - 成功了,SQL =INSERT INTO MyTable的(名字,_id)VALUES(?,?)
    2:[2015年11月13号17:59:16.209] executeForLastInsertedRowId了18毫秒 - 成功了,SQL =INSERT INTO MyTable的(名字,_id)VALUES(?,?),bindArgs = [MYNAME,1]
    3:2015年11月13号17:59:16.209] prepare了0毫秒 - 成功了,SQL =INSERT INTO MyTable的(名字,_id)VALUES(?,?)
    4:[2015年11月13号17:59:16.208] executeForLong了1ms的 - 成功了,SQL =PRAGMA user_version;
    5:[2015年11月13号17:59:16.208] prepare了0毫秒 - 成功了,SQL =PRAGMA user_version;
    6:[2015年11月13号17:59:16.208] executeForString了0毫秒 - 成功了,SQL =SELECT语言地区android_metadata UNION SELECT NULL ORDER BY区域降序极限1
    7:[2015年11月13号17:59:16.207]执行所采取1ms的 - 成功了,SQL =CREATE TABLE IF NOT EXISTS android_metadata(区域设置文本)
    8:[2015年11月13号17:59:16.207] executeForLong了0毫秒 - 成功了,SQL =PRAGMA wal_autocheckpoint = 100
    9:[2015年11月13号17:59:16.207] executeForLong了0毫秒 - 成功了,SQL =PRAGMA wal_autocheckpoint
    10:2015年11月13号17:59:16.207] executeForLong了0毫秒 - 成功了,SQL =PRAGMA journal_size_limit = 524288
    11:[2015年11月13号17:59:16.207] executeForLong了0毫秒 - 成功了,SQL =PRAGMA journal_size_limit
    12:2015年11月13号17:59:16.206] executeForString了0毫秒 - 成功了,SQL =PRAGMA同步
    13:2015年11月13号17:59:16.206] executeForString了0毫秒 - 成功了,SQL =PRAGMA journal_mode =持续
    14:2015年11月13号17:59:16.205] executeForString了1ms的 - 成功了,SQL =PRAGMA journal_mode
    15:2015年11月13号17:59:16.204] executeForLong了0毫秒 - 成功了,SQL =PRAGMA foreign_keys
    16:2015年11月13号17:59:16.204] executeForLong了0毫秒 - 成功了,SQL =PRAGMA PAGE_SIZE
  prepared语句缓存:
    0:statementPtr = 0xffffffffb8839558,numParameters = 0,类型= 1,只读=真,SQL =SELECT语言地区android_metadata UNION SELECT NULL ORDER BY区域降序极限1
可用非主连接:
<没有>
后天的连接:
<没有>
连接服务员:
<没有>
 

分析输出,在最近执行的操作:我得到以下信息(一个记录插入成功,另一个失败):

  0:[二○一五年十一月十三日17:59:16.227] executeForLastInsertedRowId了1ms的 - 失败,SQL =INSERT INTO MyTable的(名字,_id)VALUES(?,?) ,bindArgs = [MYNAME,1],异常=UNIQUE约束失败:MyTable._id(code 1555)
2:[2015年11月13号17:59:16.209] executeForLastInsertedRowId了18毫秒 - 成功了,SQL =INSERT INTO MyTable的(名字,_id)VALUES(?,?),bindArgs = [MYNAME,1]
 

解决方案2:

此解决方案是一个有点棘手,但您可以使用 android.database.sqlite.SQLiteDebug 类来获得通过Java code类似的信息。

如果您看一看<一href="https://android.googlesource.com/platform/frameworks/base.git/+/254fba8960b018a29c5fe422b8a0fd9eeedbf3e4/core/java/android/database/sqlite/SQLiteDebug.java"相对=nofollow>这个你会看到,这个类被标记为 @hide 这意味着SQLiteDebug类被排除在API文档,但它仍然可以通过反射访问。

所以,要打印的SQLite数据库的调试信息,您可以使用下面的code:

  //这些消息会使用标签打印为Log.ERRORDB
打印机P =新LogPrinter(Log.ERROR,DB);
//我们将调用android.database.sqlite.SQLiteDebug级的场的方法
//奥尼尔,我们使用-v参数,因为我们想要的输出为详细
类&LT;&GT; C =的Class.forName(android.database.sqlite.SQLiteDebug);
方法方法= c.getMethod(倾销,新的等级[] {Printer.class,字符串[]类。});
method.invoke(NULL,P,新的String [] { -  V});
 

一个简单的例子来说明解决办法:

 的MyDB DB =新的MyDB(本);

//插入相同的记录两次强行SQLiteConstraintException
db.insertIntoMyTable(1,MYNAME);
db.insertIntoMyTable(1,MYNAME);

尝试 {
    打印机P =新LogPrinter(Log.ERROR,DB);
    类&LT;&GT; C =的Class.forName(android.database.sqlite.SQLiteDebug);
    方法方法= c.getMethod(倾销,新的等级[] {Printer.class,字符串[]类。});
    method.invoke(NULL,P,新的String [] { -  V});
}
赶上(例外五){
    Log.e(MyTag的,e.getMessage());
}
 

在这种情况下,我使用了 LogPrinter 转储调试信息到logcat的,但你可以用你自己的打印机的实施。

在我的Nexus 4,logcat中看起来像这样(我不知道,但我认为输出信息可以在设备之间有所不同):

  E / SQLiteLog(22296)(1555)中止在10 INSERT INTO MyTable的(名字,_id)VALUES(?,?)]:唯一约束失败:MyTable._id
E / SQLiteDatabase(22296):错误插入的名称= MYNAME _id = 1
E / SQLiteDatabase(22296):android.database.sqlite.SQLiteConstraintException:唯一约束失败:MyTable._id(code 1555)
E / SQLiteDatabase(22296):在android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(本机方法)
E / SQLiteDatabase(22296):在android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:782)
E / SQLiteDatabase(22296):在android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
E / SQLiteDatabase(22296):在android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
E / SQLiteDatabase(22296):在android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1471)
E / SQLiteDatabase(22296):在android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)
E / SQLiteDatabase(22296):在com.example.antonio.prueba3.MyDB.insertIntoMyTable(MyDB.java:32)
E / SQLiteDatabase(22296):在com.example.antonio.prueba3.MainActivity.onCreate(MainActivity.java:24)
E / SQLiteDatabase(22296):在android.app.Activity.performCreate(Activity.java:5990)
E / SQLiteDatabase(22296):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
E / SQLiteDatabase(22296):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
E / SQLiteDatabase(22296):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
E / SQLiteDatabase(22296):在android.app.ActivityThread.access $ 800(ActivityThread.java:151)
E / SQLiteDatabase(22296):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1303)
E / SQLiteDatabase(22296):在android.os.Handler.dispatchMessage(Handler.java:102)
E / SQLiteDatabase(22296):在android.os.Looper.loop(Looper.java:135)
E / SQLiteDatabase(22296):在android.app.ActivityThread.main(ActivityThread.java:5254)
E / SQLiteDatabase(22296):在java.lang.reflect.Method.invoke(本机方法)
E / SQLiteDatabase(22296):在java.lang.reflect.Method.invoke(Method.java:372)
E / SQLiteDatabase(22296):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)
E / SQLiteDatabase(22296):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
E / DB(22296):为/data/data/com.example.antonio.prueba3/databases/MyDB连接池:
E / DB(22296):打开:真
E / DB(22296):最大连接数:1
E / DB(22296):可用主连接:
E / DB(22296):连接#0:
E / DB(22296):connectionPtr:0xffffffffb883aaf0
E / DB(22296):isPrimaryConnection:真
E / DB(22296):onlyAllowReadOnlyOperations:假的
E / DB(22296):最近执行的操作:
E / DB(22296):0:[2015年11月13号17:59:16.227] executeForLastInsertedRowId了1ms的 - 失败,SQL =INSERT INTO MyTable的(名字,_id)VALUES(?,?),bindArgs = [ MYNAME,1],异常=UNIQUE约束失败:MyTable._id(code 1555)
E / DB(22296):1:[2015年11月13号17:59:16.227] prepare了0毫秒 - 成功了,SQL =INSERT INTO MyTable的(名字,_id)VALUES(?,?)
E / DB(22296):2:[2015年11月13号17:59:16.209] executeForLastInsertedRowId了18毫秒 - 成功了,SQL =INSERT INTO MyTable的(名字,_id)VALUES(?,?),bindArgs = [ MYNAME,1]
E / DB(22296):3:[2015年11月13号17:59:16.209] prepare了0毫秒 - 成功了,SQL =INSERT INTO MyTable的(名字,_id)VALUES(?,?)
E / DB(22296):4:[2015年11月13号17:59:16.208] executeForLong了1ms的 - 成功了,SQL =PRAGMA user_version;
E / DB(22296):5:[2015年11月13号17:59:16.208] prepare了0毫秒 - 成功了,SQL =PRAGMA user_version;
E / DB(22296):6:[2015年11月13号17:59:16.208] executeForString了0毫秒 - 成功了,SQL =选择语言地区android_metadata UNION SELECT NULL ORDER BY区域降序极限1
E / DB(22296):7:[2015年11月13号17:59:16.207]执行所采取1ms的 - 成功了,SQL =CREATE TABLE IF NOT EXISTS android_metadata(区域设置文本)
E / DB(22296):8:[2015年11月13号17:59:16.207] executeForLong了0毫秒 - 成功了,SQL =PRAGMA wal_autocheckpoint = 100
E / DB(22296):9:[2015年11月13号17:59:16.207] executeForLong了0毫秒 - 成功了,SQL =PRAGMA wal_autocheckpoint
E / DB(22296):10:2015年11月13日17:59:16.207] executeForLong了0毫秒 - 成功了,SQL =PRAGMA journal_size_limit = 524288
E / DB(22296):11:2015年11月13日17:59:16.207] executeForLong了0毫秒 - 成功了,SQL =PRAGMA journal_size_limit
E / DB(22296):12:2015年11月13日17:59:16.206] executeForString了0毫秒 - 成功了,SQL =PRAGMA同步
E / DB(22296):13:2015年11月13日17:59:16.206] executeForString了0毫秒 - 成功了,SQL =PRAGMA journal_mode =持续
E / DB(22296):14:2015年11月13日17:59:16.205] executeForString了1ms的 - 成功了,SQL =PRAGMA journal_mode
E / DB(22296):15:2015年11月13日17:59:16.204] executeForLong了0毫秒 - 成功了,SQL =PRAGMA foreign_keys
E / DB(22296):16:2015年11月13日17:59:16.204] executeForLong了0毫秒 - 成功了,SQL =PRAGMA PAGE_SIZE
E / DB(22296):prepared语句缓存:
E / DB(22296):0:statementPtr = 0xffffffffb8839558,numParameters = 0,类型= 1,只读=真,SQL =选择语言地区android_metadata UNION SELECT NULL ORDER BY区域降序极限1
E / DB(22296):可用非主要连接:
E / DB(22296):其中;无&GT;
E / DB(22296):收购的连接:
E / DB(22296):其中;无&GT;
E / DB(22296):连接服务员:
E / DB(22296):其中;无&GT;
 

分析输出,我收到了 SQLiteConstraintException

  E / SQLiteDatabase(22296):android.database.sqlite.SQLiteConstraintException:唯一约束失败:MyTable._id(code 1555)
 

而在最近执行的操作:我得到以下信息(一个记录插入成功,另一个失败):

  E / DB(22296):0:[2015年11月13号17:59:16.227] executeForLastInsertedRowId了1ms的 - 失败,SQL =INSERT INTO MyTable的(名字,_id) (?,?)值,bindArgs = [MYNAME,1],异常=UNIQUE约束失败:MyTable._id(code 1555)
E / DB(22296):2:[2015年11月13号17:59:16.209] executeForLastInsertedRowId了18毫秒 - 成功了,SQL =INSERT INTO MyTable的(名字,_id)VALUES(?,?),bindArgs = [ MYNAME,1]
 

希望它帮助。

I'm getting the following error for certain data, and concept is clear enough:

android.database.sqlite.SQLiteConstraintException: FOREIGN KEY constraint failed (code 787)

However, that doesn't help me find which specific record has the invalid FK. Rather than thrash my code and try to isolate every insert with a new transaction, is there any way to turn on (or extract) logging with helpful details such as the table in question or even the FK value that is causing trouble?

Also, I'm using SqlBrite, and have turned debug logging on (that just logs the operations, I still don't get more info on the error)

Update: Here's all of the logcat above my own code; essentially the exception is caught when trying to close a transaction (BriteDatabase.Transaction) previously opened (the BriteDatabase.Transaction object is a new addition; I just migrated from SqlBrite 0.1.0 to 0.4.1).

android.database.sqlite.SQLiteConstraintException: FOREIGN KEY constraint failed (code 787)
    at android.database.sqlite.SQLiteConnection.nativeExecute(Native Method)
    at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:555)
    at android.database.sqlite.SQLiteSession.endTransactionUnchecked(SQLiteSession.java:437)
    at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:401)
    at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:522)
    at com.squareup.sqlbrite.BriteDatabase$1.end(BriteDatabase.java:85)

解决方案

Solution 1:

You can use the adb shell dumpsys dbinfo -v command to see some info about databases.

In my case, I have created a small example that inserts the same record twice forcing a SQLiteConstraintException:

MyDB db = new MyDB(this);

// Insert the same record twice to force a SQLiteConstraintException
db.insertIntoMyTable("1","MyName");
db.insertIntoMyTable("1","MyName");

This is the output of the adb shell dumpsys dbinfo -v command in my Nexus 4 (I am not sure, but I think that the output info can differ between devices):

Connection pool for /data/data/com.your.package.name/databases/MyDB:
Open: true
Max connections: 1
Available primary connection:
Connection #0:
  connectionPtr: 0xffffffffb883aaf0
  isPrimaryConnection: true
  onlyAllowReadOnlyOperations: false
  Most recently executed operations:
    0: [2015-11-13 17:59:16.227] executeForLastInsertedRowId took 1ms - failed, sql="INSERT INTO MyTable(name,_id) VALUES (?,?)", bindArgs=["MyName", "1"], exception="UNIQUE constraint failed: MyTable._id (code 1555)"
    1: [2015-11-13 17:59:16.227] prepare took 0ms - succeeded, sql="INSERT INTO MyTable(name,_id) VALUES (?,?)"
    2: [2015-11-13 17:59:16.209] executeForLastInsertedRowId took 18ms - succeeded, sql="INSERT INTO MyTable(name,_id) VALUES (?,?)", bindArgs=["MyName", "1"]
    3: [2015-11-13 17:59:16.209] prepare took 0ms - succeeded, sql="INSERT INTO MyTable(name,_id) VALUES (?,?)"
    4: [2015-11-13 17:59:16.208] executeForLong took 1ms - succeeded, sql="PRAGMA user_version;"
    5: [2015-11-13 17:59:16.208] prepare took 0ms - succeeded, sql="PRAGMA user_version;"
    6: [2015-11-13 17:59:16.208] executeForString took 0ms - succeeded, sql="SELECT locale FROM android_metadata UNION SELECT NULL ORDER BY locale DESC LIMIT 1"
    7: [2015-11-13 17:59:16.207] execute took 1ms - succeeded, sql="CREATE TABLE IF NOT EXISTS android_metadata (locale TEXT)"
    8: [2015-11-13 17:59:16.207] executeForLong took 0ms - succeeded, sql="PRAGMA wal_autocheckpoint=100"
    9: [2015-11-13 17:59:16.207] executeForLong took 0ms - succeeded, sql="PRAGMA wal_autocheckpoint"
    10: [2015-11-13 17:59:16.207] executeForLong took 0ms - succeeded, sql="PRAGMA journal_size_limit=524288"
    11: [2015-11-13 17:59:16.207] executeForLong took 0ms - succeeded, sql="PRAGMA journal_size_limit"
    12: [2015-11-13 17:59:16.206] executeForString took 0ms - succeeded, sql="PRAGMA synchronous"
    13: [2015-11-13 17:59:16.206] executeForString took 0ms - succeeded, sql="PRAGMA journal_mode=PERSIST"
    14: [2015-11-13 17:59:16.205] executeForString took 1ms - succeeded, sql="PRAGMA journal_mode"
    15: [2015-11-13 17:59:16.204] executeForLong took 0ms - succeeded, sql="PRAGMA foreign_keys"
    16: [2015-11-13 17:59:16.204] executeForLong took 0ms - succeeded, sql="PRAGMA page_size"
  Prepared statement cache:
    0: statementPtr=0xffffffffb8839558, numParameters=0, type=1, readOnly=true, sql="SELECT locale FROM android_metadata UNION SELECT NULL ORDER BY locale DESC LIMIT 1"
Available non-primary connections:
<none>
Acquired connections:
<none>
Connection waiters:
<none>

Analyzing the output, in the Most recently executed operations: I get the following info (one record successfully inserted, and another failed):

0: [2015-11-13 17:59:16.227] executeForLastInsertedRowId took 1ms - failed, sql="INSERT INTO MyTable(name,_id) VALUES (?,?)", bindArgs=["MyName", "1"], exception="UNIQUE constraint failed: MyTable._id (code 1555)"
2: [2015-11-13 17:59:16.209] executeForLastInsertedRowId took 18ms - succeeded, sql="INSERT INTO MyTable(name,_id) VALUES (?,?)", bindArgs=["MyName", "1"]

Solution 2:

This solution is a bit tricky, but you can use the android.database.sqlite.SQLiteDebug class to get similar info via Java code.

If you take a look at this you will see that this class is marked as @hide which means that the SQLiteDebug class is excluded from the API docs, but it can still be accessed via reflection.

So, to print the debug info for the SQLite databases, you can use the following code:

// The messages will be printed as Log.ERROR using the tag "DB"
Printer p = new LogPrinter(Log.ERROR, "DB");
// We will invoke the "dump" method of the "android.database.sqlite.SQLiteDebug" class
// We eill use the "-v" parameter because we want the output to be verbose
Class<?> c = Class.forName("android.database.sqlite.SQLiteDebug");
Method method = c.getMethod("dump", new Class[]{Printer.class, String[].class});
method.invoke(null, p, new String[]{"-v"});

A simple example to illustrate the solution:

MyDB db = new MyDB(this);

// Insert the same record twice to force a SQLiteConstraintException
db.insertIntoMyTable("1","MyName");
db.insertIntoMyTable("1","MyName");

try {
    Printer p = new LogPrinter(Log.ERROR, "DB");
    Class<?> c = Class.forName("android.database.sqlite.SQLiteDebug");
    Method method = c.getMethod("dump", new Class[]{Printer.class, String[].class});
    method.invoke(null, p, new String[]{"-v"});
}
catch (Exception e) {
    Log.e("MyTag", e.getMessage());
}

In this case I use a LogPrinter to dump the debug info to logcat, but you can use your own Printer implementation.

In my Nexus 4, the logcat looks like this (I am not sure, but I think that the output info can differ between devices):

E/SQLiteLog(22296): (1555) abort at 10 in [INSERT INTO MyTable(name,_id) VALUES (?,?)]: UNIQUE constraint failed: MyTable._id
E/SQLiteDatabase(22296): Error inserting name=MyName _id=1
E/SQLiteDatabase(22296): android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: MyTable._id (code 1555)
E/SQLiteDatabase(22296):    at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
E/SQLiteDatabase(22296):    at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:782)
E/SQLiteDatabase(22296):    at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
E/SQLiteDatabase(22296):    at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
E/SQLiteDatabase(22296):    at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1471)
E/SQLiteDatabase(22296):    at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)
E/SQLiteDatabase(22296):    at com.example.antonio.prueba3.MyDB.insertIntoMyTable(MyDB.java:32)
E/SQLiteDatabase(22296):    at com.example.antonio.prueba3.MainActivity.onCreate(MainActivity.java:24)
E/SQLiteDatabase(22296):    at android.app.Activity.performCreate(Activity.java:5990)
E/SQLiteDatabase(22296):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
E/SQLiteDatabase(22296):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
E/SQLiteDatabase(22296):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
E/SQLiteDatabase(22296):    at android.app.ActivityThread.access$800(ActivityThread.java:151)
E/SQLiteDatabase(22296):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
E/SQLiteDatabase(22296):    at android.os.Handler.dispatchMessage(Handler.java:102)
E/SQLiteDatabase(22296):    at android.os.Looper.loop(Looper.java:135)
E/SQLiteDatabase(22296):    at android.app.ActivityThread.main(ActivityThread.java:5254)
E/SQLiteDatabase(22296):    at java.lang.reflect.Method.invoke(Native Method)
E/SQLiteDatabase(22296):    at java.lang.reflect.Method.invoke(Method.java:372)
E/SQLiteDatabase(22296):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
E/SQLiteDatabase(22296):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
E/DB      (22296): Connection pool for /data/data/com.example.antonio.prueba3/databases/MyDB:
E/DB      (22296):   Open: true
E/DB      (22296):   Max connections: 1
E/DB      (22296):   Available primary connection:
E/DB      (22296):     Connection #0:
E/DB      (22296):       connectionPtr: 0xffffffffb883aaf0
E/DB      (22296):       isPrimaryConnection: true
E/DB      (22296):       onlyAllowReadOnlyOperations: false
E/DB      (22296):       Most recently executed operations:
E/DB      (22296):         0: [2015-11-13 17:59:16.227] executeForLastInsertedRowId took 1ms - failed, sql="INSERT INTO MyTable(name,_id) VALUES (?,?)", bindArgs=["MyName", "1"], exception="UNIQUE constraint failed: MyTable._id (code 1555)"
E/DB      (22296):         1: [2015-11-13 17:59:16.227] prepare took 0ms - succeeded, sql="INSERT INTO MyTable(name,_id) VALUES (?,?)"
E/DB      (22296):         2: [2015-11-13 17:59:16.209] executeForLastInsertedRowId took 18ms - succeeded, sql="INSERT INTO MyTable(name,_id) VALUES (?,?)", bindArgs=["MyName", "1"]
E/DB      (22296):         3: [2015-11-13 17:59:16.209] prepare took 0ms - succeeded, sql="INSERT INTO MyTable(name,_id) VALUES (?,?)"
E/DB      (22296):         4: [2015-11-13 17:59:16.208] executeForLong took 1ms - succeeded, sql="PRAGMA user_version;"
E/DB      (22296):         5: [2015-11-13 17:59:16.208] prepare took 0ms - succeeded, sql="PRAGMA user_version;"
E/DB      (22296):         6: [2015-11-13 17:59:16.208] executeForString took 0ms - succeeded, sql="SELECT locale FROM android_metadata UNION SELECT NULL ORDER BY locale DESC LIMIT 1"
E/DB      (22296):         7: [2015-11-13 17:59:16.207] execute took 1ms - succeeded, sql="CREATE TABLE IF NOT EXISTS android_metadata (locale TEXT)"
E/DB      (22296):         8: [2015-11-13 17:59:16.207] executeForLong took 0ms - succeeded, sql="PRAGMA wal_autocheckpoint=100"
E/DB      (22296):         9: [2015-11-13 17:59:16.207] executeForLong took 0ms - succeeded, sql="PRAGMA wal_autocheckpoint"
E/DB      (22296):         10: [2015-11-13 17:59:16.207] executeForLong took 0ms - succeeded, sql="PRAGMA journal_size_limit=524288"
E/DB      (22296):         11: [2015-11-13 17:59:16.207] executeForLong took 0ms - succeeded, sql="PRAGMA journal_size_limit"
E/DB      (22296):         12: [2015-11-13 17:59:16.206] executeForString took 0ms - succeeded, sql="PRAGMA synchronous"
E/DB      (22296):         13: [2015-11-13 17:59:16.206] executeForString took 0ms - succeeded, sql="PRAGMA journal_mode=PERSIST"
E/DB      (22296):         14: [2015-11-13 17:59:16.205] executeForString took 1ms - succeeded, sql="PRAGMA journal_mode"
E/DB      (22296):         15: [2015-11-13 17:59:16.204] executeForLong took 0ms - succeeded, sql="PRAGMA foreign_keys"
E/DB      (22296):         16: [2015-11-13 17:59:16.204] executeForLong took 0ms - succeeded, sql="PRAGMA page_size"
E/DB      (22296):       Prepared statement cache:
E/DB      (22296):         0: statementPtr=0xffffffffb8839558, numParameters=0, type=1, readOnly=true, sql="SELECT locale FROM android_metadata UNION SELECT NULL ORDER BY locale DESC LIMIT 1"
E/DB      (22296):   Available non-primary connections:
E/DB      (22296):     <none>
E/DB      (22296):   Acquired connections:
E/DB      (22296):     <none>
E/DB      (22296):   Connection waiters:
E/DB      (22296):     <none>

Analyzing the output, I get a SQLiteConstraintException:

E/SQLiteDatabase(22296): android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: MyTable._id (code 1555)

And in the Most recently executed operations: I get the following info (one record successfully inserted, and another failed):

E/DB      (22296):         0: [2015-11-13 17:59:16.227] executeForLastInsertedRowId took 1ms - failed, sql="INSERT INTO MyTable(name,_id) VALUES (?,?)", bindArgs=["MyName", "1"], exception="UNIQUE constraint failed: MyTable._id (code 1555)"
E/DB      (22296):         2: [2015-11-13 17:59:16.209] executeForLastInsertedRowId took 18ms - succeeded, sql="INSERT INTO MyTable(name,_id) VALUES (?,?)", bindArgs=["MyName", "1"]

Hope it helps.

这篇关于可能得到的Andr​​oid SQLiteConstraintException特定错误的详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆