Search code examples
iphoneobjective-ciosfmdb

Insert data to database table with non static name (FMDB)


I have a project where dynamically creating tables in database. And I didn't know what is table are used in some moment. And want something like this: [db executeQuery:@"INSERT INTO %@Table (image) VALUES (?)",tableName,imageData]; But it didn't work. How can I solve this problem?


Solution

  • You can create a string and then use this string to do the query, something like that:

    NSString* queryStr = [NSString stringWithFormat:@"INSERT INTO %@(image) VALUES (?) ",tableName];
    [db executeQuery:queryStr,imageData];