Add a button which, when clicked, will change the SQL sentence terminator from ';' to '//'. Would have preferred a dropdown with ';', '//' and a user-editable field, but apparently I don't master the Delphi IDE on a high enough level to accomplish such a feat. Black belts to everyone who can make that work ;).

This commit is contained in:
rosenfield
2007-06-28 02:17:57 +00:00
parent 05c867ae60
commit a34d989ca1
3 changed files with 29 additions and 10 deletions

View File

@@ -780,9 +780,9 @@ object MDIChild: TMDIChild
ParentFont = False
TabOrder = 0
object Panel8: TPanel
Left = 296
Left = 272
Top = 1
Width = 199
Width = 223
Height = 27
Align = alRight
BevelOuter = bvNone
@@ -791,7 +791,7 @@ object MDIChild: TMDIChild
object ToolBarQuery: TToolBar
Left = 1
Top = 1
Width = 197
Width = 221
Height = 25
Align = alClient
ButtonHeight = 25
@@ -870,10 +870,18 @@ object MDIChild: TMDIChild
Style = tbsCheck
OnClick = btnQueryStopOnErrorsClick
end
object btnAltTerminator: TToolButton
Left = 197
Top = 0
Hint = 'Use alternate '#39'//'#39' SQL sentence terminator'
Caption = 'btnAltTerminator'
ImageIndex = 54
Style = tbsCheck
end
end
end
object PanelCharsInQueryWindow: TPanel
Left = 180
Left = 156
Top = 1
Width = 116
Height = 27

View File

@@ -266,6 +266,7 @@ type
N21: TMenuItem;
btnUnsafeEdit: TToolButton;
btnColumnSelection: TSpeedButton;
btnAltTerminator: TToolButton;
procedure DataSourceUpdateData(Sender: TObject);
procedure btnTableViewDataClick(Sender: TObject);
procedure btnDbViewDataClick(Sender: TObject);
@@ -2602,16 +2603,19 @@ var
SQLTime : Double;
fieldcount, recordcount : Integer;
ds : TDataSet;
term : String;
begin
if btnAltTerminator.Down then term := '//' else term := ';';
if CurrentLine then begin
// Run current line
SQL := parseSQL(SynMemoQuery.LineText);
SQL := parseSQL(SynMemoQuery.LineText, term);
end else if Selection then begin
// Run selection
SQL := parsesql(SynMemoQuery.SelText);
SQL := parsesql(SynMemoQuery.SelText, term);
end else begin
// Run all
SQL := parsesql(SynMemoQuery.Text);
SQL := parsesql(SynMemoQuery.Text, term);
end;
if SQL.Count = 0 then begin

View File

@@ -21,7 +21,7 @@ uses Classes, SysUtils, Graphics, db, clipbrd, dialogs,
function strpos(haystack, needle: String; offset: Integer=0) : Integer;
procedure ensureValidIdentifier(name: String);
function getEnumValues(str: String):String;
function parsesql(sql: String) : TStringList;
function parsesql(sql: String; term: String) : TStringList;
function sstr(str: String; len: Integer) : String;
function notinlist(str: String; strlist: TStrings): Boolean;
function inarray(str: String; a: Array of String): Boolean;
@@ -338,12 +338,13 @@ end;
@param string (possibly large) bunch of SQL-statements, separated by semicolon
@return TStringList Separated statements
}
function parsesql(sql: String) : TStringList;
function parsesql(sql: String; term: String) : TStringList;
var
i, start : Integer;
instring, backslash, incomment : Boolean;
inconditional, condterminated : Boolean;
inbigcomment : Boolean;
longterm : Boolean;
encloser, secchar, thdchar : Char;
begin
result := TStringList.Create;
@@ -355,6 +356,7 @@ begin
inbigcomment := false;
inconditional := false;
condterminated := false;
longterm := Length(term) > 1;
encloser := ' ';
i := 0;
@@ -436,7 +438,7 @@ begin
if (sql[i] = '\') or backslash then
backslash := not backslash;
if (sql[i] = ';') and (not instring) then begin
if (not instring) and ((sql[i] = term) or (sql[i] + secchar = term)) then begin
if inconditional then
begin
// note:
@@ -444,8 +446,13 @@ begin
// inside each /*!nnnnn blah */ conditional comment.
condterminated := true;
sql[i] := ' ';
if longterm then begin
i := i + 1;
sql[i] := ' ';
end;
end else begin
addResult(result, copy(sql, start, i-start));
if longterm then i := i + 1;
start := i+1;
end;
end;