mysql_com.pp 11 KB

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