mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 02:50:46 -06:00
Use references instead of pointers where it's possible
In our case DDBrowserDB shares lifetime scope with MainWindow, so there's no need to pass pointers back and forth.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
|
||||
CreateIndexDialog::CreateIndexDialog(DBBrowserDB* db, QWidget* parent)
|
||||
CreateIndexDialog::CreateIndexDialog(DBBrowserDB& db, QWidget* parent)
|
||||
: QDialog(parent),
|
||||
pdb(db),
|
||||
ui(new Ui::CreateIndexDialog)
|
||||
@@ -15,7 +15,7 @@ CreateIndexDialog::CreateIndexDialog(DBBrowserDB* db, QWidget* parent)
|
||||
|
||||
// Get list of tables, sort it alphabetically and fill the combobox
|
||||
QMultiMap<QString, DBBrowserObject> dbobjs;
|
||||
QList<DBBrowserObject> tables = pdb->objMap.values("table");
|
||||
QList<DBBrowserObject> tables = pdb.objMap.values("table");
|
||||
for(auto it=tables.constBegin();it!=tables.constEnd();++it)
|
||||
dbobjs.insert((*it).getname(), (*it));
|
||||
for(auto it=dbobjs.constBegin();it!=dbobjs.constEnd();++it)
|
||||
@@ -33,7 +33,7 @@ CreateIndexDialog::~CreateIndexDialog()
|
||||
void CreateIndexDialog::tableChanged(const QString& new_table)
|
||||
{
|
||||
// And fill the table again
|
||||
QStringList fields = pdb->getObjectByName(new_table).table.fieldNames();
|
||||
QStringList fields = pdb.getObjectByName(new_table).table.fieldNames();
|
||||
ui->tableIndexColumns->setRowCount(fields.size());
|
||||
for(int i=0; i < fields.size(); ++i)
|
||||
{
|
||||
@@ -94,8 +94,8 @@ void CreateIndexDialog::accept()
|
||||
sql.chop(1); // Remove last comma
|
||||
sql.append(");");
|
||||
|
||||
if(pdb->executeSQL(sql))
|
||||
if(pdb.executeSQL(sql))
|
||||
QDialog::accept();
|
||||
else
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("Creating the index failed:\n%1").arg(pdb->lastErrorMessage));
|
||||
QMessageBox::warning(this, QApplication::applicationName(), tr("Creating the index failed:\n%1").arg(pdb.lastErrorMessage));
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class CreateIndexDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CreateIndexDialog(DBBrowserDB* db, QWidget* parent = 0);
|
||||
explicit CreateIndexDialog(DBBrowserDB& db, QWidget* parent = 0);
|
||||
~CreateIndexDialog();
|
||||
|
||||
private slots:
|
||||
@@ -23,7 +23,7 @@ private slots:
|
||||
void checkInput();
|
||||
|
||||
private:
|
||||
DBBrowserDB* pdb;
|
||||
DBBrowserDB& pdb;
|
||||
Ui::CreateIndexDialog* ui;
|
||||
};
|
||||
|
||||
|
||||
@@ -229,7 +229,7 @@ QMimeData* DbStructureModel::mimeData(const QModelIndexList& indices) const
|
||||
// If it is a table also add the content
|
||||
if(data(index.sibling(index.row(), 1), Qt::DisplayRole).toString() == "table")
|
||||
{
|
||||
SqliteTableModel tableModel(0, &m_db);
|
||||
SqliteTableModel tableModel(m_db);
|
||||
tableModel.setTable(data(index.sibling(index.row(), 0), Qt::DisplayRole).toString());
|
||||
for(int i=0; i < tableModel.rowCount(); ++i)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <QDateTime>
|
||||
#include <QKeyEvent>
|
||||
|
||||
EditTableDialog::EditTableDialog(DBBrowserDB* db, const QString& tableName, bool createTable, QWidget* parent)
|
||||
EditTableDialog::EditTableDialog(DBBrowserDB& db, const QString& tableName, bool createTable, QWidget* parent)
|
||||
: QDialog(parent),
|
||||
ui(new Ui::EditTableDialog),
|
||||
pdb(db),
|
||||
@@ -28,7 +28,7 @@ EditTableDialog::EditTableDialog(DBBrowserDB* db, const QString& tableName, bool
|
||||
if(m_bNewTable == false)
|
||||
{
|
||||
// Existing table, so load and set the current layout
|
||||
QString sTablesql = pdb->getObjectByName(curTable).getsql();
|
||||
QString sTablesql = pdb.getObjectByName(curTable).getsql();
|
||||
QPair<sqlb::Table, bool> parse_result = sqlb::Table::parseSQL(sTablesql);
|
||||
m_table = parse_result.first;
|
||||
ui->labelEditWarning->setVisible(!parse_result.second);
|
||||
@@ -39,7 +39,7 @@ EditTableDialog::EditTableDialog(DBBrowserDB* db, const QString& tableName, bool
|
||||
}
|
||||
|
||||
// And create a savepoint
|
||||
pdb->setSavepoint(m_sRestorePointName);
|
||||
pdb.setSavepoint(m_sRestorePointName);
|
||||
|
||||
// Update UI
|
||||
ui->editTableName->setText(curTable);
|
||||
@@ -138,12 +138,12 @@ void EditTableDialog::accept()
|
||||
if(m_bNewTable)
|
||||
{
|
||||
// Creation of new table
|
||||
if(!pdb->executeSQL(m_table.sql()))
|
||||
if(!pdb.executeSQL(m_table.sql()))
|
||||
{
|
||||
QMessageBox::warning(
|
||||
this,
|
||||
QApplication::applicationName(),
|
||||
tr("Error creating table. Message from database engine:\n%1").arg(pdb->lastErrorMessage));
|
||||
tr("Error creating table. Message from database engine:\n%1").arg(pdb.lastErrorMessage));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -152,9 +152,9 @@ void EditTableDialog::accept()
|
||||
// Rename table if necessary
|
||||
if(ui->editTableName->text() != curTable)
|
||||
{
|
||||
if(!pdb->renameTable(curTable, ui->editTableName->text()))
|
||||
if(!pdb.renameTable(curTable, ui->editTableName->text()))
|
||||
{
|
||||
QMessageBox::warning(this, QApplication::applicationName(), pdb->lastErrorMessage);
|
||||
QMessageBox::warning(this, QApplication::applicationName(), pdb.lastErrorMessage);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -166,7 +166,7 @@ void EditTableDialog::accept()
|
||||
void EditTableDialog::reject()
|
||||
{
|
||||
// Then rollback to our savepoint
|
||||
pdb->revertToSavepoint(m_sRestorePointName);
|
||||
pdb.revertToSavepoint(m_sRestorePointName);
|
||||
|
||||
QDialog::reject();
|
||||
}
|
||||
@@ -206,7 +206,7 @@ void EditTableDialog::updateTypes()
|
||||
|
||||
m_table.fields().at(index)->setType(type);
|
||||
if(!m_bNewTable)
|
||||
pdb->renameColumn(curTable, column, m_table.fields().at(index));
|
||||
pdb.renameColumn(curTable, column, m_table.fields().at(index));
|
||||
checkInput();
|
||||
}
|
||||
}
|
||||
@@ -239,7 +239,7 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
|
||||
if(!m_bNewTable)
|
||||
{
|
||||
sqlb::FieldVector pk = m_table.primaryKey();
|
||||
foreach(const DBBrowserObject& fkobj, pdb->objMap.values("table"))
|
||||
foreach(const DBBrowserObject& fkobj, pdb.objMap.values("table"))
|
||||
{
|
||||
QList<sqlb::ConstraintPtr> fks = fkobj.table.constraints(sqlb::FieldVector(), sqlb::Constraint::ForeignKeyConstraintType);
|
||||
foreach(sqlb::ConstraintPtr fkptr, fks)
|
||||
@@ -303,9 +303,9 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
|
||||
// Because our renameColumn() function fails when setting a column to Not Null when it already contains some NULL values
|
||||
// we need to check for this case and cancel here. Maybe we can think of some way to modify the INSERT INTO ... SELECT statement
|
||||
// to at least replace all troublesome NULL values by the default value
|
||||
SqliteTableModel m(this, pdb);
|
||||
SqliteTableModel m(pdb, this);
|
||||
m.setQuery(QString("SELECT COUNT(%1) FROM %2 WHERE %3 IS NULL;")
|
||||
.arg(sqlb::escapeIdentifier(pdb->getObjectByName(curTable).table.rowidColumn()))
|
||||
.arg(sqlb::escapeIdentifier(pdb.getObjectByName(curTable).table.rowidColumn()))
|
||||
.arg(sqlb::escapeIdentifier(curTable))
|
||||
.arg(sqlb::escapeIdentifier(field->name())));
|
||||
if(m.data(m.index(0, 0)).toInt() > 0)
|
||||
@@ -330,7 +330,7 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
|
||||
// First check if the contents of this column are all integers. If not this field cannot be set to AI
|
||||
if(!m_bNewTable)
|
||||
{
|
||||
SqliteTableModel m(this, pdb);
|
||||
SqliteTableModel m(pdb, this);
|
||||
m.setQuery(QString("SELECT COUNT(*) FROM %1 WHERE %2 <> CAST(%3 AS INTEGER);")
|
||||
.arg(sqlb::escapeIdentifier(curTable))
|
||||
.arg(sqlb::escapeIdentifier(field->name()))
|
||||
@@ -374,7 +374,7 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
|
||||
if(!m_bNewTable && item->checkState(column) == Qt::Checked)
|
||||
{
|
||||
// Because our renameColumn() function fails when setting a column to unique when it already contains the same values
|
||||
SqliteTableModel m(this, pdb);
|
||||
SqliteTableModel m(pdb, this);
|
||||
m.setQuery(QString("SELECT COUNT(%2) FROM %1;").arg(sqlb::escapeIdentifier(curTable)).arg(sqlb::escapeIdentifier(field->name())));
|
||||
int rowcount = m.data(m.index(0, 0)).toInt();
|
||||
m.setQuery(QString("SELECT COUNT(DISTINCT %2) FROM %1;").arg(sqlb::escapeIdentifier(curTable)).arg(sqlb::escapeIdentifier(field->name())));
|
||||
@@ -441,7 +441,7 @@ void EditTableDialog::itemChanged(QTreeWidgetItem *item, int column)
|
||||
}
|
||||
|
||||
if(callRenameColumn)
|
||||
pdb->renameColumn(curTable, oldFieldName, field);
|
||||
pdb.renameColumn(curTable, oldFieldName, field);
|
||||
}
|
||||
|
||||
checkInput();
|
||||
@@ -498,7 +498,7 @@ void EditTableDialog::addField()
|
||||
|
||||
// Actually add the new column to the table if we're editing an existing table
|
||||
if(!m_bNewTable)
|
||||
pdb->addColumn(curTable, f);
|
||||
pdb.addColumn(curTable, f);
|
||||
|
||||
checkInput();
|
||||
}
|
||||
@@ -526,12 +526,12 @@ void EditTableDialog::removeField()
|
||||
QString msg = tr("Are you sure you want to delete the field '%1'?\nAll data currently stored in this field will be lost.").arg(ui->treeWidget->currentItem()->text(0));
|
||||
if(QMessageBox::warning(this, QApplication::applicationName(), msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes)
|
||||
{
|
||||
if(!pdb->renameColumn(curTable, ui->treeWidget->currentItem()->text(0), sqlb::FieldPtr()))
|
||||
if(!pdb.renameColumn(curTable, ui->treeWidget->currentItem()->text(0), sqlb::FieldPtr()))
|
||||
{
|
||||
QMessageBox::warning(0, QApplication::applicationName(), pdb->lastErrorMessage);
|
||||
QMessageBox::warning(0, QApplication::applicationName(), pdb.lastErrorMessage);
|
||||
} else {
|
||||
//relayout
|
||||
QString sTablesql = pdb->getObjectByName(curTable).getsql();
|
||||
QString sTablesql = pdb.getObjectByName(curTable).getsql();
|
||||
m_table = sqlb::Table::parseSQL(sTablesql).first;
|
||||
populateFields();
|
||||
}
|
||||
@@ -604,17 +604,17 @@ void EditTableDialog::moveCurrentField(bool down)
|
||||
// Editing an old one
|
||||
|
||||
// Move the actual column
|
||||
if(!pdb->renameColumn(
|
||||
if(!pdb.renameColumn(
|
||||
curTable,
|
||||
ui->treeWidget->currentItem()->text(0),
|
||||
m_table.fields().at(ui->treeWidget->indexOfTopLevelItem(ui->treeWidget->currentItem())),
|
||||
(down ? 1 : -1)
|
||||
))
|
||||
{
|
||||
QMessageBox::warning(0, QApplication::applicationName(), pdb->lastErrorMessage);
|
||||
QMessageBox::warning(0, QApplication::applicationName(), pdb.lastErrorMessage);
|
||||
} else {
|
||||
// Reload table SQL
|
||||
QString sTablesql = pdb->getObjectByName(curTable).getsql();
|
||||
QString sTablesql = pdb.getObjectByName(curTable).getsql();
|
||||
m_table = sqlb::Table::parseSQL(sTablesql).first;
|
||||
populateFields();
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class EditTableDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EditTableDialog(DBBrowserDB* pdb, const QString& tableName, bool createTable, QWidget* parent = 0);
|
||||
explicit EditTableDialog(DBBrowserDB& pdb, const QString& tableName, bool createTable, QWidget* parent = 0);
|
||||
~EditTableDialog();
|
||||
|
||||
protected:
|
||||
@@ -60,7 +60,7 @@ private slots:
|
||||
|
||||
private:
|
||||
Ui::EditTableDialog* ui;
|
||||
DBBrowserDB* pdb;
|
||||
DBBrowserDB& pdb;
|
||||
QString curTable;
|
||||
sqlb::Table m_table;
|
||||
QStringList types;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
ExportDataDialog::ExportDataDialog(DBBrowserDB* db, ExportFormats format, QWidget* parent, const QString& query, const QString& selection)
|
||||
ExportDataDialog::ExportDataDialog(DBBrowserDB& db, ExportFormats format, QWidget* parent, const QString& query, const QString& selection)
|
||||
: QDialog(parent),
|
||||
ui(new Ui::ExportDataDialog),
|
||||
pdb(db),
|
||||
@@ -40,7 +40,7 @@ ExportDataDialog::ExportDataDialog(DBBrowserDB* db, ExportFormats format, QWidge
|
||||
if(query.isEmpty())
|
||||
{
|
||||
// Get list of tables to export
|
||||
objectMap objects = pdb->getBrowsableObjects();
|
||||
objectMap objects = pdb.getBrowsableObjects();
|
||||
foreach(const DBBrowserObject& obj, objects)
|
||||
ui->listTables->addItem(new QListWidgetItem(QIcon(QString(":icons/%1").arg(obj.gettype())), obj.getname()));
|
||||
|
||||
@@ -101,7 +101,7 @@ bool ExportDataDialog::exportQueryCsv(const QString& sQuery, const QString& sFil
|
||||
QByteArray utf8Query = sQuery.toUtf8();
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
int status = sqlite3_prepare_v2(pdb->_db, utf8Query.data(), utf8Query.size(), &stmt, NULL);
|
||||
int status = sqlite3_prepare_v2(pdb._db, utf8Query.data(), utf8Query.size(), &stmt, NULL);
|
||||
if(SQLITE_OK == status)
|
||||
{
|
||||
if(ui->checkHeader->isChecked())
|
||||
@@ -177,7 +177,7 @@ bool ExportDataDialog::exportQueryJson(const QString& sQuery, const QString& sFi
|
||||
{
|
||||
QByteArray utf8Query = sQuery.toUtf8();
|
||||
sqlite3_stmt *stmt;
|
||||
int status = sqlite3_prepare_v2(pdb->_db, utf8Query.data(), utf8Query.size(), &stmt, NULL);
|
||||
int status = sqlite3_prepare_v2(pdb._db, utf8Query.data(), utf8Query.size(), &stmt, NULL);
|
||||
|
||||
QJsonArray json_table;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
ExportFormatJson,
|
||||
};
|
||||
|
||||
explicit ExportDataDialog(DBBrowserDB* db, ExportFormats format, QWidget* parent = 0, const QString& query = "", const QString& selection = "");
|
||||
explicit ExportDataDialog(DBBrowserDB& db, ExportFormats format, QWidget* parent = 0, const QString& query = "", const QString& selection = "");
|
||||
~ExportDataDialog();
|
||||
|
||||
private slots:
|
||||
@@ -43,7 +43,7 @@ private:
|
||||
|
||||
private:
|
||||
Ui::ExportDataDialog* ui;
|
||||
DBBrowserDB* pdb;
|
||||
DBBrowserDB& pdb;
|
||||
|
||||
ExportFormats m_format;
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
MainWindow::MainWindow(QWidget* parent)
|
||||
: QMainWindow(parent),
|
||||
ui(new Ui::MainWindow),
|
||||
m_browseTableModel(new SqliteTableModel(this, &db, Settings::getSettingsValue("db", "prefetchsize").toInt())),
|
||||
m_browseTableModel(new SqliteTableModel(db, this, Settings::getSettingsValue("db", "prefetchsize").toInt())),
|
||||
m_currentTabTableModel(m_browseTableModel),
|
||||
editDock(new EditDialog(this)),
|
||||
gotoValidator(new QIntValidator(0, 0, this))
|
||||
@@ -713,7 +713,7 @@ void MainWindow::createTable()
|
||||
return;
|
||||
}
|
||||
|
||||
EditTableDialog dialog(&db, "", true, this);
|
||||
EditTableDialog dialog(db, "", true, this);
|
||||
if(dialog.exec())
|
||||
{
|
||||
populateTable();
|
||||
@@ -727,7 +727,7 @@ void MainWindow::createIndex()
|
||||
return;
|
||||
}
|
||||
|
||||
CreateIndexDialog dialog(&db, this);
|
||||
CreateIndexDialog dialog(db, this);
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
@@ -771,7 +771,7 @@ void MainWindow::editTable()
|
||||
}
|
||||
QString tableToEdit = ui->dbTreeWidget->model()->data(ui->dbTreeWidget->currentIndex().sibling(ui->dbTreeWidget->currentIndex().row(), 0)).toString();
|
||||
|
||||
EditTableDialog dialog(&db, tableToEdit, false, this);
|
||||
EditTableDialog dialog(db, tableToEdit, false, this);
|
||||
if(dialog.exec())
|
||||
populateTable();
|
||||
}
|
||||
@@ -1084,7 +1084,7 @@ void MainWindow::exportTableToCSV()
|
||||
current_table = ui->comboBrowseTable->currentText();
|
||||
|
||||
// Open dialog
|
||||
ExportDataDialog dialog(&db, ExportDataDialog::ExportFormatCsv, this, "", current_table);
|
||||
ExportDataDialog dialog(db, ExportDataDialog::ExportFormatCsv, this, "", current_table);
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
@@ -1101,7 +1101,7 @@ void MainWindow::exportTableToJson()
|
||||
current_table = ui->comboBrowseTable->currentText();
|
||||
|
||||
// Open dialog
|
||||
ExportDataDialog dialog(&db, ExportDataDialog::ExportFormatJson, this, "", current_table);
|
||||
ExportDataDialog dialog(db, ExportDataDialog::ExportFormatJson, this, "", current_table);
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
@@ -1554,7 +1554,7 @@ unsigned int MainWindow::openSqlTab(bool resetCounter)
|
||||
tabNumber = 0;
|
||||
|
||||
// Create new tab, add it to the tab widget and select it
|
||||
SqlExecutionArea* w = new SqlExecutionArea(this, &db);
|
||||
SqlExecutionArea* w = new SqlExecutionArea(db, this);
|
||||
int index = ui->tabSqlAreas->addTab(w, QString("SQL %1").arg(++tabNumber));
|
||||
ui->tabSqlAreas->setCurrentIndex(index);
|
||||
w->getEditor()->setFocus();
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <QInputDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
SqlExecutionArea::SqlExecutionArea(QWidget* parent, DBBrowserDB* _db) :
|
||||
SqlExecutionArea::SqlExecutionArea(DBBrowserDB& _db, QWidget* parent) :
|
||||
QWidget(parent),
|
||||
db(_db),
|
||||
ui(new Ui::SqlExecutionArea)
|
||||
@@ -20,7 +20,7 @@ SqlExecutionArea::SqlExecutionArea(QWidget* parent, DBBrowserDB* _db) :
|
||||
ui->setupUi(this);
|
||||
|
||||
// Create model
|
||||
model = new SqliteTableModel(this, db, Settings::getSettingsValue("db", "prefetchsize").toInt());
|
||||
model = new SqliteTableModel(db, this, Settings::getSettingsValue("db", "prefetchsize").toInt());
|
||||
ui->tableResult->setModel(model);
|
||||
|
||||
// Create popup menu for save button
|
||||
@@ -97,7 +97,7 @@ void SqlExecutionArea::saveAsView()
|
||||
name = QInputDialog::getText(this, qApp->applicationName(), tr("Please specify the view name")).trimmed();
|
||||
if(name.isEmpty())
|
||||
break;
|
||||
if(!db->getObjectByName(name).getname().isEmpty())
|
||||
if(!db.getObjectByName(name).getname().isEmpty())
|
||||
QMessageBox::warning(this, qApp->applicationName(), tr("There is already an object with that name. Please choose a different name."));
|
||||
else
|
||||
break;
|
||||
@@ -106,10 +106,10 @@ void SqlExecutionArea::saveAsView()
|
||||
return;
|
||||
|
||||
// Create the view
|
||||
if(db->executeSQL(QString("CREATE VIEW %1 AS %2;").arg(sqlb::escapeIdentifier(name)).arg(model->query())))
|
||||
if(db.executeSQL(QString("CREATE VIEW %1 AS %2;").arg(sqlb::escapeIdentifier(name)).arg(model->query())))
|
||||
QMessageBox::information(this, qApp->applicationName(), tr("View successfully created."));
|
||||
else
|
||||
QMessageBox::warning(this, qApp->applicationName(), tr("Error creating view: %1").arg(db->lastErrorMessage));
|
||||
QMessageBox::warning(this, qApp->applicationName(), tr("Error creating view: %1").arg(db.lastErrorMessage));
|
||||
}
|
||||
|
||||
void SqlExecutionArea::reloadSettings()
|
||||
|
||||
@@ -22,7 +22,7 @@ class SqlExecutionArea : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SqlExecutionArea(QWidget* parent, DBBrowserDB* _db);
|
||||
explicit SqlExecutionArea(DBBrowserDB& _db, QWidget* parent = Q_NULLPTR);
|
||||
~SqlExecutionArea();
|
||||
|
||||
QString getSql() const;
|
||||
@@ -44,7 +44,7 @@ public slots:
|
||||
virtual void reloadSettings();
|
||||
|
||||
private:
|
||||
DBBrowserDB* db;
|
||||
DBBrowserDB& db;
|
||||
SqliteTableModel* model;
|
||||
QMenu* menuPopupSave;
|
||||
QString sqlFileName;
|
||||
|
||||
@@ -469,7 +469,7 @@ bool DBBrowserDB::dump(const QString& filename,
|
||||
it.remove();
|
||||
} else {
|
||||
// Otherwise get the number of records in this table
|
||||
SqliteTableModel tableModel(0, this);
|
||||
SqliteTableModel tableModel(*this);
|
||||
tableModel.setTable(it.value().getname());
|
||||
numRecordsTotal += tableModel.totalRowCount();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include <QFile>
|
||||
#include <QUrl>
|
||||
|
||||
SqliteTableModel::SqliteTableModel(QObject* parent, DBBrowserDB* db, size_t chunkSize, const QString& encoding)
|
||||
SqliteTableModel::SqliteTableModel(DBBrowserDB& db, QObject* parent, size_t chunkSize, const QString& encoding)
|
||||
: QAbstractTableModel(parent)
|
||||
, m_db(db)
|
||||
, m_rowCount(0)
|
||||
@@ -47,9 +47,9 @@ void SqliteTableModel::setTable(const QString& table, const QVector<QString>& di
|
||||
m_vDataTypes.push_back(SQLITE_INTEGER);
|
||||
|
||||
bool allOk = false;
|
||||
if(m_db->getObjectByName(table).gettype() == "table")
|
||||
if(m_db.getObjectByName(table).gettype() == "table")
|
||||
{
|
||||
sqlb::Table t = sqlb::Table::parseSQL(m_db->getObjectByName(table).getsql()).first;
|
||||
sqlb::Table t = sqlb::Table::parseSQL(m_db.getObjectByName(table).getsql()).first;
|
||||
if(t.fields().size()) // parsing was OK
|
||||
{
|
||||
m_headers.push_back(t.rowidColumn());
|
||||
@@ -97,7 +97,7 @@ void SqliteTableModel::setQuery(const QString& sQuery, bool dontClearHeaders)
|
||||
if(!dontClearHeaders)
|
||||
reset();
|
||||
|
||||
if(!m_db->isOpen())
|
||||
if(!m_db.isOpen())
|
||||
return;
|
||||
|
||||
m_sQuery = sQuery.trimmed();
|
||||
@@ -137,7 +137,7 @@ int SqliteTableModel::getQueryRowCount()
|
||||
// So just execute the statement as it is and fetch all results counting the rows
|
||||
sqlite3_stmt* stmt;
|
||||
QByteArray utf8Query = m_sQuery.toUtf8();
|
||||
if(sqlite3_prepare_v2(m_db->_db, utf8Query, utf8Query.size(), &stmt, NULL) == SQLITE_OK)
|
||||
if(sqlite3_prepare_v2(m_db._db, utf8Query, utf8Query.size(), &stmt, NULL) == SQLITE_OK)
|
||||
{
|
||||
retval = 0;
|
||||
while(sqlite3_step(stmt) == SQLITE_ROW)
|
||||
@@ -152,11 +152,11 @@ int SqliteTableModel::getQueryRowCount()
|
||||
} else {
|
||||
// If it is a normal query - hopefully starting with SELECT - just do a COUNT on it and return the results
|
||||
QString sCountQuery = QString("SELECT COUNT(*) FROM (%1);").arg(rtrimChar(m_sQuery, ';'));
|
||||
m_db->logSQL(sCountQuery, kLogMsg_App);
|
||||
m_db.logSQL(sCountQuery, kLogMsg_App);
|
||||
QByteArray utf8Query = sCountQuery.toUtf8();
|
||||
|
||||
sqlite3_stmt* stmt;
|
||||
int status = sqlite3_prepare_v2(m_db->_db, utf8Query, utf8Query.size(), &stmt, NULL);
|
||||
int status = sqlite3_prepare_v2(m_db._db, utf8Query, utf8Query.size(), &stmt, NULL);
|
||||
if(status == SQLITE_OK)
|
||||
{
|
||||
status = sqlite3_step(stmt);
|
||||
@@ -267,7 +267,7 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const
|
||||
|
||||
sqlb::ForeignKeyClause SqliteTableModel::getForeignKeyClause(int column) const
|
||||
{
|
||||
DBBrowserObject obj = m_db->getObjectByName(m_sTable);
|
||||
DBBrowserObject obj = m_db.getObjectByName(m_sTable);
|
||||
if(obj.getname().size() && (column >= 0 && column < obj.table.fields().count()))
|
||||
{
|
||||
// Note that the rowid column has number -1 here, it can safely be excluded since there will never be a
|
||||
@@ -301,7 +301,7 @@ bool SqliteTableModel::setTypedData(const QModelIndex& index, bool isBlob, const
|
||||
if(oldValue == newValue && oldValue.isNull() == newValue.isNull())
|
||||
return true;
|
||||
|
||||
if(m_db->updateRecord(m_sTable, m_headers.at(index.column()), m_data[index.row()].at(0), newValue, isBlob))
|
||||
if(m_db.updateRecord(m_sTable, m_headers.at(index.column()), m_data[index.row()].at(0), newValue, isBlob))
|
||||
{
|
||||
// Only update the cache if this row has already been read, if not there's no need to do any changes to the cache
|
||||
if(index.row() < m_data.size())
|
||||
@@ -310,7 +310,7 @@ bool SqliteTableModel::setTypedData(const QModelIndex& index, bool isBlob, const
|
||||
emit(dataChanged(index, index));
|
||||
return true;
|
||||
} else {
|
||||
QMessageBox::warning(0, qApp->applicationName(), tr("Error changing data:\n%1").arg(m_db->lastErrorMessage));
|
||||
QMessageBox::warning(0, qApp->applicationName(), tr("Error changing data:\n%1").arg(m_db.lastErrorMessage));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -375,7 +375,7 @@ bool SqliteTableModel::insertRows(int row, int count, const QModelIndex& parent)
|
||||
DataType tempList;
|
||||
for(int i=row; i < row + count; ++i)
|
||||
{
|
||||
QString rowid = m_db->addRecord(m_sTable);
|
||||
QString rowid = m_db.addRecord(m_sTable);
|
||||
if(rowid.isNull())
|
||||
{
|
||||
return false;
|
||||
@@ -386,7 +386,7 @@ bool SqliteTableModel::insertRows(int row, int count, const QModelIndex& parent)
|
||||
|
||||
// update column with default values
|
||||
QByteArrayList rowdata;
|
||||
if( m_db->getRow(m_sTable, rowid, rowdata) )
|
||||
if( m_db.getRow(m_sTable, rowid, rowdata) )
|
||||
{
|
||||
for(int j=1; j < m_headers.size(); ++j)
|
||||
{
|
||||
@@ -417,7 +417,7 @@ bool SqliteTableModel::removeRows(int row, int count, const QModelIndex& parent)
|
||||
m_data.removeAt(row + i);
|
||||
--m_rowCount;
|
||||
}
|
||||
if(!m_db->deleteRecords(m_sTable, rowids))
|
||||
if(!m_db.deleteRecords(m_sTable, rowids))
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
@@ -432,7 +432,7 @@ QModelIndex SqliteTableModel::dittoRecord(int old_row)
|
||||
int firstEditedColumn = 0;
|
||||
int new_row = rowCount() - 1;
|
||||
|
||||
sqlb::Table t = sqlb::Table::parseSQL(m_db->getObjectByName(m_sTable).getsql()).first;
|
||||
sqlb::Table t = sqlb::Table::parseSQL(m_db.getObjectByName(m_sTable).getsql()).first;
|
||||
|
||||
sqlb::FieldVector pk = t.primaryKey();
|
||||
for (int col = 0; col < t.fields().size(); ++col) {
|
||||
@@ -466,10 +466,10 @@ void SqliteTableModel::fetchData(unsigned int from, unsigned to)
|
||||
else
|
||||
sLimitQuery = queryTemp + QString(" LIMIT %1, %2;").arg(from).arg(to-from);
|
||||
}
|
||||
m_db->logSQL(sLimitQuery, kLogMsg_App);
|
||||
m_db.logSQL(sLimitQuery, kLogMsg_App);
|
||||
QByteArray utf8Query = sLimitQuery.toUtf8();
|
||||
sqlite3_stmt *stmt;
|
||||
int status = sqlite3_prepare_v2(m_db->_db, utf8Query, utf8Query.size(), &stmt, NULL);
|
||||
int status = sqlite3_prepare_v2(m_db._db, utf8Query, utf8Query.size(), &stmt, NULL);
|
||||
|
||||
if(SQLITE_OK == status)
|
||||
{
|
||||
@@ -557,7 +557,7 @@ QStringList SqliteTableModel::getColumns(const QString& sQuery, QVector<int>& fi
|
||||
{
|
||||
sqlite3_stmt* stmt;
|
||||
QByteArray utf8Query = sQuery.toUtf8();
|
||||
int status = sqlite3_prepare_v2(m_db->_db, utf8Query, utf8Query.size(), &stmt, NULL);
|
||||
int status = sqlite3_prepare_v2(m_db._db, utf8Query, utf8Query.size(), &stmt, NULL);
|
||||
QStringList listColumns;
|
||||
if(SQLITE_OK == status)
|
||||
{
|
||||
|
||||
@@ -17,7 +17,7 @@ class SqliteTableModel : public QAbstractTableModel
|
||||
#endif
|
||||
|
||||
public:
|
||||
explicit SqliteTableModel(QObject *parent = 0, DBBrowserDB* db = 0, size_t chunkSize = 50000, const QString& encoding = QString());
|
||||
explicit SqliteTableModel(DBBrowserDB& db, QObject *parent = 0, size_t chunkSize = 50000, const QString& encoding = QString());
|
||||
void reset();
|
||||
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
@@ -74,7 +74,7 @@ private:
|
||||
QByteArray encode(const QByteArray& str) const;
|
||||
QByteArray decode(const QByteArray& str) const;
|
||||
|
||||
DBBrowserDB* m_db;
|
||||
DBBrowserDB& m_db;
|
||||
int m_rowCount;
|
||||
QStringList m_headers;
|
||||
typedef QList<QByteArrayList> DataType;
|
||||
|
||||
Reference in New Issue
Block a user