为什么dictinary会变为空?

时间:2016-02-11 06:06:30

标签: ios sqlite

我已经将记录插入到数据库中,但我仍然得到空值.....

-(NSMutableArray *)getData
{
readArray = [[NSMutableArray alloc]init];

sqlite3_stmt *statement=nil;

if(sqlite3_open([databasePath UTF8String], &employeeDB)==SQLITE_OK)
{

    NSString *string = @"SELECT Name FROM PEOPLE WHERE salary = (SELECT MAX(salary) FROM PEOPLE  WHERE salary NOT IN (SELECT DISTINCT salary FROM PEOPLE ORDER BY salary DESC LIMIT 1))";

    const char *query =[string UTF8String];
    char *error;

   if(sqlite3_exec (employeeDB, query,NULL,NULL,&error)==SQLITE_OK)
    {
        NSLog(@"Second Max Salary.");

        while (sqlite3_step(statement)==SQLITE_ROW)
        {

            NSMutableDictionary *readDic=[[NSMutableDictionary alloc] init];

            [readDic setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)] forKey:@"Name"];


            [readDic setObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)] forKey:@"Salary"];

            [readArray addObject:readDic];
            NSLog(@"%@ Array",readDic);

        }
    }
    else{
        NSLog(@"Not found.");

    }
    sqlite3_finalize(statement);
}
NSLog(@"%@",readArray);
sqlite3_close(employeeDB);
return readArray;
}

0 个答案:

没有答案