mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
cleanup DBBrowserDB::updateSchema and also get rid of a lot of unneeded object copies
This commit is contained in:
@@ -91,22 +91,21 @@ void createIndexForm::confirmCreate()
|
||||
}
|
||||
}
|
||||
|
||||
void createIndexForm::populateTable(tableMap rmap)
|
||||
void createIndexForm::populateTable(const tableMap& rmap)
|
||||
{
|
||||
mtablemap = rmap;
|
||||
tableMap::Iterator it;
|
||||
for ( it = mtablemap.begin(); it != mtablemap.end(); ++it ) {
|
||||
comboTables->addItem( it.value().getname() );
|
||||
tableMap::ConstIterator it;
|
||||
for ( it = rmap.begin(); it != rmap.end(); ++it ) {
|
||||
comboTables->addItem( it.value().getname() );
|
||||
|
||||
//populate the fields with first table name
|
||||
if (it==mtablemap.begin()){
|
||||
fieldMap::Iterator fit;
|
||||
fieldMap fmap = it.value().fldmap;
|
||||
for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) {
|
||||
comboFields->addItem( fit.value().getname() );
|
||||
}
|
||||
}
|
||||
//populate the fields with first table name
|
||||
if (it==mtablemap.begin()){
|
||||
fieldMap::Iterator fit;
|
||||
fieldMap fmap = it.value().fldmap;
|
||||
for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) {
|
||||
comboFields->addItem( fit.value().getname() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -266,7 +266,7 @@ public:
|
||||
public slots:
|
||||
virtual void tableSelected( const QString & entry );
|
||||
virtual void confirmCreate();
|
||||
virtual void populateTable( tableMap rmap );
|
||||
virtual void populateTable( const tableMap& rmap );
|
||||
|
||||
protected slots:
|
||||
virtual void languageChange();
|
||||
|
||||
@@ -970,10 +970,9 @@ void MainWindow::populateStructure()
|
||||
return;
|
||||
}
|
||||
db.updateSchema();
|
||||
tableMap::Iterator it;
|
||||
tableMap tmap = db.tbmap;
|
||||
tableMap::ConstIterator it;
|
||||
|
||||
for ( it = tmap.begin(); it != tmap.end(); ++it ) {
|
||||
for ( it = db.tbmap.begin(); it != db.tbmap.end(); ++it ) {
|
||||
|
||||
//* Table node
|
||||
QTreeWidgetItem *tableItem = new QTreeWidgetItem();
|
||||
@@ -996,9 +995,8 @@ void MainWindow::populateStructure()
|
||||
// TODO make an options/setting autoexpand
|
||||
dbTreeWidget->setItemExpanded(tableItem, true);
|
||||
}
|
||||
indexMap::Iterator it2;
|
||||
indexMap imap = db.idxmap;
|
||||
for ( it2 = imap.begin(); it2 != imap.end(); ++it2 ) {
|
||||
indexMap::ConstIterator it2;
|
||||
for ( it2 = db.idxmap.begin(); it2 != db.idxmap.end(); ++it2 ) {
|
||||
QTreeWidgetItem *idxItem = new QTreeWidgetItem();
|
||||
idxItem->setText( 0, it2.value().getname() );
|
||||
idxItem->setText( 1, "index" );
|
||||
@@ -1384,8 +1382,7 @@ void MainWindow::createIndex()
|
||||
}
|
||||
createIndexForm * indexForm = new createIndexForm( this );
|
||||
indexForm->setModal(true);
|
||||
tableMap tmap = db.tbmap;
|
||||
indexForm->populateTable( tmap );
|
||||
indexForm->populateTable( db.tbmap );
|
||||
if ( indexForm->exec() ) {
|
||||
if (!db.executeSQL(indexForm->createStatement)){
|
||||
QString error = "Error: could not create the index. Message from database engine: ";
|
||||
|
||||
@@ -533,11 +533,10 @@ resultMap DBBrowserDB::getFindResults( const QString & wstatement)
|
||||
|
||||
QStringList DBBrowserDB::getTableNames()
|
||||
{
|
||||
tableMap::Iterator it;
|
||||
tableMap tmap = tbmap;
|
||||
tableMap::ConstIterator it;
|
||||
QStringList res;
|
||||
|
||||
for ( it = tmap.begin(); it != tmap.end(); ++it ) {
|
||||
for ( it = tbmap.begin(); it != tbmap.end(); ++it ) {
|
||||
res.append( it.value().getname() );
|
||||
}
|
||||
|
||||
@@ -559,16 +558,14 @@ QStringList DBBrowserDB::getIndexNames()
|
||||
|
||||
QStringList DBBrowserDB::getTableFields(const QString & tablename)
|
||||
{
|
||||
tableMap::Iterator it;
|
||||
tableMap tmap = tbmap;
|
||||
tableMap::ConstIterator it;
|
||||
QStringList res;
|
||||
|
||||
for ( it = tmap.begin(); it != tmap.end(); ++it ) {
|
||||
for ( it = tbmap.begin(); it != tbmap.end(); ++it ) {
|
||||
if (tablename.compare(it.value().getname())==0 ){
|
||||
fieldMap::Iterator fit;
|
||||
fieldMap fmap = it.value().fldmap;
|
||||
fieldMap::ConstIterator fit;
|
||||
|
||||
for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) {
|
||||
for ( fit = it.value().fldmap.begin(); fit != it.value().fldmap.end(); ++fit ) {
|
||||
res.append( fit.value().getname() );
|
||||
}
|
||||
}
|
||||
@@ -578,16 +575,14 @@ QStringList DBBrowserDB::getTableFields(const QString & tablename)
|
||||
|
||||
QStringList DBBrowserDB::getTableTypes(const QString & tablename)
|
||||
{
|
||||
tableMap::Iterator it;
|
||||
tableMap tmap = tbmap;
|
||||
tableMap::ConstIterator it;
|
||||
QStringList res;
|
||||
|
||||
for ( it = tmap.begin(); it != tmap.end(); ++it ) {
|
||||
for ( it = tbmap.begin(); it != tbmap.end(); ++it ) {
|
||||
if (tablename.compare(it.value().getname())==0 ){
|
||||
fieldMap::Iterator fit;
|
||||
fieldMap fmap = it.value().fldmap;
|
||||
fieldMap::ConstIterator fit;
|
||||
|
||||
for ( fit = fmap.begin(); fit != fmap.end(); ++fit ) {
|
||||
for ( fit = it.value().fldmap.begin(); fit != it.value().fldmap.end(); ++fit ) {
|
||||
res.append( fit.value().gettype() );
|
||||
}
|
||||
}
|
||||
@@ -621,11 +616,7 @@ void DBBrowserDB::updateSchema( )
|
||||
// qDebug ("Getting list of tables");
|
||||
sqlite3_stmt *vm;
|
||||
const char *tail;
|
||||
QStringList r;
|
||||
int err=0;
|
||||
QString num;
|
||||
int idxnum =0;
|
||||
int tabnum = 0;
|
||||
|
||||
idxmap.clear();
|
||||
tbmap.clear();
|
||||
@@ -640,12 +631,10 @@ void DBBrowserDB::updateSchema( )
|
||||
if (err == SQLITE_OK){
|
||||
logSQL(statement, kLogMsg_App);
|
||||
while ( sqlite3_step(vm) == SQLITE_ROW ){
|
||||
num.setNum(tabnum);
|
||||
QString val1, val2;
|
||||
val1 = QString((const char *) sqlite3_column_text(vm, 0));
|
||||
val2 = QString((const char *) sqlite3_column_text(vm, 1));
|
||||
tbmap[num] = DBBrowserTable(GetDecodedQString(val1), GetDecodedQString(val2));
|
||||
tabnum++;
|
||||
tbmap[val1] = DBBrowserTable(GetDecodedQString(val1), GetDecodedQString(val2));
|
||||
}
|
||||
sqlite3_finalize(vm);
|
||||
}else{
|
||||
@@ -657,7 +646,7 @@ void DBBrowserDB::updateSchema( )
|
||||
tableMap::Iterator it;
|
||||
for ( it = tbmap.begin(); it != tbmap.end(); ++it ) {
|
||||
statement = "PRAGMA TABLE_INFO(";
|
||||
statement.append( it.value().getname().toUtf8().constData());
|
||||
statement.append( it.value().getname());
|
||||
statement.append(");");
|
||||
logSQL(statement, kLogMsg_App);
|
||||
err=sqlite3_prepare(_db,statement.toUtf8(),statement.length(),
|
||||
@@ -697,9 +686,7 @@ void DBBrowserDB::updateSchema( )
|
||||
QString val1, val2;
|
||||
val1 = QString((const char *) sqlite3_column_text(vm, 0));
|
||||
val2 = QString((const char *) sqlite3_column_text(vm, 1));
|
||||
num.setNum(idxnum);
|
||||
idxmap[num] = DBBrowserIndex(GetDecodedQString(val1),GetDecodedQString(val2));
|
||||
idxnum ++;
|
||||
idxmap[val1] = DBBrowserIndex(GetDecodedQString(val1),GetDecodedQString(val2));
|
||||
}
|
||||
sqlite3_finalize(vm);
|
||||
}else{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef SQLITEDB_H
|
||||
#define SQLITEDB_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <qstringlist.h>
|
||||
#include <qmap.h>
|
||||
#include <qobject.h>
|
||||
|
||||
Reference in New Issue
Block a user