1 /*-------
2  * Module:			pgapifunc.h
3  *
4  *-------
5  */
6 #ifndef _PG_API_FUNC_H__
7 #define _PG_API_FUNC_H__
8 
9 #include "psqlodbc.h"
10 #include <stdio.h>
11 #include <string.h>
12 
13 #ifdef	__cplusplus
14 extern "C" {
15 #endif /* __cplusplus */
16 /*	Internal flags for catalog functions */
17 #define	PODBC_NOT_SEARCH_PATTERN	1L
18 #define	PODBC_SEARCH_PUBLIC_SCHEMA	(1L << 1)
19 #define	PODBC_SEARCH_BY_IDS		(1L << 2)
20 #define	PODBC_SHOW_OID_COLUMN		(1L << 3)
21 #define	PODBC_ROW_VERSIONING		(1L << 4)
22 /*	Internal flags for PGAPI_AllocStmt functions */
23 #define	PODBC_EXTERNAL_STATEMENT	1L	/* visible to the driver manager */
24 #define	PODBC_INHERIT_CONNECT_OPTIONS	(1L << 1)
25 /*	Internal flags for PGAPI_Exec... functions */
26 #define	PODBC_WITH_HOLD			1L
27 #define	PODBC_RDONLY			(1L << 1)
28 #define	PODBC_RECYCLE_STATEMENT		(1L << 2)
29 /*	Flags for the error handling */
30 #define	PODBC_ALLOW_PARTIAL_EXTRACT	1L
31 /* #define	PODBC_ERROR_CLEAR		(1L << 1) 	no longer used */
32 
33 RETCODE SQL_API PGAPI_AllocConnect(HENV EnvironmentHandle,
34 				   HDBC * ConnectionHandle);
35 RETCODE SQL_API PGAPI_AllocEnv(HENV * EnvironmentHandle);
36 RETCODE SQL_API PGAPI_AllocStmt(HDBC ConnectionHandle,
37 				HSTMT *StatementHandle, UDWORD flag);
38 RETCODE SQL_API PGAPI_BindCol(HSTMT StatementHandle,
39 			  SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType,
40 			  PTR TargetValue, SQLLEN BufferLength,
41 			  SQLLEN *StrLen_or_Ind);
42 RETCODE SQL_API PGAPI_Cancel(HSTMT StatementHandle);
43 RETCODE SQL_API PGAPI_Columns(HSTMT StatementHandle,
44 			  const SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
45 			  const SQLCHAR *SchemaName, SQLSMALLINT NameLength2,
46 			  const SQLCHAR *TableName, SQLSMALLINT NameLength3,
47 			  const SQLCHAR *ColumnName, SQLSMALLINT NameLength4,
48 			  UWORD flag,
49 			  OID	reloid,
50 			  Int2 attnum);
51 RETCODE SQL_API PGAPI_Connect(HDBC ConnectionHandle,
52 		const SQLCHAR *ServerName, SQLSMALLINT NameLength1,
53 		const SQLCHAR *UserName, SQLSMALLINT NameLength2,
54 		const SQLCHAR *Authentication, SQLSMALLINT NameLength3);
55 RETCODE SQL_API PGAPI_DriverConnect(HDBC hdbc, HWND hwnd,
56 		const SQLCHAR * szConnStrIn, SQLSMALLINT cbConnStrIn,
57 		SQLCHAR * szConnStrOut, SQLSMALLINT cbConnStrOutMax,
58 		SQLSMALLINT * pcbConnStrOut, SQLUSMALLINT fDriverCompletion);
59 RETCODE SQL_API PGAPI_BrowseConnect(HDBC hdbc,
60 					const SQLCHAR *szConnStrIn, SQLSMALLINT cbConnStrIn,
61 					SQLCHAR *szConnStrOut, SQLSMALLINT cbConnStrOutMax,
62 					SQLSMALLINT *pcbConnStrOut);
63 RETCODE SQL_API PGAPI_DataSources(HENV EnvironmentHandle,
64 				  SQLUSMALLINT Direction, const SQLCHAR *ServerName,
65 				  SQLSMALLINT BufferLength1, SQLSMALLINT *NameLength1,
66 				  const SQLCHAR *Description, SQLSMALLINT BufferLength2,
67 				  SQLSMALLINT *NameLength2);
68 RETCODE SQL_API PGAPI_DescribeCol(HSTMT StatementHandle,
69 				  SQLUSMALLINT ColumnNumber, SQLCHAR *ColumnName,
70 				  SQLSMALLINT BufferLength, SQLSMALLINT *NameLength,
71 				  SQLSMALLINT *DataType, SQLULEN *ColumnSize,
72 				  SQLSMALLINT *DecimalDigits, SQLSMALLINT *Nullable);
73 RETCODE SQL_API PGAPI_Disconnect(HDBC ConnectionHandle);
74 RETCODE SQL_API PGAPI_Error(HENV EnvironmentHandle,
75 			HDBC ConnectionHandle, HSTMT StatementHandle,
76 			SQLCHAR *Sqlstate, SQLINTEGER *NativeError,
77 			SQLCHAR *MessageText, SQLSMALLINT BufferLength,
78 			SQLSMALLINT *TextLength);
79 /* Helper functions for Error handling */
80 RETCODE SQL_API PGAPI_EnvError(HENV EnvironmentHandle, SQLSMALLINT RecNumber,
81 			SQLCHAR *Sqlstate, SQLINTEGER *NativeError,
82 			SQLCHAR *MessageText, SQLSMALLINT BufferLength,
83 			SQLSMALLINT *TextLength, UWORD flag);
84 RETCODE SQL_API PGAPI_ConnectError(HDBC ConnectionHandle, SQLSMALLINT RecNumber,
85 			SQLCHAR *Sqlstate, SQLINTEGER *NativeError,
86 			SQLCHAR *MessageText, SQLSMALLINT BufferLength,
87 			SQLSMALLINT *TextLength, UWORD flag);
88 RETCODE SQL_API PGAPI_StmtError(HSTMT StatementHandle, SQLSMALLINT RecNumber,
89 			SQLCHAR *Sqlstate, SQLINTEGER *NativeError,
90 			SQLCHAR *MessageText, SQLSMALLINT BufferLength,
91 			SQLSMALLINT *TextLength, UWORD flag);
92 
93 RETCODE SQL_API PGAPI_ExecDirect(HSTMT StatementHandle,
94 		const SQLCHAR *StatementText, SQLINTEGER TextLength, UWORD flag);
95 RETCODE SQL_API PGAPI_Execute(HSTMT StatementHandle, UWORD flag);
96 RETCODE SQL_API PGAPI_Fetch(HSTMT StatementHandle);
97 RETCODE SQL_API PGAPI_FreeConnect(HDBC ConnectionHandle);
98 RETCODE SQL_API PGAPI_FreeEnv(HENV EnvironmentHandle);
99 RETCODE SQL_API PGAPI_FreeStmt(HSTMT StatementHandle,
100 			   SQLUSMALLINT Option);
101 RETCODE SQL_API PGAPI_GetConnectOption(HDBC ConnectionHandle,
102 			SQLUSMALLINT Option, PTR Value,
103 			SQLINTEGER *StringLength, SQLINTEGER BufferLength);
104 RETCODE SQL_API PGAPI_GetCursorName(HSTMT StatementHandle,
105 					SQLCHAR *CursorName, SQLSMALLINT BufferLength,
106 					SQLSMALLINT *NameLength);
107 RETCODE SQL_API PGAPI_GetData(HSTMT StatementHandle,
108 			  SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType,
109 			  PTR TargetValue, SQLLEN BufferLength,
110 			  SQLLEN *StrLen_or_Ind);
111 RETCODE SQL_API PGAPI_GetFunctions(HDBC ConnectionHandle,
112 				   SQLUSMALLINT FunctionId, SQLUSMALLINT *Supported);
113 RETCODE SQL_API PGAPI_GetFunctions30(HDBC ConnectionHandle,
114 					 SQLUSMALLINT FunctionId, SQLUSMALLINT *Supported);
115 RETCODE SQL_API PGAPI_GetInfo(HDBC ConnectionHandle,
116 			  SQLUSMALLINT InfoType, PTR InfoValue,
117 			  SQLSMALLINT BufferLength, SQLSMALLINT *StringLength);
118 RETCODE SQL_API PGAPI_GetStmtOption(HSTMT StatementHandle,
119 			SQLUSMALLINT Option, PTR Value,
120 			SQLINTEGER *StringLength, SQLINTEGER BufferLength);
121 RETCODE SQL_API PGAPI_GetTypeInfo(HSTMT StatementHandle,
122 				  SQLSMALLINT DataType);
123 RETCODE SQL_API PGAPI_NumResultCols(HSTMT StatementHandle,
124 					SQLSMALLINT *ColumnCount);
125 RETCODE SQL_API PGAPI_ParamData(HSTMT StatementHandle,
126 				PTR *Value);
127 RETCODE SQL_API PGAPI_Prepare(HSTMT StatementHandle,
128 			  const SQLCHAR *StatementText, SQLINTEGER TextLength);
129 RETCODE SQL_API PGAPI_PutData(HSTMT StatementHandle,
130 			  PTR Data, SQLLEN StrLen_or_Ind);
131 RETCODE SQL_API PGAPI_RowCount(HSTMT StatementHandle,
132 			   SQLLEN *RowCount);
133 RETCODE SQL_API PGAPI_SetConnectOption(HDBC ConnectionHandle,
134 					   SQLUSMALLINT Option, SQLULEN Value);
135 RETCODE SQL_API PGAPI_SetCursorName(HSTMT StatementHandle,
136 					const SQLCHAR *CursorName, SQLSMALLINT NameLength);
137 RETCODE SQL_API PGAPI_SetParam(HSTMT StatementHandle,
138 			   SQLUSMALLINT ParameterNumber, SQLSMALLINT ValueType,
139 			   SQLSMALLINT ParameterType, SQLULEN LengthPrecision,
140 			   SQLSMALLINT ParameterScale, PTR ParameterValue,
141 			   SQLLEN *StrLen_or_Ind);
142 RETCODE SQL_API PGAPI_SetStmtOption(HSTMT StatementHandle,
143 					SQLUSMALLINT Option, SQLULEN Value);
144 RETCODE SQL_API PGAPI_SpecialColumns(HSTMT StatementHandle,
145 					 SQLUSMALLINT IdentifierType, const SQLCHAR *CatalogName,
146 					 SQLSMALLINT NameLength1, const SQLCHAR *SchemaName,
147 					 SQLSMALLINT NameLength2, const SQLCHAR *TableName,
148 					 SQLSMALLINT NameLength3, SQLUSMALLINT Scope,
149 					 SQLUSMALLINT Nullable);
150 RETCODE SQL_API PGAPI_Statistics(HSTMT StatementHandle,
151 				 const SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
152 				 const SQLCHAR *SchemaName, SQLSMALLINT NameLength2,
153 				 const SQLCHAR *TableName, SQLSMALLINT NameLength3,
154 				 SQLUSMALLINT Unique, SQLUSMALLINT Reserved);
155 RETCODE SQL_API PGAPI_Tables(HSTMT StatementHandle,
156 			 const SQLCHAR *CatalogName, SQLSMALLINT NameLength1,
157 			 const SQLCHAR *SchemaName, SQLSMALLINT NameLength2,
158 			 const SQLCHAR *TableName, SQLSMALLINT NameLength3,
159 			 const SQLCHAR *TableType, SQLSMALLINT NameLength4,
160 			UWORD flag);
161 RETCODE SQL_API PGAPI_Transact(HENV EnvironmentHandle,
162 			   HDBC ConnectionHandle, SQLUSMALLINT CompletionType);
163 RETCODE SQL_API PGAPI_ColAttributes(
164 					HSTMT hstmt,
165 					SQLUSMALLINT icol,
166 					SQLUSMALLINT fDescType,
167 					PTR rgbDesc,
168 					SQLSMALLINT cbDescMax,
169 					SQLSMALLINT *pcbDesc,
170 					SQLLEN *pfDesc);
171 RETCODE SQL_API PGAPI_ColumnPrivileges(
172 					   HSTMT hstmt,
173 					   const SQLCHAR *szCatalogName,
174 					   SQLSMALLINT cbCatalogName,
175 					   const SQLCHAR *szSchemaName,
176 					   SQLSMALLINT cbSchemaName,
177 					   const SQLCHAR *szTableName,
178 					   SQLSMALLINT cbTableName,
179 					   const SQLCHAR *szColumnName,
180 					   SQLSMALLINT cbColumnName,
181 					   UWORD flag);
182 RETCODE SQL_API PGAPI_DescribeParam(
183 					HSTMT hstmt,
184 					SQLUSMALLINT ipar,
185 					SQLSMALLINT *pfSqlType,
186 					SQLULEN *pcbParamDef,
187 					SQLSMALLINT *pibScale,
188 					SQLSMALLINT *pfNullable);
189 RETCODE SQL_API PGAPI_ExtendedFetch(
190 					HSTMT hstmt,
191 					SQLUSMALLINT fFetchType,
192 					SQLLEN irow,
193 					SQLULEN *pcrow,
194 					SQLUSMALLINT *rgfRowStatus,
195 					SQLLEN FetchOffset,
196 					SQLLEN rowsetSize);
197 RETCODE SQL_API PGAPI_ForeignKeys(
198 				  HSTMT hstmt,
199 				  const SQLCHAR *szPkCatalogName,
200 				  SQLSMALLINT cbPkCatalogName,
201 				  const SQLCHAR *szPkSchemaName,
202 				  SQLSMALLINT cbPkSchemaName,
203 				  const SQLCHAR *szPkTableName,
204 				  SQLSMALLINT cbPkTableName,
205 				  const SQLCHAR *szFkCatalogName,
206 				  SQLSMALLINT cbFkCatalogName,
207 				  const SQLCHAR *szFkSchemaName,
208 				  SQLSMALLINT cbFkSchemaName,
209 				  const SQLCHAR *szFkTableName,
210 				  SQLSMALLINT cbFkTableName);
211 RETCODE SQL_API PGAPI_MoreResults(
212 				  HSTMT hstmt);
213 RETCODE SQL_API PGAPI_NativeSql(
214 				HDBC hdbc,
215 				const SQLCHAR *szSqlStrIn,
216 				SQLINTEGER cbSqlStrIn,
217 				SQLCHAR *szSqlStr,
218 				SQLINTEGER cbSqlStrMax,
219 				SQLINTEGER *pcbSqlStr);
220 RETCODE SQL_API PGAPI_NumParams(
221 				HSTMT hstmt,
222 				SQLSMALLINT *pcpar);
223 RETCODE SQL_API PGAPI_ParamOptions(
224 				   HSTMT hstmt,
225 				   SQLULEN crow,
226 				   SQLULEN *pirow);
227 RETCODE SQL_API PGAPI_PrimaryKeys(
228 				  HSTMT hstmt,
229 				  const SQLCHAR *szCatalogName,
230 				  SQLSMALLINT cbCatalogName,
231 				  const SQLCHAR *szSchemaName,
232 				  SQLSMALLINT cbSchemaName,
233 				  const SQLCHAR *szTableName,
234 				  SQLSMALLINT cbTableName,
235 				  OID	reloid);
236 RETCODE SQL_API PGAPI_ProcedureColumns(
237 					   HSTMT hstmt,
238 					   const SQLCHAR *szCatalogName,
239 					   SQLSMALLINT cbCatalogName,
240 					   const SQLCHAR *szSchemaName,
241 					   SQLSMALLINT cbSchemaName,
242 					   const SQLCHAR *szProcName,
243 					   SQLSMALLINT cbProcName,
244 					   const SQLCHAR *szColumnName,
245 					   SQLSMALLINT cbColumnName,
246 					   UWORD flag);
247 RETCODE SQL_API PGAPI_Procedures(
248 				 HSTMT hstmt,
249 				 const SQLCHAR *szCatalogName,
250 				 SQLSMALLINT cbCatalogName,
251 				 const SQLCHAR *szSchemaName,
252 				 SQLSMALLINT cbSchemaName,
253 				 const SQLCHAR *szProcName,
254 				 SQLSMALLINT cbProcName,
255 				UWORD flag);
256 RETCODE SQL_API PGAPI_SetPos(
257 			 HSTMT hstmt,
258 			 SQLSETPOSIROW irow,
259 			 SQLUSMALLINT fOption,
260 			 SQLUSMALLINT fLock);
261 RETCODE SQL_API PGAPI_TablePrivileges(
262 					  HSTMT hstmt,
263 					  const SQLCHAR *szCatalogName,
264 					  SQLSMALLINT cbCatalogName,
265 					  const SQLCHAR *szSchemaName,
266 					  SQLSMALLINT cbSchemaName,
267 					  const SQLCHAR *szTableName,
268 					  SQLSMALLINT cbTableName,
269 					  UWORD flag);
270 RETCODE SQL_API PGAPI_BindParameter(
271 					HSTMT hstmt,
272 					SQLUSMALLINT ipar,
273 					SQLSMALLINT fParamType,
274 					SQLSMALLINT fCType,
275 					SQLSMALLINT fSqlType,
276 					SQLULEN cbColDef,
277 					SQLSMALLINT ibScale,
278 					PTR rgbValue,
279 					SQLLEN cbValueMax,
280 					SQLLEN *pcbValue);
281 RETCODE SQL_API PGAPI_SetScrollOptions(
282 					   HSTMT hstmt,
283 					   SQLUSMALLINT fConcurrency,
284 					   SQLLEN crowKeyset,
285 					   SQLUSMALLINT crowRowset);
286 
287 RETCODE SQL_API PGAPI_GetDiagRec(SQLSMALLINT HandleType, SQLHANDLE Handle,
288 		SQLSMALLINT RecNumber, SQLCHAR *Sqlstate,
289 		SQLINTEGER *NativeError, SQLCHAR *MessageText,
290 		SQLSMALLINT BufferLength, SQLSMALLINT *TextLength);
291 RETCODE SQL_API PGAPI_GetDiagField(SQLSMALLINT HandleType, SQLHANDLE Handle,
292 		SQLSMALLINT RecNumber, SQLSMALLINT DiagIdentifier,
293 		PTR DiagInfoPtr, SQLSMALLINT BufferLength,
294 		SQLSMALLINT *StringLengthPtr);
295 RETCODE SQL_API PGAPI_GetConnectAttr(HDBC ConnectionHandle,
296 			SQLINTEGER Attribute, PTR Value,
297 			SQLINTEGER BufferLength, SQLINTEGER *StringLength);
298 RETCODE SQL_API PGAPI_GetStmtAttr(HSTMT StatementHandle,
299 		SQLINTEGER Attribute, PTR Value,
300 		SQLINTEGER BufferLength, SQLINTEGER *StringLength);
301 
302 /* Driver-specific connection attributes, for SQLSet/GetConnectAttr() */
303 enum {
304 	SQL_ATTR_PGOPT_DEBUG = 65536
305 	,SQL_ATTR_PGOPT_COMMLOG = 65537
306 	,SQL_ATTR_PGOPT_PARSE = 65538
307 	,SQL_ATTR_PGOPT_USE_DECLAREFETCH = 65539
308 	,SQL_ATTR_PGOPT_SERVER_SIDE_PREPARE = 65540
309 	,SQL_ATTR_PGOPT_FETCH = 65541
310 	,SQL_ATTR_PGOPT_UNKNOWNSIZES = 65542
311 	,SQL_ATTR_PGOPT_TEXTASLONGVARCHAR = 65543
312 	,SQL_ATTR_PGOPT_UNKNOWNSASLONGVARCHAR = 65544
313 	,SQL_ATTR_PGOPT_BOOLSASCHAR = 65545
314 	,SQL_ATTR_PGOPT_MAXVARCHARSIZE = 65546
315 	,SQL_ATTR_PGOPT_MAXLONGVARCHARSIZE = 65547
316 	,SQL_ATTR_PGOPT_WCSDEBUG = 65548
317 	,SQL_ATTR_PGOPT_MSJET = 65549
318 	,SQL_ATTR_PGOPT_BATCHSIZE = 65550
319 	,SQL_ATTR_PGOPT_IGNORETIMEOUT = 65551
320 };
321 RETCODE SQL_API PGAPI_SetConnectAttr(HDBC ConnectionHandle,
322 			SQLINTEGER Attribute, PTR Value,
323 			SQLINTEGER StringLength);
324 RETCODE SQL_API PGAPI_SetStmtAttr(HSTMT StatementHandle,
325 		SQLINTEGER Attribute, PTR Value,
326 		SQLINTEGER StringLength);
327 RETCODE SQL_API PGAPI_BulkOperations(HSTMT StatementHandle,
328 			SQLSMALLINT operation);
329 RETCODE SQL_API PGAPI_AllocDesc(HDBC ConnectionHandle,
330 				SQLHDESC *DescriptorHandle);
331 RETCODE SQL_API PGAPI_FreeDesc(SQLHDESC DescriptorHandle);
332 RETCODE SQL_API PGAPI_CopyDesc(SQLHDESC SourceDescHandle,
333 				SQLHDESC TargetDescHandle);
334 RETCODE SQL_API PGAPI_SetDescField(SQLHDESC DescriptorHandle,
335 			SQLSMALLINT RecNumber, SQLSMALLINT FieldIdentifier,
336 			PTR Value, SQLINTEGER BufferLength);
337 RETCODE SQL_API PGAPI_GetDescField(SQLHDESC DescriptorHandle,
338 			SQLSMALLINT RecNumber, SQLSMALLINT FieldIdentifier,
339 			PTR Value, SQLINTEGER BufferLength, SQLINTEGER *StringLength);
340 RETCODE SQL_API PGAPI_DescError(SQLHDESC DescriptorHandle, SQLSMALLINT RecNumber,
341 			SQLCHAR *Sqlstate, SQLINTEGER *NativeError,
342 			SQLCHAR *MessageText, SQLSMALLINT BufferLength,
343 			SQLSMALLINT *TextLength, UWORD flag);
344 
345 #ifdef	__cplusplus
346 }
347 #endif /* __cplusplus */
348 #endif   /* define_PG_API_FUNC_H__ */
349