执行此操作时出现数据库锁定错误,请参阅此代码
sqlite3 *database;
NSString * databaseName=[[NSString alloc]initWithString:DBName];
NSArray * documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString * databasePath = [[documentsDir stringByAppendingPathComponent:databaseName] retain];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
int customer_id = [[defaults objectForKey:@"cus_id"] intValue];
BOOL check=[self isContainsJwelIDForOrderGem:@"orderjewelprice_gram" idval:jid user_id:customer_id];
if(!check)
{
NSString *lite=[NSString stringWithFormat:@"insert into orderjewelprice_gram (id, metal_type, classification, gram, price, total_price, wastage, making, cost_price, jID, user_id) select * from jewelprice_gram where jID = %d",jid];
if(Debug)
DLog(@"Insert sqlQuery::%@",lite);
const char *sqlStatement = [lite UTF8String];
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
// Setup the SQL Statement and compile it for faster access
sqlite3_stmt *compiledStatement=nil;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) != SQLITE_OK)
{
if(Debug)
{
DLog(@"not Insert");
DLog(@"HMM, COULDNT RUN QUERY: %s\n", sqlite3_errmsg(database));
}
}
else
{
if (sqlite3_step(compiledStatement) == SQLITE_DONE)
{
//if(Debug)
DLog(@"Inserted successfully");
}
}
NSLog(@"%s",sqlite3_errmsg(database));
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
int user_id;
BOOL isCheck = [self isContainsJwelIDForOrderGem:@"orderjewelprice_gram" idval:jid user_id:0];
if(isCheck)
user_id = 0;
else
user_id = customer_id;
NSString *lite1=[NSString stringWithFormat:@"UPDATE orderjewelprice_gram SET wastage ='%@',making = '%@', price = '%@',user_id = %d where jID = %d and user_id = %d",wastage,making,price,customer_id,jid,user_id];
//if(Debug)
DLog(@"update sqlQuery::%@",lite1);
const char *sqlStatement1 = [lite1 UTF8String];
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
// Setup the SQL Statement and compile it for faster access
sqlite3_stmt *compiledStatement=nil;
if(sqlite3_prepare_v2(database, sqlStatement1, -1, &compiledStatement, NULL) != SQLITE_OK)
{
if(Debug)
{
DLog(@"not updated");
DLog(@"HMM, COULDNT RUN QUERY: %s\n", sqlite3_errmsg(database));
}
}
else
{
if (sqlite3_step(compiledStatement) == SQLITE_DONE)
{
//if(Debug)
DLog(@"updated successfully");
}
}
NSLog(@"%s",sqlite3_errmsg(database));
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
[databaseName release];
[databasePath release];
答案 0 :(得分:0)
您的数据库正确关闭或您的数据库已经打开,以便锁定数据库