2
0

mysql.inc 70 KB

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