xref: /PHP-5.3/ext/mysqlnd/mysqlnd_priv.h (revision bc11e6fd)
1 /*
2   +----------------------------------------------------------------------+
3   | PHP Version 5                                                        |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 2006-2013 The PHP Group                                |
6   +----------------------------------------------------------------------+
7   | This source file is subject to version 3.01 of the PHP license,      |
8   | that is bundled with this package in the file LICENSE, and is        |
9   | available through the world-wide-web at the following url:           |
10   | http://www.php.net/license/3_01.txt                                  |
11   | If you did not receive a copy of the PHP license and are unable to   |
12   | obtain it through the world-wide-web, please send a note to          |
13   | license@php.net so we can mail you a copy immediately.               |
14   +----------------------------------------------------------------------+
15   | Authors: Georg Richter <georg@mysql.com>                             |
16   |          Andrey Hristov <andrey@mysql.com>                           |
17   |          Ulf Wendel <uwendel@mysql.com>                              |
18   +----------------------------------------------------------------------+
19 */
20 
21 /* $Id$ */
22 
23 #ifndef MYSQLND_PRIV_H
24 #define MYSQLND_PRIV_H
25 
26 #ifndef Z_ADDREF_P
27 /* PHP 5.2, old GC */
28 #define Z_ADDREF_P(pz)				(++(pz)->refcount)
29 #define Z_DELREF_P(pz)				(--(pz)->refcount)
30 #define Z_REFCOUNT_P(pz)			((pz)->refcount)
31 #define Z_SET_REFCOUNT_P(pz, rc)	((pz)->refcount = rc)
32 #define Z_REFCOUNT_PP(ppz)			Z_REFCOUNT_P(*(ppz))
33 #define Z_DELREF_PP(ppz)			Z_DELREF_P(*(ppz))
34 #endif
35 
36 #if PHP_MAJOR_VERSION >= 6
37 #define MYSQLND_UNICODE 1
38 #else
39 #define MYSQLND_UNICODE 0
40 #endif
41 
42 #ifdef ZTS
43 #include "TSRM.h"
44 #endif
45 
46 #ifndef pestrndup
47 #define pestrndup(s, length, persistent) ((persistent)?zend_strndup((s),(length)):estrndup((s),(length)))
48 #endif
49 
50 #define MYSQLND_CLASS_METHOD_TABLE_NAME(class) mysqlnd_##class##_methods
51 #define MYSQLND_CLASS_METHODS_START(class)	struct st_##class##_methods MYSQLND_CLASS_METHOD_TABLE_NAME(class) = {
52 #define MYSQLND_CLASS_METHODS_END			}
53 
54 #if MYSQLND_UNICODE
55 #define mysqlnd_array_init(arg, field_count) \
56 { \
57 	ALLOC_HASHTABLE_REL(Z_ARRVAL_P(arg));\
58 	zend_u_hash_init(Z_ARRVAL_P(arg), (field_count), NULL, ZVAL_PTR_DTOR, 0, 0);\
59 	Z_TYPE_P(arg) = IS_ARRAY;\
60 }
61 #else
62 #define mysqlnd_array_init(arg, field_count) \
63 { \
64 	ALLOC_HASHTABLE_REL(Z_ARRVAL_P(arg));\
65 	zend_hash_init(Z_ARRVAL_P(arg), (field_count), NULL, ZVAL_PTR_DTOR, 0); \
66 	Z_TYPE_P(arg) = IS_ARRAY;\
67 }
68 #endif
69 
70 
71 #define MYSQLND_DEBUG_DUMP_TIME				1
72 #define MYSQLND_DEBUG_DUMP_TRACE			2
73 #define MYSQLND_DEBUG_DUMP_PID				4
74 #define MYSQLND_DEBUG_DUMP_LINE				8
75 #define MYSQLND_DEBUG_DUMP_FILE				16
76 #define MYSQLND_DEBUG_DUMP_LEVEL			32
77 #define MYSQLND_DEBUG_APPEND				64
78 #define MYSQLND_DEBUG_FLUSH					128
79 #define MYSQLND_DEBUG_TRACE_MEMORY_CALLS	256
80 #define MYSQLND_DEBUG_PROFILE_CALLS			512
81 
82 
83 /* Client Error codes */
84 #define CR_UNKNOWN_ERROR		2000
85 #define CR_CONNECTION_ERROR		2002
86 #define CR_SERVER_GONE_ERROR	2006
87 #define CR_OUT_OF_MEMORY		2008
88 #define CR_SERVER_LOST			2013
89 #define CR_COMMANDS_OUT_OF_SYNC	2014
90 #define CR_CANT_FIND_CHARSET	2019
91 #define CR_MALFORMED_PACKET		2027
92 #define CR_NOT_IMPLEMENTED		2054
93 #define CR_NO_PREPARE_STMT		2030
94 #define CR_PARAMS_NOT_BOUND		2031
95 #define CR_INVALID_PARAMETER_NO	2034
96 #define CR_INVALID_BUFFER_USE	2035
97 
98 #define MYSQLND_EE_FILENOTFOUND	 7890
99 
100 #define UNKNOWN_SQLSTATE		"HY000"
101 
102 #define MAX_CHARSET_LEN			32
103 
104 
105 #define SET_ERROR_AFF_ROWS(s)	(s)->upsert_status.affected_rows = (uint64_t) ~0
106 
107 /* Error handling */
108 #define SET_NEW_MESSAGE(buf, buf_len, message, len, persistent) \
109 	{\
110 		if ((buf)) { \
111 			mnd_pefree((buf), (persistent)); \
112 		} \
113 		if ((message)) { \
114 			(buf) = mnd_pestrndup((message), (len), (persistent)); \
115 		} else { \
116 			(buf) = NULL; \
117 		} \
118 		(buf_len) = (len); \
119 	}
120 
121 #define SET_EMPTY_MESSAGE(buf, buf_len, persistent) \
122 	{\
123 		if ((buf)) { \
124 			mnd_pefree((buf), (persistent)); \
125 			(buf) = NULL; \
126 		} \
127 		(buf_len) = 0; \
128 	}
129 
130 
131 #define SET_EMPTY_ERROR(error_info) \
132 	{ \
133 		(error_info).error_no = 0; \
134 		(error_info).error[0] = '\0'; \
135 		strlcpy((error_info).sqlstate, "00000", sizeof((error_info).sqlstate)); \
136 	}
137 
138 #define SET_CLIENT_ERROR(error_info, a, b, c) \
139 	{ \
140 		(error_info).error_no = (a); \
141 		strlcpy((error_info).sqlstate, (b), sizeof((error_info).sqlstate)); \
142 		strlcpy((error_info).error, (c), sizeof((error_info).error)); \
143 	}
144 
145 #define SET_OOM_ERROR(error_info) SET_CLIENT_ERROR((error_info), CR_OUT_OF_MEMORY, UNKNOWN_SQLSTATE, mysqlnd_out_of_memory)
146 
147 
148 #define SET_STMT_ERROR(stmt, a, b, c)	SET_CLIENT_ERROR((stmt)->error_info, a, b, c)
149 
150 #define CONN_GET_STATE(c)		(c)->m->get_state((c) TSRMLS_CC)
151 #define CONN_SET_STATE(c, s)	(c)->m->set_state((c), (s) TSRMLS_CC)
152 
153 /* PS stuff */
154 typedef void (*ps_field_fetch_func)(zval *zv, const MYSQLND_FIELD * const field,
155 									unsigned int pack_len, zend_uchar **row,
156 									zend_bool everything_as_unicode TSRMLS_DC);
157 struct st_mysqlnd_perm_bind {
158 	ps_field_fetch_func func;
159 	/* should be signed int */
160 	int					pack_len;
161 	unsigned int		php_type;
162 	zend_bool			is_possibly_blob;
163 	zend_bool			can_ret_as_str_in_uni;
164 };
165 
166 extern struct st_mysqlnd_perm_bind mysqlnd_ps_fetch_functions[MYSQL_TYPE_LAST + 1];
167 
168 PHPAPI extern const char * const mysqlnd_old_passwd;
169 PHPAPI extern const char * const mysqlnd_out_of_sync;
170 PHPAPI extern const char * const mysqlnd_server_gone;
171 PHPAPI extern const char * const mysqlnd_out_of_memory;
172 
173 enum_func_status mysqlnd_handle_local_infile(MYSQLND *conn, const char *filename, zend_bool *is_warning TSRMLS_DC);
174 
175 
176 
177 void _mysqlnd_init_ps_subsystem();/* This one is private, mysqlnd_library_init() will call it */
178 void _mysqlnd_init_ps_fetch_subsystem();
179 
180 void ps_fetch_from_1_to_8_bytes(zval *zv, const MYSQLND_FIELD * const field,
181 								unsigned int pack_len, zend_uchar **row, zend_bool as_unicode,
182 								unsigned int byte_count TSRMLS_DC);
183 
184 #endif	/* MYSQLND_PRIV_H */
185 
186 
187 /*
188  * Local variables:
189  * tab-width: 4
190  * c-basic-offset: 4
191  * End:
192  * vim600: noet sw=4 ts=4 fdm=marker
193  * vim<600: noet sw=4 ts=4
194  */
195