1 // Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. 2 // 3 // This program is free software; you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License, version 2.0, as 5 // published by the Free Software Foundation. 6 // 7 // This program is also distributed with certain software (including 8 // but not limited to OpenSSL) that is licensed under separate terms, 9 // as designated in a particular file or component or in included license 10 // documentation. The authors of MySQL hereby grant you an 11 // additional permission to link the program and your derivative works 12 // with the separately licensed software that they have included with 13 // MySQL. 14 // 15 // Without limiting anything contained in the foregoing, this file, 16 // which is part of MySQL Connector/ODBC, is also subject to the 17 // Universal FOSS Exception, version 1.0, a copy of which can be found at 18 // http://oss.oracle.com/licenses/universal-foss-exception. 19 // 20 // This program is distributed in the hope that it will be useful, but 21 // WITHOUT ANY WARRANTY; without even the implied warranty of 22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 23 // See the GNU General Public License, version 2.0, for more details. 24 // 25 // You should have received a copy of the GNU General Public License 26 // along with this program; if not, write to the Free Software Foundation, Inc., 27 // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 28 29 #ifndef MYODBC_MYSQL_H 30 #define MYODBC_MYSQL_H 31 32 #define DONT_DEFINE_VOID 33 34 #if (MYSQLCLIENT_STATIC_LINKING) 35 #if (MYSQL8) 36 #define WIN32_LEAN_AND_MEAN 37 #include <my_config.h> 38 #include <my_sys.h> 39 #include <mysql.h> 40 #include <mysqld_error.h> 41 #include <my_alloc.h> 42 #include <mysql/service_mysql_alloc.h> 43 #include <m_ctype.h> 44 #include <my_io.h> 45 46 #define my_bool bool 47 #define mysys_end my_end 48 49 #ifndef TRUE 50 #define TRUE 1 51 #endif 52 53 #ifndef FALSE 54 #define FALSE 0 55 #endif 56 57 #ifdef _WIN32 58 typedef DWORD thread_local_key_t; 59 typedef CRITICAL_SECTION native_mutex_t; 60 typedef int native_mutexattr_t; 61 62 #else 63 typedef pthread_key_t thread_local_key_t; 64 //typedef pthread_mutex_t native_mutex_t; 65 //typedef pthread_mutexattr_t native_mutexattr_t; 66 #endif 67 68 69 #else // MYSQL8 70 71 #include <my_global.h> 72 #include <mysql.h> 73 #include <my_sys.h> 74 #include <my_list.h> 75 #include <m_string.h> 76 #include <mysqld_error.h> 77 #endif // MYSQL8 78 79 #else 80 81 #include "include/sys/my_global.h" 82 #include "include/sys/my_thread.h" 83 #include <mysql.h> 84 #include "include/sys_main.h" 85 #include <mysqld_error.h> 86 #define myodbc_qsort my_qsort 87 88 #endif 89 90 #ifdef __cplusplus 91 extern "C" 92 { 93 #endif 94 95 #define PSI_NOT_INSTRUMENTED 0 96 97 #define MIN_MYSQL_VERSION 40100L 98 #if MYSQL_VERSION_ID < MIN_MYSQL_VERSION 99 # error "Connector/ODBC requires v4.1 (or later) of the MySQL client library" 100 #endif 101 102 #ifdef MYSQLCLIENT_STATIC_LINKING 103 104 #define my_sys_init my_init 105 #define myodbc_malloc(A,B) my_malloc(PSI_NOT_INSTRUMENTED,A,B) 106 #ifndef x_free 107 #define x_free(A) { void *tmp= (A); if (tmp) my_free((char *) tmp); } 108 #endif 109 110 #else 111 112 #define myodbc_malloc(A,B) mysys_malloc(A,B) 113 #ifndef x_free 114 #define x_free(A) { void *tmp= (A); if (tmp) mysys_free((char *) tmp); } 115 #endif 116 117 #endif 118 119 #define myodbc_mutex_t native_mutex_t 120 #define myodbc_key_t thread_local_key_t 121 #define myodbc_realloc(A,B,C) my_realloc(PSI_NOT_INSTRUMENTED,A,B,C) 122 #define myodbc_memdup(A,B,C) my_memdup(PSI_NOT_INSTRUMENTED,A,B,C) 123 #define myodbc_strdup(A,B) my_strdup(PSI_NOT_INSTRUMENTED,A,B) 124 #define myodbc_init_dynamic_array(A,B,C,D) my_init_dynamic_array(A,PSI_NOT_INSTRUMENTED,B,NULL,C,D) 125 #define myodbc_mutex_lock native_mutex_lock 126 #define myodbc_mutex_unlock native_mutex_unlock 127 #define myodbc_mutex_trylock native_mutex_trylock 128 #define myodbc_mutex_init native_mutex_init 129 #define myodbc_mutex_destroy native_mutex_destroy 130 #define sort_dynamic(A,cmp) myodbc_qsort((A)->buffer, (A)->elements, (A)->size_of_element, (cmp)) 131 #define push_dynamic(A,B) insert_dynamic((A),(B)) 132 133 #define myodbc_snprintf my_snprintf 134 myodbc_allocate_dynamic(DYNAMIC_ARRAY * array,uint max_elements)135 static my_bool inline myodbc_allocate_dynamic(DYNAMIC_ARRAY *array, uint max_elements) 136 { 137 if (max_elements >= array->max_element) 138 { 139 uint size; 140 uchar *new_ptr; 141 size = (max_elements + array->alloc_increment) / array->alloc_increment; 142 size *= array->alloc_increment; 143 if (array->buffer == (uchar *)(array + 1)) 144 { 145 /* 146 In this senerio, the buffer is statically preallocated, 147 so we have to create an all-new malloc since we overflowed 148 */ 149 if (!(new_ptr = (uchar *)myodbc_malloc(size * 150 array->size_of_element, 151 MYF(MY_WME)))) 152 return 0; 153 memcpy(new_ptr, array->buffer, 154 array->elements * array->size_of_element); 155 } 156 else 157 158 159 if (!(new_ptr = (uchar*)myodbc_realloc(array->buffer, size* 160 array->size_of_element, 161 MYF(MY_WME | MY_ALLOW_ZERO_PTR)))) 162 return 1; 163 array->buffer = new_ptr; 164 array->max_element = size; 165 } 166 return 0; 167 } 168 delete_dynamic_element(DYNAMIC_ARRAY * array,uint idx)169 static void inline delete_dynamic_element(DYNAMIC_ARRAY *array, uint idx) 170 { 171 char *ptr = (char*)array->buffer + array->size_of_element*idx; 172 array->elements--; 173 memmove(ptr, ptr + array->size_of_element, 174 (array->elements - idx)*array->size_of_element); 175 } 176 177 178 /* Get rid of defines from my_config.h that conflict with our myconf.h */ 179 #ifdef VERSION 180 # undef VERSION 181 #endif 182 #ifdef PACKAGE 183 # undef PACKAGE 184 #endif 185 186 /* 187 It doesn't matter to us what SIZEOF_LONG means to MySQL's headers, but its 188 value matters a great deal to unixODBC, which calculates it differently. 189 190 This causes problems where an application linked against unixODBC thinks 191 SIZEOF_LONG == 4, and the driver was compiled thinking SIZEOF_LONG == 8, 192 such as on Solaris x86_64 using Sun C 5.8. 193 194 This stems from unixODBC's use of silly platform macros to guess 195 SIZEOF_LONG instead of just using sizeof(long). 196 */ 197 #ifdef SIZEOF_LONG 198 # undef SIZEOF_LONG 199 #endif 200 201 #ifdef __cplusplus 202 } 203 #endif 204 205 #endif 206 207