mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2026-03-13 09:24:25 +08:00
feat: allow setting database to <none> in PostgreSQL connections, and show <none> and <default> in the pulldown selector
Refs #2424
This commit is contained in:
@@ -1304,7 +1304,7 @@ begin
|
||||
// Try to connect and lookup database names
|
||||
Params := CurrentParams;
|
||||
Connection := Params.CreateConnection(Self);
|
||||
Connection.Parameters.AllDatabasesStr := '';
|
||||
Connection.Parameters.AllDatabasesStr := TPgConnection.DBNAME_EMPTY;
|
||||
Connection.LogPrefix := SelectedSessionPath;
|
||||
Connection.OnLog := Mainform.LogSQL;
|
||||
FPopupDatabases := TPopupMenu.Create(Self);
|
||||
@@ -1312,16 +1312,29 @@ begin
|
||||
Screen.Cursor := crHourglass;
|
||||
try
|
||||
Connection.Active := True;
|
||||
if Params.NetTypeGroup = ngPgSQL then
|
||||
Databases := Connection.GetCol('SELECT datname FROM pg_database WHERE datistemplate=FALSE')
|
||||
else
|
||||
if Params.IsAnyPostgreSQL then begin
|
||||
Databases := Connection.GetCol('SELECT datname FROM pg_database WHERE datistemplate=FALSE');
|
||||
Item := TMenuItem.Create(FPopupDatabases);
|
||||
Item.Caption := TPgConnection.DBNAME_EMPTY + ' (' + _('No database') + ')';
|
||||
Item.Tag := TPgConnection.DBTAG_EMPTY;
|
||||
Item.OnClick := MenuDatabasesClick;
|
||||
Item.AutoCheck := True;
|
||||
Item.RadioItem := True;
|
||||
FPopupDatabases.Items.Add(Item);
|
||||
end
|
||||
else begin
|
||||
Databases := Connection.AllDatabases;
|
||||
end;
|
||||
for DB in Databases do begin
|
||||
Item := TMenuItem.Create(FPopupDatabases);
|
||||
Item.Caption := DB;
|
||||
if Params.IsAnyPostgreSQL and (DB = TPgConnection.DBNAME_DEFAULT) then begin
|
||||
Item.Caption := Item.Caption + ' (' + _('Default') + ')';
|
||||
Item.Tag := TPgConnection.DBTAG_DEFAULT;
|
||||
end;
|
||||
Item.OnClick := MenuDatabasesClick;
|
||||
Item.AutoCheck := True;
|
||||
Item.RadioItem := Params.NetTypeGroup = ngPgSQL;
|
||||
Item.RadioItem := Params.IsAnyPostgreSQL;
|
||||
FPopupDatabases.Items.Add(Item);
|
||||
end;
|
||||
Databases.Free;
|
||||
@@ -1334,7 +1347,14 @@ begin
|
||||
// Check/uncheck items, based on semicolon list
|
||||
Databases := Explode(';', editDatabases.Text);
|
||||
for Item in FPopupDatabases.Items do begin
|
||||
Item.Checked := Databases.IndexOf(Item.Caption) > -1;
|
||||
case Item.Tag of
|
||||
TPgConnection.DBTAG_EMPTY:
|
||||
Item.Checked := Databases.Contains(TPgConnection.DBNAME_EMPTY);
|
||||
TPgConnection.DBTAG_DEFAULT:
|
||||
Item.Checked := Databases.Contains(TPgConnection.DBNAME_DEFAULT) or Databases.IsEmpty;
|
||||
else
|
||||
Item.Checked := Databases.IndexOf(Item.Caption) > -1;
|
||||
end;
|
||||
end;
|
||||
Databases.Free;
|
||||
|
||||
@@ -1351,8 +1371,12 @@ var
|
||||
begin
|
||||
Databases := TStringList.Create;
|
||||
for Item in FPopupDatabases.Items do begin
|
||||
if Item.Checked then
|
||||
Databases.Add(Item.Caption);
|
||||
if Item.Checked then begin
|
||||
if Item.Tag in [TPgConnection.DBTAG_EMPTY, TPgConnection.DBTAG_DEFAULT] then // Remove hint
|
||||
Databases.Add(ReplaceRegExpr('\s\(.+$', Item.Caption, ''))
|
||||
else
|
||||
Databases.Add(Item.Caption);
|
||||
end;
|
||||
end;
|
||||
SelStart := editDatabases.SelStart;
|
||||
editDatabases.Text := Implode(';', Databases);
|
||||
|
||||
@@ -690,6 +690,11 @@ type
|
||||
TPGRawResults = Array of PPGresult;
|
||||
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);
|
||||
TPgConnection = class(TDBConnection)
|
||||
const
|
||||
DBNAME_DEFAULT = 'postgres';
|
||||
DBNAME_EMPTY = '!';
|
||||
DBTAG_EMPTY = 1;
|
||||
DBTAG_DEFAULT = 2;
|
||||
private
|
||||
FHandle: PPGconn;
|
||||
FLib: TPostgreSQLLib;
|
||||
@@ -2740,7 +2745,7 @@ begin
|
||||
// "You should connect as "postgres" database by default, with an option to change. Don't use template1"
|
||||
dbname := FParameters.AllDatabasesStr;
|
||||
if dbname = '' then
|
||||
dbname := 'postgres';
|
||||
dbname := DBNAME_DEFAULT;
|
||||
|
||||
// Prepare special stuff for SSH tunnel
|
||||
FinalHost := FParameters.Hostname;
|
||||
@@ -2756,9 +2761,10 @@ begin
|
||||
.AddPair('port', IntToStr(FinalPort))
|
||||
.AddPair('user', FParameters.Username)
|
||||
.AddPair('password', FParameters.Password)
|
||||
.AddPair('dbname', dbname)
|
||||
.AddPair('application_name', APPNAME)
|
||||
.AddPair('sslmode', 'disable');
|
||||
if dbname <> DBNAME_EMPTY then
|
||||
ConnectOptions.AddPair('dbname', dbname);
|
||||
if FParameters.WantSSL then begin
|
||||
// Be aware .AddPair would add duplicates
|
||||
case FParameters.SSLVerification of
|
||||
|
||||
Reference in New Issue
Block a user