テキストを含む座標値をデータベースに挿入しています。データベースから値を取得すると、値が取得されません。値の取得に 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);