mysql_com.pp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. unit mysql_com;
  2. interface
  3. {$ifndef win32}
  4. {$linklib mysqlclient}
  5. {$linklib m}
  6. {$linklib c}
  7. {$endif}
  8. {
  9. Common definition between mysql server & client
  10. }
  11. {$packrecords 4}
  12. { Extra types introduced for pascal }
  13. Type
  14. pbyte = ^byte;
  15. pcardinal = ^cardinal;
  16. Socket = longint;
  17. my_bool = byte;
  18. Const
  19. NAME_LEN = 64 ; { Field/table name length }
  20. LOCAL_HOST : pchar = 'localhost' ;
  21. MYSQL_PORT = 3306; { Alloced by ISI for MySQL }
  22. MYSQL_UNIX_ADDR : pchar = '/tmp/mysql.sock';
  23. Type
  24. enum_server_command = ( COM_SLEEP,COM_QUIT,COM_INIT_DB,COM_QUERY,
  25. COM_FIELD_LIST,COM_CREATE_DB,COM_DROP_DB,COM_REFRESH,
  26. COM_SHUTDOWN,COM_STATISTICS,
  27. COM_PROCESS_INFO,COM_CONNECT,COM_PROCESS_KILL,
  28. COM_DEBUG);
  29. Const
  30. NOT_NULL_FLAG = 1; { Field can't be NULL }
  31. PRI_KEY_FLAG = 2; { Field is part of a primary key }
  32. UNIQUE_KEY_FLAG = 4; { Field is part of a unique key }
  33. MULTIPLE_KEY_FLAG = 8; { Field is part of a key }
  34. BLOB_FLAG = 16; { Field is a blob }
  35. UNSIGNED_FLAG = 32; { Field is unsigned }
  36. ZEROFILL_FLAG = 64; { Field is zerofill }
  37. BINARY_FLAG = 128;
  38. { The following are only sent to new clients }
  39. ENUM_FLAG = 256; { field is an enum }
  40. AUTO_INCREMENT_FLAG = 512; { field is a autoincrement field }
  41. TIMESTAMP_FLAG = 1024; { Field is a timestamp }
  42. PART_KEY_FLAG = 16384; { Intern; Part of some key }
  43. GROUP_FLAG = 32768; { Intern group field }
  44. REFRESH_GRANT = 1; { Refresh grant tables }
  45. REFRESH_LOG = 2; { Start on new log file }
  46. REFRESH_TABLES = 4; { close all tables }
  47. CLIENT_LONG_PASSWORD = 1; { new more secure passwords }
  48. CLIENT_FOUND_ROWS = 2; { Found instead of affected rows }
  49. CLIENT_LONG_FLAG = 4; { Get all column flags }
  50. Type
  51. pst_used_mem = ^st_used_mem;
  52. st_used_mem = record { struct for once_alloc }
  53. next : pst_used_mem; { Next block in use }
  54. left : cardinal; { memory left in block }
  55. size : cardinal; { size of block }
  56. end;
  57. TUSED_MEM = st_used_mem;
  58. PUSED_MEM = ^TUSED_MEM;
  59. TError_handler = Procedure;
  60. st_mem_root = record
  61. free : PUSED_MEM;
  62. used : PUSED_MEM;
  63. min_malloc : cardinal;
  64. block_size : cardinal;
  65. error_handler : TERROR_Handler;
  66. end;
  67. TMEM_ROOT = st_mem_root;
  68. PMEM_ROOT = ^TMEM_ROOT;
  69. Const
  70. MYSQL_ERRMSG_SIZE = 200;
  71. Type
  72. net_type = (NET_TYPE_TCPIP, NET_TYPE_SOCKET, NETTYPE_NAMEDPIPE);
  73. st_net = record
  74. nettype : net_type; //DT
  75. fd : Socket;
  76. fcntl : Longint;
  77. buff,buff_end,write_pos,read_pos : Pchar;//DT
  78. last_error : array [0..MYSQL_ERRMSG_SIZE-1] of char;
  79. last_errno,max_packet,timeout,pkt_nr : Cardinal;
  80. error,return_errno : my_bool;
  81. compress : my_bool; //DT
  82. remain_in_buf,r_length, buf_length, where_b : cardinal; //DT
  83. more : my_bool;//DT
  84. save_char : char; //DT
  85. end;
  86. TNET = st_net;
  87. PNET = ^TNET;
  88. Const
  89. packet_error : longint = -1;
  90. Type
  91. enum_field_types = ( FIELD_TYPE_DECIMAL, FIELD_TYPE_TINY,
  92. FIELD_TYPE_SHORT, FIELD_TYPE_LONG,
  93. FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE,
  94. FIELD_TYPE_NULL, FIELD_TYPE_TIMESTAMP,
  95. FIELD_TYPE_LONGLONG,FIELD_TYPE_INT24,
  96. FIELD_TYPE_DATE, FIELD_TYPE_TIME,
  97. FIELD_TYPE_DATETIME,
  98. FIELD_TYPE_ENUM := 247,
  99. FIELD_TYPE_SET := 248,
  100. FIELD_TYPE_TINY_BLOB := 249,
  101. FIELD_TYPE_MEDIUM_BLOB := 250,
  102. FIELD_TYPE_LONG_BLOB :=251,
  103. FIELD_TYPE_BLOB :=252,
  104. FIELD_TYPE_VAR_STRING :=253,
  105. FIELD_TYPE_STRING:=254);
  106. Const
  107. FIELD_TYPE_CHAR = FIELD_TYPE_TINY; { For compability }
  108. FIELD_TYPE_INTERVAL = FIELD_TYPE_ENUM; { For compability }
  109. Procedure sql_free (root : PMEM_ROOT);{$ifdef win32} stdcall {$else} cdecl {$endif};
  110. Procedure init_alloc_root (root: PMEM_ROOT;block_size : Cardinal);{$ifdef win32} stdcall {$else} cdecl {$endif};
  111. Function sql_alloc_first_block(root : PMEM_ROOT) : my_bool;{$ifdef win32} stdcall {$else} cdecl {$endif};
  112. Function sql_alloc_root(mem_root : PMEM_ROOT;len : Cardinal) : longint;{$ifdef win32} stdcall {$else} cdecl {$endif};
  113. Function sql_strdup_root(root : PMEM_ROOT;st : pchar) : pchar;{$ifdef win32} stdcall {$else} cdecl {$endif};
  114. Function sql_memdup_root(root: PMEM_ROOT;st : pchar; len : Cardinal): longint;{$ifdef win32} stdcall {$else} cdecl {$endif};
  115. {
  116. extern unsigned long max_allowed_packet;
  117. extern unsigned long net_buffer_length;
  118. }
  119. {
  120. #define net_new_transaction(net) ((net)->pkt_nr=0)
  121. }
  122. Function my_net_init(net :PNET; fd : Socket) : Longint;{$ifdef win32} stdcall {$else} cdecl {$endif};
  123. procedure net_end(net : PNET);{$ifdef win32} stdcall {$else} cdecl {$endif};
  124. Procedure net_clear(net : PNET);{$ifdef win32} stdcall {$else} cdecl {$endif};
  125. Function net_flush(net : PNET) : longint;{$ifdef win32} stdcall {$else} cdecl {$endif};
  126. Function my_net_write(net : PNET;packet : pbyte;len : cardinal) : longint;{$ifdef win32} stdcall {$else} cdecl {$endif};
  127. Function net_write_command(net : PNET; command : char;packet : pbyte;len : cardinal) : longint;{$ifdef win32} stdcall {$else} cdecl {$endif};
  128. Function net_real_write(net : PNET;packet : pbyte; len : Cardinal) : longint;{$ifdef win32} stdcall {$else} cdecl {$endif};
  129. Function my_net_read(net : PNET) : Cardinal;{$ifdef win32} stdcall {$else} cdecl {$endif};
  130. Type
  131. TRand_struct = record
  132. seed,seed2,max_value : Cardinal;
  133. max_value_dbl : double;
  134. end;
  135. PRand_struct = ^TRand_struct;
  136. { The following is for user defined functions }
  137. Item_result = (STRING_RESULT,REAL_RESULT,INT_RESULT);
  138. st_udf_args = record
  139. arg_count : cardinal; { Number of arguments }
  140. arg_type : ^Item_result; { Pointer to item_results }
  141. args : ppchar; { Pointer to argument }
  142. lengths : PCardinal; { Length of string arguments }
  143. end;
  144. TUDF_ARGS = st_udf_args;
  145. PUDPF_ARGS = ^TUDF_ARGS;
  146. { This holds information about the result }
  147. st_udf_init = record
  148. maybe_null : my_bool; { 1 if function can return NULL }
  149. decimals : cardinal; { for real functions }
  150. max_length : Cardinal; { For string functions }
  151. ptr : PChar; { free pointer for function data }
  152. end;
  153. TUDF_INIT = st_udf_init;
  154. PUDF_INIT = TUDF_INIT;
  155. { Prototypes to password functions }
  156. procedure randominit(rand : Prand_struct; seed1,seed2 : Cardinal);{$ifdef win32} stdcall {$else} cdecl {$endif};
  157. Function rnd(rand : Prand_struct) : double;{$ifdef win32} stdcall {$else} cdecl {$endif};
  158. procedure make_scrambled_password(toarg, passwd : Pchar);{$ifdef win32} stdcall {$else} cdecl {$endif};
  159. procedure get_salt_from_password(res : pcardinal; password : pchar);{$ifdef win32} stdcall {$else} cdecl {$endif};
  160. procedure scramble(toarg,message,password : pchar; old_ver : my_bool);{$ifdef win32} stdcall {$else} cdecl {$endif};
  161. function check_scramble(scramble,message : pchar; salt : cardinal;old_ver:my_bool) : my_bool;{$ifdef win32} stdcall {$else} cdecl {$endif};
  162. function get_tty_password(opt_message: pchar) : pchar;{$ifdef win32} stdcall {$else} cdecl {$endif};
  163. {
  164. #define NULL_LENGTH ((unsigned long) ~0) { For net_store_length }
  165. }
  166. implementation
  167. Procedure sql_free (root : PMEM_ROOT);{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  168. Procedure init_alloc_root (root: PMEM_ROOT;block_size : Cardinal);{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  169. Function sql_alloc_first_block(root : PMEM_ROOT) : my_bool;{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  170. Function sql_alloc_root(mem_root : PMEM_ROOT;len : Cardinal) : longint;{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  171. Function sql_strdup_root(root : PMEM_ROOT;st : pchar) : pchar;{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  172. Function sql_memdup_root(root: PMEM_ROOT;st : pchar; len : Cardinal) : longint;{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  173. Function my_net_init(net :PNET; fd : Socket) : Longint;{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  174. procedure net_end(net : PNET);{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  175. Procedure net_clear(net : PNET);{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  176. Function net_flush(net : PNET) : longint;{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  177. Function my_net_write(net : PNET;packet : pbyte;len : cardinal) : longint;{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  178. Function net_write_command(net : PNET; command : char;packet : pbyte;len : cardinal) : longint;{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  179. Function net_real_write(net : PNET;packet : pbyte; len : Cardinal) : longint;{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  180. Function my_net_read(net : PNET) : Cardinal;{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  181. procedure randominit(rand : Prand_struct; seed1,seed2 : Cardinal);{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  182. Function rnd(rand : Prand_struct) : double;{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  183. procedure make_scrambled_password(toarg, passwd : Pchar);{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  184. procedure get_salt_from_password(res : pcardinal; password : pchar);{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  185. procedure scramble(toarg,message,password : pchar; old_ver : my_bool);{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  186. function check_scramble(scramble,message : pchar; salt : cardinal;old_ver:my_bool) : my_bool;{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  187. function get_tty_password(opt_message: pchar) : pchar;{$ifdef win32} stdcall {$else} cdecl {$endif};external;
  188. end.
  189. $Log$
  190. Revision 1.1 2002-01-29 17:54:53 peter
  191. * splitted to base and extra
  192. Revision 1.5 2001/04/13 18:04:56 peter
  193. * added missing $ifndef win32
  194. Revision 1.4 2001/03/13 08:50:38 michael
  195. + merged Fixed calling convention for win32
  196. Revision 1.3 2000/12/02 15:24:37 michael
  197. + Merged changes from fixbranch
  198. Revision 1.2 2000/07/13 11:33:26 michael
  199. + removed logs
  200. }