日期:2014-05-16  浏览次数:20392 次

FMResult 中管理数据库值得学习的代码

FMResult 中管理数据库值得学习的代码

- (NSDictionary *)resultDict {

    

    int num_cols = sqlite3_data_count(statement.statement);

    

    if (num_cols > 0) {

        NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:num_cols];

        

        int i;

        for (i = 0; i < num_cols; i++) {

            

            const char *col_name = sqlite3_column_name(statement.statement, i);

            

            if (col_name) {

                NSString *colName = [NSString stringWithUTF8String:col_name];

                id value = nil;

                

                // fetch according to type

                switch (sqlite3_column_type(statement.statement, i)) {

                    case SQLITE_INTEGER: {

                        value = [NSNumber numberWithLongLong:[self longLongIntForColumnIndex:i]];

                        break;

                    }

                    case SQLITE_FLOAT: {

                        value = [NSNumber numberWithDouble:[self doubleForColumnIndex:i]];

                        break;

                    }

                    case SQLITE_TEXT: {

          &