From 05d02627f30d02ccb5a5be573375a8c54740fc4c Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sat, 22 Feb 2020 09:06:37 +0100 Subject: [PATCH] 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" --- source/connections.pas | 8 +++--- source/dbconnection.pas | 59 ++++++++++++++++++++++++++--------------- source/exportgrid.pas | 2 +- source/insertfiles.pas | 2 +- source/loaddata.pas | 12 ++++----- source/main.pas | 18 ++++++------- source/table_editor.pas | 12 ++++----- source/tabletools.pas | 6 ++--- source/usermanager.pas | 2 +- source/view.pas | 8 +++--- 10 files changed, 72 insertions(+), 57 deletions(-) diff --git a/source/connections.pas b/source/connections.pas index c474f676..a5863d80 100644 --- a/source/connections.pas +++ b/source/connections.pas @@ -1299,9 +1299,9 @@ begin 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 @@ begin 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: diff --git a/source/dbconnection.pas b/source/dbconnection.pas index db137ae4..fd87c5ea 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -265,11 +265,12 @@ type 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 @@ begin Prefix := 'Infobright' else if IsMemSQL then Prefix := 'MemSQL' + else if IsMySQL then + Prefix := 'MySQL' else Prefix := 'MariaDB or MySQL'; end; @@ -1491,25 +1494,25 @@ begin 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; @@ -1517,49 +1520,61 @@ 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 @@ begin 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 @@ begin 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 @@ var 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 @@ begin 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 @@ end; 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 @@ begin 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; diff --git a/source/exportgrid.pas b/source/exportgrid.pas index 4bdaed47..fc2ba7ca 100644 --- a/source/exportgrid.pas +++ b/source/exportgrid.pas @@ -879,7 +879,7 @@ begin 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) diff --git a/source/insertfiles.pas b/source/insertfiles.pas index 51d5ccdc..76febc71 100644 --- a/source/insertfiles.pas +++ b/source/insertfiles.pas @@ -629,7 +629,7 @@ begin // 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 diff --git a/source/loaddata.pas b/source/loaddata.pas index 46b6771d..9afc1d47 100644 --- a/source/loaddata.pas +++ b/source/loaddata.pas @@ -155,14 +155,14 @@ begin 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 @@ begin 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); diff --git a/source/main.pas b/source/main.pas index d18aeb9d..7ae8042e 100644 --- a/source/main.pas +++ b/source/main.pas @@ -3306,7 +3306,7 @@ var 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 @@ var 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 @@ begin 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 @@ begin 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 @@ begin 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 @@ begin 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 @@ begin // 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 @@ begin 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 diff --git a/source/table_editor.pas b/source/table_editor.pas index 14cf3c2c..c7b67e64 100644 --- a/source/table_editor.pas +++ b/source/table_editor.pas @@ -282,7 +282,7 @@ begin 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 @@ begin // 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 @@ begin 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 @@ begin 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 @@ begin 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 @@ begin 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; diff --git a/source/tabletools.pas b/source/tabletools.pas index 47745cd5..3f597cf2 100644 --- a/source/tabletools.pas +++ b/source/tabletools.pas @@ -868,16 +868,16 @@ begin 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); diff --git a/source/usermanager.pas b/source/usermanager.pas index f55b7f9d..6376b20d 100644 --- a/source/usermanager.pas +++ b/source/usermanager.pas @@ -581,7 +581,7 @@ begin // http://dev.mysql.com/doc/refman/5.7/en/show-grants.html // As of MySQL 5.7.6, SHOW GRANTS output does not include IDENTIFIED BY PASSWORD clauses. // Use the SHOW CREATE USER statement instead. See Section 14.7.5.12, "SHOW CREATE USER Syntax". - if FConnection.Parameters.IsMySQL and (FConnection.ServerVersionInt < 50706) then begin + if FConnection.Parameters.IsAnyMySQL and (FConnection.ServerVersionInt < 50706) then begin if not FAdded then begin editPassword.TextHint := FConnection.UnescapeString(rxGrant.Match[10]); // Set password for changed user, to silence the error message about invalid length diff --git a/source/view.pas b/source/view.pas index 8f91700e..9ec36462 100644 --- a/source/view.pas +++ b/source/view.pas @@ -109,12 +109,12 @@ begin end; // Most clauses only supported by MySQL - comboDefiner.Enabled := comboDefiner.Enabled and Obj.Connection.Parameters.IsMySQL; + comboDefiner.Enabled := comboDefiner.Enabled and Obj.Connection.Parameters.IsAnyMySQL; lblDefiner.Enabled := comboDefiner.Enabled; - comboSecurity.Enabled := comboSecurity.Enabled and Obj.Connection.Parameters.IsMySQL; + comboSecurity.Enabled := comboSecurity.Enabled and Obj.Connection.Parameters.IsAnyMySQL; lblSecurity.Enabled := comboSecurity.Enabled; - rgAlgorithm.Enabled := rgAlgorithm.Enabled and Obj.Connection.Parameters.IsMySQL; - rgCheck.Enabled := rgCheck.Enabled and Obj.Connection.Parameters.IsMySQL; + rgAlgorithm.Enabled := rgAlgorithm.Enabled and Obj.Connection.Parameters.IsAnyMySQL; + rgCheck.Enabled := rgCheck.Enabled and Obj.Connection.Parameters.IsAnyMySQL; Modified := False; btnSave.Enabled := Modified;