FMDB 结果集包含空 iphone

发布于 2024-10-21 02:02:05 字数 1394 浏览 6 评论 0原文

我的应用程序使用 FMDB 将数据存储在 sqlite 中。这是我

来自 AppDelegate

- (void)applicationDidFinishLaunching:(UIApplication *)application 

{

FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/sql.sqlite"];

if (![db open]) {
    NSLog(@"Could not open db.");

}
NSLog(@"DB opened successfully");

的代码// 此处未显示完整代码

}

我在 ViewController 中有以下代码

-(IBAction)insertButtonClicked:(id)sender

{ NSLog(@"在 insertButtonCLicked 中");

[db beginTransaction];

[db executeUpdate:@"insert into sample (url) values (?)",@"google'"];

[db commit];

2011-03-07

30

07

NSLog(@"in DisplayCLicked");

FMResultSet *rs = [db executeQuery:@"select url from sample"];

NSLog(@"Rs contains => %@",rs);

while( [rs next])
{

    NSLog(@"%@",[rs stringForColumn:@"url"]);
}
[rs close];

:

当我运行此代码时,我得到的 rs 为 null,如下所示(这是来自控制台的 o/p)

2011-03-07 07:30:06.919 InsertDataSample[3092:20b] DB opened successfully

:13.341 InsertDataSample[3092: 20b] 在 insertButtonCLicked

2011-03-07 07:30:16.860 InsertDataSample[3092:20b] 在 DisplayCLicked

2011-03-07 07:30:16.860 InsertDataSample[3092:20b] Rs 包含 => (null)

请朋友们帮助我。我在 FMDB 上工作了很多天,但我无法使用 FMDB 。 提前致谢

I am using FMDB for my application to store data in sqlite. Here is my code

from AppDelegate

- (void)applicationDidFinishLaunching:(UIApplication *)application 

{

FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/sql.sqlite"];

if (![db open]) {
    NSLog(@"Could not open db.");

}
NSLog(@"DB opened successfully");

// full code not shown here

}

I have following code in ViewController

-(IBAction)insertButtonClicked:(id)sender

{
NSLog(@"in insertButtonCLicked");

[db beginTransaction];

[db executeUpdate:@"insert into sample (url) values (?)",@"google'"];

[db commit];

}

-(IBAction)displayButtonClicked:(id)sender

{

NSLog(@"in DisplayCLicked");

FMResultSet *rs = [db executeQuery:@"select url from sample"];

NSLog(@"Rs contains => %@",rs);

while( [rs next])
{

    NSLog(@"%@",[rs stringForColumn:@"url"]);
}
[rs close];

}

When i run this code i get rs as null as shown in following (this is o/p from console)

2011-03-07 07:30:06.919 InsertDataSample[3092:20b] DB opened successfully

2011-03-07 07:30:13.341 InsertDataSample[3092:20b] in insertButtonCLicked

2011-03-07 07:30:16.860 InsertDataSample[3092:20b] in DisplayCLicked

2011-03-07 07:30:16.860 InsertDataSample[3092:20b] Rs contains => (null)

Plz help me friends. I am working on FMDB from many days but i am unable to use FMDB .
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

圈圈圆圆圈圈 2024-10-28 02:02:05

在您的查询之后插入此内容,FMDB 可能会准确地告诉您问题所在。

if ([db hadError]) {
    NSLog(@"DB Error %d: %@", [db lastErrorCode], [db lastErrorMessage]);
}

更新:

运行此:

FMDatabase *db = [FMDatabase databaseWithPath:@"/tmp/sql.sqlite"];
[db executeUpdate:@"create table sample (url TEXT);"];
[db executeUpdate:@"insert into sample (url) values(?);", @"google'"];
FMResultSet *rs = [db executeQuery:@"select url from sample;"];
while ([rs next]) {
    NSLog(@"%@", [rs stringForColumn:@"url"]);
}
[rs close];
[db close];

产生以下输出:

2011-03-06 12:38:59.831 test[93163:207] google'

Insert this just after your query and FMDB will probably tell you exactly what the problem is.

if ([db hadError]) {
    NSLog(@"DB Error %d: %@", [db lastErrorCode], [db lastErrorMessage]);
}

Update:

Running this:

FMDatabase *db = [FMDatabase databaseWithPath:@"/tmp/sql.sqlite"];
[db executeUpdate:@"create table sample (url TEXT);"];
[db executeUpdate:@"insert into sample (url) values(?);", @"google'"];
FMResultSet *rs = [db executeQuery:@"select url from sample;"];
while ([rs next]) {
    NSLog(@"%@", [rs stringForColumn:@"url"]);
}
[rs close];
[db close];

produced this output:

2011-03-06 12:38:59.831 test[93163:207] google'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文