mysql3_comdyn.pp 4.6 KB

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