My database is defined as the following
CREATE TABLE [problems] (
[p_id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
[problem_name] VARCHAR(255) NOT NULL,
[mixed_t1] INT NOT NULL,
[mixed_t2] INT NOT NULL,
[mixed_flair] INT,
[mixed_gre] INT,
[mixed_diffusion] INT,
[mixed_adc] INT,
[fat_sat_post_t1] INT)
In my code, I'm trying to run an SQL query that looks like
SELECT problem_name from problems W开发者_StackOverflow中文版HERE mixed_t1=0
Then in code, I'm trying to assign the problem_name to a NSString and then add the NSString to an NUSMutableArray
if(sqlite3_step(statement) == SQLITE_ROW)
{
NSString *problemName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
[dataSet addObject:problemName];
[problemName release];
}
The problem is that I'm crashing at NSString *problemName
I get the following crash message
Current language: auto; currently objective-c
2011-02-08 08:54:29.035 RadAppz[1332:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithUTF8String:]: NULL cString'
* Call stack at first throw:
I know I'm getting data because executing the RAW SQL in Terminal returns 2 rows. Can someone please tell me why the data is being returned as NULL?
Your problem, I believe, is that you are checking for the second column, not the first. Note that the definition for sqlite3_column_text states that the leftmost column is column 0.
http://www.sqlite.org/capi3ref.html#sqlite3_column_blob
精彩评论