db createColumn()

This commit is contained in:
Peter Mash Morgan
2010-10-05 14:25:16 +01:00
parent 17ef4e1455
commit 99bd96c26d
6 changed files with 74 additions and 40 deletions
+8 -15
View File
@@ -57,18 +57,7 @@ void editFieldForm::setInitialValues(bool is_new, QString table, QString fld_nam
return;
}
}
return;
typeBox->clear();
typeBox->insertItem(fld_type);
// QString tString = "";
// tString = "TEXT";
// if (type.compare(tString)!=0) typeBox->insertItem(tString);
// tString = "NUMERIC";
// if (type.compare(tString)!=0) typeBox->insertItem(tString);
// tString = "BLOB";
// if (type.compare(tString)!=0) typeBox->insertItem(tString);
// tString = "INTEGER PRIMARY KEY";
// if (type.compare(tString)!=0) typeBox->insertItem(tString);
//TODO enable custom
}
void editFieldForm::confirmEdit()
@@ -84,12 +73,16 @@ void editFieldForm::confirmEdit()
}
field_name = fieldname;
field_type = typeBox->currentText();
QString sql = QString("ALTER TABLE `%1` ");
qDebug(sql);
if(!pdb.executeSQL(sql)){
bool ok = pdb.createColumn(table_name, field_name, field_type);
if(!ok){
qDebug(pdb.lastErrorMessage);
return;
}
//qDebug("");
// if(!pdb.executeSQL(sql)){
// qDebug(pdb.lastErrorMessage);
// return;
// }
accept();
}
+3 -3
View File
@@ -113,19 +113,19 @@ public:
radioBLOB->setText(QApplication::translate("addFieldForm", "BLOB", 0, QApplication::UnicodeUTF8));
radioBLOB->setProperty("field_type", QVariant("BLOB"));
radioLayout->addWidget(radioBLOB);
//groupRadioTypes->addButton(radioBLOB);
groupRadioTypes->addButton(radioBLOB);
QRadioButton *radioINTPRIMARY = new QRadioButton();
radioINTPRIMARY->setText(QApplication::translate("addFieldForm", "INTEGER PRIMARY KEY", 0, QApplication::UnicodeUTF8));
radioINTPRIMARY->setProperty("field_type", QVariant("INTEGER PRIMARY KEY"));
radioLayout->addWidget(radioINTPRIMARY);
//groupRadioTypes->addButton(radioINTPRIMARY);
groupRadioTypes->addButton(radioINTPRIMARY);
QRadioButton *radioCustom = new QRadioButton();
radioCustom->setText(QApplication::translate("addFieldForm", "Custom", 0, QApplication::UnicodeUTF8));
radioCustom->setProperty("field_type", QVariant("__custom__"));
radioLayout->addWidget(radioCustom);
//groupRadioTypes->addButton(radioCustom);
groupRadioTypes->addButton(radioCustom);
QLineEdit *txtCustomType = new QLineEdit();
radioLayout->addWidget(txtCustomType);
+22 -2
View File
@@ -1229,6 +1229,7 @@ void mainForm::on_tree_selection_changed(){
if (!dbTreeWidget->selectionModel()->hasSelection()){
editDeleteTableActionPopup->setEnabled(false);
editModifyTableActionPopup->setEnabled(false);
editAddFieldActionPopup->setEnabled(false);
editModifyFieldActionPopup->setEnabled(false);
editDeleteFieldActionPopup->setEnabled(false);
return;
@@ -1237,10 +1238,12 @@ void mainForm::on_tree_selection_changed(){
if(dbTreeWidget->currentItem()->text(1) == "table"){
editDeleteTableActionPopup->setEnabled(true);
editModifyTableActionPopup->setEnabled(true);
editAddFieldActionPopup->setEnabled(true);
editModifyFieldActionPopup->setEnabled(false);
editDeleteFieldActionPopup->setEnabled(false);
}else if(dbTreeWidget->currentItem()->text(1) == "field"){
editAddFieldActionPopup->setEnabled(false);
editDeleteTableActionPopup->setEnabled(false);
editModifyTableActionPopup->setEnabled(false);
editModifyFieldActionPopup->setEnabled(true);
@@ -1249,8 +1252,25 @@ void mainForm::on_tree_selection_changed(){
}
void mainForm::on_add_field(){
qDebug("YES");
//if( !dbTreeWidget->currentItem() ){
// return;
//}
//QTreeWidgetItem *item = dbTreeWidget->currentItem();
editFieldForm *fieldForm = new editFieldForm( this, "editfield", true );
//qDebug(item->text(2));
fieldForm->setInitialValues(true, "TABLE_NAME", "", "NUMERIC");
fieldForm->setDB(this->db);
if (fieldForm->exec())
{
//modified = true;
//do the sql rename here
qDebug(fieldForm->field_name + fieldForm->field_type);
//item->setText(0,fieldForm->field_name);
//item->setText(2,fieldForm->field_type);
}
}
void mainForm::on_edit_field(){
qDebug("YES");
if( !dbTreeWidget->currentItem() ){
+11 -5
View File
@@ -270,18 +270,21 @@ public:
editModifyTableActionPopup->setIcon(QIcon(":/icons/table_modify"));
//** Modify Field
//** Add, Modify, Delete Field
editAddFieldActionPopup = new QAction(mainForm);
editAddFieldActionPopup->setText("Add Field");
editAddFieldActionPopup->setDisabled(true);
editAddFieldActionPopup->setIcon(QIcon(":/icons/field_add"));
editModifyFieldActionPopup = new QAction(mainForm);
editModifyFieldActionPopup->setText("Modify Field");
editModifyFieldActionPopup->setText("Modify Field");
editModifyFieldActionPopup->setDisabled(true);
editModifyFieldActionPopup->setIcon(QIcon(":/icons/field_edit"));
editDeleteFieldActionPopup = new QAction(mainForm);
editDeleteFieldActionPopup->setText("Delete Field");
editDeleteFieldActionPopup->setDisabled(true);
editDeleteFieldActionPopup->setIcon(QIcon(":/icons/field_delete"));
//** Create Index
@@ -317,9 +320,11 @@ public:
mainTab->setObjectName(QString::fromUtf8("mainTab"));
structure = new QWidget();
structure->setObjectName(QString::fromUtf8("structure"));
vboxLayout1 = new QVBoxLayout(structure);
vboxLayout1->setSpacing(6);
vboxLayout1->setContentsMargins(11, 11, 11, 11);
vboxLayout1->setSpacing(0);
vboxLayout1->setContentsMargins(0,0,0,0);
vboxLayout1->setObjectName(QString::fromUtf8("vboxLayout1"));
//**** Structure ***********************************
@@ -643,9 +648,9 @@ public:
QObject::connect(editModifyTableAction, SIGNAL(activated()), mainForm, SLOT(editTable()));
QObject::connect(editDeleteTableActionPopup, SIGNAL(activated()), mainForm, SLOT(deleteTablePopup()));
QObject::connect(editModifyTableActionPopup, SIGNAL(activated()), mainForm, SLOT(editTablePopup()));
QObject::connect(editAddFieldActionPopup, SIGNAL(activated()), mainForm, SLOT(on_add_field()));
QObject::connect(editModifyFieldActionPopup, SIGNAL(activated()), mainForm, SLOT(on_edit_field()));
QObject::connect(fileExportSQLAction, SIGNAL(activated()), mainForm, SLOT(exportDatabaseToSQL()));
QObject::connect(fileImportSQLAction, SIGNAL(activated()), mainForm, SLOT(importDatabaseFromSQL()));
QObject::connect(editPreferencesAction, SIGNAL(activated()), mainForm, SLOT(openPreferences()));
@@ -958,6 +963,7 @@ public:
public slots:
virtual void on_tree_context_menu(const QPoint & qPoint);
virtual void on_tree_selection_changed();
virtual void on_add_field();
virtual void on_edit_field();
virtual void fileOpen( const QString & fileName );
+26 -15
View File
@@ -275,26 +275,25 @@ bool DBBrowserDB::dump( const QString & filename)
bool DBBrowserDB::executeSQL ( const QString & statement, bool dirtyDB, bool logsql)
{
char *errmsg;
bool ok=false;
char *errmsg;
bool ok = false;
if (!isOpen()) return false;
if (!isOpen()) return false;
if (_db){
if (logsql) logSQL(statement, kLogMsg_App);
if (dirtyDB) setDirty(true);
if (SQLITE_OK==sqlite3_exec(_db,GetEncodedQString(statement),
NULL,NULL,&errmsg)){
ok=true;
}
if (_db){
if (logsql) logSQL(statement, kLogMsg_App);
if (dirtyDB) setDirty(true);
if (SQLITE_OK==sqlite3_exec(_db,GetEncodedQString(statement),
NULL,NULL,&errmsg)){
ok=true;
}
}
if (!ok){
lastErrorMessage = QString(errmsg);
return false;
}else{
if (!ok){
lastErrorMessage = QString(errmsg);
return false;
}
return true;
}
}
@@ -426,6 +425,18 @@ bool DBBrowserDB::browseTable( const QString & tablename )
return hasValidBrowseSet;
}
bool DBBrowserDB::createColumn( QString tablename, QString fieldname, QString fieldtype ){
qDebug("create column");
QString sql = QString("ALTER TABLE `%1` ADD COLUMN `%2` %3").arg(tablename).arg(fieldname).arg(fieldtype);
qDebug(sql);
return executeSQL(sql);
}
bool DBBrowserDB::renameTable(QString from_table, QString to_table){
qDebug("renameTable column");
return true;
}
void DBBrowserDB::getTableRecords( const QString & tablename )
{
sqlite3_stmt *vm;
+4
View File
@@ -106,6 +106,10 @@ public:
bool deleteRecord(int wrow);
bool updateRecord(int wrow, int wcol, const QString & wtext);
bool browseTable( const QString & tablename );
bool renameTable(QString from_table, QString to_table);
bool createColumn(QString table, QString field, QString type);
QStringList getTableFields(const QString & tablename);
QStringList getTableTypes(const QString & tablename);
QStringList getTableNames();