mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-27 14:30:00 -06:00
Support tables with empty table names
Apparently SQLite supports empty table names for whatever reason. This commit patches SQLiteBrowser to support databases with a table with an empty name. I haven't removed the check for an empty table name in the Create/Edit table dialog though because you probably really shouldn't create such a table. See issue #194.
This commit is contained in:
@@ -10,13 +10,13 @@
|
||||
#include <QDateTime>
|
||||
#include <QKeyEvent>
|
||||
|
||||
EditTableDialog::EditTableDialog(DBBrowserDB* db, const QString& tableName, QWidget* parent)
|
||||
EditTableDialog::EditTableDialog(DBBrowserDB* db, const QString& tableName, bool createTable, QWidget* parent)
|
||||
: QDialog(parent),
|
||||
ui(new Ui::EditTableDialog),
|
||||
pdb(db),
|
||||
curTable(tableName),
|
||||
m_table(tableName),
|
||||
m_bNewTable(true),
|
||||
m_bNewTable(createTable),
|
||||
m_sRestorePointName(QString("edittable_%1_save_%2").arg(curTable).arg(QDateTime::currentMSecsSinceEpoch()))
|
||||
{
|
||||
// Create UI
|
||||
@@ -27,10 +27,8 @@ EditTableDialog::EditTableDialog(DBBrowserDB* db, const QString& tableName, QWid
|
||||
m_sqliteSyntaxHighlighter = new SQLiteSyntaxHighlighter(ui->sqlTextEdit->document());
|
||||
|
||||
// Editing an existing table?
|
||||
if(curTable != "")
|
||||
if(m_bNewTable == false)
|
||||
{
|
||||
m_bNewTable = false; // we are editing an existing table
|
||||
|
||||
// Existing table, so load and set the current layout
|
||||
QString sTablesql = pdb->getObjectByName(curTable).getsql();
|
||||
m_table = sqlb::Table::parseSQL(sTablesql).first;
|
||||
|
||||
@@ -18,7 +18,7 @@ class EditTableDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EditTableDialog(DBBrowserDB* pdb, const QString& tableName, QWidget* parent = 0);
|
||||
explicit EditTableDialog(DBBrowserDB* pdb, const QString& tableName, bool createTable, QWidget* parent = 0);
|
||||
~EditTableDialog();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -327,7 +327,7 @@ void MainWindow::populateStructure()
|
||||
void MainWindow::populateTable(const QString & tablename, bool bKeepFilter)
|
||||
{
|
||||
// Remove the model-view link if the table name is empty in order to remove any data from the view
|
||||
if(tablename.isEmpty())
|
||||
if(ui->comboBrowseTable->model()->rowCount() == 0 && tablename.isEmpty())
|
||||
{
|
||||
ui->dataTable->setModel(0);
|
||||
if(qobject_cast<FilterTableHeader*>(ui->dataTable->horizontalHeader()))
|
||||
@@ -585,7 +585,7 @@ void MainWindow::createTable()
|
||||
return;
|
||||
}
|
||||
|
||||
EditTableDialog dialog(&db, "", this);
|
||||
EditTableDialog dialog(&db, "", true, this);
|
||||
if(dialog.exec())
|
||||
{
|
||||
populateStructure();
|
||||
@@ -651,7 +651,7 @@ void MainWindow::editTable()
|
||||
}
|
||||
QString tableToEdit = ui->dbTreeWidget->model()->data(ui->dbTreeWidget->currentIndex().sibling(ui->dbTreeWidget->currentIndex().row(), 0)).toString();
|
||||
|
||||
EditTableDialog dialog(&db, tableToEdit, this);
|
||||
EditTableDialog dialog(&db, tableToEdit, false, this);
|
||||
if(dialog.exec())
|
||||
{
|
||||
populateStructure();
|
||||
|
||||
@@ -100,10 +100,13 @@ void SQLiteSyntaxHighlighter::setTableNames(const QStringList &tablenames)
|
||||
{
|
||||
tableNameRules.clear();
|
||||
foreach(const QString& tblname, tablenames) {
|
||||
HighlightingRule rule;
|
||||
rule.pattern = QRegExp(QString("\\b%1\\b").arg(tblname));
|
||||
rule.format = tableFormat;
|
||||
tableNameRules.append(rule);
|
||||
if(!tblname.isEmpty())
|
||||
{
|
||||
HighlightingRule rule;
|
||||
rule.pattern = QRegExp(QString("\\b%1\\b").arg(tblname));
|
||||
rule.format = tableFormat;
|
||||
tableNameRules.append(rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ void SqliteTableModel::setTable(const QString& table)
|
||||
if(m_db->getObjectByName(table).gettype() == "table")
|
||||
{
|
||||
sqlb::Table t = sqlb::Table::parseSQL(m_db->getObjectByName(table).getsql()).first;
|
||||
if(t.name() != "") // parsing was OK
|
||||
if(t.fields().size()) // parsing was OK
|
||||
{
|
||||
m_headers.push_back(t.rowidColumn());
|
||||
m_headers.append(m_db->getObjectByName(table).table.fieldNames());
|
||||
|
||||
Reference in New Issue
Block a user