mysql4_comdyn.pp 6.1 KB

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