Друг, я действительно так сознался, Что мне делать.
Вот мой код.
@ синтезировать имя пользователя, пароль;
- (void) createDatabaseIfNeeded {
BOOL success;
NSError *error;
//FileManager - Object allows easy access to the File System.
NSFileManager *FileManager = [NSFileManager defaultManager];
//Get the complete users document directory path.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//Get the first path in the array.
NSString *documentsDirectory = [paths objectAtIndex:0];
//Create the complete path to the database file.
NSString *databasePath = [documentsDirectory stringByAppendingPathComponent:@"Journeymapper.sql"];
//Check if the file exists or not.
success = [FileManager fileExistsAtPath:databasePath];
//If the database is present then quit.
if(success) return;
//the database does not exists, so we will copy it to the users document directory]
NSString *dbPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Journeymapper.sql"];
//Copy the database file to the users document directory.
success = [FileManager copyItemAtPath:dbPath toPath:databasePath error:&error];
//If the above operation is not a success then display a message.
//Error message can be seen in the debugger's console window.
if(!success)
NSAssert1(0, @"Failed to copy the database. Error: %@.", [error localizedDescription]);
}
-(void)check
{
//Get the database and connect to it.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dbPath = [documentsDirectory stringByAppendingPathComponent:@"Journeymapper.sql"];
//open the database
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
{
//const char *sql ="select Username@'%@',Password@'%@' from userinformation";
NSString *sql = [[NSString alloc] initWithFormat:@"select * from UserInformation where UserName='%@' and Password='%@' ",Username.text,Password.text];
sqlite3_stmt *selectSatement;
//Preoare the select Statment
int returnValue = sqlite3_prepare_v2(database, [sql UTF8String], -1, &selectSatement, NULL);
NSLog(@"%i",returnValue);
if( sqlite3_prepare_v2(database, [sql UTF8String], -1, &selectSatement, NULL) == SQLITE_OK)
{
NSString *user1 = [NSString stringWithUTF8String:(char *)sqlite3_column_text(selectSatement, 0)];
NSLog(@"%@",user1);
}
}
}
-(IBAction)Login
{
[self check];
}
проблема в том, что здесь: -Я не уверен, почему sqlite3_prepare_v2
не отвечает SQLITE_OK
.
if( sqlite3_prepare_v2(database, [sql UTF8String], -1, &selectSatement, NULL) == SQLITE_OK)
Любая помощь с этим очень ценится.