gpt4 book ai didi

iphone - 不在 SQLite 中保存数据

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:50:46 27 4
gpt4 key购买 nike

一切都在代码中进行,但不在 SQLite 数据库中保存数据。有人可以帮忙吗?

在下面找到我的代码:

-(IBAction)signin:(id)sender{
NSLog(@"%@",perDas.string1);
nameString=[[NSString alloc]initWithString:perDas.string1];
statusString=[[NSString alloc]initWithFormat:@"IN"];
{
NSLog(@"passed");
sqlite3_stmt *statement;

const char *dbpath = [perDas.databasePath UTF8String];

if (sqlite3_open(dbpath, &database) == SQLITE_OK)
{
NSLog(@"pass");
NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO status VALUES (\"%@\", \"%@\", datetime(), \"%@\")", nameString, statusString,empString];
NSLog(@"%@",insertSQL);
const char *insert_stmt = [insertSQL UTF8String];

sqlite3_prepare_v2(database, insert_stmt, -1, &statement, NULL);

sqlite3_finalize(statement);
sqlite3_close(database);

}
}}

提前致谢

最佳答案

-(IBAction)signin:(id)sender{
NSArray *dirPath;
NSString *docDir;
NSString *databasePath;

dirPath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docDir=[dirPath objectAtIndex:0];
databasePath=[docDir stringByAppendingPathComponent:@"YourDB.sql"];

const char *dbPath=[databasePath UTF8String];

if(sqlite3_open(dbPath, &db)==SQLITE_OK)
{

NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO status VALUES (\"%@\", \"%@\", datetime(), \"%@\")", nameString, statusString,empString];


const char *insertStmt=[insertSQL UTF8String];

char *errmsg=nil;

if(sqlite3_exec(db, insertStmt, NULL, NULL, &errmsg)==SQLITE_OK)
{
NSLog(@"ADDED!");
}

sqlite3_close(db);
}
}

关于iphone - 不在 SQLite 中保存数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11049363/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com