Search code examples
iosobjective-csqliteselectfmdb

Error with FMDB - unknown column name


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


Solution

  • 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.