在 Xcode 中插入问题
实际上我不确定是否存在问题,但是,我有一些数据,我想将其插入数据库。
代码似乎运行良好,每个语句都有效,没有显示错误,但我看不到数据库中的数据。它不会将数据插入数据库,但在代码中显示为插入数据。
是否有与数据库相关的设置?我正在使用 Sqlite Firefox 插件。 选择记录时没有问题。我检查了 .sqlite 文件的权限,但它设置为读取和读取写。
抱歉,我忘记添加代码片段;
NSString *stmt=[NSString stringWithFormat:@"INSERT INTO t_exam_applies(user_id,exam_id, apply_correct, apply_wrong, apply_empty, apply_start, apply_end) VALUES(%d, %d, %d, %d, %d, %d, %d)", 0,exam_id,0,0,0,0,0];
[stmt UTF8String];
const char *sql=(const char *) [stmt UTF8String];
//const char *sql= "INSERT INTO t_exam_applies(user_id,exam_id, apply_correct, apply_wrong, apply_empty, apply_start, apply_end) VALUES(?,?,?,?,?,?,?)";
sqlite3_stmt *statement;
sqlite3_prepare_v2(database, sql, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
NSLog(@"SQLITE statement executed");
else
NSLog(@"ERROR!!");
sqlite3_finalize(statement);
Actually I am not sure there is a problem but, I have some data and I want to insert it to database.
Code seems to works well, every statement works, there are no errors shown but I cant see the data in database. It doesn't insert the data to database but in code it is shown as data is inserted.
Is there a setting related with database? I am using Sqlite Firefox Add-on.
When selecting records there are no problems. I checked the .sqlite file's permissions but it is setted to read & write.
Sorry, I forgot to add code snippet;
NSString *stmt=[NSString stringWithFormat:@"INSERT INTO t_exam_applies(user_id,exam_id, apply_correct, apply_wrong, apply_empty, apply_start, apply_end) VALUES(%d, %d, %d, %d, %d, %d, %d)", 0,exam_id,0,0,0,0,0];
[stmt UTF8String];
const char *sql=(const char *) [stmt UTF8String];
//const char *sql= "INSERT INTO t_exam_applies(user_id,exam_id, apply_correct, apply_wrong, apply_empty, apply_start, apply_end) VALUES(?,?,?,?,?,?,?)";
sqlite3_stmt *statement;
sqlite3_prepare_v2(database, sql, -1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
NSLog(@"SQLITE statement executed");
else
NSLog(@"ERROR!!");
sqlite3_finalize(statement);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
鉴于这是针对 iPhone 开发的标记,我建议使用 sqlite 的目标 C 包装器,例如 FMDB。 FMDB 非常轻量级且使用广泛(在 github 上查看:https://github.com/ccgus/fmdb/ )并将为您简化整个过程。
以下是使用 FMDB 进行简单插入的示例:
Given that this is tagged for iPhone dev I would recommend using an objective c wrapper for sqlite like FMDB. FMDB is very lightweight and widely used (check it out on github: https://github.com/ccgus/fmdb/) and will simplify this whole process for you.
Here is an example of a simple insert with FMDB:
也许您在添加数据时消息为零(假设您使用 Obj-C)?这不是一个错误,但它也没有做任何事情。更具体的答案需要更多信息或代码片段。
Maybe you are messaging nil when adding the data (assuming you use Obj-C)? That's not an error, but it also doesn't do anything. More info or code snippet needed for more specific answer.