Skip to content
Permalink
Browse files

Make TConnectionParameters.IsMySQL specific to MySQL only, and rename…

… the grouped type checks to IsAnyMySQL, IsAnyMSSQL etc. This way the status bar now shows "MySQL", not "MySQL or MariaDB"
  • Loading branch information
ansgarbecker committed Feb 22, 2020
1 parent e97b8ae commit 05d02627f30d02ccb5a5be573375a8c54740fc4c
@@ -1299,9 +1299,9 @@ procedure Tconnform.ValidateControls;
lblHost.Caption := _('Hostname / IP:');
end;
end;
editHost.RightButton.Visible := Params.IsSQLite;
editHost.RightButton.Visible := Params.IsAnySQLite;
chkLoginPrompt.Enabled := Params.NetTypeGroup in [ngMySQL, ngMSSQL, ngPgSQL];
chkWindowsAuth.Enabled := Params.IsMSSQL;
chkWindowsAuth.Enabled := Params.IsAnyMSSQL;
lblUsername.Enabled := (Params.NetTypeGroup in [ngMySQL, ngMSSQL, ngPgSQL])
and ((not chkLoginPrompt.Checked) or (not chkLoginPrompt.Enabled))
and ((not chkWindowsAuth.Checked) or (not chkWindowsAuth.Enabled));
@@ -1311,8 +1311,8 @@ 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;
chkCompressed.Enabled := Params.IsMySQL;
lblDatabase.Caption := IfThen(Params.IsPostgreSQL, _('Database')+':', _('Databases')+':');
chkCompressed.Enabled := Params.IsAnyMySQL;
lblDatabase.Caption := IfThen(Params.IsAnyPostgreSQL, _('Database')+':', _('Databases')+':');
lblDatabase.Enabled := Params.NetTypeGroup in [ngMySQL, ngMSSQL, ngPgSQL];
editDatabases.Enabled := lblDatabase.Enabled;
// SSH tunnel tab:
@@ -265,11 +265,12 @@ TConnectionParameters = class(TObject)
function NetTypeName(LongFormat: Boolean): String;
function IsCompatibleToWin10S: Boolean;
function GetNetTypeGroup: TNetTypeGroup;
function IsMySQL: Boolean;
function IsMSSQL: Boolean;
function IsPostgreSQL: Boolean;
function IsSQLite: Boolean;
function IsAnyMySQL: Boolean;
function IsAnyMSSQL: Boolean;
function IsAnyPostgreSQL: Boolean;
function IsAnySQLite: Boolean;
function IsMariaDB: Boolean;
function IsMySQL: Boolean;
function IsPercona: Boolean;
function IsTokudb: Boolean;
function IsInfiniDB: Boolean;
@@ -1408,6 +1409,8 @@ function TConnectionParameters.NetTypeName(LongFormat: Boolean): String;
Prefix := 'Infobright'
else if IsMemSQL then
Prefix := 'MemSQL'
else if IsMySQL then
Prefix := 'MySQL'
else
Prefix := 'MariaDB or MySQL';
end;
@@ -1491,75 +1494,87 @@ function TConnectionParameters.GetNetTypeGroup: TNetTypeGroup;
end;


function TConnectionParameters.IsMySQL: Boolean;
function TConnectionParameters.IsAnyMySQL: Boolean;
begin
Result := NetTypeGroup = ngMySQL;
end;


function TConnectionParameters.IsMSSQL: Boolean;
function TConnectionParameters.IsAnyMSSQL: Boolean;
begin
Result := NetTypeGroup = ngMSSQL;
end;


function TConnectionParameters.IsPostgreSQL: Boolean;
function TConnectionParameters.IsAnyPostgreSQL: Boolean;
begin
Result := NetTypeGroup = ngPgSQL;
end;


function TConnectionParameters.IsSQLite;
function TConnectionParameters.IsAnySQLite;
begin
Result := NetTypeGroup = ngSQLite;
end;


function TConnectionParameters.IsMariaDB: Boolean;
begin
Result := IsMySQL and (Pos('-mariadb', LowerCase(ServerVersion)) > 0);
Result := IsAnyMySQL and (Pos('-mariadb', LowerCase(ServerVersion)) > 0);
end;


function TConnectionParameters.IsMySQL: Boolean;
begin
Result := IsAnyMySQL
and (not IsMariaDB)
and (not IsPercona)
and (not IsTokudb)
and (not IsInfiniDB)
and (not IsInfobright)
and (not IsMemSQL);
end;


function TConnectionParameters.IsPercona: Boolean;
begin
Result := IsMySQL and (Pos('percona server', LowerCase(ServerVersion)) > 0);
Result := IsAnyMySQL and (Pos('percona server', LowerCase(ServerVersion)) > 0);
end;


