\r
Date Dev Ver Change details\r
---------- --- ------ --------------\r
+2009-07-07 DP 1.12.0 Cache datatypes in dlgTable, so they don't have to be\r
+ reloaded by dlgColumn, which may be used multiple times\r
+ when creating a table [Sachin Srivastava].\r
2009-07-01 DP 1.12.0 Use the STC instead of a rich text control in the edit\r
grid to prevent issues with control characters creeping\r
in on Windows [Sachin Srivastava].\r
};
+void dataType::SetOid(OID id)
+{
+ oid = id;
+}
+
+void dataType::SetTypename(wxString name)
+{
+ typeName = name;
+}
+
+OID dataType::GetOid()
+{
+ return oid;
+}
+
+wxString dataType::GetTypename()
+{
+ return typeName;
+}
+
#define CTRLID_CHKSQLTEXTFIELD 1000
connection=db->GetConnection();
}
+void dlgProperty::SetDatatypeCache(dataTypeCache cache)
+{
+ dtCache = cache;
+}
void dlgProperty::EnableOK(bool enable)
{
FillDatatype(cb, 0, withDomains);
}
-
void dlgTypeProperty::FillDatatype(ctlComboBox *cb, ctlComboBox *cb2, bool withDomains)
{
- DatatypeReader tr(database, withDomains);
- while (tr.HasMore())
+
+ if (dtCache.IsEmpty())
{
- pgDatatype dt=tr.GetDatatype();
+ // A column dialog is directly called, no datatype caching is done.
+ // Fetching datatypes from server.
+ DatatypeReader tr(database, withDomains);
+ while (tr.HasMore())
+ {
+ pgDatatype dt=tr.GetDatatype();
- AddType(wxT("?"), tr.GetOid(), dt.FullName());
- cb->Append(dt.FullName());
- if (cb2)
- cb2->Append(dt.FullName());
- tr.MoveNext();
+ AddType(wxT("?"), tr.GetOid(), dt.FullName());
+ cb->Append(dt.FullName());
+ if (cb2)
+ cb2->Append(dt.FullName());
+ tr.MoveNext();
+ }
}
+ else
+ {
+ // A column dialog is called from a table dialog where we have already cached the datatypes.
+ // Using cached datatypes.
+ size_t i;
+ for (i = 0; i < dtCache.GetCount(); i++)
+ {
+ AddType(wxT("?"), dtCache.Item(i)->GetOid(), dtCache.Item(i)->GetTypename());
+ cb->Append(dtCache.Item(i)->GetTypename());
+ if (cb2)
+ cb2->Append(dtCache.Item(i)->GetTypename());
+ }
+ }
+
}
#include "schema/pgCheck.h"
#include "schema/pgForeignKey.h"
#include "schema/pgIndexConstraint.h"
-
+#include "schema/pgDatatype.h"
#define stHasOids CTRL_STATIC("stHasOids")
lstConstraints->CreateColumns(0, _("Constraint name"), _("Definition"), 90);
}
+dlgTable::~dlgTable()
+{
+ //Clear the cached datatypes
+ size_t i;
+ for (i = 0; i < dtCache.GetCount(); i++)
+ delete dtCache.Item(i);
+}
pgObject *dlgTable::GetObject()
{
AddGroups();
AddUsers(cbOwner);
PrepareTablespace(cbTablespace);
+ PopulateDatatypeCache();
hasPK=false;
CheckChange();
}
+// Cache datatypes to avoid multiple calls to server when adding multiple columns to a table.
+void dlgTable::PopulateDatatypeCache()
+{
+ DatatypeReader tr(database, true);
+ while (tr.HasMore())
+ {
+ pgDatatype dt=tr.GetDatatype();
+
+ dataType *dType = new dataType();
+ dType->SetOid(tr.GetOid());
+ dType->SetTypename(dt.FullName());
+ dtCache.Add(dType);
+
+ tr.MoveNext();
+ }
+}
+
void dlgTable::OnAddCol(wxCommandEvent &ev)
{
dlgColumn col(&columnFactory, mainForm, NULL, table);
col.CenterOnParent();
col.SetDatabase(database);
+ col.SetDatatypeCache(dtCache);
if (col.Go(true) != wxID_CANCEL)
{
long pos = lstColumns->AppendItem(columnFactory.GetIconId(), col.GetName(), col.GetDefinition());
#include <wx/notebook.h>
+#include <wx/dynarray.h>
#include "schema/pgObject.h"
#include "db/pgConn.h"
#include "ctl/ctlSecurityPanel.h"
#define lstColumns CTRL_LISTVIEW("lstColumns")
#define cbColumns CTRL_COMBOBOX("cbColumns")
+class dataType
+{
+public:
+ void SetTypename(wxString name);
+ wxString GetTypename();
+
+ void SetOid(OID id);
+ OID GetOid();
+
+private:
+ wxString typeName;
+ OID oid;
+
+};
+
+WX_DEFINE_ARRAY(dataType *, dataTypeCache);
+
class dlgProperty : public DialogWithHelp
{
public:
virtual wxString GetHelpPage(bool forCreate) const { return wxEmptyString; }
void SetConnection(pgConn *conn) { connection=conn; }
void SetDatabase(pgDatabase *db);
+ void SetDatatypeCache(dataTypeCache cache);
virtual int Go(bool modal=false);
virtual void CheckChange() =0;
bool readOnly;
bool processing;
pgaFactory *factory;
+ dataTypeCache dtCache;
private:
bool tryUpdate(wxTreeItemId collectionItem);
wxString GetSql();
pgObject *CreateObject(pgCollection *collection);
pgObject *GetObject();
+ ~dlgTable();
private:
pgSchema *schema;
pgTable *table;
+ dataTypeCache dtCache;
void OnOK(wxCommandEvent &ev);
void OnChangeTable(wxCommandEvent &ev);
void FillConstraint();
void FillAutoVacuumParameters(wxString& setString, wxString& resetStr,
const wxString& parameter, const wxString& val);
+ void PopulateDatatypeCache();
wxString GetItemConstraintType(ctlListView *list, long pos);
bool hasPK;