diff options
| author | 2015-01-30 17:00:24 -0500 | |
|---|---|---|
| committer | 2015-01-30 17:00:24 -0500 | |
| commit | e4767514ed04e6a0bddf3f4a47f5f0b09e65e0ee (patch) | |
| tree | 86cadc2137831d44fa29fd40a2964f7fb1326de4 /SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp | |
| parent | 26ddfe11c2b7fac52e5f57dcd9f5223a50b2a9a7 (diff) | |
| parent | 016003905ca0e8e459e3dc33e786beda8ec92f45 (diff) | |
Merge tag 'upstream/3.0.2'
Upstream version 3.0.2
# gpg: Signature made Fri 30 Jan 2015 05:00:11 PM EST using RSA key ID EBE9BD91
# gpg: Good signature from "Unit 193 <unit193@gmail.com>"
# gpg: aka "Unit 193 <unit193@ninthfloor.org>"
# gpg: aka "Unit 193 <unit193@ubuntu.com>"
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/windows/tablewindow.cpp | 35 |
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); } |
