【问题标题】:Xcode - sqlite3.dylib: illegal multi-thread access to database connectionXcode - sqlite3.dylib:非法多线程访问数据库连接
【发布时间】:2018-12-11 05:51:59
【问题描述】:

我被难住了..

设置:Xcode 9.4.1 (9F2000) 运行于:iOS 模拟器 iPhone 8 (11.4) sqlite3 配置:sqlite3_config(SQLITE_CONFIG_SERIALIZED);

问题

1) "[logging] BUG IN CLIENT OF sqlite3.dylib: 非法多线程访问数据库连接" 在线错误

if(sqlite3_prepare_v2(_contactDB, query_stmt, -1, &statment, NULL) == SQLITE_OK )
==> EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

我能做的就是改变

if(sqlite3_open([[self filepath] UTF8String], &db)!= SQLITE_OK)

if (sqlite3_open_v2([[self filepath] UTF8String], &db, SQLITE_OPEN_READWRITE|SQLITE_OPEN_FULLMUTEX, NULL) != SQLITE_OK)

但这导致我遇到第二个问题

2) 在我执行 Simulator -> Erase All Contents and Settings 之后,运行该应用程序会出现错误“libc++abi.dylib: terminating with uncaught exception of type NSException”在线

class AppDelegate: UIResponder, UIApplicationDelegate, PKPushRegistryDelegate
==> signal SIGABRT

完整的日志

[logging] API call with invalid database connection pointer
[logging] misuse at line 123231 of [2b0954060f]
[logging] API called with NULL prepared statement
[logging] misuse at line 83511 of [2b0954060f]
SQL Error. Not able to add the record. SQL: INSERT INTO SERVER_LIST
(a, b, c, dh) VALUES ("1", "2", "3, "4")
[logging] API call with invalid database connection pointer
[logging] misuse at line 148673 of [2b0954060f]
[logging] API call with invalid database connection pointer
[logging] misuse at line 123231 of [2b0954060f]
*** Terminating appxdue to uncaught exception 'NSRangeException',
reason: '*** -[__NSArrayMobjectAtIndex:]: index 18446744073709551615
beyond bounds for empty array'

*** First throw call stack:
(
0   CoreFoundation                      0x000000010ce0d1e6 __exceptionPreprocess + 294
1   libobjc.A.dylib                     0x000000010c4aa031 objc_exception_throw + 48
2   CoreFoundation                      0x000000010ce4d0bc _CFThrowFormattedException + 194
3   CoreFoundation                      0x000000010cd3ce76 -[__NSArrayM objectAtIndex:] + 150
4   App                              0x0000000106a60570 _T06App7loginVCC13newaccountAddyyF + 1296
5   App                              0x0000000106a610e4 _T06App7loginVCC13newaccountAddyyFTo + 36
6   CoreFoundation                      0x000000010cda8b8c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
7   CoreFoundation                      0x000000010cda8a65 _CFXRegistrationPost + 453
8   CoreFoundation                      0x000000010cda87a1 ___CFXNotificationPost_block_invoke + 225
9   CoreFoundation                      0x000000010cd6a422 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826
10  CoreFoundation                      0x000000010cd695a1 _CFXNotificationPost + 609
11  Foundation                          0x0000000109ccbe57 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
12  App                              0x000000010663fafb __41-[AppServer verification:url:records:]_block_invoke_2 + 2363
13  App                              0x00000001065dab94 __91-[AFHTTPSessionManager POST:parameters:constructingBodyWithBlock:progress:success:failure:]_block_invoke.106 + 228
14  App                              0x00000001065c3db9 __72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_2.119 + 201
15  libdispatch.dylib                   0x000000010f2397ab _dispatch_call_block_and_release + 12
16  libdispatch.dylib                   0x000000010f23a7ec _dispatch_client_callout + 8
17  libdispatch.dylib                   0x000000010f245a3c _dispatch_main_queue_callback_4CF + 993
18  CoreFoundation                      0x000000010cdcfc99 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
19  CoreFoundation                      0x000000010cd93ea6 __CFRunLoopRun + 2342
20  CoreFoundation                      0x000000010cd9330b CFRunLoopRunSpecific + 635
21  GraphicsServices                    0x0000000110dbda73 GSEventRunModal + 62
22  UIKit                               0x000000010a30f057 UIApplicationMain + 159
23  App                                 0x0000000106b64567 main + 55
24  libdyld.dylib                       0x000000010f2b7955 start + 1
25  ???                                 0x0000000000000001 0x0 + 1
)

请帮忙,错误让我陷入困境..

谢谢!

【问题讨论】:

  • 您似乎一直在尝试使用db 变量,即使数据库无法打开也是如此。修复您的代码,使sqlite3_open_v2 返回SQLITE_OK

标签: ios objective-c xcode sqlite


【解决方案1】:

通过修改开放代码解决

if (sqlite3_open_v2([[self filepath] UTF8String], &db_sns, SQLITE_OPEN_READWRITE|SQLITE_OPEN_FULLMUTEX|SQLITE_OPEN_CREATE, NULL) != SQLITE_OK)

【讨论】:

    猜你喜欢
    • 2018-08-18
    • 2014-10-10
    • 2011-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    相关资源
    最近更新 更多