mysql3_comdyn.pp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. {
  2. Contains the MySQL_com functions calls
  3. Call InitialiseMysql3_com before using any of the calls, and call ReleaseMysql3_com
  4. when finished.
  5. }
  6. {$IFNDEF FPC_DOTTEDUNITS}
  7. unit mysql3_comdyn;
  8. {$ENDIF FPC_DOTTEDUNITS}
  9. {
  10. Adapted from mysql4_comdyn by Bram Kuijvenhoven (Hexis BV, The Netherlands)
  11. }
  12. {$mode objfpc}{$H+}
  13. {$MACRO on}
  14. interface
  15. {$IFDEF FPC_DOTTEDUNITS}
  16. uses System.DynLibs, System.SysUtils;
  17. {$ELSE FPC_DOTTEDUNITS}
  18. uses dynlibs, sysutils;
  19. {$ENDIF FPC_DOTTEDUNITS}
  20. {$IFDEF Unix}
  21. {$DEFINE extdecl:=cdecl}
  22. const
  23. Mysqllib = 'libmysqlclient.'+sharedsuffix;
  24. {$ENDIF}
  25. {$IFDEF Windows}
  26. {$DEFINE extdecl:=stdcall}
  27. const
  28. Mysqllib = 'libmysql.dll';
  29. {$ENDIF}
  30. {$PACKRECORDS C}
  31. {$i mysql3_comtypes.inc}
  32. var
  33. sql_free : procedure(root : PMEM_ROOT);extdecl;
  34. init_alloc_root : procedure(root: PMEM_ROOT;block_size : Cardinal);extdecl;
  35. sql_alloc_first_block : function(root : PMEM_ROOT) : my_bool;extdecl;
  36. sql_alloc_root : function(mem_root : PMEM_ROOT;len : Cardinal) : longint;extdecl;
  37. sql_strdup_root : function(root : PMEM_ROOT;st : PAnsiChar) : PAnsiChar;extdecl;
  38. sql_memdup_root : function(root: PMEM_ROOT;st : PAnsiChar; len : Cardinal) : longint;extdecl;
  39. my_net_init : function(net :PNET; fd : Socket) : Longint;extdecl;
  40. net_end : procedure(net : PNET);extdecl;
  41. net_clear : procedure(net : PNET);extdecl;
  42. net_flush : function(net : PNET) : longint;extdecl;
  43. my_net_write : function(net : PNET;packet : pbyte;len : cardinal) : longint;extdecl;
  44. net_write_command : function(net : PNET; command : AnsiChar;packet : pbyte;len : cardinal) : longint;extdecl;
  45. net_real_write : function(net : PNET;packet : pbyte; len : Cardinal) : longint;extdecl;
  46. my_net_read : function(net : PNET) : Cardinal;extdecl;
  47. randominit : procedure(rand : Prand_struct; seed1,seed2 : Cardinal);extdecl;
  48. rnd : function(rand : Prand_struct) : double;extdecl;
  49. make_scrambled_password : procedure(toarg, passwd : PAnsiChar);extdecl;
  50. get_salt_from_password : procedure(res : pcardinal; password : PAnsiChar);extdecl;
  51. scramble : procedure(toarg,message,password : PAnsiChar; old_ver : my_bool);extdecl;
  52. check_scramble : function(scramble,message : PAnsiChar; salt : cardinal;old_ver:my_bool) : my_bool;extdecl;
  53. get_tty_password : function(opt_message: PAnsiChar) : PAnsiChar;extdecl;
  54. Procedure InitialiseMysql3_com;
  55. Procedure ReleaseMysql3_com;
  56. var Mysql3_comLibraryHandle : TLibHandle;
  57. implementation
  58. var RefCount : integer;
  59. Procedure InitialiseMysql3_com;
  60. begin
  61. inc(RefCount);
  62. if RefCount = 1 then
  63. begin
  64. Mysql3_comLibraryHandle := loadlibrary(Mysqllib);
  65. if Mysql3_comLibraryHandle = nilhandle then
  66. begin
  67. RefCount := 0;
  68. Raise EInOutError.Create('Can not load MySQL client. Is it installed? ('+Mysqllib+')');
  69. end;
  70. pointer(sql_free) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_free');
  71. pointer(init_alloc_root) := GetProcedureAddress(Mysql3_comLibraryHandle,'init_alloc_root');
  72. pointer(sql_alloc_first_block) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_alloc_first_block');
  73. pointer(sql_alloc_root) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_alloc_root');
  74. pointer(sql_strdup_root) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_strdup_root');
  75. pointer(sql_memdup_root) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_memdup_root');
  76. pointer(my_net_init) := GetProcedureAddress(Mysql3_comLibraryHandle,'my_net_init');
  77. pointer(net_end) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_end');
  78. pointer(net_clear) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_clear');
  79. pointer(net_flush) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_flush');
  80. pointer(my_net_write) := GetProcedureAddress(Mysql3_comLibraryHandle,'my_net_write');
  81. pointer(net_write_command) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_write_command');
  82. pointer(net_real_write) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_real_write');
  83. pointer(my_net_read) := GetProcedureAddress(Mysql3_comLibraryHandle,'my_net_read');
  84. pointer(randominit) := GetProcedureAddress(Mysql3_comLibraryHandle,'randominit');
  85. pointer(rnd) := GetProcedureAddress(Mysql3_comLibraryHandle,'rnd');
  86. pointer(make_scrambled_password) := GetProcedureAddress(Mysql3_comLibraryHandle,'make_scrambled_password');
  87. pointer(get_salt_from_password) := GetProcedureAddress(Mysql3_comLibraryHandle,'get_salt_from_password');
  88. pointer(scramble) := GetProcedureAddress(Mysql3_comLibraryHandle,'scramble');
  89. pointer(check_scramble) := GetProcedureAddress(Mysql3_comLibraryHandle,'check_scramble');
  90. pointer(get_tty_password) := GetProcedureAddress(Mysql3_comLibraryHandle,'get_tty_password');
  91. end;
  92. end;
  93. Procedure ReleaseMysql3_com;
  94. begin
  95. if RefCount > 0 then dec(RefCount);
  96. if RefCount = 0 then
  97. begin
  98. if not UnloadLibrary(Mysql3_comLibraryHandle) then inc(RefCount);
  99. end;
  100. end;
  101. end.