FMDB 结果集包含空 iphone
我的应用程序使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的查询之后插入此内容,FMDB 可能会准确地告诉您问题所在。
更新:
运行此:
产生以下输出:
Insert this just after your query and FMDB will probably tell you exactly what the problem is.
Update:
Running this:
produced this output: