mysql4_comdyn.pp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. {
  2. Contains the MySQL_com functions calls
  3. Call InitialiseMysql4_com before using any of the calls, and call ReleaseMysql4_com
  4. when finished.
  5. }
  6. unit mysql4_comdyn;
  7. {$mode objfpc}{$H+}
  8. {$MACRO on}
  9. interface
  10. uses ctypes,my4_sys,dynlibs, sysutils;
  11. {$IFDEF Unix}
  12. {$DEFINE extdecl:=cdecl}
  13. const
  14. Mysqllib = 'libmysqlclient.so';
  15. {$ENDIF}
  16. {$IFDEF Windows}
  17. {$DEFINE extdecl:=stdcall}
  18. const
  19. Mysqllib = 'libmysql.dll';
  20. {$ENDIF}
  21. {$PACKRECORDS C}
  22. {$i mysql4_comtypes.inc}
  23. { Copyright (C) 2000 MySQL AB
  24. This program is free software; you can redistribute it and/or modify
  25. it under the terms of the GNU General Public License as published by
  26. the Free Software Foundation; either version 2 of the License, or
  27. (at your option) any later version.
  28. This program is distributed in the hope that it will be useful,
  29. but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. GNU General Public License for more details.
  32. You should have received a copy of the GNU General Public License
  33. along with this program; if not, write to the Free Software
  34. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA }
  35. var
  36. my_net_init : function (net:PNET; vio:PVio):longint;extdecl;
  37. net_end : procedure (net:PNET);extdecl;
  38. net_clear : procedure (net:PNET);extdecl;
  39. net_flush : function (net:PNET):longint;extdecl;
  40. my_net_write : function (net:PNET; packet:Pchar; len:dword):longint;extdecl;
  41. net_write_command : function (net:PNET; command:byte; packet:Pchar; len:dword):longint;extdecl;
  42. net_real_write : function (net:PNET; packet:Pchar; len:dword):longint;extdecl;
  43. my_net_read : function (net:PNET):dword;extdecl;
  44. { The following function is not meant for normal usage }
  45. {
  46. struct sockaddr;
  47. int my_connect(my_socket s, const struct sockaddr name, unsigned int namelen,
  48. unsigned int timeout);
  49. }
  50. randominit : procedure (_para1:Prand_struct; seed1:dword; seed2:dword);extdecl;
  51. rnd : function (_para1:Prand_struct):double;extdecl;
  52. make_scrambled_password : procedure (_to:Pchar; password:Pchar);extdecl;
  53. get_salt_from_password : procedure (res:Pdword; password:Pchar);extdecl;
  54. make_password_from_salt : procedure (_to:Pchar; hash_res:Pdword);extdecl;
  55. scramble : function (_to:Pchar; message:Pchar; password:Pchar; old_ver:my_bool):Pchar;extdecl;
  56. check_scramble : function (_para1:Pchar; message:Pchar; salt:Pdword; old_ver:my_bool):my_bool;extdecl;
  57. get_tty_password : function (opt_message:Pchar):Pchar;extdecl;
  58. hash_password : procedure (result:Pdword; password:Pchar);extdecl;
  59. my_init : procedure;extdecl;
  60. load_defaults : procedure (conf_file:Pchar; groups:PPchar; argc:Plongint; argv:PPPchar);extdecl;
  61. my_thread_init : function : my_bool;extdecl;
  62. my_thread_end : procedure ;extdecl;
  63. function packet_error : longint;
  64. { For net_store_length }
  65. { was #define dname def_expr }
  66. function NULL_LENGTH : dword;
  67. Procedure InitialiseMysql4_com;
  68. Procedure ReleaseMysql4_com;
  69. var Mysql4_comLibraryHandle : TLibHandle;
  70. implementation
  71. var RefCount : integer;
  72. Procedure InitialiseMysql4_com;
  73. begin
  74. inc(RefCount);
  75. if RefCount = 1 then
  76. begin
  77. Mysql4_comLibraryHandle := loadlibrary(Mysqllib);
  78. if Mysql4_comLibraryHandle = nilhandle then
  79. begin
  80. RefCount := 0;
  81. Raise EInOutError.Create('Can not load MySQL client. Is it installed? ('+Mysqllib+')');
  82. end;
  83. pointer(my_net_init) := GetProcedureAddress(Mysql4_comLibraryHandle,'my_net_init');
  84. pointer(net_end) := GetProcedureAddress(Mysql4_comLibraryHandle,'net_end');
  85. pointer(net_clear) := GetProcedureAddress(Mysql4_comLibraryHandle,'net_clear');
  86. pointer(net_flush) := GetProcedureAddress(Mysql4_comLibraryHandle,'net_flush');
  87. pointer(my_net_write) := GetProcedureAddress(Mysql4_comLibraryHandle,'my_net_write');
  88. pointer(net_write_command) := GetProcedureAddress(Mysql4_comLibraryHandle,'net_write_command');
  89. pointer(net_real_write) := GetProcedureAddress(Mysql4_comLibraryHandle,'net_real_write');
  90. pointer(my_net_read) := GetProcedureAddress(Mysql4_comLibraryHandle,'my_net_read');
  91. pointer(randominit) := GetProcedureAddress(Mysql4_comLibraryHandle,'randominit');
  92. pointer(rnd) := GetProcedureAddress(Mysql4_comLibraryHandle,'rnd');
  93. pointer(make_scrambled_password) := GetProcedureAddress(Mysql4_comLibraryHandle,'make_scrambled_password');
  94. pointer(get_salt_from_password) := GetProcedureAddress(Mysql4_comLibraryHandle,'get_salt_from_password');
  95. pointer(make_password_from_salt) := GetProcedureAddress(Mysql4_comLibraryHandle,'make_password_from_salt');
  96. pointer(scramble) := GetProcedureAddress(Mysql4_comLibraryHandle,'scramble');
  97. pointer(check_scramble) := GetProcedureAddress(Mysql4_comLibraryHandle,'check_scramble');
  98. pointer(get_tty_password) := GetProcedureAddress(Mysql4_comLibraryHandle,'get_tty_password');
  99. pointer(hash_password) := GetProcedureAddress(Mysql4_comLibraryHandle,'hash_password');
  100. pointer(my_init) := GetProcedureAddress(Mysql4_comLibraryHandle,'my_init');
  101. pointer(load_defaults) := GetProcedureAddress(Mysql4_comLibraryHandle,'load_defaults');
  102. pointer(my_thread_init) := GetProcedureAddress(Mysql4_comLibraryHandle,'my_thread_init');
  103. pointer(my_thread_end) := GetProcedureAddress(Mysql4_comLibraryHandle,'my_thread_end');
  104. end;
  105. end;
  106. Procedure ReleaseMysql4_com;
  107. begin
  108. if RefCount > 0 then dec(RefCount);
  109. if RefCount = 0 then
  110. begin
  111. if not UnloadLibrary(Mysql4_comLibraryHandle) then inc(RefCount);
  112. end;
  113. end;
  114. // Next function also defined in mysql4_com
  115. { was #define dname def_expr }
  116. function packet_error : longint;
  117. { return type might be wrong }
  118. begin
  119. packet_error:= not (dword(0));
  120. end;
  121. // Next function also defined in mysql4_com
  122. { was #define dname def_expr }
  123. function NULL_LENGTH : dword;
  124. begin
  125. NULL_LENGTH:=dword( not (0));
  126. end;
  127. end.