00001 {*********************************************************}
00002 { }
00003 { Zeos Database Objects }
00004 { Delphi plain interface to libmysql.dll }
00005 { Version 3.23 }
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 ZPlainMySql323;
00061
00062 interface
00063
00064 {$I ZPlain.inc}
00065 {$DEFINE MYSQL_323_API}
00066
00067 {$J+}
00068
00069 uses Classes, ZPlainLoader, ZCompatibility, ZPlainMySqlConstants;
00070
00071 { ***************** Plain API Constants definition **************** }
00072
00073 const
00074 WINDOWS1_DLL_LOCATION = 'libmysql323.dll';
00075 LINUX1_DLL_LOCATION = 'libmysqlclient.so.10';
00076
00077 { General Declarations }
00078
00079
00080
00081 { Enum Field Types }
00082 FIELD_TYPE_DECIMAL = 0;
00083 FIELD_TYPE_TINY = 1;
00084 FIELD_TYPE_SHORT = 2;
00085 FIELD_TYPE_LONG = 3;
00086 FIELD_TYPE_FLOAT = 4;
00087 FIELD_TYPE_DOUBLE = 5;
00088 FIELD_TYPE_NULL = 6;
00089 FIELD_TYPE_TIMESTAMP = 7;
00090 FIELD_TYPE_LONGLONG = 8;
00091 FIELD_TYPE_INT24 = 9;
00092 FIELD_TYPE_DATE = 10;
00093 FIELD_TYPE_TIME = 11;
00094 FIELD_TYPE_DATETIME = 12;
00095 FIELD_TYPE_YEAR = 13;
00096 FIELD_TYPE_NEWDATE = 14;
00097 FIELD_TYPE_VARCHAR = 15;
00098 FIELD_TYPE_BIT = 16;
00099 FIELD_TYPE_NEWDECIMAL = 246;
00100 FIELD_TYPE_ENUM = 247;
00101 FIELD_TYPE_SET = 248;
00102 FIELD_TYPE_TINY_BLOB = 249;
00103 FIELD_TYPE_MEDIUM_BLOB = 250;
00104 FIELD_TYPE_LONG_BLOB = 251;
00105 FIELD_TYPE_BLOB = 252;
00106 FIELD_TYPE_VAR_STRING = 253;
00107 FIELD_TYPE_STRING = 254;
00108 FIELD_TYPE_GEOMETRY = 255;
00109
00110 { For Compatibility }
00111 FIELD_TYPE_CHAR = FIELD_TYPE_TINY;
00112 FIELD_TYPE_INTERVAL = FIELD_TYPE_ENUM;
00113
00114 { ****************** Plain API Types definition ***************** }
00115
00116 type
00117 TClientCapabilities = (
00118 CLIENT_LONG_PASSWORD,
00119 CLIENT_FOUND_ROWS,
00120 CLIENT_LONG_FLAG,
00121 CLIENT_CONNECT_WITH_DB,
00122 CLIENT_NO_SCHEMA,
00123 CLIENT_COMPRESS,
00124 CLIENT_ODBC,
00125 CLIENT_LOCAL_FILES,
00126 CLIENT_IGNORE_SPACE
00127 );
00128
00129 TSetClientCapabilities = set of TClientCapabilities;
00130
00131 TRefreshOptions = (
00132 _REFRESH_GRANT,
00133 _REFRESH_LOG,
00134 _REFRESH_TABLES,
00135 _REFRESH_HOSTS,
00136 _REFRESH_FAST
00137 );
00138 TSetRefreshOptions = set of TRefreshOptions;
00139
00140 TMySqlStatus = (
00141 MYSQL_STATUS_READY,
00142 MYSQL_STATUS_GET_RESULT,
00143 MYSQL_STATUS_USE_RESULT
00144 );
00145
00146 TMySqlOption = (
00147 MYSQL_OPT_CONNECT_TIMEOUT,
00148 MYSQL_OPT_COMPRESS,
00149 MYSQL_OPT_NAMED_PIPE,
00150 MYSQL_INIT_COMMAND,
00151 MYSQL_READ_DEFAULT_FILE,
00152 MYSQL_READ_DEFAULT_GROUP,
00153 MYSQL_SET_CHARSET_DIR,
00154 MYSQL_SET_CHARSET_NAME
00155 );
00156
00157 PUSED_MEM=^USED_MEM;
00158 USED_MEM = packed record
00159 next: PUSED_MEM;
00160 left: Integer;
00161 size: Integer;
00162 end;
00163
00164 PERR_PROC = ^ERR_PROC;
00165 ERR_PROC = procedure;
00166
00167 PMEM_ROOT = ^MEM_ROOT;
00168 MEM_ROOT = packed record
00169 free: PUSED_MEM;
00170 used: PUSED_MEM;
00171 pre_alloc: PUSED_MEM;
00172 min_malloc: Integer;
00173 block_size: Integer;
00174 error_handler: PERR_PROC;
00175 end;
00176
00177 NET = packed record
00178 hPipe: Pointer;
00179 fd: Integer;
00180 fcntl: Integer;
00181 buff: PChar;
00182 buff_end: PChar;
00183 write_pos: PChar;
00184 read_pos: PChar;
00185 last_error: array[01..MYSQL_ERRMSG_SIZE] of Char;
00186 last_errno: Integer;
00187 max_packet: Integer;
00188 timeout: Integer;
00189 pkt_nr: Integer;
00190 error: Char;
00191 return_errno: Byte;
00192 compress: Byte;
00193 no_send_ok: Byte;
00194 remain_in_buf: LongInt;
00195 length: LongInt;
00196 buf_length: LongInt;
00197 where_b: LongInt;
00198 return_status: Pointer;
00199 reading_or_writing: Char;
00200 save_char: Char;
00201 end;
00202
00203 PMYSQL_FIELD = ^MYSQL_FIELD;
00204 MYSQL_FIELD = record
00205 name: PChar;
00206 table: PChar;
00207 def: PChar;
00208 _type: Byte;
00209 length: Integer;
00210 max_length: Integer;
00211 flags: Integer;
00212 decimals: Integer;
00213 end;
00214
00215 MYSQL_FIELD_OFFSET = Cardinal;
00216
00217 MYSQL_ROW = array[00..$ff] of PChar;
00218 PMYSQL_ROW = ^MYSQL_ROW;
00219
00220 PMYSQL_ROWS = ^MYSQL_ROWS;
00221 MYSQL_ROWS = record
00222 next: PMYSQL_ROWS;
00223 data: PMYSQL_ROW;
00224 end;
00225
00226 MYSQL_ROW_OFFSET = PMYSQL_ROWS;
00227
00228 MYSQL_DATA = record
00229 Rows: Int64;
00230 Fields: Cardinal;
00231 Data: PMYSQL_ROWS;
00232 Alloc: MEM_ROOT;
00233 end;
00234 PMYSQL_DATA = ^MYSQL_DATA;
00235
00236 PMYSQL_OPTIONS = ^_MYSQL_OPTIONS;
00237 _MYSQL_OPTIONS = record
00238 connect_timeout: Integer;
00239 clientFlag: Integer;
00240 compress: Byte;
00241 named_pipe: Byte;
00242 port: Integer;
00243 host: PChar;
00244 init_command: PChar;
00245 user: PChar;
00246 password: PChar;
00247 unix_socket: PChar;
00248 db: PChar;
00249 my_cnf_file: PChar;
00250 my_cnf_group: PChar;
00251 charset_dir: PChar;
00252 charset_name: PChar;
00253 use_ssl: Byte;
00254 ssl_key: PChar;
00255 ssl_cert: PChar;
00256 ssl_ca: PChar;
00257 ssl_capath: PChar;
00258 end;
00259
00260 PMYSQL = ^MYSQL;
00261 MYSQL = record
00262 _net: NET;
00263 connector_fd: PChar;
00264 host: PChar;
00265 user: PChar;
00266 passwd: PChar;
00267 unix_socket: PChar;
00268 server_version: PChar;
00269 host_info: PChar;
00270 info: PChar;
00271 db: PChar;
00272 port: Integer;
00273 client_flag: Integer;
00274 server_capabilities: Integer;
00275 protocol_version: Integer;
00276 field_count: Integer;
00277 server_status: Integer;
00278 thread_id: LongInt;
00279 affected_rows: Int64;
00280 insert_id: Int64;
00281 extra_info: Int64;
00282 packet_length: LongInt;
00283 status: Tmysqlstatus;
00284 fields: PMYSQL_FIELD;
00285 field_alloc: MEM_ROOT;
00286 free_me, reconnect: Byte;
00287 options: _mysql_options;
00288 scramble_buff: array[0..8] of Char;
00289 charset: PChar;
00290 server_language: Integer;
00291 end;
00292
00293 TModifyType = (MODIFY_INSERT, MODIFY_UPDATE, MODIFY_DELETE);
00294 TQuoteOptions = (QUOTE_STRIP_CR,QUOTE_STRIP_LF);
00295 TQuoteOptionsSet = set of TQuoteOptions;
00296
00297 { ************** Plain API Function types definition ************* }
00298 {$I ZPlainMysqlFunc.inc}
00299
00300 { ************** Collection of Plain API Function types definition ************* }
00301 MYSQL323_API = record
00302 {$I ZPlainMysqlVar.inc}
00303 END;
00304
00305 type
00306 {** Implements a loader for MySQL native library. }
00307 TZMySQLNativeLibraryLoader = class (TZNativeLibraryLoader)
00308 public
00309 api_rec : MYSQL323_API;
00310 destructor Destroy; override;
00311 function Load: Boolean; override;
00312 end;
00313
00314 var
00315
00316 LibraryLoader: TZMySQLNativeLibraryLoader;
00317
00318 implementation
00319
00320 { TZMySQLNativeLibraryLoader }
00321
00322 {**
00323 Loads a library module.
00324 @return <code>True</code> if library was successfully loaded.
00325 }
00326 function TZMySQLNativeLibraryLoader.Load: Boolean;
00327 begin
00328 Result := inherited Load;
00329
00330 { ************** Load adresses of API Functions ************* }
00331 {$I ZPlainMysqlRec.inc}
00332 end;
00333
00334 {**
00335 Destroys the library and cleanups the memory.
00336 }
00337 destructor TZMySQLNativeLibraryLoader.Destroy;
00338 begin
00339 if (Loaded) and (@api_rec.mysql_server_end <> nil) then
00340 api_rec.mysql_server_end;
00341 inherited Destroy;
00342 end;
00343
00344 initialization
00345 {$IFNDEF UNIX}
00346 LibraryLoader := TZMySQLNativeLibraryLoader.Create(
00347 [WINDOWS1_DLL_LOCATION
00348 {$IFNDEF MYSQL_STRICT_DLL_LOADING}
00349 , WINDOWS2_DLL_LOCATION
00350 {$ENDIF}
00351 ]);
00352 {$ELSE}
00353 LibraryLoader := TZMySQLNativeLibraryLoader.Create(
00354 [LINUX1_DLL_LOCATION,LINUX2_DLL_LOCATION]);
00355 {$ENDIF}
00356 {$UNDEF MYSQL_323_API}
00357 finalization
00358 if Assigned(LibraryLoader) then
00359 LibraryLoader.Free;
00360 end.