mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Add "SQL DELETEs/INSERTs" to grid export formats. See http://www.heidisql.com/forum.php?t=20929
This commit is contained in:
@ -573,7 +573,6 @@ type
|
|||||||
procedure SetDBObject(Value: TDBObject);
|
procedure SetDBObject(Value: TDBObject);
|
||||||
procedure CreateUpdateRow;
|
procedure CreateUpdateRow;
|
||||||
function GetKeyColumns: TStringList;
|
function GetKeyColumns: TStringList;
|
||||||
function GetWhereClause: String;
|
|
||||||
function GridQuery(QueryType, QueryBody: String): String;
|
function GridQuery(QueryType, QueryBody: String): String;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
@ -599,6 +598,7 @@ type
|
|||||||
function IsNull(Column: String): Boolean; overload;
|
function IsNull(Column: String): Boolean; overload;
|
||||||
function IsFunction(Column: Integer): Boolean;
|
function IsFunction(Column: Integer): Boolean;
|
||||||
function HasResult: Boolean; virtual; abstract;
|
function HasResult: Boolean; virtual; abstract;
|
||||||
|
function GetWhereClause: String;
|
||||||
procedure CheckEditable;
|
procedure CheckEditable;
|
||||||
procedure DeleteRow;
|
procedure DeleteRow;
|
||||||
function InsertRow: Int64;
|
function InsertRow: Int64;
|
||||||
@ -6688,6 +6688,7 @@ var
|
|||||||
begin
|
begin
|
||||||
// Compose WHERE clause including values from best key for editing
|
// Compose WHERE clause including values from best key for editing
|
||||||
NeededCols := GetKeyColumns;
|
NeededCols := GetKeyColumns;
|
||||||
|
Result := '';
|
||||||
|
|
||||||
for i:=0 to NeededCols.Count-1 do begin
|
for i:=0 to NeededCols.Count-1 do begin
|
||||||
j := FColumnOrgNames.IndexOf(NeededCols[i]);
|
j := FColumnOrgNames.IndexOf(NeededCols[i]);
|
||||||
|
@ -7,7 +7,7 @@ uses
|
|||||||
Dialogs, StdCtrls, ExtCtrls, Menus, ComCtrls, VirtualTrees, SynExportHTML, gnugettext;
|
Dialogs, StdCtrls, ExtCtrls, Menus, ComCtrls, VirtualTrees, SynExportHTML, gnugettext;
|
||||||
|
|
||||||
type
|
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)
|
TfrmExportGrid = class(TForm)
|
||||||
btnOK: TButton;
|
btnOK: TButton;
|
||||||
@ -69,9 +69,9 @@ type
|
|||||||
FGrid: TVirtualStringTree;
|
FGrid: TVirtualStringTree;
|
||||||
FRecentFiles: TStringList;
|
FRecentFiles: TStringList;
|
||||||
const FFormatToFileExtension: Array[TGridExportFormat] of String =
|
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 =
|
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);
|
procedure SaveDialogTypeChange(Sender: TObject);
|
||||||
function GetExportFormat: TGridExportFormat;
|
function GetExportFormat: TGridExportFormat;
|
||||||
procedure SetExportFormat(Value: TGridExportFormat);
|
procedure SetExportFormat(Value: TGridExportFormat);
|
||||||
@ -710,11 +710,16 @@ begin
|
|||||||
|
|
||||||
efXML: tmp := #9'<row>' + CRLF;
|
efXML: tmp := #9'<row>' + CRLF;
|
||||||
|
|
||||||
efSQLInsert, efSQLReplace: begin
|
efSQLInsert, efSQLReplace, efSQLDeleteInsert: begin
|
||||||
if ExportFormat = efSQLInsert then
|
tmp := '';
|
||||||
tmp := 'INSERT'
|
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
|
else
|
||||||
tmp := 'REPLACE';
|
tmp := tmp + 'REPLACE';
|
||||||
tmp := tmp + ' INTO '+GridData.Connection.QuoteIdent(Tablename);
|
tmp := tmp + ' INTO '+GridData.Connection.QuoteIdent(Tablename);
|
||||||
if chkIncludeColumnNames.Checked then begin
|
if chkIncludeColumnNames.Checked then begin
|
||||||
tmp := tmp + ' (';
|
tmp := tmp + ' (';
|
||||||
@ -789,7 +794,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
efSQLInsert, efSQLReplace: begin
|
efSQLInsert, efSQLReplace, efSQLDeleteInsert: begin
|
||||||
if GridData.IsNull(Col) then
|
if GridData.IsNull(Col) then
|
||||||
Data := 'NULL'
|
Data := 'NULL'
|
||||||
else if GridData.DataType(Col).Index = dtBit then
|
else if GridData.DataType(Col).Index = dtBit then
|
||||||
@ -857,7 +862,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
efXML:
|
efXML:
|
||||||
tmp := tmp + #9'</row>' + CRLF;
|
tmp := tmp + #9'</row>' + CRLF;
|
||||||
efSQLInsert, efSQLReplace: begin
|
efSQLInsert, efSQLReplace, efSQLDeleteInsert: begin
|
||||||
Delete(tmp, Length(tmp)-1, 2);
|
Delete(tmp, Length(tmp)-1, 2);
|
||||||
tmp := tmp + ');' + CRLF;
|
tmp := tmp + ');' + CRLF;
|
||||||
end;
|
end;
|
||||||
@ -918,7 +923,7 @@ begin
|
|||||||
// SynEdit's exporter is slow on large strings, see issue #2903
|
// SynEdit's exporter is slow on large strings, see issue #2903
|
||||||
if S.Size < 100*SIZE_KB then begin
|
if S.Size < 100*SIZE_KB then begin
|
||||||
case ExportFormat of
|
case ExportFormat of
|
||||||
efSQLInsert, efSQLReplace: begin
|
efSQLInsert, efSQLReplace, efSQLDeleteInsert: begin
|
||||||
Exporter := TSynExporterHTML.Create(Self);
|
Exporter := TSynExporterHTML.Create(Self);
|
||||||
Exporter.Highlighter := MainForm.SynSQLSyn1;
|
Exporter.Highlighter := MainForm.SynSQLSyn1;
|
||||||
Exporter.ExportAll(Explode(CRLF, S.DataString));
|
Exporter.ExportAll(Explode(CRLF, S.DataString));
|
||||||
|
Reference in New Issue
Block a user