This should be easy enough, but I just can't get this work work.
I'm trying to use 3 const variables to create a sql statement to pass to my DB access class.
I'm concatenating the constants in different methods of the class to build a full SQL statement. This way I don't have to have the same select showing up once in each method.
Something I'm doing isn't working though. The app either crashes or returns zero records. If I change this all to a straight char and dump the sql statement in it works just fine.
Here's my constants:
Here's where I'm trying to concatenate them:
sql is a char property of the dbAccess class which is used to run a sqlite3_prepare_v2.
With this code the app crashes as soon as I try to hit this method. I'm not familiar enough with the console to know what's going wrong.
I'm pretty new to Objective-C and I'm guessing there's something blatantly obvious to more experienced people as to why this isn't working.
When I changed from #define constants to this type...
...the app doesn't crash, but the result set is empty.
The following code works but then I have SQL repeated all over the class:
Need a point in the right direction. Thanks.
I'm trying to use 3 const variables to create a sql statement to pass to my DB access class.
I'm concatenating the constants in different methods of the class to build a full SQL statement. This way I don't have to have the same select showing up once in each method.
Something I'm doing isn't working though. The app either crashes or returns zero records. If I change this all to a straight char and dump the sql statement in it works just fine.
Here's my constants:
Code:
#define sqlSelect "SELECT beers.ID, beers.name, beers.breweryID, breweries.name, beers.type, beers.style, beers.flavor, beers.rating, beers.url, beers.desc, beers.abv, beers.imageURL "
#define sqlFrom "FROM beers "
#define sqlJoinBrewery "INNER JOIN breweries ON beers.breweryID = breweries.ID "
Code:
dbAccess.sql = (char *)[NSString stringWithFormat:@"%@%@%@", sqlSelect, sqlFrom, sqlJoinBrewery];;
sql is a char property of the dbAccess class which is used to run a sqlite3_prepare_v2.
With this code the app crashes as soon as I try to hit this method. I'm not familiar enough with the console to know what's going wrong.
I'm pretty new to Objective-C and I'm guessing there's something blatantly obvious to more experienced people as to why this isn't working.
When I changed from #define constants to this type...
Code:
NSString * const MyFirstConstant = @"FirstConstant";
The following code works but then I have SQL repeated all over the class:
Code:
dbAccess.sql = "SELECT ... FROM ...";
Need a point in the right direction. Thanks.
Last edited: