0

我在 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;
4

1 回答 1

1

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

[db open]

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

[db executeUpdate:stringSQL];

希望能帮助到你!

于 2012-01-24T14:00:29.590 回答