00001 {*********************************************************}
00002 { }
00003 { Zeos Database Objects }
00004 { Delphi plain interface to libmysql.dll }
00005 { Version 3.20 }
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 ZPlainMySql320;
00061
00062 interface
00063
00064 {$I ZPlain.inc}
00065 {$DEFINE MYSQL_320_API}
00066
00067 {$J+}
00068
00069 uses Classes, ZPlainLoader, ZCompatibility, ZPlainMySqlConstants;
00070
00071 { ***************** Plain API Constants definition **************** }
00072
00073 const
00074 WINDOWS1_DLL_LOCATION = 'libmysql320.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 min_malloc: Integer;
00172 block_size: Integer;
00173 error_handler: PERR_PROC;
00174 end;
00175
00176 NET = packed record
00177 hPipe: Pointer;
00178 fd: Integer;
00179 fcntl: Integer;
00180 buff: PChar;
00181 buff_end: PChar;
00182 write_pos: PChar;
00183 read_pos: PChar;
00184 last_error: array[01..MYSQL_ERRMSG_SIZE] of Char;
00185 last_errno: Integer;
00186 max_packet: Integer;
00187 timeout: Integer;
00188 pkt_nr: Integer;
00189 error: Byte;
00190 return_errno: Byte;
00191 compress: Byte;
00192 remain_in_buf: LongInt;
00193 length: LongInt;
00194 buf_length: LongInt;
00195 where_b: LongInt;
00196 more: Byte;
00197 save_char: Char;
00198 end;
00199
00200 PMYSQL_FIELD = ^MYSQL_FIELD;
00201 MYSQL_FIELD = record
00202 name: PChar;
00203 table: PChar;
00204 def: PChar;
00205 _type: Byte;
00206 length: Integer;
00207 max_length: Integer;
00208 flags: Integer;
00209 decimals: Integer;
00210 end;
00211
00212 MYSQL_FIELD_OFFSET = Cardinal;
00213
00214 MYSQL_ROW = array[00..$ff] of PChar;
00215 PMYSQL_ROW = ^MYSQL_ROW;
00216
00217 PMYSQL_ROWS = ^MYSQL_ROWS;
00218 MYSQL_ROWS = record
00219 next: PMYSQL_ROWS;
00220 data: PMYSQL_ROW;
00221 end;
00222
00223 MYSQL_ROW_OFFSET = PMYSQL_ROWS;
00224
00225 MYSQL_DATA = record
00226 Rows: Int64;
00227 Fields: Cardinal;
00228 Data: PMYSQL_ROWS;
00229 Alloc: MEM_ROOT;
00230 end;
00231 PMYSQL_DATA = ^MYSQL_DATA;
00232
00233 PMYSQL_OPTIONS = ^_MYSQL_OPTIONS;
00234 _MYSQL_OPTIONS = record
00235 connect_timeout: Integer;
00236 clientFlag: Integer;
00237 compress: Byte;
00238 named_pipe: Byte;
00239 port: Integer;
00240 host: PChar;
00241 init_command: PChar;
00242 user: PChar;
00243 password: PChar;
00244 unix_socket: PChar;
00245 db: PChar;
00246 my_cnf_file: PChar;
00247 my_cnf_group: PChar;
00248 charset_dir: PChar;
00249 charset_name: PChar;
00250 use_ssl: Byte;
00251 ssl_key: PChar;
00252 ssl_cert: PChar;
00253 ssl_ca: PChar;
00254 ssl_capath: PChar;
00255 end;
00256
00257 PMYSQL = ^MYSQL;
00258 MYSQL = record
00259 _net: NET;
00260 connector_fd: PChar;
00261 host: PChar;
00262 user: PChar;
00263 passwd: PChar;
00264 unix_socket: PChar;
00265 server_version: PChar;
00266 host_info: PChar;
00267 info: PChar;
00268 db: PChar;
00269 port: Integer;
00270 client_flag: Integer;
00271 server_capabilities: Integer;
00272 protocol_version: Integer;
00273 field_count: Integer;
00274 thread_id: LongInt;
00275 affected_rows: Int64;
00276 insert_id: Int64;
00277 extra_info: Int64;
00278 packet_length: LongInt;
00279 status: Tmysqlstatus;
00280 fields: PMYSQL_FIELD;
00281 field_alloc: MEM_ROOT;
00282 free_me, reconnect: Byte;
00283 options: _mysql_options;
00284 scramble_buff: array[0..8] of Char;
00285 charset: PChar;
00286 end;
00287
00288 TModifyType = (MODIFY_INSERT, MODIFY_UPDATE, MODIFY_DELETE);
00289 TQuoteOptions = (QUOTE_STRIP_CR,QUOTE_STRIP_LF);
00290 TQuoteOptionsSet = set of TQuoteOptions;
00291
00292 { ************** Plain API Function types definition ************* }
00293 {$I ZPlainMysqlFunc.inc}
00294
00295 { ************** Collection of Plain API Function types definition ************* }
00296 MYSQL320_API = record
00297 {$I ZPlainMysqlVar.inc}
00298 END;
00299
00300 type
00301 {** Implements a loader for MySQL native library. }
00302 TZMySQLNativeLibraryLoader = class (TZNativeLibraryLoader)
00303 public
00304 api_rec : MYSQL320_API;
00305 destructor Destroy; override;
00306 function Load: Boolean; override;
00307 end;
00308
00309 var
00310
00311 LibraryLoader: TZMySQLNativeLibraryLoader;
00312
00313 implementation
00314
00315 { TZMySQLNativeLibraryLoader }
00316
00317 {**
00318 Loads a library module.
00319 @return <code>True</code> if library was successfully loaded.
00320 }
00321 function TZMySQLNativeLibraryLoader.Load: Boolean;
00322 begin
00323 Result := inherited Load;
00324
00325 { ************** Load adresses of API Functions ************* }
00326 {$I ZPlainMysqlRec.inc}
00327 end;
00328
00329 {**
00330 Destroys the library and cleanups the memory.
00331 }
00332 destructor TZMySQLNativeLibraryLoader.Destroy;
00333 begin
00334 if (Loaded) and (@api_rec.mysql_server_end <> nil) then
00335 api_rec.mysql_server_end;
00336 inherited Destroy;
00337 end;
00338
00339 initialization
00340 {$IFNDEF UNIX}
00341 LibraryLoader := TZMySQLNativeLibraryLoader.Create(
00342 [WINDOWS1_DLL_LOCATION
00343 {$IFNDEF MYSQL_STRICT_DLL_LOADING}
00344 , WINDOWS2_DLL_LOCATION
00345 {$ENDIF}
00346 ]);
00347 {$ELSE}
00348 LibraryLoader := TZMySQLNativeLibraryLoader.Create(
00349 [LINUX1_DLL_LOCATION,LINUX2_DLL_LOCATION]);
00350 {$ENDIF}
00351 {$UNDEF MYSQL_320_API}
00352 finalization
00353 if Assigned(LibraryLoader) then
00354 LibraryLoader.Free;
00355 end.