Ok, I tried putting the code in the header and got nowhere. I appreciate you trying to help me. I am attaching code for my files that need to be modified (I believe). I would appreciate it if you could help with this.
VGTData.h file
Code:
#import <Foundation/Foundation.h>
#import <sqlite3.h>
#import "VGTDataUser.h"
#import "VGTGame.h"
#import "VGTManufacturer.h"
#import "VGTPlatform.h"
@interface VGTData : NSObject
{
sqlite3 *readonlyDatabase;
sqlite3 *writableDatabase;
NSArray *manufacturers;
BOOL shouldReloadUserHaves;
BOOL shouldReloadUserWants;
NSMutableSet *dataUsers;
NSMutableSet *haveGames[OwnedStateCOUNT];
NSMutableSet *wantGames[OwnedStateCOUNT];
NSMutableDictionary *havePlatforms;
NSMutableDictionary *wantPlatforms;
}
@property (nonatomic, assign) sqlite3 *readonlyDatabase;
@property (nonatomic, assign) sqlite3 *writableDatabase;
@property (nonatomic, retain) NSArray *manufacturers;
+ (VGTData *)sharedInstance;
+ (void)appWillTerminate;
- (id)init;
- (void)createFavoritesTables;
- (UIImage *)imageForManufacturer:(VGTManufacturer *)manufacturer;
- (UIImage *)imageForPlatform:(VGTPlatform *)platform;
- (NSArray *)platformsWithText:(NSString *)searchText;
//- (NSArray *)gamesForPlatform:(VGTPlatform *)platform;
- (void)addDataUser:(id <VGTDataUser>)aUser;
- (BOOL)loadDatabaseUpdate:(NSData *)aData;
- (NSDictionary *)havePlatforms;
- (NSDictionary *)wantPlatforms;
- (NSSet *)haveCompleteGames;
- (NSSet *)haveLooseGames;
- (NSSet *)wantCompleteGames;
- (NSSet *)wantLooseGames;
- (OwnedState)haveItStateForGame:(NSString *)primaryKey;
- (OwnedState)wantItStateForGame:(NSString *)primaryKey;
- (void)setHaveState:(OwnedState)newState forGame:(NSString *)primaryKey;
- (void)setWantState:(OwnedState)newState forGame:(NSString *)primaryKey;
- (BOOL)shouldReloadUserHaves;
- (BOOL)shouldReloadUserWants;
- (void)userHavesDidChange;
- (void)userWantsDidChange;
@end
VGTData.m file
Code:
#import "VGTData.h"
#import "VGTManufacturer.h"
#import "VGTPlatform.h"
#import "VGTGame.h"
#import "JHSQLiteCocoa.h"
#import <sqlite3.h>
@interface VGTData ()
- (void)initializeDatabase;
- (void)closeDatabase;
@end
@implementation VGTData
VGTData *VGTData__instance = nil;
static sqlite3_stmt *search_statement = NULL;
static sqlite3_stmt *hydrate_have_platforms_statement = NULL;
static sqlite3_stmt *hydrate_have_statement = NULL;
static sqlite3_stmt *query_have_statement = NULL;
static sqlite3_stmt *delete_have_statement = NULL;
static sqlite3_stmt *insert_have_statement = NULL;
static sqlite3_stmt *hydrate_want_platforms_statement = NULL;
static sqlite3_stmt *hydrate_want_statement = NULL;
static sqlite3_stmt *query_want_statement = NULL;
static sqlite3_stmt *delete_want_statement = NULL;
static sqlite3_stmt *insert_want_statement = NULL;
@synthesize readonlyDatabase;
@synthesize writableDatabase;
@synthesize manufacturers;
+ (VGTData *)sharedInstance
{
//DLog(@"%s (%@)", __FUNCTION__, VGTData__instance);
if (VGTData__instance == nil)
{
VGTData__instance = [[VGTData alloc] init];
}
return VGTData__instance;
}
+ (void)appWillTerminate
{
[VGTData__instance closeDatabase];
}
- (void)createFavoritesTables
{
static BOOL did_create_have_table = NO;
static BOOL did_create_want_table = NO;
if (did_create_have_table == NO)
{
did_create_have_table = YES;
sqlite3_stmt *statement = NULL;
const char *sql = "CREATE TABLE IF NOT EXISTS user_have(gameId TEXT PRIMARY KEY, state INT)";
int result = sqlite3_prepare_v2(writableDatabase, sql, -1, &statement, NULL);
//DLog(@"(%d)", result);
if (result != SQLITE_OK)
{
DLog(@"");
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(writableDatabase));
}
int success = sqlite3_step(statement);
//DLog(@"(%d)", success);
result = sqlite3_finalize(statement);
DLog(@"(%d)", result);
}
if (did_create_want_table == NO)
{
did_create_want_table = YES;
sqlite3_stmt *statement = NULL;
const char *sql = "CREATE TABLE IF NOT EXISTS user_want(gameId TEXT PRIMARY KEY, state INT)";
int result = sqlite3_prepare_v2(writableDatabase, sql, -1, &statement, NULL);
//DLog(@"(%d)", result);
if (result != SQLITE_OK)
{
DLog(@"");
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(writableDatabase));
}
int success = sqlite3_step(statement);
//DLog(@"(%d)", success);
result = sqlite3_finalize(statement);
DLog(@"(%d)", result);
}
}
- (void)dealloc
{
[manufacturers release];
[super dealloc];
}
// There is actually more code then this but I think this is all you will need //
I know this is a lot of code to look into and even perhaps outside the scope of this forum. But I am beginner at this and I am stuck. Thanks