[objective-c]EGODatabase #9 カラムの型一覧取得

カラムの型一覧取得

-(EGODatabase*)getDB
{
    EGODatabase* database = [EGODatabase databaseWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/database.db"]];
    return database;
}
-(NSDictionary*)getColumnTypesByTableName:(NSString*)tableName
{
    EGODatabase*db=[self getDB];
    NSString*sql=[NSString stringWithFormat:@"pragma table_info(%@)",tableName];
    EGODatabaseResult*result=[db executeQuery:sql];
    NSMutableDictionary*dic=[NSMutableDictionary dictionary];
    for (EGODatabaseRow*row in result) {
        [dic setObject:[row stringForColumn:@"type"] forKey:[row stringForColumn:@"name"]];
    }
    return dic;
}