-(IBAction)ButtonPressed:(id)sender
{
const char *sql = "SELECT AccessCode FROM UserAccess";
NSString *sqlns;
sqlns = [NSString stringWithUTF8String:sql];
if([Password.text isEqual:sqlns])
{
NSLog(@"Correct");
}
else {
NSLog(@"Wrong");
}
NSLog(@"%@",sqlns);
}
Noob here ,
At NSLog I am able to print "SELECT AccessCode FROM UserAccess" where as let say the access code is 1234 , which I want .
In the appdelegate I Have :
///
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch
[self createEditableCopyOfDatabaseIfNeeded];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
///
- (void)createEditableCopyOfDatabaseIfNeeded {
NSLog(@"Creating editable copy of database");
// First, test for existence.
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"UserAccess.sqlite"];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success) return;
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"UserAccess.sqlite"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
///
+(sqlite3 *) getNewDBConnection{
sqlite3 *newDBconnection;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"UserAccess.sqlite"];
// Open the database. The database was prepared outside the application.
if (sqlite3_open([path UTF8String], &newDBconnection) == SQLITE_OK) {
NSLog(@"Database Successfully Opened :) ");
} else {
NSLog(@"Error in opening database :( ");
}
return newDBconnection;
}
Please help :(