php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
pdo_dblib.c
Go to the documentation of this file.
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#ifdef HAVE_CONFIG_H
19# include "config.h"
20#endif
21
22#include "php.h"
23#include "php_ini.h"
24#include "ext/standard/info.h"
25#include "ext/pdo/php_pdo.h"
27#include "php_pdo_dblib.h"
28#include "php_pdo_dblib_int.h"
29#include "zend_exceptions.h"
30#include "pdo_dblib_arginfo.h"
31
33static PHP_GINIT_FUNCTION(dblib);
34
35static zend_class_entry *PdoDblib_ce;
36
37static const zend_module_dep pdo_dblib_deps[] = {
40};
41
42#ifdef PDO_DBLIB_IS_MSSQL
43zend_module_entry pdo_mssql_module_entry = {
44#else
46#endif
48 pdo_dblib_deps,
49#ifdef PDO_DBLIB_IS_MSSQL
50 "pdo_mssql",
51#elif defined(PHP_WIN32)
52 "pdo_sybase",
53#else
54 "pdo_dblib",
55#endif
56 NULL,
57 PHP_MINIT(pdo_dblib),
58 PHP_MSHUTDOWN(pdo_dblib),
59 NULL,
60 PHP_RSHUTDOWN(pdo_dblib),
61 PHP_MINFO(pdo_dblib),
63 PHP_MODULE_GLOBALS(dblib),
64 PHP_GINIT(dblib),
65 NULL,
66 NULL,
68};
69
70#if defined(COMPILE_DL_PDO_DBLIB) || defined(COMPILE_DL_PDO_MSSQL)
71#ifdef ZTS
73#endif
74#ifdef PDO_DBLIB_IS_MSSQL
75ZEND_GET_MODULE(pdo_mssql)
76#else
77ZEND_GET_MODULE(pdo_dblib)
78#endif
79#endif
80
81int pdo_dblib_error_handler(DBPROCESS *dbproc, int severity, int dberr,
82 int oserr, char *dberrstr, char *oserrstr)
83{
84 pdo_dblib_err *einfo;
85 char *state = "HY000";
86
87 if(dbproc) {
88 einfo = (pdo_dblib_err*)dbgetuserdata(dbproc);
89 if (!einfo) einfo = &DBLIB_G(err);
90 } else {
91 einfo = &DBLIB_G(err);
92 }
93
94 einfo->severity = severity;
95 einfo->oserr = oserr;
96 einfo->dberr = dberr;
97
98 if (einfo->oserrstr) {
99 efree(einfo->oserrstr);
100 }
101 if (einfo->dberrstr) {
102 efree(einfo->dberrstr);
103 }
104 if (oserrstr) {
105 einfo->oserrstr = estrdup(oserrstr);
106 } else {
107 einfo->oserrstr = NULL;
108 }
109 if (dberrstr) {
110 einfo->dberrstr = estrdup(dberrstr);
111 } else {
112 einfo->dberrstr = NULL;
113 }
114
115 switch (dberr) {
116 case SYBESEOF:
117 case SYBEFCON: state = "01002"; break;
118 case SYBEMEM: state = "HY001"; break;
119 case SYBEPWD: state = "28000"; break;
120 }
121 strcpy(einfo->sqlstate, state);
122
123 return INT_CANCEL;
124}
125
126int pdo_dblib_msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate,
127 int severity, char *msgtext, char *srvname, char *procname, int line)
128{
129 pdo_dblib_err *einfo;
130
131 if (severity) {
132 einfo = (pdo_dblib_err*)dbgetuserdata(dbproc);
133 if (!einfo) {
134 einfo = &DBLIB_G(err);
135 }
136
137 if (einfo->lastmsg) {
138 efree(einfo->lastmsg);
139 }
140
141 einfo->lastmsg = estrdup(msgtext);
142 }
143
144 return 0;
145}
146
148{
149 if (!err) {
150 return;
151 }
152
153 if (err->dberrstr) {
154 efree(err->dberrstr);
155 err->dberrstr = NULL;
156 }
157 if (err->lastmsg) {
158 efree(err->lastmsg);
159 err->lastmsg = NULL;
160 }
161 if (err->oserrstr) {
162 efree(err->oserrstr);
163 err->oserrstr = NULL;
164 }
165}
166
167static PHP_GINIT_FUNCTION(dblib)
168{
169#if defined(ZTS) && (defined(COMPILE_DL_PDO_DBLIB) || defined(COMPILE_DL_PDO_MSSQL))
171#endif
172 memset(dblib_globals, 0, sizeof(*dblib_globals));
173 dblib_globals->err.sqlstate = dblib_globals->sqlstate;
174}
175
177{
178 if (DBLIB_G(err).oserrstr) {
179 efree(DBLIB_G(err).oserrstr);
180 DBLIB_G(err).oserrstr = NULL;
181 }
182 if (DBLIB_G(err).dberrstr) {
183 efree(DBLIB_G(err).dberrstr);
184 DBLIB_G(err).dberrstr = NULL;
185 }
186 if (DBLIB_G(err).lastmsg) {
187 efree(DBLIB_G(err).lastmsg);
188 DBLIB_G(err).lastmsg = NULL;
189 }
190 return SUCCESS;
191}
192
194{
195 REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_CONNECTION_TIMEOUT", (long) PDO_DBLIB_ATTR_CONNECTION_TIMEOUT);
196 REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_QUERY_TIMEOUT", (long) PDO_DBLIB_ATTR_QUERY_TIMEOUT);
197 REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER", (long) PDO_DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER);
198 REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_VERSION", (long) PDO_DBLIB_ATTR_VERSION);
199 REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_TDS_VERSION", (long) PDO_DBLIB_ATTR_TDS_VERSION);
200 REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_SKIP_EMPTY_ROWSETS", (long) PDO_DBLIB_ATTR_SKIP_EMPTY_ROWSETS);
201 REGISTER_PDO_CLASS_CONST_LONG("DBLIB_ATTR_DATETIME_CONVERT", (long) PDO_DBLIB_ATTR_DATETIME_CONVERT);
202
203 if (FAIL == dbinit()) {
204 return FAILURE;
205 }
206
207 PdoDblib_ce = register_class_Pdo_Dblib(pdo_dbh_ce);
208 PdoDblib_ce->create_object = pdo_dbh_new;
209
211 return FAILURE;
212 }
213
214#ifndef PHP_DBLIB_IS_MSSQL
215 dberrhandle((EHANDLEFUNC) pdo_dblib_error_handler);
216 dbmsghandle((MHANDLEFUNC) pdo_dblib_msg_handler);
217#endif
218
220}
221
223{
225 dbexit();
226 return SUCCESS;
227}
228
230{
232 php_info_print_table_row(2, "PDO Driver for "
233#ifdef PDO_DBLIB_IS_MSSQL
234 "MSSQL"
235#elif defined(PHP_WIN32)
236 "FreeTDS/Sybase/MSSQL"
237#else
238 "FreeTDS/Sybase"
239#endif
240 " DB-lib", "enabled");
243}
const pdo_driver_t pdo_dblib_driver
char * err
Definition ffi.c:3029
memset(ptr, 0, type->size)
#define NULL
Definition gdcache.h:45
#define SUCCESS
Definition hash_sha3.c:261
PDO_API void php_pdo_unregister_driver(const pdo_driver_t *driver)
Definition pdo.c:129
PDO_API zend_result php_pdo_register_driver(const pdo_driver_t *driver)
Definition pdo.c:113
PDO_API zend_result php_pdo_register_driver_specific_ce(const pdo_driver_t *driver, zend_class_entry *ce)
Definition pdo.c:140
zend_class_entry * pdo_dbh_ce
Definition pdo.c:34
zend_object * pdo_dbh_new(zend_class_entry *ce)
Definition pdo_dbh.c:1533
int pdo_dblib_error_handler(DBPROCESS *dbproc, int severity, int dberr, int oserr, char *dberrstr, char *oserrstr)
Definition pdo_dblib.c:81
void pdo_dblib_err_dtor(pdo_dblib_err *err)
Definition pdo_dblib.c:147
zend_module_entry pdo_dblib_module_entry
Definition pdo_dblib.c:45
int pdo_dblib_msg_handler(DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, char *procname, int line)
Definition pdo_dblib.c:126
php_info_print_table_start()
Definition info.c:1064
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled")
php_info_print_table_end()
Definition info.c:1074
#define PHP_GINIT
Definition php.h:397
#define PHP_MSHUTDOWN_FUNCTION
Definition php.h:401
#define PHP_MINFO
Definition php.h:396
#define PHP_MINIT_FUNCTION
Definition php.h:400
#define PHP_MSHUTDOWN
Definition php.h:393
#define PHP_MINFO_FUNCTION
Definition php.h:404
#define PHP_GINIT_FUNCTION
Definition php.h:405
#define PHP_RSHUTDOWN
Definition php.h:395
#define PHP_RSHUTDOWN_FUNCTION
Definition php.h:403
#define PHP_MINIT
Definition php.h:392
#define PHP_MODULE_GLOBALS
Definition php.h:408
int line
Definition php_ffi.h:54
#define REGISTER_PDO_CLASS_CONST_LONG(const_name, value)
Definition php_pdo.h:53
#define PHP_PDO_DBLIB_VERSION
#define DBLIB_G(v)
@ PDO_DBLIB_ATTR_VERSION
@ PDO_DBLIB_ATTR_QUERY_TIMEOUT
@ PDO_DBLIB_ATTR_SKIP_EMPTY_ROWSETS
@ PDO_DBLIB_ATTR_DATETIME_CONVERT
@ PDO_DBLIB_ATTR_TDS_VERSION
@ PDO_DBLIB_ATTR_CONNECTION_TIMEOUT
@ PDO_DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER
#define PDO_DBLIB_FLAVOUR
#define FAIL(...)
#define ZEND_TSRMLS_CACHE_UPDATE()
Definition zend.h:69
#define ZEND_TSRMLS_CACHE_DEFINE()
Definition zend.h:68
#define ZEND_DECLARE_MODULE_GLOBALS(module_name)
Definition zend_API.h:268
#define ZEND_GET_MODULE(name)
Definition zend_API.h:241
#define efree(ptr)
Definition zend_alloc.h:155
#define estrdup(s)
Definition zend_alloc.h:164
defined(string $constant_name)
#define ZEND_MOD_END
struct _zend_module_dep zend_module_dep
struct _zend_module_entry zend_module_entry
#define ZEND_MOD_REQUIRED(name)
#define STANDARD_MODULE_PROPERTIES_EX
#define STANDARD_MODULE_HEADER_EX
struct _zend_class_entry zend_class_entry
@ FAILURE
Definition zend_types.h:61