Statistiques
| Révision:

root / LicensesMercure / mysql.pas @ 5

Historique | Voir | Annoter | Télécharger (126,198 ko)

1 1 avalancogn
{  -----------------------------------------------------------------------------------------------
2

3
                      MySQL Client API for Borland Delphi (version 4 and above)
4

5
                             Pascal Interface Unit for libmySQL.dll, the
6
                          Client Library for MySQL AB's SQL Database Server
7

8
                    This is a literal translation of relevant parts of MySQL AB's
9
                      C header files, mysql.h, mysql_com.h, and mysql_version.h
10

11
   -----------------------------------------------------------------------------------------------
12
                         See mysql.h for MySQL AB's copyright and GPL notice
13
   -----------------------------------------------------------------------------------------------
14

15
       17-Aug-1999  mf  Translated mysql.h                             MySQL 3.22.24
16
       19-Aug-1999  mf  Corrected some type definitions                MySQL 3.22.24
17
       20-Aug-1999  mf  Finished debugging the unit                    MySQL 3.22.24
18
       18-Sep-1999  mf  Code maintenance for release 3.22.26a          MySQL 3.22.26a
19
       22-Oct-1999  mf  Code maintenance for release 3.22.28           MySQL 3.22.28
20
       02-Jan-2000  mf  Code maintenance for release 3.22.29           MySQL 3.22.29
21
       21-Jan-2000  mf  Code maintenance for release 3.22.30           MySQL 3.22.30
22
       07-Feb-2000  mf  Code maintenance for release 3.22.31           MySQL 3.22.31
23
       16-Feb-2000  mf  Code maintenance for release 3.22.32           MySQL 3.22.32
24
       13-Aug-2000  mf  Code maintenance for release 3.22.34           MySQL 3.22.34
25
       14-Aug-2000  mf  Reworked entire unit for first 3.23 release    MySQL 3.23.19-beta
26
       14-Aug-2000  mf  Added mysql_character_set_name()               MySQL 3.23.22-beta
27
       11-Sep-2000  mf  Added IS_NUM_FIELD and INTERNAL_NUM_FIELD      MySQL 3.23.24-beta
28
       08-Oct-2000  mf  Modified TMEM_ROOT, enum_server_command,       MySQL 3.23.25-beta
29
                        and INTERNAL_NUM_FIELD
30
       01-Nov-2000  mf  Code maintenance for release 3.23.27           MySQL 3.23.27-beta
31
       25-Nov-2000  mf  Code maintenance for release 3.23.28           MySQL 3.23.28-gamma
32
       05-Jan-2001  mf  Code maintenance for release 3.23.30           MySQL 3.23.30-gamma
33
       19-Jan-2001  mf  Code maintenance for release 3.23.31           MySQL 3.23.31
34
       11-Mar-2001  mf  Added functions mysql_real_send_query(),       MySQL 3.23.33
35
                        mysql_send_query(), and mysql_reap_query()
36
       28-Mai-2001  mf  Modified mysql_send_query(), removed           MySQL 3.23.38
37
                        mysql_real_send_query(), mysql_reap_query(),
38
                        added mysql_read_query_result(), and fixed
39
                        CLIENT_TRANSACTIONS
40
       07-Aug-2001  mf  Code maintenance for release 3.23.40           MySQL 3.23.40
41
       23-Sep-2001  mf  Code maintenance for release 3.23.42           MySQL 3.23.42
42
       29-Jan-2002  mf  Added libmysql_load(), libmysql_free(),        MySQL 3.23.47
43
                        libmysql_status and LIBMYSQL_ constants
44
                        for dynamic loading of libmySQL.dll
45
       11-Mar-2002  mf  Added MYSQL_OPT_LOCAL_INFILE to mysql_option   MySQL 3.23.49
46
       03-Jun-2002  so  result of mysql_row_tell is MYSQL_ROW_OFFSET
47
       05-Nov-2006  so  Update for LibMySQL Version 4.00 and 4.10
48
                        Different records for the varius versions
49
       26-May-2007  so  Update for LibMySQL Version 5.00 and 5.10
50
       29-Mar-2009  so  Remove all const in PAnsiChar-Params to
51
                        clearify what happend (C don't know "call by
52
                        reference")
53
       30-Mar-2009  so  Resourcestrings
54
                        Added functions mysql_field_flag,
55
                        mysql_field_type, mysql_field_name,
56
                        mysql_field_tablename
57
       11-Apr-2009  so  improved dynamic loading by new function
58
                        libmysql_fast_load
59
       13-Apr-2009  so  Added functions mysql_field_length, IS_LONGDATA;
60
                        Code maintenance enum_field_types
61
       17-Apr-2009  so  Added functions mysql_autocommit,
62
                        mysql_set_character_set, mysql_commit,
63
                        mysql_rollback, mysql_set_server_option,
64
                        mysql_sqlstate, mysql_warning_count
65
                        MySql_StrLen, CharSetNameToCodepage,
66
                        CodepageToCharSetName, MySqlToUTF16,
67
                        UTF16ToMySql
68
       01-May-2009  so  mysql_odbc_escape_string is deprecated
69
       08-Jun-2009  so  Added functions mysql_server_init, mysql_server_end
70
                        Added support for prepared statements
71
       09-Jun-2009  so  Added records: TNET501, TMYSQL501
72
       10-Jun-2009  so  Added functions mysql_thread_init, mysql_thread_end
73
       18-Jun-2009  so  Added functions mysql_more_results, mysql_next_result,
74
                        FormatIdentifier
75
       04-Jul-2009  so  Added functions EscapeString, EscapeForLike, QuoteString,
76
                        FullFieldname
77
                        Change FormatIdentifier to QuoteName
78
       04-Aug-2009  so  Bug in GetVersion fixed
79

80
   -----------------------------------------------------------------------------------------------
81

82
                     Latest releases of mysql.pas are made available through the
83
                      distribution site at: http://www.audio-data.de/mysql.html
84

85
                        See readme.txt for an introduction and documentation.
86

87
              *********************************************************************
88
              * The contents of this file are used with permission, subject to    *
89
              * the Mozilla Public License Version 1.1 (the "License"); you may   *
90
              * not use this file except in compliance with the License. You may  *
91
              * obtain a copy of the License at                                   *
92
              * http:  www.mozilla.org/MPL/MPL-1.1.html                           *
93
              *                                                                   *
94
              * Software distributed under the License is distributed on an       *
95
              * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or    *
96
              * implied. See the License for the specific language governing      *
97
              * rights and limitations under the License.                         *
98
              *                                                                   *
99
              *  Contributor(s)                                                   *
100
              *  (mf)  Matthias Fichtner <matthias@fichtner.net>                  *
101
              *  (so)  Samuel Soldat     <samuel.soldat@audio-data.de>            *
102
              *                                                                   *
103
              *********************************************************************}
104
105
unit mysql;
106
107
{$IFNDEF DEBUG}
108
{$DEBUGINFO OFF}
109
{$LOCALSYMBOLS OFF}
110
{$ASSERTIONS OFF}
111
{$ENDIF}
112
{$RANGECHECKS OFF}
113
{$TYPEDADDRESS OFF}
114
{$LONGSTRINGS ON}
115
{$EXTENDEDSYNTAX ON}
116
{$REFERENCEINFO ON}
117
{$MINENUMSIZE 4}
118
119
{$DEFINE DONT_LOAD_DLL}
120
{.$DEFINE EmbeddedCharacterConvert}
121
{$DEFINE Win32CharacterConvert}
122
123
// -----------------------------------------------------------------------------------------------
124
INTERFACE
125
// -----------------------------------------------------------------------------------------------
126
127
uses
128
  Windows,  // Needed for some type definitions
129
  Winsock;  // Needed for some type definitions
130
131
type
132
{$IFDEF CONDITIONALEXPRESSIONS}
133
  {Delphi 6 and above}
134
  {$IF NOT DECLARED(UnicodeString)}
135
  UnicodeString = WideString;
136
  {$IFEND}
137
  {$IF NOT DECLARED(RawByteString)}
138
  RawByteString = AnsiString;
139
  {$IFEND}
140
  {$IF DECLARED(UInt64)}
141
  my_ulonglong = UInt64;
142
  {$IFEND}
143
  {$IF NOT DECLARED(UInt64)}
144
  my_ulonglong = Int64;
145
  {$IFEND}
146
{$ELSE}
147
  UnicodeString = WideString;
148
  RawByteString = AnsiString;
149
  PPAnsiChar = ^PAnsiChar;
150
  {$IFDEF VER100} {For Delphi 3}
151
  longword = DWORD;
152
  pLongword = ^longword;
153
  my_ulonglong = record
154
   dwMyLow: DWORD;
155
   dwMyHigh: DWORD;
156
  end;
157
  {$ELSE}
158
  my_ulonglong = int64;
159
  {$ENDIF}
160
{$ENDIF}
161
162
// ----------------
163
// From mysql.h ...
164
// ----------------
165
166
  my_bool = ByteBool;
167
  Pmy_bool = ^my_bool;
168
  gptr = PAnsiChar;
169
170
type
171
  PUSED_MEM = ^TUSED_MEM;  // struct for once_alloc
172
  TUSED_MEM = record
173
    next: PUSED_MEM;       // Next block in use
174
    left: longword;        // memory left in block
175
    size: longword;        // size of block
176
  end;
177
178
// --------------------
179
// From my_alloc.h ...
180
// --------------------
181
182
type
183
  error_proc = procedure;
184
185
type
186
  TMEM_ROOT323 = record
187
    free: PUSED_MEM;
188
    used: PUSED_MEM;
189
    pre_alloc: PUSED_MEM;
190
    min_malloc: longword;
191
    block_size: longword;
192
    error_handler: error_proc;
193
  end;
194
  TMEM_ROOT400 = record
195
    free: PUSED_MEM;
196
    used: PUSED_MEM;
197
    pre_alloc: PUSED_MEM;
198
    min_malloc: longword;
199
    block_size: longword;
200
    block_num: longword;
201
    first_block_usage: longword;
202
    error_handler: error_proc;
203
  end;
204
205
type
206
  my_socket = TSocket;
207
208
// --------------------
209
// From mysql_com.h ...
210
// --------------------
211
212
const
213
  NAME_LEN = 64;               // Field/table name length
214
  HOSTNAME_LENGTH = 60;
215
  USERNAME_LENGTH = 16;
216
  SERVER_VERSION_LENGTH = 60;
217
  SQLSTATE_LENGTH = 5;
218
  SCRAMBLE_LENGTH = 20;
219
  SCRAMBLE_LENGTH_323 = 8;
220
221
222
  LOCAL_HOST = 'localhost';
223
  LOCAL_HOST_NAMEDPIPE = '.';
224
225
  MYSQL_NAMEDPIPE = 'MySQL';
226
  MYSQL_SERVICENAME = 'MySql';
227
228
type
229
  enum_server_command = (
230
    COM_SLEEP, COM_QUIT, COM_INIT_DB, COM_QUERY,
231
    COM_FIELD_LIST, COM_CREATE_DB, COM_DROP_DB, COM_REFRESH,
232
    COM_SHUTDOWN, COM_STATISTICS,
233
    COM_PROCESS_INFO, COM_CONNECT, COM_PROCESS_KILL,
234
    COM_DEBUG, COM_PING, COM_TIME, COM_DELAYED_INSERT,
235
    COM_CHANGE_USER, COM_BINLOG_DUMP,
236
    COM_TABLE_DUMP, COM_CONNECT_OUT
237
  );
238
239
const
240
  NOT_NULL_FLAG = 1;      // Field can't be NULL
241
  PRI_KEY_FLAG = 2;       // Field is part of a primary key
242
  UNIQUE_KEY_FLAG = 4;    // Field is part of a unique key
243
  MULTIPLE_KEY_FLAG = 8;  // Field is part of a key
244
  BLOB_FLAG = 16;         // Field is a blob
245
  UNSIGNED_FLAG = 32;     // Field is unsigned
246
  ZEROFILL_FLAG = 64;     // Field is zerofill
247
  BINARY_FLAG = 128;
248
249
  // The following are only sent to new clients
250
251
  ENUM_FLAG = 256;              // field is an enum
252
  AUTO_INCREMENT_FLAG = 512;    // field is a autoincrement field
253
  TIMESTAMP_FLAG = 1024;        // Field is a timestamp
254
  SET_FLAG = 2048;              // field is a set
255
  NUM_FLAG = 32768;             // Field is num (for clients)
256
  NO_DEFAULT_VALUE_FLAG = 4096;        // Field doesn't have default value
257
  PART_KEY_FLAG = 16384;        // Intern; Part of some key
258
  GROUP_FLAG = 32768;           // Intern: Group field
259
  UNIQUE_FLAG = 65536;          // Intern: Used by sql_yacc
260
  BINCMP_FLAG        = 131072;         // Intern: Used by sql_yacc
261
262
  REFRESH_GRANT = 1;     // Refresh grant tables
263
  REFRESH_LOG = 2;       // Start on new log file
264
  REFRESH_TABLES = 4;    // close all tables
265
  REFRESH_HOSTS = 8;     // Flush host cache
266
  REFRESH_STATUS = 16;   // Flush status variables
267
  REFRESH_THREADS = 32;  // Flush status variables
268
  REFRESH_SLAVE = 64;    // Reset master info and restart slave
269
                         // thread
270
  REFRESH_MASTER = 128;  // Remove all bin logs in the index
271
                         // and truncate the index
272
273
  // The following can't be set with mysql_refresh()
274
275
  REFRESH_READ_LOCK = 16384;  // Lock tables for read
276
  REFRESH_FAST = 32768;       // Intern flag
277
278
  // RESET (remove all queries) from query cache
279
  REFRESH_QUERY_CACHE        = 65536;
280
  REFRESH_QUERY_CACHE_FREE = $20000; // pack query cache
281
  REFRESH_DES_KEY_FILE = $40000;
282
  REFRESH_USER_RESOURCES = $80000;
283
284
  CLIENT_LONG_PASSWORD = 1;         // new more secure passwords
285
  CLIENT_FOUND_ROWS = 2;            // Found instead of affected rows
286
  CLIENT_LONG_FLAG = 4;             // Get all column flags
287
  CLIENT_CONNECT_WITH_DB = 8;       // One can specify db on connect
288
  CLIENT_NO_SCHEMA = 16;            // Don't allow database.table.column
289
  CLIENT_COMPRESS = 32;             // Can use compression protcol
290
  CLIENT_ODBC = 64;                 // Odbc client
291
  CLIENT_LOCAL_FILES = 128;         // Can use LOAD DATA LOCAL
292
  CLIENT_IGNORE_SPACE = 256;        // Ignore spaces before '('
293
  CLIENT_INTERACTIVE = 1024;        // This is an interactive client
294
  CLIENT_SSL = 2048;                // Switch to SSL after handshake
295
  CLIENT_IGNORE_SIGPIPE = 4096;     // IGNORE sigpipes
296
  CLIENT_TRANSACTIONS = 8192;       // Client knows about transactions
297
  CLIENT_RESERVED = 16384;          // Old flag for 4.1 protocol
298
  CLIENT_SECURE_CONNECTION = 32768; // New 4.1 authentication
299
  CLIENT_MULTI_STATEMENTS = 65536;  // Enable/disable multi-stmt support
300
  CLIENT_MULTI_RESULTS = $20000;    // Enable/disable multi-results
301
302
  CLIENT_SSL_VERIFY_SERVER_CERT = $40000000;
303
  CLIENT_REMEMBER_OPTIONS = $80000000;
304
305
  SERVER_STATUS_IN_TRANS = 1;     // Transaction has started
306
  SERVER_STATUS_AUTOCOMMIT = 2;   // Server in auto_commit mode
307
  SERVER_MORE_RESULTS_EXISTS = 8; // Multi query - next query exists
308
  SERVER_QUERY_NO_GOOD_INDEX_USED = 16;
309
  SERVER_QUERY_NO_INDEX_USED = 32;
310
  SERVER_STATUS_CURSOR_EXISTS = 64;
311
  SERVER_STATUS_LAST_ROW_SENT = 128;
312
  SERVER_STATUS_DB_DROPPED = 256;
313
  SERVER_STATUS_NO_BACKSLASH_ESCAPES = 512;
314
315
  MYSQL_ERRMSG_SIZE = 200;
316
  MYSQL_ERRMSG_SIZE401 = 512;
317
318
  NET_READ_TIMEOUT = 30;       // Timeout on read
319
  NET_WRITE_TIMEOUT = 60;      // Timeout on write
320
  NET_WAIT_TIMEOUT = 8*60*60;  // Wait for new query
321
322
type
323
  PVio = ^TVio;
324
  TVio = record
325
  end;
326
327
type
328
  PNET = Pointer;
329
  TNET323 = record
330
    vio: PVio;
331
    fd: my_socket;
332
    fcntl: longint;
333
    buff, buff_end, write_pos, read_pos: pByte;
334
    last_error: array [0..MYSQL_ERRMSG_SIZE - 1] of AnsiChar;
335
    last_errno, max_packet, timeout, pkt_nr: longword;                         // 228
336
    error: byte;
337
    return_errno, compress: my_bool;
338
    no_send_ok: my_bool;
339
      // needed if we are doing several
340
      // queries in one command ( as in LOAD TABLE ... FROM MASTER ),
341
      // and do not want to confuse the client with OK at the wrong time
342
    remain_in_buf, length, buf_length, where_b: longword;
343
    return_status: pLongword;
344
    reading_or_writing: byte;
345
    save_char: AnsiChar;
346
  end;
347
348
  TNET400 = record
349
    vio: PVio;
350
    buff, buff_end, write_pos, read_pos: pByte;
351
    fd: my_socket;
352
    max_packet, max_packet_size: longword;
353
    last_errno, pkt_nr, compress_pkt_nr: longword;
354
    write_timeout, read_timeout, retry_count: longword;
355
    fcntl: Integer;
356
    last_error: array [0..MYSQL_ERRMSG_SIZE - 1] of AnsiChar;
357
    error: byte;
358
    return_errno, compress: my_bool;
359
    remain_in_buf, length, buf_length, where_b: longword;
360
    return_status: pLongword;
361
    reading_or_writing: byte;
362
    save_char: AnsiChar;
363
    no_send_ok: my_bool;  // needed if we are doing several
364
    query_cache_query: gptr;
365
  end;
366
367
  TNET401 = record
368
    vio: PVio;
369
    buff, buff_end, write_pos, read_pos: pByte;
370
    fd: my_socket;
371
    max_packet, max_packet_size: longword;
372
    pkt_nr, compress_pkt_nr: longword;
373
    write_timeout, read_timeout, retry_count: longword;
374
    fcntl: Integer;
375
    compress: my_bool;
376
    remain_in_buf, length, buf_length, where_b: longword;
377
    return_status: pLongword;
378
    reading_or_writing: byte;
379
    save_char: AnsiChar;
380
    no_send_ok: my_bool;  // needed if we are doing several
381
    last_error: array [0..MYSQL_ERRMSG_SIZE401 - 1] of AnsiChar;
382
    sqlState: array [0..SQLSTATE_LENGTH] of AnsiChar;
383
    last_errno: longword;
384
    error: byte;
385
    query_cache_query: gptr;
386
    report_error: my_bool;   //* We should report error (we have unreported error) */
387
    return_errno: my_bool;
388
  end;
389
390
  TNET500 = record
391
    vio: PVio;
392
    buff, buff_end, write_pos, read_pos: pByte;
393
    fd: my_socket;
394
    max_packet, max_packet_size: longword;
395
    pkt_nr, compress_pkt_nr: longword;
396
    write_timeout, read_timeout, retry_count: longword;
397
    fcntl: Integer;
398
    compress: my_bool;
399
    remain_in_buf, length, buf_length, where_b: longword;
400
    return_status: pLongword;
401
    reading_or_writing: byte;
402
    save_char: AnsiChar;
403
    no_send_ok: my_bool;  //  For SPs and other things that do multiple stmts
404
    no_send_eof: my_bool;  // For SPs' first version read-only cursors
405
    no_send_error: my_bool;
406
    last_error: array [0..MYSQL_ERRMSG_SIZE401 - 1] of AnsiChar;
407
    sqlState: array [0..SQLSTATE_LENGTH] of AnsiChar;
408
    last_errno: longword;
409
    error: byte;
410
    query_cache_query: gptr;
411
    report_error: my_bool;   //* We should report error (we have unreported error) */
412
    return_errno: my_bool;
413
  end;
414
  TNET501 = record
415
    vio: PVio;
416
    buff, buff_end, write_pos, read_pos: pByte;
417
    fd: my_socket;
418
    remain_in_buf, length, buf_length, where_b: longword;
419
    max_packet, max_packet_size: longword;
420
    pkt_nr, compress_pkt_nr: longword;
421
    write_timeout, read_timeout, retry_count: longword;
422
    fcntl: Integer;
423
    return_status: Plongword;
424
    reading_or_writing: Byte;
425
    save_char: Char;
426
    unused0: my_bool; //* Please remove with the next incompatible ABI change. */
427
    unused: my_bool ; //* Please remove with the next incompatible ABI change */
428
    compress: my_bool;
429
    unused1: my_bool; //* Please remove with the next incompatible ABI change. */
430
    query_cache_query: gptr;
431
    last_errno: longword;
432
    error: byte;
433
    unused2: my_bool; //* Please remove with the next incompatible ABI change. */
434
    return_errno: my_bool;
435
    last_error: array [0..MYSQL_ERRMSG_SIZE401 - 1] of AnsiChar;
436
    sqlState: array [0..SQLSTATE_LENGTH] of AnsiChar;
437
    extension: Pointer;
438
  end;
439
440
const
441
  packet_error: longword = $ffffffff;
442
443
{$IFDEF CONDITIONALEXPRESSIONS} {Delphi 6 and above}
444
type
445
  enum_field_types = (MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY,
446
                      MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG,
447
                      MYSQL_TYPE_FLOAT, MYSQL_TYPE_DOUBLE,
448
                      MYSQL_TYPE_NULL, MYSQL_TYPE_TIMESTAMP,
449
                      MYSQL_TYPE_LONGLONG, MYSQL_TYPE_INT24,
450
                      MYSQL_TYPE_DATE, MYSQL_TYPE_TIME,
451
                      MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR,
452
                      MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR,
453
                      MYSQL_TYPE_BIT,
454
                      MYSQL_TYPE_NEWDECIMAL=246,
455
                      MYSQL_TYPE_ENUM=247,
456
                      MYSQL_TYPE_SET=248,
457
                      MYSQL_TYPE_TINY_BLOB=249,
458
                      MYSQL_TYPE_MEDIUM_BLOB=250,
459
                      MYSQL_TYPE_LONG_BLOB=251,
460
                      MYSQL_TYPE_BLOB=252,
461
                      MYSQL_TYPE_VAR_STRING=253,
462
                      MYSQL_TYPE_STRING=254,
463
                      MYSQL_TYPE_GEOMETRY=255);
464
465
const
466
  FIELD_TYPE_DECIMAL     = Ord(MYSQL_TYPE_DECIMAL);
467
  FIELD_TYPE_TINY        = Ord(MYSQL_TYPE_TINY);
468
  FIELD_TYPE_SHORT       = Ord(MYSQL_TYPE_DECIMAL);
469
  FIELD_TYPE_LONG        = Ord(MYSQL_TYPE_LONG);
470
  FIELD_TYPE_FLOAT       = Ord(MYSQL_TYPE_FLOAT);
471
  FIELD_TYPE_DOUBLE      = Ord(MYSQL_TYPE_DOUBLE);
472
  FIELD_TYPE_NULL        = Ord(MYSQL_TYPE_NULL);
473
  FIELD_TYPE_TIMESTAMP   = Ord(MYSQL_TYPE_TIMESTAMP);
474
  FIELD_TYPE_LONGLONG    = Ord(MYSQL_TYPE_LONGLONG);
475
  FIELD_TYPE_INT24       = Ord(MYSQL_TYPE_INT24);
476
  FIELD_TYPE_DATE        = Ord(MYSQL_TYPE_DATE);
477
  FIELD_TYPE_TIME        = Ord(MYSQL_TYPE_TIME);
478
  FIELD_TYPE_DATETIME    = Ord(MYSQL_TYPE_DATETIME);
479
  FIELD_TYPE_YEAR        = Ord(MYSQL_TYPE_YEAR);
480
  FIELD_TYPE_NEWDATE     = Ord(MYSQL_TYPE_NEWDATE);
481
  FIELD_TYPE_VARCHAR     = Ord(MYSQL_TYPE_VARCHAR);
482
  FIELD_TYPE_BIT         = Ord(MYSQL_TYPE_BIT);
483
  FIELD_TYPE_NEWDECIMAL  = Ord(MYSQL_TYPE_NEWDECIMAL);
484
  FIELD_TYPE_ENUM        = Ord(MYSQL_TYPE_ENUM);
485
  FIELD_TYPE_SET         = Ord(MYSQL_TYPE_SET);
486
  FIELD_TYPE_TINY_BLOB   = Ord(MYSQL_TYPE_TINY_BLOB);
487
  FIELD_TYPE_MEDIUM_BLOB = Ord(MYSQL_TYPE_BLOB);
488
  FIELD_TYPE_LONG_BLOB   = Ord(MYSQL_TYPE_VAR_STRING);
489
  FIELD_TYPE_BLOB        = Ord(MYSQL_TYPE_BLOB);
490
  FIELD_TYPE_VAR_STRING  = Ord(MYSQL_TYPE_VAR_STRING);
491
  FIELD_TYPE_STRING      = Ord(MYSQL_TYPE_STRING);
492
  FIELD_TYPE_GEOMETRY    = Ord(MYSQL_TYPE_GEOMETRY);
493
{$ELSE}
494
const
495
  FIELD_TYPE_DECIMAL      = 0;
496
  FIELD_TYPE_TINY         = 1;
497
  FIELD_TYPE_SHORT        = 2;
498
  FIELD_TYPE_LONG         = 3;
499
  FIELD_TYPE_FLOAT        = 4;
500
  FIELD_TYPE_DOUBLE       = 5;
501
  FIELD_TYPE_NULL         = 6;
502
  FIELD_TYPE_TIMESTAMP    = 7;
503
  FIELD_TYPE_LONGLONG     = 8;
504
  FIELD_TYPE_INT24        = 9;
505
  FIELD_TYPE_DATE         = 10;
506
  FIELD_TYPE_TIME         = 11;
507
  FIELD_TYPE_DATETIME     = 12;
508
  FIELD_TYPE_YEAR         = 13;
509
  FIELD_TYPE_NEWDATE      = 14;
510
  FIELD_TYPE_VARCHAR      = 15;
511
  FIELD_TYPE_BIT          = 16;
512
  FIELD_TYPE_NEWDECIMAL   = 246;
513
  FIELD_TYPE_ENUM         = 247;
514
  FIELD_TYPE_SET          = 248;
515
  FIELD_TYPE_TINY_BLOB    = 249;
516
  FIELD_TYPE_MEDIUM_BLOB  = 250;
517
  FIELD_TYPE_LONG_BLOB    = 251;
518
  FIELD_TYPE_BLOB         = 252;
519
  FIELD_TYPE_VAR_STRING   = 253;
520
  FIELD_TYPE_STRING       = 254;
521
  FIELD_TYPE_GEOMETRY     = 255;
522
  MYSQL_TYPE_DECIMAL      = FIELD_TYPE_DECIMAL;
523
  MYSQL_TYPE_TINY         = FIELD_TYPE_TINY;
524
  MYSQL_TYPE_SHORT        = FIELD_TYPE_SHORT;
525
  MYSQL_TYPE_LONG         = FIELD_TYPE_LONG;
526
  MYSQL_TYPE_FLOAT        = FIELD_TYPE_FLOAT;
527
  MYSQL_TYPE_DOUBLE       = FIELD_TYPE_DOUBLE;
528
  MYSQL_TYPE_NULL         = FIELD_TYPE_NULL;
529
  MYSQL_TYPE_TIMESTAMP    = FIELD_TYPE_TIMESTAMP;
530
  MYSQL_TYPE_LONGLONG     = FIELD_TYPE_LONGLONG;
531
  MYSQL_TYPE_INT24        = FIELD_TYPE_INT24;
532
  MYSQL_TYPE_DATE         = FIELD_TYPE_DATE;
533
  MYSQL_TYPE_TIME         = FIELD_TYPE_TIME;
534
  MYSQL_TYPE_DATETIME     = FIELD_TYPE_DATETIME;
535
  MYSQL_TYPE_YEAR         = FIELD_TYPE_YEAR;
536
  MYSQL_TYPE_NEWDATE      = FIELD_TYPE_NEWDATE;
537
  MYSQL_TYPE_VARCHAR      = FIELD_TYPE_VARCHAR;
538
  MYSQL_TYPE_BIT          = FIELD_TYPE_BIT;
539
  MYSQL_TYPE_NEWDECIMAL   = FIELD_TYPE_NEWDECIMAL;
540
  MYSQL_TYPE_ENUM         = FIELD_TYPE_ENUM;
541
  MYSQL_TYPE_SET          = FIELD_TYPE_SET;
542
  MYSQL_TYPE_TINY_BLOB    = FIELD_TYPE_TINY_BLOB;
543
  MYSQL_TYPE_MEDIUM_BLOB  = FIELD_TYPE_MEDIUM_BLOB;
544
  MYSQL_TYPE_LONG_BLOB    = FIELD_TYPE_LONG_BLOB;
545
  MYSQL_TYPE_BLOB         = FIELD_TYPE_BLOB;
546
  MYSQL_TYPE_VAR_STRING   = FIELD_TYPE_VAR_STRING;
547
  MYSQL_TYPE_STRING       = FIELD_TYPE_STRING;
548
  MYSQL_TYPE_GEOMETRY     = FIELD_TYPE_GEOMETRY;
549
550
type
551
  enum_field_types = FIELD_TYPE_DECIMAL..FIELD_TYPE_GEOMETRY;
552
{$ENDIF}
553
554
const
555
  FIELD_TYPE_CHAR        = FIELD_TYPE_TINY;  // For compability
556
  FIELD_TYPE_INTERVAL    = FIELD_TYPE_ENUM;  // For compability
557
558
// ------------------------
559
// From mysql_version.h ...
560
// ------------------------
561
562
const
563
  PROTOCOL_VERSION = 10;
564
  MYSQL_SERVER_SUFFIX = '';
565
  FRM_VER = 6;
566
  MYSQL_PORT = 3306;
567
568
// ----------------
569
// From mysql.h ...
570
// ----------------
571
572
function IS_PRI_KEY(n: longword): boolean;
573
function IS_AUTO_INC(n: longword): boolean;
574
function IS_NOT_NULL(n: longword): boolean;
575
function IS_BLOB(n: longword): boolean;
576
{.$IFDEF CONDITIONALEXPRESSIONS} {Delphi 6 and above}
577
function IS_NUM(t: enum_field_types): boolean;
578
function IS_LONGDATA(t: enum_field_types): boolean;
579
{ $ELSE
580
function IS_NUM(t: longword): boolean;
581
function IS_LONGDATA(t: longword): boolean;
582
 $ENDIF}
583
584
type
585
  TMYSQL_FIELD323 = record
586
    name: PAnsiChar;          // Name of column
587
    table: PAnsiChar;         // Table of column if column was a field
588
    def: PAnsiChar;           // Default value (set by mysql_list_fields)
589
    _type: enum_field_types;  // Type of field. Se mysql_com.h for types
590
    length: longword;         // Width of column
591
    max_length: longword;     // Max width of selected set
592
    flags: longword;          // Div flags
593
    decimals: longword;       // Number of decimals in field
594
  end;
595
  TMYSQL_FIELD400 = record
596
    name: PAnsiChar;          // Name of column
597
    table: PAnsiChar;         // Table of column if column was a field
598
    org_table: PAnsiChar;     // Org table name if table was an alias
599
    db: PAnsiChar;            // Database for table
600
    def: PAnsiChar;           // Default value (set by mysql_list_fields)
601
    length: longword;         // Width of column
602
    max_length: longword;     // Max width of selected set
603
    flags: longword;          // Div flags
604
    decimals: longword;       // Number of decimals in field
605
    _type: enum_field_types;  // Type of field. Se mysql_com.h for types
606
  end;
607
  TMYSQL_FIELD401 = record
608
    name: PAnsiChar;          // Name of column
609
    org_name: PAnsiChar;      // Original column name, if an alias
610
    table: PAnsiChar;         // Table of column if column was a field
611
    org_table: PAnsiChar;     // Org table name if table was an alias
612
    db: PAnsiChar;            // Database for table
613
    catalog: PAnsiChar;       // Catalog for table
614
    def: PAnsiChar;           // Default value (set by mysql_list_fields)
615
    length: longword;         // Width of column
616
    max_length: longword;     // Max width of selected set
617
    name_length: longword;
618
    org_name_length: longword;
619
    table_length: longword;
620
    org_table_length: longword;
621
    db_length: longword;
622
    catalog_length: longword;
623
    def_length: longword;
624
    flags: longword;          // Div flags
625
    decimals: longword;       // Number of decimals in field
626
    charsetnr: longword;      // Character set
627
    _type: enum_field_types;  // Type of field. Se mysql_com.h for types
628
  end;
629
  TMYSQL_FIELD501 = record
630
    name: PAnsiChar;          // Name of column
631
    org_name: PAnsiChar;      // Original column name, if an alias
632
    table: PAnsiChar;         // Table of column if column was a field
633
    org_table: PAnsiChar;     // Org table name if table was an alias
634
    db: PAnsiChar;            // Database for table
635
    catalog: PAnsiChar;       // Catalog for table
636
    def: PAnsiChar;           // Default value (set by mysql_list_fields)
637
    length: longword;         // Width of column
638
    max_length: longword;     // Max width of selected set
639
    name_length: longword;
640
    org_name_length: longword;
641
    table_length: longword;
642
    org_table_length: longword;
643
    db_length: longword;
644
    catalog_length: longword;
645
    def_length: longword;
646
    flags: longword;          // Div flags
647
    decimals: longword;       // Number of decimals in field
648
    charsetnr: longword;      // Character set
649
    _type: enum_field_types;  // Type of field. Se mysql_com.h for types
650
    extension: Pointer;
651
  end;
652
  TMYSQL_FIELD = TMYSQL_FIELD401;
653
  PMYSQL_FIELD = Pointer;
654
655
{$IFDEF CONDITIONALEXPRESSIONS}
656
   {$IF SizeOf(TMYSQL_FIELD323)<>32}
657
   {$Message Fatal 'Wrong size of TMYSQL_FIELD323'}
658
   {$IFEND}
659
   {$IF SizeOf(TMYSQL_FIELD400)<>40}
660
   {$Message Fatal 'Wrong size of TMYSQL_FIELD400'}
661
   {$IFEND}
662
   {$IF SizeOf(TMYSQL_FIELD401)<>80}
663
   {$Message Fatal 'Wrong size of TMYSQL_FIELD401'}
664
   {$IFEND}
665
   {$IF SizeOf(TMYSQL_FIELD501)<>84}
666
   {$Message Fatal 'Wrong size of TMYSQL_FIELD501'}
667
   {$IFEND}
668
{$ENDIF}
669
670
function IS_NUM_FLAG(n: longword): boolean;
671
function INTERNAL_NUM_FIELD(f: PMYSQL_FIELD): boolean;
672
673
{ Copy the content of a unspecific field to a well defined field record }
674
function UpdateField(f: PMYSQL_FIELD): TMYSQL_FIELD;
675
676
{ Get fieldtype of the field }
677
function mysql_field_type(f: PMYSQL_FIELD): enum_field_types;
678
679
{ Get fieldflags of the field }
680
function mysql_field_flag(f: PMYSQL_FIELD): longword;
681
682
{ Get Length of the field }
683
function mysql_field_length(f: PMYSQL_FIELD): longword;
684
685
{ Get the name of the field }
686
function mysql_field_name(f: PMYSQL_FIELD): PAnsiChar;
687
688
{ Get the corresponding tablename of the field }
689
function mysql_field_tablename(f: PMYSQL_FIELD): PAnsiChar;
690
691
type
692
  PMYSQL_ROW = ^TMYSQL_ROW;   // return data as array of strings
693
  TMYSQL_ROW = array[0..MaxInt div SizeOf(PAnsiChar) - 1] of PAnsiChar;
694
695
type
696
  MYSQL_FIELD_OFFSET = longword;  // offset to current field
697
698
const
699
  MYSQL_COUNT_ERROR: my_ulonglong = my_ulonglong(not 0);
700
701
type
702
  PMYSQL_ROWS = ^TMYSQL_ROWS;
703
  TMYSQL_ROWS = record
704
    next: PMYSQL_ROWS;        // list of rows
705
    data: PMYSQL_ROW;
706
  end;
707
708
type
709
  MYSQL_ROW_OFFSET = PMYSQL_ROWS;  // offset to current row
710
711
type
712
  PMYSQL_DATA323 = ^TMYSQL_DATA323;
713
  TMYSQL_DATA323 = record
714
    rows: my_ulonglong;
715
    fields: longword;
716
    data: PMYSQL_ROWS;
717
    alloc: TMEM_ROOT323;
718
  end;
719
  PMYSQL_DATA400 = ^TMYSQL_DATA400;
720
  TMYSQL_DATA400 = record
721
    rows: my_ulonglong;
722
    fields: longword;
723
    data: PMYSQL_ROWS;
724
    alloc: TMEM_ROOT400;
725
  end;
726
727
type
728
  mysql_option = (
729
  MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
730
  MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
731
  MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME, MYSQL_OPT_LOCAL_INFILE,
732
  MYSQL_OPT_PROTOCOL, MYSQL_SHARED_MEMORY_BASE_NAME, MYSQL_OPT_READ_TIMEOUT,
733
  MYSQL_OPT_WRITE_TIMEOUT, MYSQL_OPT_USE_RESULT,
734
  MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION,
735
  MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH,
736
  MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT,
737
  MYSQL_OPT_SSL_VERIFY_SERVER_CERT
738
  );
739
740
type
741
  enum_mysql_set_option = (MYSQL_OPTION_MULTI_STATEMENTS_ON, MYSQL_OPTION_MULTI_STATEMENTS_OFF);
742
743
type
744
  PMYSQL_OPTIONS = Pointer;
745
  TMYSQL_OPTIONS323 = record
746
    connect_timeout, client_flag: longword;
747
    compress, named_pipe: my_bool;
748
    port: longword;
749
    host, init_command, user, password, unix_socket, db: PAnsiChar;
750
    my_cnf_file, my_cnf_group, charset_dir, charset_name: PAnsiChar;
751
    use_ssl: my_bool;       // if to use SSL or not
752
    ssl_key: PAnsiChar;     // PEM key file
753
    ssl_cert: PAnsiChar;    // PEM cert file
754
    ssl_ca: PAnsiChar;      // PEM CA file
755
    ssl_capath: PAnsiChar;  // PEM directory of CA-s?
756
  end;
757
  TMYSQL_OPTIONS400 = record
758
    connect_timeout, client_flag: longword;
759
    port: longword;
760
    host, init_command, user, password, unix_socket, db: PAnsiChar;
761
    my_cnf_file, my_cnf_group, charset_dir, charset_name: PAnsiChar;
762
    ssl_key: PAnsiChar;     // PEM key file
763
    ssl_cert: PAnsiChar;    // PEM cert file
764
    ssl_ca: PAnsiChar;      // PEM CA file
765
    ssl_capath: PAnsiChar;  // PEM directory of CA-s?
766
    ssl_cipher: PAnsiChar;  // cipher to use
767
    max_allowed_packet: longword;
768
    use_ssl: my_bool;       // if to use SSL or not
769
    compress, named_pipe: my_bool;
770
    rpl_probe: my_bool;
771
    rpl_parse: my_bool;
772
    no_master_reads: my_bool;
773
  end;
774
  TMYSQL_OPTIONS401 = record
775
    connect_timeout, read_timeout, write_timeout: longword;
776
    port, protocol: longword;
777
    client_flag: longword;
778
    host, user, password, unix_socket, db: PAnsiChar;
779
    init_commands: PAnsiChar;
780
    my_cnf_file, my_cnf_group, charset_dir, charset_name: PAnsiChar;
781
    ssl_key: PAnsiChar;     // PEM key file
782
    ssl_cert: PAnsiChar;    // PEM cert file
783
    ssl_ca: PAnsiChar;      // PEM CA file
784
    ssl_capath: PAnsiChar;  // PEM directory of CA-s?
785
    ssl_cipher: PAnsiChar;  // cipher to use
786
    shared_memory_base_name: PAnsiChar;
787
    max_allowed_packet: longword;
788
    use_ssl: my_bool;       // if to use SSL or not
789
    compress, named_pipe: my_bool;
790
    rpl_probe: my_bool;
791
    rpl_parse: my_bool;
792
    no_master_reads: my_bool;
793
//    separate_thread: my_bool;
794
    methods_to_use: mysql_option;
795
    client_ip: PAnsiChar;
796
    secure_auth: my_bool;
797
    // function pointers for local infile support
798
    local_infile_init: Pointer;
799
    local_infile_read: Pointer;
800
    local_infile_end: Pointer;
801
    local_infile_error: Pointer;
802
    local_infile_userdata: Pointer;
803
  end;
804
805
  TMYSQL_OPTIONS500 = record
806
    connect_timeout, read_timeout, write_timeout: longword;
807
    port, protocol: longword;
808
    client_flag: longword;
809
    host, user, password, unix_socket, db: PAnsiChar;
810
    init_commands: PAnsiChar;
811
    my_cnf_file, my_cnf_group, charset_dir, charset_name: PAnsiChar;
812
    ssl_key: PAnsiChar;     // PEM key file
813
    ssl_cert: PAnsiChar;    // PEM cert file
814
    ssl_ca: PAnsiChar;      // PEM CA file
815
    ssl_capath: PAnsiChar;  // PEM directory of CA-s?
816
    ssl_cipher: PAnsiChar;  // cipher to use
817
    shared_memory_base_name: PAnsiChar;
818
    max_allowed_packet: longword;
819
    use_ssl: my_bool;       // if to use SSL or not
820
    compress, named_pipe: my_bool;
821
    rpl_probe: my_bool;
822
    rpl_parse: my_bool;
823
    no_master_reads: my_bool;
824
//    separate_thread: my_bool;
825
    methods_to_use: mysql_option;
826
    client_ip: PAnsiChar;
827
    secure_auth: my_bool;
828
    report_data_truncation: my_bool;
829
    // function pointers for local infile support
830
    local_infile_init: Pointer;
831
    local_infile_read: Pointer;
832
    local_infile_end: Pointer;
833
    local_infile_error: Pointer;
834
    local_infile_userdata: Pointer;
835
  end;
836
837
type
838
  mysql_status = (MYSQL_STATUS_READY, MYSQL_STATUS_GET_RESULT, MYSQL_STATUS_USE_RESULT);
839
840
type
841
  PMYSQL_FIELDS=Pointer;
842
843
type
844
  PCHARSET_INFO = ^TCHARSET_INFO;
845
  TCHARSET_INFO = record
846
    // Omitted: Structure not necessarily needed.
847
    // Definition of struct charset_info_st can be
848
    // found in include/m_ctype.h
849
  end;
850
851
type
852
  PMYSQL = Pointer;
853
  TMYSQL323 = record
854
    net: TNET323;                 // Communication parameters
855
    connector_fd: gptr;           // ConnectorFd for SSL
856
    host, user, passwd, unix_socket, server_version, host_info, info, db: PAnsiChar;     //  260, 264, 268, 272, 276, 280, 284
857
    port, client_flag, server_capabilities: longword;
858
    protocol_version: longword;
859
    field_count: longword;
860
    server_status: longword;
861
    thread_id: longword;          // Id for connection in server
862
    affected_rows: my_ulonglong;
863
    insert_id: my_ulonglong;      // id if insert on table with NEXTNR
864
    extra_info: my_ulonglong;     // Used by mysqlshow
865
    packet_length: longword;
866
    status: longword;             //seems to be a longword
867
//    status: mysql_status;
868
    fields: PMYSQL_FIELDS;
869
    field_alloc: TMEM_ROOT323;
870
    free_me: my_bool;             // If free in mysql_close
871
    reconnect: my_bool;           // set to 1 if automatic reconnect
872
    options: TMYSQL_OPTIONS323;
873
    scramble_buff: array [0..SCRAMBLE_LENGTH_323] of AnsiChar;
874
    charset: PCHARSET_INFO;
875
    server_language: longword;
876
  end;
877
878
  TMYSQL400 = record
879
    net: TNET400;                 // Communication parameters
880
    connector_fd: gptr;           // ConnectorFd for SSL
881
    host, user, passwd, unix_socket, server_version, host_info, info, db: PAnsiChar;     //  260, 264, 268, 272, 276, 280, 284
882
    charset: PCHARSET_INFO;
883
    fields: PMYSQL_FIELDS;
884
    field_alloc: TMEM_ROOT400;
885
    affected_rows: my_ulonglong;
886
    insert_id: my_ulonglong;      // id if insert on table with NEXTNR
887
    extra_info: my_ulonglong;     // Used by mysqlshow
888
    thread_id: longword;          // Id for connection in server
889
    packet_length: longword;
890
    port, client_flag, server_capabilities: longword;
891
    protocol_version: longword;
892
    field_count: longword;
893
    server_status: longword;
894
    server_language: longword;
895
    options: TMYSQL_OPTIONS400;
896
    status: longword;             //seems to be a longword
897
//    status: mysql_status;
898
    free_me: my_bool;             // If free in mysql_close
899
    reconnect: my_bool;           // set to 1 if automatic reconnect
900
    scramble_buff: array [0..SCRAMBLE_LENGTH_323] of AnsiChar;
901
    rpl_pivot: my_bool;
902
    master, next_slave: PMYSQL;
903
    last_used_slave: PMYSQL; //* needed for round-robin slave pick */
904
    //* needed for send/read/store/use result to work correctly with replication */
905
    last_used_con: PMYSQL;
906
  end;
907
  TMYSQL401 = record
908
    net: TNET401;                 // Communication parameters
909
    connector_fd: gptr;           // ConnectorFd for SSL
910
    host, user, passwd, unix_socket, server_version, host_info, info, db: PAnsiChar;     //  260, 264, 268, 272, 276, 280, 284
911
    charset: PCHARSET_INFO;
912
    fields: PMYSQL_FIELDS;
913
    field_alloc: TMEM_ROOT400;
914
    affected_rows: my_ulonglong;
915
    insert_id: my_ulonglong;      // id if insert on table with NEXTNR
916
    extra_info: my_ulonglong;     // Used by mysqlshow
917
    thread_id: longword;          // Id for connection in server
918
    packet_length: longword;
919
    port, client_flag, server_capabilities: longword;
920
    protocol_version: longword;
921
    field_count: longword;
922
    server_status: longword;
923
    server_language: longword;
924
    warning_count: longword;
925
    options: TMYSQL_OPTIONS401;
926
    status: mysql_status;
927
    free_me: my_bool;             // If free in mysql_close
928
    reconnect: my_bool;           // set to 1 if automatic reconnect
929
    scramble_buff: array [0..SCRAMBLE_LENGTH] of AnsiChar;
930
    rpl_pivot: my_bool;
931
    master, next_slave: PMYSQL;
932
    last_used_slave: PMYSQL;      //* needed for round-robin slave pick */
933
    //* needed for send/read/store/use result to work correctly with replication */
934
    last_used_con: PMYSQL;
935
    stmts: Pointer;               // list of all statements
936
    methods: Pointer;
937
    thd: Pointer;
938
    unbuffered_fetch_owner: Pmy_bool;
939
    current_stmt: Pointer;
940
  end;
941
  TMYSQL500 = record
942
    net: TNET500;                 // Communication parameters
943
    connector_fd: gptr;           // ConnectorFd for SSL
944
    host, user, passwd, unix_socket, server_version, host_info, info, db: PAnsiChar;
945
    charset: PCHARSET_INFO;
946
    fields: PMYSQL_FIELDS;
947
    field_alloc: TMEM_ROOT400;
948
    affected_rows: my_ulonglong;
949
    insert_id: my_ulonglong;      // id if insert on table with NEXTNR
950
    extra_info: my_ulonglong;     // Used by mysqlshow
951
    thread_id: longword;          // Id for connection in server
952
    packet_length: longword;
953
    port, client_flag, server_capabilities: longword;
954
    protocol_version: longword;
955
    field_count: longword;
956
    server_status: longword;
957
    server_language: longword;
958
    warning_count: longword;
959
    options: TMYSQL_OPTIONS500;
960
    status: mysql_status;
961
    free_me: my_bool;             // If free in mysql_close
962
    reconnect: my_bool;           // set to 1 if automatic reconnect
963
    scramble_buff: array [0..SCRAMBLE_LENGTH] of AnsiChar;
964
    rpl_pivot: my_bool;
965
    master, next_slave: PMYSQL;
966
    last_used_slave: PMYSQL;      //* needed for round-robin slave pick */
967
    //* needed for send/read/store/use result to work correctly with replication */
968
    last_used_con: PMYSQL;
969
    stmts: Pointer;               // list of all statements
970
    methods: Pointer;
971
    thd: Pointer;
972
    unbuffered_fetch_owner: Pmy_bool;
973
    info_buffer: Pointer;         // some info for embedded server
974
  end;
975
  TMYSQL501 = record
976
    net: TNET501;                 // Communication parameters
977
    connector_fd: gptr;           // ConnectorFd for SSL
978
    host, user, passwd, unix_socket, server_version, host_info, info, db: PAnsiChar;
979
    charset: PCHARSET_INFO;
980
    fields: PMYSQL_FIELDS;
981
    field_alloc: TMEM_ROOT400;
982
    affected_rows: my_ulonglong;
983
    insert_id: my_ulonglong;      // id if insert on table with NEXTNR
984
    extra_info: my_ulonglong;     // Used by mysqlshow
985
    thread_id: longword;          // Id for connection in server
986
    packet_length: longword;
987
    port, client_flag, server_capabilities: longword;
988
    protocol_version: longword;
989
    field_count: longword;
990
    server_status: longword;
991
    server_language: longword;
992
    warning_count: longword;
993
    options: TMYSQL_OPTIONS500;
994
    status: mysql_status;
995
    free_me: my_bool;             // If free in mysql_close
996
    reconnect: my_bool;           // set to 1 if automatic reconnect
997
    scramble_buff: array [0..SCRAMBLE_LENGTH] of AnsiChar;
998
    rpl_pivot: my_bool;
999
    master, next_slave: PMYSQL;
1000
    last_used_slave: PMYSQL;      //* needed for round-robin slave pick */
1001
    //* needed for send/read/store/use result to work correctly with replication */
1002
    last_used_con: PMYSQL;
1003
    stmts: Pointer;               // list of all statements
1004
    methods: Pointer;
1005
    thd: Pointer;
1006
    unbuffered_fetch_owner: Pmy_bool;
1007
    info_buffer: Pointer;         // some info for embedded server
1008
    extension: Pointer;
1009
  end;
1010
1011
type
1012
  PMYSQL_RES = Pointer;
1013
  TMYSQL_RES323 = record
1014
    row_count: my_ulonglong;
1015
    field_count, current_field: longword;
1016
    fields: PMYSQL_FIELDS;
1017
    data: PMYSQL_DATA323;
1018
    data_cursor: PMYSQL_ROWS;
1019
    field_alloc: TMEM_ROOT323;
1020
    row: PMYSQL_ROW;              // If unbuffered read
1021
    current_row: PMYSQL_ROW;      // buffer to current row
1022
    lengths: pLongword;           // column lengths of current row
1023
    handle: PMYSQL;               // for unbuffered reads
1024
    eof: my_bool;                 // Used my mysql_fetch_row
1025
  end;
1026
  TMYSQL_RES400 = record
1027
    row_count: my_ulonglong;
1028
    field_count, current_field: longword;
1029
    fields: PMYSQL_FIELDS;
1030
    data: PMYSQL_DATA400;
1031
    data_cursor: PMYSQL_ROWS;
1032
    field_alloc: TMEM_ROOT400;
1033
    row: PMYSQL_ROW;              // If unbuffered read
1034
    current_row: PMYSQL_ROW;      // buffer to current row
1035
    lengths: pLongword;           // column lengths of current row
1036
    handle: PMYSQL;               // for unbuffered reads
1037
    eof: my_bool;                 // Used my mysql_fetch_row
1038
  end;
1039
  TMYSQL_RES401 = record
1040
    row_count: my_ulonglong;
1041
    field_count, current_field: longword;
1042
    fields: PMYSQL_FIELDS;
1043
    data: PMYSQL_DATA400;
1044
    data_cursor: PMYSQL_ROWS;
1045
    field_alloc: TMEM_ROOT400;
1046
    row: PMYSQL_ROW;              // If unbuffered read
1047
    current_row: PMYSQL_ROW;      // buffer to current row
1048
    lengths: pLongword;           // column lengths of current row
1049
    handle: PMYSQL;               // for unbuffered reads
1050
    eof: my_bool;                 // Used my mysql_fetch_row
1051
    unbuffered_fetch_cancelled: my_bool;
1052
    st_mysql_methods: Pointer;
1053
  end;
1054
1055
// Functions to get information from the MYSQL and MYSQL_RES structures
1056
// Should definitely be used if one uses shared libraries
1057
1058
  function mysql_num_rows(res: PMYSQL_RES): my_ulonglong; stdcall;
1059
  function mysql_num_fields(res: PMYSQL_RES): longword; stdcall;
1060
  function mysql_eof(res: PMYSQL_RES): my_bool; stdcall;
1061
  function mysql_fetch_field_direct(res: PMYSQL_RES; fieldnr: longword): PMYSQL_FIELD; stdcall;
1062
  function mysql_fetch_fields(res: PMYSQL_RES): PMYSQL_FIELDS; stdcall;
1063
  function mysql_row_tell(res: PMYSQL_RES): MYSQL_ROW_OFFSET; stdcall;
1064
  function mysql_field_tell(res: PMYSQL_RES): longword; stdcall;
1065
1066
  function mysql_field_count(_mysql: PMYSQL): longword; stdcall;
1067
  function mysql_affected_rows(_mysql: PMYSQL): my_ulonglong; stdcall;
1068
  function mysql_insert_id(_mysql: PMYSQL): my_ulonglong; stdcall;
1069
  function mysql_errno(_mysql: PMYSQL): longword; stdcall;
1070
  function mysql_error(_mysql: PMYSQL): PAnsiChar; stdcall;
1071
  function mysql_info(_mysql: PMYSQL): PAnsiChar; stdcall;
1072
  function mysql_thread_id(_mysql: PMYSQL): longword; stdcall;
1073
  function mysql_character_set_name(_mysql: PMYSQL): PAnsiChar; stdcall; //since Client 3.23.21
1074
1075
type
1076
  PMYSQL_LENGTHS = ^TMYSQL_LENGTHS;
1077
  TMYSQL_LENGTHS = array[0..MaxInt div SizeOf(longword) - 1] of longword;
1078
1079
type
1080
  extend_buffer_func = function(void: pointer; _to: PAnsiChar; length: pLongword): PAnsiChar;
1081
1082
  function mysql_init(_mysql: PMYSQL): PMYSQL; stdcall;
1083
  function mysql_ssl_set(_mysql: PMYSQL; key, cert, ca, capath: PAnsiChar): longint; stdcall;
1084
  function mysql_ssl_cipher(_mysql: PMYSQL): PAnsiChar; stdcall;
1085
  function mysql_ssl_clear(_mysql: PMYSQL): longint; stdcall;
1086
  function mysql_connect(_mysql: PMYSQL; host, user, passwd: PAnsiChar): PMYSQL; stdcall;
1087
  function mysql_change_user(_mysql: PMYSQL; user, passwd, db: PAnsiChar): my_bool; stdcall;
1088
  function mysql_real_connect(_mysql: PMYSQL; host, user, passwd, db: PAnsiChar; port: longword; unix_socket: PAnsiChar; clientflag: longword): PMYSQL; stdcall;
1089
  procedure mysql_close(sock: PMYSQL); stdcall;
1090
  function mysql_select_db(_mysql: PMYSQL; db: PAnsiChar): longint; stdcall;
1091
  function mysql_query(_mysql: PMYSQL; q: PAnsiChar): longint; stdcall;
1092
  function mysql_send_query(_mysql: PMYSQL; q: PAnsiChar; length: longword): longint; stdcall;
1093
  function mysql_read_query_result(_mysql: PMYSQL): longint; stdcall;
1094
  function mysql_real_query(_mysql: PMYSQL; q: PAnsiChar; length: longword): longint; stdcall;
1095
  function mysql_create_db(_mysql: PMYSQL; DB: PAnsiChar): longint; stdcall;
1096
  function mysql_drop_db(_mysql: PMYSQL; DB: PAnsiChar): longint; stdcall;
1097
  function mysql_shutdown(_mysql: PMYSQL): longint; stdcall;
1098
  function mysql_dump_debug_info(_mysql: PMYSQL): longint; stdcall;
1099
  function mysql_refresh(_mysql: PMYSQL; refresh_options: longword): longint; stdcall;
1100
  function mysql_kill(_mysql: PMYSQL; pid: longword): longint; stdcall;
1101
  function mysql_ping(_mysql: PMYSQL): longint; stdcall;
1102
  function mysql_stat(_mysql: PMYSQL): PAnsiChar; stdcall;
1103
  function mysql_get_server_info(_mysql: PMYSQL): PAnsiChar; stdcall;
1104
  function mysql_get_client_info: PAnsiChar; stdcall;
1105
  function mysql_get_host_info(_mysql: PMYSQL): PAnsiChar; stdcall;
1106
  function mysql_get_proto_info(_mysql: PMYSQL): longword; stdcall;
1107
  function mysql_list_dbs(_mysql: PMYSQL; wild: PAnsiChar): PMYSQL_RES; stdcall;
1108
  function mysql_list_tables(_mysql: PMYSQL; wild: PAnsiChar): PMYSQL_RES; stdcall;
1109
  function mysql_list_fields(_mysql: PMYSQL; table, wild: PAnsiChar): PMYSQL_RES; stdcall;
1110
  function mysql_list_processes(_mysql: PMYSQL): PMYSQL_RES; stdcall;
1111
  function mysql_store_result(_mysql: PMYSQL): PMYSQL_RES; stdcall;
1112
  function mysql_use_result(_mysql: PMYSQL): PMYSQL_RES; stdcall;
1113
  function mysql_more_results(_mysql: PMYSQL): my_bool; stdcall;
1114
  function mysql_next_result(_mysql: PMYSQL): longint; stdcall;
1115
  function mysql_options(_mysql: PMYSQL; option: mysql_option; arg: Pointer): longint; stdcall;
1116
  procedure mysql_free_result(_mysql_res: PMYSQL_RES); stdcall;
1117
  procedure mysql_data_seek(_mysql_res: PMYSQL_RES; offset: my_ulonglong); stdcall;
1118
  function mysql_row_seek(_mysql_res: PMYSQL_RES; offset: MYSQL_ROW_OFFSET): MYSQL_ROW_OFFSET; stdcall;
1119
  function mysql_field_seek(_mysql_res: PMYSQL_RES; offset: MYSQL_FIELD_OFFSET): MYSQL_FIELD_OFFSET; stdcall;
1120
  function mysql_fetch_row(_mysql_res: PMYSQL_RES): PMYSQL_ROW; stdcall;
1121
  function mysql_fetch_lengths(_mysql_res: PMYSQL_RES): PMYSQL_LENGTHS; stdcall;
1122
  function mysql_fetch_field(_mysql_res: PMYSQL_RES): PMYSQL_FIELD; stdcall;
1123
  //mysql_escape_string using Latin1 character set
1124
  function mysql_escape_string(_to: PAnsiChar; from: PAnsiChar; from_length: longword): longword; stdcall;
1125
  //mysql_escape_string using the character set of the established connection
1126
  function mysql_real_escape_string(_mysql: PMYSQL; _to: PAnsiChar; from: PAnsiChar; length: longword): longword; stdcall;
1127
  procedure mysql_debug(debug: PAnsiChar); stdcall;
1128
  function mysql_odbc_escape_string(_mysql: PMYSQL; _to: PAnsiChar; to_length: longword; from: PAnsiChar; from_length: longword; param: pointer; extend_buffer: extend_buffer_func): PAnsiChar; stdcall;
1129
  procedure myodbc_remove_escape(_mysql: PMYSQL; name: PAnsiChar); stdcall;
1130
  function mysql_thread_safe: longword; stdcall;
1131
  function mysql_get_client_version: longword stdcall;
1132
  function mysql_get_server_version(_mysql: PMYSQL): longword; stdcall;
1133
  function mysql_set_character_set(_mysql: PMYSQL; csname: PAnsiChar): longint; stdcall;
1134
  function mysql_autocommit(_mysql: PMYSQL; mode: my_bool ): my_bool; stdcall;
1135
  function mysql_commit(_mysql: PMYSQL): my_bool; stdcall;
1136
  function mysql_rollback(_mysql: PMYSQL): my_bool; stdcall;
1137
  function mysql_set_server_option(_mysql: PMYSQL; option: enum_mysql_set_option): longint; stdcall;
1138
  function mysql_sqlstate(_mysql: PMYSQL): PAnsiChar; stdcall;
1139
  function mysql_warning_count(_mysql: PMYSQL): longword; stdcall;
1140
  function mysql_server_init(argc: Integer; argv, groups: PPAnsiChar): Integer; stdcall;
1141
  procedure mysql_server_end; stdcall;
1142
{ "Jeremiah Gowdy" <jgowdycox.net> wrote on 10/11/2005 03:08:40 AM:
1143
  The Windows DLL is thread safe. You do not have to call my_init()
1144
  and my_thread_init() because Windows DLLs receive events when they
1145
  are attached to a new process and when they are attached to a new
1146
  thread in a process. This is one of the nicer features of Windows
1147
  shared libraries. Other than that, you don't have to do anything
1148
  special. I am a heavy user of libmysql under Win32. You simply
1149
  mysql_init() your MYSQL struct, and then mysql_real_connect() and
1150
  you're ready to mysql_query().}
1151
  function mysql_thread_init: my_bool; stdcall; //called internal by mysql_init or mysql_server_init
1152
  procedure mysql_thread_end; stdcall;
1153
1154
  function mysql_reload(_mysql: PMySQL): longint;
1155
  function mysql_fetch_db(_mysql: PMYSQL): PAnsiChar;
1156
1157
1158
// -----------------------------------------------------------------------------------------------
1159
// Prepared statements support
1160
// -----------------------------------------------------------------------------------------------
1161
1162
type
1163
  PMYSQL_STMT=Pointer;
1164
  enum_stmt_attr_type=(
1165
  {*
1166
    When doing mysql_stmt_store_result calculate max_length attribute
1167
    of statement metadata. This is to be consistent with the old API,
1168
    where this was done automatically.
1169
    In the new API we do that only by request because it slows down
1170
    mysql_stmt_store_result sufficiently.
1171
  *}
1172
  STMT_ATTR_UPDATE_MAX_LENGTH,
1173
  {*
1174
    unsigned long with combination of cursor flags (read only, for update,
1175
    etc)
1176
  *}
1177
  STMT_ATTR_CURSOR_TYPE,
1178
  {*
1179
    Amount of rows to retrieve from server per one fetch if using cursors.
1180
    Accepts unsigned long attribute in the range 1 - ulong_max
1181
  *}
1182
  STMT_ATTR_PREFETCH_ROWS);
1183
1184
  TMYSQL_BIND401 = record    // Version>=40100
1185
    length: PDWORD;          // output length pointer
1186
    is_null: Pmy_bool;       // Pointer to null indicator
1187
    buffer: Pointer;         // buffer to get/put data
1188
    buffer_type: enum_field_types;
1189
    buffer_length: DWORD;    // buffer length, must be set for string/binary
1190
    row_ptr: PAnsiChar;      // for the current data position
1191
    offset: DWORD;           // offset position for char/binary fetch
1192
    length_value: DWORD;     // Used if length is nil
1193
    param_number: DWORD;     // For null count and error messages
1194
    pack_length: DWORD;      // Internal length for packed data
1195
    is_unsigned: my_bool;    // set if integer type is unsigned
1196
    long_data_used: my_bool; // If used with mysql_send_long_data
1197
    is_null_value: my_bool;  // Used if is_null is nil
1198
    store_param_func: FARPROC;
1199
    fetch_result: FARPROC;
1200
    skip_result: FARPROC;
1201
  end;
1202
  PMYSQL_BIND401=^TMYSQL_BIND401;
1203
1204
  TMYSQL_BIND500 = record    // Version>=50000
1205
    length: PDWORD;          // output length pointer
1206
    is_null: Pmy_bool;       // Pointer to null indicator
1207
    buffer: Pointer;         // buffer to get/put data
1208
//  set this if you want to track data truncations happened during fetch
1209
    error: Pmy_bool;
1210
    buffer_type: enum_field_types;
1211
    buffer_length: DWORD;    // buffer length, must be set for string/binary
1212
    row_ptr: PAnsiChar;      // for the current data position
1213
    offset: DWORD;           // offset position for char/binary fetch
1214
    length_value: DWORD;     // Used if length is nil
1215
    param_number: DWORD;     // For null count and error messages
1216
    pack_length: DWORD;      // Internal length for packed data
1217
    error_value: my_bool;    // used if error is nil
1218
    is_unsigned: my_bool;    // set if integer type is unsigned
1219
    long_data_used: my_bool; // If used with mysql_send_long_data
1220
    is_null_value: my_bool;  // Used if is_null is nil
1221
    store_param_func: FARPROC;
1222
    fetch_result: FARPROC;
1223
    skip_result: FARPROC;
1224
  end;
1225
  PMYSQL_BIND500=^TMYSQL_BIND500;
1226
1227
  TMYSQL_BIND501 = record    // Version>=50100
1228
    length: PDWORD;          // output length pointer
1229
    is_null: Pmy_bool;       // Pointer to null indicator
1230
    buffer: Pointer;         // buffer to get/put data
1231
//  set this if you want to track data truncations happened during fetch
1232
    error: Pmy_bool;
1233
    row_ptr: PAnsiChar;      // for the current data position
1234
    store_param_func: FARPROC;
1235
    fetch_result: FARPROC;
1236
    skip_result: FARPROC;
1237
    buffer_length: DWORD;    // buffer length, must be set for string/binary
1238
    offset: DWORD;           // offset position for char/binary fetch
1239
    length_value: DWORD;     // Used if length is nil
1240
    param_number: DWORD;     // For null count and error messages
1241
    pack_length: DWORD;      // Internal length for packed data
1242
    buffer_type: enum_field_types;
1243
    error_value: my_bool;    // used if error is nil
1244
    is_unsigned: my_bool;    // set if integer type is unsigned
1245
    long_data_used: my_bool; // If used with mysql_send_long_data
1246
    is_null_value: my_bool;  // Used if is_null is nil
1247
    extension: Pointer;
1248
  end;
1249
  PMYSQL_BIND501=^TMYSQL_BIND501;
1250
1251
  TMYSQL_BIND=TMYSQL_BIND501;
1252
  PMYSQL_BIND=Pointer;
1253
1254
{$IFDEF CONDITIONALEXPRESSIONS} {Delphi 6 and above}
1255
type
1256
  enum_mysql_timestamp_type=(
1257
    MYSQL_TIMESTAMP_NONE = -2, MYSQL_TIMESTAMP_ERROR = -1,
1258
    MYSQL_TIMESTAMP_DATE = 0, MYSQL_TIMESTAMP_DATETIME = 1, MYSQL_TIMESTAMP_TIME = 2);
1259
{$ELSE}
1260
const
1261
  MYSQL_TIMESTAMP_NONE = -2;
1262
  MYSQL_TIMESTAMP_ERROR = -1;
1263
  MYSQL_TIMESTAMP_DATE = 0;
1264
  MYSQL_TIMESTAMP_DATETIME = 1;
1265
  MYSQL_TIMESTAMP_TIME = 2;
1266
type
1267
  enum_mysql_timestamp_type=Integer;
1268
{$ENDIF}
1269
1270
type
1271
  TMYSQL_TIME = record
1272
    year, month, day, hour, minute, second: DWORD;
1273
    second_part: DWORD;
1274
    neg: my_bool;
1275
    time_type: enum_mysql_timestamp_type;
1276
  end;
1277
1278
  function mysql_stmt_affected_rows(stmt: PMYSQL_STMT): my_ulonglong; stdcall;
1279
  function mysql_stmt_attr_get(stmt: PMYSQL_STMT; option: enum_stmt_attr_type; var arg): Integer; stdcall;
1280
  function mysql_stmt_attr_set(stmt: PMYSQL_STMT; option: enum_stmt_attr_type; const arg): Integer; stdcall;
1281
  function mysql_stmt_bind_param(stmt: PMYSQL_STMT; bind: PMYSQL_BIND): my_bool; stdcall;
1282
  function mysql_stmt_bind_result(stmt: PMYSQL_STMT; bind: PMYSQL_BIND): my_bool; stdcall;
1283
  function mysql_stmt_close(stmt: PMYSQL_STMT): my_bool; stdcall;
1284
  procedure mysql_stmt_data_seek(stmt: PMYSQL_STMT; offset: my_ulonglong); stdcall;
1285
  function mysql_stmt_errno(stmt: PMYSQL_STMT): DWORD; stdcall;
1286
  function mysql_stmt_error(stmt: PMYSQL_STMT): PAnsiChar; stdcall;
1287
  function mysql_stmt_execute(stmt: PMYSQL_STMT): Integer; stdcall;
1288
  function mysql_stmt_fetch(stmt: PMYSQL_STMT): Integer; stdcall;
1289
  function mysql_stmt_fetch_column(stmt: PMYSQL_STMT; bind: PMYSQL_BIND; column: DWORD; offset: DWORD): Integer; stdcall;
1290
  function mysql_stmt_field_count(stmt: PMYSQL_STMT): DWORD; stdcall;
1291
  function mysql_stmt_free_result(stmt: PMYSQL_STMT): my_bool; stdcall;
1292
  function mysql_stmt_init(_mysql: PMYSQL): PMYSQL_STMT; stdcall;
1293
  function mysql_stmt_insert_id(stmt: PMYSQL_STMT): my_ulonglong; stdcall;
1294
  function mysql_stmt_num_rows(stmt: PMYSQL_STMT): my_ulonglong; stdcall;
1295
  function mysql_stmt_param_count(stmt: PMYSQL_STMT): DWORD; stdcall;
1296
  function mysql_stmt_param_metadata(stmt: PMYSQL_STMT): PMYSQL_RES; stdcall;
1297
  function mysql_stmt_prepare(stmt: PMYSQL_STMT; query: PAnsiChar; length: DWORD): Integer; stdcall;
1298
  function mysql_stmt_reset(stmt: PMYSQL_STMT): my_bool; stdcall;
1299
  function mysql_stmt_result_metadata(stmt: PMYSQL_STMT): PMYSQL_RES; stdcall;
1300
  function mysql_stmt_row_seek(stmt: PMYSQL_STMT; offset: MYSQL_ROW_OFFSET): MYSQL_ROW_OFFSET; stdcall;
1301
  function mysql_stmt_row_tell(stmt: PMYSQL_STMT): MYSQL_ROW_OFFSET; stdcall;
1302
  function mysql_stmt_send_long_data(stmt: PMYSQL_STMT; parameter_number: DWORD; data: PAnsiChar; length: DWORD): my_bool; stdcall;
1303
  function mysql_stmt_sqlstate(stmt: PMYSQL_STMT): PAnsiChar; stdcall;
1304
  function mysql_stmt_store_result(stmt: PMYSQL_STMT): Integer; stdcall;
1305
1306
//-- Functions for library independent BIND handling --
1307
  //Create initialized memory block for Bindings - Free it with FreeMem
1308
  function mysql_bind_init(Count: Integer): PMYSQL_BIND;
1309
  //Copy mySQL_Bind to bind record array
1310
  function mysql_bind_copy_bind(bind: PMYSQL_BIND; Index: Integer; const mySQL_Bind: TMYSQL_BIND): Boolean;
1311
  //Copy params to bind record array
1312
  function mysql_bind_set_param(bind: PMYSQL_BIND; Index: Integer;
1313
                                buffer_type: enum_field_types;
1314
                                buffer: Pointer;         // buffer to get/put data
1315
                                buffer_length: DWORD;
1316
                                length: PDWORD;          // output length pointer
1317
                                is_null: Pmy_bool        // Pointer to null indicator
1318
                                ): Boolean;
1319
1320
// -----------------------------------------------------------------------------------------------
1321
// Character Set support
1322
// -----------------------------------------------------------------------------------------------
1323
1324
{ Normally it is not necessary to use this functions. The converter functions of Delphi - AnsiString()
1325
  and UnicodeString() - should work properly in most cases. You could benefit from this functions, if
1326
  - Your application must support more than one codepage at the same time (e.g. your server connection
1327
    use another  character set than other parts of your application)
1328
  - You want change the character set for the mysql client at runtime
1329
  - You want change the codepage according to the character set of the mysql client at runtime
1330
  - You want have more encoding performance especially for the data rows coming from the server
1331
    (you can avoid multiple string scans by using mysql_fetch_lengths)
1332
  - You want support unicode using Delphi prior Delphi 2009
1333
}
1334
1335
{$IFDEF Win32CharacterConvert}
1336
   {$DEFINE CharacterConvert}
1337
1338
function MySqlToUTF16(Source: PAnsiChar; Length: Integer=-1; CodePage: Word=CP_ACP): UnicodeString; overload;
1339
1340
function UTF16ToMySql(const Source: UnicodeString; CodePage: Word=CP_ACP): RawByteString; overload;
1341
1342
var
1343
  DefaultMySqlCodePage: Word;
1344
1345
// If you feel more comfortable with a encoding class...
1346
type
1347
  TMySqlEncoding=class
1348
  private
1349
    FCodepage: Word;
1350
  public
1351
    constructor Create(Codepage: Word=CP_ACP);
1352
    function MySqlToUTF16(Source: PAnsiChar; Length: Integer=-1): UnicodeString;
1353
    function UTF16ToMySql(const Source: UnicodeString): RawByteString;
1354
  end;
1355
1356
{$ENDIF}
1357
1358
// Not official supported set of conversion functions for high speed but great
1359
// amount of memory
1360
1361
{$IFDEF EmbeddedCharacterConvert}
1362
   {$DEFINE CharacterConvert}
1363
type
1364
  TCharsetHandle=Pointer;
1365
1366
// Create a new CharsetHandle - use this prior conversion
1367
function CreateCharsetHandle(const csname: String): TCharsetHandle;
1368
1369
// Free the resources used by CharsetHandle - use this after conversion
1370
procedure FreeCharsetHandle(CharSetHandle: TCharsetHandle);
1371
1372
function GetCharSetName(CharSetHandle: TCharsetHandle): String;
1373
1374
function CreateCharsetHandleById(CharsetId: Integer): TCharsetHandle;
1375
1376
function CharSetIsEmbeeded(CharSetHandle: TCharsetHandle): Boolean;
1377
1378
//Convert from MySql string to UTF16 (Unicode) String
1379
function MySqlToUTF16(Source: PAnsiChar; Length: Integer; CharSetHandle: TCharsetHandle): UnicodeString; overload;
1380
1381
//Convert from UTF16 (Unicode) String to MySql string
1382
function UTF16ToMySql(const Source: UnicodeString; CharSetHandle: TCharsetHandle): RawByteString; overload;
1383
1384
{$ENDIF}
1385
1386
{$IFDEF CharacterConvert}
1387
1388
// Get a comma separated list of all MySql character set names matches to the Codepage
1389
function CodePageToCharsetName(CodePage: Word; List: Boolean=False): String;
1390
1391
// Get the Codepage matches to the MySql character set name
1392
function CharsetNameToCodePage(CharacterSetName: String): Word;
1393
1394
{$ENDIF}
1395
1396
// -----------------------------------------------------------------------------------------------
1397
// Utility Functions
1398
// -----------------------------------------------------------------------------------------------
1399
1400
// Same as StrLen() but return 0 if Str is nil - usefull for Delphi prior Delphi 2009
1401
// Since Delphi 2009 you can use Length(Str)
1402
function MySql_StrLen(const Str: PAnsiChar): Cardinal;
1403
1404
// ------------------------------- U n i c o d e -------------------------------------------------
1405
{ This Escape functions are native Delphi functions supporting Unicode.
1406
  There are to different ways for transfering data to the SQL-Sever:
1407
  a) Create SQL-Statement -> EscapeString -> Character Encoding -> mysql_real_query
1408
  b) Create SQL-Statement -> Character Encoding -> mysql_real_escape_string -> mysql_real_query
1409
}
1410
{$IFDEF Unicode }
1411
{ Escape String - Unicode Version }
1412
function EscapeString(const Str: String): String; overload;
1413
1414
{ Quote and escape SQL String - for transfering Values to Server.}
1415
function QuoteString(const Str: String): String; overload;
1416
1417
//"BackTick" the Identifier like Tablenames and Fieldnames
1418
function QuoteName(const Str: String): String; overload; inline;
1419
1420
// Quote "\", "_" and "%" characters and all characters normaly quoted by mysql_escape_string
1421
function EscapeForLike(const Str: String): String; overload;
1422
{$ENDIF}
1423
1424
// ----------------------------- M u l t i b y t e -----------------------------------------------
1425
{ This Escape functions are native Delphi functions supporting the System-Codepage.
1426
  There are to different ways for transfering data to the SQL-Sever:
1427
  a) Create SQL-Statement -> EscapeString -> [Character Encoding] -> mysql_real_query
