gpt4 book ai didi

iphone - 从iPhone的sqlite读取单引号编码问题

转载 作者:行者123 更新时间:2023-12-03 18:19:35 25 4
gpt4 key购买 nike

我已经为iPhone创建了一个SQLite数据库来存储我的数据(字符串)。
我有一些包含'单引号的数据(即不要紧张)。
这是使用SQLite的常规转义符插入数据库的。


INSERT INTO todo(test) VALUES('don''t be tense');


在终端中选择数据时,可以在记录中看到单引号。


don't be tense


我的问题是当我读取记录时,NSLog中没有单引号:


dont be tense


这是在该字段中读取的调用:


self.text = [NSString stringWIthUTF8String:(char *)sqlite3_column_text(init_statement, 1)];
NSLog(@"%@",self.translation);


我非常感谢您提供有关如何确保引用内容的帮助。

以下是完整的代码(如果有帮助的话):

static sqlite3_stmt *init_statement = nil;

@implementation Todo
@synthesize primaryKey,text;

- (id)initWithPrimaryKey:(NSInteger)pk database:(sqlite3 *)db {

if (self = [super init]) {
primaryKey = pk;
database = db;
// Compile the query for retrieving book data. See insertNewBookIntoDatabase: for more detail.
if (init_statement == nil) {
// Note the '?' at the end of the query. This is a parameter which can be replaced by a bound variable.
// This is a great way to optimize because frequently used queries can be compiled once, then with each
// use new variable values can be bound to placeholders.
const char *sql = "SELECT text FROM todo WHERE pk=?";
if (sqlite3_prepare_v2(database, sql, -1, &init_statement, NULL) != SQLITE_OK) {
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
}
// For this query, we bind the primary key to the first (and only) placeholder in the statement.
// Note that the parameters are numbered from 1, not from 0.
sqlite3_bind_int(init_statement, 1, primaryKey);
if (sqlite3_step(init_statement) == SQLITE_ROW) {
self.text = [NSString stringWithUTF8String:(char *)sqlite3_column_text(init_statement, 0)];
NSLog(@"%@",self.text);
} else {
self.text = @"Nothing";
}
// Reset the statement for future reuse.
sqlite3_reset(init_statement);
}
return self;
}

最佳答案

我修好了它。
似乎在更新数据库时,我并没有从模拟器中删除旧数据库,因此它一直在测试旧数据。愚蠢的错误!
因此,从SQLite中读取单引号没有问题(可能是为什么我永远找不到有关它的信息)。
感谢那些阅读并尝试提供帮助的人!

关于iphone - 从iPhone的sqlite读取单引号编码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4339021/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com