Skip to content
Permalink
Browse files

Activate Library drop down for PostgreSQL connections as well, so we …

…may provide multiple versions in the future.
  • Loading branch information...
ansgarbecker committed Jul 28, 2019
1 parent 13fa85e commit 852ac61347f0e2bd0e406c543f956d31ceff2aa0
Showing with 69 additions and 20 deletions.
  1. +31 −16 source/connections.pas
  2. +38 −4 source/dbconnection.pas
@@ -190,6 +190,7 @@ Tconnform = class(TExtForm)
procedure WMNCLBUTTONDOWN(var Msg: TWMNCLButtonDown) ; message WM_NCLBUTTONDOWN;
procedure WMNCLBUTTONUP(var Msg: TWMNCLButtonUp) ; message WM_NCLBUTTONUP;
procedure RefreshBackgroundColors;
procedure RefreshLibraries(Sess: TConnectionParameters);
public
{ Public declarations }
end;
@@ -231,9 +232,6 @@ procedure Tconnform.FormCreate(Sender: TObject);
nt: TNetType;
Node: PVirtualNode;
Params: TConnectionParameters;
rx: TRegExpr;
Libs: TStringDynArray;
LibPath, LibFile: String;
begin
// Fix GUI stuff
HasSizeGrip := True;
@@ -268,18 +266,6 @@ procedure Tconnform.FormCreate(Sender: TObject);
end;
Params.Free;

// Detect existing MySQL libraries
rx := TRegExpr.Create;
rx.ModifierI := True;
rx.Expression := '^lib(mysql|mariadb).*\.dll$';
Libs := TDirectory.GetFiles(ExtractFilePath(ParamStr(0)), '*.dll');
for LibPath in Libs do begin
LibFile := ExtractFileName(LibPath);
if rx.Exec(LibFile) then begin
comboLibrary.Items.Add(LibFile);
end;
end;

// Init sessions tree
RefreshSessions(nil);

