0

I am trying to use a NSMutableArray to show some data from my sqlite database in my tableview.

When I use AssetDesc as my cell text I can see my description from my sqlite database in my UITableCell. So I know everything is working okay.

However when I use AssetName as my cell text I get a sqlite error saying:

Warning: I could not find the column named 'AssetName'.

If I change this line:

customer.assetName = [results stringForColumn:@"AssetName"];

like this:

customer.assetName = [results stringForColumn:@"AssetDesc"];

It works so it has to be something in my database but I cannot pin point it.

But I am sure that that is in my asset table. This makes so sense to me. below is a picture of my database and code:

-(NSMutableArray *) getCustomers
{
    NSMutableArray *customers = [[NSMutableArray alloc] init];

    FMDatabase *db = [FMDatabase databaseWithPath:[Utility getDatabasePath]];

    [db open];

    FMResultSet *results = [db executeQuery:@"SELECT * FROM asset"];

    while([results next])
    {
        Customer *customer = [[Customer alloc] init];

        customer.assetId = [results intForColumn:@"AssetID"];
        customer.assetName = [results stringForColumn:@"AssetName"];
        customer.assetDesc = [results stringForColumn:@"AssetDesc"];

        [customers addObject:customer];

    }

    [db close];

    return customers;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CustomerCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    Customer *customer = [self.customers objectAtIndex:[indexPath row]];

    [[cell textLabel] setText:[NSString stringWithFormat:@"%@",customer.assetName]];
    [[cell detailTextLabel] setText:[NSString stringWithFormat:@"%@",customer.assetDesc]];

    return 
}

enter image description here

5
  • When you debugged this, what were the keys in [results resultDictionary]? Jun 1, 2013 at 21:05
  • Just a side note: You don't open and close the database between requests, you create a query, then close the query when you're done enumerating it
    – CodaFi
    Jun 1, 2013 at 21:11
  • 2013-06-01 23:22:39.840 [3759:907] Dict: ( "<Customer: 0x1f5bfda0>", "<Customer: 0x1f5bfeb0>", "<Customer: 0x1f5bff20>" ) Jun 1, 2013 at 21:24
  • Is that what you mean by keys? Jun 1, 2013 at 21:25
  • @RedDeFine Unless those are the keys in the NSDictionary returned by [results resultDictionary] (which they appear to not be, this looks like your customers array) then no. Jun 1, 2013 at 21:34

1 Answer 1

1

Turns out that I actually had to delete my app off my device and run it again. It was taking reference to the database stored in the documents directory.

I thought it it was taking reference to the dataabase in my Xcode project.

When I deleted the app off the device and installed it again it obviously deleted the files in my documents directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.