1428
  b) Create SQL-Statement -> [Character Encoding] -> mysql_real_escape_string -> mysql_real_query
1429
}
1430
{ Escape String - Multibyte-Character Version - using System-Codepage}
1431
function EscapeString(const Str: AnsiString): AnsiString; overload;
1432
1433
{ Quoted and Escaped SQL String - for transfering Values to Server.
1434
  This is the Multibyte-Character Version - using System-Codepage}
1435
function QuoteString(const Str: AnsiString): AnsiString; overload;
1436
1437
function QuoteName(const Str: AnsiString): AnsiString; overload;
1438
{$IFDEF CONDITIONALEXPRESSIONS}
1439
{$IF CompilerVersion>=18}
1440
inline;
1441
{$IFEND}
1442
{$ENDIF}
1443
1444
function EscapeForLike(const Str: AnsiString): AnsiString; overload;
1445
1446
function FullFieldname(const table, field: String): String;
1447
1448
// -----------------------------------------------------------------------------------------------
1449
// Library loading
1450
// -----------------------------------------------------------------------------------------------
1451
1452
type
1453
  Tlibmysql_status=(LIBMYSQL_UNDEFINED,     // libmysql_load() has not yet been called
1454
                    LIBMYSQL_MISSING,       // No suitable DLL could be located
1455
                    LIBMYSQL_INCOMPATIBLE,  // A DLL was found but it is not compatible
1456
                    LIBMYSQL_READY);        // The DLL was loaded successfully
