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 // pgDatatype.h - PostgreSQL Datatypes
9 //
10 //////////////////////////////////////////////////////////////////////////
11 
12 #ifndef __DATATYPE_INC
13 #define __DATATYPE_INC
14 
15 #include <wx/wx.h>
16 
17 // App headers
18 
19 #include "db/pgSet.h"
20 #include "db/pgConn.h"
21 
22 class pgDatabase;
23 
24 class pgDatatype
25 {
26 public:
27 	pgDatatype(const wxString &nsp, const wxString &typname, bool isduplicate, long numdims = 0, long typmod = -1);
Name()28 	wxString Name() const
29 	{
30 		return name;
31 	};
LengthString()32 	wxString LengthString() const
33 	{
34 		return length;
35 	}
Array()36 	wxString Array() const
37 	{
38 		return array;
39 	}
40 	wxString FullName() const;
41 	wxString QuotedFullName() const;
42 	wxString GetSchemaPrefix(pgDatabase *db) const;
43 	wxString GetQuotedSchemaPrefix(pgDatabase *db) const;
Length()44 	long Length() const
45 	{
46 		return len;
47 	}
Precision()48 	long Precision() const
49 	{
50 		return prec;
51 	}
52 	static long GetTypmod(const wxString &name, const wxString &len, const wxString &prec);
53 
HasStats()54 	bool HasStats()
55 	{
56 		return false;
57 	}
HasDepends()58 	bool HasDepends()
59 	{
60 		return true;
61 	}
HasReferences()62 	bool HasReferences()
63 	{
64 		return true;
65 	}
66 
67 private:
68 	wxString schema;
69 	wxString name;
70 	wxString length;
71 	wxString array;
72 	long len, prec;
73 	bool needSchema;
74 };
75 
76 
77 class DatatypeReader
78 {
79 public:
80 	DatatypeReader(pgDatabase *db, bool withDomains = true, bool addSerials = false);
81 	DatatypeReader(pgDatabase *db, const wxString &condition, bool addSerials = false);
~DatatypeReader()82 	~DatatypeReader()
83 	{
84 		if (set) delete set;
85 	}
HasMore()86 	bool HasMore() const
87 	{
88 		return set && !set->Eof();
89 	}
MoveNext()90 	void MoveNext()
91 	{
92 		if (set)  set->MoveNext();
93 	}
94 
95 	bool IsDomain() const;
96 	bool IsVarlen() const;
97 	bool MaySpecifyLength() const;
98 	bool MaySpecifyPrecision() const;
99 	pgDatatype GetDatatype() const;
100 	wxString GetTypename() const;
101 	wxString GetSchema() const;
102 	wxString GetSchemaPrefix() const;
103 	wxString GetQuotedSchemaPrefix() const;
104 	wxString GetOidStr() const;
105 	OID GetOid() const;
106 
107 private:
108 	pgSet *set;
109 	pgDatabase *database;
110 	void init(pgDatabase *db, const wxString &condition, bool addSerials = false);
111 };
112 
113 #endif
114