iphone sdk(fmdb 包装器)中的 SQLITE 错误

Posted

技术标签:

【中文标题】iphone sdk(fmdb 包装器)中的 SQLITE 错误【英文标题】:SQLITE ERROR IN iphone sdk (fmdb wrapper) 【发布时间】:2012-01-06 08:50:13 【问题描述】:

我在 sqlite 包装方法中遇到问题..我已经定义了以下函数及其显示错误..我无法解决它。所有我都试图做它交换数据库中的行。它在只有 sql 语句的 sqlite 管理器(firefox 插件)中工作正常。但这里它显示一个错误,所以我假设我定义函数的方式可能是错误的..有人可以对这个问题稍微了解一下,所以它有帮助吗?

提前致谢

// 这就是我在 DB 中定义函数的方式

-(NSMutableArray*)extractActivitytest:(int)pri

    [db beginTransaction];
NSString* tSqlString = [NSString stringWithFormat:@"select Activity_Name from Activity where Priority = %d", pri];
FMResultSet *tRecordSet = (FMResultSet*)[db executeQuery:tSqlString];
NSMutableArray *rowArray = [[NSMutableArray alloc] init];
   while ([tRecordSet next])


    [rowArray addObject:[tRecordSet stringForColumn:COLUMN_ACT]];


return [rowArray autorelease];
[db commit];

/// 我是这样称呼它的

 [long1  setTitle:[[[DBManager getInstance]extractActivitytest:1] objectAtIndex:0]  forState:UIControlStateNormal];
[long2  setTitle:[[[DBManager getInstance]extractActivitytest:2] objectAtIndex:0]forState:UIControlStateNormal];
[long3  setTitle:[[[DBManager getInstance]extractActivitytest:3] objectAtIndex:0] forState:UIControlStateNormal];
[long4  setTitle:[[[DBManager getInstance]extractActivitytest:4] objectAtIndex:0]forState:UIControlStateNormal];
[long5  setTitle:[[[DBManager getInstance]extractActivitytest:5] objectAtIndex:0] forState:UIControlStateNormal];
[long6  setTitle:[[[DBManager getInstance]extractActivitytest:6] objectAtIndex:0] forState:UIControlStateNormal];

//这是我得到的错误

2012-01-06 14:03:20.387 MyDaily6[5657:207] Path= /Users/rega/Library/Application       Support/iPhone Simulator/4.3.2/Applications/5A554560-A01A-4F44-980E-CC200E037CFE/Documents/Goals.sqlite
2012-01-06 14:03:22.490 MyDaily6[5657:207] Error calling sqlite3_step (1: SQL logic error or missing database) SQLITE_ERROR
2012-01-06 14:03:22.491 MyDaily6[5657:207] DB Query: BEGIN EXCLUSIVE TRANSACTION;
2012-01-06 14:03:22.491 MyDaily6[5657:207] Error calling sqlite3_step (1: SQL logic     error or missing database) SQLITE_ERROR
2012-01-06 14:03:22.492 MyDaily6[5657:207] DB Query: BEGIN EXCLUSIVE TRANSACTION;
2012-01-06 14:03:22.492 MyDaily6[5657:207] Error calling sqlite3_step (1: SQL logic error or missing database) SQLITE_ERROR
2012-01-06 14:03:22.493 MyDaily6[5657:207] DB Query: BEGIN EXCLUSIVE TRANSACTION;
2012-01-06 14:03:22.493 MyDaily6[5657:207] Error calling sqlite3_step (1: SQL logic error or missing database) SQLITE_ERROR
2012-01-06 14:03:22.494 MyDaily6[5657:207] DB Query: BEGIN EXCLUSIVE TRANSACTION;
2012-01-06 14:03:22.494 MyDaily6[5657:207] Error calling sqlite3_step (1: SQL logic error or missing database) SQLITE_ERROR
2012-01-06 14:03:22.495 MyDaily6[5657:207] DB Query: BEGIN EXCLUSIVE TRANSACTION;

/// 另一个类似的函数给出相同的错误

-(void)moveupData:(int)value1:(int)value2

NSString *stringSQL = [NSString stringWithFormat:@" UPDATE Activity SET Priority = (CASE WHEN Priority = %d THEN %d WHEN Priority = %d THEN %d END) WHERE Priority IN (%d,%d)", value1, value2];
[db executeQuery:stringSQL];
[db commit];

// 这就是我的调用方式

[[DBManager getInstance]moveupData:moveUp :moveDown];

// 我得到的错误

 MOVEDOWN = 42012-01-06 14:03:34.932 MyDaily6[5657:207] Error calling sqlite3_step (1: SQL logic error or missing database) SQLITE_ERROR
2012-01-06 14:03:34.933 MyDaily6[5657:207] DB Query: COMMIT TRANSACTION;

【问题讨论】:

【参考方案1】:

你确定你的数据库是打开的吗?你应该打电话

[db open]

而且,对于第二部分,如果你想写入数据库,你应该使用

[db executeUpdate:stringSQL];

希望对你有帮助!

【讨论】:

您能告诉我们问题出在哪里吗?你是怎么想出来的?

以上是关于iphone sdk(fmdb 包装器)中的 SQLITE 错误的主要内容,如果未能解决你的问题,请参考以下文章

FMDB 如何让 sqlite 更简单 iOS?

FMDB:错误 14,无法打开数据库文件

如何使用 iphone sdk 中的 corePlot 库将 CPTAxisLabel 包装成两行?

来自 Sqlite (FMDB) 的 UITableView 中的部分和索引

如何在 FMDB 中的两个表之间创建或稳定关系?

Iphone 单元测试:使用 SQL