出现错误[记录] sqlite3.dylib的客户端中的错误:对数据库连接的非法多线程访问

时间:2018-07-09 11:29:43

标签: ios multithreading sqlite xcode9

我有一个使用sqlite3的iOS应用,遇到多线程崩溃的问题,并出现错误 [logging] sqlite3.dylib的客户端错误:对数据库连接的非法多线程访问< / strong>这是我的sqlite代码:

- (instancetype)initWithPath:(NSString*)aPath
{
    // default flags for sqlite3_open
    return [self initWithPath:aPath flags:SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE];
}

- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags vfs:(NSString *)vfsName {

    self = [super init];

    if (self != nil) {

        _db = [[[self class] databaseClass] databaseWithPath:aPath];
        FMDBRetain(_db);

#if SQLITE_VERSION_NUMBER >= 3005000
        BOOL success = [_db openWithFlags:openFlags vfs:vfsName];
#else
        BOOL success = [_db open];
#endif
        if (!success) {
            NSLog(@"Could not create database queue for path %@", aPath);
            FMDBRelease(self);
            return 0x00;
        }

        _path = FMDBReturnRetained(aPath);

        _queue = dispatch_queue_create([[NSString stringWithFormat:@"fmdb.%@", self] UTF8String], NULL);
        dispatch_queue_set_specific(_queue, kDispatchQueueSpecificKey, (__bridge void *)self, NULL);
        _openFlags = openFlags;
    }

    return self;
}

- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags {
    return [self initWithPath:aPath flags:openFlags vfs:nil];
}

- (instancetype)initWithPath:(NSString*)aPath {

    // default flags for sqlite3_open
    return [self initWithPath:aPath flags:SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE vfs:nil];
}

- (instancetype)init {
    return [self initWithPath:nil];
}
int err = sqlite3_open_v2([self sqlitePath], &_db, flags, [vfsName UTF8String]);
    if(err != SQLITE_OK) {
        NSLog(@"error opening!: %d", err);
        return NO;
    }

    if (_maxBusyRetryTimeInterval > 0.0) {
        // set the handler
        [self setMaxBusyRetryTimeInterval:_maxBusyRetryTimeInterval];
    }

    return YES;

这些是完整的日志

2018-07-09 16:03:33.353472+0530 Aglive[1210:840662] Unknown error calling sqlite3_step (19: UNIQUE constraint failed: Property.PropertyId) eu
2018-07-09 16:03:33.353527+0530 Aglive[1210:840662] DB Query: insert into Property(PropertyId,PropertyName,Area,PropertyManagerName,PIC,Latitude,Longitude,BusinessId,BusinessName,IsEUAccredited,BusinessOwnerName,BrandingPicture,EarMarkText,Brand,DSE,StockDensity,IsFenceAvailable,MSANumber,IsGAPAccredited,IsNEAccredited) values(:PropertyId,:PropertyName,:Area,:PropertyManagerName,:PIC,:Latitude,:Longitude,:BusinessId,:BusinessName,:IsEUAccredited,:BusinessOwnerName,:BrandingPicture,:EarMarkText,:Brand,:CurrentDSE,:CurrentStockDensity,:IsFenceAvailable,:MSANumber,:IsGAPAccredited,:IsNEAccredited)
2018-07-09 16:03:33.353614+0530 Aglive[1210:840662] Unknown error finalizing or resetting statement (19: UNIQUE constraint failed: Property.PropertyId)
2018-07-09 16:03:33.354045+0530 Aglive[1210:840662] DB Query: insert into Property(PropertyId,PropertyName,Area,PropertyManagerName,PIC,Latitude,Longitude,BusinessId,BusinessName,IsEUAccredited,BusinessOwnerName,BrandingPicture,EarMarkText,Brand,DSE,StockDensity,IsFenceAvailable,MSANumber,IsGAPAccredited,IsNEAccredited) values(:PropertyId,:PropertyName,:Area,:PropertyManagerName,:PIC,:Latitude,:Longitude,:BusinessId,:BusinessName,:IsEUAccredited,:BusinessOwnerName,:BrandingPicture,:EarMarkText,:Brand,:CurrentDSE,:CurrentStockDensity,:IsFenceAvailable,:MSANumber,:IsGAPAccredited,:IsNEAccredited)
2018-07-09 16:03:33.354096+0530 Aglive[1210:840662] Error: UNIQUE constraint failed: Property.PropertyId
2018-07-09 16:03:33.354308+0530 Aglive[1210:840662] Could not find index for ExportEligibilities
2018-07-09 16:03:33.354373+0530 Aglive[1210:840662] Could not find index for ZoneCount
2018-07-09 16:03:33.354459+0530 Aglive[1210:840662] Could not find index for MobCount
2018-07-09 16:03:33.354655+0530 Aglive[1210:840662] Could not find index for Email
2018-07-09 16:03:33.354711+0530 Aglive[1210:840662] Could not find index for PaddockCount
2018-07-09 16:03:33.354866+0530 Aglive[1210:840662] Could not find index for DSE
2018-07-09 16:03:33.354914+0530 Aglive[1210:840662] Could not find index for IsMSAAccredited
2018-07-09 16:03:33.354946+0530 Aglive[1210:840662] Could not find index for EarmarkText
2018-07-09 16:03:33.354995+0530 Aglive[1210:840662] Could not find index for StockDensity
2018-07-09 16:03:33.355034+0530 Aglive[1210:840662] Could not find index for CenterCoordinate
2018-07-09 16:03:33.355077+0530 Aglive[1210:840662] Could not find index for LivestockCount
2018-07-09 16:03:33.355131+0530 Aglive[1210:840662] Could not find index for IsDeleted
2018-07-09 16:03:33.355179+0530 Aglive[1210:840662] Could not find index for PropertyAddress
2018-07-09 16:03:33.355215+0530 Aglive[1210:840662] Could not find index for PropertyTypes
2018-07-09 16:03:33.358538+0530 Aglive[1210:840662] Could not find index for Suburb
2018-07-09 16:03:33.358679+0530 Aglive[1210:840662] Could not find index for State
2018-07-09 16:03:33.359312+0530 Aglive[1210:840662] Unknown error calling sqlite3_step (19: UNIQUE constraint failed: PropertyAddress.PropertyAddressId) eu
2018-07-09 16:03:33.359394+0530 Aglive[1210:840662] DB Query: insert into PropertyAddress(PropertyAddressId,AddressLine1,AddressLine2,AddressLine3,CountryCode,SuburbId,StateId,Postcode,PropertyId) values(:AddressId,:AddresssLine1,:AddresssLine2,:AddresssLine3,:CountryCode,:SuburbId,:StateId,:PostCode,:PropertyId)
2018-07-09 16:03:33.359438+0530 Aglive[1210:840662] Unknown error finalizing or resetting statement (19: UNIQUE constraint failed: PropertyAddress.PropertyAddressId)
2018-07-09 16:03:33.359465+0530 Aglive[1210:840662] DB Query: insert into PropertyAddress(PropertyAddressId,AddressLine1,AddressLine2,AddressLine3,CountryCode,SuburbId,StateId,Postcode,PropertyId) values(:AddressId,:AddresssLine1,:AddresssLine2,:AddresssLine3,:CountryCode,:SuburbId,:StateId,:PostCode,:PropertyId)
2018-07-09 16:03:33.359749+0530 Aglive[1210:840662] Could not find index for Suburb
2018-07-09 16:03:33.359821+0530 Aglive[1210:840662] Could not find index for State
2018-07-09 16:03:33.360870+0530 Aglive[1210:840662] Could not find index for PropertyTypeName
2018-07-09 16:03:33.377717+0530 Aglive[1210:839164] Login Response:- {
    "access_token" = "R3aXD3YM6P_BuRRiOLTvTGgBAWubj43vnNiL1pVIUnLyDEto5Qd6v-9v-2qzXKtkMcsZ5ROL4_85jQVID3XdwalE27X0C0IxgYriNeLAwmrgkqIpkFc2kG47J8iZ4wlIA96R6RVMpP5ICz7FIW0yYlw9HKfWmS2C5tJrU3gGH5-JAWvziTP4BD-ChsyV0G97IYVV9qOl67LP837IMpO6WyTeI7r4KhvjJOq9UivN2A5xEtBRqyqNgdg1zt3MQU4rh8gpGhXKHUPhO2gCi36NZ790TbLjqjdon9RdHvUayfQZqyx1g6KC1CraJSZYfmHmJAIQ5mnyCBGksp5_QTGAm9YtOGvJX6-AbXPFKEhLlnOZR_XRK-nFm5PwSbInHXEYBAYcVpAxIGWkQnB_f-HlHlg-MbRZv__jjsrYb8qkc0pCyBals12x-g1BWBfIawwBt-BLBuEDmXsQEl4CCZttICP45BJMlZkxXqyr7-KnuidsR_KTukSazjv3nrhtdpcYh_frtA290EZvMFC4Lkpz0zkY-1qUBlzZSNJCBnf8WgTGqQtmXgJBxc8sdd97s2eVw5DO8G90sH73IDbYaSKEcQ";
    "expires_in" = 86399;
    "token_type" = bearer;
}
2018-07-09 16:03:33.384364+0530 Aglive[1210:840570] Task <096A726E-A48B-4554-B0E4-BB8F64332AD2>.<1230> finished with error - code: -1002
2018-07-09 16:03:33.386106+0530 Aglive[1210:839164] Could not find index for BadgeNo
2018-07-09 16:03:33.386290+0530 Aglive[1210:839164] Could not find index for PropertyName
2018-07-09 16:03:33.386465+0530 Aglive[1210:839164] Could not find index for AutoSync
2018-07-09 16:03:33.387213+0530 Aglive[1210:840662] Task <2BD51798-7A34-487F-A46C-220A8C5D2235>.<1231> finished with error - code: -1002
2018-07-09 16:03:33.388711+0530 Aglive[1210:840570] Task <DB7C779A-8AA7-45B4-8FAA-71BDFE3390BB>.<1232> finished with error - code: -1002
2018-07-09 16:03:33.389939+0530 Aglive[1210:840662] Task <6A8191A1-3288-4FA7-B0D1-AFD8412E0106>.<1233> finished with error - code: -1002
2018-07-09 16:03:33.393131+0530 Aglive[1210:840570] Task <4F6C14E6-2CBF-421F-8834-B69974ECD507>.<1234> finished with error - code: -1002
2018-07-09 16:03:33.396777+0530 Aglive[1210:839164] The FMDatabase <FMDatabase: 0x13ddb5230> is currently in use.
2018-07-09 16:03:33.396872+0530 Aglive[1210:839164] [logging] BUG IN CLIENT OF sqlite3.dylib: illegal multi-threaded access to database connection
2018-07-09 16:03:33.394988+0530 Aglive[1210:840662] Task <284867B7-927C-476D-B811-1C9AA2F41CCD>.<1235> finished with error - code: -1002
(lldb) 

一段时间以来,我一直在努力解决这个问题,但不幸的是,我在Google上找不到对此的任何引用。

0 个答案:

没有答案