summaryrefslogtreecommitdiff
blob: 810bc5b5ba9713728888f528fdcf82fb2642b47e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
From b26102b097ef6353a20d18ccdaf7a3a6a30185c7 Mon Sep 17 00:00:00 2001
From: ok2cqr <petr@petrhlozek.cz>
Date: Sat, 15 Sep 2018 07:12:30 +0200
Subject: [PATCH] database connection refactoring

---
 src/dData.pas | 126 +++++++-------------------------------------------
 1 file changed, 17 insertions(+), 109 deletions(-)

diff --git a/src/dData.pas b/src/dData.pas
index 9d72d27..bb56598 100644
--- a/src/dData.pas
+++ b/src/dData.pas
@@ -162,7 +162,6 @@ type
     function  FindLib(const Path,LibName : String) : String;
     function  GetMysqldPath : String;
     function  TableExists(TableName : String) : Boolean;
-    function  GetMySQLLib : String;
     function  GetDebugLevel : Integer;
 
     procedure CreateDBConnections;
@@ -267,6 +266,7 @@ type
     function  RbnCallExistsInLog(callsign,band,mode,LastDate,LastTime : String) : Boolean;
     function  CallNoteExists(Callsign : String) : Boolean;
     function  GetNewLogNumber : Integer;
+    function  getNewMySQLConnectionObject : TMySQL57Connection;
 
     procedure SaveQSO(date : TDateTime; time_on,time_off,call : String; freq : Currency;mode,rst_s,
                       rst_r, stn_name,qth,qsl_s,qsl_r,qsl_via,iota,pwr : String; itu,waz : Integer;
@@ -1092,49 +1092,6 @@ begin
     Writeln('   ',DLLUtilName)
   end;
 
-  lib := GetMySQLLib;
-  if fDebugLevel>=1 then Writeln('Loading libmysqlclient: ',lib);
-  if lib <> '' then
-    InitialiseMySQL(lib);
-
-  try try
-    c := TConnectionName.Create(nil);
-    MySQLVer := copy(c.ClientInfo,1,3);
-
-    if fDebugLevel>=1 then
-    begin
-      Writeln('**************************');
-      Writeln('MySQL version: ',MySQLVer);
-      Writeln('**************************')
-    end;
-
-    if MySQLVer = '10.' then
-      MySQLVer := '5.6';
-    if MySQLVer = '10.1' then
-      MySQLVer := '5.7'
-
-  except
-    on E : Exception do
-    begin
-      Writeln('FATAL ERROR: Can not get MySQL client library version version!',LineEnding,
-              'Setting to default version (5.1)');
-      MySQLVer := '5.1'
-    end
-  end
-  finally
-    FreeAndNil(c)
-  end;
-
-  if not TryStrToCurr(MySQLVer,fMySQLVersion) then
-    fMySQLVersion := 5.6;
-
-  if fDebugLevel>=1 then
-  begin
-    Writeln('**********************************');
-    Writeln('MySQL version assigned: ',FloatToStr(fMySQLVersion));
-    Writeln('**********************************')
-  end;
-
   CreateDBConnections;
 
   MainCon.KeepConnection := True;
@@ -1148,13 +1105,11 @@ begin
   end;
 
   //special connection for band map thread
-  BandMapCon.KeepConnection := True;
   BandMapCon.Transaction    := trBandMapFil;
   qBandMapFil.Transaction   := trBandMapFil;
   qBandMapFil.DataBase      := BandMapCon;
   trBandMapFil.DataBase     := BandMapCon;
 
-  RbnMonCon.KeepConnection := True;
   RbnMonCon.Transaction    := trRbnMon;
   qRbnMon.Transaction      := trRbnMon;
   qRbnMon.DataBase         := RbnMonCon;
@@ -1194,7 +1149,6 @@ begin
     Writeln('ZIP code directory:     ',fZipCodeDir);
     Writeln('Binary dir:             ',ExtractFilePath(Paramstr(0)));
     Writeln('Share dir:              ',fShareDir);
-    Writeln('TConnection to MySQL:   ',FloatToStr(fMySQLVersion));
     Writeln('*')
   end;
 
@@ -4166,70 +4120,13 @@ end;
 
 procedure TdmData.CreateDBConnections;
 begin
-  if fMySQLVersion < 5.5 then
-  begin
-    MainCon      := TMySQL51Connection.Create(self);
-    BandMapCon   := TMySQL51Connection.Create(self);
-    RbnMonCon    := TMySQL51Connection.Create(self);
-    LogUploadCon := TMySQL51Connection.Create(self);
-    dbDXC        := TMySQL51Connection.Create(self)
-  end
-  else  if fMySQLVersion < 5.6 then
-  begin
-    MainCon      := TMySQL55Connection.Create(self);
-    BandMapCon   := TMySQL55Connection.Create(self);
-    RbnMonCon    := TMySQL55Connection.Create(self);
-    LogUploadCon := TMySQL55Connection.Create(self);
-    dbDXC        := TMySQL55Connection.Create(self)
-  end
-  else begin
-    if fMySQLVersion < 5.7 then
-    begin
-      MainCon      := TMySQL56Connection.Create(self);
-      BandMapCon   := TMySQL56Connection.Create(self);
-      RbnMonCon    := TMySQL56Connection.Create(self);
-      LogUploadCon := TMySQL56Connection.Create(self);
-      dbDXC        := TMySQL56Connection.Create(self)
-    end
-    else begin
-      MainCon      := TMySQL57Connection.Create(self);
-      BandMapCon   := TMySQL57Connection.Create(self);
-      RbnMonCon    := TMySQL57Connection.Create(self);
-      LogUploadCon := TMySQL57Connection.Create(self);
-      dbDXC        := TMySQL57Connection.Create(self)
-    end
-  end
+  MainCon      := getNewMySQLConnectionObject();
+  BandMapCon   := getNewMySQLConnectionObject();
+  RbnMonCon    := getNewMySQLConnectionObject();
+  LogUploadCon := getNewMySQLConnectionObject();
+  dbDXC        := getNewMySQLConnectionObject();
 end;
 
-function TdmData.GetMySQLLib : String;
-var
-  lib : String;
-  Paths : TStringList;
-begin
-  Result := '';
-  Paths := TStringList.Create;
-  try
-    Paths.Add('/usr/lib64/');
-    Paths.Add('/lib64/');
-    Paths.Add('/usr/lib/x86_64-linux-gnu/');
-    Paths.Add('/usr/lib64/mysql/');
-    Paths.Add('/lib/x86_64-linux-gnu/');
-
-    Paths.Add('/usr/lib/i386-linux-gnu/');
-    Paths.Add('/lib/i386-linux-gnu/');
-    Paths.Add('/usr/lib/');
-    Paths.Add('/lib/');
-    Paths.Add('/usr/lib/mysql/');
-
-    Result := MyFindFile('libmariadbclient.so*', Paths);
-    if (Result='') then
-    begin
-      Result := MyFindFile('libmysqlclient.so*', Paths)
-    end
-  finally
-    FreeAndNil(Paths)
-  end
-end;
 
 function TdmData.GetDebugLevel : Integer;
 var
@@ -4315,5 +4212,16 @@ begin
     QSOColorDate := now
 end;
 
+function TdmData.getNewMySQLConnectionObject : TMySQL57Connection;
+var
+  Connection : TMySQL57Connection;
+begin
+  Connection := TMySQL57Connection.Create(self);
+  Connection.SkipLibraryVersionCheck := True;
+  Connection.KeepConnection := True;
+
+  result := Connection
+end;
+
 end.
 
-- 
2.18.1