views:

39

answers:

1
- (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);

I am getting the output as : { ( AccessCode=abcd; ) }

Where as in I want it as : abcd

I am using the wrapper from : http://th30z.netsons.org/2008/11/objective-c-sqlite-wrapper/

Please help .

A: 

The output is correct, the examples clearly show it also:

    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]);
}

You get an Array of NSDictionaries. You could write e.g

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

and will get the wished output.

Friedrich
Hey thanks , but its giving a warning : NSArray' may not respond to '-at:'when I tried objectAtIndex: it was saying Table UserAccess not found
NSArray *query = [sqlite executeQuery:@"SELECT * FROM UserAccess;"]; initWithFormat:@"%@",query]; NSDictionary *dict = [query objectAtIndex:0]; NSString *itemValue = [dict objectForKey:@"AccessCode"]; NSLog(@"%@",itemValue);got that ... thanks you are a awesome
I guess I've programmed Smalltalk a little bit too much. There the accessor is named at: but objectAtIndex is quite fine as you figured out yourself ;-)
Friedrich