带有NULLABLE外键的SQLite(SQLite with NULLABLE foreign keys)
我遇到导致SQLiteConstraintException的NULLABLE外键问题。 使用以下命令启用外键:
PRAGMA foreign_keys = ON
使用以下语句创建表:
CREATE TABLE conversation (_id INTEGER PRIMARY KEY); CREATE TABLE message (_id INTEGER PRIMARY KEY, conversation_id INTEGER, FOREIGN KEY(conversation_id) REFERENCES conversation (_id) ON DELETE CASCADE);
这些陈述令人沮丧,以提高阅读率。
如您所见,外键'conversation_id'被声明为NULLABLE,因此我不会强制将每条消息链接到一个对话(例如,当创建一个没有相应对话的草稿消息时)。
当我尝试使用conversation_id插入新消息时,一切都很顺利。 当我尝试没有时,我得到以下错误:
11-07 16:44:55.190 20582-20582/com.miawe.miabe E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.miawe.miabe, PID: 20582 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.miawe.miabe/com.miawe.miabe.gui.MainActivity}: android.database.sqlite.SQLiteConstraintException: foreign key constraint failed (code 19) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) Caused by: android.database.sqlite.SQLiteConstraintException: foreign key constraint failed (code 19) at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method) at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:782) at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788) at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86) at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469) at android.database.sqlite.SQLiteDatabase.insertOrThrow(SQLiteDatabase.java:1365) at com.miawe.miabe.database.DatabaseDataSource.insert(DatabaseDataSource.java:244) at com.miawe.miabe.database.DatabaseDataSource.createDummyData(DatabaseDataSource.java:307) at com.miawe.miabe.gui.MainActivity.onCreate(MainActivity.java:64) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)
似乎sqlite3忽略了我的NULL约束并强制每条消息都有一个外键。 我该怎么做才能使列conversation_id接受NULL值?
I am having problems with NULLABLE foreign keys leading to an SQLiteConstraintException. Foreign keys are enabled by using:
PRAGMA foreign_keys = ON
The tables are created with the following statements:
CREATE TABLE conversation (_id INTEGER PRIMARY KEY); CREATE TABLE message (_id INTEGER PRIMARY KEY, conversation_id INTEGER, FOREIGN KEY(conversation_id) REFERENCES conversation (_id) ON DELETE CASCADE);
The statements are dumbed down to improve reading.
As you can see, the foreign key 'conversation_id' is declared as NULLABLE, so that I am not forced to link every message to a conversation (for example when a draft message gets created that has no corresponding conversation).
When I try to insert a new message with a conversation_id, everything goes fine. When I try it without I get the following error:
11-07 16:44:55.190 20582-20582/com.miawe.miabe E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.miawe.miabe, PID: 20582 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.miawe.miabe/com.miawe.miabe.gui.MainActivity}: android.database.sqlite.SQLiteConstraintException: foreign key constraint failed (code 19) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) Caused by: android.database.sqlite.SQLiteConstraintException: foreign key constraint failed (code 19) at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method) at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:782) at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788) at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86) at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469) at android.database.sqlite.SQLiteDatabase.insertOrThrow(SQLiteDatabase.java:1365) at com.miawe.miabe.database.DatabaseDataSource.insert(DatabaseDataSource.java:244) at com.miawe.miabe.database.DatabaseDataSource.createDummyData(DatabaseDataSource.java:307) at com.miawe.miabe.gui.MainActivity.onCreate(MainActivity.java:64) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)
It seems like sqlite3 is ignoring my NULL-constraint and forcing every message to have a foreign key. What can I do to make the column conversation_id accept NULL values?
原文:https://stackoverflow.com/questions/26805481
最满意答案
我想你可以使用mbedtls_x509_crt_info返回一个关于证书的信息字符串。
您可以在客户端连接时
get the peer certificate from the ssl session
,然后打印出信息。mbedtls_ssl_context ssl; ... mbedtls_x509_crt *crt = ssl.session->peer_cert; unsigned char buf[1024]; int ret = mbedtls_x509_crt_info((char *) buf, sizeof( buf ) - 1, "", crt); if( ret != -1 ) { mbedtls_printf( "%s\n", buf ); }
我没有测试过这个,只是检查了一些例子。
I think you could use mbedtls_x509_crt_info which returns an informational string about the certificate.
You can
get the peer certificate from the ssl session
when the client connects and then print the info out.mbedtls_ssl_context ssl; ... mbedtls_x509_crt *crt = ssl.session->peer_cert; unsigned char buf[1024]; int ret = mbedtls_x509_crt_info((char *) buf, sizeof( buf ) - 1, "", crt); if( ret != -1 ) { mbedtls_printf( "%s\n", buf ); }
I didn't test this, just checked the examples.
相关问答
更多-
解决方案是将JVM-Paramters用于信任库和密钥库。 java -Djavax.net.ssl.trustStore=/some/path/myTruststore.jks -Djavax.net.ssl.trustStorePassword=abc -Djavax.net.ssl.keyStore=/some/path/myKeystore.p12 -Djavax.net.ssl.keyStorePassword=defg -Djavax.net.ssl.keyStoreType=PKCS12 ...
-
为什么我的客户端证书不包含在TLS握手中?(Why is my client certificate not being included in the TLS handshake?)[2023-08-03]
我找到了解决方案,但我不确定我是否完全理解它。 问题是客户端证书(或者可能只是链中的一些其他证书)需要出现在发出请求的用户的个人证书存储中。 我以Windows服务运行的用户身份登录,将证书导入其存储,现在一切正常。 这表明客户端证书以某种方式进行验证,即使它们是从文件加载而不是在商店中引用。 这在ProcMon的输出中实际上很明显,如果我一直在更加注意,我会意识到它正在搜索证书存储并提出NOT FOUND结果。 如果Microsoft的WCF客户端代码在证书出现问题时抛出异常,而不仅仅是尝试在没有证书的情 ... -
经典内存溢出 char *input = new char[inputSize]; input[inputSize] = '\0'; I've finally found a solution. The problem was strlen((char*)outputBuffer) becuase it was always 0 since output from rsa_pkcs1_encrypt starts with \0. The right solution is bool AsymetricC ...
-
您可以使用@Context Annotation来提取HttpServletRequest。 @POST @Path("/getHelloWorld") @Consumes(MediaType.APPLICATION_JSON) public String helloWorld(@Context HttpServletRequest httpRequest) { X509Certificate[] certs = (X509Certificate[]) httpRequest.getAttribut ...
-
使用客户端证书HTTPS进行移动与dektop身份验证(mobile vs dektop authentication with client certificate HTTPS)[2023-06-17]
协议没有区别,但是在设备上安装证书以及以后对它们的访问是非常不同的。 你是如何在Windows上安装设备证书的,以及如何在iPhone上安装设备证书? There's no difference in the protocols, but installation of the certificates on the devices and later access to them is much different. How did you install the device certificate o ... -
仅对某些特定资源请求客户端证书身份验证(request client certificate authentication only to some particular resource)[2022-04-22]
单独使用Tomcat无法做到这一点。 客户端身份验证最多是每个webapp,或者您可以在server.xml Connector元素中为整个容器设置它,无论用途如何。 如果您需要每个资源,您可以通过在前面使用Apache HTTPD并使其终止SSL来获取它。 (它仍然会将标头中的客户端证书传递给Tomcat,以便Tomcat可以遵守关于使其可用于Web应用程序的Servlet规范。)然后,您可以将几乎所有关于SSL的内容配置为单个文件的级别。 这也为您提供各种其他好处,如负载平衡。 You can't do ... -
如果客户端未通过证书,则https连接的安全性如何(How secure is the https connection if the client not passes certificate)[2022-03-06]
如果您不使用客户端证书,则https连接仍然是安全的: 只有客户端和服务器才能读/写内容 证书颁发机构确保服务器的身份 客户端证书仅在连接开始时为您提供客户端身份验证 。 要加密数据,首先使用服务器的公钥(请参阅公钥加密)。 如果您在登录/密码提交后使用cookie设置客户端,则仍然是安全的:您已识别客户端。 If you don't use client certificate, the https connection is still safe: Only the client and the ser ... -
简单的解决方案:从配置中删除/禁用POLARSSL_HAVE_ASM ,因为它使mpi_mul_hlp()仅使用C代码进行行为,而无需进行程序集优化。 Simple solution: Remove / disable POLARSSL_HAVE_ASM from your configuration, as it makes mpi_mul_hlp() behave with only C code an no assembly optimizations.
-
我想你可以使用mbedtls_x509_crt_info返回一个关于证书的信息字符串。 您可以在客户端连接时get the peer certificate from the ssl session ,然后打印出信息。 mbedtls_ssl_context ssl; ... mbedtls_x509_crt *crt = ssl.session->peer_cert; unsigned char buf[1024]; int ret = mbedtls_x509_crt_info((char *) ...
-
通过将证书导入为物理设备,浏览器是否允许我在导入时使用证书? 是。 但是,与软件令牌相比,使用硬件令牌时可能会发现更长的延迟(例如,对于智能卡2-3秒)。 如果证书有针,会发生什么? 浏览器每次启动时都会询问引脚吗? 默认情况下,如果您连接到启用了HTTPS客户端身份验证的网页,Firefox只会尝试访问客户端证书。 然后将要求PIN。 通常,只要不删除令牌,就不再需要PIN,但该行为可能因使用的PKCS#11模块(将Firefox与令牌连接的软件)而不同。 我可以确定无法从令牌/智能卡读卡器中提取证书吗? ...