function TConnectionParameters.IsTokudb: Boolean;
begin
Result := IsMySQL and (Pos('tokudb', LowerCase(ServerVersion)) > 0);
Result := IsAnyMySQL and (Pos('tokudb', LowerCase(ServerVersion)) > 0);
end;


function TConnectionParameters.IsInfiniDB: Boolean;
begin
Result := IsMySQL and (Pos('infinidb', LowerCase(ServerVersion)) > 0);
Result := IsAnyMySQL and (Pos('infinidb', LowerCase(ServerVersion)) > 0);
end;


function TConnectionParameters.IsInfobright: Boolean;
begin
Result := IsMySQL and (Pos('infobright', LowerCase(ServerVersion)) > 0);
Result := IsAnyMySQL and (Pos('infobright', LowerCase(ServerVersion)) > 0);
end;


function TConnectionParameters.IsAzure: Boolean;
begin
Result := IsMSSQL and (Pos('azure', LowerCase(ServerVersion)) > 0);
Result := IsAnyMSSQL and (Pos('azure', LowerCase(ServerVersion)) > 0);
end;


function TConnectionParameters.IsMemSQL: Boolean;
begin
Result := IsMySQL and (Pos('memsql', LowerCase(ServerVersion)) > 0);
Result := IsAnyMySQL and (Pos('memsql', LowerCase(ServerVersion)) > 0);
end;


function TConnectionParameters.IsRedshift: Boolean;
begin
Result := IsPostgreSQL and (Pos('redshift', LowerCase(ServerVersion)) > 0);
Result := IsAnyPostgreSQL and (Pos('redshift', LowerCase(ServerVersion)) > 0);
end;


@@ -4238,7 +4253,7 @@ function TDBConnection.QuotedDbAndTableName(DB, Obj: String): String;
else begin
// Fallback for target tables which do not yet exist. For example in copytable dialog.
Result := QuoteIdent(DB) + '.';
if Parameters.IsMSSQL then
if Parameters.IsAnyMSSQL then
Result := Result + '.';
Result := Result + QuoteIdent(Obj);
end;
@@ -4819,7 +4834,7 @@ function TDBConnection.GetTableKeys(Table: TDBObject): TTableKeyList;
KeyQuery := GetResults('SELECT * FROM '+
QuoteIdent(InfSch)+'.'+QuoteIdent(InformationSchemaObjects[ColTableIdx])+' AS col'+
', '+QuoteIdent(InfSch)+'.'+QuoteIdent(InformationSchemaObjects[ConTableIdx])+' AS con'+
' WHERE col.TABLE_SCHEMA='+EscapeString(IfThen(Parameters.IsMSSQL, Table.Schema, Table.Database))+
' WHERE col.TABLE_SCHEMA='+EscapeString(IfThen(Parameters.IsAnyMSSQL, Table.Schema, Table.Database))+
' AND col.TABLE_NAME='+EscapeString(Table.Name)+
' AND col.TABLE_SCHEMA=con.TABLE_SCHEMA'+
' AND col.TABLE_NAME=con.TABLE_NAME'+
@@ -7192,7 +7207,7 @@ function TDBQuery.HexValue(Column: Integer; IgnoreErrors: Boolean=False): String
baData: TBytes;
begin
// Return a binary column value as hex AnsiString
if FConnection.Parameters.IsMysql then begin
if FConnection.Parameters.IsAnyMysql then begin
GetColBinData(Column, baData);
Result := HexValue(baData);
end else
@@ -7765,7 +7780,7 @@ function TDBQuery.SaveModifications: Boolean;
else case Datatype(i).Category of
dtcInteger, dtcReal: begin
Val := Connection.EscapeString(Cell.NewText);
if (Datatype(i).Index = dtBit) and FConnection.Parameters.IsMySQL then
if (Datatype(i).Index = dtBit) and FConnection.Parameters.IsAnyMySQL then
Val := 'b' + Val;
end;
dtcBinary, dtcSpatial:
@@ -8454,7 +8469,7 @@ function TDBObject.QuotedDatabase(AlwaysQuote: Boolean=True): String;
function TDBObject.QuotedName(AlwaysQuote: Boolean=True; SeparateSegments: Boolean=True): String;
begin
Result := '';
if FConnection.Parameters.IsMSSQL then begin
if FConnection.Parameters.IsAnyMSSQL then begin
// MSSQL expects schema separated from table, and in some situations the whole string quoted as a whole
if Schema <> '' then begin
if SeparateSegments then
@@ -8782,7 +8797,7 @@ function TTableColumn.SQLCode(OverrideCollation: String=''; Parts: TColumnParts=
end;

if InParts(cpComment) then begin
if (Comment <> '') and FConnection.Parameters.IsMySQL then
if (Comment <> '') and FConnection.Parameters.IsAnyMySQL then
Result := Result + 'COMMENT ' + FConnection.EscapeString(Comment) + ' ';
end;

@@ -879,7 +879,7 @@ procedure TfrmExportGrid.btnOKClick(Sender: TObject);
Data := ''
else if GridData.IsNull(Col) then
Data := 'NULL'
else if (GridData.DataType(Col).Index = dtBit) and GridData.Connection.Parameters.IsMySQL then
else if (GridData.DataType(Col).Index = dtBit) and GridData.Connection.Parameters.IsAnyMySQL then
Data := 'b' + esc(Data)
else if (GridData.DataType(Col).Category in [dtcText, dtcTemporal, dtcOther])
or ((GridData.DataType(Col).Category in [dtcBinary, dtcSpatial]) and Mainform.actBlobAsText.Checked)
@@ -629,7 +629,7 @@ procedure TfrmInsertFiles.btnInsertClick(Sender: TObject);
// Import binaries as-is (byte for byte), and auto-detect encoding of text files.
if FileInfo.IsBinary then begin
FileContent := '';
if FConnection.Parameters.IsMySQL then
if FConnection.Parameters.IsAnyMySQL then
FileContent := '_binary ';
FileContent := FileContent + '0x' + BinToWideHex(ReadBinaryFile(FileInfo.Filename, 0))
end else
@@ -155,14 +155,14 @@ procedure Tloaddataform.FormShow(Sender: TObject);
FConnection := MainForm.ActiveConnection;

// Disable features supported in MySQL only, if active connection is not MySQL
if not FConnection.Parameters.IsMySQL then begin
if not FConnection.Parameters.IsAnyMySQL then begin
grpParseMethod.ItemIndex := 1;
grpDuplicates.ItemIndex := 0;
end;
grpParseMethod.Controls[0].Enabled := FConnection.Parameters.IsMySQL;
grpDuplicates.Controls[1].Enabled := FConnection.Parameters.IsMySQL;
grpDuplicates.Controls[2].Enabled := FConnection.Parameters.IsMySQL;
chkLowPriority.Enabled := FConnection.Parameters.IsMySQL;
grpParseMethod.Controls[0].Enabled := FConnection.Parameters.IsAnyMySQL;
grpDuplicates.Controls[1].Enabled := FConnection.Parameters.IsAnyMySQL;
grpDuplicates.Controls[2].Enabled := FConnection.Parameters.IsAnyMySQL;
chkLowPriority.Enabled := FConnection.Parameters.IsAnyMySQL;

// Read databases and tables from active connection
comboDatabase.Items.Clear;
@@ -319,7 +319,7 @@ procedure Tloaddataform.btnImportClick(Sender: TObject);
end;
MainForm.LogSQL(FormatNumber(RowCount)+' rows imported in '+FormatNumber((GetTickcount-StartTickCount)/1000, 3)+' seconds.');
// SHOW WARNINGS is implemented as of MySQL 4.1.0
if FConnection.Parameters.IsMySQL and (FConnection.ServerVersionInt >= 40100) then begin
if FConnection.Parameters.IsAnyMySQL and (FConnection.ServerVersionInt >= 40100) then begin
Warnings := FConnection.GetResults('SHOW WARNINGS');
while not Warnings.Eof do begin
MainForm.LogSQL(Warnings.Col(0)+' ('+Warnings.Col(1)+'): '+Warnings.Col(2), lcError);
@@ -3306,7 +3306,7 @@ procedure TMainForm.menuQueryExplainClick(Sender: TObject);
begin
// Sub menu with EXPLAIN items pops up
SQL := GetCurrentQuery(ActiveQueryTab);
actExplainCurrentQuery.Enabled := ActiveConnection.Parameters.IsMySQL;
actExplainCurrentQuery.Enabled := ActiveConnection.Parameters.IsAnyMySQL;
actExplainAnalyzeCurrentQuery.Enabled := actExplainCurrentQuery.Enabled;
end;

@@ -3618,7 +3618,7 @@ procedure TMainForm.actLaunchCommandlineExecute(Sender: TObject);
begin
// Launch mysql.exe
Conn := ActiveConnection;
if not Conn.Parameters.IsMySQL then
if not Conn.Parameters.IsAnyMySQL then
ErrorDialog(_('Command line only works on MySQL connections.'))
else begin
if FIsWine then begin
@@ -5250,9 +5250,9 @@ procedure TMainForm.DataGridBeforePaint(Sender: TBaseVirtualTree; TargetCanvas:
ngPgSQL, ngSQLite: Select := Select + ' SUBSTR(' + DBObj.Connection.QuoteIdent(c.Name) + ', 1, ' + IntToStr(GRIDMAXDATA) + '), ';
else raise Exception.CreateFmt(_(MsgUnhandledNetType), [Integer(DBObj.Connection.Parameters.NetType)]);
end;
end else if DBObj.Connection.Parameters.IsMSSQL and (c.DataType.Index=dtTimestamp) then begin
end else if DBObj.Connection.Parameters.IsAnyMSSQL and (c.DataType.Index=dtTimestamp) then begin
Select := Select + ' CAST(' + DBObj.Connection.QuoteIdent(c.Name) + ' AS INT), ';
end else if DBObj.Connection.Parameters.IsMSSQL and (c.DataType.Index=dtHierarchyid) then begin
end else if DBObj.Connection.Parameters.IsAnyMSSQL and (c.DataType.Index=dtHierarchyid) then begin
Select := Select + ' CAST(' + DBObj.Connection.QuoteIdent(c.Name) + ' AS NVARCHAR('+IntToStr(GRIDMAXDATA)+')), ';
end else begin
Select := Select + ' ' + DBObj.Connection.QuoteIdent(c.Name) + ', ';
@@ -6811,7 +6811,7 @@ procedure TMainForm.popupDBPopup(Sender: TObject);
menuTreeCollapseAll.Enabled := False;
menuTreeOptions.Enabled := False;
end;
if (ActiveConnection <> nil) and (ActiveConnection.Parameters.IsMySQL) then begin
if (ActiveConnection <> nil) and (ActiveConnection.Parameters.IsAnyMySQL) then begin
Version := ActiveConnection.ServerVersionInt;
actCreateView.Enabled := actCreateView.Enabled and (Version >= 50001);
actCreateRoutine.Enabled := actCreateRoutine.Enabled and (Version >= 50003);
@@ -7890,7 +7890,7 @@ procedure TMainForm.ListProcessesFocusChanged(Sender: TBaseVirtualTree;

SynMemoProcessView.Enabled := EnableControls;
pnlProcessView.Enabled := EnableControls;
lblExplainProcess.Enabled := EnableControls and ActiveConnection.Parameters.IsMySQL;
lblExplainProcess.Enabled := EnableControls and ActiveConnection.Parameters.IsAnyMySQL;
menuExplainProcess.Enabled := lblExplainProcess.Enabled;
lblExplainProcessAnalyzer.Enabled := lblExplainProcess.Enabled;
menuExplainAnalyzer.Enabled := lblExplainProcess.Enabled;
@@ -8655,7 +8655,7 @@ procedure TMainForm.DBtreeFocusChanged(Sender: TBaseVirtualTree; Node: PVirtualN
InvalidateVT(ListTables, VTREE_NOTLOADED, True);
if FActiveDbObj.NodeType = lntGroup then
InvalidateVT(ListTables, VTREE_NOTLOADED, True);
if FActiveDbObj.Connection.Parameters.IsSQLite then // Prefer visible filename over visible left part of path
if FActiveDbObj.Connection.Parameters.IsAnySQLite then // Prefer visible filename over visible left part of path
TabHostName := StrEllipsis(FActiveDbObj.Connection.Parameters.HostName, 60, False)
else
TabHostName := FActiveDbObj.Connection.Parameters.HostName;
@@ -10151,7 +10151,7 @@ procedure TMainForm.HostListBeforePaint(Sender: TBaseVirtualTree; TargetCanvas:
// Status + command statistics only available in MySQL
if ((vt=ListStatus) or (vt=ListCommandStats))
and (Conn <> nil)
and (not Conn.Parameters.IsMySQL) then begin
and (not Conn.Parameters.IsAnyMySQL) then begin
vt.Clear;
vt.EmptyListMessage := f_('Not available on %s', [Conn.Parameters.NetTypeName(False)]);
vt.Tag := VTREE_LOADED;
@@ -12751,7 +12751,7 @@ procedure TMainForm.RefreshHelperNode(NodeIndex: Cardinal);
Tab.treeHelpers.CheckState[Node] := OldCheckState;
Tab.treeHelpers.Expanded[Node] := vsExpanded in OldStates;
// Disable profiling when not on MySQL
if (NodeIndex = HELPERNODE_PROFILE) and (Conn <> nil) and (not Conn.Parameters.IsMySQL) then begin
if (NodeIndex = HELPERNODE_PROFILE) and (Conn <> nil) and (not Conn.Parameters.IsAnyMySQL) then begin
Tab.treeHelpers.CheckState[Node] := csUncheckedNormal;
end;
// Do not check expansion state of children unless the parent node is expanded, to avoid
@@ -282,7 +282,7 @@ procedure TfrmTableEditor.Init(Obj: TDBObject);
if DBObject.Name = '' then begin
// Creating new table
editName.Text := '';
if DBObject.Connection.Parameters.IsMySQL then
if DBObject.Connection.Parameters.IsAnyMySQL then
comboCollation.ItemIndex := comboCollation.Items.IndexOf(DBObject.Connection.GetSessionVariable('collation_database'));
PageControlMain.ActivePage := tabBasic;
FColumns := TTableColumnList.Create;
@@ -540,7 +540,7 @@ function TfrmTableEditor.ComposeAlterStatement: TSQLBatch;
// appending an ALTER COLUMN ... DROP DEFAULT, without getting an "unknown column" error.
// Also, do this after the data type was altered, if from TEXT > VARCHAR e.g.
for i:=0 to FColumns.Count-1 do begin
if (Conn.Parameters.IsMySQL or Conn.Parameters.IsPostgreSQL)
if (Conn.Parameters.IsAnyMySQL or Conn.Parameters.IsAnyPostgreSQL)
and (FColumns[i].FStatus = esModified)
and (FColumns[i].DefaultType = cdtNothing)
and (FColumns[i].OldDataType.HasDefault)
@@ -692,7 +692,7 @@ function TfrmTableEditor.ComposeAlterStatement: TSQLBatch;
if FColumns[i].Status = esDeleted then begin
Specs.Add('DROP COLUMN '+Conn.QuoteIdent(FColumns[i].OldName));
// MSSQL wants one ALTER TABLE query per DROP COLUMN
if Conn.Parameters.IsMSSQL then
if Conn.Parameters.IsAnyMSSQL then
FinishSpecs;
end;
end;
@@ -799,7 +799,7 @@ function TfrmTableEditor.ComposeCreateStatement: TSQLBatch;
SQL := SQL + '/*!50100 ' + SynMemoPartitions.Text + ' */';
SQL := SQL + ';' + CRLF;

if DBObject.Connection.Parameters.IsPostgreSQL then begin
if DBObject.Connection.Parameters.IsAnyPostgreSQL then begin
Node := listColumns.GetFirst;
while Assigned(Node) do begin
Col := listColumns.GetNodeData(Node);
@@ -1129,7 +1129,7 @@ function TfrmTableEditor.CellEditingAllowed(Node: PVirtualNode; Column: TColumnI
4: begin
Result := (Col.DataType.Category in [dtcInteger, dtcReal])
and (Col.DataType.Index <> dtBit)
and (DBObject.Connection.Parameters.IsMySQL);
and (DBObject.Connection.Parameters.IsAnyMySQL);
if (not Result) and Col.Unsigned then begin
Col.Unsigned := False;
Col.Status := esModified;
@@ -1152,7 +1152,7 @@ function TfrmTableEditor.CellEditingAllowed(Node: PVirtualNode; Column: TColumnI
6: begin
Result := (Col.DataType.Category in [dtcInteger, dtcReal])
and (Col.DataType.Index <> dtBit)
and (DBObject.Connection.Parameters.IsMySQL);
and (DBObject.Connection.Parameters.IsAnyMySQL);
if (not Result) and Col.ZeroFill then begin
Col.ZeroFill := False;
Col.Status := esModified;
@@ -868,16 +868,16 @@ procedure TfrmTableTools.DoFind(DBObj: TDBObject);
FindText := LowerCase(FindText);
FindTextJokers := LowerCase(FindTextJokers);
RoutineDefinitionColumn := 'LOWER('+RoutineDefinitionColumn+')';
if DBObj.Connection.Parameters.IsSQLite then begin
if DBObj.Connection.Parameters.IsAnySQLite then begin
DBObj.Connection.Query('PRAGMA case_sensitive_like=FALSE');
end;
end else begin
if DBObj.Connection.Parameters.IsSQLite then begin
if DBObj.Connection.Parameters.IsAnySQLite then begin
DBObj.Connection.Query('PRAGMA case_sensitive_like=TRUE');
end;
end;
RoutineSchemaColumn := 'routine_schema';
if DBObj.Connection.Parameters.IsMSSQL then
if DBObj.Connection.Parameters.IsAnyMSSQL then
RoutineSchemaColumn := 'routine_catalog';

Columns := TTableColumnList.Create(True);

0 comments on commit 05d0262

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