Issue #1965: show mysql_info() output in log panel, after warnings

This commit is contained in:
Ansgar Becker
2024-06-21 12:57:23 +02:00
parent e028e3f998
commit ac34c1271c
5 changed files with 29 additions and 9 deletions

View File

@ -99,4 +99,8 @@ const
FILEFILTER_SQLITEDB = '*.sqlite3;*.sqlite;*.db;*.s3db'; FILEFILTER_SQLITEDB = '*.sqlite3;*.sqlite;*.db;*.s3db';
FILEEXT_SQLITEDB = 'sqlite3'; FILEEXT_SQLITEDB = 'sqlite3';
PROPOSAL_ITEM_HEIGHT = 18; PROPOSAL_ITEM_HEIGHT = 18;
// Note the following should be in sync to what MySQL returns from SHOW WARNINGS
SLogPrefixWarning = 'Warning';
SLogPrefixNote = 'Note';
SLogPrefixInfo = 'Info';

View File

@ -4787,17 +4787,22 @@ end;
procedure TMySQLConnection.ShowWarnings; procedure TMySQLConnection.ShowWarnings;
var var
Warnings: TDBQuery; Warnings: TDBQuery;
Info: String;
begin begin
// Log warnings // Log warnings
// SHOW WARNINGS is implemented as of MySQL 4.1.0 // SHOW WARNINGS is implemented as of MySQL 4.1.0
if (WarningCount > 0) and (ServerVersionInt >= 40100) then begin if (WarningCount > 0) and (ServerVersionInt >= 40100) then begin
Warnings := GetResults('SHOW WARNINGS'); Warnings := GetResults('SHOW WARNINGS');
while not Warnings.Eof do begin 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; Warnings.Next;
end; end;
Warnings.Free; Warnings.Free;
end; end;
Info := DecodeAPIString(FLib.mysql_info(FHandle));
if not Info.IsEmpty then begin
Log(lcInfo, _(SLogPrefixInfo) + ': ' + Info);
end;
end; end;

View File

@ -274,6 +274,7 @@ type
mysql_get_client_info: function: PAnsiChar; stdcall; mysql_get_client_info: function: PAnsiChar; stdcall;
mysql_get_server_info: function(Handle: PMYSQL): PAnsiChar; stdcall; mysql_get_server_info: function(Handle: PMYSQL): PAnsiChar; stdcall;
mysql_init: function(Handle: PMYSQL): PMYSQL; 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_fields: function(Result: PMYSQL_RES): Integer; stdcall;
mysql_num_rows: function(Result: PMYSQL_RES): Int64; stdcall; mysql_num_rows: function(Result: PMYSQL_RES): Int64; stdcall;
mysql_options: function(Handle: PMYSQL; Option: Integer; arg: PAnsiChar): Integer; 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_client_info, 'mysql_get_client_info');
AssignProc(@mysql_get_server_info, 'mysql_get_server_info'); AssignProc(@mysql_get_server_info, 'mysql_get_server_info');
AssignProc(@mysql_init, 'mysql_init'); AssignProc(@mysql_init, 'mysql_init');
AssignProc(@mysql_info, 'mysql_info');
AssignProc(@mysql_num_fields, 'mysql_num_fields'); AssignProc(@mysql_num_fields, 'mysql_num_fields');
AssignProc(@mysql_num_rows, 'mysql_num_rows'); AssignProc(@mysql_num_rows, 'mysql_num_rows');
AssignProc(@mysql_ping, 'mysql_ping'); AssignProc(@mysql_ping, 'mysql_ping');

View File

