summaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp')
-rw-r--r--SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp35
1 files changed, 29 insertions, 6 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp b/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp
index 56accd0..1b47433 100644
--- a/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp
+++ b/SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp
@@ -208,6 +208,7 @@ void TableWindow::createStructureActions()
ui->structureToolBar->addAction(actionMap[POPULATE]);
ui->structureToolBar->addSeparator();
createAction(CREATE_SIMILAR, ICONS.TABLE_CREATE_SIMILAR, tr("Create similar table", "table window"), this, SLOT(createSimilarTable()), ui->structureToolBar);
+ createAction(RESET_AUTOINCREMENT, ICONS.RESET_AUTOINCREMENT, tr("Reset autoincrement value", "table window"), this, SLOT(resetAutoincrement()), ui->structureToolBar);
// Table constraints
createAction(ADD_TABLE_CONSTRAINT, ICONS.TABLE_CONSTRAINT_ADD, tr("Add table constraint", "table window"), this, SLOT(addConstraint()), ui->tableConstraintsToolbar, ui->tableConstraintsView);
@@ -834,6 +835,24 @@ void TableWindow::rollbackStructure()
updateStructureCommitState();
updateStructureToolbarState();
updateTableConstraintsToolbarState();
+ updateDdlTab();
+}
+
+void TableWindow::resetAutoincrement()
+{
+ if (!existingTable)
+ return;
+
+ QMessageBox::StandardButton btn = QMessageBox::question(this, tr("Reset autoincrement"), tr("Are you sure you want to reset autoincrement value for table '%1'?")
+ .arg(table));
+ if (btn != QMessageBox::Yes)
+ return;
+
+ SqlQueryPtr res = db->exec("DELETE FROM sqlite_sequence WHERE name = ?;", {table});
+ if (res->isError())
+ notifyError(tr("An error occurred while trying to reset autoincrement value for table '%1': %2").arg(table, res->getErrorText()));
+ else
+ notifyInfo(tr("Autoincrement value for table '%1' has been reset successfly.").arg(table));
}
void TableWindow::addColumn()
@@ -947,15 +966,15 @@ bool TableWindow::validate(bool skipWarning)
if (!hasPk)
{
- notifyError(tr("Cannot create table without ROWID, if it has no PRIMARY KEY defined."
- " Either uncheck the WITHOUT ROWID, or define a PRIMARY KEY."));
+ notifyError(tr("Cannot create table %1, if it has no primary key defined."
+ " Either uncheck the %2, or define a primary key.").arg("WITHOUT ROWID", "WITHOUT ROWID"));
return false;
}
if (isPkAutoIncr)
{
- notifyError(tr("Cannot use AUTOINCREMENT for PRIMARY KEY when WITHOUT ROWID clause is used."
- " Either uncheck the WITHOUT ROWID, or the AUTOINCREMENT in a PRIMARY KEY."));
+ notifyError(tr("Cannot use autoincrement for primary key when %1 clause is used."
+ " Either uncheck the %2, or the autoincrement in a primary key.").arg("WITHOUT ROWID", "WITHOUT ROWID"));
return false;
}
}
@@ -1023,9 +1042,12 @@ void TableWindow::applyInitialTab()
void TableWindow::updateDdlTab()
{
- CodeFormatter* formatter = SQLITESTUDIO->getCodeFormatter();
createTable->rebuildTokens();
- ui->ddlEdit->setPlainText(formatter->format("sql", createTable->detokenize(), db));
+ QString ddl = createTable->detokenize();
+ if (createTable->columns.size() > 0)
+ ddl = SQLITESTUDIO->getCodeFormatter()->format("sql", ddl, db);
+
+ ui->ddlEdit->setPlainText(ddl);
}
void TableWindow::updateNewTableState()
@@ -1037,6 +1059,7 @@ void TableWindow::updateNewTableState()
actionMap[IMPORT]->setEnabled(existingTable);
actionMap[POPULATE]->setEnabled(existingTable);
actionMap[CREATE_SIMILAR]->setEnabled(existingTable);
+ actionMap[RESET_AUTOINCREMENT]->setEnabled(existingTable);
actionMap[REFRESH_STRUCTURE]->setEnabled(existingTable);
}