~ubuntu-branches/debian/lenny/fpc/lenny

« back to all changes in this revision

Viewing changes to fpcsrc/packages/base/mysql/mysql.inc

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-05-17 17:12:11 UTC
  • mfrom: (3.1.9 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080517171211-9qi33xhd9evfa0kg
Tags: 2.2.0-dfsg1-9
[ Torsten Werner ]
* Add Mazen Neifer to Uploaders field.

[ Mazen Neifer ]
* Moved FPC sources into a version dependent directory from /usr/share/fpcsrc
  to /usr/share/fpcsrc/${FPCVERSION}. This allow installing more than on FPC
  release.
* Fixed far call issue in compiler preventing building huge binearies.
  (closes: #477743)
* Updated building dependencies, recomennded and suggested packages.
* Moved fppkg to fp-utils as it is just a helper tool and is not required by
  compiler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
  This file is created by H2Pas, and thereafter heavily edited to make it
 
3
  readable and dynamically loadable.
 
4
 
 
5
  The goal was not to be complete, but to make it work and maintainable.
 
6
 
 
7
  The mysql_com.h, mysql.h and some other files are merged together into this
 
8
  one file.
 
9
 
 
10
  Automatically converted by H2Pas 1.0.0 from mysql_com.h / mysql.h
 
11
  The following command line parameters were used:
 
12
    -p
 
13
    -D
 
14
    -l
 
15
    mysqlclient
 
16
    mysql_com.h / mysql.h
 
17
 
 
18
}
 
19
{$MODE objfpc}
 
20
{$MACRO on}
 
21
 
 
22
interface
 
23
 
 
24
uses
 
25
{$IFDEF LinkDynamically}
 
26
     Dynlibs, sysutils,
 
27
{$ENDIF}
 
28
     ctypes;
 
29
 
 
30
{$IFDEF Unix}
 
31
  {$DEFINE extdecl:=cdecl}
 
32
  const
 
33
    mysqllib = 'libmysqlclient.so';
 
34
{$ENDIF}
 
35
{$IFDEF Windows}
 
36
  {$DEFINE extdecl:=stdcall}
 
37
  const
 
38
    mysqllib = 'libmysql.dll';
 
39
{$ENDIF}
 
40
 
 
41
{$IFDEF mysql50}
 
42
  {$DEFINE mysql41}
 
43
{$ENDIF mysql50}
 
44
 
 
45
{$PACKRECORDS C}
 
46
 
 
47
  { Copyright (C) 2000-2003 MySQL AB
 
48
  
 
49
     This program is free software; you can redistribute it and/or modify
 
50
     it under the terms of the GNU General Public License as published by
 
51
     the Free Software Foundation; either version 2 of the License, or
 
52
     (at your option) any later version.
 
53
  
 
54
     This program is distributed in the hope that it will be useful,
 
55
     but WITHOUT ANY WARRANTY; without even the implied warranty of
 
56
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
57
     GNU General Public License for more details.
 
58
  
 
59
     You should have received a copy of the GNU General Public License
 
60
     along with this program; if not, write to the Free Software
 
61
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  }
 
62
 
 
63
    type
 
64
       my_bool = byte;
 
65
       Pmy_bool  = ^my_bool;
 
66
 
 
67
       PVIO = Pointer;
 
68
 
 
69
       Pgptr = ^gptr;
 
70
       gptr = ^char;
 
71
 
 
72
       Pmy_socket = ^my_socket;
 
73
       my_socket = longint;
 
74
       
 
75
       pppchar = ^ppchar;
 
76
       PPByte     = ^PByte;
 
77
 
 
78
{  ------------ Start of declaration in "mysql_com.h"   ---------------------  }
 
79
 
 
80
  {
 
81
  ** Common definition between mysql server & client
 
82
   }
 
83
 
 
84
  { Field/table name length  }
 
85
 
 
86
  const
 
87
     NAME_LEN = 64;
 
88
     HOSTNAME_LENGTH = 60;
 
89
     USERNAME_LENGTH = 16;
 
90
     SERVER_VERSION_LENGTH = 60;
 
91
     SQLSTATE_LENGTH = 5;
 
92
     LOCAL_HOST = 'localhost';
 
93
     LOCAL_HOST_NAMEDPIPE = '.';
 
94
 
 
95
  const
 
96
     MYSQL_NAMEDPIPE = 'MySQL';
 
97
     MYSQL_SERVICENAME = 'MySQL';
 
98
 
 
99
  type
 
100
     enum_server_command = (COM_SLEEP,COM_QUIT,COM_INIT_DB,COM_QUERY,
 
101
       COM_FIELD_LIST,COM_CREATE_DB,COM_DROP_DB,
 
102
       COM_REFRESH,COM_SHUTDOWN,COM_STATISTICS,
 
103
       COM_PROCESS_INFO,COM_CONNECT,COM_PROCESS_KILL,
 
104
       COM_DEBUG,COM_PING,COM_TIME,COM_DELAYED_INSERT,
 
105
       COM_CHANGE_USER,COM_BINLOG_DUMP,COM_TABLE_DUMP,
 
106
       COM_CONNECT_OUT,COM_REGISTER_SLAVE,
 
107
{$IFDEF mysql50}
 
108
       COM_STMT_PREPARE, COM_STMT_EXECUTE, COM_STMT_SEND_LONG_DATA, COM_STMT_CLOSE,
 
109
       COM_STMT_RESET, COM_SET_OPTION, COM_STMT_FETCH,
 
110
{$ELSE}
 
111
  {$IFDEF mysql41}
 
112
       COM_PREPARE,COM_EXECUTE,COM_LONG_DATA,COM_CLOSE_STMT,
 
113
       COM_RESET_STMT,COM_SET_OPTION,
 
114
  {$ENDIF}
 
115
{$ENDIF}
 
116
       COM_END
 
117
       );
 
118
 
 
119
  {
 
120
    Length of random string sent by server on handshake; this is also length of
 
121
    obfuscated password, recieved from client
 
122
   }
 
123
 
 
124
  const
 
125
     SCRAMBLE_LENGTH = 20;
 
126
     SCRAMBLE_LENGTH_323 = 8;
 
127
 
 
128
  { length of password stored in the db: new passwords are preceeded with '*'  }
 
129
 
 
130
     SCRAMBLED_PASSWORD_CHAR_LENGTH = SCRAMBLE_LENGTH*2+1;
 
131
     SCRAMBLED_PASSWORD_CHAR_LENGTH_323 = SCRAMBLE_LENGTH_323*2;
 
132
 
 
133
 
 
134
       NOT_NULL_FLAG = 1;       //  Field can't be NULL
 
135
       PRI_KEY_FLAG = 2;        //  Field is part of a primary key
 
136
       UNIQUE_KEY_FLAG = 4;     //  Field is part of a unique key
 
137
       MULTIPLE_KEY_FLAG = 8;   //  Field is part of a key
 
138
       BLOB_FLAG = 16;          //  Field is a blob
 
139
       UNSIGNED_FLAG = 32;      //  Field is unsigned
 
140
       ZEROFILL_FLAG = 64;      //  Field is zerofill
 
141
       BINARY_FLAG = 128;       //  Field is binary
 
142
 
 
143
    { The following are only sent to new clients  }
 
144
 
 
145
       ENUM_FLAG = 256;            // field is an enum
 
146
       AUTO_INCREMENT_FLAG = 512;  // field is a autoincrement field
 
147
       TIMESTAMP_FLAG = 1024;      // Field is a timestamp
 
148
       SET_FLAG = 2048;            // field is a set
 
149
{$IFDEF mysql50}
 
150
       NO_DEFAULT_VALUE_FLAG=4096; // Field doesn't have default value
 
151
{$ENDIF}
 
152
       NUM_FLAG = 32768;           // Field is num (for clients)
 
153
       PART_KEY_FLAG = 16384;      // Intern; Part of some key
 
154
       GROUP_FLAG = 32768;         // Intern: Group field
 
155
       UNIQUE_FLAG = 65536;        // Intern: Used by sql_yacc
 
156
       BINCMP_FLAG = 131072;       // Intern: Used by sql_yacc
 
157
 
 
158
       REFRESH_GRANT = 1;          // Refresh grant tables
 
159
       REFRESH_LOG = 2;            // Start on new log file
 
160
       REFRESH_TABLES = 4;         // close all tables
 
161
       REFRESH_HOSTS = 8;          // Flush host cache
 
162
       REFRESH_STATUS = 16;        // Flush status variables
 
163
       REFRESH_THREADS = 32;       // Flush thread cache
 
164
       REFRESH_SLAVE = 64;         // Reset master info and restart slave thread
 
165
       REFRESH_MASTER = 128;       // Remove all bin logs in the index and truncate the index
 
166
 
 
167
    { The following can't be set with mysql_refresh()  }
 
168
       REFRESH_READ_LOCK = 16384;          // Lock tables for read
 
169
       REFRESH_FAST = 32768;               // Intern flag
 
170
       REFRESH_QUERY_CACHE = 65536;        // RESET (remove all queries) from query cache
 
171
       REFRESH_QUERY_CACHE_FREE = $20000;  // pack query cache
 
172
 
 
173
       REFRESH_DES_KEY_FILE = $40000;
 
174
       REFRESH_USER_RESOURCES = $80000;
 
175
 
 
176
       CLIENT_LONG_PASSWORD = 1;           // new more secure passwords
 
177
       CLIENT_FOUND_ROWS = 2;              // Found instead of affected rows
 
178
       CLIENT_LONG_FLAG = 4;               // Get all column flags
 
179
       CLIENT_CONNECT_WITH_DB = 8;         // One can specify db on connect
 
180
       CLIENT_NO_SCHEMA = 16;              // Don't allow database.table.column
 
181
       CLIENT_COMPRESS = 32;               // Can use compression protocol
 
182
       CLIENT_ODBC = 64;                   // Odbc client
 
183
       CLIENT_LOCAL_FILES = 128;           // Can use LOAD DATA LOCAL
 
184
       CLIENT_IGNORE_SPACE = 256;          // Ignore spaces before '('
 
185
       CLIENT_PROTOCOL_41 = 512;           // New 4.1 protocol
 
186
       CLIENT_INTERACTIVE = 1024;          // This is an interactive client
 
187
       CLIENT_SSL = 2048;                  // Switch to SSL after handshake
 
188
       CLIENT_IGNORE_SIGPIPE = 4096;       // IGNORE sigpipes
 
189
       CLIENT_TRANSACTIONS = 8192;         // Client knows about transactions
 
190
       CLIENT_RESERVED = 16384;            // Old flag for 4.1 protocol
 
191
       CLIENT_SECURE_CONNECTION = 32768;   // New 4.1 authentication
 
192
       CLIENT_MULTI_STATEMENTS = 65536;    // Enable/disable multi-stmt support
 
193
       CLIENT_MULTI_RESULTS = 131072;      // Enable/disable multi-results
 
194
       CLIENT_REMEMBER_OPTIONS : cardinal = 1 shl 31;
 
195
 
 
196
 
 
197
       SERVER_STATUS_IN_TRANS = 1;         // Transaction has started
 
198
       SERVER_STATUS_AUTOCOMMIT = 2;       // Server in auto_commit mode
 
199
       SERVER_STATUS_MORE_RESULTS = 4;     // More results on server
 
200
       SERVER_MORE_RESULTS_EXISTS = 8;     // Multi query - next query exists
 
201
       SERVER_QUERY_NO_GOOD_INDEX_USED = 16;
 
202
       SERVER_QUERY_NO_INDEX_USED = 32;
 
203
{$IFDEF mysql50}
 
204
    { The server was able to fulfill the clients request and opened a
 
205
      read-only non-scrollable cursor for a query. This flag comes
 
206
      in reply to COM_STMT_EXECUTE and COM_STMT_FETCH commands. }
 
207
       SERVER_STATUS_CURSOR_EXISTS = 64;
 
208
    { This flag is sent when a read-only cursor is exhausted, in reply to
 
209
      COM_STMT_FETCH command. }
 
210
       SERVER_STATUS_LAST_ROW_SENT = 128;
 
211
{$ENDIF}
 
212
       SERVER_STATUS_DB_DROPPED = 256;     // A database was dropped
 
213
{$IFDEF mysql50}
 
214
       SERVER_STATUS_NO_BACKSLASH_ESCAPES = 512;
 
215
{$ENDIF}
 
216
 
 
217
{$IFDEF mysql41}
 
218
       MYSQL_ERRMSG_SIZE = 512;
 
219
{$ELSE}
 
220
       MYSQL_ERRMSG_SIZE = 200;
 
221
{$ENDIF}
 
222
       NET_READ_TIMEOUT = 30;              // Timeout on read
 
223
       NET_WRITE_TIMEOUT = 60;             // Timeout on write
 
224
       NET_WAIT_TIMEOUT = 8*60*60;         // Wait for new query
 
225
{$IFDEF mysql50}
 
226
       ONLY_KILL_QUERY = 1;
 
227
{$ENDIF}
 
228
 
 
229
 
 
230
    const
 
231
       MAX_TINYINT_WIDTH = 3;           // Max width for a TINY w.o. sign
 
232
       MAX_SMALLINT_WIDTH = 5;          // Max width for a SHORT w.o. sign
 
233
       MAX_MEDIUMINT_WIDTH = 8;         // Max width for a INT24 w.o. sign
 
234
       MAX_INT_WIDTH = 10;              // Max width for a LONG w.o. sign
 
235
       MAX_BIGINT_WIDTH = 20;           // Max width for a LONGLONG
 
236
       MAX_CHAR_WIDTH = 255;            // Max length for a CHAR colum
 
237
       MAX_BLOB_WIDTH = 8192;           // Default width for blob
 
238
 
 
239
    type
 
240
       Pst_net = ^st_net;
 
241
       st_net = record
 
242
{ $if !defined(CHECK_EMBEDDED_DIFFERENCES) || !defined(EMBEDDED_LIBRARY)}
 
243
            vio : PVio;
 
244
            buff : Pbyte;
 
245
            buff_end : Pbyte;
 
246
            write_pos : Pbyte;
 
247
            read_pos : Pbyte;
 
248
            fd : my_socket;     // For Perl DBI/dbd
 
249
            max_packet : dword;
 
250
            max_packet_size : dword;
 
251
{$IFNDEF mysql41}
 
252
            last_errno : dword;
 
253
{$ENDIF}
 
254
            pkt_nr : dword;
 
255
            compress_pkt_nr : dword;
 
256
            write_timeout : dword;
 
257
            read_timeout : dword;
 
258
            retry_count : dword;
 
259
            fcntl : longint;
 
260
{$IFNDEF mysql41}
 
261
            last_error : array[0..(MYSQL_ERRMSG_SIZE)-1] of char;
 
262
            error : byte;
 
263
            return_errno : my_bool;
 
264
{$ENDIF}
 
265
            compress : my_bool;
 
266
    {   The following variable is set if we are doing several queries in one
 
267
        command ( as in LOAD TABLE ... FROM MASTER ),
 
268
        and do not want to confuse the client with OK at the wrong time }
 
269
            remain_in_buf : dword;
 
270
            length : dword;
 
271
            buf_length : dword;
 
272
            where_b : dword;
 
273
            return_status : Pdword;
 
274
            reading_or_writing : byte;
 
275
            save_char : char;
 
276
            no_send_ok : my_bool;     // For SPs and other things that do multiple stmts
 
277
{$IFDEF mysql50}
 
278
            no_send_eof : my_bool;    // For SPs' first version read-only cursors
 
279
            no_send_error : my_bool;  // Set if OK packet is already sent, and
 
280
                                      // we do not need to send error messages
 
281
{$ENDIF}
 
282
    {   Pointer to query object in query cache, do not equal NULL (0) for
 
283
        queries in cache that have not stored its results yet }
 
284
{ $endif}
 
285
{$IFDEF mysql41}
 
286
            last_error : array[0..(MYSQL_ERRMSG_SIZE)-1] of char;
 
287
            sqlstate : array[0..(SQLSTATE_LENGTH+1)-1] of char;
 
288
            last_errno : dword;
 
289
            error : byte;
 
290
{$ENDIF}
 
291
            query_cache_query : gptr;
 
292
{$IFDEF mysql41}
 
293
            report_error : my_bool;   // We should report error (we have unreported error)
 
294
            return_errno : my_bool;
 
295
{$ENDIF}
 
296
         end;
 
297
       NET = st_net;
 
298
       PNET = ^NET;
 
299
 
 
300
    const
 
301
       packet_error : culong = culong(not(0));
 
302
 
 
303
    type
 
304
       enum_field_types = (MYSQL_TYPE_DECIMAL,MYSQL_TYPE_TINY,
 
305
         MYSQL_TYPE_SHORT,MYSQL_TYPE_LONG,MYSQL_TYPE_FLOAT,
 
306
         MYSQL_TYPE_DOUBLE,MYSQL_TYPE_NULL,
 
307
         MYSQL_TYPE_TIMESTAMP,MYSQL_TYPE_LONGLONG,
 
308
         MYSQL_TYPE_INT24,MYSQL_TYPE_DATE,MYSQL_TYPE_TIME,
 
309
         MYSQL_TYPE_DATETIME,MYSQL_TYPE_YEAR,
 
310
         MYSQL_TYPE_NEWDATE,
 
311
{$IFDEF mysql50}
 
312
         MYSQL_TYPE_VARCHAR, MYSQL_TYPE_BIT, MYSQL_TYPE_NEWDECIMAL=246,
 
313
{$ENDIF}
 
314
         MYSQL_TYPE_ENUM := 247,
 
315
         MYSQL_TYPE_SET := 248,MYSQL_TYPE_TINY_BLOB := 249,
 
316
         MYSQL_TYPE_MEDIUM_BLOB := 250,MYSQL_TYPE_LONG_BLOB := 251,
 
317
         MYSQL_TYPE_BLOB := 252,MYSQL_TYPE_VAR_STRING := 253,
 
318
         MYSQL_TYPE_STRING := 254,MYSQL_TYPE_GEOMETRY := 255
 
319
         );
 
320
 
 
321
    { For backward compatibility  }
 
322
 
 
323
    const
 
324
       CLIENT_MULTI_QUERIES = CLIENT_MULTI_STATEMENTS;
 
325
       FIELD_TYPE_DECIMAL = MYSQL_TYPE_DECIMAL;
 
326
{$IFDEF mysql50}
 
327
       FIELD_TYPE_NEWDECIMAL = MYSQL_TYPE_NEWDECIMAL;
 
328
{$ENDIF}
 
329
       FIELD_TYPE_TINY = MYSQL_TYPE_TINY;
 
330
       FIELD_TYPE_SHORT = MYSQL_TYPE_SHORT;
 
331
       FIELD_TYPE_LONG = MYSQL_TYPE_LONG;
 
332
       FIELD_TYPE_FLOAT = MYSQL_TYPE_FLOAT;
 
333
       FIELD_TYPE_DOUBLE = MYSQL_TYPE_DOUBLE;
 
334
       FIELD_TYPE_NULL = MYSQL_TYPE_NULL;
 
335
       FIELD_TYPE_TIMESTAMP = MYSQL_TYPE_TIMESTAMP;
 
336
       FIELD_TYPE_LONGLONG = MYSQL_TYPE_LONGLONG;
 
337
       FIELD_TYPE_INT24 = MYSQL_TYPE_INT24;
 
338
       FIELD_TYPE_DATE = MYSQL_TYPE_DATE;
 
339
       FIELD_TYPE_TIME = MYSQL_TYPE_TIME;
 
340
       FIELD_TYPE_DATETIME = MYSQL_TYPE_DATETIME;
 
341
       FIELD_TYPE_YEAR = MYSQL_TYPE_YEAR;
 
342
       FIELD_TYPE_NEWDATE = MYSQL_TYPE_NEWDATE;
 
343
       FIELD_TYPE_ENUM = MYSQL_TYPE_ENUM;
 
344
       FIELD_TYPE_SET = MYSQL_TYPE_SET;
 
345
       FIELD_TYPE_TINY_BLOB = MYSQL_TYPE_TINY_BLOB;
 
346
       FIELD_TYPE_MEDIUM_BLOB = MYSQL_TYPE_MEDIUM_BLOB;
 
347
       FIELD_TYPE_LONG_BLOB = MYSQL_TYPE_LONG_BLOB;
 
348
       FIELD_TYPE_BLOB = MYSQL_TYPE_BLOB;
 
349
       FIELD_TYPE_VAR_STRING = MYSQL_TYPE_VAR_STRING;
 
350
       FIELD_TYPE_STRING = MYSQL_TYPE_STRING;
 
351
       FIELD_TYPE_CHAR = MYSQL_TYPE_TINY;
 
352
       FIELD_TYPE_INTERVAL = MYSQL_TYPE_ENUM;
 
353
       FIELD_TYPE_GEOMETRY = MYSQL_TYPE_GEOMETRY;
 
354
{$IFDEF mysql50}
 
355
       FIELD_TYPE_BIT = MYSQL_TYPE_BIT;
 
356
{$ENDIF}
 
357
    { Shutdown/kill enums and constants  }
 
358
    { Bits for THD::killable.  }
 
359
       MYSQL_SHUTDOWN_KILLABLE_CONNECT    : byte = 1 shl 0;
 
360
       MYSQL_SHUTDOWN_KILLABLE_TRANS      : byte = 1 shl 1;
 
361
       MYSQL_SHUTDOWN_KILLABLE_LOCK_TABLE : byte = 1 shl 2;
 
362
       MYSQL_SHUTDOWN_KILLABLE_UPDATE     : byte = 1 shl 3;
 
363
 
 
364
 
 
365
    {   We want levels to be in growing order of hardness (because we use number
 
366
        comparisons). Note that DEFAULT does not respect the growing property, but
 
367
        it's ok.  }
 
368
    type
 
369
       mysql_enum_shutdown_level = (SHUTDOWN_DEFAULT := 0,
 
370
         SHUTDOWN_WAIT_CONNECTIONS := 1, //MYSQL_SHUTDOWN_KILLABLE_CONNECT,     // wait for existing connections to finish
 
371
         SHUTDOWN_WAIT_TRANSACTIONS := 2, //MYSQL_SHUTDOWN_KILLABLE_TRANS,      // wait for existing trans to finish
 
372
         SHUTDOWN_WAIT_UPDATES := 8, //MYSQL_SHUTDOWN_KILLABLE_UPDATE,          // wait for existing updates to finish (=> no partial MyISAM update)
 
373
         SHUTDOWN_WAIT_ALL_BUFFERS := 16, //MYSQL_SHUTDOWN_KILLABLE_UPDATE shl 1,// flush InnoDB buffers and other storage engines' buffers
 
374
         SHUTDOWN_WAIT_CRITICAL_BUFFERS := 17, //(MYSQL_SHUTDOWN_KILLABLE_UPDATE shl 1)+1, // don't flush InnoDB buffers, flush other storage engines' buffers
 
375
    { Now the 2 levels of the KILL command  }
 
376
{ $if MYSQL_VERSION_ID >= 50000}
 
377
         KILL_QUERY := 254,
 
378
{ $endif}
 
379
         KILL_CONNECTION := 255
 
380
         );
 
381
 
 
382
{$IFDEF mysql50}
 
383
       enum_cursor_type = (CURSOR_TYPE_NO_CURSOR := 0,CURSOR_TYPE_READ_ONLY := 1,
 
384
         CURSOR_TYPE_FOR_UPDATE := 2,CURSOR_TYPE_SCROLLABLE := 4
 
385
         );
 
386
{$ENDIF}
 
387
 
 
388
    { options for mysql_set_option  }
 
389
       enum_mysql_set_option = (MYSQL_OPTION_MULTI_STATEMENTS_ON,
 
390
         MYSQL_OPTION_MULTI_STATEMENTS_OFF
 
391
         );
 
392
 
 
393
    function net_new_transaction(net : st_net) : st_net;
 
394
 
 
395
{$IFNDEF LinkDynamically}
 
396
    function my_net_init(net:PNET; vio:PVio):my_bool;cdecl;external mysqllib name 'my_net_init';
 
397
    procedure my_net_local_init(net:PNET);cdecl;external mysqllib name 'my_net_local_init';
 
398
    procedure net_end(net:PNET);cdecl;external mysqllib name 'net_end';
 
399
    procedure net_clear(net:PNET);cdecl;external mysqllib name 'net_clear';
 
400
    function net_realloc(net:PNET; length:dword):my_bool;cdecl;external mysqllib name 'net_realloc';
 
401
    function net_flush(net:PNET):my_bool;cdecl;external mysqllib name 'net_flush';
 
402
    function my_net_write(net:PNET; packet:Pchar; len:dword):my_bool;cdecl;external mysqllib name 'my_net_write';
 
403
    function net_write_command(net:PNET; command:byte; header:Pchar; head_len:dword; packet:Pchar;
 
404
               len:dword):my_bool;cdecl;external mysqllib name 'net_write_command';
 
405
    function net_real_write(net:PNET; packet:Pchar; len:dword):longint;cdecl;external mysqllib name 'net_real_write';
 
406
    function my_net_read(net:PNET):dword;cdecl;external mysqllib name 'my_net_read';
 
407
{$ENDIF}
 
408
    { The following function is not meant for normal usage
 
409
      Currently it's used internally by manager.c  }
 
410
 
 
411
    type
 
412
       Psockaddr = ^sockaddr;
 
413
       sockaddr = record
 
414
           // undefined structure
 
415
         end;
 
416
{$IFNDEF LinkDynamically}
 
417
    function my_connect(s:my_socket; name:Psockaddr; namelen:dword; timeout:dword):longint;cdecl;external mysqllib name 'my_connect';
 
418
{$ENDIF}
 
419
 
 
420
    type
 
421
       Prand_struct = ^rand_struct;
 
422
       rand_struct = record
 
423
            seed1 : dword;
 
424
            seed2 : dword;
 
425
            max_value : dword;
 
426
            max_value_dbl : double;
 
427
         end;
 
428
 
 
429
    { The following is for user defined functions  }
 
430
{$IFDEF mysql50}
 
431
       Item_result = (STRING_RESULT,REAL_RESULT,INT_RESULT,
 
432
         ROW_RESULT);
 
433
{$ELSE}
 
434
       Item_result = (STRING_RESULT := 0,REAL_RESULT,INT_RESULT,
 
435
         ROW_RESULT,DECIMAL_RESULT);
 
436
{$ENDIF}
 
437
       PItem_result = ^Item_result;
 
438
 
 
439
       Pst_udf_args = ^st_udf_args;
 
440
       st_udf_args = record
 
441
            arg_count : dword;           // Number of arguments
 
442
            arg_type : PItem_result;     // Pointer to item_results
 
443
            args : ^Pchar;               // Pointer to item_results
 
444
            lengths : Pdword;            // Length of string arguments
 
445
            maybe_null : Pchar;          // Length of string arguments
 
446
{$IFDEF mysql50}
 
447
            attributes : ^pchar;         // Pointer to attribute name
 
448
            attribute_lengths : ^dword;  // Length of attribute arguments
 
449
{$ENDIF}
 
450
         end;
 
451
       UDF_ARGS = st_udf_args;
 
452
       PUDF_ARGS = ^UDF_ARGS;
 
453
 
 
454
    { This holds information about the result  }
 
455
 
 
456
       Pst_udf_init = ^st_udf_init;
 
457
       st_udf_init = record
 
458
            maybe_null : my_bool;        // 1 if function can return NULL
 
459
            decimals : dword;            // for real functions
 
460
            max_length : dword;          // For string functions
 
461
            ptr : Pchar;                 // free pointer for function data
 
462
            const_item : my_bool;        // free pointer for function data
 
463
         end;
 
464
       UDF_INIT = st_udf_init;
 
465
       PUDF_INIT = ^UDF_INIT;
 
466
 
 
467
    { Constants when using compression  }
 
468
    const
 
469
       NET_HEADER_SIZE = 4;              // standard header size
 
470
       COMP_HEADER_SIZE = 3;             // compression header extra size
 
471
 
 
472
    { Prototypes to password functions  }
 
473
 
 
474
    { These functions are used for authentication by client and server and
 
475
      implemented in sql/password.c     }
 
476
{$IFNDEF LinkDynamically}
 
477
    procedure randominit(_para1:Prand_struct; seed1:dword; seed2:dword);cdecl;external mysqllib name 'randominit';
 
478
    function my_rnd(_para1:Prand_struct):double;cdecl;external mysqllib name 'my_rnd';
 
479
    procedure create_random_string(fto:Pchar; length:dword; rand_st:Prand_struct);cdecl;external mysqllib name 'create_random_string';
 
480
    procedure hash_password(fto:Pdword; password:Pchar; password_len:dword);cdecl;external mysqllib name 'hash_password';
 
481
    procedure make_scrambled_password_323(fto:Pchar; password:Pchar);cdecl;external mysqllib name 'make_scrambled_password_323';
 
482
    procedure scramble_323(fto:Pchar; message:Pchar; password:Pchar);cdecl;external mysqllib name 'scramble_323';
 
483
    function check_scramble_323(_para1:Pchar; message:Pchar; salt:Pdword):my_bool;cdecl;external mysqllib name 'check_scramble_323';
 
484
    procedure get_salt_from_password_323(res:Pdword; password:Pchar);cdecl;external mysqllib name 'get_salt_from_password_323';
 
485
    procedure make_password_from_salt_323(fto:Pchar; salt:Pdword);cdecl;external mysqllib name 'make_password_from_salt_323';
 
486
{$IFDEF mysql50}
 
487
    function octet2hex(fto:Pchar; str:Pchar; len:dword):pchar;cdecl;external mysqllib name 'octet2hex';
 
488
{$ENDIF}
 
489
    procedure make_scrambled_password(fto:Pchar; password:Pchar);cdecl;external mysqllib name 'make_scrambled_password';
 
490
    procedure scramble(fto:Pchar; message:Pchar; password:Pchar);cdecl;external mysqllib name 'scramble';
 
491
    function check_scramble(reply:Pchar; message:Pchar; hash_stage2:Pbyte):my_bool;cdecl;external mysqllib name 'check_scramble';
 
492
    procedure get_salt_from_password(res:Pbyte; password:Pchar);cdecl;external mysqllib name 'get_salt_from_password';
 
493
    procedure make_password_from_salt(fto:Pchar; hash_stage2:Pbyte);cdecl;external mysqllib name 'make_password_from_salt';
 
494
    { end of password.c  }
 
495
 
 
496
    function get_tty_password(opt_message:Pchar):Pchar;cdecl;external mysqllib name 'get_tty_password';
 
497
    function mysql_errno_to_sqlstate(mysql_errno:dword):Pchar;cdecl;external mysqllib name 'mysql_errno_to_sqlstate';
 
498
 
 
499
    { Some other useful functions  }
 
500
{$IFDEF mysql50}
 
501
    function modify_defaults_file(file_location:Pchar; option:Pchar; option_value:Pchar; section_name:Pchar; remove_option:longint):longint;cdecl;external mysqllib name 'load_defaults';
 
502
{$ENDIF}
 
503
 
 
504
    function load_defaults(conf_file:Pchar; groups:PPchar; argc:Plongint; argv:PPPchar):longint;cdecl;external mysqllib name 'load_defaults';
 
505
    function my_init:my_bool;cdecl;external mysqllib name 'my_init';
 
506
    function my_thread_init:my_bool;cdecl;external mysqllib name 'my_thread_init';
 
507
    procedure my_thread_end;cdecl;external mysqllib name 'my_thread_end';
 
508
{$ELSE}
 
509
    var
 
510
      my_init : function :my_bool;cdecl;
 
511
      my_thread_init : function :my_bool;cdecl;
 
512
      my_thread_end : procedure ;cdecl;
 
513
{$ENDIF}
 
514
 
 
515
{$ifdef _global_h}
 
516
{$IFNDEF LinkDynamically}
 
517
    function net_field_length(packet:PPuchar):culong;extdecl;external mysqllib name 'net_field_length_ll';
 
518
    function net_field_length_ll(packet:PPuchar):my_ulonglong;cdecl;external mysqllib name 'net_field_length_ll';
 
519
    function net_store_length(pkg:Pchar; length:ulonglong):Pchar;cdecl;external mysqllib name 'net_store_length';
 
520
{$ENDIF}
 
521
{$endif}
 
522
 
 
523
    const
 
524
       NULL_LENGTH : dword = dword(not(0)); // For net_store_length
 
525
 
 
526
    const
 
527
       MYSQL_STMT_HEADER = 4;
 
528
       MYSQL_LONG_DATA_HEADER = 6;
 
529
 
 
530
{  ------------ Stop of declaration in "mysql_com.h"   -----------------------  }
 
531
 
 
532
{ $include "mysql_time.h"}
 
533
{ $include "mysql_version.h"}
 
534
{ $include "typelib.h"}
 
535
{ $include "my_list.h" /* for LISTs used in 'MYSQL' and 'MYSQL_STMT' */}
 
536
 
 
537
{$IFNDEF LinkDynamically}
 
538
      var
 
539
         mysql_port : dword;cvar;external;
 
540
         mysql_unix_port : Pchar;cvar;external;
 
541
{$ENDIF}
 
542
 
 
543
      const
 
544
         CLIENT_NET_READ_TIMEOUT = 365*24*3600;     // Timeout on read
 
545
         CLIENT_NET_WRITE_TIMEOUT = 365*24*3600;    // Timeout on write
 
546
      
 
547
{$ifdef NETWARE}
 
548
(** unsupported pragma#pragma pack(push, 8)             /* 8 byte alignment */*)
 
549
{$endif}
 
550
 
 
551
    type
 
552
       Pst_mysql_field = ^st_mysql_field;
 
553
       st_mysql_field = record
 
554
            name : Pchar;             // Name of column
 
555
{$IFDEF mysql41}
 
556
            org_name : Pchar;         // Original column name, if an alias
 
557
{$ENDIF}
 
558
            table : Pchar;            // Table of column if column was a field
 
559
            org_table : Pchar;        // Org table name, if table was an alias
 
560
            db : Pchar;               // Database for table
 
561
{$IFDEF mysql41}
 
562
            catalog : Pchar;          // Catalog for table
 
563
{$ENDIF}
 
564
            def : Pchar;              // Default value (set by mysql_list_fields)
 
565
            length : dword;           // Width of column (create length)
 
566
            max_length : dword;       // Max width for selected set
 
567
{$IFDEF mysql41}
 
568
            name_length : dword;
 
569
            org_name_length : dword;
 
570
            table_length : dword;
 
571
            org_table_length : dword;
 
572
            db_length : dword;
 
573
            catalog_length : dword;
 
574
            def_length : dword;
 
575
{$ENDIF}
 
576
            flags : dword;            // Div flags
 
577
            decimals : dword;         // Number of decimals in field
 
578
{$IFDEF mysql41}
 
579
            charsetnr : dword;        // Character set
 
580
{$ENDIF}
 
581
            ftype : enum_field_types; // Type of field. See mysql_com.h for types
 
582
         end;
 
583
       MYSQL_FIELD = st_mysql_field;
 
584
       PMYSQL_FIELD = ^MYSQL_FIELD;
 
585
 
 
586
       PMYSQL_ROW = ^MYSQL_ROW;       // return data as array of strings
 
587
       MYSQL_ROW = ppchar;
 
588
 
 
589
       PMYSQL_FIELD_OFFSET = ^MYSQL_FIELD_OFFSET;     // offset to current field
 
590
       MYSQL_FIELD_OFFSET = dword;
 
591
 
 
592
    function IS_PRI_KEY(n : longint) : boolean;
 
593
    function IS_NOT_NULL(n : longint) : boolean;
 
594
    function IS_BLOB(n : longint) : boolean;
 
595
    function IS_NUM(t : enum_field_types) : boolean;
 
596
    function INTERNAL_NUM_FIELD(f : Pst_mysql_field) : boolean;
 
597
    function IS_NUM_FIELD(f : Pst_mysql_field) : boolean;
 
598
 
 
599
    type
 
600
{$if defined(NO_CLIENT_LONG_LONG)}
 
601
       my_ulonglong = dword;
 
602
{$elseif defined(mswindows)}
 
603
       my_ulonglong = int64;
 
604
{$else}
 
605
       my_ulonglong = qword;
 
606
{$endif}
 
607
       Pmy_ulonglong = ^my_ulonglong;
 
608
 
 
609
    const
 
610
       MYSQL_COUNT_ERROR = not (my_ulonglong(0));
 
611
 
 
612
    type
 
613
       Pst_mysql_rows = ^st_mysql_rows;
 
614
       st_mysql_rows = record
 
615
            next : Pst_mysql_rows;                    // list of rows
 
616
            data : MYSQL_ROW;
 
617
{$IFDEF mysql41}
 
618
            length : dword;
 
619
{$ENDIF}
 
620
         end;
 
621
       MYSQL_ROWS = st_mysql_rows;
 
622
       PMYSQL_ROWS = ^MYSQL_ROWS;
 
623
 
 
624
       PMYSQL_ROW_OFFSET = ^MYSQL_ROW_OFFSET;         // offset to current row
 
625
       MYSQL_ROW_OFFSET = MYSQL_ROWS;
 
626
 
 
627
{  ------------ Start of declaration in "my_alloc.h"     --------------------  }
 
628
{ $include "my_alloc.h"}
 
629
 
 
630
  const
 
631
     ALLOC_MAX_BLOCK_TO_DROP = 4096;
 
632
     ALLOC_MAX_BLOCK_USAGE_BEFORE_DROP = 10;
 
633
 
 
634
 { struct for once_alloc (block)  }
 
635
  type
 
636
     Pst_used_mem = ^st_used_mem;
 
637
     st_used_mem = record
 
638
          next : Pst_used_mem;   // Next block in use
 
639
          left : dword;          // memory left in block
 
640
          size : dword;          // size of block
 
641
       end;
 
642
     USED_MEM = st_used_mem;
 
643
     PUSED_MEM = ^USED_MEM;
 
644
 
 
645
 
 
646
     Pst_mem_root = ^st_mem_root;
 
647
     st_mem_root = record
 
648
          free : PUSED_MEM;      // blocks with free memory in it
 
649
          used : PUSED_MEM;      // blocks almost without free memory
 
650
          pre_alloc : PUSED_MEM; // preallocated block
 
651
          min_malloc : dword;    // if block have less memory it will be put in 'used' list
 
652
          block_size : dword;    // initial block size
 
653
          block_num : dword;     // allocated blocks counter
 
654
  {    first free block in queue test counter (if it exceed
 
655
       MAX_BLOCK_USAGE_BEFORE_DROP block will be dropped in 'used' list)     }
 
656
          first_block_usage : dword;
 
657
          error_handler : procedure ;cdecl;
 
658
       end;
 
659
     MEM_ROOT = st_mem_root;
 
660
     PMEM_ROOT = ^MEM_ROOT;
 
661
 
 
662
{  ------------ Stop of declaration in "my_alloc.h"    ----------------------  }
 
663
 
 
664
    type
 
665
       Pst_mysql_data = ^st_mysql_data;
 
666
       st_mysql_data = record
 
667
            rows : my_ulonglong;
 
668
            fields : dword;
 
669
            data : PMYSQL_ROWS;
 
670
            alloc : MEM_ROOT;
 
671
{ $if !defined(CHECK_EMBEDDED_DIFFERENCES) || defined(EMBEDDED_LIBRARY)}
 
672
{$IFDEF mysql41}
 
673
            prev_ptr : ^PMYSQL_ROWS;
 
674
{$ENDIF}
 
675
{ $endif}
 
676
         end;
 
677
         
 
678
       MYSQL_DATA = st_mysql_data;
 
679
       PMYSQL_DATA = ^MYSQL_DATA;
 
680
       mysql_option = (MYSQL_OPT_CONNECT_TIMEOUT,MYSQL_OPT_COMPRESS,
 
681
         MYSQL_OPT_NAMED_PIPE,MYSQL_INIT_COMMAND,
 
682
         MYSQL_READ_DEFAULT_FILE,MYSQL_READ_DEFAULT_GROUP,
 
683
         MYSQL_SET_CHARSET_DIR,MYSQL_SET_CHARSET_NAME,
 
684
         MYSQL_OPT_LOCAL_INFILE,MYSQL_OPT_PROTOCOL,
 
685
         MYSQL_SHARED_MEMORY_BASE_NAME,MYSQL_OPT_READ_TIMEOUT,
 
686
         MYSQL_OPT_WRITE_TIMEOUT,MYSQL_OPT_USE_RESULT,
 
687
         MYSQL_OPT_USE_REMOTE_CONNECTION,MYSQL_OPT_USE_EMBEDDED_CONNECTION,
 
688
         MYSQL_OPT_GUESS_CONNECTION,MYSQL_SET_CLIENT_IP,
 
689
         MYSQL_SECURE_AUTH
 
690
{$IFDEF MYSQL50}
 
691
         ,MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT
 
692
{$ENDIF}
 
693
         );
 
694
 
 
695
    const
 
696
       MAX_MYSQL_MANAGER_ERR = 256;
 
697
       MAX_MYSQL_MANAGER_MSG = 256;
 
698
       MANAGER_OK = 200;
 
699
       MANAGER_INFO = 250;
 
700
       MANAGER_ACCESS = 401;
 
701
       MANAGER_CLIENT_ERR = 450;
 
702
       MANAGER_INTERNAL_ERR = 500;
 
703
 
 
704
    type
 
705
       st_dynamic_array = record
 
706
            buffer : ^char;
 
707
            elements : cuint;
 
708
            max_element : cuint;
 
709
            alloc_increment : cuint;
 
710
            size_of_element : cuint;
 
711
         end;
 
712
       DYNAMIC_ARRAY = st_dynamic_array;
 
713
       Pst_dynamic_array = ^st_dynamic_array;
 
714
 
 
715
       Pst_mysql_options = ^st_mysql_options;
 
716
       st_mysql_options = record
 
717
            connect_timeout : dword;
 
718
{$IFNDEF mysql41}
 
719
            client_flag : dword;
 
720
            port : dword;
 
721
{$ELSE}
 
722
            read_timeout : dword;
 
723
            write_timeout : dword;
 
724
{$ENDIF}
 
725
{$IFDEF mysql41}
 
726
            port : dword;
 
727
            protocol : dword;
 
728
            client_flag : dword;
 
729
{$ENDIF}
 
730
            host : Pchar;
 
731
{$IFNDEF mysql41}
 
732
            init_command: Pchar;
 
733
{$ENDIF}
 
734
            user : Pchar;
 
735
            password : Pchar;
 
736
            unix_socket : Pchar;
 
737
            db : Pchar;
 
738
{$IFDEF mysql41}
 
739
            init_commands : Pst_dynamic_array;
 
740
{$ENDIF}
 
741
            my_cnf_file : Pchar;
 
742
            my_cnf_group : Pchar;
 
743
            charset_dir : Pchar;
 
744
            charset_name : Pchar;
 
745
            ssl_key : Pchar;                 // PEM key file
 
746
            ssl_cert : Pchar;                // PEM cert file
 
747
            ssl_ca : Pchar;                  // PEM CA file
 
748
            ssl_capath : Pchar;              // PEM directory of CA-s?
 
749
            ssl_cipher : Pchar;              // cipher to use
 
750
{$IFDEF mysql41}
 
751
            shared_memory_base_name : Pchar;
 
752
{$ENDIF}
 
753
            max_allowed_packet : dword;
 
754
            use_ssl : my_bool;               // if to use SSL or not
 
755
            compress : my_bool;
 
756
            named_pipe : my_bool;
 
757
    {  On connect, find out the replication role of the server, and
 
758
       establish connections to all the peers  }
 
759
            rpl_probe : my_bool;
 
760
    {  Each call to mysql_real_query() will parse it to tell if it is a read
 
761
       or a write, and direct it to the slave or the master      }
 
762
            rpl_parse : my_bool;
 
763
    {  If set, never read from a master, only from slave, when doing
 
764
       a read that is replication-aware    }
 
765
            no_master_reads : my_bool;
 
766
{ $if !defined(CHECK_EMBEDDED_DIFFERENCES) || defined(EMBEDDED_LIBRARY)}
 
767
{$IFDEF mysql41}
 
768
            separate_thread : my_bool;
 
769
{ $endif}
 
770
            methods_to_use : mysql_option;
 
771
            client_ip : Pchar;
 
772
            secure_auth : my_bool;           // Refuse client connecting to server if it uses old (pre-4.1.1) protocol
 
773
{$IFDEF mysql50}
 
774
            report_data_truncation : my_bool;// 0 - never report, 1 - always report (default)
 
775
{$ENDIF}
 
776
    { function pointers for local infile support  }
 
777
            local_infile_init : function (_para1:Ppointer; _para2:Pchar; _para3:pointer):longint;cdecl;
 
778
            local_infile_read : function (_para1:pointer; _para2:Pchar; _para3:dword):longint;
 
779
            local_infile_end : procedure (_para1:pointer);
 
780
            local_infile_error : function (_para1:pointer; _para2:Pchar; _para3:dword):longint;
 
781
            local_infile_userdata : pointer;
 
782
{$ENDIF}
 
783
         end;
 
784
 
 
785
       mysql_status = (MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,
 
786
         MYSQL_STATUS_USE_RESULT);
 
787
 
 
788
       mysql_protocol_type = (MYSQL_PROTOCOL_DEFAULT,MYSQL_PROTOCOL_TCP,
 
789
         MYSQL_PROTOCOL_SOCKET,MYSQL_PROTOCOL_PIPE,
 
790
         MYSQL_PROTOCOL_MEMORY);
 
791
 
 
792
    { There are three types of queries - the ones that have to go to
 
793
      the master, the ones that go to a slave, and the adminstrative
 
794
      type which must happen on the pivot connectioin     }
 
795
       mysql_rpl_type = (MYSQL_RPL_MASTER,MYSQL_RPL_SLAVE,MYSQL_RPL_ADMIN
 
796
         );
 
797
 
 
798
       charset_info_st = record
 
799
            number : cuint;
 
800
            primary_number : cuint;
 
801
            binary_number : cuint;
 
802
            state : cuint;
 
803
            csname : ^char;
 
804
            name : ^char;
 
805
            comment : ^char;
 
806
            tailoring : ^char;
 
807
            ftype : ^cuchar;
 
808
            to_lower : ^cuchar;
 
809
            to_upper : ^cuchar;
 
810
            sort_order : ^cuchar;
 
811
            contractions : ^cuint16;
 
812
            sort_order_big : ^pword;
 
813
            tab_to_uni : ^cuint16;
 
814
            tab_from_uni : pointer; // was ^MY_UNI_IDX
 
815
            state_map : ^cuchar;
 
816
            ident_map : ^cuchar;
 
817
            strxfrm_multiply : cuint;
 
818
            mbminlen : cuint;
 
819
            mbmaxlen : cuint;
 
820
            min_sort_char : cuint16;
 
821
            max_sort_char : cuint16;
 
822
            escape_with_backslash_is_dangerous : my_bool;
 
823
            cset : pointer; // was ^MY_CHARSET_HANDLER
 
824
            coll : pointer; // was ^MY_COLLATION_HANDLER;
 
825
         end;
 
826
       CHARSET_INFO = charset_info_st;
 
827
       Pcharset_info_st = ^charset_info_st;
 
828
 
 
829
{$IFDEF mysql50}
 
830
       Pcharacter_set = ^character_set;
 
831
       character_set = record
 
832
            number : dword;
 
833
            state : dword;
 
834
            csname : Pchar;
 
835
            name : Pchar;
 
836
            comment : Pchar;
 
837
            dir : Pchar;
 
838
            mbminlen : dword;
 
839
            mbmaxlen : dword;
 
840
         end;
 
841
       MY_CHARSET_INFO = character_set;
 
842
       PMY_CHARSET_INFO = ^MY_CHARSET_INFO;
 
843
{$ENDIF}
 
844
 
 
845
       Pst_mysql_methods = ^st_mysql_methods;
 
846
 
 
847
       Pst_mysql = ^st_mysql;
 
848
       st_mysql = record
 
849
            net : NET;                   // Communication parameters
 
850
            connector_fd : gptr;         // ConnectorFd for SSL
 
851
            host : Pchar;
 
852
            user : Pchar;
 
853
            passwd : Pchar;
 
854
            unix_socket : Pchar;
 
855
            server_version : Pchar;
 
856
            host_info : Pchar;
 
857
            info : Pchar;
 
858
            db : Pchar;
 
859
            charset : Pcharset_info_st;
 
860
            fields : PMYSQL_FIELD;
 
861
            field_alloc : MEM_ROOT;
 
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, not used by mysql 5.0 and up
 
865
            thread_id : dword;           // Id for connection in server
 
866
            packet_length : dword;
 
867
            port : dword;
 
868
            client_flag : dword;
 
869
            server_capabilities : dword;
 
870
            protocol_version : dword;
 
871
            field_count : dword;
 
872
            server_status : dword;
 
873
            server_language : dword;
 
874
            warning_count : dword;
 
875
            options : st_mysql_options;
 
876
            status : mysql_status;
 
877
            free_me : my_bool;           // If free in mysql_close
 
878
            reconnect : my_bool;         // set to 1 if automatic reconnect
 
879
            scramble : array[0..(SCRAMBLE_LENGTH+1)-1] of char;  // session-wide random string
 
880
    {  Set if this is the original connection, not a master or a slave we have
 
881
       added though mysql_rpl_probe() or mysql_set_master()/ mysql_add_slave()      }
 
882
            rpl_pivot : my_bool;
 
883
    {   Pointers to the master, and the next slave connections, points to
 
884
        itself if lone connection.       }
 
885
            master : Pst_mysql;
 
886
            next_slave : Pst_mysql;
 
887
            last_used_slave : Pst_mysql; // needed for round-robin slave pick
 
888
            last_used_con : Pst_mysql;   // needed for send/read/store/use result to work correctly with replication
 
889
{$IFDEF mysql41}
 
890
            stmts : Pointer;             // was PList, list of all statements
 
891
            methods : Pst_mysql_methods;
 
892
            thd : pointer;
 
893
    {   Points to boolean flag in MYSQL_RES  or MYSQL_STMT. We set this flag
 
894
        from mysql_stmt_close if close had to cancel result set of this object.       }
 
895
            unbuffered_fetch_owner : Pmy_bool;
 
896
{$ENDIF}
 
897
         end;
 
898
       MYSQL = st_mysql;
 
899
       PMYSQL = ^MYSQL;
 
900
 
 
901
 
 
902
       Pst_mysql_res = ^st_mysql_res;
 
903
       st_mysql_res = record
 
904
            row_count : my_ulonglong;
 
905
            fields : PMYSQL_FIELD;
 
906
            data : PMYSQL_DATA;
 
907
            data_cursor : PMYSQL_ROWS;
 
908
            lengths : Pdword;            // column lengths of current row
 
909
            handle : PMYSQL;             // for unbuffered reads
 
910
            field_alloc : MEM_ROOT;
 
911
            field_count : dword;
 
912
            current_field : dword;
 
913
            row : MYSQL_ROW;             // If unbuffered read
 
914
            current_row : MYSQL_ROW;     // buffer to current row
 
915
            eof : my_bool;               // Used by mysql_fetch_row
 
916
{$IFDEF mysql41}
 
917
            unbuffered_fetch_cancelled : my_bool;  // mysql_stmt_close() had to cancel this result
 
918
 
 
919
            methods : Pst_mysql_methods;
 
920
{$ENDIF}
 
921
         end;
 
922
       MYSQL_RES = st_mysql_res;
 
923
       PMYSQL_RES = ^MYSQL_RES;
 
924
 
 
925
       Pst_mysql_stmt = ^st_mysql_stmt;
 
926
       PMYSQL_STMT = ^MYSQL_STMT;
 
927
 
 
928
       st_mysql_methods = record
 
929
            read_query_result : function (mysql:PMYSQL):my_bool;cdecl;
 
930
            advanced_command : function (mysql:PMYSQL; command:enum_server_command; header:Pchar; header_length:dword; arg:Pchar;
 
931
                         arg_length:dword; skip_check:my_bool):my_bool;
 
932
            read_rows : function (mysql:PMYSQL; mysql_fields:PMYSQL_FIELD; fields:dword):PMYSQL_DATA;
 
933
            use_result : function (mysql:PMYSQL):PMYSQL_RES;
 
934
            fetch_lengths : procedure (fto:Pdword; column:MYSQL_ROW; field_count:dword);
 
935
            flush_use_result : procedure (mysql:PMYSQL);
 
936
{ $if !defined(MYSQL_SERVER) || defined(EMBEDDED_LIBRARY)}
 
937
            list_fields : function (mysql:PMYSQL):PMYSQL_FIELD;
 
938
            read_prepare_result : function (mysql:PMYSQL; stmt:PMYSQL_STMT):my_bool;
 
939
            stmt_execute : function (stmt:PMYSQL_STMT):longint;
 
940
            read_binary_rows : function (stmt:PMYSQL_STMT):longint;
 
941
            unbuffered_fetch : function (mysql:PMYSQL; row:PPchar):longint;
 
942
            free_embedded_thd : procedure (mysql:PMYSQL);
 
943
            read_statistics : function (mysql:PMYSQL):Pchar;
 
944
            next_result : function (mysql:PMYSQL):my_bool;
 
945
            read_change_user_result : function (mysql:PMYSQL; buff:Pchar; passwd:Pchar):longint;
 
946
{ $endif}
 
947
         end;
 
948
       MYSQL_METHODS = st_mysql_methods;
 
949
       PMYSQL_METHODS = ^MYSQL_METHODS;
 
950
 
 
951
 
 
952
       Pst_mysql_manager = ^st_mysql_manager;
 
953
       st_mysql_manager = record
 
954
            net : NET;
 
955
            host : Pchar;
 
956
            user : Pchar;
 
957
            passwd : Pchar;
 
958
            port : dword;
 
959
            free_me : my_bool;
 
960
            eof : my_bool;
 
961
            cmd_status : longint;
 
962
            last_errno : longint;
 
963
            net_buf : Pchar;
 
964
            net_buf_pos : Pchar;
 
965
            net_data_end : Pchar;
 
966
            net_buf_size : longint;
 
967
            last_error : array[0..(MAX_MYSQL_MANAGER_ERR)-1] of char;
 
968
         end;
 
969
       MYSQL_MANAGER = st_mysql_manager;
 
970
       PMYSQL_MANAGER = ^MYSQL_MANAGER;
 
971
 
 
972
       Pst_mysql_parameters = ^st_mysql_parameters;
 
973
       st_mysql_parameters = record
 
974
            p_max_allowed_packet : Pdword;
 
975
            p_net_buffer_length : Pdword;
 
976
         end;
 
977
       MYSQL_PARAMETERS = st_mysql_parameters;
 
978
       PMYSQL_PARAMETERS = ^MYSQL_PARAMETERS;
 
979
 
 
980
    { The following definitions are added for the enhanced
 
981
      client-server protocol }
 
982
 
 
983
    { statement state  }
 
984
 
 
985
       enum_mysql_stmt_state = (MYSQL_STMT_INIT_DONE := 1,MYSQL_STMT_PREPARE_DONE,
 
986
         MYSQL_STMT_EXECUTE_DONE,MYSQL_STMT_FETCH_DONE
 
987
         );
 
988
 
 
989
    {
 
990
      Note: this info is from the mysql-5.0 version:
 
991
    
 
992
      This structure is used to define bind information, and
 
993
      internally by the client library.
 
994
      Public members with their descriptions are listed below
 
995
      (conventionally `On input' refers to the binds given to
 
996
      mysql_stmt_bind_param, `On output' refers to the binds given
 
997
      to mysql_stmt_bind_result):
 
998
 
 
999
      buffer_type    - One of the MYSQL_* types, used to describe
 
1000
                       the host language type of buffer.
 
1001
                       On output: if column type is different from
 
1002
                       buffer_type, column value is automatically converted
 
1003
                       to buffer_type before it is stored in the buffer.
 
1004
      buffer         - On input: points to the buffer with input data.
 
1005
                       On output: points to the buffer capable to store
 
1006
                       output data.
 
1007
                       The type of memory pointed by buffer must correspond
 
1008
                       to buffer_type. See the correspondence table in
 
1009
                       the comment to mysql_stmt_bind_param.
 
1010
 
 
1011
      The two above members are mandatory for any kind of bind.
 
1012
 
 
1013
      buffer_length  - the length of the buffer. You don't have to set
 
1014
                       it for any fixed length buffer: float, double,
 
1015
                       int, etc. It must be set however for variable-length
 
1016
                       types, such as BLOBs or STRINGs.
 
1017
 
 
1018
      length         - On input: in case when lengths of input values
 
1019
                       are different for each execute, you can set this to
 
1020
                       point at a variable containining value length. This
 
1021
                       way the value length can be different in each execute.
 
1022
                       If length is not NULL, buffer_length is not used.
 
1023
                       Note, length can even point at buffer_length if
 
1024
                       you keep bind structures around while fetching:
 
1025
                       this way you can change buffer_length before
 
1026
                       each execution, everything will work ok.
 
1027
                       On output: if length is set, mysql_stmt_fetch will
 
1028
                       write column length into it.
 
1029
 
 
1030
      is_null        - On input: points to a boolean variable that should
 
1031
                       be set to TRUE for NULL values.
 
1032
                       This member is useful only if your data may be
 
1033
                       NULL in some but not all cases.
 
1034
                       If your data is never NULL, is_null should be set to 0.
 
1035
                       If your data is always NULL, set buffer_type
 
1036
                       to MYSQL_TYPE_NULL, and is_null will not be used.
 
1037
 
 
1038
      is_unsigned    - On input: used to signify that values provided for one
 
1039
                       of numeric types are unsigned.
 
1040
                       On output describes signedness of the output buffer.
 
1041
                       If, taking into account is_unsigned flag, column data
 
1042
                       is out of range of the output buffer, data for this column
 
1043
                       is regarded truncated. Note that this has no correspondence
 
1044
                       to the sign of result set column, if you need to find it out
 
1045
                       use mysql_stmt_result_metadata.
 
1046
      error          - where to write a truncation error if it is present.
 
1047
                       possible error value is:
 
1048
                       0  no truncation
 
1049
                       1  value is out of range or buffer is too small
 
1050
 
 
1051
      Please note that MYSQL_BIND also has internals members.
 
1052
    }
 
1053
       Pst_mysql_bind = ^st_mysql_bind;
 
1054
       st_mysql_bind = record
 
1055
            length : Pdword;                // output length pointer
 
1056
            is_null : Pmy_bool;             // Pointer to null indicator
 
1057
            buffer : pointer;               // buffer to get/put data
 
1058
{$IFDEF mysql50}
 
1059
            error: pmy_bool;                // set this if you want to track data truncations happened during fetch
 
1060
{$ENDIF}
 
1061
            buffer_type : enum_field_types; // buffer type
 
1062
            buffer_length : dword;          // buffer length, must be set for str/binary
 
1063
    { Following are for internal use. Set by mysql_stmt_bind_param  }
 
1064
{$IFNDEF mysql50}
 
1065
            inter_buffer : Pbyte;           // for the current data position
 
1066
{$ELSE}
 
1067
            row_ptr : PByte;                // for the current data position
 
1068
{$ENDIF}
 
1069
            offset : dword;                 // offset position for char/binary fetch
 
1070
{$IFNDEF mysql50}
 
1071
            internal_length : dword;        //  Used if length is 0
 
1072
{$ELSE}
 
1073
            length_value : dword;           //  Used if length is 0
 
1074
{$ENDIF}
 
1075
            param_number : dword;           // For null count and error messages
 
1076
            pack_length : dword;            // Internal length for packed data
 
1077
{$IFDEF mysql50}
 
1078
            error_value : pmy_bool;         // used if error is 0
 
1079
{$ENDIF}
 
1080
            is_unsigned : my_bool;          // set if integer type is unsigned
 
1081
            long_data_used : my_bool;       // If used with mysql_send_long_data
 
1082
{$IFNDEF mysql50}
 
1083
            internal_is_null : my_bool;     // Used if is_null is 0
 
1084
{$ELSE}
 
1085
            is_null_value : my_bool;        // Used if is_null is 0
 
1086
{$ENDIF}
 
1087
            store_param_func : procedure (net:PNET; param:Pst_mysql_bind);cdecl;
 
1088
            fetch_result : procedure (_para1:Pst_mysql_bind; _para2:PMYSQL_FIELD; row:PPbyte);
 
1089
            skip_result : procedure (_para1:Pst_mysql_bind; _para2:PMYSQL_FIELD; row:PPbyte);
 
1090
         end;
 
1091
       MYSQL_BIND = st_mysql_bind;
 
1092
       PMYSQL_BIND = ^MYSQL_BIND;
 
1093
 
 
1094
    { statement handler  }
 
1095
       st_mysql_stmt = record
 
1096
            mem_root : MEM_ROOT;            // root allocations
 
1097
//            list : LIST;                    // list to keep track of all stmts
 
1098
            mysql : PMYSQL;                 // connection handle
 
1099
            params : PMYSQL_BIND;           // input parameters
 
1100
            bind : PMYSQL_BIND;             // input parameters
 
1101
            fields : PMYSQL_FIELD;          // result set metadata
 
1102
            result : MYSQL_DATA;            // cached result set
 
1103
            data_cursor : PMYSQL_ROWS;      // current row in cached result
 
1104
            affected_rows : my_ulonglong;   // copy of mysql->affected_rows after statement execution
 
1105
            insert_id : my_ulonglong;       // copy of mysql->insert_id
 
1106
    {   mysql_stmt_fetch() calls this function to fetch one row (it's different
 
1107
        for buffered, unbuffered and cursor fetch).       }
 
1108
            read_row_func : function (stmt:Pst_mysql_stmt; row:PPbyte):longint;cdecl;
 
1109
            stmt_id : dword;                // Id for prepared statement
 
1110
{$IFDEF mysql50}
 
1111
            flags : dword;                  // i.e. type of cursor to open
 
1112
            prefetch_rows : dword;          // number of rows per one COM_FETCH
 
1113
            server_status : dword;          // Copied from mysql->server_status after execute/fetch to know
 
1114
                                            // server-side cursor status for this statement.
 
1115
{$ENDIF}
 
1116
            last_errno : dword;             // error code
 
1117
            param_count : dword;            // input parameter count
 
1118
            field_count : dword;            // number of columns in result set
 
1119
            state : enum_mysql_stmt_state;  // statement state
 
1120
            last_error : array[0..(MYSQL_ERRMSG_SIZE)-1] of char;  // error message
 
1121
            sqlstate : array[0..(SQLSTATE_LENGTH+1)-1] of char;
 
1122
            send_types_to_server : my_bool; // Types of input parameters should be sent to server
 
1123
            bind_param_done : my_bool;      // input buffers were supplied
 
1124
{$IFNDEF mysql50}
 
1125
            bind_result_done : my_bool;     // output buffers were supplied
 
1126
{$ELSE}
 
1127
            bind_result_done : byte;        // output buffers were supplied
 
1128
{$ENDIF}
 
1129
 
 
1130
            unbuffered_fetch_cancelled : my_bool;   // mysql_stmt_close() had to cancel this result
 
1131
    {   Is set to true if we need to calculate field->max_length for
 
1132
        metadata fields when doing mysql_stmt_store_result.       }
 
1133
            update_max_length : my_bool;
 
1134
         end;
 
1135
       MYSQL_STMT = st_mysql_stmt;
 
1136
    {   When doing mysql_stmt_store_result calculate max_length attribute
 
1137
        of statement metadata. This is to be consistent with the old API,
 
1138
        where this was done automatically.
 
1139
        In the new API we do that only by request because it slows down
 
1140
        mysql_stmt_store_result sufficiently.       }
 
1141
       enum_stmt_attr_type = (STMT_ATTR_UPDATE_MAX_LENGTH
 
1142
{$IFDEF mysql50}
 
1143
                              ,STMT_ATTR_CURSOR_TYPE,  // unsigned long with combination of cursor flags (read only, for update, etc)
 
1144
                              STMT_ATTR_PREFETCH_ROWS // Amount of rows to retrieve from server per one fetch if using cursors.
 
1145
                                                      // Accepts unsigned long attribute in the range 1 - ulong_max
 
1146
{$ENDIF}
 
1147
                             );
 
1148
 
 
1149
 
 
1150
//#define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet)
 
1151
//#define net_buffer_length (*mysql_get_parameters()->p_net_buffer_length)
 
1152
 
 
1153
{$IFNDEF LinkDynamically}
 
1154
    { Set up and bring down the server; to ensure that applications will
 
1155
      work when linked against either the standard client library or the
 
1156
      embedded server library, these functions should be called.     }
 
1157
    function mysql_server_init(argc:longint; argv:PPchar; groups:PPchar):longint;cdecl;external mysqllib name 'mysql_server_init';
 
1158
    procedure mysql_server_end;cdecl;external mysqllib name 'mysql_server_end';
 
1159
 
 
1160
    { mysql_server_init/end need to be called when using libmysqld or
 
1161
      libmysqlclient (exactly, mysql_server_init() is called by mysql_init() so
 
1162
      you don't need to call it explicitely; but you need to call
 
1163
      mysql_server_end() to free memory). The names are a bit misleading
 
1164
      (mysql_SERVER* to be used when using libmysqlCLIENT). So we add more general
 
1165
      names which suit well whether you're using libmysqld or libmysqlclient. We
 
1166
      intend to promote these aliases over the mysql_server* ones.     }
 
1167
 
 
1168
    function mysql_library_init(argc:longint; argv:PPchar; groups:PPchar):longint;cdecl;external mysqllib name 'mysql_server_init';
 
1169
    procedure mysql_library_end;cdecl;external mysqllib name 'mysql_server_end';
 
1170
 
 
1171
    function mysql_get_parameters:PMYSQL_PARAMETERS;extdecl;external mysqllib name 'mysql_get_parameters';
 
1172
 
 
1173
    { Set up and bring down a thread; these function should be called
 
1174
      for each thread in an application which opens at least one MySQL
 
1175
      connection.  All uses of the connection(s) should be between these
 
1176
      function calls.     }
 
1177
    function mysql_thread_init:my_bool;extdecl;external mysqllib name 'mysql_thread_init';
 
1178
    procedure mysql_thread_end;extdecl;external mysqllib name 'mysql_thread_end';
 
1179
    { Functions to get information from the MYSQL and MYSQL_RES structures
 
1180
      Should definitely be used if one uses shared libraries.     }
 
1181
    function mysql_num_rows(res:PMYSQL_RES):my_ulonglong;extdecl;external mysqllib name 'mysql_num_rows';
 
1182
    function mysql_num_fields(res:PMYSQL_RES):dword;extdecl;external mysqllib name 'mysql_num_fields';
 
1183
    function mysql_eof(res:PMYSQL_RES):my_bool;extdecl;external mysqllib name 'mysql_eof';
 
1184
    function mysql_fetch_field_direct(res:PMYSQL_RES; fieldnr:dword):PMYSQL_FIELD;extdecl;external mysqllib name 'mysql_fetch_field_direct';
 
1185
    function mysql_fetch_fields(res:PMYSQL_RES):PMYSQL_FIELD;extdecl;external mysqllib name 'mysql_fetch_fields';
 
1186
    function mysql_row_tell(res:PMYSQL_RES):MYSQL_ROW_OFFSET;extdecl;external mysqllib name 'mysql_row_tell';
 
1187
    function mysql_field_tell(res:PMYSQL_RES):MYSQL_FIELD_OFFSET;extdecl;external mysqllib name 'mysql_field_tell';
 
1188
    function mysql_field_count(mysql:PMYSQL):dword;extdecl;external mysqllib name 'mysql_field_count';
 
1189
    function mysql_affected_rows(mysql:PMYSQL):my_ulonglong;extdecl;external mysqllib name 'mysql_affected_rows';
 
1190
    function mysql_insert_id(mysql:PMYSQL):my_ulonglong;extdecl;external mysqllib name 'mysql_insert_id';
 
1191
    function mysql_errno(mysql:PMYSQL):dword;extdecl;external mysqllib name 'mysql_errno';
 
1192
    function mysql_error(mysql:PMYSQL):Pchar;extdecl;external mysqllib name 'mysql_error';
 
1193
    function mysql_sqlstate(mysql:PMYSQL):Pchar;extdecl;external mysqllib name 'mysql_sqlstate';
 
1194
    function mysql_warning_count(mysql:PMYSQL):dword;extdecl;external mysqllib name 'mysql_warning_count';
 
1195
    function mysql_info(mysql:PMYSQL):Pchar;extdecl;external mysqllib name 'mysql_info';
 
1196
    function mysql_thread_id(mysql:PMYSQL):dword;extdecl;external mysqllib name 'mysql_thread_id';
 
1197
    function mysql_character_set_name(mysql:PMYSQL):Pchar;extdecl;external mysqllib name 'mysql_character_set_name';
 
1198
    function mysql_set_character_set(mysql:PMYSQL; csname:Pchar):longint;extdecl;external mysqllib name 'mysql_set_character_set';
 
1199
    function mysql_init(mysql:PMYSQL):PMYSQL;extdecl;external mysqllib name 'mysql_init';
 
1200
    function mysql_ssl_set(mysql:PMYSQL; key:Pchar; cert:Pchar; ca:Pchar; capath:Pchar;
 
1201
               cipher:Pchar):my_bool;extdecl;external mysqllib name 'mysql_ssl_set';
 
1202
    function mysql_change_user(mysql:PMYSQL; user:Pchar; passwd:Pchar; db:Pchar):my_bool;extdecl;external mysqllib name 'mysql_change_user';
 
1203
    function mysql_real_connect(mysql:PMYSQL; host:Pchar; user:Pchar; passwd:Pchar; db:Pchar;
 
1204
               port:dword; unix_socket:Pchar; clientflag:dword):PMYSQL;extdecl;external mysqllib name 'mysql_real_connect';
 
1205
    function mysql_select_db(mysql:PMYSQL; db:Pchar):longint;extdecl;external mysqllib name 'mysql_select_db';
 
1206
    function mysql_query(mysql:PMYSQL; q:Pchar):longint;extdecl;external mysqllib name 'mysql_query';
 
1207
    function mysql_send_query(mysql:PMYSQL; q:Pchar; length:dword):longint;extdecl;external mysqllib name 'mysql_send_query';
 
1208
    function mysql_real_query(mysql:PMYSQL; q:Pchar; length:dword):longint;extdecl;external mysqllib name 'mysql_real_query';
 
1209
    function mysql_store_result(mysql:PMYSQL):PMYSQL_RES;extdecl;external mysqllib name 'mysql_store_result';
 
1210
    function mysql_use_result(mysql:PMYSQL):PMYSQL_RES;extdecl;external mysqllib name 'mysql_use_result';
 
1211
 
 
1212
{$ELSE}
 
1213
 
 
1214
    var
 
1215
      mysql_server_init: function (argc:longint; argv:PPchar; groups:PPchar):longint;cdecl;
 
1216
      mysql_server_end: procedure ;cdecl;
 
1217
      mysql_library_init: function (argc:longint; argv:PPchar; groups:PPchar):longint;cdecl;
 
1218
      mysql_library_end: procedure ;cdecl;
 
1219
      mysql_num_rows: function (res:PMYSQL_RES):my_ulonglong;extdecl;
 
1220
      mysql_num_fields: function (res:PMYSQL_RES):dword;extdecl;
 
1221
      mysql_eof: function (res:PMYSQL_RES):my_bool;extdecl;
 
1222
      mysql_fetch_field_direct: function (res:PMYSQL_RES; fieldnr:dword):PMYSQL_FIELD;extdecl;
 
1223
      mysql_fetch_fields: function (res:PMYSQL_RES):PMYSQL_FIELD;extdecl;
 
1224
      mysql_row_tell: function (res:PMYSQL_RES):MYSQL_ROW_OFFSET;extdecl;
 
1225
      mysql_field_tell: function (res:PMYSQL_RES):MYSQL_FIELD_OFFSET;extdecl;
 
1226
      mysql_field_count: function (mysql:PMYSQL):dword;extdecl;
 
1227
      mysql_affected_rows: function (mysql:PMYSQL):my_ulonglong;extdecl;
 
1228
      mysql_insert_id: function (mysql:PMYSQL):my_ulonglong;extdecl;
 
1229
      mysql_errno: function (mysql:PMYSQL):dword;extdecl;
 
1230
      mysql_error: function (mysql:PMYSQL):Pchar;extdecl;
 
1231
      mysql_sqlstate: function (mysql:PMYSQL):Pchar;extdecl;
 
1232
      mysql_warning_count: function (mysql:PMYSQL):dword;extdecl;
 
1233
      mysql_info: function (mysql:PMYSQL):Pchar;extdecl;
 
1234
      mysql_thread_id: function (mysql:PMYSQL):dword;extdecl;
 
1235
      mysql_character_set_name: function (mysql:PMYSQL):Pchar;extdecl;
 
1236
      mysql_set_character_set: function (mysql:PMYSQL; csname:Pchar):longint;extdecl;
 
1237
      mysql_init: function (mysql:PMYSQL):PMYSQL;extdecl;
 
1238
      mysql_ssl_set: function (mysql:PMYSQL; key:Pchar; cert:Pchar; ca:Pchar; capath:Pchar;
 
1239
                 cipher:Pchar):my_bool;extdecl;
 
1240
      mysql_change_user: function (mysql:PMYSQL; user:Pchar; passwd:Pchar; db:Pchar):my_bool;extdecl;
 
1241
      mysql_real_connect: function (mysql:PMYSQL; host:Pchar; user:Pchar; passwd:Pchar; db:Pchar;
 
1242
                 port:dword; unix_socket:Pchar; clientflag:dword):PMYSQL;extdecl;
 
1243
      mysql_select_db: function (mysql:PMYSQL; db:Pchar):longint;extdecl;
 
1244
      mysql_query: function (mysql:PMYSQL; q:Pchar):longint;extdecl;
 
1245
      mysql_send_query: function (mysql:PMYSQL; q:Pchar; length:dword):longint;extdecl;
 
1246
      mysql_real_query: function (mysql:PMYSQL; q:Pchar; length:dword):longint;extdecl;
 
1247
      mysql_store_result: function (mysql:PMYSQL):PMYSQL_RES;extdecl;
 
1248
      mysql_use_result: function (mysql:PMYSQL):PMYSQL_RES;extdecl;
 
1249
{$ENDIF}
 
1250
 
 
1251
{$IFNDEF LinkDynamically}
 
1252
    { perform query on master  }
 
1253
    function mysql_master_query(mysql:PMYSQL; q:Pchar; length:dword):my_bool;extdecl;external mysqllib name 'mysql_master_query';
 
1254
    function mysql_master_send_query(mysql:PMYSQL; q:Pchar; length:dword):my_bool;extdecl;external mysqllib name 'mysql_master_send_query';
 
1255
 
 
1256
    { perform query on slave  }
 
1257
    function mysql_slave_query(mysql:PMYSQL; q:Pchar; length:dword):my_bool;extdecl;external mysqllib name 'mysql_slave_query';
 
1258
    function mysql_slave_send_query(mysql:PMYSQL; q:Pchar; length:dword):my_bool;extdecl;external mysqllib name 'mysql_slave_send_query';
 
1259
{$IFDEF mysql50}
 
1260
    procedure mysql_get_character_set_info(mysql : PMYSQL; charset : PMY_CHARSET_INFO);extdecl;external mysqllib name 'mysql_get_character_set_info';
 
1261
{$ENDIF}
 
1262
{$ENDIF}
 
1263
 
 
1264
    { local infile support  }
 
1265
 
 
1266
    const
 
1267
       LOCAL_INFILE_ERROR_LEN = 512;
 
1268
 
 
1269
{$IFNDEF LinkDynamically}
 
1270
{    procedure mysql_set_local_infile_handler(mysql:PMYSQL; local_infile_init:function (_para1:Ppointer; _para2:Pchar; _para3:pointer):longint; local_infile_read:function (_para1:pointer; _para2:Pchar; _para3:dword):longint; local_infile_end:procedure (_pa
 
1271
                _para6:pointer);cdecl;external mysqllib name 'mysql_set_local_infile_handler';}
 
1272
    procedure mysql_set_local_infile_default(mysql:PMYSQL);cdecl;external mysqllib name 'mysql_set_local_infile_default';
 
1273
 
 
1274
    { enable/disable parsing of all queries to decide if they go on master or
 
1275
      slave     }
 
1276
    procedure mysql_enable_rpl_parse(mysql:PMYSQL);extdecl;external mysqllib name 'mysql_enable_rpl_parse';
 
1277
    procedure mysql_disable_rpl_parse(mysql:PMYSQL);extdecl;external mysqllib name 'mysql_disable_rpl_parse';
 
1278
 
 
1279
    { get the value of the parse flag  }
 
1280
    function mysql_rpl_parse_enabled(mysql:PMYSQL):longint;extdecl;external mysqllib name 'mysql_rpl_parse_enabled';
 
1281
 
 
1282
    {  enable/disable reads from master  }
 
1283
    procedure mysql_enable_reads_from_master(mysql:PMYSQL);extdecl;external mysqllib name 'mysql_enable_reads_from_master';
 
1284
    procedure mysql_disable_reads_from_master(mysql:PMYSQL);extdecl;external mysqllib name 'mysql_disable_reads_from_master';
 
1285
 
 
1286
    { get the value of the master read flag  }
 
1287
    function mysql_reads_from_master_enabled(mysql:PMYSQL):my_bool;extdecl;external mysqllib name 'mysql_reads_from_master_enabled';
 
1288
 
 
1289
    function mysql_rpl_query_type(q : pchar;len : longint):mysql_rpl_type;extdecl;external mysqllib name 'mysql_rpl_query_type';
 
1290
 
 
1291
    { discover the master and its slaves  }
 
1292
    function mysql_rpl_probe(mysql:PMYSQL):my_bool;extdecl;external mysqllib name 'mysql_rpl_probe';
 
1293
 
 
1294
    { set the master, close/free the old one, if it is not a pivot  }
 
1295
    function mysql_set_master(mysql:PMYSQL; host:Pchar; port:dword; user:Pchar; passwd:Pchar):longint;extdecl;external mysqllib name 'mysql_set_master';
 
1296
    function mysql_add_slave(mysql:PMYSQL; host:Pchar; port:dword; user:Pchar; passwd:Pchar):longint;extdecl;external mysqllib name 'mysql_add_slave';
 
1297
    function mysql_shutdown(mysql:PMYSQL; shutdown_level:mysql_enum_shutdown_level):longint;extdecl;external mysqllib name 'mysql_shutdown';
 
1298
    function mysql_dump_debug_info(mysql:PMYSQL):longint;extdecl;external mysqllib name 'mysql_dump_debug_info';
 
1299
    function mysql_refresh(mysql:PMYSQL; refresh_options:dword):longint;extdecl;external mysqllib name 'mysql_refresh';
 
1300
    function mysql_kill(mysql:PMYSQL; pid:dword):longint;extdecl;external mysqllib name 'mysql_kill';
 
1301
    function mysql_set_server_option(mysql:PMYSQL; option:enum_mysql_set_option):longint;extdecl;external mysqllib name 'mysql_set_server_option';
 
1302
    function mysql_ping(mysql:PMYSQL):longint;extdecl;external mysqllib name 'mysql_ping';
 
1303
    function mysql_stat(mysql:PMYSQL):Pchar;extdecl;external mysqllib name 'mysql_stat';
 
1304
    function mysql_get_server_info(mysql:PMYSQL):Pchar;extdecl;external mysqllib name 'mysql_get_server_info';
 
1305
    function mysql_get_client_info:Pchar;extdecl;external mysqllib name 'mysql_get_client_info';
 
1306
    function mysql_get_client_version:dword;extdecl;external mysqllib name 'mysql_get_client_version';
 
1307
    function mysql_get_host_info(mysql:PMYSQL):Pchar;extdecl;external mysqllib name 'mysql_get_host_info';
 
1308
    function mysql_get_server_version(mysql:PMYSQL):dword;extdecl;external mysqllib name 'mysql_get_server_version';
 
1309
    function mysql_get_proto_info(mysql:PMYSQL):dword;extdecl;external mysqllib name 'mysql_get_proto_info';
 
1310
    function mysql_list_dbs(mysql:PMYSQL; wild:Pchar):PMYSQL_RES;extdecl;external mysqllib name 'mysql_list_dbs';
 
1311
 
 
1312
    function mysql_list_tables(mysql:PMYSQL; wild:Pchar):PMYSQL_RES;extdecl;external mysqllib name 'mysql_list_tables';
 
1313
    function mysql_list_processes(mysql:PMYSQL):PMYSQL_RES;extdecl;external mysqllib name 'mysql_list_processes';
 
1314
    function mysql_options(mysql:PMYSQL; option:mysql_option; arg:Pchar):longint;extdecl;external mysqllib name 'mysql_options';
 
1315
    procedure mysql_free_result(result:PMYSQL_RES);extdecl;external mysqllib name 'mysql_free_result';
 
1316
    procedure mysql_data_seek(result:PMYSQL_RES; offset:my_ulonglong);extdecl;external mysqllib name 'mysql_data_seek';
 
1317
    function mysql_row_seek(result:PMYSQL_RES; offset:MYSQL_ROW_OFFSET):MYSQL_ROW_OFFSET;extdecl;external mysqllib name 'mysql_row_seek';
 
1318
    function mysql_field_seek(result:PMYSQL_RES; offset:MYSQL_FIELD_OFFSET):MYSQL_FIELD_OFFSET;extdecl;external mysqllib name 'mysql_field_seek';
 
1319
    function mysql_fetch_row(result:PMYSQL_RES):MYSQL_ROW;extdecl;external mysqllib name 'mysql_fetch_row';
 
1320
    function mysql_fetch_lengths(result:PMYSQL_RES):Pdword;extdecl;external mysqllib name 'mysql_fetch_lengths';
 
1321
    function mysql_fetch_field(result:PMYSQL_RES):PMYSQL_FIELD;extdecl;external mysqllib name 'mysql_fetch_field';
 
1322
    function mysql_list_fields(mysql:PMYSQL; table:Pchar; wild:Pchar):PMYSQL_RES;extdecl;external mysqllib name 'mysql_list_fields';
 
1323
    function mysql_escape_string(fto:Pchar; from:Pchar; from_length:dword):dword;extdecl;external mysqllib name 'mysql_escape_string';
 
1324
    function mysql_hex_string(fto:Pchar; from:Pchar; from_length:dword):dword;extdecl;external mysqllib name 'mysql_hex_string';
 
1325
    function mysql_real_escape_string(mysql:PMYSQL; fto:Pchar; from:Pchar; length:dword):dword;extdecl;external mysqllib name 'mysql_real_escape_string';
 
1326
    procedure mysql_debug(debug:Pchar);extdecl;external mysqllib name 'mysql_debug';
 
1327
{    function mysql_odbc_escape_string(mysql:PMYSQL; fto:Pchar; to_length:dword; from:Pchar; from_length:dword;
 
1328
               param:pointer; extend_buffer:function (_para1:pointer; to:Pchar; length:Pdword):Pchar):Pchar;extdecl;external mysqllib name 'mysql_odbc_escape_string';}
 
1329
    procedure myodbc_remove_escape(mysql:PMYSQL; name:Pchar);extdecl;external mysqllib name 'myodbc_remove_escape';
 
1330
    function mysql_thread_safe:dword;extdecl;external mysqllib name 'mysql_thread_safe';
 
1331
    function mysql_embedded:my_bool;extdecl;external mysqllib name 'mysql_embedded';
 
1332
    function mysql_manager_init(con:PMYSQL_MANAGER):PMYSQL_MANAGER;extdecl;external mysqllib name 'mysql_manager_init';
 
1333
    function mysql_manager_connect(con:PMYSQL_MANAGER; host:Pchar; user:Pchar; passwd:Pchar; port:dword):PMYSQL_MANAGER;extdecl;external mysqllib name 'mysql_manager_connect';
 
1334
    procedure mysql_manager_close(con:PMYSQL_MANAGER);extdecl;external mysqllib name 'mysql_manager_close';
 
1335
    function mysql_manager_command(con:PMYSQL_MANAGER; cmd:Pchar; cmd_len:longint):longint;extdecl;external mysqllib name 'mysql_manager_command';
 
1336
    function mysql_manager_fetch_line(con:PMYSQL_MANAGER; res_buf:Pchar; res_buf_size:longint):longint;extdecl;external mysqllib name 'mysql_manager_fetch_line';
 
1337
    function mysql_read_query_result(mysql:PMYSQL):my_bool;extdecl;external mysqllib name 'mysql_read_query_result';
 
1338
 
 
1339
    function mysql_stmt_init(mysql:PMYSQL):PMYSQL_STMT;extdecl;external mysqllib name 'mysql_stmt_init';
 
1340
    function mysql_stmt_prepare(stmt:PMYSQL_STMT; query:Pchar; length:dword):longint;extdecl;external mysqllib name 'mysql_stmt_prepare';
 
1341
    function mysql_stmt_execute(stmt:PMYSQL_STMT):longint;extdecl;external mysqllib name 'mysql_stmt_execute';
 
1342
    function mysql_stmt_fetch(stmt:PMYSQL_STMT):longint;extdecl;external mysqllib name 'mysql_stmt_fetch';
 
1343
    function mysql_stmt_fetch_column(stmt:PMYSQL_STMT; bind:PMYSQL_BIND; column:dword; offset:dword):longint;extdecl;external mysqllib name 'mysql_stmt_fetch_column';
 
1344
    function mysql_stmt_store_result(stmt:PMYSQL_STMT):longint;extdecl;external mysqllib name 'mysql_stmt_store_result';
 
1345
    function mysql_stmt_param_count(stmt:PMYSQL_STMT):dword;extdecl;external mysqllib name 'mysql_stmt_param_count';
 
1346
    function mysql_stmt_attr_set(stmt:PMYSQL_STMT; attr_type:enum_stmt_attr_type; attr:pointer):my_bool;extdecl;external mysqllib name 'mysql_stmt_attr_set';
 
1347
    function mysql_stmt_attr_get(stmt:PMYSQL_STMT; attr_type:enum_stmt_attr_type; attr:pointer):my_bool;extdecl;external mysqllib name 'mysql_stmt_attr_get';
 
1348
    function mysql_stmt_bind_param(stmt:PMYSQL_STMT; bnd:PMYSQL_BIND):my_bool;extdecl;external mysqllib name 'mysql_stmt_bind_param';
 
1349
    function mysql_stmt_bind_result(stmt:PMYSQL_STMT; bnd:PMYSQL_BIND):my_bool;extdecl;external mysqllib name 'mysql_stmt_bind_result';
 
1350
    function mysql_stmt_close(stmt:PMYSQL_STMT):my_bool;extdecl;external mysqllib name 'mysql_stmt_close';
 
1351
    function mysql_stmt_reset(stmt:PMYSQL_STMT):my_bool;extdecl;external mysqllib name 'mysql_stmt_reset';
 
1352
    function mysql_stmt_free_result(stmt:PMYSQL_STMT):my_bool;extdecl;external mysqllib name 'mysql_stmt_free_result';
 
1353
    function mysql_stmt_send_long_data(stmt:PMYSQL_STMT; param_number:dword; data:Pchar; length:dword):my_bool;extdecl;external mysqllib name 'mysql_stmt_send_long_data';
 
1354
    function mysql_stmt_result_metadata(stmt:PMYSQL_STMT):PMYSQL_RES;extdecl;external mysqllib name 'mysql_stmt_result_metadata';
 
1355
    function mysql_stmt_param_metadata(stmt:PMYSQL_STMT):PMYSQL_RES;extdecl;external mysqllib name 'mysql_stmt_param_metadata';
 
1356
    function mysql_stmt_errno(stmt:PMYSQL_STMT):dword;extdecl;external mysqllib name 'mysql_stmt_errno';
 
1357
    function mysql_stmt_error(stmt:PMYSQL_STMT):Pchar;extdecl;external mysqllib name 'mysql_stmt_error';
 
1358
    function mysql_stmt_sqlstate(stmt:PMYSQL_STMT):Pchar;extdecl;external mysqllib name 'mysql_stmt_sqlstate';
 
1359
    function mysql_stmt_row_seek(stmt:PMYSQL_STMT; offset:MYSQL_ROW_OFFSET):MYSQL_ROW_OFFSET;extdecl;external mysqllib name 'mysql_stmt_row_seek';
 
1360
    function mysql_stmt_row_tell(stmt:PMYSQL_STMT):MYSQL_ROW_OFFSET;extdecl;external mysqllib name 'mysql_stmt_row_tell';
 
1361
    procedure mysql_stmt_data_seek(stmt:PMYSQL_STMT; offset:my_ulonglong);extdecl;external mysqllib name 'mysql_stmt_data_seek';
 
1362
    function mysql_stmt_num_rows(stmt:PMYSQL_STMT):my_ulonglong;extdecl;external mysqllib name 'mysql_stmt_num_rows';
 
1363
    function mysql_stmt_affected_rows(stmt:PMYSQL_STMT):my_ulonglong;extdecl;external mysqllib name 'mysql_stmt_affected_rows';
 
1364
    function mysql_stmt_insert_id(stmt:PMYSQL_STMT):my_ulonglong;extdecl;external mysqllib name 'mysql_stmt_insert_id';
 
1365
    function mysql_stmt_field_count(stmt:PMYSQL_STMT):dword;extdecl;external mysqllib name 'mysql_stmt_field_count';
 
1366
 
 
1367
    function mysql_commit(mysql:PMYSQL):my_bool;extdecl;external mysqllib name 'mysql_commit';
 
1368
    function mysql_rollback(mysql:PMYSQL):my_bool;extdecl;external mysqllib name 'mysql_rollback';
 
1369
    function mysql_autocommit(mysql:PMYSQL; auto_mode:my_bool):my_bool;extdecl;external mysqllib name 'mysql_autocommit';
 
1370
    function mysql_more_results(mysql:PMYSQL):my_bool;extdecl;external mysqllib name 'mysql_more_results';
 
1371
    function mysql_next_result(mysql:PMYSQL):longint;extdecl;external mysqllib name 'mysql_next_result';
 
1372
    procedure mysql_close(sock:PMYSQL);extdecl;external mysqllib name 'mysql_close';
 
1373
 
 
1374
{$ELSE}
 
1375
    var
 
1376
      mysql_shutdown: function (mysql:PMYSQL; shutdown_level:mysql_enum_shutdown_level):longint;extdecl;
 
1377
      mysql_dump_debug_info: function (mysql:PMYSQL):longint;extdecl;
 
1378
      mysql_refresh: function (mysql:PMYSQL; refresh_options:dword):longint;extdecl;
 
1379
      mysql_kill: function (mysql:PMYSQL; pid:dword):longint;extdecl;
 
1380
      mysql_set_server_option: function (mysql:PMYSQL; option:enum_mysql_set_option):longint;extdecl;
 
1381
      mysql_ping: function (mysql:PMYSQL):longint;extdecl;
 
1382
      mysql_stat: function (mysql:PMYSQL):Pchar;extdecl;
 
1383
      mysql_get_server_info: function (mysql:PMYSQL):Pchar;extdecl;
 
1384
      mysql_get_client_info: function :Pchar;extdecl;
 
1385
      mysql_get_client_version: function :dword;extdecl;
 
1386
      mysql_get_host_info: function (mysql:PMYSQL):Pchar;extdecl;
 
1387
      mysql_get_server_version: function (mysql:PMYSQL):dword;extdecl;
 
1388
      mysql_get_proto_info: function (mysql:PMYSQL):dword;extdecl;
 
1389
      mysql_list_dbs: function (mysql:PMYSQL; wild:Pchar):PMYSQL_RES;extdecl;
 
1390
 
 
1391
      mysql_list_tables: function (mysql:PMYSQL; wild:Pchar):PMYSQL_RES;extdecl;
 
1392
      mysql_list_processes: function (mysql:PMYSQL):PMYSQL_RES;extdecl;
 
1393
      mysql_options: function (mysql:PMYSQL; option:mysql_option; arg:Pchar):longint;extdecl;
 
1394
      mysql_free_result: procedure (result:PMYSQL_RES);extdecl;
 
1395
      mysql_data_seek: procedure (result:PMYSQL_RES; offset:my_ulonglong);extdecl;
 
1396
      mysql_row_seek: function (result:PMYSQL_RES; offset:MYSQL_ROW_OFFSET):MYSQL_ROW_OFFSET;extdecl;
 
1397
      mysql_field_seek: function (result:PMYSQL_RES; offset:MYSQL_FIELD_OFFSET):MYSQL_FIELD_OFFSET;extdecl;
 
1398
      mysql_fetch_row: function (result:PMYSQL_RES):MYSQL_ROW;extdecl;
 
1399
      mysql_fetch_lengths: function (result:PMYSQL_RES):Pdword;extdecl;
 
1400
      mysql_fetch_field: function (result:PMYSQL_RES):PMYSQL_FIELD;extdecl;
 
1401
      mysql_list_fields: function (mysql:PMYSQL; table:Pchar; wild:Pchar):PMYSQL_RES;extdecl;
 
1402
      mysql_escape_string: function (fto:Pchar; from:Pchar; from_length:dword):dword;extdecl;
 
1403
      mysql_hex_string: function (fto:Pchar; from:Pchar; from_length:dword):dword;extdecl;
 
1404
      mysql_real_escape_string: function (mysql:PMYSQL; fto:Pchar; from:Pchar; length:dword):dword;extdecl;
 
1405
      mysql_debug: procedure (debug:Pchar);extdecl;
 
1406
 
 
1407
      mysql_rollback: function (mysql:PMYSQL):my_bool;extdecl;
 
1408
      mysql_autocommit: function (mysql:PMYSQL; auto_mode:my_bool):my_bool;extdecl;
 
1409
      mysql_commit: function (mysql:PMYSQL):my_bool;extdecl;
 
1410
      mysql_more_results: function (mysql:PMYSQL):my_bool;extdecl;
 
1411
      mysql_next_result: function (mysql:PMYSQL):longint;extdecl;
 
1412
      mysql_close: procedure (sock:PMYSQL);extdecl;
 
1413
 
 
1414
      mysql_stmt_init: function (mysql:PMYSQL):PMYSQL_STMT;extdecl;
 
1415
      mysql_stmt_prepare: function (stmt:PMYSQL_STMT; query:Pchar; length:dword):longint;extdecl;
 
1416
      mysql_stmt_execute: function (stmt:PMYSQL_STMT):longint;extdecl;
 
1417
      mysql_stmt_fetch: function (stmt:PMYSQL_STMT):longint;extdecl;
 
1418
      mysql_stmt_fetch_column: function (stmt:PMYSQL_STMT; bind:PMYSQL_BIND; column:dword; offset:dword):longint;extdecl;
 
1419
      mysql_stmt_store_result: function (stmt:PMYSQL_STMT):longint;extdecl;
 
1420
      mysql_stmt_param_count: function (stmt:PMYSQL_STMT):dword;extdecl;
 
1421
      mysql_stmt_attr_set: function (stmt:PMYSQL_STMT; attr_type:enum_stmt_attr_type; attr:pointer):my_bool;extdecl;
 
1422
      mysql_stmt_attr_get: function (stmt:PMYSQL_STMT; attr_type:enum_stmt_attr_type; attr:pointer):my_bool;extdecl;
 
1423
      mysql_stmt_bind_param: function (stmt:PMYSQL_STMT; bnd:PMYSQL_BIND):my_bool;extdecl;
 
1424
      mysql_stmt_bind_result: function (stmt:PMYSQL_STMT; bnd:PMYSQL_BIND):my_bool;extdecl;
 
1425
      mysql_stmt_close: function (stmt:PMYSQL_STMT):my_bool;extdecl;
 
1426
      mysql_stmt_reset: function (stmt:PMYSQL_STMT):my_bool;extdecl;
 
1427
      mysql_stmt_free_result: function (stmt:PMYSQL_STMT):my_bool;extdecl;
 
1428
      mysql_stmt_send_long_data: function (stmt:PMYSQL_STMT; param_number:dword; data:Pchar; length:dword):my_bool;extdecl;
 
1429
      mysql_stmt_result_metadata: function (stmt:PMYSQL_STMT):PMYSQL_RES;extdecl;
 
1430
      mysql_stmt_param_metadata: function (stmt:PMYSQL_STMT):PMYSQL_RES;extdecl;
 
1431
      mysql_stmt_errno: function (stmt:PMYSQL_STMT):dword;extdecl;
 
1432
      mysql_stmt_error: function (stmt:PMYSQL_STMT):Pchar;extdecl;
 
1433
      mysql_stmt_sqlstate: function (stmt:PMYSQL_STMT):Pchar;extdecl;
 
1434
      mysql_stmt_row_seek: function (stmt:PMYSQL_STMT; offset:MYSQL_ROW_OFFSET):MYSQL_ROW_OFFSET;extdecl;
 
1435
      mysql_stmt_row_tell: function (stmt:PMYSQL_STMT):MYSQL_ROW_OFFSET;extdecl;
 
1436
      mysql_stmt_data_seek: procedure (stmt:PMYSQL_STMT; offset:my_ulonglong);extdecl;
 
1437
      mysql_stmt_num_rows: function (stmt:PMYSQL_STMT):my_ulonglong;extdecl;
 
1438
      mysql_stmt_affected_rows: function (stmt:PMYSQL_STMT):my_ulonglong;extdecl;
 
1439
      mysql_stmt_insert_id: function (stmt:PMYSQL_STMT):my_ulonglong;extdecl;
 
1440
      mysql_stmt_field_count: function (stmt:PMYSQL_STMT):dword;extdecl;
 
1441
 
 
1442
{$ENDIF}
 
1443
 
 
1444
 
 
1445
    { status return codes  }
 
1446
 
 
1447
    const
 
1448
       MYSQL_NO_DATA = 100;
 
1449
       MYSQL_DATA_TRUNCATED  = 101;
 
1450
 
 
1451
    function mysql_reload(mysql : PMySQL) : longint;
 
1452
 
 
1453
{$IFNDEF LinkDynamically}
 
1454
{$ifdef USE_OLD_FUNCTIONS}
 
1455
    function mysql_connect(mysql:PMYSQL; host:Pchar; user:Pchar; passwd:Pchar):PMYSQL;extdecl;external External_library name 'mysql_connect';
 
1456
    function mysql_create_db(mysql:PMYSQL; DB:Pchar):longint;extdecl;external External_library name 'mysql_create_db';
 
1457
    function mysql_drop_db(mysql:PMYSQL; DB:Pchar):longint;extdecl;external External_library name 'mysql_drop_db';
 
1458
    function mysql_reload(mysql : PMySQL) : longint;
 
1459
{$endif}
 
1460
{$endif}
 
1461
 
 
1462
{$define HAVE_MYSQL_REAL_CONNECT}    
 
1463
    { The following functions are mainly exported because of mysqlbinlog;
 
1464
      They are not for general usage     }
 
1465
 
 
1466
    function simple_command(mysql,command,arg,length,skip_check : longint) : longint;
 
1467
{$IFNDEF LinkDynamically}
 
1468
    function net_safe_read(mysql:PMYSQL):dword;cdecl;external mysqllib name 'net_safe_read';
 
1469
{$ENDIF}
 
1470
 
 
1471
{$ifdef NETWARE}
 
1472
(** unsupported pragma#pragma pack(pop)         /* restore alignment */*)
 
1473
{$endif}
 
1474
 
 
1475
{$IFDEF LinkDynamically}
 
1476
Function InitialiseMysql(Const LibraryName : String) : Integer;
 
1477
Function InitialiseMysql : Integer;
 
1478
Procedure ReleaseMysql;
 
1479
 
 
1480
var MysqlLibraryHandle : TLibHandle;
 
1481
{$ENDIF}
 
1482
 
 
1483
implementation
 
1484
 
 
1485
{$IFDEF LinkDynamically}
 
1486
 
 
1487
ResourceString
 
1488
  SErrAlreadyLoaded = 'MySQL interface already initialized from library %s.';
 
1489
  SLoadFailed       = 'Can not load MySQL library "%s". Please check your installation.';
 
1490
  
 
1491
var 
 
1492
  RefCount : integer;
 
1493
  LoadedLibrary : String;
 
1494
 
 
1495
Function InitialiseMysql : Integer;
 
1496
 
 
1497
begin
 
1498
  // Use Default library
 
1499
  Result:=InitialiseMySQL(Mysqllib);
 
1500
end;
 
1501
 
 
1502
 
 
1503
Function InitialiseMysql(Const LibraryName : String) : Integer;
 
1504
 
 
1505
 
 
1506
begin
 
1507
  if (RefCount=0) then
 
1508
    begin
 
1509
    MysqlLibraryHandle := loadlibrary(LibraryName);
 
1510
    if (MysqlLibraryHandle=nilhandle) then
 
1511
      begin
 
1512
      Raise EInOutError.CreateFmt(SLoadFailed,[LibraryName]);
 
1513
      end;
 
1514
    Inc(RefCount);  
 
1515
    LoadedLibrary:=LibraryName;
 
1516
// Only the procedure that are given in the c-library documentation are loaded, to
 
1517
// avoid problems with 'incomplete' libraries
 
1518
    pointer(my_init) := GetProcedureAddress(MysqlLibraryHandle,'my_init');
 
1519
    pointer(my_thread_init) := GetProcedureAddress(MysqlLibraryHandle,'my_thread_init');
 
1520
    pointer(my_thread_end) := GetProcedureAddress(MysqlLibraryHandle,'my_thread_end');
 
1521
 
 
1522
    pointer(mysql_affected_rows) := GetProcedureAddress(MysqlLibraryHandle,'mysql_affected_rows');
 
1523
    pointer(mysql_autocommit) := GetProcedureAddress(MysqlLibraryHandle,'mysql_autocommit');
 
1524
    pointer(mysql_change_user) := GetProcedureAddress(MysqlLibraryHandle,'mysql_change_user');
 
1525
//    pointer(mysql_charset_name) := GetProcedureAddress(MysqlLibraryHandle,'mysql_charset_name');
 
1526
    pointer(mysql_close) := GetProcedureAddress(MysqlLibraryHandle,'mysql_close');
 
1527
    pointer(mysql_commit) := GetProcedureAddress(MysqlLibraryHandle,'mysql_commit');
 
1528
//    pointer(mysql_connect) := GetProcedureAddress(MysqlLibraryHandle,'mysql_connect');
 
1529
//    pointer(mysql_create_db) := GetProcedureAddress(MysqlLibraryHandle,'mysql_create_db');
 
1530
    pointer(mysql_data_seek) := GetProcedureAddress(MysqlLibraryHandle,'mysql_data_seek');
 
1531
//    pointer(mysql_drop_db) := GetProcedureAddress(MysqlLibraryHandle,'mysql_drop_db');
 
1532
    pointer(mysql_debug) := GetProcedureAddress(MysqlLibraryHandle,'mysql_debug');
 
1533
    pointer(mysql_dump_debug_info) := GetProcedureAddress(MysqlLibraryHandle,'mysql_dump_debug_info');
 
1534
    pointer(mysql_eof) := GetProcedureAddress(MysqlLibraryHandle,'mysql_eof');
 
1535
    pointer(mysql_errno) := GetProcedureAddress(MysqlLibraryHandle,'mysql_errno');
 
1536
    pointer(mysql_error) := GetProcedureAddress(MysqlLibraryHandle,'mysql_error');
 
1537
    pointer(mysql_escape_string) := GetProcedureAddress(MysqlLibraryHandle,'mysql_escape_string');
 
1538
    pointer(mysql_fetch_field) := GetProcedureAddress(MysqlLibraryHandle,'mysql_fetch_field');
 
1539
    pointer(mysql_fetch_field_direct) := GetProcedureAddress(MysqlLibraryHandle,'mysql_fetch_field_direct');
 
1540
    pointer(mysql_fetch_fields) := GetProcedureAddress(MysqlLibraryHandle,'mysql_fetch_fields');
 
1541
    pointer(mysql_fetch_lengths) := GetProcedureAddress(MysqlLibraryHandle,'mysql_fetch_lengths');
 
1542
    pointer(mysql_fetch_row) := GetProcedureAddress(MysqlLibraryHandle,'mysql_fetch_row');
 
1543
    pointer(mysql_field_seek) := GetProcedureAddress(MysqlLibraryHandle,'mysql_field_seek');
 
1544
    pointer(mysql_field_count) := GetProcedureAddress(MysqlLibraryHandle,'mysql_field_count');
 
1545
    pointer(mysql_field_tell) := GetProcedureAddress(MysqlLibraryHandle,'mysql_field_tell');
 
1546
    pointer(mysql_free_result) := GetProcedureAddress(MysqlLibraryHandle,'mysql_free_result');
 
1547
    pointer(mysql_get_client_info) := GetProcedureAddress(MysqlLibraryHandle,'mysql_get_client_info');
 
1548
    pointer(mysql_get_client_version) := GetProcedureAddress(MysqlLibraryHandle,'mysql_get_client_version');
 
1549
    pointer(mysql_get_host_info) := GetProcedureAddress(MysqlLibraryHandle,'mysql_get_host_info');
 
1550
    pointer(mysql_get_server_version) := GetProcedureAddress(MysqlLibraryHandle,'mysql_get_server_version');
 
1551
    pointer(mysql_get_proto_info) := GetProcedureAddress(MysqlLibraryHandle,'mysql_get_proto_info');
 
1552
    pointer(mysql_get_server_info) := GetProcedureAddress(MysqlLibraryHandle,'mysql_get_server_info');
 
1553
    pointer(mysql_info) := GetProcedureAddress(MysqlLibraryHandle,'mysql_info');
 
1554
    pointer(mysql_init) := GetProcedureAddress(MysqlLibraryHandle,'mysql_init');
 
1555
    pointer(mysql_insert_id) := GetProcedureAddress(MysqlLibraryHandle,'mysql_insert_id');
 
1556
    pointer(mysql_kill) := GetProcedureAddress(MysqlLibraryHandle,'mysql_kill');
 
1557
    pointer(mysql_library_end) := GetProcedureAddress(MysqlLibraryHandle,'mysql_server_end');
 
1558
    pointer(mysql_library_init) := GetProcedureAddress(MysqlLibraryHandle,'mysql_server_init');
 
1559
    pointer(mysql_list_dbs) := GetProcedureAddress(MysqlLibraryHandle,'mysql_list_dbs');
 
1560
    pointer(mysql_list_fields) := GetProcedureAddress(MysqlLibraryHandle,'mysql_list_fields');
 
1561
    pointer(mysql_list_processes) := GetProcedureAddress(MysqlLibraryHandle,'mysql_list_processes');
 
1562
    pointer(mysql_list_tables) := GetProcedureAddress(MysqlLibraryHandle,'mysql_list_tables');
 
1563
    pointer(mysql_more_results) := GetProcedureAddress(MysqlLibraryHandle,'mysql_more_results');
 
1564
    pointer(mysql_next_result) := GetProcedureAddress(MysqlLibraryHandle,'mysql_next_result');
 
1565
    pointer(mysql_num_fields) := GetProcedureAddress(MysqlLibraryHandle,'mysql_num_fields');
 
1566
    pointer(mysql_num_rows) := GetProcedureAddress(MysqlLibraryHandle,'mysql_num_rows');
 
1567
    pointer(mysql_options) := GetProcedureAddress(MysqlLibraryHandle,'mysql_options');
 
1568
    pointer(mysql_ping) := GetProcedureAddress(MysqlLibraryHandle,'mysql_ping');
 
1569
    pointer(mysql_query) := GetProcedureAddress(MysqlLibraryHandle,'mysql_query');
 
1570
    pointer(mysql_real_connect) := GetProcedureAddress(MysqlLibraryHandle,'mysql_real_connect');
 
1571
    pointer(mysql_real_escape_string) := GetProcedureAddress(MysqlLibraryHandle,'mysql_real_escape_string');
 
1572
    pointer(mysql_real_query) := GetProcedureAddress(MysqlLibraryHandle,'mysql_real_query');
 
1573
    pointer(mysql_refresh) := GetProcedureAddress(MysqlLibraryHandle,'mysql_refresh');
 
1574
//    pointer(mysql_reload) := GetProcedureAddress(MysqlLibraryHandle,'mysql_reload');
 
1575
    pointer(mysql_rollback) := GetProcedureAddress(MysqlLibraryHandle,'mysql_rollback');
 
1576
    pointer(mysql_row_seek) := GetProcedureAddress(MysqlLibraryHandle,'mysql_row_seek');
 
1577
    pointer(mysql_row_tell) := GetProcedureAddress(MysqlLibraryHandle,'mysql_row_tell');
 
1578
    pointer(mysql_select_db) := GetProcedureAddress(MysqlLibraryHandle,'mysql_select_db');
 
1579
    pointer(mysql_server_end) := GetProcedureAddress(MysqlLibraryHandle,'mysql_server_end');
 
1580
    pointer(mysql_server_init) := GetProcedureAddress(MysqlLibraryHandle,'mysql_server_init');
 
1581
    pointer(mysql_set_server_option) := GetProcedureAddress(MysqlLibraryHandle,'mysql_set_server_option');
 
1582
    pointer(mysql_sqlstate) := GetProcedureAddress(MysqlLibraryHandle,'mysql_sqlstate');
 
1583
    pointer(mysql_shutdown) := GetProcedureAddress(MysqlLibraryHandle,'mysql_shutdown');
 
1584
    pointer(mysql_stat) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stat');
 
1585
    pointer(mysql_store_result) := GetProcedureAddress(MysqlLibraryHandle,'mysql_store_result');
 
1586
    pointer(mysql_thread_id) := GetProcedureAddress(MysqlLibraryHandle,'mysql_thread_id');
 
1587
//    pointer(mysql_thread_save) := GetProcedureAddress(MysqlLibraryHandle,'mysql_thread_save');
 
1588
    pointer(mysql_use_result) := GetProcedureAddress(MysqlLibraryHandle,'mysql_use_result');
 
1589
    pointer(mysql_warning_count) := GetProcedureAddress(MysqlLibraryHandle,'mysql_warning_count');
 
1590
    pointer(mysql_stmt_init) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_init');
 
1591
    pointer(mysql_stmt_prepare) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_prepare');
 
1592
    pointer(mysql_stmt_execute) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_execute');
 
1593
    pointer(mysql_stmt_fetch) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_fetch');
 
1594
    pointer(mysql_stmt_fetch_column) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_fetch_column');
 
1595
    pointer(mysql_stmt_store_result) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_store_result');
 
1596
    pointer(mysql_stmt_param_count) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_param_count');
 
1597
    pointer(mysql_stmt_attr_set) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_attr_set');
 
1598
    pointer(mysql_stmt_attr_get) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_attr_get');
 
1599
    pointer(mysql_stmt_bind_param) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_bind_param');
 
1600
    pointer(mysql_stmt_bind_result) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_bind_result');
 
1601
    pointer(mysql_stmt_close) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_close');
 
1602
    pointer(mysql_stmt_reset) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_reset');
 
1603
    pointer(mysql_stmt_free_result) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_free_result');
 
1604
    pointer(mysql_stmt_send_long_data) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_send_long_data');
 
1605
    pointer(mysql_stmt_result_metadata) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_result_metadata');
 
1606
    pointer(mysql_stmt_param_metadata) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_param_metadata');
 
1607
    pointer(mysql_stmt_errno) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_errno');
 
1608
    pointer(mysql_stmt_error) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_error');
 
1609
    pointer(mysql_stmt_sqlstate) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_sqlstate');
 
1610
    pointer(mysql_stmt_row_seek) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_row_seek');
 
1611
    pointer(mysql_stmt_row_tell) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_row_tell');
 
1612
    pointer(mysql_stmt_data_seek) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_data_seek');
 
1613
    pointer(mysql_stmt_num_rows) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_num_rows');
 
1614
    pointer(mysql_stmt_affected_rows) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_affected_rows');
 
1615
    pointer(mysql_stmt_insert_id) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_insert_id');
 
1616
    pointer(mysql_stmt_field_count) := GetProcedureAddress(MysqlLibraryHandle,'mysql_stmt_field_count');
 
1617
    end
 
1618
  else
 
1619
    If (LibraryName<>LoadedLibrary) then
 
1620
      Raise EInOUtError.CreateFmt(SErrAlreadyLoaded,[LoadedLibrary]);
 
1621
  Result:=RefCount;  
 
1622
end;
 
1623
 
 
1624
Procedure ReleaseMysql;
 
1625
 
 
1626
begin
 
1627
  if RefCount> 1 then
 
1628
    Dec(RefCount)
 
1629
  else if UnloadLibrary(MysqlLibraryHandle) then 
 
1630
    begin
 
1631
    Dec(RefCount);
 
1632
    MysqlLibraryHandle := NilHandle;
 
1633
    LoadedLibrary:='';
 
1634
    end;
 
1635
end;
 
1636
 
 
1637
{$ENDIF}
 
1638
    function net_new_transaction(net : st_net) : st_net;
 
1639
    begin
 
1640
      net.pkt_nr := 0;
 
1641
      result := net;
 
1642
    end;
 
1643
 
 
1644
    function IS_PRI_KEY(n : longint) : boolean;
 
1645
    begin
 
1646
      IS_PRI_KEY:=(n and PRI_KEY_FLAG)<>0;
 
1647
    end;
 
1648
 
 
1649
    function IS_NOT_NULL(n : longint) : boolean;
 
1650
    begin
 
1651
     IS_NOT_NULL:=(n and NOT_NULL_FLAG)<>0;
 
1652
    end;
 
1653
 
 
1654
    function IS_BLOB(n : longint) : boolean;
 
1655
    begin
 
1656
     IS_BLOB:=(n and BLOB_FLAG)<>0;
 
1657
    end;
 
1658
 
 
1659
    function IS_NUM_FIELD(f : pst_mysql_field) : boolean;
 
1660
    begin
 
1661
       IS_NUM_FIELD:=((f^.flags) and NUM_FLAG)<>0;
 
1662
    end;
 
1663
 
 
1664
    function IS_NUM(t : enum_field_types) : boolean;
 
1665
    begin
 
1666
{$IFDEF mysql50}
 
1667
      IS_NUM := (t <= FIELD_TYPE_INT24) or (t=FIELD_TYPE_YEAR) or (t=FIELD_TYPE_NEWDECIMAL);
 
1668
{$ELSE}
 
1669
      IS_NUM := (t <= FIELD_TYPE_INT24) or (t=FIELD_TYPE_YEAR);
 
1670
{$ENDIF}
 
1671
    end;
 
1672
 
 
1673
    function INTERNAL_NUM_FIELD(f : Pst_mysql_field) : boolean;
 
1674
    begin
 
1675
      INTERNAL_NUM_FIELD := (f^.ftype <= FIELD_TYPE_INT24) and ((f^.ftype <> FIELD_TYPE_TIMESTAMP)
 
1676
      or (f^.length = 14) or (f^.length=8)) or (f^.ftype=FIELD_TYPE_YEAR);
 
1677
    end;
 
1678
 
 
1679
    function mysql_reload(mysql : PMySQL) : longint;
 
1680
    begin
 
1681
      mysql_reload:=mysql_refresh(mysql,REFRESH_GRANT);
 
1682
    end;
 
1683
 
 
1684
    function simple_command(mysql,command,arg,length,skip_check : longint) : longint;
 
1685
    begin
 
1686
      //simple_command:=mysql^.(methods^.advanced_command)(mysqlcommandNullS0arglengthskip_check);
 
1687
      result := -1;
 
1688
    end;
 
1689
 
 
1690
 
 
1691
end.