Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 目标c中的Sqlite3查询_Objective C_Iphone_Iphone Sdk 3.0_Sqlite - Fatal编程技术网

Objective c 目标c中的Sqlite3查询

Objective c 目标c中的Sqlite3查询,objective-c,iphone,iphone-sdk-3.0,sqlite,Objective C,Iphone,Iphone Sdk 3.0,Sqlite,这里没有, 在NSLog上,我可以打印“SelectAccessCodefromUserAccess”,比如说访问代码是1234,这是我想要的 1234从数据表UserAccess.sqlite中的UserAccess表中的AccessCode列 我的数据库和表名是相同的oops。 在appdelegate中,我有: /// /// /// 请提供帮助:(您需要进行一些sqlite3调用以执行select语句并检索列值 包含此特定任务所需的所有信息。您应该使用Objective-C字符串常量NS

这里没有, 在NSLog上,我可以打印“SelectAccessCodefromUserAccess”,比如说访问代码是1234,这是我想要的 1234从数据表UserAccess.sqlite中的UserAccess表中的AccessCode列 我的数据库和表名是相同的oops。 在appdelegate中,我有: ///

///

///


请提供帮助:(

您需要进行一些sqlite3调用以执行select语句并检索列值


包含此特定任务所需的所有信息。

您应该使用Objective-C字符串常量
NSString*sqlns=@“SELECT ACCESS code FROM UserAccess”;
而不是从正在使用的C字符串生成Objective-C字符串的复杂方法。我需要NSLog中“ACCESS code”列的值(@“%@”,sqlns);我应该获取1234而不是:从UserAccess中选择AccessCode
  -(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);
    }
- (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;

              }