我正在将带有文本的坐标值插入数据库。当我从数据库中检索值时,它没有得到。我使用 NSLog 检索值,但 nslog 坐标值为 0。getmainsql is SELECT textnotes,text_id,txcoor,tycoor FROM textnote where text_id = '159' AND txcoor = '0.000000' AND tycoor = '0.000000'
插入:
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
const char *sql = [[NSString stringWithFormat:@"SELECT textnotes,text_id,txcoor,tycoor FROM textnote where textnotes = '%@' AND text_id = '%@' AND txcoor = '%f' AND tycoor = '%f'",txtview.text,artID,xcor,ycor] cStringUsingEncoding:NSUTF8StringEncoding];
NSLog(@"sql is %s",sql);
BOOL favExist = false;
sqlite3_stmt *statement, *addStmt;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
// We "step" through the results - once for each row.
while (sqlite3_step(statement) == SQLITE_ROW) {
favExist = true;
}
}
if(!favExist){
const char *sqlInsert = [[NSString stringWithFormat:@"insert into textnote (textnotes,text_id,txcoor,tycoor ) values ('%@','%@','%f','%f')", txtview.text,artID,xcor,ycor] cStringUsingEncoding:NSUTF8StringEncoding];
NSLog(@"sql insert is %s",sqlInsert);
// [catID release];
if(sqlite3_prepare_v2(database, sqlInsert, -1, &addStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
if(SQLITE_DONE != sqlite3_step(addStmt))
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
.h 文件:
@property(nonatomic) float a;
@property(nonatomic) float b;
获取价值:
const char *sql = [[NSString stringWithFormat:@"SELECT textnotes,text_id,txcoor,tycoor FROM textnote where text_id = '%@' AND txcoor = '%f' AND tycoor = '%f'",artID,a,b] cStringUsingEncoding:NSUTF8StringEncoding];
NSLog(@"getmainsql is %s",sql);
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
// We "step" through the results - once for each row.
while (sqlite3_step(statement) == SQLITE_ROW) {
xff=sqlite3_column_double(statement, 2);
yff=sqlite3_column_double(statement, 3);
art_Id = sqlite3_column_int(statement, 1);
NSLog(@"xff is %f",xff);
NSLog(@"yff is %f",yff);
// NSLog(@"zc is %@",zc);
NSLog(@"art_Id is %ld",(long)art_Id);