wxString dlgTablespace::GetSql2() { wxString sql; wxString name = GetName(); if (!tablespace) { sql += GetGrant(wxT("C"), wxT("TABLESPACE ") + qtIdent(name)); AppendComment(sql, wxT("TABLESPACE"), 0, tablespace); // check for changed or added vars for (int pos = 0 ; pos < lstVariables->GetItemCount() ; pos++) { sql += wxT("ALTER TABLESPACE ") + qtIdent(name) + wxT("\n SET (") + lstVariables->GetText(pos) + wxT("=") + lstVariables->GetText(pos, 1) + wxT(");\n"); } } return sql; }
wxString frmBackup::getCmdPart1() { pgServer *server = object->GetDatabase()->GetServer(); wxString cmd = backupExecutable; if (!server->GetName().IsEmpty()) cmd += wxT(" --host ") + server->GetName(); cmd += wxT(" --port ") + NumToStr((long)server->GetPort()) + wxT(" --username ") + commandLineCleanOption(qtIdent(server->GetUsername())); if (!cbRolename->GetValue().IsEmpty()) cmd += wxT(" --role ") + commandLineCleanOption(qtIdent(cbRolename->GetValue())); if (pgAppMinimumVersion(backupExecutable, 8, 4)) cmd += wxT(" --no-password "); if (object->GetConnection()->GetIsGreenplum()) cmd += wxT(" --gp-syntax "); return cmd; }
int dlgCollation::Go(bool modal) { if (collation) { // edit mode txtLcCollate->SetValue(collation->GetLcCollate()); txtLcCtype->SetValue(collation->GetLcCtype()); txtLocale->Disable(); txtLcCollate->Disable(); txtLcCtype->Disable(); cbCollation->Disable(); } else { // create mode // fill collation combobox cbCollation->Append(wxEmptyString); pgSet *set = connection->ExecuteSet( wxT("SELECT nspname, collname\n") wxT(" FROM pg_collation c, pg_namespace n\n") wxT(" WHERE c.collnamespace=n.oid\n") wxT(" ORDER BY nspname, collname")); if (set) { while (!set->Eof()) { wxString name = qtIdent(set->GetVal(wxT("nspname"))) + wxT(".") + qtIdent(set->GetVal(wxT("collname"))); cbCollation->Append(name); set->MoveNext(); } delete set; } cbCollation->SetSelection(0); } return dlgProperty::Go(modal); }
wxString frmRestore::getCmdPart1() { wxString cmd; cmd = restoreExecutable; if (!server->GetName().IsEmpty()) cmd += wxT(" --host ") + server->GetName(); cmd += wxT(" --port ") + NumToStr((long)server->GetPort()) + wxT(" --username ") + qtIdent(server->GetUsername()) + wxT(" --dbname ") + commandLineCleanOption(object->GetDatabase()->GetQuotedIdentifier()); return cmd; }
wxString dlgForeignServer::GetSql() { wxString sql, name; name = txtName->GetValue(); if (foreignserver) { // edit mode if (txtVersion->GetValue() != foreignserver->GetVersion()) { sql = wxT("ALTER SERVER ") + qtIdent(name) + wxT(" VERSION ") + qtDbString(txtVersion->GetValue()) + wxT(";\n"); } wxString sqloptions = GetOptionsSql(); if (sqloptions.Length() > 0) { sql += wxT("ALTER SERVER ") + name + wxT(" OPTIONS (") + sqloptions + wxT(");\n"); } AppendOwnerChange(sql, wxT("SERVER ") + qtIdent(name)); } else { // create mode sql = wxT("CREATE SERVER ") + qtIdent(name); if (!(txtType->GetValue()).IsEmpty()) sql += wxT("\n TYPE ") + qtDbString(txtType->GetValue()); if (!(txtVersion->GetValue()).IsEmpty()) sql += wxT("\n VERSION ") + qtDbString(txtVersion->GetValue()); sql += wxT("\n FOREIGN DATA WRAPPER ") + qtIdent(foreigndatawrapper->GetName()); // check for options if (lstOptions->GetItemCount() > 0) { wxString options = wxEmptyString; for (int pos = 0 ; pos < lstOptions->GetItemCount() ; pos++) { if (options.Length() > 0) options += wxT(", "); options += lstOptions->GetText(pos, 0) + wxT(" '") + lstOptions->GetText(pos, 1) + wxT("' "); } sql += wxT("\n OPTIONS (") + options + wxT(")"); } sql += wxT(";\n"); AppendOwnerNew(sql, wxT("SERVER ") + qtIdent(name)); } sql += GetGrant(wxT("U"), wxT("SERVER ") + qtIdent(name)); AppendComment(sql, wxT("SERVER"), 0, foreignserver); return sql; }
wxString dlgSynonym::GetSql() { wxString sql; if (!synonymSchema) { sql = wxT("CREATE OR REPLACE PUBLIC SYNONYM ") + qtIdent(txtName->GetValue()) + wxT("\n FOR "); if (cbTargetSchema->GetValue() != wxEmptyString) sql += qtIdent(cbTargetSchema->GetValue()) + wxT("."); sql += qtIdent(cbTargetObject->GetValue()) + wxT(";\n"); AppendComment(sql, wxT("PUBLIC SYNONYM ") + qtIdent(txtName->GetValue()), synonym); } else { wxString createSql, commentSql; if (synonymSchema->GetName() == wxT("public")) { createSql = wxT("CREATE OR REPLACE PUBLIC SYNONYM "); commentSql = wxT("PUBLIC SYNONYM "); } else { createSql = wxT("CREATE OR REPLACE SYNONYM ") + qtIdent(synonymSchema->GetName()) + wxT("."); commentSql = wxT("PRIVATE SYNONYM "); } sql = createSql + qtIdent(txtName->GetValue()) + wxT("\n FOR "); if (cbTargetSchema->GetValue() != wxEmptyString) sql += qtIdent(cbTargetSchema->GetValue()) + wxT("."); sql += qtIdent(cbTargetObject->GetValue()) + wxT(";\n"); AppendComment(sql, commentSql + qtIdent(txtName->GetValue()), synonym); } return sql; }
wxString dlgPackage::GetSql() { wxString sql; wxString qtName = schema->GetQuotedSchemaPrefix(schema->GetName()) + qtIdent(txtName->GetValue()); if (!package || (package && txtHeader->GetText() != package->GetHeaderInner())) { if (package) sql = wxT("DROP PACKAGE BODY ") + qtName + wxT(";\n\n"); sql += wxT("CREATE OR REPLACE PACKAGE ") + qtName + wxT("\nIS\n"); sql += txtHeader->GetText(); sql += wxT("\nEND ") + qtIdent(txtName->GetValue()) + wxT(";\n\n"); } if (!package || (package && txtBody->GetText() != package->GetBodyInner()) || (package && txtHeader->GetText() != package->GetHeaderInner())) { if (!txtBody->GetText().Trim().IsEmpty()) { sql += wxT("CREATE OR REPLACE PACKAGE BODY ") + qtName + wxT("\nIS\n"); sql += txtBody->GetText().Trim().Trim(false); sql += wxT("\nEND ") + qtIdent(txtName->GetValue()) + wxT(";\n\n"); } else { if (package && !package->GetBodyInner().Trim().IsEmpty()) sql = wxT("DROP PACKAGE BODY ") + qtName + wxT(";\n\n"); } } sql += GetGrant(wxT("X"), wxT("PACKAGE ") + qtName); AppendComment(sql, wxT("PACKAGE"), schema, package); return sql; }
wxString dlgForeignKey::GetDefinition() { wxString sql; wxString cols, refs; int pos; for (pos=0 ; pos < lstColumns->GetItemCount() ; pos++) { if (pos) { cols += wxT(", "); refs += wxT(", "); } cols += qtIdent(lstColumns->GetText(pos)); refs += qtIdent(lstColumns->GetText(pos, 1)); } sql = wxT("(") + cols + wxT(") REFERENCES "); AppendQuoted(sql, cbReferences->GetValue()); sql += wxT(" (") + refs + wxT(")"); if (chkMatchFull->GetValue()) sql += wxT(" MATCH FULL"); sql += wxT("\n ") wxT(" ON UPDATE ") + rbOnUpdate->GetStringSelection() + wxT(" ON DELETE ") + rbOnDelete->GetStringSelection(); if (chkDeferrable->GetValue()) sql += wxT("\n DEFERRABLE"); if (chkDeferred->GetValue()) sql += wxT(" INITIALLY DEFERRED"); return sql; }
wxString dlgIndexConstraint::GetSql() { wxString sql; wxString name = GetName(); if (!index) { sql = wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier() + wxT("\n ADD"); AppendIfFilled(sql, wxT(" CONSTRAINT "), qtIdent(name)); sql += wxT(" ") + wxString(factory->GetTypeName()).Upper() + wxT(" ") + GetDefinition() + wxT(";\n"); } else { if (connection->BackendMinimumVersion(8, 0) && cbTablespace->GetOIDKey() != index->GetTablespaceOid()) { sql += wxT("ALTER INDEX ") + index->GetSchema()->GetQuotedIdentifier() + wxT(".") + qtIdent(name) + wxT("\n SET TABLESPACE ") + qtIdent(cbTablespace->GetValue()) + wxT(";\n"); } if (txtFillFactor->GetValue().Trim().Length() > 0 && txtFillFactor->GetValue() != index->GetFillFactor()) { sql += wxT("ALTER INDEX ") + index->GetSchema()->GetQuotedIdentifier() + wxT(".") + qtIdent(name) + wxT("\n SET (FILLFACTOR=") + txtFillFactor->GetValue() + wxT(");\n"); } } if (!name.IsEmpty()) AppendComment(sql, wxT("CONSTRAINT ") + qtIdent(name) + wxT(" ON ") + table->GetQuotedFullIdentifier(), index); return sql; }
wxString dlgIndexConstraint::GetDefinition() { wxString sql = wxEmptyString; if (cbIndex->GetCurrentSelection() > 0) { sql += wxT(" USING INDEX ") + qtIdent(cbIndex->GetValue()); } else { if (cbType->GetCurrentSelection() > 0) AppendIfFilled(sql, wxT(" USING "), cbType->GetValue()); sql += wxT("(") + GetColumns() + wxT(")"); if (txtFillFactor) { if (connection->BackendMinimumVersion(8, 2) && txtFillFactor->GetValue().Length() > 0) sql += wxT("\n WITH (FILLFACTOR=") + txtFillFactor->GetValue() + wxT(")"); } if (cbTablespace->GetOIDKey() > 0) sql += wxT(" USING INDEX TABLESPACE ") + qtIdent(cbTablespace->GetValue()); if (chkDeferrable->GetValue()) { sql += wxT(" DEFERRABLE"); if (chkDeferred->GetValue()) sql += wxT(" INITIALLY DEFERRED"); } if (txtWhere->GetValue().Length() > 0) sql += wxT(" WHERE (") + txtWhere->GetValue() + wxT(")"); } return sql; }
void pgRole::ReassignDropOwnedTo(frmMain *form) { wxString query; dlgReassignDropOwned rdo(form, GetConnection(), this, GetServer()->GetDbRestriction()); if (rdo.ShowModal() != wxID_CANCEL) { pgConn *conn; conn = new pgConn(GetConnection()->GetHost(), GetConnection()->GetService(), GetConnection()->GetHostAddr(), rdo.GetDatabase(), GetConnection()->GetUser(), GetConnection()->GetPassword(), GetConnection()->GetPort(), GetConnection()->GetRole(), GetConnection()->GetSslMode(), 0, GetConnection()->GetApplicationName(), GetConnection()->GetSSLCert(), GetConnection()->GetSSLKey(), GetConnection()->GetSSLRootCert(), GetConnection()->GetSSLCrl(), GetConnection()->GetSSLCompression()); if (conn->GetStatus() == PGCONN_OK) { if (rdo.IsReassign()) { if (wxMessageBox(_("Are you sure you wish to reassign all objects owned by the selected role?"), _("Reassign objects"), wxYES_NO) != wxYES) return; query = wxT("REASSIGN OWNED BY ") + GetQuotedFullIdentifier() + wxT(" TO ") + qtIdent(rdo.GetRole()); } else { if (wxMessageBox(_("Are you sure you wish to drop all objects owned by the selected role?"), _("Drop objects"), wxYES_NO) != wxYES) return; query = wxT("DROP OWNED BY ") + GetQuotedFullIdentifier(); } conn->ExecuteVoid(query); } else { wxMessageBox(wxT("Connection failed: ") + conn->GetLastError()); } } }
wxString edbPrivateSynonym::GetSql(ctlTree *browser) { if (sql.IsNull()) { if (isPublic) sql = wxT("-- Public synonym: ") + GetQuotedIdentifier() + wxT("\n\n") + wxT("-- DROP PUBLIC SYNONYM ") + GetQuotedIdentifier(); else sql = wxT("-- Private synonym: ") + GetSchema()->GetQuotedIdentifier() + wxT(".") + GetQuotedIdentifier() + wxT("\n\n") + wxT("-- DROP SYNONYM ") + GetSchema()->GetQuotedIdentifier() + wxT(".") + GetQuotedIdentifier(); if (isPublic) sql += wxT("\n\nCREATE OR REPLACE PUBLIC SYNONYM ") + GetQuotedIdentifier() + wxT(" FOR "); else sql += wxT("\n\nCREATE OR REPLACE SYNONYM ") + GetSchema()->GetQuotedIdentifier() + wxT(".") + GetQuotedIdentifier() + wxT(" FOR "); if (GetTargetSchema() != wxEmptyString) sql += qtIdent(GetTargetSchema()) + wxT("."); sql += qtIdent(GetTargetObject()) + wxT(";\n"); } return sql; }
wxString frmBackupGlobals::getCmdPart1() { pgServer *server; if (object->GetMetaType() == PGM_SERVER) server = (pgServer *)object; else server = object->GetDatabase()->GetServer(); wxString cmd = backupExecutable; if (!server->GetName().IsEmpty()) cmd += wxT(" --host ") + server->GetName(); cmd += wxT(" --port ") + NumToStr((long)server->GetPort()) + wxT(" --username ") + commandLineCleanOption(qtIdent(server->GetUsername())); if (!cbRolename->GetValue().IsEmpty()) cmd += wxT(" --role ") + commandLineCleanOption(qtIdent(cbRolename->GetValue())); if (pgAppMinimumVersion(backupExecutable, 8, 4)) cmd += wxT(" --no-password "); return cmd; }
wxString dlgForeignKey::GetSql() { wxString sql; wxString name=GetName(); if (!foreignKey) { sql = wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier() + wxT(" ADD"); AppendIfFilled(sql, wxT(" CONSTRAINT "), qtIdent(name)); sql +=wxT(" FOREIGN KEY ") + GetDefinition() + wxT(";\n"); } if (!name.IsEmpty()) AppendComment(sql, wxT("CONSTRAINT ") + qtIdent(name) + wxT(" ON ") + table->GetQuotedFullIdentifier(), foreignKey); if (chkAutoIndex->GetValue()) { sql += wxT("CREATE INDEX ") + qtIdent(txtIndexName->GetValue()) + wxT(" ON ") + table->GetQuotedFullIdentifier() + wxT("("); int pos; for (pos=0 ; pos < lstColumns->GetItemCount() ; pos++) { if (pos) sql += wxT(", "); sql += qtIdent(lstColumns->GetText(pos)); } sql += wxT(");\n"); } return sql; }
wxString dlgForeignKey::GetSql() { wxString sql; wxString name = GetName(); if (!foreignKey) { sql = wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier() + wxT("\n ADD"); AppendIfFilled(sql, wxT(" CONSTRAINT "), qtIdent(name)); sql += wxT(" FOREIGN KEY ") + GetDefinition() + wxT(";\n"); } else { if (foreignKey->GetName() != name) { sql = wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier() + wxT("\n RENAME CONSTRAINT ") + qtIdent(foreignKey->GetName()) + wxT(" TO ") + qtIdent(name) + wxT(";\n"); } if (connection->BackendMinimumVersion(9, 1) && !foreignKey->GetValid() && !chkDontValidate->GetValue()) { sql += wxT("ALTER TABLE ") + table->GetQuotedFullIdentifier() + wxT("\n VALIDATE CONSTRAINT ") + qtIdent(name) + wxT(";\n"); } } if (!name.IsEmpty()) AppendComment(sql, wxT("CONSTRAINT ") + qtIdent(name) + wxT(" ON ") + table->GetQuotedFullIdentifier(), foreignKey); if (chkAutoIndex->GetValue()) { sql += wxT("CREATE INDEX ") + qtIdent(txtIndexName->GetValue()) + wxT("\n ON ") + table->GetQuotedFullIdentifier() + wxT("("); int pos; for (pos = 0 ; pos < lstColumns->GetItemCount() ; pos++) { if (pos) sql += wxT(", "); sql += qtIdent(lstColumns->GetText(pos)); } sql += wxT(");\n"); } return sql; }
wxString dlgTrigger::GetColumns() { wxString sql; int pos; // iterate cols for (pos = 0 ; pos < lstColumns->GetItemCount() ; pos++) { if (pos) sql += wxT(", "); sql += qtIdent(lstColumns->GetItemText(pos)); } return sql; }
void pgTrigger::ReadColumnDetails() { if (!expandedKids && GetLanguage() != wxT("edbspl")) { expandedKids = true; if (GetConnection()->BackendMinimumVersion(8, 5)) { pgSet *res = ExecuteSet( wxT("SELECT attname\n") wxT("FROM pg_attribute,\n") wxT("(SELECT tgrelid, unnest(tgattr) FROM pg_trigger\n") wxT(" WHERE oid=") + GetOidStr() + wxT(") AS columns(tgrelid, colnum)\n") wxT("WHERE colnum=attnum AND tgrelid=attrelid")); // Allocate memory to store column def if (res->NumRows() > 0) columnList.Alloc(res->NumRows()); long i = 1; columns = wxT(""); quotedColumns = wxT(""); while (!res->Eof()) { if (i > 1) { columns += wxT(", "); quotedColumns += wxT(", "); } columns += res->GetVal(wxT("attname")); quotedColumns += qtIdent(res->GetVal(wxT("attname"))); columnList.Add(res->GetVal(wxT("attname"))); i++; res->MoveNext(); } } else { columns = wxT(""); quotedColumns = wxT(""); } } }
wxString pgView::GetCols(ctlTree *browser, size_t indent, wxString &QMs, bool withQM) { wxString sql; wxString line; int colcount = 0; pgSetIterator set(GetConnection(), wxT("SELECT attname\n") wxT(" FROM pg_attribute\n") wxT(" WHERE attrelid=") + GetOidStr() + wxT(" AND attnum>0\n") wxT(" ORDER BY attnum")); while (set.RowsLeft()) { if (colcount++) { line += wxT(", "); QMs += wxT(", "); } if (line.Length() > 60) { if (!sql.IsEmpty()) { sql += wxT("\n") + wxString(' ', indent); } sql += line; line = wxEmptyString; QMs += wxT("\n") + wxString(' ', indent); } line += qtIdent(set.GetVal(0)); if (withQM) line += wxT("=?"); QMs += wxT("?"); } if (!line.IsEmpty()) { if (!sql.IsEmpty()) sql += wxT("\n") + wxString(' ', indent); sql += line; } return sql; }
wxString pgForeignTable::GetSelectSql(ctlTree *browser) { wxString columns = wxEmptyString; wxArrayString elements = GetTypesArray(); size_t i; for (i = 0 ; i < elements.GetCount() ; i += 3) { if (!columns.IsEmpty()) columns += wxT(", "); columns += qtIdent(elements.Item(i)); } wxString sql = wxT("SELECT ") + columns + wxT("\n") wxT(" FROM ") + GetQuotedFullIdentifier() + wxT(";\n"); return sql; }
wxWindow *slonyRestartFactory::StartDialog(frmMain *form, pgObject *obj) { slCluster *cluster = (slCluster *)obj; wxString notifyName; wxString pidcol = cluster->GetDatabase()->BackendMinimumVersion(9, 2) ? wxT(" sa.pid ") : wxT(" sa.procpid "); if (cluster->GetDatabase()->BackendMinimumVersion(9, 0)) { notifyName = cluster->GetDatabase()->ExecuteScalar( wxT("SELECT ") + cluster->GetDatabase()->GetConnection()->qtDbString(wxT("_") + cluster->GetName() + wxT("_Restart")) + wxT(" FROM _") + cluster->GetName() + wxT(".sl_nodelock nl,") wxT(" pg_stat_activity sa WHERE nl.nl_backendpid = ") + pidcol + wxT("AND nl_nodeid = ") + NumToStr(cluster->GetLocalNodeID())); } else { notifyName = cluster->GetDatabase()->ExecuteScalar( wxT("SELECT relname FROM pg_listener") wxT(" WHERE relname=") + cluster->GetDatabase()->GetConnection()->qtDbString(wxT("_") + cluster->GetName() + wxT("_Restart"))); } if (notifyName.IsEmpty()) { wxMessageDialog dlg(form, wxString::Format(_("Node \"%s\" not running"), cluster->GetLocalNodeName().c_str()), _("Can't restart node"), wxICON_EXCLAMATION | wxOK); dlg.ShowModal(); form->CheckAlive(); return 0; } wxMessageDialog dlg(form, wxString::Format(_("Restart node \"%s\"?"), cluster->GetLocalNodeName().c_str()), _("Restart node"), wxICON_EXCLAMATION | wxYES_NO | wxNO_DEFAULT); if (dlg.ShowModal() != wxID_YES) return 0; if (!cluster->GetDatabase()->ExecuteVoid( wxT("NOTIFY ") + qtIdent(notifyName))) form->CheckAlive(); return 0; }
void pgGroup::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane) { if (!expandedKids) { expandedKids = true; if (!memberIds.IsEmpty()) { wxString ml = memberIds; ml.Replace(wxT(" "), wxT(",")); pgSet *set = server->ExecuteSet(wxT( "SELECT usename FROM pg_user WHERE usesysid IN (") + ml + wxT(")")); if (set) { while (!set->Eof()) { wxString user = set->GetVal(0); if (memberCount) { members += wxT(", "); quotedMembers += wxT(", "); } members += user; quotedMembers += qtIdent(user); memberCount++; usersIn.Add(user); set->MoveNext(); } delete set; } } } if (properties) { CreateListColumns(properties); properties->AppendItem(_("Name"), GetName()); properties->AppendItem(_("Group ID"), GetGroupId()); properties->AppendItem(_("Member count"), GetMemberCount()); properties->AppendItem(_("Members"), GetMembers()); } }
wxString dlgResourceGroup::GetSql2() { wxString sql = wxEmptyString; wxString name = GetName(); wxString cpuRate = txtCPURate->GetValue(); wxString dirtyRate = txtDirtyRate->GetValue(); if (!resourceGroup || m_isNameChange) { // Check the "cpu rate/dirty rate" limit is changed or not if (m_cpuRate.compare(cpuRate) != 0 || m_dirtyRate.compare(dirtyRate) != 0) { sql = wxT("ALTER RESOURCE GROUP ") + qtIdent(name) + wxT(" SET cpu_rate_limit = ") + cpuRate + wxT(", dirty_rate_limit = ") + dirtyRate + wxT(";\n"); } } return sql; }
wxString pgCast::GetSql(ctlTree *browser) { if (sql.IsNull()) { sql = wxT("-- Cast: ") + GetQuotedFullIdentifier() + wxT("\n\n") wxT("-- DROP CAST (") + GetSourceType() + wxT(" AS ") + GetTargetType() + wxT(");") wxT("\n\nCREATE CAST (") + GetSourceType() + wxT(" AS ") + GetTargetType(); if (GetCastFunction().IsNull()) sql += wxT(")\n WITHOUT FUNCTION"); else sql += wxT(")\n WITH FUNCTION ") + GetQuotedSchemaPrefix(GetCastNamespace()) + qtIdent(GetCastFunction()) + wxT("(") + GetSourceType() + wxT(")"); if (GetCastContext() != wxT("EXPLICIT")) sql += wxT("\n AS ") + GetCastContext(); sql += wxT(";\n"); } return sql; }
long slCluster::GetSlonPid() { long slonPid; wxString pidcol = GetConnection()->BackendMinimumVersion(9, 2) ? wxT("pid") : wxT("procpid"); if (GetConnection()->BackendMinimumVersion(9, 0)) { slonPid = StrToLong(GetConnection()->ExecuteScalar( wxT("SELECT nl_backendpid FROM ") + qtIdent(wxT("_") + GetName()) + wxT(".sl_nodelock nl, ") wxT("pg_stat_activity sa WHERE nl.nl_backendpid = sa.") + pidcol + wxT(" AND nl_nodeid = ") + NumToStr(GetLocalNodeID()))); } else { slonPid = StrToLong(GetConnection()->ExecuteScalar( wxT("SELECT listenerpid FROM pg_listener WHERE relname = ") + qtDbString(wxT("_") + GetName() + wxT("_Event")))); } return slonPid; }
wxString pgCheck::GetSql(ctlTree *browser) { if (sql.IsNull()) { sql = wxT("-- Check: ") + GetQuotedFullIdentifier() + wxT("\n\n") + wxT("-- ALTER ") + objectKind + wxT(" ") + GetQuotedSchemaPrefix(objectSchema) + qtIdent(objectName) + wxT(" DROP CONSTRAINT ") + GetQuotedIdentifier() + wxT(";\n\nALTER ") + objectKind + wxT(" ") + GetQuotedSchemaPrefix(objectSchema) + qtIdent(objectName) + wxT("\n ADD CONSTRAINT ") + GetConstraint() + wxT(";\n"); if (!GetComment().IsNull()) { sql += wxT("COMMENT ON CONSTRAINT ") + GetQuotedIdentifier() + wxT(" ON ") + GetQuotedSchemaPrefix(objectSchema) + qtIdent(objectName) + wxT(" IS ") + qtDbString(GetComment()) + wxT(";\n"); } } return sql; }
wxString dlgTextSearchDictionary::GetSql() { wxString sql; wxString objname=schema->GetQuotedPrefix() + qtIdent(GetName()); if (dict) { // edit mode AppendNameChange(sql); AppendOwnerChange(sql, wxT("TEXT SEARCH DICTIONARY ") + objname); wxString sqloptions = GetOptionsSql(); if (sqloptions.Length() > 0) { sql += wxT("ALTER TEXT SEARCH DICTIONARY ") + objname + wxT(" (") + sqloptions + wxT(")"); } } else { // create mode sql = wxT("CREATE TEXT SEARCH DICTIONARY ") + schema->GetQuotedPrefix() + GetName() + wxT(" (") + wxT("\n TEMPLATE = ") + cbTemplate->GetValue(); // check for options for (int pos=0 ; pos < lstOptions->GetItemCount() ; pos++) { sql += wxT(", ") + lstOptions->GetText(pos, 0) + wxT("=") + lstOptions->GetText(pos, 1); } sql += wxT("\n);\n"); } AppendComment(sql, wxT("TEXT SEARCH DICTIONARY ") + objname, dict); return sql; }
wxString pgUser::GetSql(ctlTree *browser) { if (sql.IsNull()) { sql = wxT("-- User: "******"\n\n") + wxT("-- DROP USER ") + GetQuotedFullIdentifier() + wxT(";") + wxT("\n\nCREATE USER ") + GetQuotedIdentifier() + wxT("\n WITH SYSID ") + NumToStr(userId); if (GetPassword() != wxT("********")) AppendIfFilled(sql, wxT("\n ENCRYPTED PASSWORD "), qtDbString(GetPassword())); sql += wxT("\n "); if (GetCreateDatabase()) sql += wxT(" CREATEDB"); else sql += wxT(" NOCREATEDB"); if (GetUpdateCatalog()) sql += wxT(" CREATEUSER"); else sql += wxT(" NOCREATEUSER"); if (GetAccountExpires().IsValid()) AppendIfFilled(sql, wxT(" VALID UNTIL "), qtDbString(DateToAnsiStr(GetAccountExpires()))); sql += wxT(";\n"); size_t index; for (index = 0 ; index < configList.GetCount() ; index++) { if (configList.Item(index).BeforeFirst('=') != wxT("search_path") && configList.Item(index).BeforeFirst('=') != wxT("temp_tablespaces")) sql += wxT("ALTER USER ") + GetQuotedIdentifier() + wxT(" SET ") + configList.Item(index).BeforeFirst('=') + wxT("='") + configList.Item(index).AfterFirst('=') + wxT("';\n"); else sql += wxT("ALTER USER ") + GetQuotedIdentifier() + wxT(" SET ") + configList.Item(index).BeforeFirst('=') + wxT("=") + configList.Item(index).AfterFirst('=') + wxT(";\n"); } for (index = 0 ; index < groupsIn.GetCount() ; index++) sql += wxT("ALTER GROUP ") + qtIdent(groupsIn.Item(index)) + wxT(" ADD USER ") + GetQuotedIdentifier() + wxT(";\n"); } return sql; }
wxString dlgIndex::GetColumns() { wxString sql; int pos; // iterate cols for (pos = 0 ; pos < lstColumns->GetItemCount() ; pos++) { if (pos) sql += wxT(", "); sql += qtIdent(lstColumns->GetItemText(pos)); if (this->database->BackendMinimumVersion(9, 1)) { wxString collation = lstColumns->GetText(pos, 4); if (!collation.IsEmpty() && collation != wxT("pg_catalog.\"default\"")) sql += wxT(" COLLATE ") + collation; } wxString opclass = lstColumns->GetText(pos, 3); if (!opclass.IsEmpty()) sql += wxT(" ") + opclass; if (this->database->BackendMinimumVersion(8, 3)) { wxString order = lstColumns->GetText(pos, 1); if (!order.IsEmpty()) sql += wxT(" ") + order; wxString nullsOrder = lstColumns->GetText(pos, 2); if (!nullsOrder.IsEmpty()) sql += wxT(" NULLS ") + nullsOrder; } } return sql; }
wxString dlgCollation::GetSql() { wxString sql; wxString name; if (collation) { // edit mode name = schema->GetQuotedPrefix() + qtIdent(GetName());; AppendNameChange(sql, wxT("COLLATION ") + collation->GetQuotedFullIdentifier()); AppendOwnerChange(sql, wxT("COLLATION ") + name); AppendSchemaChange(sql, wxT("COLLATION ") + name); } else { // create mode name = qtIdent(cbSchema->GetValue()) + wxT(".") + qtIdent(GetName()); sql = wxT("CREATE COLLATION ") + name; if (cbCollation->GetValue().IsEmpty()) { if (txtLocale->GetValue().IsEmpty()) { sql += wxT("(LC_COLLATE=") + qtDbString(txtLcCollate->GetValue()) + wxT(", LC_CTYPE=") + qtDbString(txtLcCtype->GetValue()) + wxT(")"); } else { sql += wxT("(LOCALE=") + qtDbString(txtLocale->GetValue()) + wxT(")"); } } else { sql += wxT(" FROM ") + cbCollation->GetValue(); } sql += wxT(";\n"); AppendOwnerNew(sql, wxT("COLLATION ") + schema->GetQuotedPrefix() + qtIdent(name)); } AppendComment(sql, wxT("COLLATION ") + qtIdent(cbSchema->GetValue()) + wxT(".") + qtIdent(GetName()), collation); return sql; }
wxString pgForeignServer::GetSql(ctlTree *browser) { if (sql.IsNull()) { sql = wxT("-- Server: ") + GetQuotedFullIdentifier() + wxT("\n\n") + wxT("-- DROP SERVER ") + GetQuotedFullIdentifier() + wxT(";") + wxT("\n\nCREATE SERVER ") + GetQuotedFullIdentifier() + wxT("\n FOREIGN DATA WRAPPER ") + qtIdent(GetForeignDataWrapper()->GetName()); if (!GetType().IsEmpty()) sql += wxT("\n TYPE ") + qtDbString(GetType()); if (!GetVersion().IsEmpty()) sql += wxT("\n VERSION ") + qtDbString(GetVersion()); if (!GetOptions().IsEmpty()) sql += wxT("\n OPTIONS (") + GetCreateOptions() + wxT(")"); sql += wxT(";\n") + GetOwnerSql(8, 4, wxT("SERVER ") + GetQuotedFullIdentifier()) + GetGrant(wxT("U"), wxT("FOREIGN SERVER ") + GetQuotedFullIdentifier()); } return sql; }