1 ////////////////////////////////////////////////////////////////////////// 2 // 3 // pgAdmin III - PostgreSQL Tools 4 // 5 // Copyright (C) 2002 - 2016, The pgAdmin Development Team 6 // This software is released under the PostgreSQL Licence 7 // 8 // pgObject.h - PostgreSQL base object class 9 // 10 ////////////////////////////////////////////////////////////////////////// 11 12 #ifndef PGOBJECT_H 13 #define PGOBJECT_H 14 15 class ctlTree; 16 class ctlSQLBox; 17 class ctlListView; 18 class frmMain; 19 class frmReport; 20 class pgDatabase; 21 class pgSchema; 22 class pgCollection; 23 class pgConn; 24 class pgSet; 25 class pgServer; 26 class pgTable; 27 class pgaJob; 28 29 30 class pgTypes 31 { 32 public: 33 wxChar *typName; 34 long typeIcon; 35 wxChar *newString; 36 wxChar *newLongString; 37 }; 38 39 40 class pgaFactory; 41 42 43 enum 44 { 45 RETRIEVINGDETAILS = 1, 46 REFRESHINGDETAILS, 47 BACKUPGLOBALS, 48 GRANTWIZARDTITLE, 49 MAINTENANCEDIALOGTITLE, 50 BACKUPSERVERTITLE, 51 BACKUPTITLE, 52 RESTORETITLE, 53 CANNOTDROPSYSTEM, 54 DROPINCLUDINGDEPS, 55 DROPEXCLUDINGDEPS, 56 DROPCASCADETITLE, 57 DROPTITLE, 58 PROPERTIESREPORT, 59 PROPERTIES, 60 DDLREPORT, 61 DDL, 62 DATADICTIONNARYREPORT, 63 STATISTICSREPORT, 64 OBJSTATISTICS, 65 DEPENDENCIESREPORT, 66 DEPENDENCIES, 67 DEPENDENTSREPORT, 68 DEPENDENTS, 69 OBJECTSLISTREPORT 70 }; 71 72 73 // Class declarations 74 class pgObject : public wxTreeItemData 75 { 76 protected: 77 pgObject(int newType, const wxString &newName = wxEmptyString); 78 pgObject(pgaFactory &factory, const wxString &newName = wxEmptyString); 79 80 public: 81 /* 82 * Except column level privileges, column will be always an empty 83 * string in any case 84 */ 85 static wxString GetPrivileges(const wxString &allPattern, 86 const wxString &acl, const wxString &grantObject, 87 const wxString &user, const wxString &column = wxT("")); 88 89 static wxString GetDefaultPrivileges(const wxString &strType, const wxString &strSupportedPrivs, 90 const wxString &strSchema, const wxString &strOrigDefPrivs, 91 const wxString &strNewDefPrivs, const wxString &strRole); 92 static wxString GetPrivilegeName(wxChar privilege); 93 static bool findUserPrivs(wxString &, wxString &, wxString &); 94 95 static int GetTypeId(const wxString &typname); 96 GetFactory()97 pgaFactory *GetFactory() 98 { 99 return factory; 100 } IsCreatedBy(pgaFactory & f)101 bool IsCreatedBy(pgaFactory &f) const 102 { 103 return &f == factory; 104 } IsCreatedBy(pgaFactory * f)105 bool IsCreatedBy(pgaFactory *f) const 106 { 107 return f == factory; 108 } 109 int GetType() const; 110 int GetMetaType() const; 111 wxString GetTypeName() const; 112 wxString GetTranslatedTypeName() const; 113 virtual wxString GetTranslatedMessage(int kindOfMessage) const; 114 virtual int GetIconId(); 115 bool UpdateIcon(ctlTree *browser); 116 ShowProperties()117 virtual void ShowProperties() const {}; GetDatabase()118 virtual pgDatabase *GetDatabase() const 119 { 120 return 0; 121 } GetServer()122 virtual pgServer *GetServer() const 123 { 124 return 0; 125 } GetSchema()126 virtual pgSchema *GetSchema() const 127 { 128 return 0; 129 } GetTable()130 virtual pgTable *GetTable() const 131 { 132 return 0; 133 } GetJob()134 virtual pgaJob *GetJob() const 135 { 136 return 0; 137 } iSetName(const wxString & newVal)138 void iSetName(const wxString &newVal) 139 { 140 name = newVal; 141 } GetName()142 wxString GetName() const 143 { 144 return name; 145 } GetOid()146 OID GetOid() const 147 { 148 return oid; 149 } GetOidStr()150 wxString GetOidStr() const 151 { 152 return NumToStr(oid) + wxT("::oid"); 153 } iSetOid(const OID newVal)154 void iSetOid(const OID newVal) 155 { 156 oid = newVal; 157 } iSetXid(const OID x)158 void iSetXid(const OID x) 159 { 160 xid = x; 161 }; GetXid()162 OID GetXid() 163 { 164 return xid; 165 }; GetOwner()166 wxString GetOwner() const 167 { 168 return owner; 169 } iSetOwner(const wxString & newVal)170 void iSetOwner(const wxString &newVal) 171 { 172 owner = newVal; 173 } GetComment()174 wxString GetComment() const 175 { 176 return comment; 177 } iSetComment(const wxString & newVal)178 void iSetComment(const wxString &newVal) 179 { 180 comment = newVal; 181 } GetAcl()182 wxString GetAcl() const 183 { 184 return acl; 185 } iSetAcl(const wxString & newVal)186 void iSetAcl(const wxString &newVal) 187 { 188 acl = newVal; 189 } GetSystemObject()190 virtual bool GetSystemObject() const 191 { 192 return false; 193 } IsCollection()194 virtual bool IsCollection() const 195 { 196 return false; 197 } ShowHint(frmMain * form,bool force)198 virtual void ShowHint(frmMain *form, bool force) {} 199 200 void ShowTree(frmMain *form, ctlTree *browser, ctlListView *properties, ctlSQLBox *sqlPane); 201 202 wxTreeItemId AppendBrowserItem(ctlTree *browser, pgObject *object); 203 204 virtual wxString GetHelpPage(bool forCreate) const; GetFullName()205 virtual wxString GetFullName() 206 { 207 return name; 208 } GetIdentifier()209 virtual wxString GetIdentifier() const 210 { 211 return name; 212 } GetQuotedIdentifier()213 virtual wxString GetQuotedIdentifier() const 214 { 215 return qtIdent(name); 216 } GetDisplayName()217 virtual wxString GetDisplayName() 218 { 219 return GetFullName(); 220 }; iSetProviders(const wxString & newVal)221 void iSetProviders(const wxString &newVal) 222 { 223 providers = newVal; 224 } GetProviders()225 wxString GetProviders() const 226 { 227 return providers; 228 } iSetLabels(const wxString & newVal)229 void iSetLabels(const wxString &newVal) 230 { 231 labels = newVal; 232 } GetLabels()233 wxString GetLabels() const 234 { 235 return labels; 236 } 237 wxArrayString GetProviderLabelArray(); 238 wxString GetSeqLabelsSql(); 239 240 virtual wxMenu *GetNewMenu(); 241 GetSql(ctlTree * browser)242 virtual wxString GetSql(ctlTree *browser) 243 { 244 return wxT(""); 245 } 246 /* 247 * Except column level privileges, column will be always an empty 248 * string in any case 249 */ 250 wxString GetGrant(const wxString &allPattern, const wxString &grantFor = wxT(""), const wxString &column = wxT("")); 251 wxString GetCommentSql(); 252 wxString GetOwnerSql(int major, int minor, wxString objname = wxEmptyString, wxString objtype = wxEmptyString); 253 pgConn *GetConnection() const; 254 SetDirty()255 virtual void SetDirty() 256 { 257 sql = wxT(""); 258 expandedKids = false; 259 needReread = true; 260 } GetFullIdentifier()261 virtual wxString GetFullIdentifier() const 262 { 263 return GetName(); 264 } GetQuotedFullIdentifier()265 virtual wxString GetQuotedFullIdentifier() const 266 { 267 return qtIdent(name); 268 } 269 270 virtual void ShowTreeDetail(ctlTree *browser, frmMain *form = 0, ctlListView *properties = 0, ctlSQLBox *sqlPane = 0) = 0; 271 virtual void ShowStatistics(frmMain *form, ctlListView *statistics); 272 virtual void ShowDependencies(frmMain *form, ctlListView *Dependencies, const wxString &where = wxEmptyString); 273 virtual void ShowDependents(frmMain *form, ctlListView *referencedBy, const wxString &where = wxEmptyString); Refresh(ctlTree * browser,const wxTreeItemId item)274 virtual pgObject *Refresh(ctlTree *browser, const wxTreeItemId item) 275 { 276 return this; 277 } 278 virtual bool DropObject(wxFrame *frame, ctlTree *browser, bool cascaded = false) 279 { 280 return false; 281 } EditObject(wxFrame * frame,ctlTree * browser)282 virtual bool EditObject(wxFrame *frame, ctlTree *browser) 283 { 284 return false; 285 } 286 NeedCascadedDrop()287 virtual bool NeedCascadedDrop() 288 { 289 return false; 290 } CanCreate()291 virtual bool CanCreate() 292 { 293 return false; 294 } CanView()295 virtual bool CanView() 296 { 297 return false; 298 } CanEdit()299 virtual bool CanEdit() 300 { 301 return false; 302 } CanDrop()303 virtual bool CanDrop() 304 { 305 return false; 306 } CanDropCascaded()307 virtual bool CanDropCascaded() 308 { 309 return false; 310 } CanMaintenance()311 virtual bool CanMaintenance() 312 { 313 return false; 314 } RequireDropConfirm()315 virtual bool RequireDropConfirm() 316 { 317 return false; 318 } WantDummyChild()319 virtual bool WantDummyChild() 320 { 321 return false; 322 } CanBackup()323 virtual bool CanBackup() 324 { 325 return false; 326 } CanBackupGlobals()327 virtual bool CanBackupGlobals() 328 { 329 return false; 330 } CanRestore()331 virtual bool CanRestore() 332 { 333 return false; 334 } GetCanHint()335 virtual bool GetCanHint() 336 { 337 return false; 338 } HasStats()339 virtual bool HasStats() 340 { 341 return false; 342 } HasDepends()343 virtual bool HasDepends() 344 { 345 return false; 346 } HasReferences()347 virtual bool HasReferences() 348 { 349 return false; 350 } 351 352 wxString qtDbString(const wxString &str); 353 354 void SetWindowPtr(dlgProperty *dlgprop); GetWindowPtr()355 dlgProperty *GetWindowPtr() 356 { 357 return dlg; 358 } 359 360 bool CheckOpenDialogs(ctlTree *browser, wxTreeItemId node); 361 362 protected: 363 void CreateList3Columns(ctlListView *properties, const wxString &left = _("Object"), const wxString &middle = _("Owner"), const wxString &right = _("Value")); 364 void CreateListColumns(ctlListView *properties, const wxString &left = _("Property"), const wxString &right = _("Value")); 365 366 void AppendMenu(wxMenu *menu, int type = -1); SetContextInfo(frmMain * form)367 virtual void SetContextInfo(frmMain *form) {} 368 369 bool expandedKids, needReread; 370 wxString sql; 371 bool hintShown; 372 pgaFactory *factory; 373 374 private: 375 /* 376 * Except column level privileges, column will be always an empty 377 * string in any case 378 */ 379 static void AppendRight(wxString &rights, const wxString &acl, wxChar c, const wxChar *rightName, const wxString &column = wxEmptyString); 380 static wxString GetPrivilegeGrant(const wxString &allPattern, const wxString &acl, const wxString &grantObject, const wxString &user, const wxString &column); 381 void ShowDependency(pgDatabase *db, ctlListView *list, const wxString &query, const wxString &clsOrder); 382 wxString name, owner, schema, comment, acl; 383 int type; 384 OID oid, xid; 385 wxString providers, labels; 386 dlgProperty *dlg; 387 388 friend class pgaFactory; 389 }; 390 391 #endif 392 393