-(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);
}
Нуб здесь,
В NSLog я могу напечатать «SELECT AccessCode FROM UserAccess», где, скажем, код доступа 1234, который я хочу. Задача состоит в том, чтобы выполнить команду, чтобы я мог получить
1234 из столбца AccessCode в таблице UserAccess в datable UserAcess.sqlite
Моя база данных и имя таблицы совпадают.
В приложении заявлено:
///
- (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;
}
Пожалуйста, помогите: (