xref: /PHP-8.1/ext/pdo_dblib/php_pdo_dblib_int.h (revision 01b3fc03)
1 /*
2   +----------------------------------------------------------------------+
3   | Copyright (c) The PHP Group                                          |
4   +----------------------------------------------------------------------+
5   | This source file is subject to version 3.01 of the PHP license,      |
6   | that is bundled with this package in the file LICENSE, and is        |
7   | available through the world-wide-web at the following url:           |
8   | https://www.php.net/license/3_01.txt                                 |
9   | If you did not receive a copy of the PHP license and are unable to   |
10   | obtain it through the world-wide-web, please send a note to          |
11   | license@php.net so we can mail you a copy immediately.               |
12   +----------------------------------------------------------------------+
13   | Author: Wez Furlong <wez@php.net>                                    |
14   |         Frank M. Kromann <frank@kromann.info>                        |
15   +----------------------------------------------------------------------+
16 */
17 
18 #ifndef PHP_PDO_DBLIB_INT_H
19 #define PHP_PDO_DBLIB_INT_H
20 
21 #ifndef PDO_DBLIB_FLAVOUR
22 # define PDO_DBLIB_FLAVOUR "Generic DB-lib"
23 #endif
24 
25 #ifdef PHP_DBLIB_IS_MSSQL
26 # include <sqlfront.h>
27 # include <sqldb.h>
28 
29 # define DBERRHANDLE(a, b)	dbprocerrhandle(a, b)
30 # define DBMSGHANDLE(a, b)	dbprocmsghandle(a, b)
31 # define EHANDLEFUNC		DBERRHANDLE_PROC
32 # define MHANDLEFUNC		DBMSGHANDLE_PROC
33 # define DBSETOPT(a, b, c)	dbsetopt(a, b, c)
34 # define SYBESMSG		SQLESMSG
35 # define SYBESEOF		SQLESEOF
36 # define SYBEFCON		SQLECONN		/* SQLEFCON does not exist in MS SQL Server. */
37 # define SYBEMEM		SQLEMEM
38 # define SYBEPWD		SQLEPWD
39 
40 #else
41 # include <sybfront.h>
42 # include <sybdb.h>
43 # include <syberror.h>
44 
45 /* alias some types */
46 # define SQLTEXT	SYBTEXT
47 # define SQLCHAR	SYBCHAR
48 # define SQLVARCHAR	SYBVARCHAR
49 # define SQLINT1	SYBINT1
50 # define SQLINT2	SYBINT2
51 # define SQLINT4	SYBINT4
52 # define SQLINT8	SYBINT8
53 # define SQLINTN	SYBINTN
54 # define SQLBIT		SYBBIT
55 # define SQLFLT4	SYBREAL
56 # define SQLFLT8	SYBFLT8
57 # define SQLFLTN	SYBFLTN
58 # define SQLDECIMAL	SYBDECIMAL
59 # define SQLNUMERIC	SYBNUMERIC
60 # define SQLDATETIME	SYBDATETIME
61 # define SQLDATETIM4	SYBDATETIME4
62 # define SQLDATETIMN	SYBDATETIMN
63 # ifdef SYBMSDATETIME2
64 # define SQLMSDATETIME2  SYBMSDATETIME2
65 # endif
66 # define SQLMONEY		SYBMONEY
67 # define SQLMONEY4		SYBMONEY4
68 # define SQLMONEYN		SYBMONEYN
69 # define SQLIMAGE		SYBIMAGE
70 # define SQLBINARY		SYBBINARY
71 # define SQLVARBINARY	SYBVARBINARY
72 # ifdef SYBUNIQUE
73 #  define SQLUNIQUE		SYBUNIQUE
74 #else
75 #  define SQLUNIQUE		36 /* FreeTDS Hack */
76 # endif
77 
78 # define DBERRHANDLE(a, b)	dberrhandle(b)
79 # define DBMSGHANDLE(a, b)	dbmsghandle(b)
80 # define DBSETOPT(a, b, c)	dbsetopt(a, b, c, -1)
81 # define NO_MORE_RPC_RESULTS	3
82 # define dbfreelogin		dbloginfree
83 # define dbrpcexec			dbrpcsend
84 
85 typedef short TDS_SHORT;
86 # ifndef PHP_WIN32
87 typedef unsigned char *LPBYTE;
88 # endif
89 typedef float			DBFLT4;
90 #endif
91 
92 /* hardcoded string length from FreeTDS
93  * src/tds/convert.c:tds_convert_datetimeall()
94  */
95 # define DATETIME_MAX_LEN   63
96 
97 int pdo_dblib_error_handler(DBPROCESS *dbproc, int severity, int dberr,
98 	int oserr, char *dberrstr, char *oserrstr);
99 
100 int pdo_dblib_msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate,
101 	int severity, char *msgtext, char *srvname, char *procname, int line);
102 
103 extern const pdo_driver_t pdo_dblib_driver;
104 extern const struct pdo_stmt_methods dblib_stmt_methods;
105 
106 typedef struct {
107 	int severity;
108 	int oserr;
109 	int dberr;
110 	char *oserrstr;
111 	char *dberrstr;
112 	char *sqlstate;
113 	char *lastmsg;
114 } pdo_dblib_err;
115 
116 void pdo_dblib_err_dtor(pdo_dblib_err *err);
117 
118 typedef struct {
119 	LOGINREC	*login;
120 	DBPROCESS	*link;
121 
122 	pdo_dblib_err err;
123 	unsigned assume_national_character_set_strings:1;
124 	unsigned stringify_uniqueidentifier:1;
125 	unsigned skip_empty_rowsets:1;
126 	unsigned datetime_convert:1;
127 } pdo_dblib_db_handle;
128 
129 typedef struct {
130 	pdo_dblib_db_handle *H;
131 	pdo_dblib_err err;
132 	unsigned int computed_column_name_count;
133 } pdo_dblib_stmt;
134 
135 typedef struct {
136 	const char* key;
137 	int value;
138 } pdo_dblib_keyval;
139 
140 
141 ZEND_BEGIN_MODULE_GLOBALS(dblib)
142 	pdo_dblib_err err;
143 	char sqlstate[6];
144 ZEND_END_MODULE_GLOBALS(dblib)
145 
146 #if defined(ZTS) && (defined(COMPILE_DL_PDO_DBLIB) || defined(COMPILE_DL_PDO_MSSQL))
147 ZEND_TSRMLS_CACHE_EXTERN()
148 #endif
149 
150 ZEND_EXTERN_MODULE_GLOBALS(dblib)
151 #define DBLIB_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(dblib, v)
152 
153 ZEND_EXTERN_MODULE_GLOBALS(dblib)
154 
155 enum {
156 	PDO_DBLIB_ATTR_CONNECTION_TIMEOUT = PDO_ATTR_DRIVER_SPECIFIC,
157 	PDO_DBLIB_ATTR_QUERY_TIMEOUT,
158 	PDO_DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER,
159 	PDO_DBLIB_ATTR_VERSION,
160 	PDO_DBLIB_ATTR_TDS_VERSION,
161 	PDO_DBLIB_ATTR_SKIP_EMPTY_ROWSETS,
162 	PDO_DBLIB_ATTR_DATETIME_CONVERT,
163 };
164 
165 #endif
166