00001 {*********************************************************}
00002 { }
00003 { Zeos Database Objects }
00004 { Delphi plain interface to libmysql.dll }
00005 { Version 4.0 }
00006 { }
00007 { Originally written by Sergey Seroukhov }
00008 { }
00009 { Thanks to : }
00010 { Pascal Data Objects Library }
00011 { }
00012 { Copyright (c) 2006 John Marino, www.synsport.com }
00013 { }
00014 {*********************************************************}
00015
00016 {@********************************************************}
00017 { Copyright (c) 1999-2006 Zeos Development Group }
00018 { }
00019 { License Agreement: }
00020 { }
00021 { This library is distributed in the hope that it will be }
00022 { useful, but WITHOUT ANY WARRANTY; without even the }
00023 { implied warranty of MERCHANTABILITY or FITNESS FOR }
00024 { A PARTICULAR PURPOSE. See the GNU Lesser General }
00025 { Public License for more details. }
00026 { }
00027 { The source code of the ZEOS Libraries and packages are }
00028 { distributed under the Library GNU General Public }
00029 { License (see the file COPYING / COPYING.ZEOS) }
00030 { with the following modification: }
00031 { As a special exception, the copyright holders of this }
00032 { library give you permission to link this library with }
00033 { independent modules to produce an executable, }
00034 { regardless of the license terms of these independent }
00035 { modules, and to copy and distribute the resulting }
00036 { executable under terms of your choice, provided that }
00037 { you also meet, for each linked independent module, }
00038 { the terms and conditions of the license of that module. }
00039 { An independent module is a module which is not derived }
00040 { from or based on this library. If you modify this }
00041 { library, you may extend this exception to your version }
00042 { of the library, but you are not obligated to do so. }
00043 { If you do not wish to do so, delete this exception }
00044 { statement from your version. }
00045 { }
00046 { }
00047 { The project web site is located on: }
00048 { http:
00049 { http:
00050 { svn:
00051 { }
00052 { http:
00053 { http:
00054 { }
00055 { }
00056 { }
00057 { Zeos Development Group. }
00058 {********************************************************@}
00059
00060 unit ZPlainMySql40;
00061
00062 interface
00063
00064 {$I ZPlain.inc}
00065 {$DEFINE MYSQL_40_API}
00066
00067 {$J+}
00068
00069 uses Classes, ZPlainLoader, ZCompatibility, ZPlainMySqlConstants;
00070
00071 { ***************** Plain API Constants definition **************** }
00072
00073 const
00074 WINDOWS1_DLL_LOCATION = 'libmysql40.dll';
00075 WINDOWS1_DLL_LOCATION_EMBEDDED = 'libmysqld40.dll';
00076 LINUX1_DLL_LOCATION = 'libmysqlclient.so.12';
00077
00078 { General Declarations }
00079
00080
00081
00082 { Enum Field Types }
00083 FIELD_TYPE_DECIMAL = 0;
00084 FIELD_TYPE_TINY = 1;
00085 FIELD_TYPE_SHORT = 2;
00086 FIELD_TYPE_LONG = 3;
00087 FIELD_TYPE_FLOAT = 4;
00088 FIELD_TYPE_DOUBLE = 5;
00089 FIELD_TYPE_NULL = 6;
00090 FIELD_TYPE_TIMESTAMP = 7;
00091 FIELD_TYPE_LONGLONG = 8;
00092 FIELD_TYPE_INT24 = 9;
00093 FIELD_TYPE_DATE = 10;
00094 FIELD_TYPE_TIME = 11;
00095 FIELD_TYPE_DATETIME = 12;
00096 FIELD_TYPE_YEAR = 13;
00097 FIELD_TYPE_NEWDATE = 14;
00098 FIELD_TYPE_VARCHAR = 15;
00099 FIELD_TYPE_BIT = 16;
00100 FIELD_TYPE_NEWDECIMAL = 246;
00101 FIELD_TYPE_ENUM = 247;
00102 FIELD_TYPE_SET = 248;
00103 FIELD_TYPE_TINY_BLOB = 249;
00104 FIELD_TYPE_MEDIUM_BLOB = 250;
00105 FIELD_TYPE_LONG_BLOB = 251;
00106 FIELD_TYPE_BLOB = 252;
00107 FIELD_TYPE_VAR_STRING = 253;
00108 FIELD_TYPE_STRING = 254;
00109 FIELD_TYPE_GEOMETRY = 255;
00110
00111 { For Compatibility }
00112 FIELD_TYPE_CHAR = FIELD_TYPE_TINY;
00113 FIELD_TYPE_INTERVAL = FIELD_TYPE_ENUM;
00114
00115 MAX_MYSQL_MANAGER_ERR = 256;
00116 MAX_MYSQL_MANAGER_MSG = 256;
00117
00118 MANAGER_OK = 200;
00119 MANAGER_INFO = 250;
00120 MANAGER_ACCESS = 401;
00121 MANAGER_CLIENT_ERR = 450;
00122 MANAGER_INTERNAL_ERR = 500;
00123
00124 { ****************** Plain API Types definition ***************** }
00125
00126 type
00127 TClientCapabilities = (
00128 CLIENT_LONG_PASSWORD,
00129 CLIENT_FOUND_ROWS,
00130 CLIENT_LONG_FLAG,
00131 CLIENT_CONNECT_WITH_DB,
00132 CLIENT_NO_SCHEMA,
00133 CLIENT_COMPRESS,
00134 CLIENT_ODBC,
00135 CLIENT_LOCAL_FILES,
00136 CLIENT_IGNORE_SPACE
00137 );
00138
00139 TSetClientCapabilities = set of TClientCapabilities;
00140
00141 TRefreshOptions = (
00142 _REFRESH_GRANT,
00143 _REFRESH_LOG,
00144 _REFRESH_TABLES,
00145 _REFRESH_HOSTS,
00146 _REFRESH_FAST
00147 );
00148 TSetRefreshOptions = set of TRefreshOptions;
00149
00150 TMySqlStatus = (
00151 MYSQL_STATUS_READY,
00152 MYSQL_STATUS_GET_RESULT,
00153 MYSQL_STATUS_USE_RESULT
00154 );
00155
00156 TMySqlOption = (
00157 MYSQL_OPT_CONNECT_TIMEOUT,
00158 MYSQL_OPT_COMPRESS,
00159 MYSQL_OPT_NAMED_PIPE,
00160 MYSQL_INIT_COMMAND,
00161 MYSQL_READ_DEFAULT_FILE,
00162 MYSQL_READ_DEFAULT_GROUP,
00163 MYSQL_SET_CHARSET_DIR,
00164 MYSQL_SET_CHARSET_NAME,
00165 MYSQL_OPT_LOCAL_INFILE
00166 );
00167
00168 TMySqlRplType = (
00169 MYSQL_RPL_MASTER,
00170 MYSQL_RPL_SLAVE,
00171 MYSQL_RPL_ADMIN
00172 );
00173
00174 PUSED_MEM=^USED_MEM;
00175 USED_MEM = packed record
00176 next: PUSED_MEM;
00177 left: Integer;
00178 size: Integer;
00179 end;
00180
00181 PERR_PROC = ^ERR_PROC;
00182 ERR_PROC = procedure;
00183
00184 PMEM_ROOT = ^MEM_ROOT;
00185 MEM_ROOT = packed record
00186 free: PUSED_MEM;
00187 used: PUSED_MEM;
00188 pre_alloc: PUSED_MEM;
00189 min_malloc: Integer;
00190 block_size: Integer;
00191 block_num: Integer;
00192 first_block_usage: Integer;
00193 error_handler: PERR_PROC;
00194 end;
00195
00196 NET = packed record
00197 hPipe: Pointer;
00198 buff: PChar;
00199 buff_end: PChar;
00200 write_pos: PChar;
00201 read_pos: PChar;
00202 fd: Integer;
00203 max_packet: Cardinal;
00204 max_packet_size: Cardinal;
00205 last_errno: Cardinal;
00206 pkt_nr: Cardinal;
00207 compress_pkt_nr: Cardinal;
00208 write_timeout: Cardinal;
00209 read_timeout: Cardinal;
00210 retry_count: Cardinal;
00211 fcntl: Integer;
00212 last_error: array[01..MYSQL_ERRMSG_SIZE] of Char;
00213 error: Char;
00214 return_errno: Byte;
00215 compress: Byte;
00216 remain_in_buf: LongInt;
00217 length: LongInt;
00218 buf_length: LongInt;
00219 where_b: LongInt;
00220 return_status: Pointer;
00221 reading_or_writing: Char;
00222 save_char: Char;
00223 no_send_ok: Byte;
00224 query_cache_query: Pointer;
00225 end;
00226
00227 PMYSQL_FIELD = ^MYSQL_FIELD;
00228 MYSQL_FIELD = record
00229 name: PChar;
00230 table: PChar;
00231 org_table: PChar;
00232 db: PChar;
00233 def: PChar;
00234 length: LongInt;
00235 max_length: LongInt;
00236 flags: Integer;
00237 decimals: Integer;
00238 _type: Byte;
00239 end;
00240
00241 MYSQL_FIELD_OFFSET = Cardinal;
00242
00243 MYSQL_ROW = array[00..$ff] of PChar;
00244 PMYSQL_ROW = ^MYSQL_ROW;
00245
00246 PMYSQL_ROWS = ^MYSQL_ROWS;
00247 MYSQL_ROWS = record
00248 next: PMYSQL_ROWS;
00249 data: PMYSQL_ROW;
00250 end;
00251
00252 MYSQL_ROW_OFFSET = PMYSQL_ROWS;
00253
00254 MYSQL_DATA = record
00255 Rows: Int64;
00256 Fields: Cardinal;
00257 Data: PMYSQL_ROWS;
00258 Alloc: MEM_ROOT;
00259 end;
00260 PMYSQL_DATA = ^MYSQL_DATA;
00261
00262 _MYSQL_OPTIONS = record
00263 connect_timeout: Cardinal;
00264 clientFlag: Cardinal;
00265 port: Cardinal;
00266 host: PChar;
00267 init_command: PChar;
00268 user: PChar;
00269 password: PChar;
00270 unix_socket: PChar;
00271 db: PChar;
00272 my_cnf_file: PChar;
00273 my_cnf_group: PChar;
00274 charset_dir: PChar;
00275 charset_name: PChar;
00276 ssl_key: PChar;
00277 ssl_cert: PChar;
00278 ssl_ca: PChar;
00279 ssl_capath: PChar;
00280 ssl_cipher: PChar;
00281 max_allowed_packet: LongInt;
00282 use_ssl: Byte;
00283 compress: Byte;
00284 named_pipe: Byte;
00285 rpl_probe: Byte;
00286 rpl_parse: Byte;
00287 no_master_reads: Byte;
00288 end;
00289
00290 PMYSQL_OPTIONS = ^_MYSQL_OPTIONS;
00291
00292 PMYSQL = ^MYSQL;
00293 MYSQL = record
00294 _net: NET;
00295 connector_fd: Pointer;
00296 host: PChar;
00297 user: PChar;
00298 passwd: PChar;
00299 unix_socket: PChar;
00300 server_version: PChar;
00301 host_info: PChar;
00302 info: PChar;
00303 db: PChar;
00304 charset: PChar;
00305 fields: PMYSQL_FIELD;
00306 field_alloc: MEM_ROOT;
00307 affected_rows: Int64;
00308 insert_id: Int64;
00309 extra_info: Int64;
00310 thread_id: LongInt;
00311 packet_length: LongInt;
00312 port: Cardinal;
00313 client_flag: Cardinal;
00314 server_capabilities: Cardinal;
00315 protocol_version: Cardinal;
00316 field_count: Cardinal;
00317 server_status: Cardinal;
00318 server_language: Cardinal;
00319 options: _mysql_options;
00320 status: TMySqlStatus;
00321 free_me: Byte;
00322 reconnect: Byte;
00323 scramble_buff: array[0..8] of Char;
00324 rpl_pivot: Byte;
00325 master: PMYSQL;
00326 next_slave: PMYSQL;
00327 last_used_slave: PMYSQL;
00328 last_used_con: PMYSQL;
00329 end;
00330
00331 TModifyType = (MODIFY_INSERT, MODIFY_UPDATE, MODIFY_DELETE);
00332 TQuoteOptions = (QUOTE_STRIP_CR,QUOTE_STRIP_LF);
00333 TQuoteOptionsSet = set of TQuoteOptions;
00334
00335 MYSQL_MANAGER = record
00336 _net: NET;
00337 host: PChar;
00338 user: PChar;
00339 passwd: PChar;
00340 port: Cardinal;
00341 free_me: Byte;
00342 eof: Byte;
00343 cmd_status: Integer;
00344 last_errno: Integer;
00345 net_buf: PChar;
00346 net_buf_pos: PChar;
00347 net_data_end: PChar;
00348 net_buf_size: Integer;
00349 last_error: array[1..MAX_MYSQL_MANAGER_ERR] of Char;
00350 end;
00351 PMYSQL_MANAGER = ^MYSQL_MANAGER;
00352
00353 { ************** Plain API Function types definition ************* }
00354 {$I ZPlainMysqlFunc.inc}
00355
00356 { ************** Collection of Plain API Function types definition ************* }
00357 MYSQL40_API = record
00358 {$I ZPlainMysqlVar.inc}
00359 END;
00360
00361 type
00362 {** Implements a loader for MySQL native library. }
00363 TZMySQLNativeLibraryLoader = class (TZNativeLibraryLoader)
00364 public
00365 api_rec : MYSQL40_API;
00366 destructor Destroy; override;
00367 function Load: Boolean; override;
00368 end;
00369
00370 var
00371
00372 LibraryLoader: TZMySQLNativeLibraryLoader;
00373 LibraryLoaderEmbedded: TZMySQLNativeLibraryLoader;
00374
00375 implementation
00376
00377 { TZMySQLNativeLibraryLoader }
00378
00379 {**
00380 Loads a library module.
00381 @return <code>True</code> if library was successfully loaded.
00382 }
00383 function TZMySQLNativeLibraryLoader.Load: Boolean;
00384 begin
00385 Result := inherited Load;
00386
00387 { ************** Load adresses of API Functions ************* }
00388 {$I ZPlainMysqlRec.inc}
00389 end;
00390
00391 {**
00392 Destroys the library and cleanups the memory.
00393 }
00394 destructor TZMySQLNativeLibraryLoader.Destroy;
00395 begin
00396 if (Loaded) and (@api_rec.mysql_server_end <> nil) then
00397 api_rec.mysql_server_end;
00398 inherited Destroy;
00399 end;
00400
00401 initialization
00402 {$IFNDEF UNIX}
00403 LibraryLoader := TZMySQLNativeLibraryLoader.Create(
00404 [WINDOWS1_DLL_LOCATION
00405 {$IFNDEF MYSQL_STRICT_DLL_LOADING}
00406 , WINDOWS2_DLL_LOCATION
00407 {$ENDIF}
00408 ]);
00409 LibraryLoaderEmbedded := TZMySQLNativeLibraryLoader.Create(
00410 [WINDOWS1_DLL_LOCATION_EMBEDDED
00411 {$IFNDEF MYSQL_STRICT_DLL_LOADING}
00412 , WINDOWS2_DLL_LOCATION_EMBEDDED
00413 {$ENDIF}
00414 ]);
00415 {$ELSE}
00416 LibraryLoader := TZMySQLNativeLibraryLoader.Create(
00417 [LINUX1_DLL_LOCATION,LINUX2_DLL_LOCATION]);
00418 LibraryLoaderEmbedded := TZMySQLNativeLibraryLoader.Create(
00419 [LINUX_DLL_LOCATION_EMBEDDED]);
00420 {$ENDIF}
00421 {$UNDEF MYSQL_40_API}
00422 finalization
00423 if Assigned(LibraryLoader) then
00424 LibraryLoader.Free;
00425 if Assigned(LibraryLoaderEmbedded) then
00426 LibraryLoaderEmbedded.Free;
00427 end.