mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-14 01:56:36 +08:00
Create new grid export format: SQL UPDATEs. Closes #125.
This commit is contained in:
@ -8,7 +8,7 @@ uses
|
|||||||
extra_controls, dbstructures, SynRegExpr;
|
extra_controls, dbstructures, SynRegExpr;
|
||||||
|
|
||||||
type
|
type
|
||||||
TGridExportFormat = (efExcel, efCSV, efHTML, efXML, efSQLInsert, efSQLReplace, efSQLDeleteInsert, efLaTeX, efWiki, efPHPArray, efMarkDown, efJSON);
|
TGridExportFormat = (efExcel, efCSV, efHTML, efXML, efSQLInsert, efSQLReplace, efSQLDeleteInsert, efSQLUpdate, efLaTeX, efWiki, efPHPArray, efMarkDown, efJSON);
|
||||||
|
|
||||||
TfrmExportGrid = class(TExtForm)
|
TfrmExportGrid = class(TExtForm)
|
||||||
btnOK: TButton;
|
btnOK: TButton;
|
||||||
@ -85,11 +85,11 @@ type
|
|||||||
public
|
public
|
||||||
{ Public declarations }
|
{ Public declarations }
|
||||||
const FormatToFileExtension: Array[TGridExportFormat] of String =
|
const FormatToFileExtension: Array[TGridExportFormat] of String =
|
||||||
(('csv'), ('csv'), ('html'), ('xml'), ('sql'), ('sql'), ('sql'), ('LaTeX'), ('wiki'), ('php'), ('md'), ('json'));
|
(('csv'), ('csv'), ('html'), ('xml'), ('sql'), ('sql'), ('sql'), ('sql'), ('LaTeX'), ('wiki'), ('php'), ('md'), ('json'));
|
||||||
const FormatToDescription: Array[TGridExportFormat] of String =
|
const FormatToDescription: Array[TGridExportFormat] of String =
|
||||||
(('Excel CSV'), ('Delimited text'), ('HTML table'), ('XML'), ('SQL INSERTs'), ('SQL REPLACEs'), ('SQL DELETEs/INSERTs'), ('LaTeX'), ('Wiki markup'), ('PHP Array'), ('Markdown Here'), ('JSON'));
|
(('Excel CSV'), ('Delimited text'), ('HTML table'), ('XML'), ('SQL INSERTs'), ('SQL REPLACEs'), ('SQL DELETEs/INSERTs'), ('SQL UPDATEs'), ('LaTeX'), ('Wiki markup'), ('PHP Array'), ('Markdown Here'), ('JSON'));
|
||||||
const FormatToImageIndex: Array[TGridExportFormat] of Integer =
|
const FormatToImageIndex: Array[TGridExportFormat] of Integer =
|
||||||
(49, 50, 32, 48, 201, 201, 201, 153, 154, 202, 199, 200);
|
(49, 50, 32, 48, 201, 201, 201, 201, 153, 154, 202, 199, 200);
|
||||||
const CopyAsActionPrefix = 'actCopyAs';
|
const CopyAsActionPrefix = 'actCopyAs';
|
||||||
property Grid: TVirtualStringTree read FGrid write FGrid;
|
property Grid: TVirtualStringTree read FGrid write FGrid;
|
||||||
property ExportFormat: TGridExportFormat read GetExportFormat write SetExportFormat;
|
property ExportFormat: TGridExportFormat read GetExportFormat write SetExportFormat;
|
||||||
@ -811,6 +811,11 @@ begin
|
|||||||
|
|
||||||
efXML: tmp := #9'<row>' + CRLF;
|
efXML: tmp := #9'<row>' + CRLF;
|
||||||
|
|
||||||
|
efSQLUpdate: begin
|
||||||
|
tmp := '';
|
||||||
|
tmp := tmp + 'UPDATE ' + GridData.Connection.QuoteIdent(Tablename) + ' SET ';
|
||||||
|
end;
|
||||||
|
|
||||||
efSQLInsert, efSQLReplace, efSQLDeleteInsert: begin
|
efSQLInsert, efSQLReplace, efSQLDeleteInsert: begin
|
||||||
tmp := '';
|
tmp := '';
|
||||||
if ExportFormat = efSQLDeleteInsert then begin
|
if ExportFormat = efSQLDeleteInsert then begin
|
||||||
@ -925,7 +930,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
efSQLInsert, efSQLReplace, efSQLDeleteInsert: begin
|
efSQLInsert, efSQLReplace, efSQLDeleteInsert, efSQLUpdate: begin
|
||||||
if GridData.ColIsVirtual(Col) then
|
if GridData.ColIsVirtual(Col) then
|
||||||
Data := ''
|
Data := ''
|
||||||
else if GridData.IsNull(Col) then
|
else if GridData.IsNull(Col) then
|
||||||
@ -938,8 +943,11 @@ begin
|
|||||||
Data := GridData.Connection.EscapeString(Data)
|
Data := GridData.Connection.EscapeString(Data)
|
||||||
else if Data = '' then
|
else if Data = '' then
|
||||||
Data := GridData.Connection.EscapeString(Data);
|
Data := GridData.Connection.EscapeString(Data);
|
||||||
if not Data.IsEmpty then
|
if not Data.IsEmpty then begin
|
||||||
|
if ExportFormat = efSQLUpdate then
|
||||||
|
tmp := tmp + GridData.Connection.QuoteIdent(Grid.Header.Columns[Col].Text) + '=';
|
||||||
tmp := tmp + Data + ', ';
|
tmp := tmp + Data + ', ';
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
efPHPArray: begin
|
efPHPArray: begin
|
||||||
@ -998,6 +1006,10 @@ begin
|
|||||||
Delete(tmp, Length(tmp)-1, 2);
|
Delete(tmp, Length(tmp)-1, 2);
|
||||||
tmp := tmp + ');' + CRLF;
|
tmp := tmp + ');' + CRLF;
|
||||||
end;
|
end;
|
||||||
|
efSQLUpdate : begin
|
||||||
|
Delete(tmp, length(tmp)-1,2);
|
||||||
|
tmp := tmp + ' WHERE' + GridData.GetWhereClause + ';' + sLineBreak;
|
||||||
|
end;
|
||||||
efPHPArray:
|
efPHPArray:
|
||||||
tmp := tmp + #9 + '),' + CRLF;
|
tmp := tmp + #9 + '),' + CRLF;
|
||||||
efMarkDown:
|
efMarkDown:
|
||||||
|
Reference in New Issue
Block a user