1457
1458
var
1459
  libmysql_handle: HMODULE = 0;
1460
1461
function libmysql_ClientVersion: longword; //current Client-Version as longword 3.23.58=32358
1462
function libmysql_status: Tlibmysql_status;
1463
1464
//Load library and resolve all functions
1465
function libmysql_load(name: PChar): Tlibmysql_status;
1466
//Raise exception if library not loaded
1467
procedure libmysql_load_check;
1468
1469
//Load library - functions are resolved if needed - Exception if library not loaded
1470
procedure libmysql_fast_load(name: PChar);
1471
1472
//Unload library
1473
procedure libmysql_free;
1474
1475
// -----------------------------------------------------------------------------------------------
1476
IMPLEMENTATION
1477
// -----------------------------------------------------------------------------------------------
1478
1479
{$IFDEF AD}
1480
uses
1481
  SysUtils, UadConsts;
1482
{$ELSE}
1483
uses
1484
  SysUtils;
1485
{$ENDIF}
1486
1487
1488
resourcestring
1489
  sLibMySql_Undefined = 'MySQL: libmysql not loaded';
1490
  sLibMySql_Missing = 'MySQL: No suitable DLL could be located';
1491
  sLibMySql_Incompatible = 'MySQL: A DLL was found but it is not compatible';
