Alter table

This commit is contained in:
Peter Morgan
2010-10-05 08:05:05 +01:00
parent 7432e10610
commit d6a8425f20
4 changed files with 42 additions and 15 deletions

View File

@@ -18,6 +18,7 @@
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QComboBox>
#include <QtGui/QRadioButton>
#include <QtGui/QDialog>
#include <QtGui/QGridLayout>
#include <QtGui/QHBoxLayout>
@@ -51,8 +52,9 @@ public:
void setupUi(QDialog *addFieldForm)
{
if (addFieldForm->objectName().isEmpty())
if (addFieldForm->objectName().isEmpty()){
addFieldForm->setObjectName(QString::fromUtf8("addFieldForm"));
}
addFieldForm->resize(338, 136);
gridLayout = new QGridLayout(addFieldForm);
gridLayout->setSpacing(6);

View File

@@ -92,15 +92,35 @@ void editTableForm::renameTable()
//if (!pdb->executeSQL(QString("BEGIN TRANSACTION;"))){
// goto rollback;
//}
QString sql = QString("ALTER TABLE %1 RENAME TO %2").arg(curTable, newName);
qDebug(sql);
QString sql = QString("ALTER TABLE `%1` RENAME TO `%2`").arg(curTable, newName);
//qDebug(sql);
if (!pdb->executeSQL(sql)){
qDebug("OOPS");
qDebug( pdb->lastErrorMessage);
}else{
qDebug("OK");
//qDebug("OOPS");
//qDebug( pdb->lastErrorMessage);
QApplication::restoreOverrideCursor();
statusBar->showMessage(pdb->lastErrorMessage, 5000);
QString error("Error renaming table. Message from database engine:\n");
error.append(pdb->lastErrorMessage).append("\n\n").append(sql);
//error.append("").arg(pdb->lastErrorMessage).arg(sql);
//error.append(pdb->lastErrorMessage);
QMessageBox::warning( this, applicationName, error );
return;
}
QApplication::restoreOverrideCursor();
statusBar->showMessage(QString("Renamed %1 to %2").arg(curTable, newName), 5000);
//}
//sQApplication::restoreOverrideCursor(); // restore original cursor
//QString error = "Error renaming table. Message from database engine: ";
//error.append(pdb->lastErrorMessage);
// QMessageBox::warning( this, applicationName, error );
// pdb->executeSQ(QString("DROP TABLE TEMP_TABLE;"));
// //pdb->executeSQL(QString("ROLLBACK;"));
setActiveTable(pdb, curTable);
tableLine->setText(newName);
return;
// WTF is below ???
}
// sql = "CREATE TEMPORARY TABLE TEMP_TABLE(";
// Q3ListViewItemIterator it( fieldListView );
@@ -184,11 +204,11 @@ void editTableForm::renameTable()
// QApplication::restoreOverrideCursor(); // restore original cursor
// return;
//
rollback:
QApplication::restoreOverrideCursor(); // restore original cursor
QString error = "Error renaming table. Message from database engine: ";
error.append(pdb->lastErrorMessage);
QMessageBox::warning( this, applicationName, error );
// rollback:
// QApplication::restoreOverrideCursor(); // restore original cursor
//QString error = "Error renaming table. Message from database engine: ";
//error.append(pdb->lastErrorMessage);
// QMessageBox::warning( this, applicationName, error );
// pdb->executeSQL(QString("DROP TABLE TEMP_TABLE;"));
// //pdb->executeSQL(QString("ROLLBACK;"));
// setActiveTable(pdb, curTable);

View File

@@ -26,7 +26,7 @@
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
//#include <QtGui/QGridLayout>
#include <QtGui/QStatusBar>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLineEdit>
@@ -56,6 +56,8 @@ public:
QPushButton *closeButton;
QStatusBar *statusBar;
void setupUi(QDialog *editTableForm)
{
if (editTableForm->objectName().isEmpty()){
@@ -147,6 +149,8 @@ public:
closeButton->setObjectName(QString::fromUtf8("closeButton"));
bottomButtonBox->addWidget(closeButton);
statusBar = new QStatusBar();
mainVBoxLayout->addWidget(statusBar);
retranslateUi(editTableForm);
QObject::connect(closeButton, SIGNAL(clicked()), editTableForm, SLOT(accept()));

View File

@@ -43,6 +43,7 @@ public:
if (renameTableForm->objectName().isEmpty()){
renameTableForm->setObjectName(QString::fromUtf8("renameTableForm"));
}
renameTableForm->setWindowIcon(QIcon(":/icons/table_modify"));
renameTableForm->resize(313, 101);
vboxLayout = new QVBoxLayout(renameTableForm);
vboxLayout->setSpacing(6);
@@ -66,13 +67,13 @@ public:
closeButton = new QPushButton(renameTableForm);
closeButton->setObjectName(QString::fromUtf8("closeButton"));
closeButton->setIcon(QIcon(":/icons/cancel"));
hboxLayout->addWidget(closeButton);
renameButton = new QPushButton(renameTableForm);
renameButton->setObjectName(QString::fromUtf8("renameButton"));
renameButton->setDefault(true);
renameButton->setIcon(QIcon(":/icons/save"));
hboxLayout->addWidget(renameButton);