SQLite insert error in iOS - iphone

I'm trying to do an insert statement with SQLite and I'm sure I must be doing something stupid, but I can't figure out how to get it to work.
The error I'm getting is: "Error preparing statement"
Here's my code:
NSString *json_string = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
// Create new SBJSON parser object
SBJsonParser *parser = [[SBJsonParser alloc] init];
// parse the JSON response into an object
NSDictionary *download = [parser objectWithString:json_string error:nil];
NSDictionary *buildings = [download objectForKey:#"buildings"];
// Open DB
sqlite3 *db = [RLSampleAppDelegate getNewDBConnection];
// Buildings
for (NSDictionary *building in buildings)
{
NSDictionary *thisbuilding = [building objectForKey:#"building"];
NSLog(#"%#", [thisbuilding objectForKey:#"buildingname"]);
sqlite3_stmt *statement = nil;
NSString* someString = [NSString stringWithFormat:#"INSERT INTO building (buildingid, buildingname) VALUES (\'%#\', \'%#\')", [thisbuilding objectForKey:#"buildingid"], [thisbuilding objectForKey:#"buildingname"]];
NSLog(#"somestring: %#", someString);
const char *sql = (const char *) someString;
if(sqlite3_prepare_v2(db, sql, -1, &statement, NULL)!=SQLITE_OK)
NSAssert1(0,#"Error preparing statement",sqlite3_errmsg(db));
while(sqlite3_step(statement) == SQLITE_DONE){}
sqlite3_finalize(statement);
}
[json_string release];

You can't use a NSString instance in the SQLite3 API. You need a pure C string.
So, try changing this:
const char *sql = (const char *) someString;
Into:
const char *sql = [someString cStringUsingEncoding:[NSString defaultCStringEncoding]];

Try this:
sqlite3_prepare_v2(db, [someString UTF8String], -1, &statement, nil)

First you need sure that you get database file from Document or Library folder of simulator. Because you can not insert databases stored in the app resources. And try my code.
NSString *json_string = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
// Create new SBJSON parser object
SBJsonParser *parser = [[SBJsonParser alloc] init];
// parse the JSON response into an object
NSDictionary *download = [parser objectWithString:json_string error:nil];
NSDictionary *buildings = [download objectForKey:#"buildings"];
// Open DB
sqlite3 *db = [RLSampleAppDelegate getNewDBConnection];
// Buildings
for (NSDictionary *building in buildings)
{
NSDictionary *thisbuilding = [building objectForKey:#"building"];
NSLog(#"%#", [thisbuilding objectForKey:#"buildingname"]);
NSString* someString = [NSString stringWithFormat:#"INSERT INTO building (buildingid, buildingname) VALUES ('%#','%#')", [thisbuilding objectForKey:#"buildingid"], [thisbuilding objectForKey:#"buildingname"]];
const char *sql = [someString UTF8String];
char *error;
if (sqlite3_exec(db, sql, NULL, NULL, &error)==SQLITE_OK) {
NSLog(#"insert success.");
}
}
[json_string release];

Related

Error while converting NSData to NSDictionary using NSKeyedUnarchiver

I want to archive and Unarchive data which contains NSDictionary object. Crash is observed while Unarchiving data. Please find the code and error below,
Archive:
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:mydictobject];
Unarchiving:
NSData *Objdata = [[NSData alloc] initWithBytes:sqlite3_column_blob(statement, 2)
length:sqlite3_column_bytes(statement, 2)];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc]
initForReadingWithData:Objdata];
NSDictionary *dict = [NSDictionary dictionaryWithDictionary:
[NSKeyedUnarchiver unarchiveObjectWithData:Objdata]];
[dict objectForKey:#"key1"];
Error:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' -[NSKeyedUnarchiver initForReadingWithData:]: incomprehensible archive (0xfffffff8, 0xffffffc7, 0xf, 0x1, 0x2, 0x0, 0x0, 0x0)'
** First throw call stack:
(0x222b012 0x194e7e 0x222adeb 0xe78c90 0xe7f2 0x3c11 0x19256 0x43f8d5 0x43fb3d 0xe46e83 0x21ea376 0x21e9e06 0x21d1a82 0x21d0f44 0x21d0e1b 0x21857e3 0x2185668 0x39065c 0x2612 0x2545 0x1)
libc++abi.dylib: terminate called throwing an exception
Thanks.
// To read data do following
-(void) readAnimalsFromDatabase {
// Setup the database object
sqlite3 *database;
// Init the animals Array
dataArray = [[NSMutableArray alloc] init];
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "select * from anyTable";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSString *aImageUrl = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:aName, #"name", aDescription, #"description", aImageUrl, #"imageURL", nil];
// Add the animal object to the animals Array
[dataArray addObject:dict];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
// Archive NSArray to NSData
NSData *archiveData = [NSKeyedArchiver archivedDataWithRootObject:dataArray];
// UnArchive NSData to NSDictionary
NSArray *array = [NSArray arrayWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:data]];
NSLog(#"%#",array);
}

send many NSURLConnection requests and get response in connectionDidFinishLoading

I'm trying to send many asynchronous request to php file that shows my data as json code and in the response I parse the json so I added the following in ViewDidload:
NSURLRequest *aboutRequest = [self getDataFromServer:#"http://al-awal.com/Rashad/iPhonePhp/about.php"];
aboutConn = [[NSURLConnection alloc] initWithRequest:aboutRequest delegate:self];
NSURLRequest *wisdomRequest = [self getDataFromServer:#"http://al-awal.com/Rashad/iPhonePhp/wisdomtoday.php"];
wisdomConn = [[NSURLConnection alloc] initWithRequest:wisdomRequest delegate:self];
then
-(NSURLRequest *) getDataFromServer:(NSString *)phpUrl{
responseData = [NSMutableData data];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:phpUrl]];
return request;
}
then I added:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
sqlite3 *database;
if(sqlite3_open([[rashadDB databasePath] UTF8String], &database) == SQLITE_OK) {
if (connection == aboutConn) {
NSLog(#"get from table about");
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSString *json_string = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSArray *statuses = [parser objectWithString:json_string error:nil];
for (NSDictionary *status in statuses)
{
NSString *sAboutID = [status objectForKey:#"ID"];
NSString *sPhone1 = [status objectForKey:#"Phone1"];
NSString *sPhone2 = [status objectForKey:#"Phone2"];
NSString *sJawal = [status objectForKey:#"Jawal"];
NSString *sFax = [status objectForKey:#"Fax"];
NSString *sWebSite = [status objectForKey:#"WebSite"];
NSString *sEmail = [status objectForKey:#"Email"];
NSString *sAddress = [status objectForKey:#"Address"];
int sAboutID2 = [sAboutID intValue];
NSLog(#"in server, aboutID = %d, Phone1 = %#, Phone2 = %#, Jawal = %#, Fax = %#, WebSite = %#, Email = %#, Address = %#",sAboutID2, sPhone1, sPhone2, sJawal, sFax, sWebSite, sEmail, sAddress);
sqlite3_exec(database, [[NSString stringWithFormat:#"INSERT OR ABORT INTO About VALUES(%d, '%#', '%#', '%#', '%#', '%#', '%#', '%#')",sAboutID2, sPhone1, sPhone2, sJawal, sFax, sWebSite, sEmail, sAddress] UTF8String], NULL, NULL, NULL);
sqlite3_exec(database, [[NSString stringWithFormat:#"UPDATE About set Phone1 = '%#', Phone2 = '%#', Jawal = '%#', Fax = '%#', WebSite = '%#', Email = '%#', Address = '%#' Where aboutID = %d", sPhone1, sPhone2, sJawal, sFax, sWebSite, sEmail, sAddress, sAboutID2] UTF8String], NULL, NULL, NULL);
}
} else if (connection == wisdomConn) {
NSLog(#"get from table wisdoms");
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSString *json_string = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSArray *statuses = [parser objectWithString:json_string error:nil];
for (NSDictionary *status in statuses)
{
NSString *sWisdomTodayID = [status objectForKey:#"ID"];
NSString *sContent = [status objectForKey:#"Content"];
NSString *sAuthorName = [status objectForKey:#"AuthorName"];
NSString *sDateCreate = [status objectForKey:#"DateCreate"];
NSString *sEnable = [status objectForKey:#"Enable"];
int sWisdomTodayID2 = [sWisdomTodayID intValue];
int sEnable2 = [sEnable intValue];
NSLog(#"wisdomTodayID = %#, Content = '%#', AuthorName = '%#', DateCreate = '%#', Enable = %#", sWisdomTodayID, sContent, sAuthorName, sDateCreate, sEnable);
sqlite3_exec(database, [[NSString stringWithFormat:#"INSERT OR ABORT INTO WisdomToday VALUES(%d, '%#', '%#', '%#', %d)",sWisdomTodayID2, sContent, sAuthorName, sDateCreate, sEnable2] UTF8String], NULL, NULL, NULL);
sqlite3_exec(database, [[NSString stringWithFormat:#"UPDATE WisdomToday set Content = '%#', AuthorName = '%#', DateCreate = '%#', Enable = %d Where wisdomTodayID = %d", sContent, sAuthorName, sDateCreate, sEnable2, sWisdomTodayID2] UTF8String], NULL, NULL, NULL);
}
}
} // sqlite3 open end
sqlite3_close(database);
}
the first if condition --> if(connection == aboutConn) works ok with me and I got my output but the other if condition --> if (connection == wisdomConn) only gives me this output NSLog(#"get from table wisdoms"); and not go throw the for loop.
Is there are any wrong in my code?
You are not closing braces properly...
Before opening the brace for else - if condition you should close the brace for if_condition..
Some of your relevant code is missing (the NSConnectionDataDelegate methods). But it would seem that you are using one instance variable, responseData, to build up both return values. This would mean that some times you would get the faster response data only; and other times you would get mixed data in the same NSMutableData object.

Arabic string in NSMutableArray or NSMutableDictionary

I have a problem when I add an arabic string to NSMutableArray or NSMutableDictionary.
Example:
NSMutableDictionary *data = [[NSMutableDictionary alloc]init];
[data setObject:#"فرسان" forKey:#"name"];
NSLog(#"%#",data);
Output:
2012-01-18 21:55:05.646 aa[367:207] {
name = "\U0641\U0631\U0633\U0627\U0646";
}
my problem exactly i save this data to sqlite [data objectForKey:#"name"] its saved \U0641\U0631\U0633\U0627\U0646 and when fetch data to to put it in UILabel or anything like it the text be \U0641\U0631\U0633\U0627\U0646
Any Help? Thank you :)
- (void)SaveMessage {
NSMutableDictionary *TableProperties = [[NSMutableDictionary alloc]init];
[TableProperties setObject:#"INSERT" forKey:#"Operation"];
[TableProperties setObject:#"savedmessages" forKey:#"tableName"];
NSString *string = [[NSString alloc]initWithFormat:#" %#",MessageBox.text];
[TableProperties setValue:string forKey:#"message"];
NSString *msgResult;
NSArray *result = [[DatabaseFunctions database] DataBaseOperation:TableProperties];
if ([[result objectAtIndex:0] isEqualToString:#"Done"])
msgResult = #"تم حفظ الرسالة بنجاح";
else
msgResult = #"لم تت العملية بنجاح حاول لاحقا";
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"حفظ الرسالة"
message:msgResult
delegate:self
cancelButtonTitle:#"موافق"
otherButtonTitles:nil, nil ];
[alert show];
}
- (NSArray *)DataBaseOperation:(NSMutableDictionary *)TableProperties{
NSMutableArray *retval = [[NSMutableArray alloc] init];
NSString *Operation = [TableProperties objectForKey:#"Operation"];
if ([Operation isEqualToString:#"SELECT" ]) {
NSString *tableColumns = [TableProperties objectForKey:#"tableColumns"];
NSString *tableName = [TableProperties objectForKey:#"tableName"];
NSString *tableWhere = [TableProperties objectForKey:#"tableWhere"];
NSString *tableOrder = [TableProperties objectForKey:#"tableOrder"];
NSString *tableLimit = [TableProperties objectForKey:#"tableLimit"];
NSString *Query;
if ([tableLimit isEqualToString:#"NO"]) {
Query = [[NSString alloc] initWithFormat:#"SELECT %# FROM %# WHERE %# ORDER BY %#",
tableColumns,tableName,tableWhere,tableOrder,tableLimit];
}else{
Query = [[NSString alloc] initWithFormat:#"SELECT %# FROM %# WHERE %# ORDER BY %# LIMIT %#",
tableColumns,tableName,tableWhere,tableOrder,tableLimit];
}
NSArray *FieldArray = [[TableProperties objectForKey:#"tableColumns"] componentsSeparatedByString:#","];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(_database, [Query UTF8String], -1, &statement, nil) == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
NSMutableDictionary *Row = [[NSMutableDictionary alloc]init];
NSString *uniqueId = [[NSString alloc] initWithFormat:#"%i",sqlite3_column_int(statement, 0)];
[Row setObject:uniqueId forKey:#"uniqueId"];
for (int i = 1; i<[FieldArray count]; i++) {
NSString *column = [[NSString alloc] initWithUTF8String:(char *) sqlite3_column_text(statement, i)];
[Row setObject:column forKey:[FieldArray objectAtIndex:i]];
}
Objects *rowOfTable = [[Objects alloc] initSelectDataFromTables:Row];
Row = nil;
[retval addObject:rowOfTable];
}
sqlite3_finalize(statement);
}
}
else if([Operation isEqualToString:#"INSERT" ]) {
NSString *tableName = [TableProperties objectForKey:#"tableName"];
[TableProperties removeObjectForKey:#"Operation"];
[TableProperties removeObjectForKey:#"tableName"];
NSArray *Columns = [TableProperties allKeys];
NSArray *Values = [TableProperties allValues];
NSString *Query = [[NSString alloc] initWithFormat:#"INSERT INTO %# %# VALUES %#",tableName,Columns,Values];
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(_database, [Query UTF8String], -1, &statement, nil) == SQLITE_OK)
if (SQLITE_DONE!=sqlite3_step(statement)){
NSLog(#"Error when inserting %s",sqlite3_errmsg(_database));
[retval addObject:#"Error"];
}else{
NSLog(#"Data inserted Successfully");
[retval addObject:#"Done"];
}
else{
NSLog(#"Error when inserting %s",sqlite3_errmsg(_database));
[retval addObject:#"Error"];
}
sqlite3_finalize(statement);
}
return retval;
}
When you log an object using %#, NSLog sends the description message to the object and prints the resulting string.
An NSDictionary responds to the description message by encoding its keys and values in a "safe" format, escaping non-ASCII characters using \U#### codes.
If you pass the Arabic string to NSLog directly, it will just print the string without the escape codes:
NSMutableDictionary *data = [[NSMutableDictionary alloc]init];
[data setObject:#"فرسان" forKey:#"name"];
NSLog(#"data = %#",data);
NSLog(#"string = %#", [data objectForKey:#"name"]);
Output:
2012-01-18 14:17:42.498 Animal[62723:f803] {
name = "\U0641\U0631\U0633\U0627\U0646";
}
2012-01-18 14:17:42.500 Animal[62723:f803] فرسان
If you don't like the way NSDictionary responds to description, you will have to write your own method to format a dictionary as a string and use it to log your dictionary.
Update
I have looked at the source code you posted that talks to sqlite. The problem is that you are turning the values array ([TableProperties allValues]) into a string using the %# format specifier. This sends the description method to the NSArray, which returns a string. Just like NSDictionary, NSArray formats the description string in a "safe" format, escaping non-ASCII characters using \U#### codes.
You need to write your own method that takes an array and turns it into a string and does not escape special characters. (It needs to escape quotes though.)

Sqlite database file is getting encrypted or is not a database

I have no idea what was the problem is in my program. When run this select code for fetching data from SQlite in my program, the first time it crashes with this error message:
kill error while killing target (killing anyway):
warning: error on line 2179 of "/SourceCache/gdb/gdb-1510/src/gdb/macosx/macosx-nat-inferior.c" in function "macosx_kill_inferior_safe": (os/kern) failure (0x5x)
quit
Here's my insert code:
-(id)init {
self = [super init];
sqlite3 *database;
NSMutableArray *locations;
NSString *result = nil;
NSString *dbPath = [self getWritableDBPath];
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
NSString *sqlStr = [NSString stringWithFormat:#"select Longitude,Latitude from myLocation"];
const char *sqlStatement = [sqlStr UTF8String];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
locations = [NSMutableArray array];
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
double longitude = sqlite3_column_double(compiledStatement, 0);
double latitude = sqlite3_column_double(compiledStatement, 1);
NSLog(#"%f , %f",longitude,latitude);
NSString *coords = [[[NSString alloc] initWithFormat:#"%f,%f\n",longitude,latitude] autorelease];
[locations addObject:coords];
NSLog(#"this location :-%#",locations);
//[coords release];
}
result = [locations componentsJoinedByString:#","]; // same as `fake_location`
NSLog(#"this for resulte data :- %#",result);
// Get file path here
NSError *error;
if ( [result writeToFile:dbPath atomically:YES encoding:NSUTF8StringEncoding error:&error] ) {
NSLog(#"%#", [error localizedDescription]);
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
pointsArray = [[result componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] retain];
pointsArrayIndex = 0;
oldLocationsIndex = 0;
[result release];
oldLocations = [[NSMutableArray alloc] init];
return self;
}
The second time I run my application, it shows me that on the console:
Save Error: file is encrypted or is not a database
What do these errors mean, and how do I solve that?
You need to fire insert query using following:
-(void)insertLocation:(double)latitude withLongitude:(double)longitude
{
sqlite3_stmt *insertStatement = nil;
const char *sql = "insert into UserJourneyLocation(Latitude, Longitude) Values(?,?)";
int returnValue = sqlite3_prepare_v2(database, sql, -1, &insertStatement, NULL);
if(returnValue == SQLITE_OK)
{
sqlite3_bind_double(insertStatement,1,latitude);
sqlite3_bind_double(insertStatement,2,longitude);
if(sqlite3_step(insertStatement)==SQLITE_DONE)
{
//Data;
}
}
sqlite3_finalize(insertStatement);
}
Yes I have.
Go to iphone application document folder
/users/(yourname)/library/application support/iphone simulator/user/application
And remove all Targets.After that Restart your application.

Problem while scrolling Table View

I have the following problem while i scroll the table view:
NSCFString objectAtIndex:]: unrecognized selector sent to instance
I create NSDictionary tableContents and when i scroll it becomes deallocated.
This is my code:
- (void)viewDidLoad {
lessonsInGroup1 = [NSMutableArray array];
lessonsInGroup2 = [NSMutableArray array];
lessonsInGroup1 = [self grabRowsInGroup:#"1"];
lessonsInGroup2 = [self grabRowsInGroup:#"2"];
NSDictionary *temp =[[NSDictionary alloc]initWithObjectsAndKeys:lessonsInGroup1,#"General Information",lessonsInGroup2,#"LaTeX Examples", nil];
//[[tableContents alloc] init];
self.tableContents =temp;
[temp release];
NSLog(#"table %#",self.tableContents);
NSLog(#"table with Keys %#",[self.tableContents allKeys]);
self.sortedKeys =[[self.tableContents allKeys] sortedArrayUsingSelector:#selector(compare:)];
NSLog(#"sorted %#",self.sortedKeys);
[lessonsInGroup1 release];
[lessonsInGroup2 release];
//[table reloadData];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
[super viewDidLoad];
}
- (NSMutableArray *) grabRowsInGroup:(NSString*)GroupID{
NSMutableArray *groupOfLessons;
groupOfLessons = [[NSMutableArray alloc] init];
char *sqlStatement;
int returnCode;
sqlite3_stmt *statement;
NSString *databaseName;
NSString *databasePath;
// Setup some globals
databaseName = #"TexDatabase.sql";
// Get the path to the documents directory and append the databaseName
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
// Setup the database object
sqlite3 *database;
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) != SQLITE_OK) {
fprintf(stderr, "Error in opening the database. Error: %s",
sqlite3_errmsg(database));
sqlite3_close(database);
return;
}
sqlStatement = sqlite3_mprintf(
"SELECT * FROM Lessons WHERE LessonGroup = '%s';", [GroupID UTF8String]);
returnCode =
sqlite3_prepare_v2(database,
sqlStatement, strlen(sqlStatement),
&statement, NULL);
if(returnCode != SQLITE_OK) {
fprintf(stderr, "Error in preparation of query. Error: %s",
sqlite3_errmsg(database));
sqlite3_close(database);
return;
}
returnCode = sqlite3_step(statement);
while(returnCode == SQLITE_ROW) {
NSString *aLessonID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
NSString *aLessonGroup = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
NSString *aLessonTopic = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2)];
NSString *aLessonText = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 3)];
NSString *aLessonCode = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 4)];
NSString *aLessonPicture = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 5)];
/*NSLog(aLessonID);
NSLog(aLessonGroup);
NSLog(aLessonTopic);
NSLog(aLessonText);
NSLog(aLessonCode);
NSLog(aLessonPicture);*/
// Create a new busCit object with the data from the database
Lesson *lesson = [[Lesson alloc] initWithLessonID:aLessonID LessonGroup:aLessonGroup LessonTopic:aLessonTopic LessonText:aLessonText LessonCode:aLessonCode LessonPicture:aLessonPicture];
[groupOfLessons addObject:lesson];
returnCode = sqlite3_step(statement);
}
sqlite3_finalize(statement);
sqlite3_free(sqlStatement);
return [groupOfLessons autorelease];
}
What does your #property for tableofContents look like?
Also, you are going to run into issues with
[lessonsInGroup1 release];
[lessonsInGroup2 release];
because you are autoreleasing those in the grabRowsInGroup:
So, you don't need to call release them.
Looks like you are calling objectAtIndex on NSString. It should rather be some array