使用包装器时sqlite查询有问题

时间:2010-04-21 05:03:34

标签: iphone objective-c sqlite wrapper

- (IBAction)EnterButtonPressed:(id)sender {
    Sqlite *sqlite = [[Sqlite alloc] init];

NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"test.sqlite"];
    if (![sqlite open:writableDBPath])
        return;
NSArray *query = [sqlite executeQuery:@"SELECT AccessCode FROM UserAccess"];
NSLog(@"%@",query);

我得到的输出为:{ ( AccessCode = ABCD; ) }

我想要的地方如下:abcd

我正在使用来自http://th30z.netsons.org/2008/11/objective-c-sqlite-wrapper/

的包装器

请帮忙。

1 个答案:

答案 0 :(得分:0)

输出正确,示例清楚地显示了它:

    NSArray *results = [sqlite executeQuery:@"SELECT * FROM test;"];
for (NSDictionary *dictionary in results) {
  NSLog(@"Row");
  for (NSString *key in [dictionary keyEnumerator])
      NSLog(@" - %@ %@", key, [dictionary objectForKey:key]);
}

您将获得一个NSDictionaries数组。你可以写例如

NSDictionary *dict = [result at: 0];
NSSTring *itemValue = [dict objectForKey: @"AccessCode"]
NSLog(..., itemValue)

并获得希望的输出。