+1  A: 

Are you sure that any of your SQLite calls are successful? You should initialize result to nil so that your function returns nil if any errors are caught.

Three (probably related) issues with your code:

  1. The index to sqlite3_column_text should be zero-based; you're passing 2, which should refer to the third column. You probably mean to pass 1. From the docs:

    ...the second argument is the index of the column for which information should be returned. The leftmost column of the result set has the index 0.

  2. You really shouldn't use SELECT *. Specify the columns you want!

  3. You should specialize your query by binding values, not by concatenating strings! Your code is rife with the possibility of SQL injections (not to mention incorrect queries).

For example (with no error checking):

const char *query = "SELECT * FROM ? WHERE ?=?";
sqlite3_stmt *compiledQuery;
sqlite3_prepare_v2(database, query, -1, &compiledQuery, NULL);
sqlite3_bind_text(compiledQuery, 1, "Lessons", -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledQuery, 2, "Chrono", -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledQuery, 3, "0001", -1, SQLITE_TRANSIENT);

Note that the index here is 1-based (I don't know why they do that). From the docs:

The second argument is the index of the SQL parameter to be set. The leftmost SQL parameter has an index of 1.

Jesse Beder
Thanks for the quick reply! I actually found an alternative way to write the code, but I am def going to try yours. It had to do with the type of string encoding I was using.
Dick Savagewood
A: 

Haha whoops I realized that I was just displaying the string as a data format by using the %d string format. when i changed it to %@ i got the string format

Dick Savagewood