//这里创建数据库
-(void) createDataBase
{
docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
fullPath = [docPath stringByAppendingPathComponent:@"Recording.sqlite"];
sqlite3_open([fullPath UTF8String], &dbForEmf);
}
// create table
-(void) createTable
{
if (sqlite3_open([fullPath UTF8String], &dbForE) == SQLITE_OK)
{
const char* createQuery = "CREATE TABLE IF NOT EXISTS EEE(E_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, E_NAME TEXT,E_READING TEXT,E_DATE TEXT,E_SIZE TEXT,E_LABLE TEXT)";
int errorCode = sqlite3_prepare(dbForE, createQuery, -1, &prepareStmt, NULL);
if (errorCode == 0) {
sqlite3_step(prepareStmt);
}
else
{
}
sqlite3_finalize(prepareStmt);
sqlite3_close(dbForE);
}
else
{
NSLog(@"data base not Open");
}
}
// insert data here
-(void) insertData
{
if (sqlite3_open([fullPath UTF8String], &dbForE)==SQLITE_OK)
{
NSString *insertSql = [NSString stringWithFormat:@"INSERT INTO EEE(E_NAME,E_READING,E_DATE,E_SIZE,E_LABLE) VALUES('%@','%@','%@','%@','%@')",_referenceObject.lastFilePath,_referenceObject.fileString,_referenceObject.dateString,_referenceObject.fileSizeString,_referenceObject.titleOfButtonString];
const char *insert_stmt=[insertSql UTF8String];
sqlite3_prepare_v2(dbForE,insert_stmt,-1,&prepareStmt,NULL);
sqlite3_reset(prepareStmt);
if (sqlite3_step(prepareStmt)==SQLITE_DONE)
{
NSLog(@"inserted the values in table");
}
else
{
NSLog(@" not inserted the values in table");
NSLog(@"error: %s", sqlite3_errmsg(dbForE));
}
sqlite3_finalize(prepareStmt);
sqlite3_close(dbForE);
}
}
当我转到第二个 viewController 并返回到第一个 viewController 时,hai 数据会插入到第一个 viewController 上,数据未插入错误显示数据库已锁定...