waynew
11th March 2010, 23:10
Has anyone successfully created a Sqlite table using a variable for a table name?
Like this:
void createTable(QString tableName) {
query.prepare("Create table ? (col1, col2)");
query.addBindValue(tableName);
query.exec();
}
Also tried :bind notation, same error: parameter count mismatch.
Also tried creating the table with a dummy name then renaming like this:
void createTable(QString name) {
query.prepare("CREATE table tablename (col1, col2)");
query.exec();
query.prepare("ALTER table tablename rename to ?");
query.addBindValue(name);
query.exec();
}
Still the parameter count mismatch error.
Any ideas how to do this?
Like this:
void createTable(QString tableName) {
query.prepare("Create table ? (col1, col2)");
query.addBindValue(tableName);
query.exec();
}
Also tried :bind notation, same error: parameter count mismatch.
Also tried creating the table with a dummy name then renaming like this:
void createTable(QString name) {
query.prepare("CREATE table tablename (col1, col2)");
query.exec();
query.prepare("ALTER table tablename rename to ?");
query.addBindValue(name);
query.exec();
}
Still the parameter count mismatch error.
Any ideas how to do this?