1 /*
2 
3 Boost Software License - Version 1.0 - August 17th,2003
4 
5 Permission is hereby granted,free of charge,to any person or organization
6 obtaining a copy of the software and accompanying documentation covered by
7 this license (the "Software") to use,reproduce,display,distribute,
8 execute,and transmit the Software,and to prepare derivative works of the
9 Software,and to permit third-parties to whom the Software is furnished to
10 do so,all subject to the following:
11 
12 The copyright notices in the Software and this entire statement,including
13 the above license grant,this restriction and the following disclaimer,
14 must be included in all copies of the Software,in whole or in part,and
15 all derivative works of the Software,unless such copies or derivative
16 works are solely in the form of machine-executable object code generated by
17 a source language processor.
18 
19 THE SOFTWARE IS PROVIDED "AS IS",WITHOUT WARRANTY OF ANY KIND,EXPRESS OR
20 IMPLIED,INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE,TITLE AND NON-INFRINGEMENT. IN NO EVENT
22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23 FOR ANY DAMAGES OR OTHER LIABILITY,WHETHER IN CONTRACT,TORT OR OTHERWISE,
24 ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26 
27 */
28 module derelict.pq.types;
29 
30 alias Oid = uint;
31 alias pqbool = char;
32 alias pg_int64 = long;
33 public import core.stdc.stdio : FILE;
34 
35 enum {
36     PG_COPYRES_ATTRS       = 0x01,
37     PG_COPYRES_TUPLES      = 0x02,
38     PG_COPYRES_EVENTS      = 0x04,
39     PG_COPYRES_NOTICEHOOKS = 0x08,
40 }
41 
42 alias ConnStatusType = int;
43 enum {
44     CONNECTION_OK,
45     CONNECTION_BAD,
46     CONNECTION_STARTED,
47     CONNECTION_MADE,
48     CONNECTION_AWAITING_RESPONSE,
49     CONNECTION_AUTH_OK,
50     CONNECTION_SETENV,
51     CONNECTION_SSL_STARTUP,
52     CONNECTION_NEEDED
53 }
54 
55 alias PostgresPollingStatusType = int;
56 enum {
57     PGRES_POLLING_FAILED = 0,
58     PGRES_POLLING_READING,
59     PGRES_POLLING_WRITING,
60     PGRES_POLLING_OK,
61     PGRES_POLLING_ACTIVE
62 }
63 
64 alias ExecStatusType = int;
65 enum {
66     PGRES_EMPTY_QUERY = 0,
67     PGRES_COMMAND_OK,
68     PGRES_TUPLES_OK,
69     PGRES_COPY_OUT,
70     PGRES_COPY_IN,
71     PGRES_BAD_RESPONSE,
72     PGRES_NONFATAL_ERROR,
73     PGRES_FATAL_ERROR,
74     PGRES_COPY_BOTH,
75     PGRES_SINGLE_TUPLE
76 }
77 
78 alias PGTransactionStatusType = int;
79 enum {
80     PQTRANS_IDLE,
81     PQTRANS_ACTIVE,
82     PQTRANS_INTRANS,
83     PQTRANS_INERROR,
84     PQTRANS_UNKNOWN
85 }
86 
87 alias PGVerbosity = int;
88 enum {
89     PQERRORS_TERSE,
90     PQERRORS_DEFAULT,
91     PQERRORS_VERBOSE
92 }
93 
94 alias PGContextVisibility = int;
95 enum{
96     PQSHOW_CONTEXT_NEVER,
97     PQSHOW_CONTEXT_ERRORS,
98     PQSHOW_CONTEXT_ALWAYS
99 } ;
100 
101 alias PGPing = int;
102 enum {
103     PQPING_OK,
104     PQPING_REJECT,
105     PQPING_NO_RESPONSE,
106     PQPING_NO_ATTEMTP
107 }
108 
109 struct PGconn;
110 struct PGresult;
111 struct PGcancel;
112 
113 struct PGnotify {
114     char* relname;
115     int be_pid;
116     char* extra;
117     private PGnotify* next;
118 }
119 
120 extern(C) @nogc nothrow {
121     alias PQnoticeReceiver = void function(void*,PGresult*);
122     alias PQnoticeProcessor = void function(void*,char*);
123 }
124 
125 struct PQprintOpt {
126     pqbool header;
127     pqbool aligment;
128     pqbool standard;
129     pqbool html3;
130     pqbool expander;
131     pqbool pager;
132     char* fieldSep;
133     char* tableOpt;
134     char* caption;
135     char** fieldName;
136 }
137 
138 struct PQconninfoOption {
139     char* keyword;
140     char* envvar;
141     char* compiled;
142     char* val;
143     char* label;
144     char* dispchar;
145     int dispsize;
146 }
147 
148 struct PQArgBlock {
149     int len;
150     int ising;
151     union u
152     {
153         int* ptr;
154         int integer;
155     }
156 }
157 
158 struct PGresAttDesc {
159     char* name;
160     Oid tableid;
161     int columnid;
162     int format;
163     Oid typid;
164     int typlen;
165     int atttypmod;
166 }
167 
168 alias PGEventId = int;
169 enum {
170     PGEVT_REGISTER,
171     PGEVT_CONNRESET,
172     PGEVT_CONNDESTROY,
173     PGEVT_RESULTCREATE,
174     PGEVT_RESULTCOPY,
175     PGEVT_RESULTDESTROY
176 }
177 
178 struct PGEventResultCreate {
179     PGconn* conn;
180     PGresult* result;
181 }
182 
183 extern(C) @nogc nothrow {
184     alias pgthreadlock_t = void function(int);
185     alias PGEventProc = size_t function(PGEventId,void*,void*);
186 }
187 
188 // from postgres_ext.h
189 enum : int {
190     PG_DIAG_SEVERITY =          'S',
191     PG_DIAG_SEVERITY_NONLOCALIZED = 'V', // New in 9.6
192     PG_DIAG_SQLSTATE =          'C',
193     PG_DIAG_MESSAGE_PRIMARY =   'M',
194     PG_DIAG_MESSAGE_DETAIL =    'D',
195     PG_DIAG_MESSAGE_HINT =      'H',
196     PG_DIAG_STATEMENT_POSITION ='P',
197     PG_DIAG_INTERNAL_POSITION = 'p',
198     PG_DIAG_INTERNAL_QUERY =    'q',
199     PG_DIAG_CONTEXT =           'W',
200     PG_DIAG_SCHEMA_NAME =       's',
201     PG_DIAG_TABLE_NAME =        't',
202     PG_DIAG_COLUMN_NAME =       'c',
203     PG_DIAG_DATATYPE_NAME =     'd',
204     PG_DIAG_CONSTRAINT_NAME =   'n',
205     PG_DIAG_SOURCE_FILE =       'F',
206     PG_DIAG_SOURCE_LINE =       'L',
207     PG_DIAG_SOURCE_FUNCTION =   'R'
208 }