Issue #1965: show SQL warnings in forms: event editor, copy table, create database, insert files, load CSV

This commit is contained in:
Ansgar Becker
2024-06-19 17:09:46 +02:00
parent 51f199ca69
commit 54bb0bab45
6 changed files with 20 additions and 16 deletions

View File

@ -377,6 +377,7 @@ begin
Exit; Exit;
end; end;
FConnection.Query('DROP TABLE '+TargetTable); FConnection.Query('DROP TABLE '+TargetTable);
FConnection.ShowWarnings;
end; end;
Screen.Cursor := crHourglass; Screen.Cursor := crHourglass;
@ -479,8 +480,11 @@ begin
try try
MainForm.ShowStatusMsg(_('Creating table ...')); MainForm.ShowStatusMsg(_('Creating table ...'));
FConnection.Query(CreateCode); FConnection.Query(CreateCode);
if InsertCode <> '' then FConnection.ShowWarnings;
if InsertCode <> '' then begin
FConnection.Query(InsertCode); FConnection.Query(InsertCode);
FConnection.ShowWarnings;
end;
// actRefresh takes care of whether the table editor is open // actRefresh takes care of whether the table editor is open
// See also issue #1597 // See also issue #1597
MainForm.actRefresh.Execute MainForm.actRefresh.Execute

View File

@ -138,6 +138,7 @@ begin
if modifyDB = '' then try if modifyDB = '' then try
sql := GetCreateStatement; sql := GetCreateStatement;
FConnection.Query(sql); FConnection.Query(sql);
FConnection.ShowWarnings;
AppSettings.WriteString(asCreateDbCollation, comboCollation.Text); AppSettings.WriteString(asCreateDbCollation, comboCollation.Text);
MainForm.RefreshTree; MainForm.RefreshTree;
// Close form // Close form
@ -154,6 +155,7 @@ begin
if modifyDB = editDBName.Text then begin if modifyDB = editDBName.Text then begin
// Alter database // Alter database
FConnection.Query(sql); FConnection.Query(sql);
FConnection.ShowWarnings;
end else begin end else begin
// Rename database // Rename database
ObjectsInOldDb := FConnection.GetDBObjects(modifyDB, True); ObjectsInOldDb := FConnection.GetDBObjects(modifyDB, True);
@ -180,6 +182,7 @@ begin
if AllDatabases.IndexOf(editDBName.Text) = -1 then begin if AllDatabases.IndexOf(editDBName.Text) = -1 then begin
// Target db does not exist - create it // Target db does not exist - create it
FConnection.Query(GetCreateStatement); FConnection.Query(GetCreateStatement);
FConnection.ShowWarnings;
end else begin end else begin
if MessageDialog(f_('Database "%s" exists. But it does not contain objects with same names as in "%s", so it''s uncritical to move everything. Move all objects to "%s"?', [editDBName.Text, modifyDB, editDBName.Text]), if MessageDialog(f_('Database "%s" exists. But it does not contain objects with same names as in "%s", so it''s uncritical to move everything. Move all objects to "%s"?', [editDBName.Text, modifyDB, editDBName.Text]),
mtConfirmation, [mbYes, mbCancel]) <> mrYes then mtConfirmation, [mbYes, mbCancel]) <> mrYes then
@ -195,6 +198,7 @@ begin
Delete(sql, Length(sql)-1, 2); Delete(sql, Length(sql)-1, 2);
sql := 'RENAME TABLE '+sql; sql := 'RENAME TABLE '+sql;
FConnection.Query(sql); FConnection.Query(sql);
FConnection.ShowWarnings;
FConnection.ClearDbObjects(modifyDB); FConnection.ClearDbObjects(modifyDB);
FConnection.ClearDbObjects(editDBName.Text); FConnection.ClearDbObjects(editDBName.Text);
end; end;
@ -202,6 +206,7 @@ begin
ObjectsLeft := FConnection.GetDBObjects(modifyDB); ObjectsLeft := FConnection.GetDBObjects(modifyDB);
if ObjectsLeft.Count = 0 then begin if ObjectsLeft.Count = 0 then begin
FConnection.Query('DROP DATABASE '+FConnection.QuoteIdent(modifyDB)); FConnection.Query('DROP DATABASE '+FConnection.QuoteIdent(modifyDB));
FConnection.ShowWarnings;
MainForm.RefreshTree; MainForm.RefreshTree;
end; end;
end; end;

