Skip to content

Commit 3d547fd

Browse files
committed
refactor: revert most of what I did for #2424
This changes the meaning of an empty database setting for a PostgreSQL session: - old: empty meant "postgres", and "!" meant empty - new: empty means empty now Refs #2424 and #2442
1 parent 86ea19c commit 3d547fd

File tree

2 files changed

+10
-44
lines changed

2 files changed

+10
-44
lines changed

source/connections.pas

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,34 +1309,21 @@ procedure Tconnform.editDatabasesRightButtonClick(Sender: TObject);
13091309
// Try to connect and lookup database names
13101310
Params := CurrentParams;
13111311
Connection := Params.CreateConnection(Self);
1312-
Connection.Parameters.AllDatabasesStr := TPgConnection.DBNAME_EMPTY;
1312+
Connection.Parameters.AllDatabasesStr := '';
13131313
Connection.LogPrefix := SelectedSessionPath;
13141314
Connection.OnLog := Mainform.LogSQL;
13151315
FPopupDatabases := TPopupMenu.Create(Self);
13161316
//FPopupDatabases.AutoHotkeys := maManual;
13171317
Screen.Cursor := crHourglass;
13181318
try
13191319
Connection.Active := True;
1320-
if Params.IsAnyPostgreSQL then begin
1321-
Databases := Connection.GetCol('SELECT datname FROM pg_database WHERE datistemplate=FALSE');
1322-
Item := TMenuItem.Create(FPopupDatabases);
1323-
Item.Caption := TPgConnection.DBNAME_EMPTY + ' (' + _('No database') + ')';
1324-
Item.Tag := TPgConnection.DBTAG_EMPTY;
1325-
Item.OnClick := MenuDatabasesClick;
1326-
Item.AutoCheck := True;
1327-
Item.RadioItem := True;
1328-
FPopupDatabases.Items.Add(Item);
1329-
end
1330-
else begin
1320+
if Params.NetTypeGroup = ngPgSQL then
1321+
Databases := Connection.GetCol('SELECT datname FROM pg_database WHERE datistemplate=FALSE')
1322+
else
13311323
Databases := Connection.AllDatabases;
1332-
end;
13331324
for DB in Databases do begin
13341325
Item := TMenuItem.Create(FPopupDatabases);
13351326
Item.Caption := DB;
1336-
if Params.IsAnyPostgreSQL and (DB = TPgConnection.DBNAME_DEFAULT) then begin
1337-
Item.Caption := Item.Caption + ' (' + _('Default') + ')';
1338-
Item.Tag := TPgConnection.DBTAG_DEFAULT;
1339-
end;
13401327
Item.OnClick := MenuDatabasesClick;
13411328
Item.AutoCheck := True;
13421329
Item.RadioItem := Params.IsAnyPostgreSQL;
@@ -1352,14 +1339,7 @@ procedure Tconnform.editDatabasesRightButtonClick(Sender: TObject);
13521339
// Check/uncheck items, based on semicolon list
13531340
Databases := Explode(';', editDatabases.Text);
13541341
for Item in FPopupDatabases.Items do begin
1355-
case Item.Tag of
1356-
TPgConnection.DBTAG_EMPTY:
1357-
Item.Checked := Databases.Contains(TPgConnection.DBNAME_EMPTY);
1358-
TPgConnection.DBTAG_DEFAULT:
1359-
Item.Checked := Databases.Contains(TPgConnection.DBNAME_DEFAULT) or Databases.IsEmpty;
1360-
else
1361-
Item.Checked := Databases.IndexOf(Item.Caption) > -1;
1362-
end;
1342+
Item.Checked := Databases.IndexOf(Item.Caption) > -1;
13631343
end;
13641344
Databases.Free;
13651345

@@ -1376,12 +1356,8 @@ procedure Tconnform.MenuDatabasesClick(Sender: TObject);
13761356
begin
13771357
Databases := TStringList.Create;
13781358
for Item in FPopupDatabases.Items do begin
1379-
if Item.Checked then begin
1380-
if Item.Tag in [TPgConnection.DBTAG_EMPTY, TPgConnection.DBTAG_DEFAULT] then // Remove hint
1381-
Databases.Add(ReplaceRegExpr('\s\(.+$', Item.Caption, ''))
1382-
else
1383-
Databases.Add(Item.Caption);
1384-
end;
1359+
if Item.Checked then
1360+
Databases.Add(Item.Caption);
13851361
end;
13861362
SelStart := editDatabases.SelStart;
13871363
editDatabases.Text := Implode(';', Databases);

source/dbconnection.pas

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,6 @@ TSqlSrvConnection = class(TDBConnection)
702702
TPGRawResults = Array of PPGresult;
703703
TPQerrorfields = (PG_DIAG_SEVERITY, PG_DIAG_SQLSTATE, PG_DIAG_MESSAGE_PRIMARY, PG_DIAG_MESSAGE_DETAIL, PG_DIAG_MESSAGE_HINT, PG_DIAG_STATEMENT_POSITION, PG_DIAG_INTERNAL_POSITION, PG_DIAG_INTERNAL_QUERY, PG_DIAG_CONTEXT, PG_DIAG_SOURCE_FILE, PG_DIAG_SOURCE_LINE, PG_DIAG_SOURCE_FUNCTION);
704704
TPgConnection = class(TDBConnection)
705-
const
706-
DBNAME_DEFAULT = 'postgres';
707-
DBNAME_EMPTY = '!';
708-
DBTAG_EMPTY = 1;
709-
DBTAG_DEFAULT = 2;
710705
private
711706
FHandle: PPGconn;
712707
FLib: TPostgreSQLLib;
@@ -2734,18 +2729,13 @@ procedure TSqlSrvConnection.SetActive(Value: Boolean);
27342729

27352730
procedure TPgConnection.SetActive(Value: Boolean);
27362731
var
2737-
dbname, ConnectionString, OptionValue, Error: String;
2732+
ConnectionString, OptionValue, Error: String;
27382733
ConnectOptions: TStringList;
27392734
FinalHost, ErrorHint: String;
27402735
FinalPort, i: Integer;
27412736
begin
27422737
if Value then begin
27432738
DoBeforeConnect;
2744-
// Simon Riggs:
2745-
// "You should connect as "postgres" database by default, with an option to change. Don't use template1"
2746-
dbname := FParameters.AllDatabasesStr;
2747-
if dbname = '' then
2748-
dbname := DBNAME_DEFAULT;
27492739

27502740
// Prepare special stuff for SSH tunnel
27512741
FinalHost := FParameters.Hostname;
@@ -2763,8 +2753,8 @@ procedure TPgConnection.SetActive(Value: Boolean);
27632753
.AddPair('password', FParameters.Password)
27642754
.AddPair('application_name', APPNAME)
27652755
.AddPair('sslmode', 'disable');
2766-
if dbname <> DBNAME_EMPTY then
2767-
ConnectOptions.AddPair('dbname', dbname);
2756+
if not FParameters.AllDatabasesStr.IsEmpty then
2757+
ConnectOptions.AddPair('dbname', FParameters.AllDatabasesStr);
27682758
if FParameters.WantSSL then begin
27692759
// Be aware .AddPair would add duplicates
27702760
case FParameters.SSLVerification of

0 commit comments

Comments
 (0)