From ac34c1271c97bd4a1f4adb371b19f5f67abfa721 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Fri, 21 Jun 2024 12:57:23 +0200 Subject: [PATCH] Issue #1965: show mysql_info() output in log panel, after warnings --- source/const.inc | 4 ++++ source/dbconnection.pas | 7 ++++++- source/dbstructures.mysql.pas | 2 ++ source/loaddata.pas | 10 ++++++---- source/main.pas | 15 +++++++++++---- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/source/const.inc b/source/const.inc index 3747a840..8484ce0a 100644 --- a/source/const.inc +++ b/source/const.inc @@ -99,4 +99,8 @@ const FILEFILTER_SQLITEDB = '*.sqlite3;*.sqlite;*.db;*.s3db'; FILEEXT_SQLITEDB = 'sqlite3'; PROPOSAL_ITEM_HEIGHT = 18; + // Note the following should be in sync to what MySQL returns from SHOW WARNINGS + SLogPrefixWarning = 'Warning'; + SLogPrefixNote = 'Note'; + SLogPrefixInfo = 'Info'; diff --git a/source/dbconnection.pas b/source/dbconnection.pas index dce63607..b6896498 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -4787,17 +4787,22 @@ end; procedure TMySQLConnection.ShowWarnings; var Warnings: TDBQuery; + Info: String; begin // Log warnings // SHOW WARNINGS is implemented as of MySQL 4.1.0 if (WarningCount > 0) and (ServerVersionInt >= 40100) then begin Warnings := GetResults('SHOW WARNINGS'); while not Warnings.Eof do begin - Log(lcError, Warnings.Col('Level') + ': ('+Warnings.Col('Code')+') ' + Warnings.Col('Message')); + Log(lcError, _(Warnings.Col('Level')) + ': ('+Warnings.Col('Code')+') ' + Warnings.Col('Message')); Warnings.Next; end; Warnings.Free; end; + Info := DecodeAPIString(FLib.mysql_info(FHandle)); + if not Info.IsEmpty then begin + Log(lcInfo, _(SLogPrefixInfo) + ': ' + Info); + end; end; diff --git a/source/dbstructures.mysql.pas b/source/dbstructures.mysql.pas index 7b0e5fe5..8ca5457e 100644 --- a/source/dbstructures.mysql.pas +++ b/source/dbstructures.mysql.pas @@ -274,6 +274,7 @@ type mysql_get_client_info: function: PAnsiChar; stdcall; mysql_get_server_info: function(Handle: PMYSQL): PAnsiChar; stdcall; mysql_init: function(Handle: PMYSQL): PMYSQL; stdcall; + mysql_info: function(Handle: PMYSQL): PAnsiChar; stdcall; mysql_num_fields: function(Result: PMYSQL_RES): Integer; stdcall; mysql_num_rows: function(Result: PMYSQL_RES): Int64; stdcall; mysql_options: function(Handle: PMYSQL; Option: Integer; arg: PAnsiChar): Integer; stdcall; @@ -3150,6 +3151,7 @@ begin AssignProc(@mysql_get_client_info, 'mysql_get_client_info'); AssignProc(@mysql_get_server_info, 'mysql_get_server_info'); AssignProc(@mysql_init, 'mysql_init'); + AssignProc(@mysql_info, 'mysql_info'); AssignProc(@mysql_num_fields, 'mysql_num_fields'); AssignProc(@mysql_num_rows, 'mysql_num_rows'); AssignProc(@mysql_ping, 'mysql_ping'); diff --git a/source/loaddata.pas b/source/loaddata.pas index 202a439c..8cc547be 100644 --- a/source/loaddata.pas +++ b/source/loaddata.pas @@ -439,8 +439,8 @@ begin FConnection.Query(SQL); - FConnection.ShowWarnings; FRowCount := Max(FConnection.RowsAffected, 0); + FConnection.ShowWarnings; end; @@ -448,6 +448,7 @@ procedure Tloaddataform.ClientParse(Sender: TObject); var P, ContentLen, ProgressCharsPerStep, ProgressChars: Integer; IgnoreLines, ValueCount, PacketSize: Integer; + LineNum: Int64; RowCountInChunk: Int64; EnclLen, TermLen, LineTermLen: Integer; Contents: String; @@ -541,13 +542,13 @@ var begin if SQL = '' then Exit; - Inc(FRowCount); + Inc(LineNum); for i:=ValueCount to FColumnCount do begin Value := 'NULL'; AddValue; end; ValueCount := 0; - if FRowCount > IgnoreLines then begin + if LineNum > IgnoreLines then begin Delete(SQL, Length(SQL)-1, 2); StreamWrite(OutStream, SQL + ')'); SQL := ''; @@ -561,6 +562,7 @@ var OutStream.Read(PAnsiChar(SA)^, ChunkSize); OutStream.Size := 0; FConnection.Query(UTF8ToString(SA), False, lcScript); + Inc(FRowCount, Max(FConnection.RowsAffected, 0)); FConnection.ShowWarnings; SQL := ''; RowCountInChunk := 0; @@ -598,6 +600,7 @@ begin ProgressCharsPerStep := ContentLen div ProgressBarSteps; ProgressChars := 0; FRowCount := 0; + LineNum := 0; RowCountInChunk := 0; IgnoreLines := UpDownIgnoreLines.Position; ValueCount := 0; @@ -639,7 +642,6 @@ begin Contents := ''; FreeAndNil(OutStream); - FRowCount := Max(FRowCount-IgnoreLines, 0); if FConnection.Parameters.IsAnyMySQL then begin FConnection.Query('/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '''') */'); diff --git a/source/main.pas b/source/main.pas index 4be69214..54c3eac3 100644 --- a/source/main.pas +++ b/source/main.pas @@ -1395,12 +1395,14 @@ var const CheckedStates = [csCheckedNormal, csCheckedPressed, csMixedNormal, csMixedPressed]; - ErrorLineForeground: TColor = $00FFFFFF; - ErrorLineBackground: TColor = $00000080; + ErrorLineForeground: TColor = $00000000; + ErrorLineBackground: TColor = $00D2B7FF; WarningLineForeground: TColor = $00000000; WarningLineBackground: TColor = $00B7CDFF; NoteLineForeground: TColor = $00000000; NoteLineBackground: TColor = $00D3F7FF; + InfoLineForeground: TColor = $00000000; + InfoLineBackground: TColor = $00C6FFEC; {$I const.inc} @@ -7038,15 +7040,20 @@ begin FG := ErrorLineForeground; BG := ErrorLineBackground; end - else if LineText.Contains(_('Warning')+':') then begin + else if LineText.Contains(_(SLogPrefixWarning)+':') then begin Special := True; FG := WarningLineForeground; BG := WarningLineBackground; end - else if LineText.Contains(_('Note')+':') then begin + else if LineText.Contains(_(SLogPrefixNote)+':') then begin Special := True; FG := NoteLineForeground; BG := NoteLineBackground; + end + else if LineText.Contains(_(SLogPrefixInfo)+':') then begin + Special := True; + FG := InfoLineForeground; + BG := InfoLineBackground; end; end;