mysql3_com.pp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. unit mysql3_com;
  2. {$undef use_mysql_321} { if undefined, use mysql 3.23 interface }
  3. { updated to match version 3.23 header files of mysql by Bernhard Steffen
  4. ([email protected])
  5. }
  6. interface
  7. uses
  8. mysql3_version;
  9. {$ifdef win32}
  10. Const mysqllib = 'libmysql';
  11. {$else}
  12. Const mysqllib = 'mysqlclient';
  13. {$endif}
  14. {$ifndef win32}
  15. {$linklib c}
  16. {$linklib m}
  17. {$linklib mysqlclient}
  18. {$endif}
  19. {$r+,i+,o+}
  20. {
  21. Common definition between mysql server & client
  22. }
  23. {$packrecords 4}
  24. { Extra types introduced for pascal }
  25. Type
  26. pbyte = ^byte;
  27. pcardinal = ^cardinal;
  28. Socket = longint;
  29. my_bool = byte;
  30. Const
  31. NAME_LEN = 64 ; { Field/table name length }
  32. LOCAL_HOST : pchar = 'localhost' ;
  33. MYSQL_PORT = 3306; { Alloced by ISI for MySQL }
  34. MYSQL_UNIX_ADDR : pchar = '/tmp/mysql.sock';
  35. Type
  36. enum_server_command = ( COM_SLEEP,COM_QUIT,COM_INIT_DB,COM_QUERY,
  37. COM_FIELD_LIST,COM_CREATE_DB,COM_DROP_DB,COM_REFRESH,
  38. COM_SHUTDOWN,COM_STATISTICS,
  39. COM_PROCESS_INFO,COM_CONNECT,COM_PROCESS_KILL,
  40. COM_DEBUG);
  41. Const
  42. NOT_NULL_FLAG = 1; { Field can't be NULL }
  43. PRI_KEY_FLAG = 2; { Field is part of a primary key }
  44. UNIQUE_KEY_FLAG = 4; { Field is part of a unique key }
  45. MULTIPLE_KEY_FLAG = 8; { Field is part of a key }
  46. BLOB_FLAG = 16; { Field is a blob }
  47. UNSIGNED_FLAG = 32; { Field is unsigned }
  48. ZEROFILL_FLAG = 64; { Field is zerofill }
  49. BINARY_FLAG = 128;
  50. { The following are only sent to new clients }
  51. ENUM_FLAG = 256; { field is an enum }
  52. AUTO_INCREMENT_FLAG = 512; { field is a autoincrement field }
  53. TIMESTAMP_FLAG = 1024; { Field is a timestamp }
  54. PART_KEY_FLAG = 16384; { Intern; Part of some key }
  55. GROUP_FLAG = 32768; { Intern group field }
  56. {$ifndef use_mysql_321}
  57. UNIQUE_FLAG = 65536; { Intern: Used by sql_yacc }
  58. {$endif}
  59. REFRESH_GRANT = 1; { Refresh grant tables }
  60. REFRESH_LOG = 2; { Start on new log file }
  61. REFRESH_TABLES = 4; { close all tables }
  62. {$ifndef use_mysql_321}
  63. REFRESH_HOSTS = 8; { Flush host cache }
  64. REFRESH_STATUS = 16; { Flush status variables }
  65. REFRESH_THREADS = 32; { Flush status variables }
  66. REFRESH_SLAVE = 64; { Reset master info and restart slave
  67. thread }
  68. REFRESH_MASTER = 128; { Remove all bin logs in the index
  69. and truncate the index }
  70. {$endif}
  71. {$ifndef use_mysql_321}
  72. { The following can't be set with mysql_refresh() }
  73. REFRESH_READ_LOCK = 16384; { Lock tables for read }
  74. REFRESH_FAST = 32768; { Intern flag }
  75. {$endif}
  76. CLIENT_LONG_PASSWORD = 1; { new more secure passwords }
  77. CLIENT_FOUND_ROWS = 2; { Found instead of affected rows }
  78. CLIENT_LONG_FLAG = 4; { Get all column flags }
  79. {$ifndef use_mysql_321}
  80. CLIENT_CONNECT_WITH_DB = 8; { One can specify db on connect }
  81. CLIENT_NO_SCHEMA = 16; { Don't allow database.table.column }
  82. CLIENT_COMPRESS = 32; { Can use compression protocol }
  83. CLIENT_ODBC = 64; { Odbc client }
  84. CLIENT_LOCAL_FILES = 128; { Can use LOAD DATA LOCAL }
  85. CLIENT_IGNORE_SPACE = 256; { Ignore spaces before '(' }
  86. CLIENT_CHANGE_USER = 512; { Support the mysql_change_user() }
  87. CLIENT_INTERACTIVE = 1024; { This is an interactive client }
  88. CLIENT_SSL = 2048; { Switch to SSL after handshake }
  89. CLIENT_IGNORE_SIGPIPE = 4096; { IGNORE sigpipes }
  90. CLIENT_TRANSACTIONS = 8192; { Client knows about transactions }
  91. SERVER_STATUS_IN_TRANS = 1; { Transaction has started }
  92. SERVER_STATUS_AUTOCOMMIT = 2; { Server in auto_commit mode }
  93. {$endif}
  94. MYSQL_ERRMSG_SIZE = 200;
  95. NET_READ_TIMEOUT = 30; { Timeout on read }
  96. NET_WRITE_TIMEOUT = 60; { Timeout on write }
  97. NET_WAIT_TIMEOUT = 8*60*60; { Wait for new query }
  98. Type
  99. pst_used_mem = ^st_used_mem;
  100. st_used_mem = record { struct for once_alloc }
  101. next : pst_used_mem; { Next block in use }
  102. left : cardinal; { memory left in block }
  103. size : cardinal; { size of block }
  104. end;
  105. TUSED_MEM = st_used_mem;
  106. PUSED_MEM = ^TUSED_MEM;
  107. TError_handler = Procedure;
  108. st_mem_root = record
  109. free : PUSED_MEM;
  110. used : PUSED_MEM;
  111. {$ifndef use_mysql_321}
  112. pre_alloc: PUSED_MEM;
  113. {$endif use_mysql_321}
  114. min_malloc : cardinal;
  115. block_size : cardinal;
  116. error_handler : TERROR_Handler;
  117. end;
  118. TMEM_ROOT = st_mem_root;
  119. PMEM_ROOT = ^TMEM_ROOT;
  120. Type
  121. net_type = (NET_TYPE_TCPIP, NET_TYPE_SOCKET, NETTYPE_NAMEDPIPE);
  122. st_net = record
  123. nettype : net_type; //DT
  124. fd : Socket;
  125. fcntl : Longint;
  126. buff,buff_end,write_pos,read_pos : Pchar;//DT
  127. last_error : array [0..MYSQL_ERRMSG_SIZE-1] of char;
  128. last_errno,max_packet,timeout,pkt_nr : Cardinal;
  129. error,return_errno : my_bool;
  130. compress : my_bool; //DT
  131. {$ifndef use_mysql_321}
  132. no_send_ok : my_bool;
  133. {$endif}
  134. remain_in_buf,r_length, buf_length, where_b : cardinal; //DT
  135. {$ifndef use_mysql_321}
  136. return_status : ^Cardinal;
  137. reading_or_writing : my_bool;
  138. {$else}
  139. more : my_bool;//DT
  140. {$endif}
  141. save_char : char; //DT
  142. end;
  143. TNET = st_net;
  144. PNET = ^TNET;
  145. Const
  146. packet_error : longint = -1;
  147. Type
  148. enum_field_types = ( FIELD_TYPE_DECIMAL, FIELD_TYPE_TINY,
  149. FIELD_TYPE_SHORT, FIELD_TYPE_LONG,
  150. FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE,
  151. FIELD_TYPE_NULL, FIELD_TYPE_TIMESTAMP,
  152. FIELD_TYPE_LONGLONG,FIELD_TYPE_INT24,
  153. FIELD_TYPE_DATE, FIELD_TYPE_TIME,
  154. FIELD_TYPE_DATETIME,
  155. {$ifndef use_mysql_321}
  156. FIELD_TYPE_YEAR,
  157. FIELD_TYPE_NEWDATE,
  158. {$endif}
  159. FIELD_TYPE_ENUM := 247,
  160. FIELD_TYPE_SET := 248,
  161. FIELD_TYPE_TINY_BLOB := 249,
  162. FIELD_TYPE_MEDIUM_BLOB := 250,
  163. FIELD_TYPE_LONG_BLOB :=251,
  164. FIELD_TYPE_BLOB :=252,
  165. FIELD_TYPE_VAR_STRING :=253,
  166. FIELD_TYPE_STRING:=254);
  167. Const
  168. FIELD_TYPE_CHAR = FIELD_TYPE_TINY; { For compability }
  169. FIELD_TYPE_INTERVAL = FIELD_TYPE_ENUM; { For compability }
  170. Procedure sql_free (root : PMEM_ROOT);stdcall;
  171. Procedure init_alloc_root (root: PMEM_ROOT;block_size : Cardinal);stdcall;
  172. Function sql_alloc_first_block(root : PMEM_ROOT) : my_bool;stdcall;
  173. Function sql_alloc_root(mem_root : PMEM_ROOT;len : Cardinal) : longint;stdcall;
  174. Function sql_strdup_root(root : PMEM_ROOT;st : pchar) : pchar;stdcall;
  175. Function sql_memdup_root(root: PMEM_ROOT;st : pchar; len : Cardinal): longint;stdcall;
  176. {
  177. extern unsigned long max_allowed_packet;
  178. extern unsigned long net_buffer_length;
  179. }
  180. {
  181. #define net_new_transaction(net) ((net)->pkt_nr=0)
  182. }
  183. Function my_net_init(net :PNET; fd : Socket) : Longint;stdcall;
  184. procedure net_end(net : PNET);stdcall;
  185. Procedure net_clear(net : PNET);stdcall;
  186. Function net_flush(net : PNET) : longint;stdcall;
  187. Function my_net_write(net : PNET;packet : pbyte;len : cardinal) : longint;stdcall;
  188. Function net_write_command(net : PNET; command : char;packet : pbyte;len : cardinal) : longint;stdcall;
  189. Function net_real_write(net : PNET;packet : pbyte; len : Cardinal) : longint;stdcall;
  190. Function my_net_read(net : PNET) : Cardinal;stdcall;
  191. Type
  192. TRand_struct = record
  193. seed,seed2,max_value : Cardinal;
  194. max_value_dbl : double;
  195. end;
  196. PRand_struct = ^TRand_struct;
  197. { The following is for user defined functions }
  198. Item_result = (STRING_RESULT,REAL_RESULT,INT_RESULT);
  199. st_udf_args = record
  200. arg_count : cardinal; { Number of arguments }
  201. arg_type : ^Item_result; { Pointer to item_results }
  202. args : ppchar; { Pointer to argument }
  203. lengths : PCardinal; { Length of string arguments }
  204. end;
  205. TUDF_ARGS = st_udf_args;
  206. PUDPF_ARGS = ^TUDF_ARGS;
  207. { This holds information about the result }
  208. st_udf_init = record
  209. maybe_null : my_bool; { 1 if function can return NULL }
  210. decimals : cardinal; { for real functions }
  211. max_length : Cardinal; { For string functions }
  212. ptr : PChar; { free pointer for function data }
  213. end;
  214. TUDF_INIT = st_udf_init;
  215. PUDF_INIT = TUDF_INIT;
  216. { Prototypes to password functions }
  217. procedure randominit(rand : Prand_struct; seed1,seed2 : Cardinal);stdcall;
  218. Function rnd(rand : Prand_struct) : double;stdcall;
  219. procedure make_scrambled_password(toarg, passwd : Pchar);stdcall;
  220. procedure get_salt_from_password(res : pcardinal; password : pchar);stdcall;
  221. procedure scramble(toarg,message,password : pchar; old_ver : my_bool);stdcall;
  222. function check_scramble(scramble,message : pchar; salt : cardinal;old_ver:my_bool) : my_bool;stdcall;
  223. function get_tty_password(opt_message: pchar) : pchar;stdcall;
  224. {
  225. #define NULL_LENGTH ((unsigned long) ~0) { For net_store_length }
  226. }
  227. implementation
  228. Procedure sql_free (root : PMEM_ROOT);stdcall;external;
  229. Procedure init_alloc_root (root: PMEM_ROOT;block_size : Cardinal);stdcall;external;
  230. Function sql_alloc_first_block(root : PMEM_ROOT) : my_bool;stdcall;external;
  231. Function sql_alloc_root(mem_root : PMEM_ROOT;len : Cardinal) : longint;stdcall;external;
  232. Function sql_strdup_root(root : PMEM_ROOT;st : pchar) : pchar;stdcall;external;
  233. Function sql_memdup_root(root: PMEM_ROOT;st : pchar; len : Cardinal) : longint;stdcall;external;
  234. Function my_net_init(net :PNET; fd : Socket) : Longint;stdcall;external;
  235. procedure net_end(net : PNET);stdcall;external;
  236. Procedure net_clear(net : PNET);stdcall;external;
  237. Function net_flush(net : PNET) : longint;stdcall;external;
  238. Function my_net_write(net : PNET;packet : pbyte;len : cardinal) : longint;stdcall;external;
  239. Function net_write_command(net : PNET; command : char;packet : pbyte;len : cardinal) : longint;stdcall;external;
  240. Function net_real_write(net : PNET;packet : pbyte; len : Cardinal) : longint;stdcall;external;
  241. Function my_net_read(net : PNET) : Cardinal;stdcall;external;
  242. procedure randominit(rand : Prand_struct; seed1,seed2 : Cardinal);stdcall;external;
  243. Function rnd(rand : Prand_struct) : double;stdcall;external;
  244. procedure make_scrambled_password(toarg, passwd : Pchar);stdcall;external;
  245. procedure get_salt_from_password(res : pcardinal; password : pchar);stdcall;external;
  246. procedure scramble(toarg,message,password : pchar; old_ver : my_bool);stdcall;external;
  247. function check_scramble(scramble,message : pchar; salt : cardinal;old_ver:my_bool) : my_bool;stdcall;external;
  248. function get_tty_password(opt_message: pchar) : pchar;stdcall;external;
  249. end.
  250. $Log$
  251. Revision 1.1 2004-09-30 19:34:47 michael
  252. + Split everything in version 3 and version 4
  253. Revision 1.1 2004/09/28 18:38:23 michael
  254. + Moved to subdir, switching to version 4.0
  255. Revision 1.5 2004/08/05 10:36:25 olle
  256. + added, on unixes, $linklib mysqlclient
  257. Revision 1.4 2004/07/01 20:04:17 jonas
  258. * fixed st_mem_root record (only changed for 3.23, may still be wrong for
  259. 3.21)
  260. Revision 1.3 2002/09/07 15:42:52 peter
  261. * old logs removed and tabs fixed
  262. Revision 1.2 2002/08/26 17:52:31 michael
  263. + Upgraded to 3.23
  264. }