Add "SQL DELETEs/INSERTs" to grid export formats. See http://www.heidisql.com/forum.php?t=20929

This commit is contained in:
Ansgar Becker
2016-04-03 09:45:04 +00:00
parent ecdce66677
commit 347ed4880e
2 changed files with 17 additions and 11 deletions

View File

@ -573,7 +573,6 @@ type
procedure SetDBObject(Value: TDBObject);
procedure CreateUpdateRow;
function GetKeyColumns: TStringList;
function GetWhereClause: String;
function GridQuery(QueryType, QueryBody: String): String;
public
constructor Create(AOwner: TComponent); override;
@ -599,6 +598,7 @@ type
function IsNull(Column: String): Boolean; overload;
function IsFunction(Column: Integer): Boolean;
function HasResult: Boolean; virtual; abstract;
function GetWhereClause: String;
procedure CheckEditable;
procedure DeleteRow;
function InsertRow: Int64;
@ -6688,6 +6688,7 @@ var
begin
// Compose WHERE clause including values from best key for editing
NeededCols := GetKeyColumns;
Result := '';
for i:=0 to NeededCols.Count-1 do begin
j := FColumnOrgNames.IndexOf(NeededCols[i]);

View File

@ -7,7 +7,7 @@ uses
Dialogs, StdCtrls, ExtCtrls, Menus, ComCtrls, VirtualTrees, SynExportHTML, gnugettext;
type
TGridExportFormat = (efExcel, efCSV, efHTML, efXML, efSQLInsert, efSQLReplace, efLaTeX, efWiki, efPHPArray, efMarkDown, efJSON);
TGridExportFormat = (efExcel, efCSV, efHTML, efXML, efSQLInsert, efSQLReplace, efSQLDeleteInsert, efLaTeX, efWiki, efPHPArray, efMarkDown, efJSON);
TfrmExportGrid = class(TForm)
btnOK: TButton;
@ -69,9 +69,9 @@ type
FGrid: TVirtualStringTree;
FRecentFiles: TStringList;
const FFormatToFileExtension: Array[TGridExportFormat] of String =
(('csv'), ('csv'), ('html'), ('xml'), ('sql'), ('sql'), ('LaTeX'), ('wiki'), ('php'), ('md'), ('json'));
(('csv'), ('csv'), ('html'), ('xml'), ('sql'), ('sql'), ('sql'), ('LaTeX'), ('wiki'), ('php'), ('md'), ('json'));
const FFormatToDescription: Array[TGridExportFormat] of String =
(('Excel CSV'), ('Delimited text'), ('HTML table'), ('XML'), ('SQL INSERTs'), ('SQL REPLACEs'), ('LaTeX'), ('Wiki markup'), ('PHP Array'), ('Markdown Here'), ('JSON'));
(('Excel CSV'), ('Delimited text'), ('HTML table'), ('XML'), ('SQL INSERTs'), ('SQL REPLACEs'), ('SQL DELETEs/INSERTs'), ('LaTeX'), ('Wiki markup'), ('PHP Array'), ('Markdown Here'), ('JSON'));
procedure SaveDialogTypeChange(Sender: TObject);
function GetExportFormat: TGridExportFormat;
procedure SetExportFormat(Value: TGridExportFormat);
@ -710,11 +710,16 @@ begin
efXML: tmp := #9'<row>' + CRLF;
efSQLInsert, efSQLReplace: begin
if ExportFormat = efSQLInsert then
tmp := 'INSERT'
efSQLInsert, efSQLReplace, efSQLDeleteInsert: begin
tmp := '';
if ExportFormat = efSQLDeleteInsert then begin
tmp := tmp + 'DELETE FROM ' + GridData.Connection.QuoteIdent(Tablename) + ' WHERE' + GridData.GetWhereClause + ';' + CRLF;
end;
if ExportFormat in [efSQLInsert, efSQLDeleteInsert] then
tmp := tmp + 'INSERT'
else
tmp := 'REPLACE';
tmp := tmp + 'REPLACE';
tmp := tmp + ' INTO '+GridData.Connection.QuoteIdent(Tablename);
if chkIncludeColumnNames.Checked then begin
tmp := tmp + ' (';
@ -789,7 +794,7 @@ begin
end;
end;
efSQLInsert, efSQLReplace: begin
efSQLInsert, efSQLReplace, efSQLDeleteInsert: begin
if GridData.IsNull(Col) then
Data := 'NULL'
else if GridData.DataType(Col).Index = dtBit then
@ -857,7 +862,7 @@ begin
end;
efXML:
tmp := tmp + #9'</row>' + CRLF;
efSQLInsert, efSQLReplace: begin
efSQLInsert, efSQLReplace, efSQLDeleteInsert: begin
Delete(tmp, Length(tmp)-1, 2);
tmp := tmp + ');' + CRLF;
end;
@ -918,7 +923,7 @@ begin
// SynEdit's exporter is slow on large strings, see issue #2903
if S.Size < 100*SIZE_KB then begin
case ExportFormat of
efSQLInsert, efSQLReplace: begin
efSQLInsert, efSQLReplace, efSQLDeleteInsert: begin
Exporter := TSynExporterHTML.Create(Self);
Exporter.Highlighter := MainForm.SynSQLSyn1;
Exporter.ExportAll(Explode(CRLF, S.DataString));