I needed to create an instance property for the database. My assumption that the static declaration was sufficient was incorrect. BTW, the FMDB/ORM advice is great. I am a huge fan of ORMs. However, this project is my first iphone and it is a small amount of database work and I want to learn. So, I am going to do it old school. Thanks for the advice.
Here are the code changes I made to make my global reference work.. Hope it helps someone:
/* myAppDelegate.h file */
import
@interface myAppDelegate : NSObject {
... // you may have windows etc here
sqlite3 *database;
}
@property (readwrite) sqlite3 *database;
/* myAppDelegate.m file */
@implementation myAppDelegate
...
@synthesize database;
/* some method in some class that uses the database */
- (void) getSomeData
{
myAppDelegate *appDelegate = (myAppDelegate *) [[ UIApplication sharedApplication ] delegate ];
const char *sql = "SELECT * FROM myTable";
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(appDelegate.database, sql, -1, &selectstmt, NULL) == SQLITE_OK)
{
// get the data here.
}
}