0
-(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我能打印“选择AccessCode FROM UserAccess”里为let说,接入码为1234,这是我想.The挑战是要执行的命令,从而我可以检索 1234从数据库UserAcess.sqlite的表UserAccess中的列AccessCode我的数据库和表名是相同的oops。 在AppDelegate中我有: ///SQLITE3查询目标C
- (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;
}
请帮助:(
您应该使用Objective-C字符串常量'NSString * sqlns = @“SELECT AccessCode FROM UserAccess”;'而不是从您正在使用的C字符串中生成Objective-C字符串的复杂方法。 – 2010-04-16 06:34:41
我想NSLog中的'AccessCode'列的值(@“%@”,sqlns); 我应该得到1234而不是:SELECT AccessCode FROM UserAccess – 2010-04-16 06:44:24