~ubuntu-branches/ubuntu/lucid/fpc/lucid-proposed

« back to all changes in this revision

Viewing changes to fpcsrc/packages/mysql/src/mysql3_comdyn.pp

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-10-09 23:29:00 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081009232900-553f61m37jkp6upv
Tags: 2.2.2-4
[ Torsten Werner ]
* Update ABI version in fpc-depends automatically.
* Remove empty directories from binary package fpc-source.

[ Mazen Neifer ]
* Removed leading path when calling update-alternatives to remove a Linitian
  error.
* Fixed clean target.
* Improved description of packages. (Closes: #498882)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
  Contains the MySQL_com functions calls
 
3
 
 
4
  Call InitialiseMysql3_com before using any of the calls, and call ReleaseMysql3_com
 
5
  when finished.
 
6
}
 
7
unit mysql3_comdyn;
 
8
 
 
9
{
 
10
  Adapted from mysql4_comdyn by Bram Kuijvenhoven (Hexis BV, The Netherlands)
 
11
}
 
12
 
 
13
{$mode objfpc}{$H+}
 
14
{$MACRO on}
 
15
 
 
16
interface
 
17
 
 
18
uses dynlibs, sysutils;
 
19
 
 
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
 
 
31
{$PACKRECORDS C}
 
32
 
 
33
{$i mysql3_comtypes.inc}
 
34
 
 
35
var
 
36
  sql_free : procedure(root : PMEM_ROOT);extdecl;
 
37
  init_alloc_root : procedure(root: PMEM_ROOT;block_size : Cardinal);extdecl;
 
38
  sql_alloc_first_block : function(root : PMEM_ROOT) : my_bool;extdecl;
 
39
  sql_alloc_root : function(mem_root : PMEM_ROOT;len : Cardinal) : longint;extdecl;
 
40
  sql_strdup_root : function(root : PMEM_ROOT;st : pchar) : pchar;extdecl;
 
41
  sql_memdup_root : function(root: PMEM_ROOT;st : pchar; len : Cardinal) : longint;extdecl;
 
42
  my_net_init : function(net :PNET; fd : Socket) : 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 : pbyte;len : cardinal) : longint;extdecl;
 
47
  net_write_command : function(net : PNET; command : char;packet : pbyte;len : cardinal) : longint;extdecl;
 
48
  net_real_write : function(net : PNET;packet : pbyte; len : Cardinal) : longint;extdecl;
 
49
  my_net_read : function(net : PNET) : Cardinal;extdecl;
 
50
  randominit : procedure(rand : Prand_struct; seed1,seed2 : Cardinal);extdecl;
 
51
  rnd : function(rand : Prand_struct) : double;extdecl;
 
52
  make_scrambled_password : procedure(toarg, passwd : Pchar);extdecl;
 
53
  get_salt_from_password : procedure(res : pcardinal; password : pchar);extdecl;
 
54
  scramble : procedure(toarg,message,password : pchar; old_ver : my_bool);extdecl;
 
55
  check_scramble : function(scramble,message : pchar; salt : cardinal;old_ver:my_bool) : my_bool;extdecl;
 
56
  get_tty_password : function(opt_message:  pchar) : pchar;extdecl;
 
57
 
 
58
Procedure InitialiseMysql3_com;
 
59
Procedure ReleaseMysql3_com;
 
60
 
 
61
var Mysql3_comLibraryHandle : TLibHandle;
 
62
 
 
63
implementation
 
64
 
 
65
var RefCount : integer;
 
66
 
 
67
Procedure InitialiseMysql3_com;
 
68
 
 
69
begin
 
70
  inc(RefCount);
 
71
  if RefCount = 1 then
 
72
    begin
 
73
    Mysql3_comLibraryHandle := loadlibrary(Mysqllib);
 
74
    if Mysql3_comLibraryHandle = nilhandle then
 
75
      begin
 
76
      RefCount := 0;
 
77
      Raise EInOutError.Create('Can not load MySQL client. Is it installed? ('+Mysqllib+')');
 
78
      end;
 
79
 
 
80
    pointer(sql_free) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_free');
 
81
    pointer(init_alloc_root) := GetProcedureAddress(Mysql3_comLibraryHandle,'init_alloc_root');
 
82
    pointer(sql_alloc_first_block) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_alloc_first_block');
 
83
    pointer(sql_alloc_root) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_alloc_root');
 
84
    pointer(sql_strdup_root) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_strdup_root');
 
85
    pointer(sql_memdup_root) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_memdup_root');
 
86
    pointer(my_net_init) := GetProcedureAddress(Mysql3_comLibraryHandle,'my_net_init');
 
87
    pointer(net_end) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_end');
 
88
    pointer(net_clear) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_clear');
 
89
    pointer(net_flush) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_flush');
 
90
    pointer(my_net_write) := GetProcedureAddress(Mysql3_comLibraryHandle,'my_net_write');
 
91
    pointer(net_write_command) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_write_command');
 
92
    pointer(net_real_write) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_real_write');
 
93
    pointer(my_net_read) := GetProcedureAddress(Mysql3_comLibraryHandle,'my_net_read');
 
94
    pointer(randominit) := GetProcedureAddress(Mysql3_comLibraryHandle,'randominit');
 
95
    pointer(rnd) := GetProcedureAddress(Mysql3_comLibraryHandle,'rnd');
 
96
    pointer(make_scrambled_password) := GetProcedureAddress(Mysql3_comLibraryHandle,'make_scrambled_password');
 
97
    pointer(get_salt_from_password) := GetProcedureAddress(Mysql3_comLibraryHandle,'get_salt_from_password');
 
98
    pointer(scramble) := GetProcedureAddress(Mysql3_comLibraryHandle,'scramble');
 
99
    pointer(check_scramble) := GetProcedureAddress(Mysql3_comLibraryHandle,'check_scramble');
 
100
    pointer(get_tty_password) := GetProcedureAddress(Mysql3_comLibraryHandle,'get_tty_password');
 
101
    end;
 
102
end;
 
103
 
 
104
Procedure ReleaseMysql3_com;
 
105
 
 
106
begin
 
107
  if RefCount > 0 then dec(RefCount);
 
108
  if RefCount = 0 then
 
109
    begin
 
110
    if not UnloadLibrary(Mysql3_comLibraryHandle) then inc(RefCount);
 
111
    end;
 
112
end;
 
113
 
 
114
end.