加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 如何调用sqlite3_errmsg来了解sqlite3_prepare_v2失败的

发布时间:2020-12-14 17:40:44 所属栏目:百科 来源:网络整理
导读:基于C的函数sqlite3_prepare_v2返回1.我只想知道可读形式的错误消息并更正我的代码.我正在学习这个作为raywinderlich博客的教程.我遇到过sqlite3_errmsg,我不知道如何使用sqlite3_errmsg函数. 虽然here问了同样的问题,但遗憾的是仍然没有答案. 我想知道错误
基于C的函数sqlite3_prepare_v2返回1.我只想知道可读形式的错误消息并更正我的代码.我正在学习这个作为raywinderlich博客的教程.我遇到过sqlite3_errmsg,我不知道如何使用sqlite3_errmsg函数.

虽然here问了同样的问题,但遗憾的是仍然没有答案.

我想知道错误和纠正将非常感激.谢谢.

- (NSArray *)failedBankInfos {
    NSMutableArray *retval = [[NSMutableArray alloc]init];
    NSString *query = @"SELECT id,name,city,state FROM failed_banks ORDER BY close_date DESC";
    sqlite3_stmt *statement;
    int tmp  = sqlite3_prepare_v2(_database,[query UTF8String],-1,&statement,nil);
    NSLog(@"%i",tmp); // printing 1
    if (sqlite3_prepare_v2(_database,nil)
        == SQLITE_OK) {
        while (sqlite3_step(statement) == SQLITE_ROW) {
            int uniqueId = sqlite3_column_int(statement,0);
            char *nameChars = (char *) sqlite3_column_text(statement,1);
            char *cityChars = (char *) sqlite3_column_text(statement,2);
            char *stateChars = (char *) sqlite3_column_text(statement,3);

            NSString *name = [[NSString alloc] initWithUTF8String:nameChars];
            NSString *city = [[NSString alloc] initWithUTF8String:cityChars];
            NSString *state = [[NSString alloc] initWithUTF8String:stateChars];
            NSLog(@"name is  : %@",name);
             NSLog(@"city is : %@",city);
            FailedBankInfo *info = [[FailedBankInfo alloc]
                                    initWithUniqueId:uniqueId name:name city:city state:state];
            [retval addObject:info];
        }
        sqlite3_finalize(statement);
    }
    else
    {
        // if part is failing and control is arriving in else.
    }
    return retval;

}

解决方法

您可以使用sqlite3_errmsg(),如:

NSLog(@"Database Error Message : %s",sqlite3_errmsg(_database));

您也可以使用sqlite3_errstr().

The sqlite3_errmsg() and sqlite3_errmsg16() return English-language
text that describes the error,as either UTF-8 or UTF-16 respectively.
Memory to hold the error message string is managed internally. The
application does not need to worry about freeing the result. However,
the error string might be overwritten or deallocated by subsequent
calls to other SQLite interface functions.

The sqlite3_errstr() interface returns the English-language text that
describes the result code,as UTF-8. Memory to hold the error message
string is managed internally and must not be freed by the application.

参考SQLite Error Messages

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读