Skip to content

Commit 4737689

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 f5d054d commit 4737689

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
@@ -1296,34 +1296,21 @@ procedure Tconnform.editDatabasesRightButtonClick(Sender: TObject);
12961296
// Try to connect and lookup database names
12971297
Params := CurrentParams;
12981298
Connection := Params.CreateConnection(Self);
1299-
Connection.Parameters.AllDatabasesStr := TPgConnection.DBNAME_EMPTY;
1299+
Connection.Parameters.AllDatabasesStr := '';
13001300
Connection.LogPrefix := SelectedSessionPath;
13011301
Connection.OnLog := Mainform.LogSQL;
13021302
FPopupDatabases := TPopupMenu.Create(Self);
13031303
FPopupDatabases.AutoHotkeys := maManual;
13041304
Screen.Cursor := crHourglass;
13051305
try
13061306
Connection.Active := True;
1307-
if Params.IsAnyPostgreSQL then begin
1308-
Databases := Connection.GetCol('SELECT datname FROM pg_database WHERE datistemplate=FALSE');
1309-
Item := TMenuItem.Create(FPopupDatabases);
1310-
Item.Caption := TPgConnection.DBNAME_EMPTY + ' (' + _('No database') + ')';
1311-
Item.Tag := TPgConnection.DBTAG_EMPTY;
1312-
Item.OnClick := MenuDatabasesClick;
1313-
Item.AutoCheck := True;
1314-
Item.RadioItem := True;
1315-
FPopupDatabases.Items.Add(Item);
1316-
end
1317-
else begin
1307+
if Params.NetTypeGroup = ngPgSQL then
1308+
Databases := Connection.GetCol('SELECT datname FROM pg_database WHERE datistemplate=FALSE')
1309+
else
13181310
Databases := Connection.AllDatabases;
1319-
end;
13201311
for DB in Databases do begin
13211312
Item := TMenuItem.Create(FPopupDatabases);
13221313
Item.Caption := DB;
1323-
if Params.IsAnyPostgreSQL and (DB = TPgConnection.DBNAME_DEFAULT) then begin
1324-
Item.Caption := Item.Caption + ' (' + _('Default') + ')';
1325-
Item.Tag := TPgConnection.DBTAG_DEFAULT;
1326-
end;
13271314
Item.OnClick := MenuDatabasesClick;
13281315
Item.AutoCheck := True;
13291316
Item.RadioItem := Params.IsAnyPostgreSQL;
@@ -1339,14 +1326,7 @@ procedure Tconnform.editDatabasesRightButtonClick(Sender: TObject);
13391326
// Check/uncheck items, based on semicolon list
13401327
Databases := Explode(';', editDatabases.Text);
13411328
for Item in FPopupDatabases.Items do begin
1342-
case Item.Tag of
1343-
TPgConnection.DBTAG_EMPTY:
1344-
Item.Checked := Databases.Contains(TPgConnection.DBNAME_EMPTY);
1345-
TPgConnection.DBTAG_DEFAULT:
1346-
Item.Checked := Databases.Contains(TPgConnection.DBNAME_DEFAULT) or Databases.IsEmpty;
1347-
else
1348-
Item.Checked := Databases.IndexOf(Item.Caption) > -1;
1349-
end;
1329+
Item.Checked := Databases.IndexOf(Item.Caption) > -1;
13501330
end;
13511331
Databases.Free;
13521332

@@ -1364,12 +1344,8 @@ procedure Tconnform.MenuDatabasesClick(Sender: TObject);
13641344
begin
13651345
Databases := TStringList.Create;
13661346
for Item in FPopupDatabases.Items do begin
1367-
if Item.Checked then begin
1368-
if Item.Tag in [TPgConnection.DBTAG_EMPTY, TPgConnection.DBTAG_DEFAULT] then // Remove hint
1369-
Databases.Add(ReplaceRegExpr('\s\(.+$', Item.Caption, ''))
1370-
else
1371-
Databases.Add(Item.Caption);
1372-
end;
1347+
if Item.Checked then
1348+
Databases.Add(Item.Caption);
13731349
end;
13741350
SelStart := editDatabases.SelStart;
13751351
editDatabases.Text := Implode(';', Databases);

source/dbconnection.pas

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -707,11 +707,6 @@ TAdoDBConnection = class(TDBConnection)
707707
TPGRawResults = Array of PPGresult;
708708
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);
709709
TPgConnection = class(TDBConnection)
710-
const
711-
DBNAME_DEFAULT = 'postgres';
712-
DBNAME_EMPTY = '!';
713-
DBTAG_EMPTY = 1;
714-
DBTAG_DEFAULT = 2;
715710
private
716711
FHandle: PPGconn;
717712
FLib: TPostgreSQLLib;
@@ -2863,18 +2858,13 @@ procedure TAdoDBConnection.SetActive(Value: Boolean);
28632858

28642859
procedure TPgConnection.SetActive(Value: Boolean);
28652860
var
2866-
dbname, ConnectionString, OptionValue, Error: String;
2861+
ConnectionString, OptionValue, Error: String;
28672862
ConnectOptions: TStringList;
28682863
FinalHost, ErrorHint: String;
28692864
FinalPort, i: Integer;
28702865
begin
28712866
if Value then begin
28722867
DoBeforeConnect;
2873-
// Simon Riggs:
2874-
// "You should connect as "postgres" database by default, with an option to change. Don't use template1"
2875-
dbname := FParameters.AllDatabasesStr;
2876-
if dbname = '' then
2877-
dbname := DBNAME_DEFAULT;
28782868

28792869
// Prepare special stuff for SSH tunnel
28802870
FinalHost := FParameters.Hostname;
@@ -2892,8 +2882,8 @@ procedure TPgConnection.SetActive(Value: Boolean);
28922882
.AddPair('password', FParameters.Password)
28932883
.AddPair('application_name', APPNAME)
28942884
.AddPair('sslmode', 'disable');
2895-
if dbname <> DBNAME_EMPTY then
2896-
ConnectOptions.AddPair('dbname', dbname);
2885+
if not FParameters.AllDatabasesStr.IsEmpty then
2886+
ConnectOptions.AddPair('dbname', FParameters.AllDatabasesStr);
28972887
if FParameters.WantSSL then begin
28982888
// Be aware .AddPair would add duplicates
28992889
case FParameters.SSLVerification of

0 commit comments

Comments
 (0)