views:

404

answers:

2

Hi Everyone,

I am in the process of learning Objective-C for Mac/iPhone development and decided to try and write something useful without looking at the bible (Aaron Hillegass: Cocoa Programming 3rd Edition).

I'm writing a simple puzzle game. The data that defines the levels is stored as a string in a SQLite database and read into a level object with this line of code:

tempLevel.levelData = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];

I have two other lines that read in other properties from the database (integers this time, not strings) and they work fine so I am wondering if anyone can help me with the problem.

When this line of code executes I get the following error: *** +[NSString stringWithUTF8String:]: NULL cString

I would greatly appreciate any help you can give. If you need any more information I would be glad to provide it.

Thanks!

+2  A: 

Not really an answer, but there's no good reason to deal with sqlite directly when there are some great wrappers available:

http://cocoaheads.byu.edu/resources/sqlite

Dave DeLong
There are two reasons for not using a wrapper. Firstly there are quite a few it seems and I have no idea which are good or bad and it is depending on code that I haven't written which is annoying. Also I thought that database access was a fairly necessary skill in any language so I thought it a good idea to learn it for Objective-C. I might try a wrapper.
danpalmer
it's not so much good or bad code as it is about what is basically boilerplate code for sqlite. it's been done so many times that redoing it yourself will take a lot more time than just finding a decent wrapper so you can focus on your app and sql.
pxl
+1  A: 

Most likely it is an error in compiledStatement. As a general point, you should check that you get an actual value from sqlite3_column_text first, since getting back NULL is often the "correct" response to what you ask for.

Gordon Worley
The compiled statement is very simple and works for the other two pieces of data I am retrieving. In column 1 there is string data so therefore it should be returned if the other data is returned. It wouldn't make sense for one part of a record to be returned but not others.
danpalmer
Regardless, if the problem is not with `compiledStatement`, then it simply lies somewhere else in your call. You're sure that there's a string in column 1? Have you checked the database using `sqlite3` in the Terminal? If it is there, then I think we're going to need to see more code, since it's likely something else with the sqlite3 context.
Gordon Worley