int dlgGroup::Go(bool modal) { pgSet *set = connection->ExecuteSet(wxT("SELECT usename FROM pg_user")); if (set) { while (!set->Eof()) { wxString userName = set->GetVal(wxT("usename")); if (group && group->GetUsersIn().Index(userName) >= 0) lbUsersIn->Append(userName); else lbUsersNotIn->Append(userName); set->MoveNext(); } delete set; } if (group) { // Edit Mode readOnly = !group->GetServer()->GetSuperUser(); txtID->SetValue(NumToStr(group->GetGroupId())); if (!connection->BackendMinimumVersion(7, 4)) txtName->Disable(); txtID->Disable(); if (readOnly) { btnAddUser->Disable(); btnDelUser->Disable(); } } else { txtID->SetValidator(numericValidator); } return dlgProperty::Go(modal); }
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 ctlSQLResult::OnGetItemText(long item, long col) const { if (thread && thread->DataValid()) { if (!rowcountSuppressed) { if (col) col--; else return NumToStr(item + 1L); } if (item >= 0) { thread->DataSet()->Locate(item + 1); return thread->DataSet()->GetVal(col); } else return thread->DataSet()->ColName(col); } return wxEmptyString; }
VOID LIClass::Render (struct RenderMessage &rmsg) { if(Flags & FLG_Layouted) { if(!rmsg.TargetObj) { struct RastPort *rp = rmsg.RPort; if(Number) { char str[64]; NumToStr(str, rmsg.OL_Type); struct TextFont *font = rmsg.Share->Fonts[Font_Normal]; ULONG len = strlen(str); ULONG x = Left - MyTextLength(font, str, len) - rmsg.OffsetX; SetAPen(rp, rmsg.Colours[Col_Text]); SetFont(rp, font); Move(rp, x, Baseline - rmsg.OffsetY); Text(rp, str, len); } else { if(rmsg.Share->LI_BMp) { LONG x, y, width = rmsg.Share->LI_Width, height = rmsg.Share->LI_Height; x = Left - width - rmsg.OffsetX; y = Baseline - rmsg.OffsetY - height + 1; ULONG index = 0; if(rmsg.UL_Nesting > 1) index = width * min(rmsg.UL_Nesting-1, 2); if(rmsg.Share->LI_Mask) BltMaskRPort(rmsg.Share->LI_BMp, index, 0, rp, x, y, width, height, rmsg.Share->LI_Mask); else BltBitMapRastPort(rmsg.Share->LI_BMp, index, 0, rp, x, y, width, height, 0x0c0); } } } TreeClass::Render(rmsg); } }
pgObject *slSlSequenceFactory::CreateObjects(pgCollection *coll, ctlTree *browser, const wxString &restr) { slSetObjCollection *collection = (slSetObjCollection *)coll; slSequence *sequence = 0; wxString restriction; if (restr.IsEmpty()) restriction = wxT(" WHERE seq_set = ") + NumToStr(collection->GetSlId()); else restriction = restr; pgSet *sequences = collection->GetDatabase()->ExecuteSet( wxT("SELECT seq_id, seq_set, nspname, relname, seq_comment\n") wxT(" FROM ") + collection->GetCluster()->GetSchemaPrefix() + wxT("sl_sequence\n") wxT(" JOIN ") + collection->GetCluster()->GetSchemaPrefix() + wxT("sl_set ON set_id=seq_set\n") wxT(" JOIN pg_class cl ON cl.oid=seq_reloid\n") wxT(" JOIN pg_namespace nsp ON nsp.oid=relnamespace\n") + restriction + wxT(" ORDER BY seq_id")); if (sequences) { while (!sequences->Eof()) { sequence = new slSequence(collection->GetSet(), sequences->GetVal(wxT("nspname")) + wxT(".") + sequences->GetVal(wxT("relname"))); sequence->iSetSlId(sequences->GetLong(wxT("seq_id"))); sequence->iSetComment(sequences->GetVal(wxT("seq_comment"))); if (browser) { browser->AppendObject(collection, sequence); sequences->MoveNext(); } else break; } delete sequences; } return sequence; }
pgObject *slPathFactory::CreateObjects(pgCollection *coll, ctlTree *browser, const wxString &restr) { slNodeObjCollection *collection = (slNodeObjCollection *)coll; slPath *path = 0; wxString restriction; if (restr.IsEmpty()) restriction = wxT(" WHERE pa_client = ") + NumToStr(collection->GetSlId()); else restriction = restr; pgSet *paths = collection->GetDatabase()->ExecuteSet( wxT("SELECT pa_client, pa_server, pa_conninfo, pa_connretry, no_comment\n") wxT(" FROM ") + collection->GetCluster()->GetSchemaPrefix() + wxT("sl_path\n") wxT(" JOIN ") + collection->GetCluster()->GetSchemaPrefix() + wxT("sl_node on no_id=pa_server\n") + restriction + wxT(" ORDER BY pa_server")); if (paths) { while (!paths->Eof()) { path = new slPath(collection->GetNode(), paths->GetVal(wxT("no_comment")).BeforeFirst('\n')); path->iSetSlId(paths->GetLong(wxT("pa_server"))); path->iSetConnInfo(paths->GetVal(wxT("pa_conninfo"))); path->iSetConnRetry(paths->GetLong(wxT("pa_connretry"))); if (browser) { browser->AppendObject(collection, path); paths->MoveNext(); } else break; } delete paths; } return path; }
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 dlgRepSetMove::Go(bool modal) { txtID->SetValue(IdAndName(set->GetSlId(), set->GetName())); txtID->Disable(); pgSet *nodes = connection->ExecuteSet( wxT("SELECT no_id, no_comment\n") wxT(" FROM ") + cluster->GetSchemaPrefix() + wxT("sl_node\n") wxT(" JOIN ") + cluster->GetSchemaPrefix() + wxT("sl_subscribe ON sub_receiver=no_id\n") wxT(" WHERE sub_set = ") + NumToStr(set->GetSlId())); if (nodes) { while (!nodes->Eof()) { long id = nodes->GetLong(wxT("no_id")); cbTargetNode->Append(IdAndName(id, nodes->GetVal(wxT("no_comment"))), (void *)id); nodes->MoveNext(); } delete nodes; } return dlgProperty::Go(modal); }
int dlgRepSet::Go(bool modal) { txtID->SetValidator(numericValidator); if (set) { // edit mode txtID->SetValue(NumToStr(set->GetSlId())); txtID->Disable(); txtOrigin->SetValue(IdAndName(set->GetOriginId(), set->GetOriginNode())); txtComment->Disable(); } else { // create mode txtOrigin->SetValue(IdAndName(cluster->GetLocalNodeID(), cluster->GetLocalNodeName())); EnableOK(true); } txtOrigin->Disable(); return dlgProperty::Go(modal); }
void increase(UCHAR time[]) { UCHAR i; UINT quantity; bit Carry = 0; //若发生进位,则Carry为1,否则为0 for (i=0; i<7; i++) //i=0~6分别代表秒、分、时、星期、日、月、年 { quantity = StrToNum(i, time); if (quantity > 9999) { time[0] = 'E'; time[1] = 'r'; time[2] = 'r'; break; } quantity++; Carry = NumToStr(i, quantity, time); if (i == 3) //若是星期数增加了,则日也要增加 continue; if (Carry == 0) break; } }
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 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 dlgRole::GetSql() { int pos; wxString sql; wxString name = GetName(); wxString passwd = txtPasswd->GetValue(); bool createDB = chkCreateDB->GetValue(), createRole = chkCreateRole->GetValue(), superuser = chkSuperuser->GetValue(), inherits = chkInherits->GetValue(), canLogin = chkCanLogin->GetValue(), replication = chkReplication->GetValue(); if (role) { // Edit Mode AppendNameChange(sql, wxT("ROLE ") + role->GetQuotedFullIdentifier()); wxString options; if (canLogin != role->GetCanLogin()) { if (canLogin) options = wxT(" LOGIN"); else options = wxT(" NOLOGIN"); } if (canLogin && !passwd.IsEmpty()) options += wxT(" ENCRYPTED PASSWORD ") + qtDbString(connection->EncryptPassword(name, passwd)); if (createDB != role->GetCreateDatabase() || createRole != role->GetCreateRole() || superuser != role->GetSuperuser() || inherits != role->GetInherits() || replication != role->GetReplication()) { options += wxT("\n "); if (superuser != role->GetSuperuser()) { if (superuser) options += wxT(" SUPERUSER"); else options += wxT(" NOSUPERUSER"); } if (inherits != role->GetInherits()) { if (inherits) options += wxT(" INHERIT"); else options += wxT(" NOINHERIT"); } if (createDB != role->GetCreateDatabase()) { if (createDB) options += wxT(" CREATEDB"); else options += wxT(" NOCREATEDB"); } if (createRole != role->GetCreateRole()) { if (createRole) options += wxT(" CREATEROLE"); else options += wxT(" NOCREATEROLE"); } if (connection->BackendMinimumVersion(9, 1)) { if (replication != role->GetReplication()) { if (replication) options += wxT(" REPLICATION"); else options += wxT(" NOREPLICATION"); } } } if (!datValidUntil->GetValue().IsValid() || DateToStr(datValidUntil->GetValue() + timValidUntil->GetValue()) != DateToStr(role->GetAccountExpires())) { if (datValidUntil->GetValue().IsValid()) options += wxT("\n VALID UNTIL ") + qtDbString(DateToAnsiStr(datValidUntil->GetValue() + timValidUntil->GetValue())); else if (!role->GetIsValidInfinity() && role->GetAccountExpires().GetValue() != -1) options += wxT("\n VALID UNTIL 'infinity'"); } if (txtConnectionLimit->GetValue().Length() == 0) { if (role->GetConnectionLimit() != -1) { options += wxT(" CONNECTION LIMIT -1"); } } else { if (txtConnectionLimit->GetValue() != NumToStr(role->GetConnectionLimit())) { options += wxT(" CONNECTION LIMIT ") + txtConnectionLimit->GetValue(); } } if (!options.IsNull()) sql += wxT("ALTER ROLE ") + qtIdent(name) + options + wxT(";\n"); if (!connection->BackendMinimumVersion(9, 5) && chkUpdateCat->GetValue() != role->GetUpdateCatalog()) { if (!connection->HasPrivilege(wxT("Table"), wxT("pg_authid"), wxT("update"))) sql += wxT(" -- Can't update 'UpdateCatalog privilege: can't write to pg_authid.\n") wxT("-- "); sql += wxT("UPDATE pg_authid SET rolcatupdate=") + BoolToStr(chkUpdateCat->GetValue()) + wxT(" WHERE OID=") + role->GetOidStr() + wxT(";\n"); } int cnt = lbRolesIn->GetCount(); wxArrayString tmpRoles = role->GetRolesIn(); // check for added roles for (pos = 0 ; pos < cnt ; pos++) { wxString roleName = lbRolesIn->GetString(pos); int index = tmpRoles.Index(roleName); if (index >= 0) { // role membership unchanged tmpRoles.RemoveAt(index); } else { bool admin = false; if (roleName.Right(PGROLE_ADMINOPTION_LEN) == PGROLE_ADMINOPTION) { admin = true; roleName = roleName.Left(roleName.Length() - PGROLE_ADMINOPTION_LEN); } else { // new role membership without admin option index = tmpRoles.Index(roleName + PGROLE_ADMINOPTION); if (index >= 0) { // old membership with admin option tmpRoles.RemoveAt(index); sql += wxT("REVOKE ADMIN OPTION FOR ") + qtIdent(roleName) + wxT(" FROM ") + qtIdent(name) + wxT(";\n"); continue; } } index = tmpRoles.Index(roleName); if (index >= 0) { // admin option added to existing membership tmpRoles.RemoveAt(index); } sql += wxT("GRANT ") + qtIdent(roleName) + wxT(" TO ") + qtIdent(name); if (admin) sql += wxT(" WITH ADMIN OPTION"); sql += wxT(";\n"); } } // check for removed roles for (pos = 0 ; pos < (int)tmpRoles.GetCount() ; pos++) { sql += wxT("REVOKE ") + qtIdent(tmpRoles.Item(pos)) + wxT(" FROM ") + qtIdent(name) + wxT(";\n"); } } else { // Create Mode sql = wxT( "CREATE ROLE ") + qtIdent(name); if (canLogin) { sql += wxT(" LOGIN"); if (!passwd.IsEmpty()) sql += wxT(" ENCRYPTED PASSWORD ") + qtDbString(connection->EncryptPassword(name, passwd)); } if (createDB || createRole || !inherits || superuser) sql += wxT("\n "); if (superuser) sql += wxT(" SUPERUSER"); if (!inherits) sql += wxT(" NOINHERIT"); if (createDB) sql += wxT(" CREATEDB"); if (createRole) sql += wxT(" CREATEROLE"); if (connection->BackendMinimumVersion(9, 1)) { if (replication) sql += wxT(" REPLICATION"); } if (datValidUntil->GetValue().IsValid()) sql += wxT("\n VALID UNTIL ") + qtDbString(DateToAnsiStr(datValidUntil->GetValue() + timValidUntil->GetValue())); else sql += wxT("\n VALID UNTIL 'infinity'"); if (txtConnectionLimit->GetValue().Length() > 0) { sql += wxT(" CONNECTION LIMIT ") + txtConnectionLimit->GetValue(); } int cnt = lbRolesIn->GetCount(); wxString grants; if (cnt) { wxString roleName; for (pos = 0 ; pos < cnt ; pos++) { bool admin = false; roleName = lbRolesIn->GetString(pos); if (roleName.Right(PGROLE_ADMINOPTION_LEN) == PGROLE_ADMINOPTION) { roleName = roleName.Left(roleName.Length() - PGROLE_ADMINOPTION_LEN); admin = true; } grants += wxT("GRANT ") + qtIdent(roleName) + wxT(" TO ") + qtIdent(name); if (admin) grants += wxT(" WITH ADMIN OPTION;\n"); else grants += wxT(";\n"); } } sql += wxT(";\n") + grants; if (superuser && !chkUpdateCat->GetValue() && !connection->BackendMinimumVersion(9, 5)) sql += wxT("UPDATE pg_authid SET rolcatupdate=false WHERE rolname=") + qtDbString(name) + wxT(";\n"); } wxArrayString vars; wxString dbname; wxString parameter; wxString value; size_t index; if (role) { for (index = 0 ; index < role->GetVariables().GetCount() ; index++) vars.Add(role->GetVariables().Item(index)); } int cnt = lstVariables->GetItemCount(); // check for changed or added vars for (pos = 0 ; pos < cnt ; pos++) { wxString newDb = lstVariables->GetText(pos); wxString newVar = lstVariables->GetText(pos, 1); wxString newVal = lstVariables->GetText(pos, 2); wxString oldVal; for (index = 0 ; index < vars.GetCount() ; index += 3) { dbname = vars.Item(index); parameter = vars.Item(index + 1); value = vars.Item(index + 2); if (newDb == dbname && newVar == parameter) { oldVal = value; vars.RemoveAt(index); vars.RemoveAt(index); vars.RemoveAt(index); break; } } if (oldVal != newVal) { if (newDb.Length() == 0) sql += wxT("ALTER ROLE ") + qtIdent(name); else sql += wxT("ALTER ROLE ") + qtIdent(name) + wxT(" IN DATABASE ") + newDb; if (newVar != wxT("search_path") && newVar != wxT("temp_tablespaces")) { sql += wxT("\n SET ") + newVar + wxT(" = '") + newVal + wxT("';\n"); } else { sql += wxT("\n SET ") + newVar + wxT(" = ") + newVal + wxT(";\n"); } } } // check for removed vars for (pos = 0 ; pos < (int)vars.GetCount() ; pos += 3) { dbname = vars.Item(pos); parameter = vars.Item(pos + 1); value = vars.Item(pos + 2); if (dbname.Length() == 0) { sql += wxT("ALTER ROLE ") + qtIdent(name) + wxT(" RESET ") + parameter + wxT(";\n"); } else { sql += wxT("ALTER ROLE ") + qtIdent(name) + wxT(" IN DATABASE ") + dbname + wxT(" RESET ") + parameter + wxT(";\n"); } } AppendComment(sql, wxT("ROLE"), 0, role); if (seclabelPage && connection->BackendMinimumVersion(9, 2)) sql += seclabelPage->GetSqlForSecLabels(wxT("ROLE"), qtIdent(name)); return sql; }
int dlgDomain::Go(bool modal) { if (connection->BackendMinimumVersion(9, 1)) { seclabelPage->SetConnection(connection); seclabelPage->SetObject(domain); this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgDomain::OnChange)); } else seclabelPage->Disable(); if (domain) { // edit mode cbSchema->Enable(connection->BackendMinimumVersion(8, 1)); cbDatatype->Append(domain->GetBasetype()); AddType(wxT(" "), 0, domain->GetBasetype()); cbDatatype->SetSelection(0); if (domain->GetLength() >= 0) { txtLength->SetValue(NumToStr(domain->GetLength())); if (domain->GetPrecision() >= 0) txtPrecision->SetValue(NumToStr(domain->GetPrecision())); } chkNotNull->SetValue(domain->GetNotNull()); txtDefault->SetValue(domain->GetDefault()); wxCookieType cookie; pgObject *data = 0; wxTreeItemId item = mainForm->GetBrowser()->GetFirstChild(domain->GetId(), cookie); while (item) { data = mainForm->GetBrowser()->GetObject(item); pgaFactory *factory = data->GetFactory(); if (factory == checkFactory.GetCollectionFactory()) constraintsItem = item; else if (data->GetMetaType() == PGM_CONSTRAINT) constraintsItem = item; if (constraintsItem) break; item = mainForm->GetBrowser()->GetNextChild(domain->GetId(), cookie); } if (constraintsItem) { pgCollection *coll = (pgCollection *)mainForm->GetBrowser()->GetObject(constraintsItem); // make sure all constraints are appended coll->ShowTreeDetail(mainForm->GetBrowser()); // this is the constraints collection item = mainForm->GetBrowser()->GetFirstChild(constraintsItem, cookie); // add constraints while (item) { data = mainForm->GetBrowser()->GetObject(item); switch (data->GetMetaType()) { case PGM_CHECK: { pgCheck *obj = (pgCheck *)data; lstConstraints->AppendItem(data->GetIconId(), obj->GetName(), obj->GetDefinition()); constraintsDefinition.Add(obj->GetDefinition()); previousConstraints.Add(obj->GetQuotedIdentifier() + wxT(" ") + obj->GetTypeName().Upper() + wxT(" ") + obj->GetDefinition()); break; } } item = mainForm->GetBrowser()->GetNextChild(constraintsItem, cookie); } } cbDatatype->Disable(); cbCollation->SetValue(domain->GetQuotedCollation()); cbCollation->Disable(); if (!connection->BackendMinimumVersion(7, 4)) { cbOwner->Disable(); txtDefault->Disable(); chkNotNull->Disable(); } } else { // create mode FillDatatype(cbDatatype, false); cbCollation->Enable(connection->BackendMinimumVersion(9, 1)); if (connection->BackendMinimumVersion(9, 1)) { // 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); } } cbConstrType->Clear(); cbConstrType->Append(_("Check")); cbConstrType->SetSelection(0); btnRemoveConstr->Disable(); return dlgProperty::Go(modal); }
bool frmMain::dropSingleObject(pgObject *data, bool updateFinal, bool cascaded) { if (updateFinal) { // accelerator can bypass disabled menu, so we need to check if (!data || !data->CanDrop()) return false; if (data->CheckOpenDialogs(browser, browser->GetSelection())) { wxString msg = _("There are properties dialogues open for one or more objects that would be dropped. Please close the properties dialogues and try again."); wxMessageBox(msg, _("Cannot drop object"), wxICON_WARNING | wxOK); return false; } if (data->GetSystemObject()) { wxMessageDialog msg(this, data->GetTranslatedMessage(CANNOTDROPSYSTEM), _("Trying to drop system object"), wxICON_EXCLAMATION); msg.ShowModal(); return false; } if (cascaded || data->RequireDropConfirm() || settings->GetConfirmDelete()) { wxString text, caption; if (cascaded) { text = data->GetTranslatedMessage(DROPINCLUDINGDEPS); caption = data->GetTranslatedMessage(DROPCASCADETITLE); } else { /* * currentObject is set using the following command. * i.e. currentObject = browser->GetObject(item); * While fetching this object using this code, somehow it looses its virtual table pointer. * Hence, it is not able to call the GetFullIdentifier - virtual function from the * particular class, but it will always call this functions from pgObject class always. * To rectify this problem, we need to explicitly check the meta data type and call the * function from the particular class. */ if (data->GetMetaType() == PGM_SERVER) text = wxString::Format(_("Are you sure you wish to drop server \"%s\"?"), ((pgServer *)data)->GetFullIdentifier().c_str()); else if (data->GetMetaType() == EDB_SYNONYM) text = ((edbPrivateSynonym *)data)->GetTranslatedMessage(DROPEXCLUDINGDEPS); else text = data->GetTranslatedMessage(DROPEXCLUDINGDEPS); caption = data->GetTranslatedMessage(DROPTITLE); } wxMessageDialog msg(this, text, caption, wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT); if (msg.ShowModal() != wxID_YES) { return false; } } } bool done = data->DropObject(this, browser, cascaded); if (done) { wxLogInfo(wxT("Dropping %s %s"), data->GetTypeName().c_str(), data->GetIdentifier().c_str()); wxTreeItemId parentItem = browser->GetItemParent(data->GetId()); if (updateFinal) { wxTreeItemId nextItem; if (browser->IsVisible(data->GetId())) nextItem = browser->GetNextVisible(data->GetId()); if (nextItem) { pgObject *nextData = browser->GetObject(nextItem); if (!nextData || nextData->GetType() != data->GetType()) nextItem = browser->GetPrevSibling(data->GetId()); } else nextItem = browser->GetPrevSibling(data->GetId()); if (nextItem) browser->SelectItem(nextItem); } pgaFactory *droppedCollFactory = data->GetFactory()->GetCollectionFactory(); wxTreeItemId oldgroupitem; wxString oldgroupname; if (data->IsCreatedBy(serverFactory)) { oldgroupname = ((pgServer *)data)->GetGroup(); oldgroupitem = browser->GetItemParent(data->GetId()); } browser->Delete(data->GetId()); // data is invalid now if (updateFinal) { if (!oldgroupname.IsEmpty()) { int total = browser->GetChildrenCount(oldgroupitem, false); if (total == 0) browser->Delete(oldgroupitem); else { wxString label = oldgroupname + wxT(" (") + NumToStr((long)total) + wxT(")"); browser->SetItemText(oldgroupitem, label); } } else { pgCollection *collection = 0; while (parentItem) { collection = (pgCollection *)browser->GetObject(parentItem); if (collection && collection->IsCollection() && collection->GetFactory() == droppedCollFactory) { collection->UpdateChildCount(browser); break; } parentItem = browser->GetItemParent(parentItem); } } } // Update the server list, if we dropped a server StoreServers(); } return done; }
wxWindow *pluginUtilityFactory::StartDialog(frmMain *form, pgObject *obj) { wxString execCmd = command; wxArrayString environment = set_env; // Remember this as the last plugin used form->SetLastPluginUtility(this); // Replace all the place holders with appropriate values if (HaveDatabase(obj)) { execCmd.Replace(wxT("$$HOSTNAME"), obj->GetConnection()->GetHostName()); execCmd.Replace(wxT("$$HOSTADDR"), obj->GetConnection()->GetHostName()); execCmd.Replace(wxT("$$PORT"), NumToStr((long)obj->GetConnection()->GetPort())); execCmd.Replace(wxT("$$SSLMODE"), obj->GetConnection()->GetSslModeName()); execCmd.Replace(wxT("$$DATABASE"), obj->GetConnection()->GetDbname()); execCmd.Replace(wxT("$$USERNAME"), obj->GetConnection()->GetUser()); execCmd.Replace(wxT("$$PASSWORD"), obj->GetConnection()->GetPassword()); // Set the PGPASSWORD variable if required. if (set_password && !obj->GetConnection()->GetPassword().IsEmpty()) wxSetEnv(wxT("PGPASSWORD"), obj->GetConnection()->GetPassword()); // Pass the SSL settings via the environment switch (obj->GetConnection()->GetSslMode()) { case 1: wxSetEnv(wxT("PGREQUIRESSL"), wxT("1")); break; case 2: wxSetEnv(wxT("PGREQUIRESSL"), wxT("0")); break; } wxSetEnv(wxT("PGSSLMODE"), obj->GetConnection()->GetSslModeName()); wxSetEnv(wxT("PGSSLCERT"), obj->GetConnection()->GetSSLCert()); wxSetEnv(wxT("PGSSLKEY"), obj->GetConnection()->GetSSLKey()); wxSetEnv(wxT("PGSSLROOTCERT"), obj->GetConnection()->GetSSLRootCert()); wxSetEnv(wxT("PGSSLCRL"), obj->GetConnection()->GetSSLCrl()); } else { // Blank the rest execCmd.Replace(wxT("$$HOSTNAME"), wxEmptyString); execCmd.Replace(wxT("$$HOSTADDR"), wxEmptyString); execCmd.Replace(wxT("$$PORT"), wxEmptyString); execCmd.Replace(wxT("$$SSLMODE"), wxEmptyString); execCmd.Replace(wxT("$$DATABASE"), wxEmptyString); execCmd.Replace(wxT("$$USERNAME"), wxEmptyString); execCmd.Replace(wxT("$$PASSWORD"), wxEmptyString); } // Name if (obj && obj->IsCollection()) execCmd.Replace(wxT("$$OBJECTNAME"), wxT("*")); else if (obj) execCmd.Replace(wxT("$$OBJECTNAME"), obj->GetName()); else execCmd.Replace(wxT("$$OBJECTNAME"), wxEmptyString); // Object type if (obj && obj->GetFactory()) execCmd.Replace(wxT("$$OBJECTTYPE"), wxString(obj->GetFactory()->GetTypeName()).Upper()); else execCmd.Replace(wxT("$$OBJECTTYPE"), wxEmptyString); // Schema if (obj) { if (obj->GetMetaType() == PGM_SCHEMA) execCmd.Replace(wxT("$$SCHEMA"), obj->GetName()); else if (obj->GetSchema()) execCmd.Replace(wxT("$$SCHEMA"), obj->GetSchema()->GetName()); } else execCmd.Replace(wxT("$$SCHEMA"), wxEmptyString); // Table if (obj) { if (obj->GetMetaType() == PGM_TABLE || obj->GetMetaType() == GP_PARTITION) execCmd.Replace(wxT("$$TABLE"), obj->GetName()); else if (obj->GetTable()) execCmd.Replace(wxT("$$TABLE"), obj->GetTable()->GetName()); } else execCmd.Replace(wxT("$$TABLE"), wxEmptyString); // Directory substitutions execCmd.Replace(wxT("$$BINDIR"), loadPath); execCmd.Replace(wxT("$$WORKINGDIR"), wxGetCwd()); execCmd.Replace(wxT("$$PGBINDIR"), settings->GetPostgresqlPath()); execCmd.Replace(wxT("$$EDBBINDIR"), settings->GetEnterprisedbPath()); execCmd.Replace(wxT("$$SLONYBINDIR"), settings->GetSlonyPath()); // set Environment variable. for (size_t i = 0 ; i < environment.GetCount() ; i++) { wxString str = environment.Item(i); wxSetEnv(str.BeforeFirst('='), str.AfterFirst('=')); } // Let's go!! if (wxExecute(execCmd) == 0) { wxLogError(_("Failed to execute plugin %s (%s)"), title.c_str(), command.c_str()); } // Reset the environment variables set by us wxUnsetEnv(wxT("PGPASSWORD")); wxUnsetEnv(wxT("PGSSLMODE")); wxUnsetEnv(wxT("PGREQUIRESSL")); wxUnsetEnv(wxT("PGSSLCERT")); wxUnsetEnv(wxT("PGSSLKEY")); wxUnsetEnv(wxT("PGSSLROOTCERT")); wxUnsetEnv(wxT("PGSSLCRL")); return 0; }
void pgUser::ShowDependents(frmMain *form, ctlListView *referencedBy, const wxString &where) { form->StartMsg(_(" Retrieving user owned objects")); referencedBy->ClearAll(); referencedBy->AddColumn(_("Type"), 60); referencedBy->AddColumn(_("Database"), 80); referencedBy->AddColumn(_("Name"), 300); wxString uid = NumToStr(GetUserId()); wxString sysoid = NumToStr(GetConnection()->GetLastSystemOID()); wxArrayString dblist; pgSet *set; if (GetConnection()->BackendMinimumVersion(7, 5)) set = GetConnection()->ExecuteSet( wxT("SELECT 'd' as type, datname, datallowconn, datdba\n") wxT(" FROM pg_database db\n") wxT("UNION\n") wxT("SELECT 'M', spcname, null, null\n") wxT(" FROM pg_tablespace where spcowner=") + uid + wxT("\n") wxT(" ORDER BY 1, 2")); else set = GetConnection()->ExecuteSet( wxT("SELECT 'd' as type, datname, datallowconn, datdba\n") wxT(" FROM pg_database db")); if (set) { while (!set->Eof()) { wxString name = set->GetVal(wxT("datname")); if (set->GetVal(wxT("type")) == wxT("d")) { if (set->GetBool(wxT("datallowconn"))) dblist.Add(name); if (GetUserId() == set->GetLong(wxT("datdba"))) referencedBy->AppendItem(databaseFactory.GetIconId(), _("Database"), name); } else referencedBy->AppendItem(tablespaceFactory.GetIconId(), _("Tablespace"), wxEmptyString, name); set->MoveNext(); } delete set; } FillOwned(form->GetBrowser(), referencedBy, dblist, wxT("SELECT cl.relkind, COALESCE(cin.nspname, cln.nspname) as nspname, COALESCE(ci.relname, cl.relname) as relname, cl.relname as indname\n") wxT(" FROM pg_class cl\n") wxT(" JOIN pg_namespace cln ON cl.relnamespace=cln.oid\n") wxT(" LEFT OUTER JOIN pg_index ind ON ind.indexrelid=cl.oid\n") wxT(" LEFT OUTER JOIN pg_class ci ON ind.indrelid=ci.oid\n") wxT(" LEFT OUTER JOIN pg_namespace cin ON ci.relnamespace=cin.oid\n") wxT(" WHERE cl.relowner = ") + uid + wxT(" AND cl.oid > ") + sysoid + wxT("\n") wxT("UNION ALL\n") wxT("SELECT 'n', null, nspname, null\n") wxT(" FROM pg_namespace nsp WHERE nspowner = ") + uid + wxT(" AND nsp.oid > ") + sysoid + wxT("\n") wxT("UNION ALL\n") wxT("SELECT CASE WHEN typtype='d' THEN 'd' ELSE 'y' END, null, typname, null\n") wxT(" FROM pg_type ty WHERE typowner = ") + uid + wxT(" AND ty.oid > ") + sysoid + wxT("\n") wxT("UNION ALL\n") wxT("SELECT 'C', null, conname, null\n") wxT(" FROM pg_conversion co WHERE conowner = ") + uid + wxT(" AND co.oid > ") + sysoid + wxT("\n") wxT("UNION ALL\n") wxT("SELECT CASE WHEN prorettype=") + NumToStr(PGOID_TYPE_TRIGGER) + wxT(" THEN 'T' ELSE 'p' END, null, proname, null\n") wxT(" FROM pg_proc pr WHERE proowner = ") + uid + wxT(" AND pr.oid > ") + sysoid + wxT("\n") wxT("UNION ALL\n") wxT("SELECT 'o', null, oprname || '('::text || ") wxT("COALESCE(tl.typname, ''::text) || ") wxT("CASE WHEN tl.oid IS NOT NULL AND tr.oid IS NOT NULL THEN ','::text END || ") wxT("COALESCE(tr.typname, ''::text) || ')'::text, null\n") wxT(" FROM pg_operator op\n") wxT(" LEFT JOIN pg_type tl ON tl.oid=op.oprleft\n") wxT(" LEFT JOIN pg_type tr ON tr.oid=op.oprright\n") wxT(" WHERE oprowner = ") + uid + wxT(" AND op.oid > ") + sysoid + wxT("\n") wxT(" ORDER BY 1,2,3")); form->EndMsg(set != 0); }
int dlgServer::Go(bool modal) { chkSSLCompression->Disable(); cbSSL->Clear(); cbSSL->Append(wxT(" ")); #ifdef SSL cbSSL->Append(_("require")); cbSSL->Append(_("prefer")); if (pgConn::GetLibpqVersion() > 7.3) { cbSSL->Append(_("allow")); cbSSL->Append(_("disable")); } if (pgConn::GetLibpqVersion() >= 8.4) { cbSSL->Append(_("verify-ca")); cbSSL->Append(_("verify-full")); } if (pgConn::GetLibpqVersion() >= 9.2) { chkSSLCompression->Enable(); } #endif if (server) { if (cbDatabase->FindString(server->GetDatabaseName()) < 0) cbDatabase->Append(server->GetDatabaseName()); txtHostAddr->SetValue(server->GetHostAddr()); txtDescription->SetValue(server->GetDescription()); txtService->SetValue(server->GetService()); txtServiceID->SetValue(server->GetServiceID()); txtPort->SetValue(NumToStr((long)server->GetPort())); cbSSL->SetSelection(server->GetSSL()); cbDatabase->SetValue(server->GetDatabaseName()); txtUsername->SetValue(server->GetUsername()); chkStorePwd->SetValue(server->GetStorePwd()); txtRolename->SetValue(server->GetRolename()); chkRestore->SetValue(server->GetRestore()); txtDbRestriction->SetValue(server->GetDbRestriction()); colourPicker->SetColour(server->GetColour()); cbGroup->SetValue(server->GetGroup()); pickerSSLCert->SetPath(server->GetSSLCert()); pickerSSLKey->SetPath(server->GetSSLKey()); pickerSSLRootCert->SetPath(server->GetSSLRootCert()); pickerSSLCrl->SetPath(server->GetSSLCrl()); chkSSLCompression->SetValue(server->GetSSLCompression()); stPassword->Disable(); txtPassword->Disable(); if (connection) { txtHostAddr->Disable(); txtDescription->Disable(); txtService->Disable(); txtServiceID->Disable(); txtName->Disable(); cbDatabase->Disable(); txtPort->Disable(); cbSSL->Disable(); txtUsername->Disable(); chkStorePwd->Disable(); txtRolename->Disable(); chkRestore->Disable(); txtDbRestriction->Disable(); colourPicker->Disable(); cbGroup->Disable(); pickerSSLCert->Disable(); pickerSSLKey->Disable(); pickerSSLRootCert->Disable(); pickerSSLCrl->Disable(); chkSSLCompression->Disable(); EnableOK(false); } } else { SetTitle(_("Add server")); cbGroup->SetValue(_("Servers")); wxString colour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW).GetAsString(wxC2S_HTML_SYNTAX); colourPicker->SetColour(colour); } return dlgProperty::Go(modal); }
void dlgServer::OnOK(wxCommandEvent &ev) { #ifdef __WXGTK__ if (!btnOK->IsEnabled()) return; #endif // Display the 'save password' hint if required if(chkStorePwd->GetValue()) { if (frmHint::ShowHint(this, HINT_SAVING_PASSWORDS) == wxID_CANCEL) return; } // notice: changes active after reconnect EnableOK(false); if (server) { server->iSetName(GetName()); server->iSetHostAddr(txtHostAddr->GetValue()); server->iSetDescription(txtDescription->GetValue()); server->iSetService(txtService->GetValue()); if (txtServiceID->GetValue() != server->GetServiceID()) { mainForm->StartMsg(_("Checking server status")); server->iSetServiceID(txtServiceID->GetValue()); mainForm->EndMsg(); } server->iSetPort(StrToLong(txtPort->GetValue())); server->iSetSSL(cbSSL->GetCurrentSelection()); server->iSetDatabase(cbDatabase->GetValue()); server->iSetUsername(txtUsername->GetValue()); server->iSetRolename(txtRolename->GetValue()); server->iSetStorePwd(chkStorePwd->GetValue()); server->iSetRestore(chkRestore->GetValue()); server->iSetDbRestriction(txtDbRestriction->GetValue().Trim()); server->SetSSLCert(pickerSSLCert->GetPath()); server->SetSSLKey(pickerSSLKey->GetPath()); server->SetSSLRootCert(pickerSSLRootCert->GetPath()); server->SetSSLCrl(pickerSSLCrl->GetPath()); server->iSetSSLCompression(chkSSLCompression->GetValue()); wxColour colour = colourPicker->GetColour(); wxString sColour = colour.GetAsString(wxC2S_HTML_SYNTAX); server->iSetColour(sColour); if (cbGroup->GetValue().IsEmpty()) cbGroup->SetValue(_("Servers")); if (server->GetGroup() != cbGroup->GetValue()) { ctlTree *browser = mainForm->GetBrowser(); wxTreeItemId oldgroupitem, groupitem, serveritem; wxTreeItemIdValue groupcookie; bool found; int total; wxString label, oldgroupname; // Duplicate server object pgServer *newserver = new pgServer( server->GetName(), server->GetHostAddr(), server->GetDescription(), server->GetService(), server->GetDatabaseName(), server->GetUsername(), server->GetPort(), server->GetStorePwd(), server->GetRolename(), server->GetRestore(), server->GetSSL(), server->GetColour(), server->GetGroup()); newserver->iSetDbRestriction(server->GetDbRestriction().Trim()); newserver->iSetServiceID(server->GetServiceID().Trim()); newserver->iSetDiscoveryID(server->GetDiscoveryID().Trim()); newserver->SetSSLCert(server->GetSSLCert()); newserver->SetSSLKey(server->GetSSLKey()); newserver->SetSSLRootCert(server->GetSSLRootCert()); newserver->SetSSLCrl(server->GetSSLCrl()); newserver->iSetSSLCompression(server->GetSSLCompression()); // Drop the old item // (will also take care of dropping the pgServer item) oldgroupitem = browser->GetItemParent(item); oldgroupname = server->GetGroup(); if (oldgroupname.IsEmpty()) oldgroupname = _("Servers"); browser->Delete(item); // Move the item found = false; if (browser->ItemHasChildren(browser->GetRootItem())) { groupitem = browser->GetFirstChild(browser->GetRootItem(), groupcookie); while (!found && groupitem) { if (browser->GetItemText(groupitem).StartsWith(cbGroup->GetValue())) found = true; else groupitem = browser->GetNextChild(browser->GetRootItem(), groupcookie); } } if (!found) { groupitem = browser->AppendItem(browser->GetRootItem(), cbGroup->GetValue(), browser->GetItemImage(browser->GetRootItem())); browser->SortChildren(browser->GetRootItem()); } serveritem = browser->AppendItem(groupitem, newserver->GetFullName(), newserver->GetIconId(), -1, newserver); browser->SortChildren(groupitem); browser->Expand(groupitem); browser->SelectItem(serveritem); // Count the number of items in the old group item total = browser->GetChildrenCount(oldgroupitem, false); if (total == 0) browser->Delete(oldgroupitem); else { label = oldgroupname + wxT(" (") + NumToStr((long)total) + wxT(")"); browser->SetItemText(oldgroupitem, label); } // Count the number of items in the new group item total = browser->GetChildrenCount(groupitem, false); label = cbGroup->GetValue() + wxT(" (") + NumToStr((long)total) + wxT(")"); browser->SetItemText(groupitem, label); // Re-initialize old variables to have their new meanings server = newserver; item = serveritem; } server->iSetGroup(cbGroup->GetValue()); mainForm->execSelChange(server->GetId(), true); mainForm->GetBrowser()->SetItemText(item, server->GetFullName()); mainForm->SetItemBackgroundColour(item, wxColour(server->GetColour())); mainForm->StoreServers(); } if (IsModal()) { EndModal(wxID_OK); return; } else Destroy(); }
//WARNING: event ID must match enum ddDataType!!! this event was created on view void ddTextTableItemFigure::OnGenericPopupClick(wxCommandEvent &event, hdDrawingView *view) { wxTextEntryDialog *nameDialog = NULL; ddPrecisionScaleDialog *numericDialog = NULL; wxString tmpString; int answer; int tmpprecision; long tmpvalue; hdRemoveDeleteDialog *delremDialog = NULL; switch(event.GetId()) { case MNU_DDADDCOLUMN: nameDialog = new wxTextEntryDialog(view, wxT("New column name"), wxT("Add a column")); answer = nameDialog->ShowModal(); if (answer == wxID_OK) { tmpString = nameDialog->GetValue(); getOwnerColumn()->getOwnerTable()->addColumn(view->getIdx(), new ddColumnFigure(tmpString, getOwnerColumn()->getOwnerTable())); view->notifyChanged(); } delete nameDialog; break; case MNU_DELCOLUMN: answer = wxMessageBox(wxT("Are you sure you wish to delete column ") + getText(true) + wxT("?"), wxT("Delete column?"), wxYES_NO | wxNO_DEFAULT, view); if (answer == wxYES) { getOwnerColumn()->getOwnerTable()->removeColumn(view->getIdx(), getOwnerColumn()); view->notifyChanged(); } break; case MNU_AUTONAMCOLUMN: getOwnerColumn()->activateGenFkName(); getOwnerColumn()->getFkSource()->syncAutoFkName(); view->notifyChanged(); break; case MNU_RENAMECOLUMN: nameDialog = new wxTextEntryDialog(view, wxT("New column name"), wxT("Rename Column"), getText()); nameDialog->ShowModal(); if(getOwnerColumn()->isGeneratedForeignKey()) //after a manual user column rename, deactivated automatic generation of fk name. getOwnerColumn()->deactivateGenFkName(); setText(nameDialog->GetValue()); delete nameDialog; view->notifyChanged(); break; case MNU_NOTNULL: if(getOwnerColumn()->isNotNull()) getOwnerColumn()->setColumnOption(null); else getOwnerColumn()->setColumnOption(notnull); view->notifyChanged(); break; case MNU_PKEY: if(getOwnerColumn()->isPrimaryKey()) { getOwnerColumn()->disablePrimaryKey(); } else { getOwnerColumn()->enablePrimaryKey(); getOwnerColumn()->setColumnOption(notnull); } view->notifyChanged(); break; case MNU_UKEY: getOwnerColumn()->toggleColumnKind(uk, view); view->notifyChanged(); break; case MNU_TYPESERIAL: setDataType(dt_serial); //Should use setDataType always to set this value to allow fk to work flawlessly recalculateDisplayBox(); getOwnerColumn()->displayBoxUpdate(); getOwnerColumn()->getOwnerTable()->updateTableSize(); view->notifyChanged(); break; case MNU_TYPEBOOLEAN: setDataType(dt_boolean); recalculateDisplayBox(); getOwnerColumn()->displayBoxUpdate(); getOwnerColumn()->getOwnerTable()->updateTableSize(); view->notifyChanged(); break; case MNU_TYPEINTEGER: setDataType(dt_integer); recalculateDisplayBox(); getOwnerColumn()->displayBoxUpdate(); getOwnerColumn()->getOwnerTable()->updateTableSize(); view->notifyChanged(); break; case MNU_TYPEMONEY: setDataType(dt_money); recalculateDisplayBox(); getOwnerColumn()->displayBoxUpdate(); getOwnerColumn()->getOwnerTable()->updateTableSize(); view->notifyChanged(); break; case MNU_TYPEVARCHAR: setDataType(dt_varchar); tmpprecision = wxGetNumberFromUser(_("Varchar size"), _("Size for varchar datatype"), _("Varchar size"), getPrecision(), 0, 255, view); if (tmpprecision >= 0) { setPrecision(tmpprecision); setScale(-1); } recalculateDisplayBox(); getOwnerColumn()->displayBoxUpdate(); getOwnerColumn()->getOwnerTable()->updateTableSize(); view->notifyChanged(); break; case MNU_TYPEOTHER: answer = wxGetSingleChoiceIndex(wxT("New column datatype"), wxT("Column Datatypes"), dataTypes(), view); if(answer >= 0) { view->notifyChanged(); if(answer == dt_varchar || answer == dt_bit || answer == dt_char || answer == dt_interval || answer == dt_varbit) { tmpprecision = wxGetNumberFromUser(_("datatype size"), _("Size for datatype"), _("size"), getPrecision(), 0, 255, view); if (tmpprecision >= 0) { setPrecision(tmpprecision); setScale(-1); } recalculateDisplayBox(); getOwnerColumn()->displayBoxUpdate(); getOwnerColumn()->getOwnerTable()->updateTableSize(); } if(answer == dt_numeric) { numericDialog = new ddPrecisionScaleDialog( view, NumToStr((long)getPrecision()), NumToStr((long)getScale())); numericDialog->ShowModal(); numericDialog->GetValue1().ToLong(&tmpvalue); setPrecision(tmpvalue); numericDialog->GetValue2().ToLong(&tmpvalue); setScale(tmpvalue); delete numericDialog; recalculateDisplayBox(); getOwnerColumn()->displayBoxUpdate(); getOwnerColumn()->getOwnerTable()->updateTableSize(); } setDataType( (ddDataType) answer ); recalculateDisplayBox(); getOwnerColumn()->displayBoxUpdate(); getOwnerColumn()->getOwnerTable()->updateTableSize(); } break; case MNU_TYPEPKEY_CONSTRAINTNAME: tmpString = wxGetTextFromUser(wxT("New name of primary key:"), getOwnerColumn()->getOwnerTable()->getPkConstraintName(), getOwnerColumn()->getOwnerTable()->getPkConstraintName(), view); if(tmpString.length() > 0) { getOwnerColumn()->getOwnerTable()->setPkConstraintName(tmpString); view->notifyChanged(); } break; case MNU_TYPEUKEY_CONSTRAINTNAME: answer = wxGetSingleChoiceIndex(wxT("Select Unique Key constraint to edit name"), wxT("Select Unique Constraint to edit name:"), getOwnerColumn()->getOwnerTable()->getUkConstraintsNames(), view); if(answer >= 0) { tmpString = wxGetTextFromUser(wxT("Change name of Unique Key constraint:"), getOwnerColumn()->getOwnerTable()->getUkConstraintsNames().Item(answer), getOwnerColumn()->getOwnerTable()->getUkConstraintsNames().Item(answer), view); if(tmpString.length() > 0) { getOwnerColumn()->getOwnerTable()->getUkConstraintsNames().Item(answer) = tmpString; view->notifyChanged(); } } break; case MNU_DELTABLE: delremDialog = new hdRemoveDeleteDialog(wxT("Are you sure you wish to delete table ") + getOwnerColumn()->getOwnerTable()->getTableName() + wxT("?"), wxT("Delete table?"), view); answer = delremDialog->ShowModal(); ddTableFigure *table = getOwnerColumn()->getOwnerTable(); if (answer == DD_DELETE) { ddDrawingEditor *editor = (ddDrawingEditor *) view->editor(); //Unselect table at all diagrams editor->removeFromAllSelections(table); //Drop foreign keys with this table as origin or destination table->processDeleteAlert(view->getDrawing()); //Drop table editor->deleteModelFigure(table); editor->getDesign()->refreshBrowser(); view->notifyChanged(); } else if(answer == DD_REMOVE) { ddDrawingEditor *editor = (ddDrawingEditor *) view->editor(); editor->getExistingDiagram(view->getIdx())->removeFromSelection(table); editor->getExistingDiagram(view->getIdx())->remove(table); view->notifyChanged(); } delete delremDialog; break; } }
pgConn::pgConn(const wxString &server, const wxString &service, const wxString &hostaddr, const wxString &database, const wxString &username, const wxString &password, int port, const wxString &rolename, int sslmode, OID oid, const wxString &applicationname, const wxString &sslcert, const wxString &sslkey, const wxString &sslrootcert, const wxString &sslcrl, const bool sslcompression) : m_cancelConn(NULL) { wxString msg; save_server = server; save_hostaddr = hostaddr; save_service = service; save_database = database; save_username = username; save_password = password; save_port = port; save_rolename = rolename; save_sslmode = sslmode; save_oid = oid; save_applicationname = applicationname; save_sslcert = sslcert; save_sslkey = sslkey; save_sslrootcert = sslrootcert; save_sslcrl = sslcrl; save_sslcompression = sslcompression; memset(features, 0, sizeof(features)); majorVersion = 0; conv = &wxConvLibc; needColQuoting = false; utfConnectString = false; // Check the hostname/ipaddress conn = 0; noticeArg = 0; connStatus = PGCONN_BAD; // Create the connection string if (!server.IsEmpty()) { connstr.Append(wxT(" host=")); connstr.Append(qtConnString(server)); } if (!hostaddr.IsEmpty()) { connstr.Append(wxT(" hostaddr=")); connstr.Append(qtConnString(hostaddr)); } if (!service.IsEmpty()) { connstr.Append(wxT(" service=")); connstr.Append(qtConnString(service)); } if (!database.IsEmpty()) { connstr.Append(wxT(" dbname=")); connstr.Append(qtConnString(database)); } if (!username.IsEmpty()) { connstr.Append(wxT(" user="******" password="******" port=")); connstr.Append(NumToStr((long)port)); } if (libpqVersion > 7.3) { switch (sslmode) { case 1: connstr.Append(wxT(" sslmode=require")); break; case 2: connstr.Append(wxT(" sslmode=prefer")); break; case 3: connstr.Append(wxT(" sslmode=allow")); break; case 4: connstr.Append(wxT(" sslmode=disable")); break; case 5: connstr.Append(wxT(" sslmode=verify-ca")); break; case 6: connstr.Append(wxT(" sslmode=verify-full")); break; } } else { switch (sslmode) { case 1: connstr.Append(wxT(" requiressl=1")); break; case 2: connstr.Append(wxT(" requiressl=0")); break; } } if (libpqVersion > 8.3 && sslmode != 4) { if (!sslcert.IsEmpty()) { connstr.Append(wxT(" sslcert=")); connstr.Append(qtConnString(sslcert)); } if (!sslkey.IsEmpty()) { connstr.Append(wxT(" sslkey=")); connstr.Append(qtConnString(sslkey)); } if (!sslrootcert.IsEmpty()) { connstr.Append(wxT(" sslrootcert=")); connstr.Append(qtConnString(sslrootcert)); } if (!sslcrl.IsEmpty()) { connstr.Append(wxT(" sslcrl=")); connstr.Append(qtConnString(sslcrl)); } } if (libpqVersion > 9.1 && sslmode != 4) { if (!sslcompression) { connstr.Append(wxT(" sslcompression=0")); } } connstr.Trim(false); dbHost = server; dbHostName = server; dbRole = rolename; #ifdef HAVE_CONNINFO_PARSE if (!applicationname.IsEmpty()) { // Check connection string with application_name char *errmsg; wxString connstr_with_applicationname = connstr + wxT(" application_name='") + applicationname + wxT("'"); if (PQconninfoParse(connstr_with_applicationname.mb_str(wxConvUTF8), &errmsg)) { connstr = connstr_with_applicationname; } else if (PQconninfoParse(connstr_with_applicationname.mb_str(wxConvLibc), &errmsg)) { connstr = connstr_with_applicationname; } } #endif // Open the connection wxString cleanConnStr = connstr; cleanConnStr.Replace(qtConnString(password), wxT("'XXXXXX'")); wxLogInfo(wxT("Opening connection with connection string: %s"), cleanConnStr.c_str()); DoConnect(); }
int dlgDomain::Go(bool modal) { if (connection->BackendMinimumVersion(9, 1)) { seclabelPage->SetConnection(connection); seclabelPage->SetObject(domain); this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgDomain::OnChange)); } else seclabelPage->Disable(); if (domain) { // edit mode cbSchema->Enable(connection->BackendMinimumVersion(8, 1)); cbDatatype->Append(domain->GetBasetype()); AddType(wxT(" "), 0, domain->GetBasetype()); cbDatatype->SetSelection(0); if (domain->GetLength() >= 0) { txtLength->SetValue(NumToStr(domain->GetLength())); if (domain->GetPrecision() >= 0) txtPrecision->SetValue(NumToStr(domain->GetPrecision())); } chkNotNull->SetValue(domain->GetNotNull()); txtDefault->SetValue(domain->GetDefault()); txtCheck->SetValue(domain->GetCheck()); cbDatatype->Disable(); cbCollation->SetValue(domain->GetQuotedCollation()); cbCollation->Disable(); if (!connection->BackendMinimumVersion(7, 4)) { cbOwner->Disable(); txtDefault->Disable(); chkNotNull->Disable(); } if (connection->BackendMinimumVersion(9, 2)) chkDontValidate->SetValue(!domain->GetValid()); } else { // create mode if (!connection->BackendMinimumVersion(7, 4)) txtCheck->Disable(); FillDatatype(cbDatatype, false); cbCollation->Enable(connection->BackendMinimumVersion(9, 1)); if (connection->BackendMinimumVersion(9, 1)) { // 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); } } if (connection->BackendMinimumVersion(9, 2)) chkDontValidate->Enable(!domain || (domain && !domain->GetValid())); else chkDontValidate->Enable(false); return dlgProperty::Go(modal); }
int dlgRole::Go(bool modal) { // In wxMac, the text deletion of "calenderBox" is not raising the EVT_CALENDAR_SEL_CHANGED, EVT_DATE_CHANGED events properly. // Hence, raising these events with wxEVT_CHILD_FOCUS events. // #ifdef __WXMAC__ datValidUntil->Connect(wxEVT_CHILD_FOCUS, wxCommandEventHandler(dlgRole::OnChange), NULL, this); timValidUntil->Connect(wxEVT_CHILD_FOCUS, wxCommandEventHandler(dlgRole::OnChange), NULL, this); #endif if (connection->BackendMinimumVersion(9, 0)) { cbVarDbname->Append(wxT("")); AddDatabases(cbVarDbname); } else { cbVarDbname->Enable(false); } if (connection->BackendMinimumVersion(9, 2)) { seclabelPage->SetConnection(connection); seclabelPage->SetObject(role); this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgRole::OnChange)); } else seclabelPage->Disable(); wxString roleSql = wxT("SELECT rolname\n") wxT(" FROM pg_roles r\n"); varInfo.Add(wxT("role")); cbVarname->Append(wxT("role")); pgSet *set; set = connection->ExecuteSet(wxT("SELECT name, vartype, min_val, max_val\n") wxT(" FROM pg_settings WHERE context in ('user', 'superuser')")); if (set) { while (!set->Eof()) { cbVarname->Append(set->GetVal(0)); varInfo.Add(set->GetVal(wxT("vartype")) + wxT(" ") + set->GetVal(wxT("min_val")) + wxT(" ") + set->GetVal(wxT("max_val"))); set->MoveNext(); } delete set; cbVarname->SetSelection(0); if (connection->BackendMinimumVersion(9, 0)) { cbVarDbname->SetSelection(0); } SetupVarEditor(0); } if (role) { wxArrayString roles = role->GetRolesIn(); size_t i; for (i = 0 ; i < roles.GetCount() ; i++) lbRolesIn->Append(roles.Item(i)); roleSql += wxT(" LEFT JOIN pg_auth_members ON r.oid=roleid AND member = ") + role->GetOidStr() + wxT("\n") wxT(" WHERE r.oid <> ") + role->GetOidStr() + wxT("\n") wxT(" AND roleid IS NULL"); // Edit Mode if (role->GetServer()->GetSuperUser() || role->GetServer()->GetCreateRole()) readOnly = false; else readOnly = true; chkCreateDB->SetValue(role->GetCreateDatabase()); chkCreateRole->SetValue(role->GetCreateRole()); chkSuperuser->SetValue(role->GetSuperuser()); chkInherits->SetValue(role->GetInherits()); if (!connection->BackendMinimumVersion(9, 5)) chkUpdateCat->SetValue(role->GetUpdateCatalog()); else chkUpdateCat->Disable(); chkCanLogin->SetValue(role->GetCanLogin()); chkReplication->SetValue(role->GetReplication()); if (role->GetAccountExpires().IsValid() && role->GetAccountExpires().GetValue() != -1) { datValidUntil->SetValue(role->GetAccountExpires().GetDateOnly()); timValidUntil->SetTime(role->GetAccountExpires()); } else { wxDateTime empty; datValidUntil->SetValue(empty); } txtConnectionLimit->SetValue(NumToStr(role->GetConnectionLimit())); txtComment->SetValue(role->GetComment()); size_t index; wxString dbname; wxString parameter; wxString value; for (index = 0 ; index < role->GetVariables().GetCount() ; index += 3) { dbname = role->GetVariables().Item(index); parameter = role->GetVariables().Item(index + 1); value = role->GetVariables().Item(index + 2); lstVariables->AppendItem(0, dbname, parameter, value); } timValidUntil->Enable(!readOnly && role->GetAccountExpires().IsValid()); if (readOnly) { chkCanLogin->Disable(); chkCreateDB->Disable(); chkCreateRole->Disable(); chkSuperuser->Disable(); chkInherits->Disable(); chkUpdateCat->Disable(); chkReplication->Disable(); datValidUntil->Disable(); timValidUntil->Disable(); btnAddRole->Disable(); btnDelRole->Disable(); cbVarname->Disable(); cbVarDbname->Disable(); txtValue->Disable(); txtConnectionLimit->Disable(); btnRemove->Disable(); /* Its own password can be changed. */ if (connection->GetUser() != role->GetName()) { txtPasswd->Disable(); txtRePasswd->Disable(); btnAdd->Disable(); } else { txtPasswd->Enable(); txtRePasswd->Enable(); btnAdd->Enable(); } } } else { chkCanLogin->Disable(); wxDateTime empty; datValidUntil->SetValue(empty); timValidUntil->Disable(); } // Role comments are only appropriate in 8.2+ if (!connection->BackendMinimumVersion(8, 2)) txtComment->Disable(); // Replication roles added in 9.1 if (!connection->BackendMinimumVersion(9, 1)) { chkReplication->Disable(); } if (!settings->GetShowUsersForPrivileges()) { if (role) roleSql += wxT("\n AND NOT rolcanlogin"); else roleSql += wxT("\n WHERE NOT rolcanlogin"); } roleSql += wxT("\n ORDER BY rolname"); pgSetIterator roles(connection, roleSql); while (roles.RowsLeft()) lbRolesNotIn->Append(roles.GetVal(wxT("rolname"))); return dlgProperty::Go(modal); }
char *TechTypeToString(TechnologyType tech) { return NumToStr(techtypeinfo,(uword)tech); }
bool pgConn::Initialize() { // Set client encoding to Unicode/Ascii, Datestyle to ISO, and ask for notices. if (PQstatus(conn) == CONNECTION_OK) { connStatus = PGCONN_OK; PQsetNoticeProcessor(conn, pgNoticeProcessor, this); wxString sql = wxT("SET DateStyle=ISO;\nSET client_min_messages=notice;\n"); if (BackendMinimumVersion(9, 0)) sql += wxT("SET bytea_output=escape;\n"); sql += wxT("SELECT oid, pg_encoding_to_char(encoding) AS encoding, datlastsysoid\n") wxT(" FROM pg_database WHERE "); if (save_oid) sql += wxT("oid = ") + NumToStr(save_oid); else { // Note, can't use qtDbString here as we don't know the server version yet. wxString db = save_database; db.Replace(wxT("\\"), wxT("\\\\")); db.Replace(wxT("'"), wxT("''")); sql += wxT("datname=") + qtString(db); } pgSet *set = ExecuteSet(sql); if (set) { if (set->ColNumber(wxT("\"datlastsysoid\"")) >= 0) needColQuoting = true; lastSystemOID = set->GetOid(wxT("datlastsysoid")); dbOid = set->GetOid(wxT("oid")); wxString encoding = set->GetVal(wxT("encoding")); if (encoding != wxT("SQL_ASCII") && encoding != wxT("MULE_INTERNAL")) { encoding = wxT("UNICODE"); conv = &wxConvUTF8; } else conv = &wxConvLibc; wxLogInfo(wxT("Setting client_encoding to '%s'"), encoding.c_str()); if (PQsetClientEncoding(conn, encoding.ToAscii())) { wxLogError(wxT("%s"), GetLastError().c_str()); } delete set; // Switch to the requested default role if supported by backend if (dbRole != wxEmptyString && BackendMinimumVersion(8, 1)) { sql = wxT("SET ROLE TO "); sql += qtIdent(dbRole); pgSet *set = ExecuteSet(sql); if (set) delete set; else return false; } return true; } } return false; }
int dlgDatabase::Go(bool modal) { bool createDefPriv = false; wxString strDefPrivsOnTables, strDefPrivsOnSeqs, strDefPrivsOnFuncs, strDefPrivsOnTypes; if (connection->BackendMinimumVersion(9, 2)) { seclabelPage->SetConnection(connection); seclabelPage->SetObject(database); this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgDatabase::OnChange)); } else seclabelPage->Disable(); if (connection->BackendMinimumVersion(9, 0)) { cbVarUsername->Append(wxT("")); // AddUsers function of dlgDefaultSecurity has already been called. // Hence, calling dlgProperty::AddUsers instead of that. dlgProperty::AddUsers(cbVarUsername); } else cbVarUsername->Enable(false); if (connection->BackendMinimumVersion(8, 0)) { stPath->Hide(); txtPath->Hide(); } else { stTablespace->Hide(); cbTablespace->Hide(); } if (!connection->BackendMinimumVersion(8, 1)) { txtConnLimit->Disable(); } else txtConnLimit->SetValidator(numericValidator); if (!connection->BackendMinimumVersion(8, 4)) { cbCollate->Disable(); cbCType->Disable(); } pgSet *set; if (connection->BackendMinimumVersion(7, 4)) set = connection->ExecuteSet(wxT("SELECT name, vartype, min_val, max_val\n") wxT(" FROM pg_settings WHERE context in ('user', 'superuser')")); else set = connection->ExecuteSet(wxT("SELECT name, 'string' as vartype, '' as min_val, '' as max_val FROM pg_settings")); if (set) { while (!set->Eof()) { cbVarname->Append(set->GetVal(0)); varInfo.Add(set->GetVal(wxT("vartype")) + wxT(" ") + set->GetVal(wxT("min_val")) + wxT(" ") + set->GetVal(wxT("max_val"))); set->MoveNext(); } delete set; cbVarname->SetSelection(0); if (connection->BackendMinimumVersion(9, 0)) { cbVarUsername->SetSelection(0); } SetupVarEditor(0); } if (database) { // edit mode if (!connection->BackendMinimumVersion(7, 4)) txtName->Disable(); if (!connection->BackendMinimumVersion(8, 0)) cbOwner->Disable(); readOnly = !database->GetServer()->GetCreatePrivilege(); if (connection->BackendMinimumVersion(9, 0)) { createDefPriv = true; strDefPrivsOnTables = database->GetDefPrivsOnTables(); strDefPrivsOnSeqs = database->GetDefPrivsOnSequences(); strDefPrivsOnFuncs = database->GetDefPrivsOnFunctions(); } if (connection->BackendMinimumVersion(9, 2)) strDefPrivsOnTypes = database->GetDefPrivsOnTypes(); if (readOnly) { cbVarname->Disable(); cbVarUsername->Disable(); txtValue->Disable(); btnAdd->Disable(); btnRemove->Disable(); } size_t i; wxString username; wxString varname; wxString varvalue; for (i = 0 ; i < database->GetVariables().GetCount() ; i += 3) { username = database->GetVariables().Item(i); varname = database->GetVariables().Item(i + 1); varvalue = database->GetVariables().Item(i + 2); lstVariables->AppendItem(0, username, varname, varvalue); } PrepareTablespace(cbTablespace, database->GetTablespaceOid()); if (connection->BackendMinimumVersion(8, 4)) cbTablespace->Enable(); else cbTablespace->Disable(); txtPath->SetValue(database->GetPath()); txtPath->Disable(); cbEncoding->Append(database->GetEncoding()); cbEncoding->SetSelection(0); if (connection->BackendMinimumVersion(8, 1)) { wxString strConnLimit; strConnLimit.Printf(wxT("%ld"), database->GetConnectionLimit()); txtConnLimit->SetValue(strConnLimit); } if (connection->BackendMinimumVersion(8, 4)) { cbCollate->Append(database->GetCollate()); cbCollate->SetSelection(0); cbCType->Append(database->GetCType()); cbCType->SetSelection(0); } cbTemplate->Disable(); cbEncoding->Disable(); cbCollate->Disable(); cbCType->Disable(); txtSchemaRestr->SetValue(database->GetSchemaRestriction()); } else { // create mode if (!connection->BackendMinimumVersion(8, 2)) txtComment->Disable(); PrepareTablespace(cbTablespace); // Add the default tablespace cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0); cbTablespace->SetSelection(0); cbTemplate->Append(wxEmptyString); FillCombobox(wxT("SELECT datname FROM pg_database ORDER BY datname"), cbTemplate); cbTemplate->SetSelection(0); if (connection->BackendMinimumVersion(8, 4)) { FillCombobox(wxT("select DISTINCT(datctype) from pg_database UNION SELECT DISTINCT(datcollate) from pg_database"), cbCollate, cbCType); if (cbCollate->FindString(wxT("C")) < 0) { cbCollate->AppendString(wxT("C")); cbCType->AppendString(wxT("C")); } if (cbCollate->FindString(wxT("POSIX")) < 0) { cbCollate->AppendString(wxT("POSIX")); cbCType->AppendString(wxT("POSIX")); } } if (connection->BackendMinimumVersion(8, 1)) { txtConnLimit->SetValue(wxT("-1")); } long encNo = 0; wxString encStr; do { encStr = connection->ExecuteScalar( wxT("SELECT pg_encoding_to_char(") + NumToStr(encNo) + wxT(")")); if (pgConn::IsValidServerEncoding(encNo) && !encStr.IsEmpty()) cbEncoding->Append(encStr); encNo++; } while (!encStr.IsEmpty()); encStr = connection->ExecuteScalar(wxT("SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = 'template0'")); encNo = cbEncoding->FindString(encStr); if (encNo < 0) { encNo = cbEncoding->FindString(wxT("UNICODE")); if (encNo < 0) encNo = cbEncoding->FindString(wxT("UTF8")); } if (encNo >= 0) cbEncoding->SetSelection(encNo); } // Find, and disable the CONNECT ACL option if we're on pre 8.2 if (!connection->BackendMinimumVersion(8, 2)) { // Disable the checkbox if (!DisablePrivilege(wxT("CONNECT"))) { wxLogError(_("Failed to disable the CONNECT privilege checkbox!")); } } return dlgDefaultSecurityProperty::Go(modal, createDefPriv, strDefPrivsOnTables, strDefPrivsOnSeqs, strDefPrivsOnFuncs, strDefPrivsOnTypes); }
pgObject *edbPackageFactory::CreateObjects(pgCollection *collection, ctlTree *browser, const wxString &restriction) { edbPackage *package=0; wxString sql; if (collection->GetConnection()->EdbMinimumVersion(8, 2)) { sql = wxT("SELECT nsp.oid, nsp.xmin, nspname AS pkgname, nspbodysrc AS pkgbodysrc, nspheadsrc AS pkgheadsrc,\n") wxT(" nspacl AS pkgacl, pg_get_userbyid(nspowner) AS owner, description\n") wxT(" FROM pg_namespace nsp") wxT(" LEFT OUTER JOIN pg_description des ON des.objoid=nsp.oid\n") wxT(" WHERE nspparent = ") + NumToStr(collection->GetSchema()->GetOid()) + wxT("::oid\n") + restriction + wxT(" ORDER BY nspname;"); } else { sql = wxT("SELECT oid, xmin, *, pg_get_userbyid(pkgowner) AS owner\n") wxT(" FROM edb_package") wxT(" WHERE pkgnamespace = ") + NumToStr(collection->GetSchema()->GetOid()) + wxT("::oid\n") + restriction + wxT(" ORDER BY pkgname;"); } pgSet *packages = collection->GetDatabase()->ExecuteSet(sql); if (packages) { while (!packages->Eof()) { wxString name=packages->GetVal(wxT("pkgname")); package = new edbPackage(collection->GetSchema(), name); package->iSetOid(packages->GetOid(wxT("oid"))); package->iSetXid(packages->GetOid(wxT("xmin"))); package->iSetDatabase(collection->GetDatabase()); package->iSetOwner(packages->GetVal(wxT("owner"))); if (collection->GetConnection()->EdbMinimumVersion(8, 2)) package->iSetComment(packages->GetVal(wxT("description"))); // EnterpriseDB's CVS code has some new parser code // which is stricter about the formatting of body & // header code and leaves off trailing ;'s wxString tmp = packages->GetVal(wxT("pkgheadsrc")).Strip(wxString::both); if (!tmp.EndsWith(wxT(";"))) package->iSetHeader(tmp + wxT(";")); else package->iSetHeader(tmp); tmp = packages->GetVal(wxT("pkgbodysrc")).Strip(wxString::both); if (!tmp.EndsWith(wxT(";")) && !tmp.IsEmpty()) package->iSetBody(tmp + wxT(";")); else package->iSetBody(tmp); package->iSetAcl(packages->GetVal(wxT("pkgacl"))); if (browser) { browser->AppendObject(collection, package); packages->MoveNext(); } else break; } delete packages; } return package; }
wxString pgRole::GetSql(ctlTree *browser) { if (sql.IsNull()) { sql = wxT("-- Role: ") + GetName() + wxT("\n\n") + wxT("-- DROP ROLE ") + GetQuotedFullIdentifier() + wxT(";") + wxT("\n\nCREATE ROLE ") + GetQuotedIdentifier(); if (GetCanLogin()) { sql += wxT(" LOGIN"); if (GetPassword() != wxT("********") && !GetPassword().IsEmpty()) AppendIfFilled(sql, wxT("\n ENCRYPTED PASSWORD "), qtDbString(GetPassword())); } sql += wxT("\n "); if (this->GetSuperuser()) sql += wxT(" SUPERUSER"); else sql += wxT(" NOSUPERUSER"); if (GetInherits()) sql += wxT(" INHERIT"); else sql += wxT(" NOINHERIT"); if (GetCreateDatabase()) sql += wxT(" CREATEDB"); else sql += wxT(" NOCREATEDB"); if (GetCreateRole()) sql += wxT(" CREATEROLE"); else sql += wxT(" NOCREATEROLE"); if (server->GetConnection()->BackendMinimumVersion(9, 1)) { if (GetReplication()) sql += wxT(" REPLICATION"); else sql += wxT(" NOREPLICATION"); } if (GetConnectionLimit() > 0) sql += wxT(" CONNECTION LIMIT ") + NumToStr(GetConnectionLimit()); if (GetAccountExpires().IsValid()) AppendIfFilled(sql, wxT(" VALID UNTIL "), qtDbString(DateToAnsiStr(GetAccountExpires()))); if (GetRolQueueName().Length() > 0) AppendIfFilled(sql, wxT(" RESOURCE QUEUE "), GetRolQueueName()); sql +=wxT(";\n"); if (this->GetSuperuser() && !GetUpdateCatalog()) sql += wxT("UPDATE pg_authid SET rolcatupdate=false WHERE rolname=") + qtDbString(GetIdentifier()) + 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 ROLE ") + GetQuotedIdentifier() + wxT(" SET ") + configList.Item(index).BeforeFirst('=') + wxT("='") + configList.Item(index).AfterFirst('=') + wxT("';\n"); else sql += wxT("ALTER ROLE ") + GetQuotedIdentifier() + wxT(" SET ") + configList.Item(index).BeforeFirst('=') + wxT("=") + configList.Item(index).AfterFirst('=') + wxT(";\n"); } for (index=0 ; index < rolesIn.GetCount() ; index++) { wxString role=rolesIn.Item(index); bool admin=false; if (role.Right(PGROLE_ADMINOPTION_LEN) == PGROLE_ADMINOPTION) { admin=true; role=role.Left(role.Length()-PGROLE_ADMINOPTION_LEN); } sql += wxT("GRANT ") + qtIdent(role) + wxT(" TO ") + GetQuotedIdentifier(); if (admin) sql += wxT(" WITH ADMIN OPTION"); sql += wxT(";\n"); } if (!GetComment().IsNull()) { sql += wxT("COMMENT ON ROLE ") + GetQuotedFullIdentifier() + wxT(" IS ") + qtDbString(GetComment()) + wxT(";\n"); } } return sql; }
int dlgTrigger::Go(bool modal) { if (trigger) { // edit mode chkRow->SetValue((trigger->GetTriggerType() & TRIGGER_TYPE_ROW) != 0); chkInsert->SetValue((trigger->GetTriggerType() & TRIGGER_TYPE_INSERT) != 0); chkUpdate->SetValue((trigger->GetTriggerType() & TRIGGER_TYPE_UPDATE) != 0); chkDelete->SetValue((trigger->GetTriggerType() & TRIGGER_TYPE_DELETE) != 0); chkTruncate->SetValue((trigger->GetTriggerType() & TRIGGER_TYPE_TRUNCATE) != 0); if (trigger->GetTriggerType() & TRIGGER_TYPE_BEFORE) rdbFires->SetSelection(0); else if (trigger->GetTriggerType() & TRIGGER_TYPE_INSTEAD) rdbFires->SetSelection(2); else rdbFires->SetSelection(1); txtArguments->SetValue(trigger->GetArguments()); txtWhen->SetValue(trigger->GetWhen()); if (!connection->BackendMinimumVersion(7, 4)) txtName->Disable(); if (trigger->GetLanguage() == wxT("edbspl")) { cbFunction->Append(wxString::Format(wxT("<%s>"), _("Inline EDB-SPL"))); txtBody->SetText(trigger->GetSource()); } else { cbFunction->Append(trigger->GetFunction()); txtBody->Disable(); } cbFunction->SetSelection(0); txtArguments->Disable(); cbFunction->Disable(); if (!connection->EdbMinimumVersion(8, 0)) { chkRow->Disable(); rdbFires->Disable(); chkInsert->Disable(); chkUpdate->Disable(); chkDelete->Disable(); chkTruncate->Disable(); } else if (!connection->BackendMinimumVersion(8, 4)) chkTruncate->Disable(); else if (!connection->BackendMinimumVersion(8, 5)) txtWhen->Disable(); wxArrayString colsArr = trigger->GetColumnList(); for (int colIdx = 0, colsCount = colsArr.Count(); colIdx < colsCount; colIdx++) { lstColumns->InsertItem(colIdx, colsArr.Item(colIdx)); } if (connection->BackendMinimumVersion(8, 2)) { chkConstraint->SetValue(trigger->GetIsConstraint()); chkDeferrable->SetValue(trigger->GetDeferrable()); chkDeferred->SetValue(trigger->GetDeferred()); } chkConstraint->Enable(false); chkDeferrable->Enable(false); chkDeferred->Enable(false); } else { // create mode if (connection->EdbMinimumVersion(8, 0)) cbFunction->Append(wxString::Format(wxT("<%s>"), _("Inline EDB-SPL"))); wxString sysRestr; if (!settings->GetShowSystemObjects()) sysRestr = wxT(" AND ") + connection->SystemNamespaceRestriction(wxT("nspname")); pgSet *set = connection->ExecuteSet( wxT("SELECT quote_ident(nspname) || '.' || quote_ident(proname)\n") wxT(" FROM pg_proc p, pg_namespace n, pg_language l\n") wxT(" WHERE p.pronamespace = n.oid AND p.prolang = l.oid AND l.lanname != 'edbspl' AND prorettype=") + NumToStr(PGOID_TYPE_TRIGGER) + sysRestr + wxT(" ORDER BY nspname ASC, proname ASC ")); if (set) { while (!set->Eof()) { cbFunction->Append(set->GetVal(0)); set->MoveNext(); } delete set; } if (!connection->BackendMinimumVersion(7, 4)) { chkRow->SetValue(true); chkRow->Disable(); } txtBody->Disable(); if (!connection->BackendMinimumVersion(8, 4)) chkTruncate->Disable(); if (!connection->BackendMinimumVersion(9, 1) || table->GetMetaType() != PGM_VIEW) rdbFires->Enable(2, false); chkConstraint->Enable(connection->BackendMinimumVersion(8, 2)); chkDeferrable->Disable(); chkDeferred->Disable(); } cbColumns->Disable(); btnAddCol->Disable(); btnRemoveCol->Disable(); // Reset the radio box rbxEvent item values with the keywords to resolve the locale issues. rdbFires->SetString(0, wxT("BEFORE")); rdbFires->SetString(1, wxT("AFTER")); rdbFires->SetString(2, wxT("INSTEAD OF")); chkTruncate->SetLabel(wxT("TRUNCATE")); chkDelete->SetLabel(wxT("DELETE")); chkInsert->SetLabel(wxT("INSERT")); chkUpdate->SetLabel(wxT("UPDATE")); return dlgCollistProperty::Go(modal); }
dlgServer::dlgServer(pgaFactory *f, frmMain *frame, pgServer *node) : dlgProperty(f, frame, wxT("dlgServer")) { server = node; dbRestrictionOk = true; cbDatabase->Append(wxT("postgres")); cbDatabase->Append(wxT("edb")); cbDatabase->Append(wxT("template1")); wxString lastDB = settings->GetLastDatabase(); if (lastDB != wxT("postgres") && lastDB != wxT("edb") && lastDB != wxT("template1")) cbDatabase->Append(lastDB); cbDatabase->SetSelection(0); txtPort->SetValue(NumToStr((long)settings->GetLastPort())); if (!cbSSL->GetValue().IsEmpty()) cbSSL->SetSelection(settings->GetLastSSL()); txtUsername->SetValue(settings->GetLastUsername()); chkTryConnect->SetValue(true); chkStorePwd->SetValue(true); chkRestore->SetValue(true); if (node) { chkTryConnect->SetValue(false); chkTryConnect->Disable(); } // Fill the group combobox cbGroup->Append(_("Servers")); ctlTree *browser = frame->GetBrowser(); wxTreeItemId groupitem; wxTreeItemIdValue groupcookie, servercookie; pgServer *firstserver; if (browser->ItemHasChildren(browser->GetRootItem())) { groupitem = browser->GetFirstChild(browser->GetRootItem(), groupcookie); while (groupitem) { firstserver = (pgServer *)browser->GetObject(browser->GetFirstChild(groupitem, servercookie)); if (firstserver && !firstserver->GetGroup().IsEmpty() && firstserver->GetGroup() != _("Servers")) cbGroup->Append(firstserver->GetGroup()); groupitem = browser->GetNextChild(browser->GetRootItem(), groupcookie); } } #if defined(HAVE_OPENSSL_CRYPTO) || defined(HAVE_GCRYPT) EnableSSHTunnelControls(false); radioBtnPassword->SetValue(true); radioBtnKeyfile->SetValue(false); txtTunnelPassword->SetMaxLength(SSH_MAX_PASSWORD_LEN); txtTunnelPort->SetValue(NumToStr((long)DEFAULT_SSH_PORT)); #ifdef HAVE_OPENSSL_CRYPTO stPublicKeyFile->Show(false); pickerPublicKeyFile->Show(false); #endif #else for(size_t i = 0; i < nbNotebook->GetPageCount(); i++) { if(nbNotebook->GetPageText(i).compare(wxT("SSH Tunnel")) == 0) { nbNotebook->RemovePage(i); } } #endif }