1492
  sLibMySql_Version_Incompatible = 'MySQL: libmysql %s is not compatible';
1493
1494
{$IFNDEF AD}
1495
  EProcNotFound = 'MySQL: Procedure "%s" not found in library "%s"';
1496
  ELibraryNotFound = 'MySQL: Library "%s" not found';
1497
{$ENDIF}
1498
1499
const
1500
  mysql_not_compatible_version=60100;
1501
1502
var
1503
  internal_libmysql_status: Tlibmysql_status=LIBMYSQL_UNDEFINED;
1504
  internal_libmysql_ClientVersion: longword;
1505
1506
function IS_PRI_KEY(n: longword): boolean;
1507
begin
1508
  Result := (n and PRI_KEY_FLAG) <> 0;
1509
end;
1510
1511
function IS_AUTO_INC(n: longword): boolean;
1512
begin
1513
  Result := (n and AUTO_INCREMENT_FLAG) <> 0;
1514
end;
1515
1516
function IS_NOT_NULL(n: longword): boolean;
1517
begin
1518
  Result := (n and NOT_NULL_FLAG) <> 0;
1519
end;
1520
1521
function IS_BLOB(n: longword): boolean;
1522
begin
1523
  Result := (n and BLOB_FLAG) <> 0;
1524
end;
1525
1526
function IS_NUM_FLAG(n: longword): boolean;
1527
begin
1528
  Result := (n and NUM_FLAG) <> 0
1529
end;
1530
1531
function IS_NUM(t: enum_field_types): boolean;
1532
begin
1533
  Result := (t<>MYSQL_TYPE_TIMESTAMP) and ((t <= MYSQL_TYPE_INT24) or (t = MYSQL_TYPE_YEAR)  or (t = MYSQL_TYPE_NEWDECIMAL));
1534
end;
1535
1536
function IS_LONGDATA(t: enum_field_types): boolean;
1537
begin
1538
  Result := (t >= MYSQL_TYPE_TINY_BLOB) and (t <= MYSQL_TYPE_STRING);
1539
end;
1540
1541
function INTERNAL_NUM_FIELD(f: PMYSQL_FIELD): boolean;
1542
begin
1543
  if internal_libmysql_ClientVersion<40000
1544
  then begin
1545
    with TMYSQL_FIELD323(f^) do
1546
      Result := (((_type <= MYSQL_TYPE_INT24) and ((_type <> MYSQL_TYPE_TIMESTAMP) or (length = 14) or (length = 8))) or (_type = MYSQL_TYPE_YEAR));
1547
  end
1548
  else
1549
  if internal_libmysql_ClientVersion<40100
1550
  then begin
1551
    with TMYSQL_FIELD400(f^) do
1552
      Result := (((_type <= MYSQL_TYPE_INT24) and ((_type <> MYSQL_TYPE_TIMESTAMP) or (length = 14) or (length = 8))) or (_type = MYSQL_TYPE_YEAR));
1553
  end
1554
  else
1555
  if internal_libmysql_ClientVersion<mysql_not_compatible_version
1556
  then begin
1557
    with TMYSQL_FIELD401(f^) do
1558
      Result := (((_type <= MYSQL_TYPE_INT24) and ((_type <> MYSQL_TYPE_TIMESTAMP) or (length = 14) or (length = 8))) or (_type = MYSQL_TYPE_YEAR));
1559
  end
1560
  else
1561
    Result := False;
1562
end;
1563
1564
1565
function UpdateField(f: PMYSQL_FIELD): TMYSQL_FIELD;
1566
  procedure CopyStr(var dest: PAnsiChar; var DestLen: Cardinal; src: PAnsiChar);
1567
  //eax: dest edx: DestLen ecx: src
1568
  asm
1569
    mov     [dest], src
1570
    push    Dest
1571
    push    DestLen
1572
    xor     edx, edx
1573
    test    src, src        //src=nil?
1574
    jz      @NoString
1575
    cmp     src, $BAADF00D  //special for Client 4.0.27
1576
    jz      @NoString
1577
    mov     eax, src
1578
  @Scan:
1579
    cmp     dl, [eax+0]
1580
    jz      @add_0
1581
    cmp     dl, [eax+1]
1582
    jz      @add_1
1583
    cmp     dl, [eax+2]
1584
    jz      @add_2
1585
    cmp     dl, [eax+3]
1586
    jz      @add_3
1587
    add     eax, 4
1588
    jmp     @Scan
1589
  @add_3:
1590
    inc     eax
1591
  @add_2:
1592
    inc     eax
1593
  @add_1:
1594
    inc     eax
1595
  @add_0:
1596
    sub     eax, src
1597
    pop     ecx             //DestLen
1598
    mov     [ecx], eax
1599
    pop     ecx             //Dest
1600
    jmp     @out
1601
  @NoString:
1602
    pop     ecx             //DestLen
1603
    mov     [ecx], edx
1604
    pop     ecx             //Dest
1605
    mov     [ecx], edx
1606
  @out:
1607
  end;
1608
begin
1609
  if f<>nil
1610
  then begin
1611
    if internal_libmysql_ClientVersion<40000
1612
    then begin
1613
      CopyStr(Result.name, Result.name_length, TMYSQL_FIELD323(f^).name);
1614
      CopyStr(Result.table,Result.table_length, TMYSQL_FIELD323(f^).table);
1615
      CopyStr(Result.def, Result.def_length, TMYSQL_FIELD323(f^).def);
1616
      Result.length := TMYSQL_FIELD323(f^).length;
1617
      Result.max_length := TMYSQL_FIELD323(f^).max_length;
1618
      Result.org_table := nil;
1619
      Result.org_table_length := 0;
1620
      Result.org_name := nil;
1621
      Result.org_name_length := 0;
1622
      Result.db := nil;
1623
      Result.db_length := 0;
1624
      Result.catalog := nil;
1625
      Result.catalog_length := 0;
1626
      Result.flags := TMYSQL_FIELD323(f^).flags;
1627
      Result.decimals := TMYSQL_FIELD323(f^).decimals;
1628
      Result.charsetnr := 0;
1629
      Result._type := TMYSQL_FIELD323(f^)._type;
1630
    end
1631
    else
1632
    if internal_libmysql_ClientVersion<40100
1633
    then begin
1634
      CopyStr(Result.name, Result.name_length, TMYSQL_FIELD400(f^).name);
1635
      CopyStr(Result.table,Result.table_length, TMYSQL_FIELD400(f^).table);
1636
      CopyStr(Result.org_table, Result.org_table_length, TMYSQL_FIELD400(f^).org_table);
1637
      CopyStr(Result.db, Result.db_length, TMYSQL_FIELD400(f^).db);
1638
      CopyStr(Result.def, Result.def_length, TMYSQL_FIELD400(f^).def);
1639
      CopyStr(Result.org_table, Result.org_table_length, TMYSQL_FIELD400(f^).org_table);
1640
      Result.length := TMYSQL_FIELD400(f^).length;
1641
      Result.max_length := TMYSQL_FIELD400(f^).max_length;
1642
      Result.org_name := nil;
1643
      Result.org_name_length := 0;
1644
      Result.catalog := nil;
1645
      Result.catalog_length := 0;
1646
      Result.flags := TMYSQL_FIELD400(f^).flags;
1647
      Result.decimals := TMYSQL_FIELD400(f^).decimals;
1648
      Result.charsetnr := 0;
1649
      Result._type := TMYSQL_FIELD400(f^)._type;
1650
    end
1651
    else
1652
    if internal_libmysql_ClientVersion<mysql_not_compatible_version
1653
    then begin
1654
      move(f^, Result, sizeof(TMYSQL_FIELD401));
1655
    end;
1656
  end;
1657
end;
1658
1659
function GetVersion(VersionString: PAnsiChar): longword;
1660
  function GetValue(var v: Cardinal; var p: PAnsiChar): Boolean;
1661
  var
1662
    t: SmallInt;
1663
    c: AnsiChar;
1664
  begin
1665
    t := 0;
1666
    c := p^;
1667
    while ((c>='0') and (c<='9')) do
1668
    begin
1669
      t := t * 10 + Ord(c) - Ord('0');
1670
      inc(p);
1671
      c := p^;
1672
    end;
1673
    if c<>#0 then inc(P);
1674
    v := v * 100 + Cardinal(t);
