android sqlite 单引号,从sqlite for iPhone读取单引号编码问题

我为iPhone创建了一个SQLite数据库来存储我的数据(字符串)。

我有一些包含'单引号的数据(即不要紧张)。

使用SQLite的正常''转义将其插入到数据库中。

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

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

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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值