@ -439,8 +439,8 @@ begin
FConnection.Query(SQL); FConnection.Query(SQL);
FConnection.ShowWarnings;
FRowCount := Max(FConnection.RowsAffected, 0); FRowCount := Max(FConnection.RowsAffected, 0);
FConnection.ShowWarnings;
end; end;
@ -448,6 +448,7 @@ procedure Tloaddataform.ClientParse(Sender: TObject);
var var
P, ContentLen, ProgressCharsPerStep, ProgressChars: Integer; P, ContentLen, ProgressCharsPerStep, ProgressChars: Integer;
IgnoreLines, ValueCount, PacketSize: Integer; IgnoreLines, ValueCount, PacketSize: Integer;
LineNum: Int64;
RowCountInChunk: Int64; RowCountInChunk: Int64;
EnclLen, TermLen, LineTermLen: Integer; EnclLen, TermLen, LineTermLen: Integer;
Contents: String; Contents: String;
@ -541,13 +542,13 @@ var
begin begin
if SQL = '' then if SQL = '' then
Exit; Exit;
Inc(FRowCount); Inc(LineNum);
for i:=ValueCount to FColumnCount do begin for i:=ValueCount to FColumnCount do begin
Value := 'NULL'; Value := 'NULL';
AddValue; AddValue;
end; end;
ValueCount := 0; ValueCount := 0;
if FRowCount > IgnoreLines then begin if LineNum > IgnoreLines then begin
Delete(SQL, Length(SQL)-1, 2); Delete(SQL, Length(SQL)-1, 2);
StreamWrite(OutStream, SQL + ')'); StreamWrite(OutStream, SQL + ')');
SQL := ''; SQL := '';
@ -561,6 +562,7 @@ var
OutStream.Read(PAnsiChar(SA)^, ChunkSize); OutStream.Read(PAnsiChar(SA)^, ChunkSize);
OutStream.Size := 0; OutStream.Size := 0;
FConnection.Query(UTF8ToString(SA), False, lcScript); FConnection.Query(UTF8ToString(SA), False, lcScript);
Inc(FRowCount, Max(FConnection.RowsAffected, 0));
FConnection.ShowWarnings; FConnection.ShowWarnings;
SQL := ''; SQL := '';
RowCountInChunk := 0; RowCountInChunk := 0;
@ -598,6 +600,7 @@ begin
ProgressCharsPerStep := ContentLen div ProgressBarSteps; ProgressCharsPerStep := ContentLen div ProgressBarSteps;
ProgressChars := 0; ProgressChars := 0;
FRowCount := 0; FRowCount := 0;
LineNum := 0;
RowCountInChunk := 0; RowCountInChunk := 0;
IgnoreLines := UpDownIgnoreLines.Position; IgnoreLines := UpDownIgnoreLines.Position;
ValueCount := 0; ValueCount := 0;
@ -639,7 +642,6 @@ begin
Contents := ''; Contents := '';
FreeAndNil(OutStream); FreeAndNil(OutStream);
FRowCount := Max(FRowCount-IgnoreLines, 0);
if FConnection.Parameters.IsAnyMySQL then begin if FConnection.Parameters.IsAnyMySQL then begin
FConnection.Query('/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '''') */'); FConnection.Query('/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '''') */');

View File

@ -1395,12 +1395,14 @@ var
const const
CheckedStates = [csCheckedNormal, csCheckedPressed, csMixedNormal, csMixedPressed]; CheckedStates = [csCheckedNormal, csCheckedPressed, csMixedNormal, csMixedPressed];
ErrorLineForeground: TColor = $00FFFFFF; ErrorLineForeground: TColor = $00000000;
ErrorLineBackground: TColor = $00000080; ErrorLineBackground: TColor = $00D2B7FF;
WarningLineForeground: TColor = $00000000; WarningLineForeground: TColor = $00000000;
WarningLineBackground: TColor = $00B7CDFF; WarningLineBackground: TColor = $00B7CDFF;
NoteLineForeground: TColor = $00000000; NoteLineForeground: TColor = $00000000;
NoteLineBackground: TColor = $00D3F7FF; NoteLineBackground: TColor = $00D3F7FF;
InfoLineForeground: TColor = $00000000;
InfoLineBackground: TColor = $00C6FFEC;
{$I const.inc} {$I const.inc}
@ -7038,15 +7040,20 @@ begin
FG := ErrorLineForeground; FG := ErrorLineForeground;
BG := ErrorLineBackground; BG := ErrorLineBackground;
end end
else if LineText.Contains(_('Warning')+':') then begin else if LineText.Contains(_(SLogPrefixWarning)+':') then begin
Special := True; Special := True;
FG := WarningLineForeground; FG := WarningLineForeground;
BG := WarningLineBackground; BG := WarningLineBackground;
end end
else if LineText.Contains(_('Note')+':') then begin else if LineText.Contains(_(SLogPrefixNote)+':') then begin
Special := True; Special := True;
FG := NoteLineForeground; FG := NoteLineForeground;
BG := NoteLineBackground; BG := NoteLineBackground;
end
else if LineText.Contains(_(SLogPrefixInfo)+':') then begin
Special := True;
FG := InfoLineForeground;
BG := InfoLineBackground;
end; end;
end; end;