1675
    Result := ((c='.') or (c='-') or (c=#0)) and (t<100);
1676
  end;
1677
begin
1678
  if (VersionString=nil) or (VersionString^=#0)
1679
  then
1680
    Result := longword(-1)
1681
  else begin
1682
    Result := 0;
1683
    if not GetValue(Result, VersionString) or
1684
       not GetValue(Result, VersionString) or
1685
       not GetValue(Result, VersionString)
1686
    then
1687
      Result := longword(-1);
1688
  end;
1689
end;
1690
1691
1692
function libmysql_ClientVersion_substitute: longword; stdcall;
1693
begin
1694
  Result := GetVersion(mysql_get_client_info);
1695
end;
1696
1697
function libmysql_ServerVersion_substitute(_mysql: PMYSQL): longword; stdcall;
1698
begin
1699
  Result := GetVersion(mysql_get_server_info(_mysql));
1700
end;
1701
1702
function mysql_reload(_mysql: PMYSQL): longint;
1703
begin
1704
  Result := mysql_refresh(_mysql, REFRESH_GRANT);
1705
end;
1706
1707
{$IFDEF CONDITIONALEXPRESSIONS}
1708
  {$DEFINE DYNAMICARRAYS}
1709
{$ENDIF}
1710
{$IFDEF VER120} //Delphi 4
1711
  {$DEFINE DYNAMICARRAYS}
1712
{$ENDIF}
1713
{$IFDEF VER130} //Delphi 5
1714
  {$DEFINE DYNAMICARRAYS}
1715
{$ENDIF}
1716
1717
{$IFDEF DYNAMICARRAYS}
1718
var
1719
  MysqlVarArray: array of ^Pointer;
1720
1721
procedure PushProc(procvar: Pointer);
1722
var
1723
  L: Integer;
1724
begin
1725
  L := Length(MysqlVarArray);
1726
  SetLength(MysqlVarArray, L+1);
1727
  MysqlVarArray[L] := procvar;
1728
end;
1729
1730
procedure FinalizeLibmysql;
1731
var
1732
  i: Integer;
1733
begin
1734
  if MysqlVarArray<>nil
1735
  then begin
1736
    for i := High(MysqlVarArray) downto 0 do
1737
    begin
1738
      MysqlVarArray[i]^ := nil;
1739
    end;
1740
    SetLength(MysqlVarArray, 0);
1741
  end;
1742
end;
1743
1744
{$ELSE}
1745
//dynamic array for Delphi 3 (not testet with Delphi 3)
1746
Type
1747
  TMysqlProcArray=array [0..4095] of ^Pointer;
1748
  PMysqlProcArray=^TMysqlProcArray;
1749
var
1750
  MysqlVarArraySize: Integer;
1751
  MysqlVarArray: PMysqlProcArray;
1752
1753
procedure PushProc(procvar: Pointer);
1754
begin
1755
  ReallocMem(MysqlVarArray, (MysqlVarArraySize+1)*SizeOf(Pointer));
1756
  MysqlVarArray^[MysqlVarArraySize] := procvar;
1757
  inc(MysqlVarArraySize);
1758
end;
1759
1760
procedure FinalizeLibmysql;
1761
var
1762
  i: Integer;
1763
begin
1764
  if MysqlVarArray<>nil
1765
  then begin
1766
    for i := MysqlVarArraySize - 1 downto 0 do
1767
    begin
1768
      MysqlVarArray^[i]^ := nil;
1769
    end;
1770
    FreeMem(MysqlVarArray);
1771
    MysqlVarArray := nil;
1772
    MysqlVarArraySize := 0;
1773
  end;
1774
end;
1775
{$ENDIF}
1776
1777
procedure LoadProcAddress(var proc: FARPROC; name: PAnsiChar);
1778
var
1779
  ModulPath: String;
1780
begin
1781
  if proc = nil
1782
  then begin
1783
    if libmysql_handle=0
1784
    then
1785
      raise Exception.Create(sLibMySql_Undefined);
1786
    proc := GetProcAddress(libmysql_handle, name);
1787
    if proc = nil
1788
    then begin
1789
      internal_libmysql_status := LIBMYSQL_INCOMPATIBLE;
1790
      SetLength(ModulPath, MAX_PATH);
1791
      SetLength(ModulPath, GetModuleFileName(libmysql_handle, Pointer(ModulPath), MAX_PATH));
1792
      raise Exception.CreateFmt(EProcNotFound, [name, ModulPath])
1793
    end;
1794
    PushProc(@proc);
1795
  end;
1796
end;
1797
1798
function mysql_fetch_db(_mysql: PMYSQL): PAnsiChar;
1799
begin
1800
  if internal_libmysql_ClientVersion<40000
1801
  then
1802
    Result := TMYSQL323(_mysql^).db
1803
  else
1804
  if internal_libmysql_ClientVersion<40100
1805
  then
1806
    Result := TMYSQL400(_mysql^).db
1807
  else
1808
  if internal_libmysql_ClientVersion<mysql_not_compatible_version
1809
  then
1810
    Result := TMYSQL401(_mysql^).db
1811
  else
1812
    Result := nil;
1813
end;
1814
1815
function mysql_field_type(f: PMYSQL_FIELD): enum_field_types;
1816
begin
1817
  if internal_libmysql_ClientVersion<40000
1818
  then
1819
    Result := TMYSQL_FIELD323(f^)._type
1820
  else
1821
  if internal_libmysql_ClientVersion<40100
1822
  then
1823
    Result := TMYSQL_FIELD400(f^)._type
1824
  else
1825
  if internal_libmysql_ClientVersion<mysql_not_compatible_version
1826
  then
1827
    Result := TMYSQL_FIELD401(f^)._type
1828
  else
1829
    raise Exception.Create(sLibMySql_Incompatible);
1830
end;
1831
1832
function mysql_field_flag(f: PMYSQL_FIELD): longword;
1833
begin
1834
  if internal_libmysql_ClientVersion<40000
1835
  then
1836
    Result := TMYSQL_FIELD323(f^).flags
1837
  else
1838
  if internal_libmysql_ClientVersion<40100
1839
  then
1840
    Result := TMYSQL_FIELD400(f^).flags
1841
  else
1842
  if internal_libmysql_ClientVersion<mysql_not_compatible_version
1843
  then
1844
    Result := TMYSQL_FIELD401(f^).flags
1845
  else
1846
    raise Exception.Create(sLibMySql_Incompatible);
1847
end;
1848
1849
function mysql_field_length(f: PMYSQL_FIELD): longword;
1850
begin
1851
  if internal_libmysql_ClientVersion<40000
1852
  then
1853
    Result := TMYSQL_FIELD323(f^).length
1854
  else
1855
  if internal_libmysql_ClientVersion<40100
1856
  then
1857
    Result := TMYSQL_FIELD400(f^).length
1858
  else
1859
  if internal_libmysql_ClientVersion<mysql_not_compatible_version
1860
  then
1861
    Result := TMYSQL_FIELD401(f^).length
1862
  else
1863
    raise Exception.Create(sLibMySql_Incompatible);
1864
end;
1865
1866
function mysql_field_name(f: PMYSQL_FIELD): PAnsiChar;
1867
begin
1868
  Result := TMYSQL_FIELD(f^).name;
1869
end;
1870
1871
function mysql_field_tablename(f: PMYSQL_FIELD): PAnsiChar;
1872
begin
1873
  if internal_libmysql_ClientVersion<40100
1874
  then
1875
    Result := TMYSQL_FIELD400(f^).table
1876
  else
1877
  if internal_libmysql_ClientVersion<mysql_not_compatible_version
1878
  then
1879
    Result := TMYSQL_FIELD401(f^).table
1880
  else
1881
    raise Exception.Create(sLibMySql_Incompatible);
1882
end;
1883
1884
{$WARNINGS OFF}
1885
{.$WARN NO_RETVAL OFF}
1886
var
1887
  _mysql_num_rows: FARPROC;
1888
1889
function mysql_num_rows(res: PMYSQL_RES): my_ulonglong; stdcall;
1890
begin
1891
  if _mysql_num_rows=nil
1892
  then
1893
    LoadProcAddress(_mysql_num_rows, 'mysql_num_rows');
1894
  asm
1895
    MOV     ESP, EBP
1896
    POP     EBP
1897
    JMP     [_mysql_num_rows]
1898
  end;
1899
end;
1900
1901
var
1902
  _mysql_num_fields: FARPROC;
1903
1904
function mysql_num_fields(res: PMYSQL_RES): longword; stdcall;
1905
begin
1906
  if _mysql_num_fields=nil
1907
  then
1908
    LoadProcAddress(_mysql_num_fields, 'mysql_num_fields');
1909
  asm
1910
    MOV     ESP, EBP
1911
    POP     EBP
1912
    JMP     [_mysql_num_fields]
1913
  end;
1914
end;
1915
1916
var
1917
  _mysql_eof: FARPROC;
1918
1919
function mysql_eof(res: PMYSQL_RES): my_bool; stdcall;
1920
begin
1921
  if _mysql_eof=nil
1922
  then
1923
    LoadProcAddress(_mysql_eof, 'mysql_eof');
1924
  asm
1925
    MOV     ESP, EBP
1926
    POP     EBP
1927
    JMP     [_mysql_eof]
1928
  end;
1929
end;
1930
1931
var
1932
  _mysql_fetch_field_direct: FARPROC;
1933
1934
function mysql_fetch_field_direct(res: PMYSQL_RES; fieldnr: longword): PMYSQL_FIELD; stdcall;
1935
begin
1936
  if _mysql_fetch_field_direct=nil
1937
  then
1938
    LoadProcAddress(_mysql_fetch_field_direct, 'mysql_fetch_field_direct');
1939
  asm
1940
    MOV     ESP, EBP
1941
    POP     EBP
1942
    JMP     [_mysql_fetch_field_direct]
1943
  end;
1944
end;
1945
1946
var
1947
  _mysql_fetch_fields: FARPROC;
1948
1949
function mysql_fetch_fields(res: PMYSQL_RES): PMYSQL_FIELDS; stdcall;
1950
begin
1951
  if _mysql_fetch_fields=nil
1952
  then
1953
    LoadProcAddress(_mysql_fetch_fields, 'mysql_fetch_fields');
1954
  asm
1955
    MOV     ESP, EBP
1956
    POP     EBP
1957
    JMP     [_mysql_fetch_fields]
1958
  end;
1959
end;
1960
1961
var
1962
  _mysql_row_tell: FARPROC;
1963
1964
function mysql_row_tell(res: PMYSQL_RES): MYSQL_ROW_OFFSET; stdcall;
1965
begin
1966
  if _mysql_row_tell=nil
1967
  then
1968
    LoadProcAddress(_mysql_row_tell, 'mysql_row_tell');
1969
  asm
1970
    MOV     ESP, EBP
1971
    POP     EBP
1972
    JMP     [_mysql_row_tell]
1973
  end;
1974
end;
1975
1976
var
1977
  _mysql_field_tell: FARPROC;
1978
1979
function mysql_field_tell(res: PMYSQL_RES): longword; stdcall;
1980
begin
1981
  if _mysql_field_tell=nil
1982
  then
1983
    LoadProcAddress(_mysql_field_tell, 'mysql_field_tell');
1984
  asm
1985
    MOV     ESP, EBP
1986
    POP     EBP
1987
    JMP     [_mysql_field_tell]
1988
  end;
1989
end;
1990
1991
var
1992
  _mysql_field_count: FARPROC;
1993
1994
function mysql_field_count(_mysql: PMYSQL): longword; stdcall;
1995
begin
1996
  if _mysql_field_count=nil
1997
  then
1998
    LoadProcAddress(_mysql_field_count, 'mysql_field_count');
1999
  asm
2000
    MOV     ESP, EBP
2001
    POP     EBP
2002
    JMP     [_mysql_field_count]
2003
  end;
2004
end;
2005
2006
var
2007
  _mysql_affected_rows: FARPROC;
2008
2009
function mysql_affected_rows(_mysql: PMYSQL): my_ulonglong; stdcall;
2010
begin
2011
  if _mysql_affected_rows=nil
2012
  then
2013
    LoadProcAddress(_mysql_affected_rows, 'mysql_affected_rows');
2014
  asm
2015
    MOV     ESP, EBP
2016
    POP     EBP
2017
    JMP     [_mysql_affected_rows]
2018
  end;
2019
end;
2020
2021
var
2022
  _mysql_insert_id: FARPROC;
2023
2024
function mysql_insert_id(_mysql: PMYSQL): my_ulonglong; stdcall;
2025
begin
2026
  if _mysql_insert_id=nil
2027
  then
2028
    LoadProcAddress(_mysql_insert_id, 'mysql_insert_id');
2029
  asm
2030
    MOV     ESP, EBP
2031
    POP     EBP
2032
    JMP     [_mysql_insert_id]
2033
  end;
2034
end;
2035
2036
var
2037
  _mysql_errno: FARPROC;
2038
2039
function mysql_errno(_mysql: PMYSQL): longword; stdcall;
2040
begin
2041
  if _mysql_errno=nil
2042
  then
2043
    LoadProcAddress(_mysql_errno, 'mysql_errno');
2044
  asm
2045
    MOV     ESP, EBP
2046
    POP     EBP
2047
    JMP     [_mysql_errno]
2048
  end;
2049
end;
2050
2051
var
2052
  _mysql_error: FARPROC;
2053
2054
function mysql_error(_mysql: PMYSQL): PAnsiChar; stdcall;
2055
begin
2056
  if _mysql_error=nil
2057
  then
2058
    LoadProcAddress(_mysql_error, 'mysql_error');
2059
  asm
2060
    MOV     ESP, EBP
2061
    POP     EBP
2062
    JMP     [_mysql_error]
2063
  end;
2064
end;
2065
2066
var
2067
  _mysql_info: FARPROC;
2068
2069
function mysql_info(_mysql: PMYSQL): PAnsiChar; stdcall;
2070
begin
2071
  if _mysql_info=nil
2072
  then
2073
    LoadProcAddress(_mysql_info, 'mysql_info');
2074
  asm
2075
    MOV     ESP, EBP
2076
    POP     EBP
2077
    JMP     [_mysql_info]
2078
  end;
2079
end;
2080
2081
var
2082
  _mysql_thread_id: FARPROC;
2083
2084
function mysql_thread_id(_mysql: PMYSQL): longword; stdcall;
2085
begin
2086
  if _mysql_thread_id=nil
2087
  then
2088
    LoadProcAddress(_mysql_thread_id, 'mysql_thread_id');
2089
  asm
2090
    MOV     ESP, EBP
2091
    POP     EBP
2092
    JMP     [_mysql_thread_id]
2093
  end;
2094
end;
2095
2096
var
2097
  _mysql_character_set_name: FARPROC;
2098
2099
function mysql_character_set_name(_mysql: PMYSQL): PAnsiChar; stdcall;
2100
begin
2101
  if _mysql_character_set_name=nil
2102
  then
2103
    LoadProcAddress(_mysql_character_set_name, 'mysql_character_set_name');
2104
  asm
2105
    MOV     ESP, EBP
2106
    POP     EBP
2107
    JMP     [_mysql_character_set_name]
2108
  end;
2109
end;
2110
2111
var
2112
  _mysql_init: FARPROC;
2113
2114
function mysql_init(_mysql: PMYSQL): PMYSQL; stdcall;
2115
begin
2116
  if _mysql_init=nil
2117
  then
2118
    LoadProcAddress(_mysql_init, 'mysql_init');
2119
  asm
2120
    MOV     ESP, EBP
2121
    POP     EBP
2122
    JMP     [_mysql_init]
2123
  end;
2124
end;
2125
2126
var
2127
  _mysql_ssl_set: FARPROC;
2128
2129
function mysql_ssl_set(_mysql: PMYSQL; key, cert, ca, capath: PAnsiChar): longint; stdcall;
2130
begin
2131
  if _mysql_ssl_set=nil
2132
  then
2133
    LoadProcAddress(_mysql_ssl_set, 'mysql_ssl_set');
2134
  asm
2135
    MOV     ESP, EBP
2136
    POP     EBP
2137
    JMP     [_mysql_ssl_set]
2138
  end;
2139
end;
2140
2141
var
2142
  _mysql_ssl_cipher: FARPROC;
2143
2144
function mysql_ssl_cipher(_mysql: PMYSQL): PAnsiChar; stdcall;
2145
begin
2146
  if _mysql_ssl_cipher=nil
2147
  then
2148
    LoadProcAddress(_mysql_ssl_cipher, 'mysql_ssl_cipher');
2149
  asm
2150
    MOV     ESP, EBP
2151
    POP     EBP
2152
    JMP     [_mysql_ssl_cipher]
2153
  end;
2154
end;
2155
2156
var
2157
  _mysql_ssl_clear: FARPROC;
2158
2159
function mysql_ssl_clear(_mysql: PMYSQL): longint; stdcall;
2160
begin
2161
  if _mysql_ssl_clear=nil
2162
  then
2163
    LoadProcAddress(_mysql_ssl_clear, 'mysql_ssl_clear');
2164
  asm
2165
    MOV     ESP, EBP
2166
    POP     EBP
2167
    JMP     [_mysql_ssl_clear]
2168
  end;
2169
end;
2170
2171
var
2172
  _mysql_connect: FARPROC;
2173
2174
function mysql_connect(_mysql: PMYSQL; host, user, passwd: PAnsiChar): PMYSQL; stdcall;
2175
begin
2176
  if _mysql_connect=nil
2177
  then
2178
    LoadProcAddress(_mysql_connect, 'mysql_connect');
2179
  asm
2180
    MOV     ESP, EBP
2181
    POP     EBP
2182
    JMP     [_mysql_connect]
2183
  end;
2184
end;
2185
2186
var
2187
  _mysql_change_user: FARPROC;
2188
2189
function mysql_change_user(_mysql: PMYSQL; user, passwd, db: PAnsiChar): my_bool; stdcall;
2190
begin
2191
  if _mysql_change_user=nil
2192
  then
2193
    LoadProcAddress(_mysql_change_user, 'mysql_change_user');
2194
  asm
2195
    MOV     ESP, EBP
2196
    POP     EBP
2197
    JMP     [_mysql_change_user]
2198
  end;
2199
end;
2200
2201
var
2202
  _mysql_real_connect: FARPROC;
2203
2204
function mysql_real_connect(_mysql: PMYSQL; host, user, passwd, db: PAnsiChar; port: longword; unix_socket: PAnsiChar; clientflag: longword): PMYSQL; stdcall;
2205
begin
2206
  if _mysql_real_connect=nil
2207
  then
2208
    LoadProcAddress(_mysql_real_connect, 'mysql_real_connect');
2209
  asm
2210
    MOV     ESP, EBP
2211
    POP     EBP
2212
    JMP     [_mysql_real_connect]
2213
  end;
2214
end;
2215
2216
var
2217
  _mysql_close: FARPROC;
2218
2219
procedure mysql_close(sock: PMYSQL); stdcall;
2220
begin
2221
  if _mysql_close=nil
2222
  then
2223
    LoadProcAddress(_mysql_close, 'mysql_close');
2224
  asm
2225
    MOV     ESP, EBP
2226
    POP     EBP
2227
    JMP     [_mysql_close]
2228
  end;
2229
end;
2230
2231
var
2232
  _mysql_select_db: FARPROC;
2233
2234
function mysql_select_db(_mysql: PMYSQL; db: PAnsiChar): longint; stdcall;
2235
begin
2236
  if _mysql_select_db=nil
2237
  then
2238
    LoadProcAddress(_mysql_select_db, 'mysql_select_db');
2239
  asm
2240
    MOV     ESP, EBP
2241
    POP     EBP
2242
    JMP     [_mysql_select_db]
2243
  end;
2244
end;
2245
2246
var
2247
  _mysql_query: FARPROC;
2248
2249
function mysql_query(_mysql: PMYSQL; q: PAnsiChar): longint; stdcall;
2250
begin
2251
  if _mysql_query=nil
2252
  then
2253
    LoadProcAddress(_mysql_query, 'mysql_query');
2254
  asm
2255
    MOV     ESP, EBP
2256
    POP     EBP
2257
    JMP     [_mysql_query]
2258
  end;
2259
end;
2260
2261
var
2262
  _mysql_send_query: FARPROC;
2263
2264
function mysql_send_query(_mysql: PMYSQL; q: PAnsiChar; length: longword): longint; stdcall;
2265
begin
2266
  if _mysql_send_query=nil
2267
  then
2268
    LoadProcAddress(_mysql_send_query, 'mysql_send_query');
2269
  asm
2270
    MOV     ESP, EBP
2271
    POP     EBP
2272
    JMP     [_mysql_send_query]
2273
  end;
2274
end;
2275
2276
var
2277
  _mysql_read_query_result: FARPROC;
2278
2279
function mysql_read_query_result(_mysql: PMYSQL): longint; stdcall;
2280
begin
2281
  if _mysql_read_query_result=nil
2282
  then
2283
    LoadProcAddress(_mysql_read_query_result, 'mysql_read_query_result');
2284
  asm
2285
    MOV     ESP, EBP
2286
    POP     EBP
2287
    JMP     [_mysql_read_query_result]
2288
  end;
2289
end;
2290
2291
var
2292
  _mysql_real_query: FARPROC;
2293
2294
function mysql_real_query(_mysql: PMYSQL; q: PAnsiChar; length: longword): longint; stdcall;
2295
begin
2296
  if _mysql_real_query=nil
2297
  then
2298
    LoadProcAddress(_mysql_real_query, 'mysql_real_query');
2299
  asm
2300
    MOV     ESP, EBP
2301
    POP     EBP
2302
    JMP     [_mysql_real_query]
2303
  end;
2304
end;
2305
2306
var
2307
  _mysql_create_db: FARPROC;
2308
2309
function mysql_create_db(_mysql: PMYSQL; DB: PAnsiChar): longint; stdcall;
2310
begin
2311
  if _mysql_create_db=nil
2312
  then
2313
    LoadProcAddress(_mysql_create_db, 'mysql_create_db');
2314
  asm
2315
    MOV     ESP, EBP
2316
    POP     EBP
2317
    JMP     [_mysql_create_db]
2318
  end;
2319
end;
2320
2321
var
2322
  _mysql_drop_db: FARPROC;
2323
2324
function mysql_drop_db(_mysql: PMYSQL; DB: PAnsiChar): longint; stdcall;
2325
begin
2326
  if _mysql_drop_db=nil
2327
  then
2328
    LoadProcAddress(_mysql_drop_db, 'mysql_drop_db');
2329
  asm
2330
    MOV     ESP, EBP
2331
    POP     EBP
2332
    JMP     [_mysql_drop_db]
2333
  end;
2334
end;
2335
2336
var
2337
  _mysql_shutdown: FARPROC;
2338
2339
function mysql_shutdown(_mysql: PMYSQL): longint; stdcall;
2340
begin
2341
  if _mysql_shutdown=nil
2342
  then
2343
    LoadProcAddress(_mysql_shutdown, 'mysql_shutdown');
2344
  asm
2345
    MOV     ESP, EBP
2346
    POP     EBP
2347
    JMP     [_mysql_shutdown]
2348
  end;
2349
end;
2350
2351
var
2352
  _mysql_dump_debug_info: FARPROC;
2353
2354
function mysql_dump_debug_info(_mysql: PMYSQL): longint; stdcall;
2355
begin
2356
  if _mysql_dump_debug_info=nil
2357
  then
2358
    LoadProcAddress(_mysql_dump_debug_info, 'mysql_dump_debug_info');
2359
  asm
2360
    MOV     ESP, EBP
2361
    POP     EBP
2362
    JMP     [_mysql_dump_debug_info]
2363
  end;
2364
end;
2365
2366
var
2367
  _mysql_refresh: FARPROC;
2368
2369
function mysql_refresh(_mysql: PMYSQL; refresh_options: longword): longint; stdcall;
2370
begin
2371
  if _mysql_refresh=nil
2372
  then
2373
    LoadProcAddress(_mysql_refresh, 'mysql_refresh');
2374
  asm
2375
    MOV     ESP, EBP
2376
    POP     EBP
2377
    JMP     [_mysql_refresh]
2378
  end;
2379
end;
2380
2381
var
2382
  _mysql_kill: FARPROC;
2383
2384
function mysql_kill(_mysql: PMYSQL; pid: longword): longint; stdcall;
2385
begin
2386
  if _mysql_kill=nil
2387
  then
2388
    LoadProcAddress(_mysql_kill, 'mysql_kill');
2389
  asm
2390
    MOV     ESP, EBP
2391
    POP     EBP
2392
    JMP     [_mysql_kill]
2393
  end;
2394
end;
2395
2396
var
2397
  _mysql_ping: FARPROC;
2398
2399
function mysql_ping(_mysql: PMYSQL): longint; stdcall;
2400
begin
2401
  if _mysql_ping=nil
2402
  then
2403
    LoadProcAddress(_mysql_ping, 'mysql_ping');
2404
  asm
2405
    MOV     ESP, EBP
2406
    POP     EBP
2407
    JMP     [_mysql_ping]
2408
  end;
2409
end;
2410
2411
var
2412
  _mysql_stat: FARPROC;
2413
2414
function mysql_stat(_mysql: PMYSQL): PAnsiChar; stdcall;
2415
begin
2416
  if _mysql_stat=nil
2417
  then
2418
    LoadProcAddress(_mysql_stat, 'mysql_stat');
2419
  asm
2420
    MOV     ESP, EBP
2421
    POP     EBP
2422
    JMP     [_mysql_stat]
2423
  end;
2424
end;
2425
2426
var
2427
  _mysql_get_server_info: FARPROC;
2428
2429
function mysql_get_server_info(_mysql: PMYSQL): PAnsiChar; stdcall;
2430
begin
2431
  if _mysql_get_server_info=nil
2432
  then
2433
    LoadProcAddress(_mysql_get_server_info, 'mysql_get_server_info');
2434
  asm
2435
    MOV     ESP, EBP
2436
    POP     EBP
2437
    JMP     [_mysql_get_server_info]
2438
  end;
2439
end;
2440
2441
var
2442
  _mysql_get_client_info: FARPROC;
2443
2444
function mysql_get_client_info: PAnsiChar; stdcall;
2445
begin
2446
  Result := nil;
2447
  if _mysql_get_client_info=nil
2448
  then
2449
    LoadProcAddress(_mysql_get_client_info, 'mysql_get_client_info');
2450
  if _mysql_get_client_info<>nil
2451
  then begin
2452
    asm
2453
      CALL    [_mysql_get_client_info]
2454
      MOV     @Result, EAX
2455
    end;
2456
  end;
2457
end;
2458
2459
var
2460
  _mysql_get_host_info: FARPROC;
2461
2462
function mysql_get_host_info(_mysql: PMYSQL): PAnsiChar; stdcall;
2463
begin
2464
  if _mysql_get_host_info=nil
2465
  then
2466
    LoadProcAddress(_mysql_get_host_info, 'mysql_get_host_info');
2467
  asm
2468
    MOV     ESP, EBP
2469
    POP     EBP
2470
    JMP     [_mysql_get_host_info]
2471
  end;
2472
end;
2473
2474
var
2475
  _mysql_get_proto_info: FARPROC;
2476
2477
function mysql_get_proto_info(_mysql: PMYSQL): longword; stdcall;
2478
begin
2479
  if _mysql_get_proto_info=nil
2480
  then
2481
    LoadProcAddress(_mysql_get_proto_info, 'mysql_get_proto_info');
2482
  asm
2483
    MOV     ESP, EBP
2484
    POP     EBP
2485
    JMP     [_mysql_get_proto_info]
2486
  end;
2487
end;
2488
2489
var
2490
  _mysql_list_dbs: FARPROC;
2491
2492
function mysql_list_dbs(_mysql: PMYSQL; wild: PAnsiChar): PMYSQL_RES; stdcall;
2493
begin
2494
  if _mysql_list_dbs=nil
2495
  then
2496
    LoadProcAddress(_mysql_list_dbs, 'mysql_list_dbs');
2497
  asm
2498
    MOV     ESP, EBP
2499
    POP     EBP
2500
    JMP     [_mysql_list_dbs]
2501
  end;
2502
end;
2503
2504
var
2505
  _mysql_list_tables: FARPROC;
2506
2507
function mysql_list_tables(_mysql: PMYSQL; wild: PAnsiChar): PMYSQL_RES; stdcall;
2508
begin
2509
  if _mysql_list_tables=nil
2510
  then
2511
    LoadProcAddress(_mysql_list_tables, 'mysql_list_tables');
2512
  asm
2513
    MOV     ESP, EBP
2514
    POP     EBP
2515
    JMP     [_mysql_list_tables]
2516
  end;
2517
end;
2518
2519
var
2520
  _mysql_list_fields: FARPROC;
2521
2522
function mysql_list_fields(_mysql: PMYSQL; table, wild: PAnsiChar): PMYSQL_RES; stdcall;
2523
begin
2524
  if _mysql_list_fields=nil
2525
  then
2526
    LoadProcAddress(_mysql_list_fields, 'mysql_list_fields');
2527
  asm
2528
    MOV     ESP, EBP
2529
    POP     EBP
2530
    JMP     [_mysql_list_fields]
2531
  end;
2532
end;
2533
2534
var
2535
  _mysql_list_processes: FARPROC;
2536
2537
function mysql_list_processes(_mysql: PMYSQL): PMYSQL_RES; stdcall;
2538
begin
2539
  if _mysql_list_processes=nil
2540
  then
2541
    LoadProcAddress(_mysql_list_processes, 'mysql_list_processes');
2542
  asm
2543
    MOV     ESP, EBP
2544
    POP     EBP
2545
    JMP     [_mysql_list_processes]
2546
  end;
2547
end;
2548
2549
var
2550
  _mysql_store_result: FARPROC;
2551
2552
function mysql_store_result(_mysql: PMYSQL): PMYSQL_RES; stdcall;
2553
begin
2554
  if _mysql_store_result=nil
2555
  then
2556
    LoadProcAddress(_mysql_store_result, 'mysql_store_result');
2557
  asm
2558
    MOV     ESP, EBP
2559
    POP     EBP
2560
    JMP     [_mysql_store_result]
2561
  end;
2562
end;
2563
2564
var
2565
  _mysql_use_result: FARPROC;
2566
2567
function mysql_use_result(_mysql: PMYSQL): PMYSQL_RES; stdcall;
2568
begin
2569
  if _mysql_use_result=nil
2570
  then
2571
    LoadProcAddress(_mysql_use_result, 'mysql_use_result');
2572
  asm
2573
    MOV     ESP, EBP
2574
    POP     EBP
2575
    JMP     [_mysql_use_result]
2576
  end;
2577
end;
2578
2579
var
2580
  _mysql_more_results: FARPROC;
2581
2582
function mysql_more_results(_mysql: PMYSQL): my_bool; stdcall;
2583
begin
2584
  if _mysql_more_results=nil
2585
  then
2586
    LoadProcAddress(_mysql_more_results, 'mysql_more_results');
2587
  asm
2588
    MOV     ESP, EBP
2589
    POP     EBP
2590
    JMP     [_mysql_more_results]
2591
  end;
2592
end;
2593
2594
var
2595
  _mysql_next_result: FARPROC;
2596
2597
function mysql_next_result(_mysql: PMYSQL): longint; stdcall;
2598
begin
2599
  if _mysql_next_result=nil
2600
  then
2601
    LoadProcAddress(_mysql_next_result, 'mysql_next_result');
2602
  asm
2603
    MOV     ESP, EBP
2604
    POP     EBP
2605
    JMP     [_mysql_next_result]
2606
  end;
2607
end;
2608
2609
var
2610
  _mysql_options: FARPROC;
2611
2612
function mysql_options(_mysql: PMYSQL; option: mysql_option; arg: Pointer): longint; stdcall;
2613
begin
2614
  if _mysql_options=nil
2615
  then
2616
    LoadProcAddress(_mysql_options, 'mysql_options');
2617
  asm
2618
    MOV     ESP, EBP
2619
    POP     EBP
2620
    JMP     [_mysql_options]
2621
  end;
2622
end;
2623
2624
var
2625
  _mysql_free_result: FARPROC;
2626
2627
procedure mysql_free_result(_mysql_res: PMYSQL_RES); stdcall;
2628
begin
2629
  if _mysql_free_result=nil
2630
  then
2631
    LoadProcAddress(_mysql_free_result, 'mysql_free_result');
2632
  asm
2633
    MOV     ESP, EBP
2634
    POP     EBP
2635
    JMP     [_mysql_free_result]
2636
  end;
2637
end;
2638
2639
var
2640
  _mysql_data_seek: FARPROC;
2641
2642
procedure mysql_data_seek(_mysql_res: PMYSQL_RES; offset: my_ulonglong); stdcall;
2643
begin
2644
  if _mysql_data_seek=nil
2645
  then
2646
    LoadProcAddress(_mysql_data_seek, 'mysql_data_seek');
2647
  asm
2648
    MOV     ESP, EBP
2649
    POP     EBP
2650
    JMP     [_mysql_data_seek]
2651
  end;
2652
end;
2653
2654
var
2655
  _mysql_row_seek: FARPROC;
2656
2657
function mysql_row_seek(_mysql_res: PMYSQL_RES; offset: MYSQL_ROW_OFFSET): MYSQL_ROW_OFFSET; stdcall;
2658
begin
2659
  if _mysql_row_seek=nil
2660
  then
2661
    LoadProcAddress(_mysql_row_seek, 'mysql_row_seek');
2662
  asm
2663
    MOV     ESP, EBP
2664
    POP     EBP
2665
    JMP     [_mysql_row_seek]
2666
  end;
2667
end;
2668
2669
var
2670
  _mysql_field_seek: FARPROC;
2671
2672
function mysql_field_seek(_mysql_res: PMYSQL_RES; offset: MYSQL_FIELD_OFFSET): MYSQL_FIELD_OFFSET; stdcall;
2673
begin
2674
  if _mysql_field_seek=nil
2675
  then
2676
    LoadProcAddress(_mysql_field_seek, 'mysql_field_seek');
2677
  asm
2678
    MOV     ESP, EBP
2679
    POP     EBP
2680
    JMP     [_mysql_field_seek]
2681
  end;
2682
end;
2683
2684
var
2685
  _mysql_fetch_row: FARPROC;
2686
2687
function mysql_fetch_row(_mysql_res: PMYSQL_RES): PMYSQL_ROW; stdcall;
2688
begin
2689
  if _mysql_fetch_row=nil
2690
  then
2691
    LoadProcAddress(_mysql_fetch_row, 'mysql_fetch_row');
2692
  asm
2693
    MOV     ESP, EBP
2694
    POP     EBP
2695
    JMP     [_mysql_fetch_row]
2696
  end;
2697
end;
2698
2699
var
2700
  _mysql_fetch_lengths: FARPROC;
2701
2702
function mysql_fetch_lengths(_mysql_res: PMYSQL_RES): PMYSQL_LENGTHS; stdcall;
2703
begin
2704
  if _mysql_fetch_lengths=nil
2705
  then
2706
    LoadProcAddress(_mysql_fetch_lengths, 'mysql_fetch_lengths');
2707
  asm
2708
    MOV     ESP, EBP
2709
    POP     EBP
2710
    JMP     [_mysql_fetch_lengths]
2711
  end;
2712
end;
2713
2714
var
2715
  _mysql_fetch_field: FARPROC;
2716
2717
function mysql_fetch_field(_mysql_res: PMYSQL_RES): PMYSQL_FIELD; stdcall;
2718
begin
2719
  if _mysql_fetch_field=nil
2720
  then
2721
    LoadProcAddress(_mysql_fetch_field, 'mysql_fetch_field');
2722
  asm
2723
    MOV     ESP, EBP
2724
    POP     EBP
2725
    JMP     [_mysql_fetch_field]
2726
  end;
2727
end;
2728
2729
var
2730
  _mysql_escape_string: FARPROC;
2731
2732
function mysql_escape_string(_to: PAnsiChar; from: PAnsiChar; from_length: longword): longword; stdcall;
2733
begin
2734
  if _mysql_escape_string=nil
2735
  then
2736
    LoadProcAddress(_mysql_escape_string, 'mysql_escape_string');
2737
  asm
2738
    MOV     ESP, EBP
2739
    POP     EBP
2740
    JMP     [_mysql_escape_string]
2741
  end;
2742
end;
2743
2744
var
2745
  _mysql_real_escape_string: FARPROC;
2746
2747
function mysql_real_escape_string(_mysql: PMYSQL; _to: PAnsiChar; from: PAnsiChar; length: longword): longword; stdcall;
2748
begin
2749
  if _mysql_real_escape_string=nil
2750
  then
2751
    LoadProcAddress(_mysql_real_escape_string, 'mysql_real_escape_string');
2752
  asm
2753
    MOV     ESP, EBP
2754
    POP     EBP
2755
    JMP     [_mysql_real_escape_string]
2756
  end;
2757
end;
2758
2759
var
2760
  _mysql_debug: FARPROC;
2761
2762
procedure mysql_debug(debug: PAnsiChar); stdcall;
2763
begin
2764
  if _mysql_debug=nil
2765
  then
2766
    LoadProcAddress(_mysql_debug, 'mysql_debug');
2767
  asm
2768
    MOV     ESP, EBP
2769
    POP     EBP
2770
    JMP     [_mysql_debug]
2771
  end;
2772
end;
2773
2774
var
2775
  _mysql_odbc_escape_string: FARPROC;
2776
2777
function mysql_odbc_escape_string(_mysql: PMYSQL; _to: PAnsiChar; to_length: longword; from: PAnsiChar; from_length: longword; param: pointer; extend_buffer: extend_buffer_func): PAnsiChar; stdcall;
2778
begin
2779
  if _mysql_odbc_escape_string=nil
2780
  then
2781
    LoadProcAddress(_mysql_odbc_escape_string, 'mysql_odbc_escape_string');
2782
  asm
2783
    MOV     ESP, EBP
2784
    POP     EBP
2785
    JMP     [_mysql_odbc_escape_string]
2786
  end;
2787
end;
2788
2789
var
2790
  _myodbc_remove_escape: FARPROC;
2791
2792
procedure myodbc_remove_escape(_mysql: PMYSQL; name: PAnsiChar); stdcall;
2793
begin
2794
  if _myodbc_remove_escape=nil
2795
  then
2796
    LoadProcAddress(_myodbc_remove_escape, 'myodbc_remove_escape');
2797
  asm
2798
    MOV     ESP, EBP
2799
    POP     EBP
2800
    JMP     [_myodbc_remove_escape]
2801
  end;
2802
end;
2803
2804
var
2805
  _mysql_thread_safe: FARPROC;
2806
2807
function mysql_thread_safe: longword; stdcall;
2808
begin
2809
  if _mysql_thread_safe=nil
2810
  then
2811
    LoadProcAddress(_mysql_thread_safe, 'mysql_thread_safe');
2812
  asm
2813
    CALL    [_mysql_thread_safe]
2814
    MOV     @RESULT, EAX
2815
  end;
2816
end;
2817
2818
var
2819
  _mysql_get_client_version: FARPROC;
2820
2821
function mysql_get_client_version: longword; stdcall;
2822
begin
2823
  if _mysql_get_client_version=nil
2824
  then begin
2825
    _mysql_get_client_version := GetProcAddress(libmysql_handle, 'mysql_get_client_version');
2826
    if _mysql_get_client_version=nil
2827
    then
2828
      _mysql_get_client_version := @libmysql_ClientVersion_substitute;
2829
    PushProc(@_mysql_get_client_version);
2830
  end;
2831
  asm
2832
    CALL    [_mysql_get_client_version]
2833
    MOV     @RESULT, EAX
2834
  end;
2835
end;
2836
2837
var
2838
  _mysql_get_server_version: FARPROC;
2839
2840
function mysql_get_server_version(_mysql: PMYSQL): longword; stdcall;
2841
begin
2842
  if _mysql_get_server_version=nil
2843
  then begin
2844
    _mysql_get_server_version := GetProcAddress(libmysql_handle, 'mysql_get_server_version');
2845
    if (_mysql_get_server_version=nil)
2846
    then
2847
      _mysql_get_server_version := @libmysql_ServerVersion_substitute;
2848
    PushProc(@_mysql_get_server_version);
2849
  end;
2850
  asm
2851
    MOV     ESP, EBP
2852
    POP     EBP
2853
    JMP     [_mysql_get_server_version]
2854
  end;
2855
end;
2856
2857
var
2858
  _mysql_set_character_set: FARPROC;
2859
2860
function mysql_set_character_set(_mysql: PMYSQL; csname: PAnsiChar): longint; stdcall;
2861
begin
2862
  if _mysql_set_character_set=nil
2863
  then
2864
    LoadProcAddress(_mysql_set_character_set, 'mysql_set_character_set');
2865
  asm
2866
    MOV     ESP, EBP
2867
    POP     EBP
2868
    JMP     [_mysql_set_character_set]
2869
  end;
2870
end;
2871
2872
var
2873
  _mysql_autocommit: FARPROC;
2874
2875
function mysql_autocommit(_mysql: PMYSQL; mode: my_bool ): my_bool; stdcall;
2876
begin
2877
  if _mysql_autocommit=nil
2878
  then
2879
    LoadProcAddress(_mysql_autocommit, 'mysql_autocommit');
2880
  asm
2881
    MOV     ESP, EBP
2882
    POP     EBP
2883
    JMP     [_mysql_autocommit]
2884
  end;
2885
end;
2886
2887
var
2888
  _mysql_commit: FARPROC;
2889
2890
function mysql_commit(_mysql: PMYSQL): my_bool; stdcall;
2891
begin
2892
  if _mysql_commit=nil
2893
  then
2894
    LoadProcAddress(_mysql_commit, 'mysql_commit');
2895
  asm
2896
    MOV     ESP, EBP
2897
    POP     EBP
2898
    JMP     [_mysql_commit]
2899
  end;
2900
end;
2901
2902
var
2903
  _mysql_rollback: FARPROC;
2904
2905
function mysql_rollback(_mysql: PMYSQL): my_bool; stdcall;
2906
begin
2907
  if _mysql_rollback=nil
2908
  then
2909
    LoadProcAddress(_mysql_rollback, 'mysql_rollback');
2910
  asm
2911
    MOV     ESP, EBP
2912
    POP     EBP
2913
    JMP     [_mysql_rollback]
2914
  end;
2915
end;
2916
2917
var
2918
  _mysql_set_server_option: FARPROC;
2919
2920
function mysql_set_server_option(_mysql: PMYSQL; option: enum_mysql_set_option): longint; stdcall;
2921
begin
2922
  if _mysql_set_server_option=nil
2923
  then
2924
    LoadProcAddress(_mysql_set_server_option, 'mysql_set_server_option');
2925
  asm
2926
    MOV     ESP, EBP
2927
    POP     EBP
2928
    JMP     [_mysql_set_server_option]
2929
  end;
2930
end;
2931
2932
var
2933
  _mysql_sqlstate: FARPROC;
2934
2935
function mysql_sqlstate(_mysql: PMYSQL): PAnsiChar; stdcall;
2936
begin
2937
  if _mysql_sqlstate=nil
2938
  then
2939
    LoadProcAddress(_mysql_sqlstate, 'mysql_sqlstate');
2940
  asm
2941
    MOV     ESP, EBP
2942
    POP     EBP
2943
    JMP     [_mysql_sqlstate]
2944
  end;
2945
end;
2946
2947
var
2948
  _mysql_warning_count: FARPROC;
2949
2950
function mysql_warning_count(_mysql: PMYSQL): longword; stdcall;
2951
begin
2952
  if _mysql_warning_count=nil
2953
  then
2954
    LoadProcAddress(_mysql_warning_count, 'mysql_warning_count');
2955
  asm
2956
    MOV     ESP, EBP
2957
    POP     EBP
2958
    JMP     [_mysql_warning_count]
2959
  end;
2960
end;
2961
2962
var
2963
  _mysql_server_init: FARPROC;
2964
2965
function mysql_server_init(argc: Integer; argv, groups: PPAnsiChar): Integer; stdcall;
2966
begin
2967
  if _mysql_server_init=nil
2968
  then
2969
    LoadProcAddress(_mysql_server_init, 'mysql_server_init');
2970
  asm
2971
    MOV     ESP, EBP
2972
    POP     EBP
2973
    JMP     [_mysql_server_init]
2974
  end;
2975
end;
2976
2977
var
2978
  _mysql_server_end: FARPROC;
2979
2980
procedure mysql_server_end;
2981
begin
2982
  if _mysql_server_end=nil
2983
  then
2984
    LoadProcAddress(_mysql_server_end, 'mysql_server_end');
2985
  asm
2986
    CALL     [_mysql_server_end]
2987
  end;
2988
end;
2989
2990
var
2991
  _mysql_thread_init: FARPROC;
2992
2993
function mysql_thread_init: my_bool; stdcall;
2994
begin
2995
  if _mysql_thread_init=nil
2996
  then
2997
    LoadProcAddress(_mysql_thread_init, 'mysql_thread_init');
2998
  asm
2999
    CALL     [_mysql_thread_init]
3000
  end;
3001
end;
3002
3003
var
3004
  _mysql_thread_end: FARPROC;
3005
3006
procedure mysql_thread_end; stdcall;
3007
begin
3008
  if _mysql_thread_end=nil
3009
  then
3010
    LoadProcAddress(_mysql_thread_end, 'mysql_thread_end');
3011
  asm
3012
    CALL     [_mysql_thread_end]
3013
  end;
3014
end;
3015
3016
var
3017
  _mysql_stmt_affected_rows: FARPROC;
3018
3019
function mysql_stmt_affected_rows(stmt: PMYSQL_STMT): my_ulonglong;
3020
begin
3021
  if _mysql_stmt_affected_rows=nil
3022
  then
3023
    LoadProcAddress(_mysql_stmt_affected_rows, 'mysql_stmt_affected_rows');
3024
  asm
3025
    MOV     ESP, EBP
3026
    POP     EBP
3027
    JMP     [_mysql_stmt_affected_rows]
3028
  end;
3029
end;
3030
3031
var
3032
  _mysql_stmt_attr_get: FARPROC;
3033
3034
function mysql_stmt_attr_get(stmt: PMYSQL_STMT; option: enum_stmt_attr_type; var arg): Integer;
3035
begin
3036
  if _mysql_stmt_attr_get=nil
3037
  then
3038
    LoadProcAddress(_mysql_stmt_attr_get, 'mysql_stmt_attr_get');
3039
  asm
3040
    MOV     ESP, EBP
3041
    POP     EBP
3042
    JMP     [_mysql_stmt_attr_get]
3043
  end;
3044
end;
3045
3046
var
3047
  _mysql_stmt_attr_set: FARPROC;
3048
3049
function mysql_stmt_attr_set(stmt: PMYSQL_STMT; option: enum_stmt_attr_type; const arg): Integer;
3050
begin
3051
  if _mysql_stmt_attr_set=nil
3052
  then
3053
    LoadProcAddress(_mysql_stmt_attr_set, 'mysql_stmt_attr_set');
3054
  asm
3055
    MOV     ESP, EBP
3056
    POP     EBP
3057
    JMP     [_mysql_stmt_attr_set]
3058
  end;
3059
end;
3060
3061
var
3062
  _mysql_stmt_bind_param: FARPROC;
3063
3064
function mysql_stmt_bind_param(stmt: PMYSQL_STMT; bind: PMYSQL_BIND): my_bool;
3065
begin
3066
  if _mysql_stmt_bind_param=nil
3067
  then
3068
    LoadProcAddress(_mysql_stmt_bind_param, 'mysql_stmt_bind_param');
3069
  asm
3070
    MOV     ESP, EBP
3071
    POP     EBP
3072
    JMP     [_mysql_stmt_bind_param]
3073
  end;
3074
end;
3075
3076
var
3077
  _mysql_stmt_bind_result: FARPROC;
3078
3079
function mysql_stmt_bind_result(stmt: PMYSQL_STMT; bind: PMYSQL_BIND): my_bool;
3080
begin
3081
  if _mysql_stmt_bind_result=nil
3082
  then
3083
    LoadProcAddress(_mysql_stmt_bind_result, 'mysql_stmt_bind_result');
3084
  asm
3085
    MOV     ESP, EBP
3086
    POP     EBP
3087
    JMP     [_mysql_stmt_bind_result]
3088
  end;
3089
end;
3090
3091
var
3092
  _mysql_stmt_close: FARPROC;
3093
3094
function mysql_stmt_close(stmt: PMYSQL_STMT): my_bool;
3095
begin
3096
  if _mysql_stmt_close=nil
3097
  then
3098
    LoadProcAddress(_mysql_stmt_close, 'mysql_stmt_close');
3099
  asm
3100
    MOV     ESP, EBP
3101
    POP     EBP
3102
    JMP     [_mysql_stmt_close]
3103
  end;
3104
end;
3105
3106
var
3107
  _mysql_stmt_data_seek: FARPROC;
3108
3109
procedure mysql_stmt_data_seek(stmt: PMYSQL_STMT; offset: my_ulonglong);
3110
begin
3111
  if _mysql_stmt_data_seek=nil
3112
  then
3113
    LoadProcAddress(_mysql_stmt_data_seek, 'mysql_stmt_data_seek');
3114
  asm
3115
    MOV     ESP, EBP
3116
    POP     EBP
3117
    JMP     [_mysql_stmt_data_seek]
3118
  end;
3119
end;
3120
3121
var
3122
  _mysql_stmt_errno: FARPROC;
3123
3124
function mysql_stmt_errno(stmt: PMYSQL_STMT): DWORD;
3125
begin
3126
  if _mysql_stmt_errno=nil
3127
  then
3128
    LoadProcAddress(_mysql_stmt_errno, 'mysql_stmt_errno');
3129
  asm
3130
    MOV     ESP, EBP
3131
    POP     EBP
3132
    JMP     [_mysql_stmt_errno]
3133
  end;
3134
end;
3135
3136
var
3137
  _mysql_stmt_error: FARPROC;
3138
3139
function mysql_stmt_error(stmt: PMYSQL_STMT): PAnsiChar;
3140
begin
3141
  if _mysql_stmt_error=nil
3142
  then
3143
    LoadProcAddress(_mysql_stmt_error, 'mysql_stmt_error');
3144
  asm
3145
    MOV     ESP, EBP
3146
    POP     EBP
3147
    JMP     [_mysql_stmt_error]
3148
  end;
3149
end;
3150
3151
var
3152
  _mysql_stmt_execute: FARPROC;
3153
3154
function mysql_stmt_execute(stmt: PMYSQL_STMT): Integer;
3155
begin
3156
  if _mysql_stmt_execute=nil
3157
  then
3158
    LoadProcAddress(_mysql_stmt_execute, 'mysql_stmt_execute');
3159
  asm
3160
    MOV     ESP, EBP
3161
    POP     EBP
3162
    JMP     [_mysql_stmt_execute]
3163
  end;
3164
end;
3165
3166
var
3167
  _mysql_stmt_fetch: FARPROC;
3168
3169
function mysql_stmt_fetch(stmt: PMYSQL_STMT): Integer;
3170
begin
3171
  if _mysql_stmt_fetch=nil
3172
  then
3173
    LoadProcAddress(_mysql_stmt_fetch, 'mysql_stmt_fetch');
3174
  asm
3175
    MOV     ESP, EBP
3176
    POP     EBP
3177
    JMP     [_mysql_stmt_fetch]
3178
  end;
3179
end;
3180
3181
var
3182
  _mysql_stmt_fetch_column: FARPROC;
3183
3184
function mysql_stmt_fetch_column(stmt: PMYSQL_STMT; bind: PMYSQL_BIND; column: DWORD; offset: DWORD): Integer;
3185
begin
3186
  if _mysql_stmt_fetch_column=nil
3187
  then
3188
    LoadProcAddress(_mysql_stmt_fetch_column, 'mysql_stmt_fetch_column');
3189
  asm
3190
    MOV     ESP, EBP
3191
    POP     EBP
3192
    JMP     [_mysql_stmt_fetch_column]
3193
  end;
3194
end;
3195
3196
var
3197
  _mysql_stmt_field_count: FARPROC;
3198
3199
function mysql_stmt_field_count(stmt: PMYSQL_STMT): DWORD;
3200
begin
3201
  if _mysql_stmt_field_count=nil
3202
  then
3203
    LoadProcAddress(_mysql_stmt_field_count, 'mysql_stmt_field_count');
3204
  asm
3205
    MOV     ESP, EBP
3206
    POP     EBP
3207
    JMP     [_mysql_stmt_field_count]
3208
  end;
3209
end;
3210
3211
var
3212
  _mysql_stmt_free_result: FARPROC;
3213
3214
function mysql_stmt_free_result(stmt: PMYSQL_STMT): my_bool;
3215
begin
3216
  if _mysql_stmt_free_result=nil
3217
  then
3218
    LoadProcAddress(_mysql_stmt_free_result, 'mysql_stmt_free_result');
3219
  asm
3220
    MOV     ESP, EBP
3221
    POP     EBP
3222
    JMP     [_mysql_stmt_free_result]
3223
  end;
3224
end;
3225
3226
var
3227
  _mysql_stmt_init: FARPROC;
3228
3229
function mysql_stmt_init(_mysql: PMYSQL): PMYSQL_STMT;
3230
begin
3231
  if _mysql_stmt_init=nil
3232
  then
3233
    LoadProcAddress(_mysql_stmt_init, 'mysql_stmt_init');
3234
  asm
3235
    MOV     ESP, EBP
3236
    POP     EBP
3237
    JMP     [_mysql_stmt_init]
3238
  end;
3239
end;
3240
3241
var
3242
  _mysql_stmt_insert_id: FARPROC;
3243
3244
function mysql_stmt_insert_id(stmt: PMYSQL_STMT): my_ulonglong;
3245
begin
3246
  if _mysql_stmt_insert_id=nil
3247
  then
3248
    LoadProcAddress(_mysql_stmt_insert_id, 'mysql_stmt_insert_id');
3249
  asm
3250
    MOV     ESP, EBP
3251
    POP     EBP
3252
    JMP     [_mysql_stmt_insert_id]
3253
  end;
3254
end;
3255
3256
var
3257
  _mysql_stmt_num_rows: FARPROC;
3258
3259
function mysql_stmt_num_rows(stmt: PMYSQL_STMT): my_ulonglong;
3260
begin
3261
  if _mysql_stmt_num_rows=nil
3262
  then
3263
    LoadProcAddress(_mysql_stmt_num_rows, 'mysql_stmt_num_rows');
3264
  asm
3265
    MOV     ESP, EBP
3266
    POP     EBP
3267
    JMP     [_mysql_stmt_num_rows]
3268
  end;
3269
end;
3270
3271
var
3272
  _mysql_stmt_param_count: FARPROC;
3273
3274
function mysql_stmt_param_count(stmt: PMYSQL_STMT): DWORD;
3275
begin
3276
  if _mysql_stmt_param_count=nil
3277
  then
3278
    LoadProcAddress(_mysql_stmt_param_count, 'mysql_stmt_param_count');
3279
  asm
3280
    MOV     ESP, EBP
3281
    POP     EBP
3282
    JMP     [_mysql_stmt_param_count]
3283
  end;
3284
end;
3285
3286
var
3287
  _mysql_stmt_param_metadata: FARPROC;
3288
3289
function mysql_stmt_param_metadata(stmt: PMYSQL_STMT): PMYSQL_RES;
3290
begin
3291
  if _mysql_stmt_param_metadata=nil
3292
  then
3293
    LoadProcAddress(_mysql_stmt_param_metadata, 'mysql_stmt_param_metadata');
3294
  asm
3295
    MOV     ESP, EBP
3296
    POP     EBP
3297
    JMP     [_mysql_stmt_param_metadata]
3298
  end;
3299
end;
3300
3301
var
3302
  _mysql_stmt_prepare: FARPROC;
3303
3304
function mysql_stmt_prepare(stmt: PMYSQL_STMT; query: PAnsiChar; length: DWORD): Integer;
3305
begin
3306
  if _mysql_stmt_prepare=nil
3307
  then
3308
    LoadProcAddress(_mysql_stmt_prepare, 'mysql_stmt_prepare');
3309
  asm
3310
    MOV     ESP, EBP
3311
    POP     EBP
3312
    JMP     [_mysql_stmt_prepare]
3313
  end;
3314
end;
3315
3316
var
3317
  _mysql_stmt_reset: FARPROC;
3318
3319
function mysql_stmt_reset(stmt: PMYSQL_STMT): my_bool;
3320
begin
3321
  if _mysql_stmt_reset=nil
3322
  then
3323
    LoadProcAddress(_mysql_stmt_reset, 'mysql_stmt_reset');
3324
  asm
3325
    MOV     ESP, EBP
3326
    POP     EBP
3327
    JMP     [_mysql_stmt_reset]
3328
  end;
3329
end;
3330
3331
var
3332
  _mysql_stmt_result_metadata: FARPROC;
3333
3334
function mysql_stmt_result_metadata(stmt: PMYSQL_STMT): PMYSQL_RES;
3335
begin
3336
  if _mysql_stmt_result_metadata=nil
3337
  then
3338
    LoadProcAddress(_mysql_stmt_result_metadata, 'mysql_stmt_result_metadata');
3339
  asm
3340
    MOV     ESP, EBP
3341
    POP     EBP
3342
    JMP     [_mysql_stmt_result_metadata]
3343
  end;
3344
end;
3345
3346
var
3347
  _mysql_stmt_row_seek: FARPROC;
3348
3349
function mysql_stmt_row_seek(stmt: PMYSQL_STMT; offset: MYSQL_ROW_OFFSET): MYSQL_ROW_OFFSET;
3350
begin
3351
  if _mysql_stmt_row_seek=nil
3352
  then
3353
    LoadProcAddress(_mysql_stmt_row_seek, 'mysql_stmt_row_seek');
3354
  asm
3355
    MOV     ESP, EBP
3356
    POP     EBP
3357
    JMP     [_mysql_stmt_row_seek]
3358
  end;
3359
end;
3360
3361
var
3362
  _mysql_stmt_row_tell: FARPROC;
3363
3364
function mysql_stmt_row_tell(stmt: PMYSQL_STMT): MYSQL_ROW_OFFSET;
3365
begin
3366
  if _mysql_stmt_row_tell=nil
3367
  then
3368
    LoadProcAddress(_mysql_stmt_row_tell, 'mysql_stmt_row_tell');
3369
  asm
3370
    MOV     ESP, EBP
3371
    POP     EBP
3372
    JMP     [_mysql_stmt_row_tell]
3373
  end;
3374
end;
3375
3376
var
3377
  _mysql_stmt_send_long_data: FARPROC;
3378
3379
function mysql_stmt_send_long_data(stmt: PMYSQL_STMT; parameter_number: DWORD; data: PAnsiChar; length: DWORD): my_bool;
3380
begin
3381
  if _mysql_stmt_send_long_data=nil
3382
  then
3383
    LoadProcAddress(_mysql_stmt_send_long_data, 'mysql_stmt_send_long_data');
3384
  asm
3385
    MOV     ESP, EBP
3386
    POP     EBP
3387
    JMP     [_mysql_stmt_send_long_data]
3388
  end;
3389
end;
3390
3391
var
3392
  _mysql_stmt_sqlstate: FARPROC;
3393
3394
function mysql_stmt_sqlstate(stmt: PMYSQL_STMT): PAnsiChar;
3395
begin
3396
  if _mysql_stmt_sqlstate=nil
3397
  then
3398
    LoadProcAddress(_mysql_stmt_sqlstate, 'mysql_stmt_sqlstate');
3399
  asm
3400
    MOV     ESP, EBP
3401
    POP     EBP
3402
    JMP     [_mysql_stmt_sqlstate]
3403
  end;
3404
end;
3405
3406
var
3407
  _mysql_stmt_store_result: FARPROC;
3408
3409
function mysql_stmt_store_result(stmt: PMYSQL_STMT): Integer;
3410
begin
3411
  if _mysql_stmt_store_result=nil
3412
  then
3413
    LoadProcAddress(_mysql_stmt_store_result, 'mysql_stmt_store_result');
3414
  asm
3415
    MOV     ESP, EBP
3416
    POP     EBP
3417
    JMP     [_mysql_stmt_store_result]
3418
  end;
3419
end;
3420
3421
3422
{$WARNINGS ON}
3423
{.$WARN NO_RETVAL ON}
3424
3425
//Create initialized memory block for Bindings
3426
function mysql_bind_init(Count: Integer): PMYSQL_BIND;
3427
var
3428
  Size: Integer;
3429
begin
3430
  Result := niL;
3431
  if Count>0
3432
  then begin
3433
    if internal_libmysql_ClientVersion>=50100
3434
    then
3435
      Size := SizeOf(TMYSQL_BIND501)
3436
    else
3437
    if internal_libmysql_ClientVersion>=50000
3438
    then
3439
      Size := SizeOf(TMYSQL_BIND500)
3440
    else
3441
    if internal_libmysql_ClientVersion>=40100
3442
    then
3443
      Size := SizeOf(TMYSQL_BIND401)
3444
    else
3445
      exit;
3446
    Result := AllocMem(Count*Size);
3447
  end;
3448
end;
3449
3450
//Copy mySQL_Bind to bind record array
3451
function mysql_bind_copy_bind(bind: PMYSQL_BIND; Index: Integer; const mySQL_Bind: TMYSQL_BIND): Boolean;
3452
begin
3453
  Result := False;
3454
  if bind<>nil
3455
  then begin
3456
    if internal_libmysql_ClientVersion>=50100
3457
    then begin
3458
      inc(PMYSQL_BIND501(bind), Index);
3459
      move(mySQL_Bind, bind^, SizeOf(TMYSQL_BIND501));
3460
      Result := true;
3461
    end
3462
    else
3463
    if internal_libmysql_ClientVersion>=50000
3464
    then begin
3465
      inc(PMYSQL_BIND500(bind), Index);
3466
      TMYSQL_BIND500(bind^).length := mySQL_Bind.length;
3467
      TMYSQL_BIND500(bind^).is_null := mySQL_Bind.is_null;
3468
      TMYSQL_BIND500(bind^).buffer := mySQL_Bind.buffer;
3469
      TMYSQL_BIND500(bind^).error := mySQL_Bind.error;
3470
      TMYSQL_BIND500(bind^).buffer_type := mySQL_Bind.buffer_type;
3471
      TMYSQL_BIND500(bind^).buffer_length := mySQL_Bind.buffer_length;
3472
      TMYSQL_BIND500(bind^).row_ptr := mySQL_Bind.row_ptr;
3473
      TMYSQL_BIND500(bind^).offset := mySQL_Bind.offset;
3474
      TMYSQL_BIND500(bind^).length_value := mySQL_Bind.length_value;
3475
      TMYSQL_BIND500(bind^).param_number := mySQL_Bind.param_number;
3476
      TMYSQL_BIND500(bind^).pack_length := mySQL_Bind.pack_length;
3477
      TMYSQL_BIND500(bind^).error_value := mySQL_Bind.error_value;
3478
      TMYSQL_BIND500(bind^).is_unsigned := mySQL_Bind.is_unsigned;
3479
      TMYSQL_BIND500(bind^).long_data_used := mySQL_Bind.long_data_used;
3480
      TMYSQL_BIND500(bind^).is_null_value := mySQL_Bind.is_null_value;
3481
      TMYSQL_BIND500(bind^).store_param_func := mySQL_Bind.store_param_func;
3482
      TMYSQL_BIND500(bind^).fetch_result := mySQL_Bind.fetch_result;
3483
      TMYSQL_BIND500(bind^).skip_result := mySQL_Bind.skip_result;
3484
      Result := true;
3485
    end
3486
    else
3487
    if internal_libmysql_ClientVersion>=40100
3488
    then begin
3489
      inc(PMYSQL_BIND401(bind), Index);
3490
      TMYSQL_BIND401(bind^).length := mySQL_Bind.length;
3491
      TMYSQL_BIND401(bind^).is_null := mySQL_Bind.is_null;
3492
      TMYSQL_BIND401(bind^).buffer := mySQL_Bind.buffer;
3493
      TMYSQL_BIND401(bind^).buffer_type := mySQL_Bind.buffer_type;
3494
      TMYSQL_BIND401(bind^).buffer_length := mySQL_Bind.buffer_length;
3495
      TMYSQL_BIND401(bind^).row_ptr := mySQL_Bind.row_ptr;
3496
      TMYSQL_BIND401(bind^).offset := mySQL_Bind.offset;
3497
      TMYSQL_BIND401(bind^).length_value := mySQL_Bind.length_value;
3498
      TMYSQL_BIND401(bind^).param_number := mySQL_Bind.param_number;
3499
      TMYSQL_BIND401(bind^).pack_length := mySQL_Bind.pack_length;
3500
      TMYSQL_BIND401(bind^).is_unsigned := mySQL_Bind.is_unsigned;
3501
      TMYSQL_BIND401(bind^).long_data_used := mySQL_Bind.long_data_used;
3502
      TMYSQL_BIND401(bind^).is_null_value := mySQL_Bind.is_null_value;
3503
      TMYSQL_BIND401(bind^).store_param_func := mySQL_Bind.store_param_func;
3504
      TMYSQL_BIND401(bind^).fetch_result := mySQL_Bind.fetch_result;
3505
      TMYSQL_BIND401(bind^).skip_result := mySQL_Bind.skip_result;
3506
      Result := true;
3507
    end;
3508
  end;
3509
end;
3510
3511
//Copy params bind record array
3512
function mysql_bind_set_param(bind: PMYSQL_BIND; Index: Integer;
3513
                              buffer_type: enum_field_types;
3514
                              buffer: Pointer;         // buffer to get/put data
3515
                              buffer_length: DWORD;
3516
                              length: PDWORD;          // output length pointer
3517
                              is_null: Pmy_bool        // Pointer to null indicator
3518
                              ): Boolean;
3519
begin
3520
  Result := False;
3521
  if bind<>nil
3522
  then begin
3523
    if internal_libmysql_ClientVersion>=50100
3524
    then begin
3525
      inc(PMYSQL_BIND501(bind), Index);
3526
      TMYSQL_BIND501(bind^).length := length;
3527
      TMYSQL_BIND501(bind^).is_null := is_null;
3528
      TMYSQL_BIND501(bind^).buffer := buffer;
3529
      TMYSQL_BIND501(bind^).buffer_length := buffer_length;
3530
      TMYSQL_BIND501(bind^).buffer_type := buffer_type;
3531
      Result := true;
3532
    end
3533
    else
3534
    if internal_libmysql_ClientVersion>=50000
3535
    then begin
3536
      inc(PMYSQL_BIND500(bind), Index);
3537
      TMYSQL_BIND500(bind^).length := length;
3538
      TMYSQL_BIND500(bind^).is_null := is_null;
3539
      TMYSQL_BIND500(bind^).buffer := buffer;
3540
      TMYSQL_BIND500(bind^).buffer_length := buffer_length;
3541
      TMYSQL_BIND500(bind^).buffer_type := buffer_type;
3542
      Result := true;
3543
    end
3544
    else
3545
    if internal_libmysql_ClientVersion>=40100
3546
    then begin
3547
      inc(PMYSQL_BIND401(bind), Index);
3548
      TMYSQL_BIND401(bind^).length := length;
3549
      TMYSQL_BIND401(bind^).is_null := is_null;
3550
      TMYSQL_BIND401(bind^).buffer := buffer;
3551
      TMYSQL_BIND401(bind^).buffer_length := buffer_length;
3552
      TMYSQL_BIND401(bind^).buffer_type := buffer_type;
3553
      Result := true;
3554
    end;
3555
  end;
3556
end;
3557
3558
function MySql_StrLen(const Str: PAnsiChar): Cardinal;
3559
asm
3560
        test    Str, Str
3561
        jz      @NoString
3562
        mov     edx, Str
3563
        xor     ecx, ecx
3564
@Scan:  cmp     cl, [eax+0]
3565
        jz      @add_0
3566
        cmp     cl, [eax+1]
3567
        jz      @add_1
3568
        cmp     cl, [eax+2]
3569
        jz      @add_2
3570
        cmp     cl, [eax+3]
3571
        jz      @add_3
3572
        add     eax, 4
3573
        jmp     @scan
3574
@add_3: inc     eax
3575
@add_2: inc     eax
3576
@add_1: inc     eax
3577
@add_0: sub     eax, edx
3578
@NoString:
3579
end;
3580
3581
{$IFDEF Unicode}
3582
function EscapeString(const Str: String): String;
3583
var
3584
  L: Integer;
3585
  src, dest: PChar;
3586
  ch: Char;
3587
begin
3588
  L := Length(Str);
3589
  SetLength(Result, Length(Str)*2);
3590
  src := Pointer(Str); dest := Pointer(Result);
3591
  while L>0 do
3592
  begin
3593
    ch := src^;
3594
    if (ch='\') or (ch='"')
3595
    then begin
3596
      dest^ := '\'; inc(dest);
3597
    end
3598
    else
3599
    if ch=#26
3600
    then begin
3601
      dest^ := '\'; inc(dest); ch := 'Z';
3602
    end
3603
    else
3604
    if ch=#13
3605
    then begin
3606
      dest^ := '\'; inc(dest); ch := 'r';
3607
    end
3608
    else
3609
    if ch=#10
3610
    then begin
3611
      dest^ := '\'; inc(dest); ch := 'n';
3612
    end;
3613
    dest^ := ch; inc(dest);
3614
    inc(src); dec(L);
3615
  end;
3616
  L := (Integer(Dest)-Integer(Result)) shr 1;
3617
  SetLength(Result, L);
3618
end;
3619
{$ENDIF}
3620
3621
function EscapeString(const Str: AnsiString): AnsiString;
3622
var
3623
  L, d: Integer;
3624
  src, dest: PAnsiChar;
3625
  ch: AnsiChar;
3626
  {$IFDEF Unicode}
3627
  CP: Word;
3628
  {$ENDIF}
3629
begin
3630
  {$IFDEF Unicode}
3631
  CP := DefaultSystemCodePage;
3632
  {$ENDIF}
3633
  L := Length(Str);
3634
  SetLength(Result, Length(Str)*2);
3635
  src := Pointer(Str); dest := Pointer(Result);
3636
  while L>0 do
3637
  begin
3638
    if src^=#0
3639
    then begin
3640
      dest^ := #0; inc(dest); inc(src); dec(L);
3641
    end
3642
    else begin
3643
      {$IFDEF Unicode}
3644
      d := Integer(CharNextExA(CP, src, 0))-Integer(src);
3645
      {$ELSE}
3646
      d := Integer(CharNext(src))-Integer(src);
3647
      {$ENDIF}
3648
      if d>1
3649
      then begin
3650
        dec(L, d);
3651
        while d>0 do
3652
        begin
3653
          dest^ := src^;
3654
          inc(dest); inc(src);
3655
          dec(d);
3656
        end;
3657
      end
3658
      else begin
3659
        ch := src^;
3660
        if (ch='\') or (ch='"')
3661
        then begin
3662
          dest^ := '\'; inc(dest);
3663
        end
3664
        else
3665
        if ch=#26
3666
        then begin
3667
          dest^ := '\'; inc(dest); ch := 'Z';
3668
        end
3669
        else
3670
        if ch=#13
3671
        then begin
3672
          dest^ := '\'; inc(dest); ch := 'r';
3673
        end
3674
        else
3675
        if ch=#10
3676
        then begin
3677
          dest^ := '\'; inc(dest); ch := 'n';
3678
        end;
3679
        dest^ := ch; inc(dest);
3680
        inc(src); dec(L);
3681
      end;
3682
    end
3683
  end;
3684
  L := Integer(Dest)-Integer(Result);
3685
  SetLength(Result, L);
3686
end;
3687
3688
{$IFDEF Unicode}
3689
function QuoteString(const Str: String): String;
3690
begin
3691
  Result := '"' + EscapeString(Str) + '"';
3692
end;
3693
{$ENDIF}
3694
3695
function QuoteString(const Str: AnsiString): AnsiString; overload;
3696
begin
3697
  Result := '"' + EscapeString(Str) + '"';
3698
end;
3699
3700
{$IFDEF Unicode}
3701
function QuoteName(const Str: String): String;
3702
const
3703
  BacktickChar=#96; //'`' $60
3704
begin
3705
  Result := BacktickChar + Str + BacktickChar;
3706
end;
3707
{$ENDIF}
3708
3709
function QuoteName(const Str: AnsiString): AnsiString;
3710
const
3711
  BacktickChar=#96; //'`' $60
3712
begin
3713
  Result := BacktickChar + Str + BacktickChar;
3714
end;
3715
3716
{ Additional to normal escaped Characters this also escape "%" and "_". Use
3717
  it, if you want to search for wildcards in LIKE
3718
}
3719
{$IFDEF Unicode}
3720
function EscapeForLike(const Str: String): String;
3721
{   Note: To search for '\', specify it as '\\\\'
3722
    (the backslashes are stripped once by the parser
3723
    and another time when the pattern match is done, leaving a
3724
    single backslash to be matched). To search for '%' or '_',
3725
    specify it as '\%' or '\_'.
3726
}
3727
var
3728
  L: Integer;
3729
  src, dest: PChar;
3730
  ch: Char;
3731
begin
3732
  L := Length(Str);
3733
  SetLength(Result, Length(Str)*4);
3734
  src := Pointer(Str); dest := Pointer(Result);
3735
  while L>0 do
3736
  begin
3737
    ch := src^;
3738
    if ch='\'
3739
    then begin
3740
      dest^ := ch; inc(dest);
3741
      dest^ := ch; inc(dest);
3742
      dest^ := ch; inc(dest);
3743
    end
3744
    else
3745
    if (ch='"') or (ch='%') or (ch='_')
3746
    then begin
3747
      dest^ := '\'; inc(dest);
3748
    end
3749
    else
3750
    if ch=#26
3751
    then begin
3752
      dest^ := '\'; inc(dest);
3753
      ch := 'Z';
3754
    end
3755
    else
3756
    if ch=#13
3757
    then begin
3758
      dest^ := '\'; inc(dest);
3759
      ch := 'r';
3760
    end
3761
    else
3762
    if ch=#10
3763
    then begin
3764
      dest^ := '\'; inc(dest);
3765
      ch := 'n';
3766
    end;
3767
    dest^ := ch; inc(dest);
3768
    inc(src); dec(L);
3769
  end;
3770
  L := (Integer(dest)-Integer(Result)) shr 1;
3771
  SetLength(Result, L);
3772
end;
3773
{$ENDIF}
3774
3775
function EscapeForLike(const Str: AnsiString): AnsiString;
3776
var
3777
  L, d: Integer;
3778
  src, dest: PAnsiChar;
3779
  ch: AnsiChar;
3780
  {$IFDEF Unicode}
3781
  CP: Word;
3782
  {$ENDIF}
3783
begin
3784
  {$IFDEF Unicode}
3785
  CP := DefaultSystemCodePage;
3786
  {$ENDIF}
3787
  L := Length(Str);
3788
  SetLength(Result, Length(Str)*4);
3789
  src := Pointer(Str); dest := Pointer(Result);
3790
  while L>0 do
3791
  begin
3792
    if src^=#0
3793
    then begin
3794
      dest^ := #0; inc(dest); inc(src); dec(L);
3795
    end
3796
    else begin
3797
      {$IFDEF Unicode}
3798
      d := Integer(CharNextExA(CP, src, 0))-Integer(src);
3799
      {$ELSE}
3800
      d := Integer(CharNext(src))-Integer(src);
3801
      {$ENDIF}
3802
      if d>1
3803
      then begin
3804
        dec(L, d);
3805
        while d>0 do
3806
        begin
3807
          dest^ := src^;
3808
          inc(dest); inc(src);
3809
          dec(d);
3810
        end;
3811
      end
3812
      else begin
3813
        ch := src^;
3814
        if ch='\'
3815
        then begin
3816
          dest^ := ch; inc(dest);
3817
          dest^ := ch; inc(dest);
3818
          dest^ := ch; inc(dest);
3819
        end
3820
        else
3821
        if (ch='"') or (ch='%') or (ch='_')
3822
        then begin
3823
          dest^ := '\'; inc(dest);
3824
        end
3825
        else
3826
        if ch=#26
3827
        then begin
3828
          dest^ := '\'; inc(dest);
3829
          ch := 'Z';
3830
        end
3831
        else
3832
        if ch=#13
3833
        then begin
3834
          dest^ := '\'; inc(dest);
3835
          ch := 'r';
3836
        end
3837
        else
3838
        if ch=#10
3839
        then begin
3840
          dest^ := '\'; inc(dest);
3841
          ch := 'n';
3842
        end;
3843
        dest^ := ch; inc(dest);
3844
        inc(src); dec(L);
3845
      end;
3846
    end
3847
  end;
3848
  L := Integer(dest)-Integer(Result);
3849
  SetLength(Result, L);
3850
end;
3851
3852
function FullFieldname(const table, field: String): String;
3853
begin
3854
  Result := QuoteName(table) + '.' + QuoteName(field);
3855
end;
3856
3857
function libmysql_load(name: PChar): Tlibmysql_status;
3858
  procedure assign_proc(var proc: FARPROC; name: PAnsiChar);
3859
  begin
3860
    proc := GetProcAddress(libmysql_handle, name);
3861
    if proc = nil
3862
    then
3863
      internal_libmysql_status := LIBMYSQL_INCOMPATIBLE
3864
    else
3865
      PushProc(@proc);
3866
  end;
3867
begin
3868
  libmysql_free;
3869
  if name = nil then name := 'libmysql.dll';
3870
  libmysql_handle := LoadLibrary(name);
3871
  if libmysql_handle = 0
3872
  then
3873
    internal_libmysql_status := LIBMYSQL_MISSING
3874
  else begin
3875
    internal_libmysql_status := LIBMYSQL_READY;
3876
    assign_proc(_mysql_num_rows, 'mysql_num_rows');
3877
    assign_proc(_mysql_num_fields, 'mysql_num_fields');
3878
    assign_proc(_mysql_eof, 'mysql_eof');
3879
    assign_proc(_mysql_fetch_field_direct, 'mysql_fetch_field_direct');
3880
    assign_proc(_mysql_fetch_fields, 'mysql_fetch_fields');
3881
    assign_proc(_mysql_row_tell, 'mysql_row_tell');
3882
    assign_proc(_mysql_field_tell, 'mysql_field_tell');
3883
    assign_proc(_mysql_field_count, 'mysql_field_count');
3884
    assign_proc(_mysql_affected_rows, 'mysql_affected_rows');
3885
    assign_proc(_mysql_insert_id, 'mysql_insert_id');
3886
    assign_proc(_mysql_errno, 'mysql_errno');
3887
    assign_proc(_mysql_error, 'mysql_error');
3888
    assign_proc(_mysql_info, 'mysql_info');
3889
    assign_proc(_mysql_thread_id, 'mysql_thread_id');
3890
    assign_proc(_mysql_character_set_name, 'mysql_character_set_name');
3891
    assign_proc(_mysql_init, 'mysql_init');
3892
    {$IFDEF HAVE_OPENSSL}
3893
    assign_proc(_mysql_ssl_set, 'mysql_ssl_set');
3894
    assign_proc(_mysql_ssl_cipher, 'mysql_ssl_cipher');
3895
    assign_proc(_mysql_ssl_clear, 'mysql_ssl_clear');
3896
    {$ENDIF} // HAVE_OPENSSL
3897
    {$IFDEF USE_DEPRECATED}
3898
    assign_proc(_mysql_connect, 'mysql_connect');          //Old Client 3.23
3899
    {$ENDIF}
3900
    assign_proc(_mysql_change_user, 'mysql_change_user');
3901
    assign_proc(_mysql_real_connect, 'mysql_real_connect');
3902
    assign_proc(_mysql_close, 'mysql_close');
3903
    assign_proc(_mysql_select_db, 'mysql_select_db');
3904
    assign_proc(_mysql_query, 'mysql_query');
3905
    assign_proc(_mysql_send_query, 'mysql_send_query');
3906
    assign_proc(_mysql_read_query_result, 'mysql_read_query_result');
3907
    assign_proc(_mysql_real_query, 'mysql_real_query');
3908
    {$IFDEF USE_DEPRECATED}
3909
    assign_proc(_mysql_create_db, 'mysql_create_db');      //Old Client 3.23
3910
    assign_proc(_mysql_drop_db, 'mysql_drop_db');          //Old Client 3.23
3911
    {$ENDIF}
3912
    assign_proc(_mysql_shutdown, 'mysql_shutdown');
3913
    assign_proc(_mysql_dump_debug_info, 'mysql_dump_debug_info');
3914
    assign_proc(_mysql_refresh, 'mysql_refresh');
3915
    assign_proc(_mysql_kill, 'mysql_kill');
3916
    assign_proc(_mysql_ping, 'mysql_ping');
3917
    assign_proc(_mysql_stat, 'mysql_stat');
3918
    assign_proc(_mysql_get_server_info, 'mysql_get_server_info');
3919
    assign_proc(_mysql_get_client_info, 'mysql_get_client_info');
3920
    assign_proc(_mysql_get_host_info, 'mysql_get_host_info');
3921
    assign_proc(_mysql_get_proto_info, 'mysql_get_proto_info');
3922
    assign_proc(_mysql_list_dbs, 'mysql_list_dbs');
3923
    assign_proc(_mysql_list_tables, 'mysql_list_tables');
3924
    assign_proc(_mysql_list_fields, 'mysql_list_fields');
3925
    assign_proc(_mysql_list_processes, 'mysql_list_processes');
3926
    assign_proc(_mysql_store_result, 'mysql_store_result');
3927
    assign_proc(_mysql_use_result, 'mysql_use_result');
3928
    assign_proc(_mysql_options, 'mysql_options');
3929
    assign_proc(_mysql_free_result, 'mysql_free_result');
3930
    assign_proc(_mysql_data_seek, 'mysql_data_seek');
3931
    assign_proc(_mysql_row_seek, 'mysql_row_seek');
3932
    assign_proc(_mysql_field_seek, 'mysql_field_seek');
3933
    assign_proc(_mysql_fetch_row, 'mysql_fetch_row');
3934
    assign_proc(_mysql_fetch_lengths, 'mysql_fetch_lengths');
3935
    assign_proc(_mysql_fetch_field, 'mysql_fetch_field');
3936
    assign_proc(_mysql_escape_string, 'mysql_escape_string');
3937
    assign_proc(_mysql_real_escape_string, 'mysql_real_escape_string');
3938
    assign_proc(_mysql_debug, 'mysql_debug');
3939
    {$IFDEF USE_DEPRECATED}
3940
    assign_proc(_mysql_odbc_escape_string, 'mysql_odbc_escape_string'); //Removed from libmysql 5.0.54
3941
    assign_proc(_myodbc_remove_escape, 'myodbc_remove_escape');         //Removed - not supported as core-function
3942
    {$ENDIF}
3943
    assign_proc(_mysql_thread_safe, 'mysql_thread_safe');
3944
    _mysql_get_client_version := GetProcAddress(libmysql_handle, 'mysql_get_client_version');
3945
    if (_mysql_get_client_version=nil)
3946
    then
3947
      _mysql_get_client_version := @libmysql_ClientVersion_substitute;
3948
    PushProc(@_mysql_get_client_version);
3949
    internal_libmysql_ClientVersion := mysql_get_client_version;
3950
    _mysql_get_server_version := GetProcAddress(libmysql_handle, 'mysql_get_server_version');
3951
    if (_mysql_get_server_version=nil)
3952
    then
3953
      _mysql_get_server_version := @libmysql_ServerVersion_substitute;
3954
    PushProc(@_mysql_get_server_version);
3955
    if internal_libmysql_ClientVersion>=mysql_not_compatible_version
3956
    then
3957
      internal_libmysql_status := LIBMYSQL_INCOMPATIBLE;
3958
  end;
3959
  Result := internal_libmysql_status;
3960
end;
3961
3962
{ This kind of dynamic loading give the linker the chance to kick out all functions
3963
  never used by the application. Furthermore if a function is not exposed by the
3964
  library, but not needed by the application, it is ignored - same as it is done by
3965
  static linking. If you use the mysql-library in more than one thread, it is a good
3966
  idea to call this in the mainthread.
3967
}
3968
procedure libmysql_fast_load(name: PChar);
3969
begin
3970
  libmysql_free;
3971
  if name = nil then name := 'libmysql.dll';
3972
  libmysql_handle := LoadLibrary(name);
3973
  if libmysql_handle = 0
3974
  then begin
3975
    internal_libmysql_status := LIBMYSQL_MISSING;
3976
    raise Exception.CreateFmt(ELibraryNotFound, [name]);
3977
  end
3978
  else begin
3979
    internal_libmysql_ClientVersion := mysql_get_client_version;
3980
    if internal_libmysql_ClientVersion>=mysql_not_compatible_version
3981
    then begin
3982
      internal_libmysql_status := LIBMYSQL_INCOMPATIBLE;
3983
      raise Exception.CreateFmt(sLibMySql_Version_Incompatible, [mysql_get_client_info]);
3984
    end
3985
    else
3986
      internal_libmysql_status := LIBMYSQL_READY;
3987
  end;
3988
end;
3989
3990
procedure libmysql_free;
3991
begin
3992
  if libmysql_handle <> 0
3993
  then
3994
    FreeLibrary(libmysql_handle);
3995
  libmysql_handle := 0;
3996
  internal_libmysql_status := LIBMYSQL_UNDEFINED;
3997
  FinalizeLibmysql;
3998
end;
3999
4000
procedure libmysql_load_check;
4001
var
4002
  Old_libmysql_status: TLibMysql_status;
4003
  ErrorText: String;
4004
begin
4005
  if internal_libmysql_status<>LIBMYSQL_READY
4006
  then begin
4007
    Old_libmysql_status := internal_libmysql_status;
4008
    if libmysql_handle <> 0 then FreeLibrary(libmysql_handle);
4009
    libmysql_handle := 0;
4010
    internal_libmysql_status := LIBMYSQL_UNDEFINED;
4011
    case Old_libmysql_status of
4012
      LIBMYSQL_UNDEFINED: ErrorText := sLibMySql_Undefined;
4013
      LIBMYSQL_MISSING: ErrorText := sLibMySql_Missing;
4014
      LIBMYSQL_INCOMPATIBLE: ErrorText := sLibMySql_Incompatible;
4015
    end;
4016
    raise Exception.Create(ErrorText);
4017
  end;
4018
end;
4019
4020
function libmysql_status: Tlibmysql_status;
4021
begin
4022
  Result := internal_libmysql_status;
4023
end;
4024
4025
//current Client-Version as longword 3.23.58=32358
4026
function libmysql_ClientVersion: longword;
4027
begin
4028
  Result := internal_libmysql_ClientVersion;
4029
end;
4030
4031
{$IFDEF EmbeddedCharacterConvert}
4032
{$INCLUDE *_emb.inc}
4033
{$ENDIF}
4034
4035
{$IFDEF Win32CharacterConvert}
4036
{$INCLUDE *_win32.inc}
4037
{$ENDIF}
4038
4039
// -----------------------------------------------------------------------------------------------
4040
INITIALIZATION
4041
// -----------------------------------------------------------------------------------------------
4042
4043
  {$IFNDEF DONT_LOAD_DLL}
4044
  libmysql_fast_load(nil);
4045
  {$ENDIF} // DONT_LOAD_DLL
4046
4047
{$IFDEF Win32CharacterConvert}
4048
  DefaultMySqlCodePage := GetACP;
4049
{$ENDIF}
4050
4051
  Assert(SizeOf(TNET323)=272, 'Wrong size of TNET323');
4052
  Assert(SizeOf(TNET400)=292, 'Wrong size of TNET400');
4053
  Assert(SizeOf(TNET401)=620, 'Wrong size of TNET401');
4054
  Assert(SizeOf(TNET500)=620, 'Wrong size of TNET500');
4055
  Assert(SizeOf(TNET501)=620, 'Wrong size of TNET501');
4056
  Assert(SizeOf(TMYSQL323)=496, 'Wrong size of TMYSQL323');
4057
  Assert(SizeOf(TMYSQL400)=544, 'Wrong size of TMYSQL400');
4058
  Assert(SizeOf(TMYSQL401)=960, 'Wrong size of TMYSQL401');
4059
  Assert(SizeOf(TMYSQL500)=960, 'Wrong size of TMYSQL500');
4060
  Assert(SizeOf(TMYSQL501)=960, 'Wrong size of TMYSQL501');
4061
  Assert(SizeOf(TMYSQL_FIELD323)=32, 'Wrong size of TMYSQL_FIELD323');
4062
  Assert(SizeOf(TMYSQL_FIELD400)=40, 'Wrong size of TMYSQL_FIELD400');
4063
  Assert(SizeOf(TMYSQL_FIELD401)=80, 'Wrong size of TMYSQL_FIELD401');
4064
  Assert(SizeOf(TMYSQL_FIELD501)=84, 'Wrong size of TMYSQL_FIELD501');
4065
  Assert(SizeOf(TMYSQL_BIND401)=56, 'Wrong size of TMYSQL_BIND401');
4066
  Assert(SizeOf(TMYSQL_BIND500)=60, 'Wrong size of TMYSQL_BIND500');
4067
  Assert(SizeOf(TMYSQL_BIND501)=64, 'Wrong size of TMYSQL_BIND501');
4068
  Assert(SizeOf(TMYSQL_TIME)=36, 'Wrong size of TMYSQL_TIME');
4069
4070
// -----------------------------------------------------------------------------------------------
4071
FINALIZATION
4072
// -----------------------------------------------------------------------------------------------
4073
4074
  libmysql_free;
4075
4076
end.