View File

@ -4788,7 +4788,9 @@ procedure TMySQLConnection.ShowWarnings;
var var
Warnings: TDBQuery; Warnings: TDBQuery;
begin begin
if WarningCount > 0 then 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'); 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'));

View File

@ -231,6 +231,7 @@ begin
sql := ComposeAlterStatement; sql := ComposeAlterStatement;
try try
MainForm.ActiveConnection.Query(sql); MainForm.ActiveConnection.Query(sql);
MainForm.ActiveConnection.ShowWarnings;
DBObject.Name := editName.Text; DBObject.Name := editName.Text;
DBObject.UnloadDetails; DBObject.UnloadDetails;
tabALTERcode.TabVisible := ObjectExists; tabALTERcode.TabVisible := ObjectExists;

View File

@ -659,6 +659,7 @@ begin
sql := sql + ')'; sql := sql + ')';
try try
FConnection.Query(sql); FConnection.Query(sql);
FConnection.ShowWarnings;
Mainform.ProgressStep; Mainform.ProgressStep;
except except
on E:EDbError do begin on E:EDbError do begin

View File

@ -300,7 +300,6 @@ procedure Tloaddataform.btnImportClick(Sender: TObject);
var var
StartTickCount: Cardinal; StartTickCount: Cardinal;
i: Integer; i: Integer;
Warnings: TDBQuery;
begin begin
Screen.Cursor := crHourglass; Screen.Cursor := crHourglass;
StartTickCount := GetTickCount; StartTickCount := GetTickCount;
@ -309,9 +308,11 @@ begin
// Truncate table before importing // Truncate table before importing
if chkTruncateTable.Checked then try if chkTruncateTable.Checked then try
FConnection.Query('TRUNCATE TABLE ' + FConnection.QuotedDbAndTableName(comboDatabase.Text, comboTable.Text)); FConnection.Query('TRUNCATE TABLE ' + FConnection.QuotedDbAndTableName(comboDatabase.Text, comboTable.Text));
FConnection.ShowWarnings;
except except
try try
FConnection.Query('DELETE FROM ' + FConnection.QuotedDbAndTableName(comboDatabase.Text, comboTable.Text)); FConnection.Query('DELETE FROM ' + FConnection.QuotedDbAndTableName(comboDatabase.Text, comboTable.Text));
FConnection.ShowWarnings;
except except
on E:EDbError do on E:EDbError do
ErrorDialog(_('Cannot truncate table'), E.Message); ErrorDialog(_('Cannot truncate table'), E.Message);
@ -335,20 +336,8 @@ begin
1: ClientParse(Sender); 1: ClientParse(Sender);
end; end;
MainForm.LogSQL(FormatNumber(FRowCount)+' rows imported in '+FormatNumber((GetTickcount-StartTickCount)/1000, 3)+' seconds.'); MainForm.LogSQL(FormatNumber(FRowCount)+' rows imported in '+FormatNumber((GetTickcount-StartTickCount)/1000, 3)+' seconds.');
// SHOW WARNINGS is implemented as of MySQL 4.1.0
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);
Warnings.Next;
end;
if Warnings.RecordCount > 0 then begin
ErrorDialog(f_('Your file was imported but the server returned %s warnings and/or notes. See the log panel for details.', [FormatNumber(Warnings.RecordCount)]));
ModalResult := mrNone;
end;
end;
// Hint user if zero rows were detected in file // Hint user if zero rows were detected in file
if (ModalResult <> mrNone) and (FRowCount = 0) then begin if FRowCount = 0 then begin
ErrorDialog(_('No rows were imported'), ErrorDialog(_('No rows were imported'),
_('This can have several causes:')+CRLF+ _('This can have several causes:')+CRLF+
_(' - File is empty')+CRLF+ _(' - File is empty')+CRLF+
@ -450,6 +439,7 @@ begin
FConnection.Query(SQL); FConnection.Query(SQL);
FConnection.ShowWarnings;
FRowCount := Max(FConnection.RowsAffected, 0); FRowCount := Max(FConnection.RowsAffected, 0);
end; end;
@ -571,6 +561,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);
FConnection.ShowWarnings;
SQL := ''; SQL := '';
RowCountInChunk := 0; RowCountInChunk := 0;
end; end;