mysql4_comdyn.pp 6.0 KB

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