diff --git a/src/EditTableForm.cpp b/src/EditTableForm.cpp index b6783483..d30ab16f 100644 --- a/src/EditTableForm.cpp +++ b/src/EditTableForm.cpp @@ -68,21 +68,18 @@ void editTableForm::accept() { // Creation of new table - // Build SQL statement from what the use entered - QString sql = QString("CREATE TABLE `%1` (").arg(ui->editTableName->text()); + // Prepare creation of the table + QList tbl_structure; for(int i=0;itreeWidget->topLevelItemCount();i++) - sql.append(QString("`%1` %2,").arg(ui->treeWidget->topLevelItem(i)->text(0)).arg(ui->treeWidget->topLevelItem(i)->text(1))); - sql.remove(sql.count() - 1, 1); // Remove last comma - sql.append(");"); + tbl_structure.push_back(DBBrowserField(ui->treeWidget->topLevelItem(i)->text(0), ui->treeWidget->topLevelItem(i)->text(1))); - // Execute it - modified = true; - if (!pdb->executeSQL(sql)){ - QString error("Error creating table. Message from database engine:\n"); - error.append(pdb->lastErrorMessage).append("\n\n").append(sql); - QMessageBox::warning( this, QApplication::applicationName(), error ); + // Create table + if(!pdb->createTable(ui->editTableName->text(), tbl_structure)) + { + QMessageBox::warning(this, QApplication::applicationName(), QString("Error creating table. Message from database engine:\n%1").arg(pdb->lastErrorMessage)); return; } + modified = true; } else { // Editing of old table diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index 5fe5a78e..37d0e18b 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -414,8 +414,21 @@ bool DBBrowserDB::browseTable( const QString & tablename, const QString& orderby return hasValidBrowseSet; } -bool DBBrowserDB::createColumn( QString tablename, QString fieldname, QString fieldtype ){ - qDebug("create column"); +bool DBBrowserDB::createTable(QString name, const QList& structure) +{ + // Build SQL statement + QString sql = QString("CREATE TABLE `%1` (").arg(name); + for(int i=0;i new_table_structure; for(int i=0;i new_table_structure; QString select_cols; for(int i=0;i& structure); bool renameTable(QString from_table, QString to_table); bool createColumn(QString table, QString field, QString type); bool renameColumn(QString tablename, QString from, QString to, QString type);