아이폰 개발할때 sqlite3의 테이블 동적 변경하는 소스

- (id)initWithPrimaryKey:(NSInteger)pk database:(sqlite3 *)db tableName:(NSString *)tn { if ( (self = [super init]) ) 
 { primaryKey = pk; database = db; tableName = tn; // Compile the query for retrieving travel bug data. See insertIntoDatabase: 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. strInit = [NSString stringWithFormat:@"SELECT name FROM %@ WHERE pk=?", self.tableName]; const char *sql = [strInit UTF8String]; 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.name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(init_statement, 0)]; } else { self.name = @"Unknown"; } // Reset the statement for future reuse. sqlite3_reset(init_statement); dirty = NO;
 } return self; }



출처 : http://blog.naver.com/PostList.nhn?blogId=philipousys¤tPage=18
Posted by 오늘마감

댓글을 달아 주세요