void Schema::populateSchemaTables() { foreach (Table *table, getTableList()) delete table; this->table_list.clear(); this->setTableCount(0); QList<Table*> table_list; QSqlQuery table_query(parent_database->getDatabaseConnection()); QString table_query_string = "SELECT 0, tablename FROM pg_tables WHERE schemaname='"+this->getName()+"' ORDER BY 1,2"; table_query.exec(table_query_string); setTableCount(table_query.size()); if(table_query.lastError().isValid()) { QMessageBox *error_message = new QMessageBox(QMessageBox::Critical, tr("Database error"), tr("Unable to retrieve schema tables.\n" "Check your database connection or permissions.\n"), QMessageBox::Cancel,0,Qt::Dialog); error_message->setWindowModality(Qt::NonModal); error_message->show(); return; } while (table_query.next()) { QString table_name = table_query.value(1).toString(); Table *table; if(table_query.value(0).toInt() == 0) { table = new Table(parent_database, this, table_name, table_list.size(), QColor(100,50,50)); table->setView(false); } else return; table->setSearched(true); if(mainwin->isColumnView()) table->verticalPosition2(); else table->defaultPosition(); QObject::connect(mainwin->getSearchBox(), SIGNAL(textChanged(QString)), table, SLOT(getSearchTerm(QString))); QObject::connect(mainwin, SIGNAL(showColumnView()), table, SLOT(verticalPosition2())); QObject::connect(table, SIGNAL(expandTable(Database *, Schema *, Table*)), mainwin, SLOT(showTableView(Database *, Schema *, Table*))); QObject::connect(table, SIGNAL(designTable(Database *, Schema *, Table*)), mainwin, SLOT(showDesignView(Database *, Schema *, Table*))); //QObject::connect(table, SIGNAL(rename(Database *, Schema *, Table*)), mainwin, SLOT(renameTable(Database *, Schema *, Table*))); QObject::connect(table, SIGNAL(clearTable(Database *, Schema *, Table*)), mainwin, SLOT(clearTableView(Database *, Schema *, Table*))); QObject::connect(table, SIGNAL(dropTable(Database *, Schema *, Table*)), mainwin, SLOT(dropTable(Database *, Schema *, Table*))); table_list.append(table); if(!parent_database->tableNamesList().contains(table_name)) parent_database->appendTableName(table_name); } setTableList(table_list); }
void Schema::populateSchemaFunctions() { foreach (Function *func, getFunctionList()) delete func; this->function_list.clear(); setFunctionCount(0); QList<Function*> function_list; QSqlQuery *function_query = new QSqlQuery(parent_database->getDatabaseConnection()); QString function_query_string = "SELECT proname,proargnames,proargtypes FROM pg_catalog.pg_namespace n JOIN pg_catalog.pg_proc p ON pronamespace = n.oid WHERE nspname='"+this->getName()+"' ORDER BY 1,2,3"; function_query->exec(function_query_string); setFunctionCount(function_query->size()); if(function_query->lastError().isValid()) { QMessageBox *error_message = new QMessageBox(QMessageBox::Critical, tr("Database error"), tr("Unable to retrieve schema tables.\n" "Check your database connection or permissions.\n"), QMessageBox::Cancel,0,Qt::Dialog); error_message->setWindowModality(Qt::NonModal); error_message->show(); return; } while (function_query->next()) { QString function_name = function_query->value(0).toString(); QString function_args = function_query->value(1).toString(); QString function_arg_types = function_query->value(2).toString(); Function *function = new Function(parent_database, this, function_name, function_args, function_arg_types, function_list.size(), QColor(100,100,50)); function->setSearched(true); if(mainwin->isColumnView()) function->verticalPosition2(); else function->defaultPosition(); QObject::connect(mainwin->getSearchBox(), SIGNAL(textChanged(QString)), function, SLOT(getSearchTerm(QString))); //QObject::connect(mainwin, SIGNAL(), function, SLOT(getSearchTerm(QString))); QObject::connect(mainwin, SIGNAL(showColumnView()), function, SLOT(verticalPosition2())); QObject::connect(function, SIGNAL(expandFunction(Schema*, Function*)), mainwin, SLOT(showFunctionEditor(Schema*, Function*))); //QObject::connect(function, SIGNAL(runFunction(Database *, Schema *, Function*)), mainwin, SLOT(runFunction(Database *, Schema *, Function*))); QObject::connect(function, SIGNAL(dropFunction(Database *, Schema *, Function*)), mainwin, SLOT(dropFunction(Database *, Schema *, Function*))); function_list.append(function); if(!parent_database->functionNamesList().contains(function_name)) parent_database->appendFunctionName(function_name); } setFunctionList(function_list); }
void Schema::populateSchemaViews() { foreach (View *view, getViewList()) delete view; this->view_list.clear(); QList<View*> view_list; QSqlQuery *view_query = new QSqlQuery(parent_database->getDatabaseConnection()); QString view_query_string = "SELECT 1, viewname FROM pg_views WHERE schemaname='"+this->getName()+"' ORDER BY 1,2"; view_query->exec(view_query_string); setViewCount(view_query->size()); if(view_query->lastError().isValid()) { QMessageBox *error_message = new QMessageBox(QMessageBox::Critical, tr("Database error"), tr("Unable to retrieve schema views.\n" "Check your database connection or permissions.\n"), QMessageBox::Cancel,0,Qt::Dialog); error_message->setWindowModality(Qt::NonModal); error_message->show(); return; } while (view_query->next()) { QString view_name = view_query->value(1).toString(); View *view; if(view_query->value(0).toInt() == 1) { view = new View(parent_database, this, view_name, view_list.size(), QColor(100,50,50)); } else { return; } view->setSearched(true); if(mainwin->isColumnView()) view->verticalPosition2(); else view->defaultPosition(); QObject::connect(mainwin->getSearchBox(), SIGNAL(textChanged(QString)), view, SLOT(getSearchTerm(QString))); QObject::connect(mainwin, SIGNAL(showColumnView()), view, SLOT(verticalPosition2())); QObject::connect(view, SIGNAL(expandView(Database *, Schema *, View*)), mainwin, SLOT(showViewView(Database *, Schema *, View*))); QObject::connect(view, SIGNAL(dropView(Database *, Schema *, View*)), mainwin, SLOT(dropView(Database *, Schema *, View*))); view_list.append(view); if(!mainwin->view_completer_list.contains(view_name)) mainwin->view_completer_list.append(view_name); } setViewList(view_list); }