diff --git a/src/EditTableDialog.cpp b/src/EditTableDialog.cpp index 2e4dff3c..6c5d1b72 100644 --- a/src/EditTableDialog.cpp +++ b/src/EditTableDialog.cpp @@ -30,7 +30,7 @@ EditTableDialog::EditTableDialog(DBBrowserDB* db, const QString& tableName, QWid m_bNewTable = false; // we are editing an existing table // Existing table, so load and set the current layout - QString sTablesql = pdb->getTableSQL(curTable); + QString sTablesql = pdb->getObjectByName(curTable).getsql(); m_table = sqlb::Table::parseSQL(sTablesql); populateFields(); } @@ -366,7 +366,7 @@ void EditTableDialog::removeField() QMessageBox::warning(0, QApplication::applicationName(), pdb->lastErrorMessage); } else { //relayout - QString sTablesql = pdb->getTableSQL(curTable); + QString sTablesql = pdb->getObjectByName(curTable).getsql(); m_table = sqlb::Table::parseSQL(sTablesql); populateFields(); } diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index f9ee0f8d..8d0abe5e 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -424,7 +424,7 @@ int DBBrowserDB::addRecord(const QString& sTableName) // add record is seldom called, for now this is ok // but if we ever going to add a lot of records // we should cache the parsed tables somewhere - sqlb::Table table = sqlb::Table::parseSQL(getTableSQL(sTableName)); + sqlb::Table table = sqlb::Table::parseSQL(getObjectByName(sTableName).getsql()); QString sInsertstmt = table.emptyInsertStmt(); lastErrorMessage = ""; logSQL(sInsertstmt, kLogMsg_App); @@ -531,7 +531,7 @@ bool DBBrowserDB::renameColumn(const QString& tablename, const QString& name, sq //return executeSQL(sql); // Collect information on the current DB layout - QString tableSql = getTableSQL(tablename); + QString tableSql = getObjectByName(tablename).getsql(); if(tableSql.isEmpty()) { lastErrorMessage = QObject::tr("renameColumn: cannot find table %1.").arg(tablename); @@ -740,32 +740,6 @@ void DBBrowserDB::logSQL(QString statement, int msgtype) } } -QString DBBrowserDB::getTableSQL(const QString& sTable) -{ - sqlite3_stmt *vm; - const char *tail; - int err; - QString sTableSQL; - - QString statement = QString("SELECT sql FROM sqlite_master WHERE name='%1';").arg(sTable); - - QByteArray utf8Statement = statement.toUtf8(); - err=sqlite3_prepare_v2(_db, utf8Statement, utf8Statement.length(), - &vm, &tail); - if (err == SQLITE_OK){ - logSQL(statement, kLogMsg_App); - if( sqlite3_step(vm) == SQLITE_ROW ) - { - sTableSQL = QString::fromUtf8((const char*)sqlite3_column_text(vm, 0)); - } - sqlite3_finalize(vm); - }else{ - qCritical() << "Unable to get sql for table: " << sTable; - } - - return sTableSQL; -} - void DBBrowserDB::updateSchema( ) { sqlite3_stmt *vm; diff --git a/src/sqlitedb.h b/src/sqlitedb.h index 7ee42ba4..653405c3 100644 --- a/src/sqlitedb.h +++ b/src/sqlitedb.h @@ -65,13 +65,6 @@ public: bool executeSQL ( const QString & statement, bool dirtyDB=true, bool logsql=true); bool executeMultiSQL(const QString& statement, bool dirty = true, bool log = false); - /** - * @brief getTableSQL Returns the create table statement for the given table. - * @param sTable Table name - * @return An empty string if the table does not exist - * or the create table statement. - */ - QString getTableSQL(const QString& sTable); void updateSchema(); int addRecord(const QString& sTableName); bool deleteRecord(const QString& table, int rowid);