@@ -869,6 +855,7 @@ procedure Tconnform.ListSessionsFocusChanged(Sender: TBaseVirtualTree;
RefreshBackgroundColors;
ColorBoxBackgroundColor.Selected := Sess.SessionColor;
editDatabases.Text := Sess.AllDatabasesStr;
RefreshLibraries(Sess^);
comboLibrary.ItemIndex := comboLibrary.Items.IndexOf(Sess.LibraryFile);
if (comboLibrary.ItemIndex = -1) and (comboLibrary.Items.Count > 0) then begin
comboLibrary.ItemIndex := 0;
@@ -910,6 +897,33 @@ procedure Tconnform.RefreshBackgroundColors;
end;


procedure Tconnform.RefreshLibraries(Sess: TConnectionParameters);
var
rx: TRegExpr;
Libs: TStringDynArray;
LibPath, LibFile: String;
begin
// Detect existing dll files in app folder
comboLibrary.Clear;

rx := TRegExpr.Create;
rx.ModifierI := True;
case Sess.NetTypeGroup of
ngMySQL: rx.Expression := '^lib(mysql|mariadb).*\.dll$';
ngMSSQL: rx.Expression := '^$';
ngPgSQL: rx.Expression := '^libpq.*\.dll$';
end;

Libs := TDirectory.GetFiles(ExtractFilePath(ParamStr(0)), '*.dll');
for LibPath in Libs do begin
LibFile := ExtractFileName(LibPath);
if rx.Exec(LibFile) then begin
comboLibrary.Items.Add(LibFile);
end;
end;
end;


procedure Tconnform.TimerStatisticsTimer(Sender: TObject);
var
LastConnect, Created, DummyDate: TDateTime;
@@ -1132,6 +1146,7 @@ procedure Tconnform.comboNetTypeChange(Sender: TObject);
updownPort.Position := Params.DefaultPort;
if not editUsername.Modified then
editUsername.Text := Params.DefaultUsername;
comboLibrary.ItemIndex := comboLibrary.Items.IndexOf(Params.DefaultLibrary);
end;

FLastSelectedNetTypeGroup := Params.NetTypeGroup;
@@ -1240,7 +1255,7 @@ procedure Tconnform.ValidateControls;
lblPort.Enabled := Params.NetType in [ntMySQL_TCPIP, ntMySQL_SSHtunnel, ntMSSQL_TCPIP, ntPgSQL_TCPIP, ntPgSQL_SSHtunnel];
editPort.Enabled := lblPort.Enabled;
updownPort.Enabled := lblPort.Enabled;
comboLibrary.Enabled := Params.NetTypeGroup in [ngMySQL];
comboLibrary.Enabled := Params.NetTypeGroup in [ngMySQL, ngPgSQL];
if Params.NetTypeGroup = ngPgSQL then
lblDatabase.Caption := _('Database')+':'
else
@@ -236,6 +236,7 @@ TConnectionParameters = class(TObject)
function IsAzure: Boolean;
function IsMemSQL: Boolean;
property ImageIndex: Integer read GetImageIndex;
function DefaultLibrary: String;
function DefaultPort: Integer;
function DefaultUsername: String;
published
@@ -1076,7 +1077,7 @@ constructor TConnectionParameters.Create;
FPort := DefaultPort;
FCompressed := AppSettings.GetDefaultBool(asCompressed);
FAllDatabases := AppSettings.GetDefaultString(asDatabases);
FLibraryFile := AppSettings.GetDefaultString(asLibrary);
FLibraryFile := DefaultLibrary;
FComment := AppSettings.GetDefaultString(asComment);

FSSHHost := AppSettings.GetDefaultString(asSSHtunnelHost);
@@ -1439,6 +1440,17 @@ function TConnectionParameters.DefaultUsername: String;
end;


function TConnectionParameters.DefaultLibrary: String;
begin
case NetTypeGroup of
ngMySQL: Result := 'libmariadb.dll';
ngMSSQL: Result := '';
ngPgSQL: Result := 'libpq.dll';
else Result := '';
end;
end;


function TConnectionParameters.GetSessionName: String;
var
LastBackSlash: Integer;
@@ -1914,6 +1926,7 @@ procedure TAdoDBConnection.SetActive(Value: Boolean);
ntMSSQL_VINES: NetLib := 'DBMSVINN';
ntMSSQL_RPC: NetLib := 'DBMSRPCN';
end;
//fadohandle.Properties.Item['Initial Catalog'] := '';

DataSource := Parameters.Hostname;
if (Parameters.NetType = ntMSSQL_TCPIP) and (Parameters.Port <> 0) then
@@ -2221,7 +2234,7 @@ procedure TPgConnection.DoBeforeConnect;
LibraryPath: String;
begin
// Init lib before actually connecting.
LibraryPath := ExtractFilePath(ParamStr(0)) + 'libpq.dll';
LibraryPath := ExtractFilePath(ParamStr(0)) + Parameters.LibraryFile;
Log(lcDebug, f_('Loading library file %s ...', [LibraryPath]));
FLib := TPostgreSQLLib.Create(LibraryPath);
Log(lcDebug, FLib.DllFile + ' v' + IntToStr(FLib.PQlibVersion) + ' loaded.');
@@ -2707,6 +2720,10 @@ function TMySQLConnection.GetCreateCode(Obj: TDBObject): String;
Result := GetCreateViewCode(Obj.Database, Obj.Name)
else
Result := GetVar('SHOW CREATE '+UpperCase(Obj.ObjType)+' '+QuoteIdent(Obj.Database)+'.'+QuoteIdent(Obj.Name), Column);
//if UpperCase(Obj.ObjType)='TABLE' then begin
// Result := Result + ' `compression`=''tokudb_zlib''';
//Log(lcinfo, Result);
//end;
TmpObj.Free;
end;

@@ -3143,6 +3160,7 @@ procedure TDBConnection.SetDatabase(Value: String);
end else
s := QuoteIdent(Value);
Query(Format(GetSQLSpecifity(spUSEQuery), [s]), False);
//TAdoDBConnection(self).fadohandle.ConnectionObject.Properties.Item['Initial Catalog'] := Value;
end;
if Assigned(FOnObjectnamesChanged) then
FOnObjectnamesChanged(Self, FDatabase);
@@ -3343,6 +3361,7 @@ function TAdoDBConnection.GetLastErrorMsg: String;

function TPgConnection.GetLastErrorMsg: String;
begin
// https://support.microsoft.com/en-us/help/3179560/update-for-visual-c-2013-and-visual-c-redistributable-package
Result := DecodeAPIString(FLib.PQerrorMessage(FHandle));
Result := Trim(Result);
end;
@@ -4362,6 +4381,14 @@ function TMySQLConnection.ExplainAnalyzer(SQL, DatabaseName: String): Boolean;
i: Integer;
begin
// Send EXPLAIN output to MariaDB.org

// Mimimum structure of what seems compatible:
//+
//|id|select_type|table|type|possible_keys|key|key_len|ref|rows|Extra|
//+
//|1|SIMPLE|t1|ALL|NULL|NULL|NULL|NULL|3||
//|1|SIMPLE|t1|ALL|NULL|NULL|NULL|NULL|3||

Result := True;
Database := DatabaseName;
Results := GetResults('EXPLAIN '+SQL);
@@ -5077,6 +5104,7 @@ procedure TDBConnection.ParseTableStructure(CreateTable: String; Columns: TTable
ColSpec := Copy(CreateTable, rx.MatchPos[0], SIZE_MB);
ColSpec := Copy(ColSpec, 1, Pos(#10, ColSpec));
ColSpec := Trim(ColSpec);
//Log(lcInfo, '>> '+ColSpec);

Col := TTableColumn.Create(Self);
Columns.Add(Col);
@@ -5200,6 +5228,7 @@ procedure TDBConnection.ParseTableStructure(CreateTable: String; Columns: TTable
end;
Delete(ColSpec, 1, rxCol.MatchLen[1]);
ColSpec := Trim(ColSpec);
//Log(lcInfo, ' Detected DefaultText: "'+Col.DefaultText+'" Detected DefaultType: '+Integer(Col.DefaultType).ToString);

// Do the same for a potentially existing ON UPDATE clause
if ColSpec.StartsWith('ON UPDATE ', True) then begin
@@ -5211,6 +5240,7 @@ procedure TDBConnection.ParseTableStructure(CreateTable: String; Columns: TTable
Col.OnUpdateText := Col.OnUpdateText.TrimRight([',']);
Col.OnUpdateType := cdtExpression;
Delete(ColSpec, 1, rxCol.MatchPos[1]);
//Log(lcInfo, ' Detected OnUpdateText: "'+Col.OnUpdateText+'" Detected OnUpdateType: '+Integer(Col.OnUpdateType).ToString);
end;
end;

@@ -5686,6 +5716,7 @@ procedure TMySQLQuery.Execute(AddResult: Boolean=False; UseRawResult: Integer=-1
FColumnNames.Clear;
FColumnOrgNames.Clear;
for i:=0 to NumFields-1 do begin
//Field := FConnection.Lib.mysql_fetch_field_direct(LastResult, i);
Field := FConnection.Lib.mysql_fetch_field_direct(LastResult, i);
FColumnNames.Add(Connection.DecodeAPIString(Field.name));
if Connection.ServerVersionInt >= 40100 then
@@ -5696,6 +5727,7 @@ procedure TMySQLQuery.Execute(AddResult: Boolean=False; UseRawResult: Integer=-1
FColumnTypes[i] := FConnection.Datatypes[0];
if (Field.flags and AUTO_INCREMENT_FLAG) = AUTO_INCREMENT_FLAG then
FAutoIncrementColumn := i;
//FConnection.Log(lcDebug, 'Field._type: '+Field._type.ToString);
for j:=0 to High(FConnection.Datatypes) do begin
if (Field.flags and ENUM_FLAG) = ENUM_FLAG then begin
if FConnection.Datatypes[j].Index = dtEnum then
@@ -7059,8 +7091,10 @@ function TDBQuery.GetKeyColumns: TStringList;
Result := Connection.GetKeyColumns(FColumns, FKeys);
if Result.Count = 0 then begin
// No good key found. Just expect all columns to be present.
for i:=0 to FColumns.Count-1 do
Result.Add(FColumns[i].Name);
// .. at least of it's not MemSQL, who does not support a later added LIMIT
// SQL Error (1749): Feature 'UPDATE...LIMIT must be constrained to a single partition' is not supported by MemSQL Distributed
for i:=0 to FColumns.Count-1 do
Result.Add(FColumns[i].Name);
end;
end;

0 comments on commit 852ac61

Please sign in to comment.
You can’t perform that action at this time.