31 |
|
|
32 |
|
interface |
33 |
|
|
34 |
< |
uses Classes, IBDatabase, IBSQL, IB, IBDataOutput; |
35 |
< |
|
36 |
< |
const |
37 |
< |
ibx_blob = 'IBX_BLOB'; |
38 |
< |
ibx_array = 'IBX_ARRAY'; |
39 |
< |
|
40 |
< |
BlobLineLength = 40; |
41 |
< |
|
42 |
< |
DefaultTerminator = ';'; |
43 |
< |
|
44 |
< |
{Non-character symbols} |
45 |
< |
sqNone = #0; |
46 |
< |
sqEnd = #1; |
47 |
< |
sqBegin = #2; |
48 |
< |
sqString = #3; |
49 |
< |
sqComment = #4; |
50 |
< |
sqCase = #5; |
51 |
< |
sqDeclare = #6; |
52 |
< |
sqCommentLine = #7; |
53 |
< |
sqEOL = #8; |
54 |
< |
sqTab = #9; |
55 |
< |
sqTerminator = #10; |
56 |
< |
sqEOF = #11; |
57 |
< |
sqTag = #12; |
58 |
< |
sqEndTag = #13; |
59 |
< |
sqQuotedString = #14; |
60 |
< |
sqDoubleQuotedString = #15; |
34 |
> |
uses Classes, IBDatabase, IBSQL, IB, IBDataOutput, IBUtils; |
35 |
|
|
36 |
|
type |
63 |
– |
TSQLSymbol = char; |
64 |
– |
|
65 |
– |
TSQLStates = (stInit, stError, stInSQL, stNested, stInDeclaration); |
66 |
– |
|
67 |
– |
TXMLStates = (stInTag,stAttribute,stAttributeValue,stQuotedAttributeValue, |
68 |
– |
stTagged,stEndTag); |
69 |
– |
|
70 |
– |
TXMLTag = (xtNone,xtBlob,xtArray,xtElt); |
37 |
|
|
38 |
|
TOnNextLine = procedure(Sender: TObject; Line: string) of object; |
39 |
|
TOnProgressEvent = procedure (Sender: TObject; Reset: boolean; value: integer) of object; |
40 |
|
|
41 |
< |
TXMLTagDef = record |
76 |
< |
XMLTag: TXMLTag; |
77 |
< |
TagValue: string; |
78 |
< |
end; |
79 |
< |
|
80 |
< |
const |
81 |
< |
XMLTagDefs: array [0..2] of TXMLTagDef = ( |
82 |
< |
(XMLTag: xtBlob; TagValue: 'blob'), |
83 |
< |
(XMLTag: xtArray; TagValue: 'array'), |
84 |
< |
(XMLTag: xtElt; TagValue: 'elt') |
85 |
< |
); |
41 |
> |
{ TSQLXMLReader } |
42 |
|
|
43 |
< |
type |
43 |
> |
TSQLXMLReader = class(TSQLTokeniser) |
44 |
> |
private |
45 |
> |
type |
46 |
> |
TXMLStates = (stNoXML, stInTag,stInTagBody, |
47 |
> |
stAttribute,stAttributeValue,stQuotedAttributeValue, |
48 |
> |
stInEndTag, stInEndTagBody, |
49 |
> |
stXMLData); |
50 |
> |
|
51 |
> |
TXMLTag = (xtNone,xtBlob,xtArray,xtElt); |
52 |
> |
|
53 |
> |
TXMLTagDef = record |
54 |
> |
XMLTag: TXMLTag; |
55 |
> |
TagValue: string; |
56 |
> |
end; |
57 |
> |
|
58 |
> |
const |
59 |
> |
XMLTagDefs: array [xtBlob..xtElt] of TXMLTagDef = ( |
60 |
> |
(XMLTag: xtBlob; TagValue: 'blob'), |
61 |
> |
(XMLTag: xtArray; TagValue: 'array'), |
62 |
> |
(XMLTag: xtElt; TagValue: 'elt') |
63 |
> |
); |
64 |
> |
MaxXMLTags = 20; |
65 |
> |
BlobLineLength = 40; |
66 |
|
|
67 |
< |
{ TSymbolStream } |
67 |
> |
public |
68 |
> |
const |
69 |
> |
ibx_blob = 'IBX_BLOB'; |
70 |
> |
ibx_array = 'IBX_ARRAY'; |
71 |
> |
|
72 |
> |
type |
73 |
> |
TBlobData = record |
74 |
> |
BlobIntf: IBlob; |
75 |
> |
SubType: cardinal; |
76 |
> |
end; |
77 |
> |
|
78 |
> |
TArrayData = record |
79 |
> |
ArrayIntf: IArray; |
80 |
> |
SQLType: cardinal; |
81 |
> |
relationName: string; |
82 |
> |
columnName: string; |
83 |
> |
dim: cardinal; |
84 |
> |
Size: cardinal; |
85 |
> |
Scale: integer; |
86 |
> |
CharSet: string; |
87 |
> |
bounds: TArrayBounds; |
88 |
> |
CurrentRow: integer; |
89 |
> |
Index: array of integer; |
90 |
> |
end; |
91 |
> |
|
92 |
> |
private |
93 |
> |
FDatabase: TIBDatabase; |
94 |
> |
FOnProgressEvent: TOnProgressEvent; |
95 |
> |
FTransaction: TIBTransaction; |
96 |
> |
FXMLState: TXMLStates; |
97 |
> |
FXMLTagStack: array [1..MaxXMLTags] of TXMLTag; |
98 |
> |
FXMLTagIndex: integer; |
99 |
> |
FAttributeName: string; |
100 |
> |
FXMLData: string; |
101 |
> |
FBlobData: array of TBlobData; |
102 |
> |
FCurrentBlob: integer; |
103 |
> |
FBlobBuffer: PChar; |
104 |
> |
FArrayData: array of TArrayData; |
105 |
> |
FCurrentArray: integer; |
106 |
> |
FXMLString: string; |
107 |
> |
function FindTag(tag: string; var xmlTag: TXMLTag): boolean; |
108 |
> |
function GetArrayData(index: integer): TArrayData; |
109 |
> |
function GetArrayDataCount: integer; |
110 |
> |
function GetBlobData(index: integer): TBlobData; |
111 |
> |
function GetBlobDataCount: integer; |
112 |
> |
function GetTagName(xmltag: TXMLTag): string; |
113 |
> |
procedure ProcessAttributeValue(attrValue: string); |
114 |
> |
procedure ProcessBoundsList(boundsList: string); |
115 |
> |
procedure ProcessTagValue(tagValue: string); |
116 |
> |
procedure XMLTagInit(xmltag: TXMLTag); |
117 |
> |
function XMLTagEnd(var xmltag: TXMLTag): boolean; |
118 |
> |
procedure XMLTagEnter; |
119 |
> |
protected |
120 |
> |
function GetErrorPrefix: string; virtual; abstract; |
121 |
> |
function TokenFound(var token: TSQLTokens): boolean; override; |
122 |
> |
procedure Reset; override; |
123 |
> |
procedure ShowError(msg: string; params: array of const); virtual; overload; |
124 |
> |
procedure ShowError(msg: string); overload; |
125 |
> |
public |
126 |
> |
constructor Create; |
127 |
> |
procedure FreeDataObjects; |
128 |
> |
class function FormatBlob(Field: ISQLData): string; |
129 |
> |
class function FormatArray(Database: TIBDatabase; ar: IArray): string; |
130 |
> |
property BlobData[index: integer]: TBlobData read GetBlobData; |
131 |
> |
property BlobDataCount: integer read GetBlobDataCount; |
132 |
> |
property ArrayData[index: integer]: TArrayData read GetArrayData; |
133 |
> |
property ArrayDataCount: integer read GetArrayDataCount; |
134 |
> |
property Database: TIBDatabase read FDatabase write FDatabase; |
135 |
> |
property Transaction: TIBTransaction read FTransaction write FTransaction; |
136 |
> |
property OnProgressEvent: TOnProgressEvent read FOnProgressEvent write FOnProgressEvent; {Progress Bar Support} |
137 |
> |
end; |
138 |
|
|
139 |
< |
{A simple lookahead one parser to process a text stream as a stream of symbols. |
92 |
< |
This is an abstract object, subclassed for different sources.} |
139 |
> |
{ TSQLStatementReader } |
140 |
|
|
141 |
< |
TSymbolStream = class |
141 |
> |
TSQLStatementReader = class(TSQLXMLReader) |
142 |
|
private |
143 |
< |
FNextSymbol: TSQLSymbol; |
143 |
> |
type |
144 |
> |
TSQLState = (stDefault, stInStmt, stInBlock, stInArrayDim, stInDeclare); |
145 |
> |
private |
146 |
> |
FHasBegin: boolean; |
147 |
|
FOnNextLine: TOnNextLine; |
98 |
– |
FOnProgressEvent: TOnProgressEvent; |
148 |
|
FTerminator: char; |
100 |
– |
FLastChar: char; |
101 |
– |
FIndex: integer; |
102 |
– |
FLine: string; |
103 |
– |
FString: string; |
104 |
– |
FXMLTag: TXMLTag; |
105 |
– |
FXMLMode: integer; |
149 |
|
protected |
150 |
< |
FNextStatement: boolean; |
108 |
< |
function GetErrorPrefix: string; virtual; abstract; |
109 |
< |
function GetNextSymbol(C: char): TSQLSymbol; |
110 |
< |
function FindTag(tag: string; var xmlTag: TXMLTag): boolean; |
111 |
< |
function GetNextLine(var Line: string):boolean; virtual; abstract; |
150 |
> |
procedure EchoNextLine(aLine: string); |
151 |
|
public |
152 |
|
constructor Create; |
153 |
< |
procedure ShowError(msg: string; params: array of const); |
154 |
< |
function GetSymbol: TSQLSymbol; virtual; |
155 |
< |
procedure NextStatement; |
117 |
< |
property SymbolValue: string read FString; |
118 |
< |
property Terminator: char read FTerminator write FTerminator; |
119 |
< |
property XMLTag: TXMLTag read FXMLTag; |
153 |
> |
function GetNextStatement(var stmt: string) : boolean; virtual; |
154 |
> |
property HasBegin: boolean read FHasBegin; |
155 |
> |
property Terminator: char read FTerminator write FTerminator default DefaultTerminator; |
156 |
|
property OnNextLine: TOnNextLine read FOnNextLine write FOnNextLine; |
121 |
– |
property OnProgressEvent: TOnProgressEvent read FOnProgressEvent write FOnProgressEvent; {Progress Bar Support} |
157 |
|
end; |
158 |
|
|
124 |
– |
{ TBatchSymbolStream } |
159 |
|
|
160 |
< |
{This symbol stream supports non-interactive parsing of a text file, stream or |
160 |
> |
{ TBatchSQLStatementReader } |
161 |
> |
|
162 |
> |
{This SQL Reader supports non-interactive parsing of a text file, stream or |
163 |
|
lines of text.} |
164 |
|
|
165 |
< |
TBatchSymbolStream = class(TSymbolStream) |
165 |
> |
TBatchSQLStatementReader = class(TSQLStatementReader) |
166 |
|
private |
167 |
< |
FLines: TStrings; |
167 |
> |
FInStream: TStream; |
168 |
> |
FOwnsInStream: boolean; |
169 |
|
FLineIndex: integer; |
170 |
+ |
FIndex: integer; |
171 |
+ |
FCurLine: string; |
172 |
|
protected |
173 |
+ |
function GetChar: char; override; |
174 |
|
function GetErrorPrefix: string; override; |
135 |
– |
function GetNextLine(var Line: string):boolean; override; |
175 |
|
public |
176 |
< |
constructor Create; |
138 |
< |
destructor Destroy; override; |
176 |
> |
procedure Reset; override; |
177 |
|
procedure SetStreamSource(Lines: TStrings); overload; |
178 |
|
procedure SetStreamSource(S: TStream); overload; |
179 |
|
procedure SetStreamSource(FileName: string); overload; |
180 |
+ |
procedure SetStringStreamSource(S: string); |
181 |
|
end; |
182 |
|
|
183 |
< |
{ TInteractiveSymbolStream } |
183 |
> |
{ TInteractiveSQLStatementReader } |
184 |
|
|
185 |
< |
{This symbol stream supports interactive parsing of commands and |
185 |
> |
{This SQL reader supports interactive parsing of commands and |
186 |
|
SQL statements entered at a console} |
187 |
|
|
188 |
< |
TInteractiveSymbolStream = class(TSymbolStream) |
188 |
> |
TInteractiveSQLStatementReader = class(TSQLStatementReader) |
189 |
|
private |
190 |
|
FPrompt: string; |
191 |
|
FContinuePrompt: string; |
192 |
|
FTerminated: boolean; |
193 |
+ |
FLine: string; |
194 |
+ |
FLineIndex: integer; |
195 |
+ |
FNextStatement: boolean; |
196 |
+ |
function GetNextLine(var Line: string):boolean; |
197 |
|
protected |
198 |
+ |
function GetChar: char; override; |
199 |
|
function GetErrorPrefix: string; override; |
156 |
– |
function GetNextLine(var Line: string):boolean; override; |
200 |
|
public |
201 |
|
constructor Create(aPrompt: string='SQL>'; aContinue: string = 'CON>'); |
202 |
< |
function GetSymbol: TSQLSymbol; override; |
202 |
> |
function GetNextStatement(var stmt: string) : boolean; override; |
203 |
|
property Terminated: boolean read FTerminated write FTerminated; |
204 |
|
end; |
205 |
|
|
163 |
– |
TBlobData = record |
164 |
– |
BlobIntf: IBlob; |
165 |
– |
SubType: cardinal; |
166 |
– |
end; |
167 |
– |
|
168 |
– |
TArrayData = record |
169 |
– |
ArrayIntf: IArray; |
170 |
– |
SQLType: cardinal; |
171 |
– |
relationName: string; |
172 |
– |
columnName: string; |
173 |
– |
dim: cardinal; |
174 |
– |
Size: cardinal; |
175 |
– |
Scale: integer; |
176 |
– |
CharSet: string; |
177 |
– |
bounds: TArrayBounds; |
178 |
– |
CurrentRow: integer; |
179 |
– |
Index: array of integer; |
180 |
– |
end; |
181 |
– |
|
182 |
– |
{ TIBXMLProcessor } |
183 |
– |
|
184 |
– |
{This is a simple XML parser that parses the output of a symbol stream as XML |
185 |
– |
structured data, recognising tags, attributes and data. The tags are given in |
186 |
– |
the table XMLTagDefs. The BlobData and ArrayData properties return blob and |
187 |
– |
array data decoded from the XML stream.} |
188 |
– |
|
189 |
– |
TIBXMLProcessor = class |
190 |
– |
private |
191 |
– |
FDatabase: TIBDatabase; |
192 |
– |
FSymbolStream: TSymbolStream; |
193 |
– |
FState: TXMLStates; |
194 |
– |
FTransaction: TIBTransaction; |
195 |
– |
FXMLTagStack: array [1..20] of TXMLTag; |
196 |
– |
FXMLTagIndex: integer; |
197 |
– |
FAttributeName: string; |
198 |
– |
FBlobData: array of TBlobData; |
199 |
– |
FCurrentBlob: integer; |
200 |
– |
FArrayData: array of TArrayData; |
201 |
– |
FCurrentArray: integer; |
202 |
– |
FBlobBuffer: PChar; |
203 |
– |
procedure EndXMLTag(xmltag: TXMLTag); |
204 |
– |
procedure EnterTag; |
205 |
– |
function GetArrayData(index: integer): TArrayData; |
206 |
– |
function GetArrayDataCount: integer; |
207 |
– |
function GetBlobData(index: integer): TBlobData; |
208 |
– |
function GetBlobDataCount: integer; |
209 |
– |
procedure ProcessTagValue(tagValue: string); |
210 |
– |
procedure StartXMLTag(xmltag: TXMLTag); |
211 |
– |
procedure ProcessAttributeValue(attrValue: string); |
212 |
– |
procedure ProcessBoundsList(boundsList: string); |
213 |
– |
public |
214 |
– |
constructor Create; |
215 |
– |
destructor Destroy; override; |
216 |
– |
function AnalyseXML(SymbolStream: TSymbolStream): string; |
217 |
– |
procedure NextStatement; |
218 |
– |
class function FormatBlob(Field: ISQLData): string; |
219 |
– |
class function FormatArray(Database: TIBDatabase; ar: IArray): string; |
220 |
– |
property BlobData[index: integer]: TBlobData read GetBlobData; |
221 |
– |
property BlobDataCount: integer read GetBlobDataCount; |
222 |
– |
property ArrayData[index: integer]: TArrayData read GetArrayData; |
223 |
– |
property ArrayDataCount: integer read GetArrayDataCount; |
224 |
– |
property Database: TIBDatabase read FDatabase write FDatabase; |
225 |
– |
property Transaction: TIBTransaction read FTransaction write FTransaction; |
226 |
– |
end; |
227 |
– |
|
228 |
– |
{ TIBSQLProcessor } |
229 |
– |
|
230 |
– |
{This parses a symbol stream into SQL statements. If embedded XML is found then |
231 |
– |
this is processed by the supplied XMLProcessor. The HasBegin property provides |
232 |
– |
a simple way to recognised stored procedure DDL, and "Execute As" statements.} |
233 |
– |
|
234 |
– |
TIBSQLProcessor = class |
235 |
– |
private |
236 |
– |
FSQLText: string; |
237 |
– |
FState: TSQLStates; |
238 |
– |
FStack: array [0..16] of TSQLStates; |
239 |
– |
FStackindex: integer; |
240 |
– |
FHasBegin: boolean; |
241 |
– |
FInCase: boolean; |
242 |
– |
FNested: integer; |
243 |
– |
FXMLProcessor: TIBXMLProcessor; |
244 |
– |
FSymbolStream: TSymbolStream; |
245 |
– |
procedure AddToSQL(const Symbol: string); |
246 |
– |
procedure SetState(AState: TSQLStates); |
247 |
– |
function PopState: TSQLStates; |
248 |
– |
public |
249 |
– |
constructor Create(XMLProcessor: TIBXMLProcessor); |
250 |
– |
function GetNextStatement(SymbolStream: TSymbolStream; var stmt: string) : boolean; |
251 |
– |
property HasBegin: boolean read FHasBegin; |
252 |
– |
end; |
253 |
– |
|
206 |
|
TGetParamValue = procedure(Sender: TObject; ParamName: string; var BlobID: TISC_QUAD) of object; |
207 |
|
TLogEvent = procedure(Sender: TObject; Msg: string) of Object; |
208 |
|
TOnSelectSQL = procedure (Sender: TObject; SQLText: string) of object; |
224 |
|
TCustomIBXScript = class(TComponent) |
225 |
|
private |
226 |
|
FEcho: boolean; |
227 |
< |
FIBXMLProcessor: TIBXMLProcessor; |
276 |
< |
FIBSQLProcessor: TIBSQLProcessor; |
227 |
> |
FSQLReader: TSQLStatementReader; |
228 |
|
FDatabase: TIBDatabase; |
229 |
|
FDataOutputFormatter: TIBCustomDataOutput; |
230 |
|
FIgnoreCreateDatabase: boolean; |
253 |
|
procedure SetShowPerformanceStats(AValue: boolean); |
254 |
|
procedure SetTransaction(AValue: TIBTransaction); |
255 |
|
protected |
305 |
– |
FSymbolStream: TSymbolStream; |
256 |
|
procedure Add2Log(const Msg: string; IsError: boolean=true); virtual; |
257 |
|
procedure ExecSQL(stmt: string); |
258 |
|
procedure EchoNextLine(Sender: TObject; Line: string); |
259 |
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override; |
260 |
|
function ProcessStatement(stmt: string): boolean; virtual; |
261 |
|
function ProcessStream: boolean; |
262 |
+ |
procedure SetSQLStatementReader(SQLStatementReader: TSQLStatementReader); |
263 |
|
public |
264 |
|
constructor Create(aOwner: TComponent); override; |
265 |
|
destructor Destroy; override; |
266 |
|
procedure DefaultSelectSQLHandler(aSQLText: string); |
267 |
+ |
property SQLStatementReader: TSQLStatementReader read FSQLReader; |
268 |
|
published |
269 |
|
property Database: TIBDatabase read FDatabase write SetDatabase; |
270 |
|
property DataOutputFormatter: TIBCustomDataOutput read FDataOutputFormatter |
383 |
|
uses Sysutils, RegExpr; |
384 |
|
|
385 |
|
resourcestring |
434 |
– |
sTerminatorUnknownState = 'Statement Terminator in unexpected state (%d)'; |
386 |
|
sNoSelectSQL = 'Select SQL Statements are not supported'; |
436 |
– |
sStackUnderflow = 'Stack Underflow'; |
387 |
|
sNoParamQueries = 'Parameterised Queries are not supported'; |
438 |
– |
sStackOverFlow = 'Stack Overflow'; |
388 |
|
sResolveQueryParam = 'Resolving Query Parameter: %s'; |
389 |
|
sXMLStackUnderflow = 'XML Stack Underflow'; |
390 |
|
sInvalidEndTag = 'XML End Tag Mismatch - %s'; |
391 |
+ |
sBadEndTagClosing = 'XML End Tag incorrectly closed'; |
392 |
|
sXMLStackOverFlow = 'XML Stack Overflow'; |
443 |
– |
sErrorState = 'Entered Error State'; |
444 |
– |
sXMLError = 'Invalid XML (%c)'; |
393 |
|
sXMLAttributeError = 'Unexpected attribute - "%s" = "%s"'; |
394 |
|
sInvalidBoundsList = 'Invalid array bounds list - "%s"'; |
395 |
|
sBinaryBlockMustbeEven = 'Binary block must have an even number of characters'; |
398 |
|
sArrayIndexError = 'Array Index Error (%d)'; |
399 |
|
sBlobIndexError = 'Blob Index Error (%d)'; |
400 |
|
sStatementError = 'Error processing SQL statement: %s %s - for statement "%s"'; |
401 |
+ |
sNotInArray = 'elt tag found but not in an XML array tag'; |
402 |
+ |
sNoDatabase = 'Missing database for xml tag import'; |
403 |
+ |
sNoTransaction = 'Missing transaction for xml tag import'; |
404 |
|
|
405 |
|
function StringToHex(octetString: string; MaxLineLength: integer): string; overload; |
406 |
|
|
442 |
|
TextOut.Add(StringToHex(octetString,MaxLineLength)); |
443 |
|
end; |
444 |
|
|
445 |
+ |
{ TSQLStatementReader } |
446 |
+ |
|
447 |
+ |
procedure TSQLStatementReader.EchoNextLine(aLine: string); |
448 |
+ |
begin |
449 |
+ |
if assigned(FOnNextLine) then |
450 |
+ |
OnNextLine(self,aLine); |
451 |
+ |
end; |
452 |
+ |
|
453 |
+ |
constructor TSQLStatementReader.Create; |
454 |
+ |
begin |
455 |
+ |
inherited Create; |
456 |
+ |
Terminator := DefaultTerminator; |
457 |
+ |
end; |
458 |
+ |
|
459 |
+ |
function TSQLStatementReader.GetNextStatement(var stmt: string): boolean; |
460 |
+ |
var State: TSQLState; |
461 |
+ |
Nested: integer; |
462 |
+ |
token: TSQLTokens; |
463 |
+ |
EndOfStatement: boolean; |
464 |
+ |
begin |
465 |
+ |
FHasBegin := false; |
466 |
+ |
Result := false; |
467 |
+ |
EndOfStatement := false; |
468 |
+ |
Nested := 0; |
469 |
+ |
stmt := ''; |
470 |
+ |
State := stDefault; |
471 |
+ |
while not EOF and not EndOfStatement do |
472 |
+ |
begin |
473 |
+ |
token := GetNextToken; |
474 |
+ |
// writeln(token,' ',TokenText,' ',Terminator); |
475 |
+ |
case State of |
476 |
+ |
stDefault: |
477 |
+ |
{ignore everything before a reserved word} |
478 |
+ |
if (token <= high(TSQLReservedWords)) or (token = sqltIdentifier) then |
479 |
+ |
begin |
480 |
+ |
State := stInStmt; |
481 |
+ |
stmt += TokenText; |
482 |
+ |
end; |
483 |
+ |
|
484 |
+ |
stInStmt: |
485 |
+ |
begin |
486 |
+ |
case token of |
487 |
+ |
sqltBegin: |
488 |
+ |
begin |
489 |
+ |
FHasBegin := true; |
490 |
+ |
State := stInBlock; |
491 |
+ |
Nested := 1; |
492 |
+ |
stmt += TokenText; |
493 |
+ |
end; |
494 |
+ |
|
495 |
+ |
sqltDeclare: |
496 |
+ |
begin |
497 |
+ |
State := stInDeclare; |
498 |
+ |
stmt += TokenText; |
499 |
+ |
end; |
500 |
+ |
|
501 |
+ |
sqltOpenSquareBracket: |
502 |
+ |
begin |
503 |
+ |
State := stInArrayDim; |
504 |
+ |
stmt += TokenText; |
505 |
+ |
end; |
506 |
+ |
|
507 |
+ |
sqltComment: |
508 |
+ |
stmt += '/*' + TokenText + '*/'; |
509 |
+ |
|
510 |
+ |
sqltCommentLine: |
511 |
+ |
stmt += '/*' + TokenText + ' */' + LineEnding; |
512 |
+ |
|
513 |
+ |
sqltQuotedString: |
514 |
+ |
stmt += '''' + SQLSafeString(TokenText) + ''''; |
515 |
+ |
|
516 |
+ |
sqltIdentifierInDoubleQuotes: |
517 |
+ |
stmt += '"' + TokenText + '"'; |
518 |
+ |
|
519 |
+ |
sqltCR: {ignore}; |
520 |
+ |
|
521 |
+ |
sqltEOL: |
522 |
+ |
stmt += LineEnding; |
523 |
+ |
|
524 |
+ |
else |
525 |
+ |
begin |
526 |
+ |
if (tokentext = Terminator) and (Nested = 0) then |
527 |
+ |
begin |
528 |
+ |
EndOfStatement := true; |
529 |
+ |
State := stDefault; |
530 |
+ |
end |
531 |
+ |
else |
532 |
+ |
stmt += TokenText; |
533 |
+ |
end; |
534 |
+ |
end; |
535 |
+ |
end; |
536 |
+ |
|
537 |
+ |
{ignore begin..end blocks for Terminator detection } |
538 |
+ |
|
539 |
+ |
stInBlock: |
540 |
+ |
begin |
541 |
+ |
case token of |
542 |
+ |
sqltBegin: |
543 |
+ |
begin |
544 |
+ |
Inc(Nested); |
545 |
+ |
stmt += TokenText; |
546 |
+ |
end; |
547 |
+ |
|
548 |
+ |
sqltEnd: |
549 |
+ |
begin |
550 |
+ |
Dec(Nested); |
551 |
+ |
stmt += TokenText; |
552 |
+ |
if Nested = 0 then |
553 |
+ |
begin |
554 |
+ |
State := stDefault; |
555 |
+ |
EndOfStatement := true; |
556 |
+ |
end; |
557 |
+ |
end; |
558 |
+ |
|
559 |
+ |
sqltComment: |
560 |
+ |
stmt += '/*' + TokenText + '*/'; |
561 |
+ |
|
562 |
+ |
sqltCommentLine: |
563 |
+ |
stmt += '/* ' + TokenText + ' */' + LineEnding; |
564 |
+ |
|
565 |
+ |
sqltQuotedString: |
566 |
+ |
stmt += '''' + SQLSafeString(TokenText) + ''''; |
567 |
+ |
|
568 |
+ |
sqltIdentifierInDoubleQuotes: |
569 |
+ |
stmt += '"' + TokenText + '"'; |
570 |
+ |
|
571 |
+ |
sqltCR: {ignore}; |
572 |
+ |
|
573 |
+ |
sqltEOL: |
574 |
+ |
stmt += LineEnding; |
575 |
+ |
|
576 |
+ |
else |
577 |
+ |
stmt += TokenText; |
578 |
+ |
end; |
579 |
+ |
end; |
580 |
+ |
|
581 |
+ |
{ignore array dimensions for Terminator detection } |
582 |
+ |
|
583 |
+ |
stInArrayDim: |
584 |
+ |
begin |
585 |
+ |
case token of |
586 |
+ |
|
587 |
+ |
sqltComment: |
588 |
+ |
stmt += '/*' + TokenText + '*/'; |
589 |
+ |
|
590 |
+ |
sqltCommentLine: |
591 |
+ |
stmt += '/* ' + TokenText + ' */' + LineEnding; |
592 |
+ |
|
593 |
+ |
sqltCloseSquareBracket: |
594 |
+ |
begin |
595 |
+ |
stmt += TokenText; |
596 |
+ |
State := stInStmt; |
597 |
+ |
end; |
598 |
+ |
|
599 |
+ |
sqltCR: {ignore}; |
600 |
+ |
|
601 |
+ |
sqltEOL: |
602 |
+ |
stmt += LineEnding; |
603 |
+ |
|
604 |
+ |
else |
605 |
+ |
stmt += TokenText; |
606 |
+ |
end; |
607 |
+ |
end; |
608 |
+ |
|
609 |
+ |
{ignore Declare statement for terminator - semi-colon terminates declaration} |
610 |
+ |
|
611 |
+ |
stInDeclare: |
612 |
+ |
begin |
613 |
+ |
case token of |
614 |
+ |
|
615 |
+ |
sqltComment: |
616 |
+ |
stmt += '/*' + TokenText + '*/'; |
617 |
+ |
|
618 |
+ |
sqltCommentLine: |
619 |
+ |
stmt += '/* ' + TokenText + ' */' + LineEnding; |
620 |
+ |
|
621 |
+ |
sqltSemiColon: |
622 |
+ |
begin |
623 |
+ |
State := stInStmt; |
624 |
+ |
stmt += TokenText; |
625 |
+ |
end; |
626 |
+ |
|
627 |
+ |
sqltCR: {ignore}; |
628 |
+ |
|
629 |
+ |
sqltEOL: |
630 |
+ |
stmt += LineEnding; |
631 |
+ |
|
632 |
+ |
else |
633 |
+ |
stmt += TokenText; |
634 |
+ |
end; |
635 |
+ |
end; |
636 |
+ |
end; |
637 |
+ |
end; |
638 |
+ |
Result := stmt <> ''; |
639 |
+ |
end; |
640 |
+ |
|
641 |
+ |
{ TSQLXMLReader } |
642 |
+ |
|
643 |
+ |
function TSQLXMLReader.FindTag(tag: string; var xmlTag: TXMLTag): boolean; |
644 |
+ |
var i: TXMLTag; |
645 |
+ |
begin |
646 |
+ |
Result := false; |
647 |
+ |
for i := xtBlob to xtElt do |
648 |
+ |
if XMLTagDefs[i].TagValue = tag then |
649 |
+ |
begin |
650 |
+ |
xmlTag := XMLTagDefs[i].XMLTag; |
651 |
+ |
Result := true; |
652 |
+ |
break; |
653 |
+ |
end; |
654 |
+ |
end; |
655 |
+ |
|
656 |
+ |
function TSQLXMLReader.GetArrayData(index: integer): TArrayData; |
657 |
+ |
begin |
658 |
+ |
if (index < 0) or (index > ArrayDataCount) then |
659 |
+ |
ShowError(sArrayIndexError,[index]); |
660 |
+ |
Result := FArrayData[index]; |
661 |
+ |
end; |
662 |
+ |
|
663 |
+ |
function TSQLXMLReader.GetArrayDataCount: integer; |
664 |
+ |
begin |
665 |
+ |
Result := Length(FArrayData); |
666 |
+ |
end; |
667 |
+ |
|
668 |
+ |
function TSQLXMLReader.GetBlobData(index: integer): TBlobData; |
669 |
+ |
begin |
670 |
+ |
if (index < 0) or (index > BlobDataCount) then |
671 |
+ |
ShowError(sBlobIndexError,[index]); |
672 |
+ |
Result := FBlobData[index]; |
673 |
+ |
end; |
674 |
+ |
|
675 |
+ |
function TSQLXMLReader.GetBlobDataCount: integer; |
676 |
+ |
begin |
677 |
+ |
Result := Length(FBlobData); |
678 |
+ |
end; |
679 |
+ |
|
680 |
+ |
function TSQLXMLReader.GetTagName(xmltag: TXMLTag): string; |
681 |
+ |
var i: TXMLTag; |
682 |
+ |
begin |
683 |
+ |
Result := 'unknown'; |
684 |
+ |
for i := xtBlob to xtElt do |
685 |
+ |
if XMLTagDefs[i].XMLTag = xmltag then |
686 |
+ |
begin |
687 |
+ |
Result := XMLTagDefs[i].TagValue; |
688 |
+ |
Exit; |
689 |
+ |
end; |
690 |
+ |
end; |
691 |
+ |
|
692 |
+ |
procedure TSQLXMLReader.ProcessAttributeValue(attrValue: string); |
693 |
+ |
begin |
694 |
+ |
case FXMLTagStack[FXMLTagIndex] of |
695 |
+ |
xtBlob: |
696 |
+ |
if FAttributeName = 'subtype' then |
697 |
+ |
FBlobData[FCurrentBlob].SubType := StrToInt(attrValue) |
698 |
+ |
else |
699 |
+ |
ShowError(sXMLAttributeError,[FAttributeName,attrValue]); |
700 |
+ |
|
701 |
+ |
xtArray: |
702 |
+ |
if FAttributeName = 'sqltype' then |
703 |
+ |
FArrayData[FCurrentArray].SQLType := StrToInt(attrValue) |
704 |
+ |
else |
705 |
+ |
if FAttributeName = 'relation_name' then |
706 |
+ |
FArrayData[FCurrentArray].relationName := attrValue |
707 |
+ |
else |
708 |
+ |
if FAttributeName = 'column_name' then |
709 |
+ |
FArrayData[FCurrentArray].columnName := attrValue |
710 |
+ |
else |
711 |
+ |
if FAttributeName = 'dim' then |
712 |
+ |
FArrayData[FCurrentArray].Dim := StrToInt(attrValue) |
713 |
+ |
else |
714 |
+ |
if FAttributeName = 'length' then |
715 |
+ |
FArrayData[FCurrentArray].Size := StrToInt(attrValue) |
716 |
+ |
else |
717 |
+ |
if FAttributeName = 'scale' then |
718 |
+ |
FArrayData[FCurrentArray].Scale := StrToInt(attrValue) |
719 |
+ |
else |
720 |
+ |
if FAttributeName = 'charset' then |
721 |
+ |
FArrayData[FCurrentArray].CharSet := attrValue |
722 |
+ |
else |
723 |
+ |
if FAttributeName = 'bounds' then |
724 |
+ |
ProcessBoundsList(attrValue) |
725 |
+ |
else |
726 |
+ |
ShowError(sXMLAttributeError,[FAttributeName,attrValue]); |
727 |
+ |
|
728 |
+ |
xtElt: |
729 |
+ |
if FAttributeName = 'ix' then |
730 |
+ |
with FArrayData[FCurrentArray] do |
731 |
+ |
Index[CurrentRow] := StrToInt(attrValue) |
732 |
+ |
else |
733 |
+ |
ShowError(sXMLAttributeError,[FAttributeName,attrValue]); |
734 |
+ |
end; |
735 |
+ |
end; |
736 |
+ |
|
737 |
+ |
procedure TSQLXMLReader.ProcessBoundsList(boundsList: string); |
738 |
+ |
var list: TStringList; |
739 |
+ |
i,j: integer; |
740 |
+ |
begin |
741 |
+ |
list := TStringList.Create; |
742 |
+ |
try |
743 |
+ |
list.Delimiter := ','; |
744 |
+ |
list.DelimitedText := boundsList; |
745 |
+ |
with FArrayData[FCurrentArray] do |
746 |
+ |
begin |
747 |
+ |
if dim <> list.Count then |
748 |
+ |
ShowError(sInvalidBoundsList,[boundsList]); |
749 |
+ |
SetLength(bounds,dim); |
750 |
+ |
for i := 0 to list.Count - 1 do |
751 |
+ |
begin |
752 |
+ |
j := Pos(':',list[i]); |
753 |
+ |
if j = 0 then |
754 |
+ |
raise Exception.CreateFmt(sInvalidBoundsList,[boundsList]); |
755 |
+ |
bounds[i].LowerBound := StrToInt(system.copy(list[i],1,j-1)); |
756 |
+ |
bounds[i].UpperBound := StrToInt(system.copy(list[i],j+1,length(list[i])-j)); |
757 |
+ |
end; |
758 |
+ |
end; |
759 |
+ |
finally |
760 |
+ |
list.Free; |
761 |
+ |
end; |
762 |
+ |
end; |
763 |
+ |
|
764 |
+ |
procedure TSQLXMLReader.ProcessTagValue(tagValue: string); |
765 |
+ |
|
766 |
+ |
function nibble(hex: char): byte; |
767 |
+ |
begin |
768 |
+ |
case hex of |
769 |
+ |
'0': Result := 0; |
770 |
+ |
'1': Result := 1; |
771 |
+ |
'2': Result := 2; |
772 |
+ |
'3': Result := 3; |
773 |
+ |
'4': Result := 4; |
774 |
+ |
'5': Result := 5; |
775 |
+ |
'6': Result := 6; |
776 |
+ |
'7': Result := 7; |
777 |
+ |
'8': Result := 8; |
778 |
+ |
'9': Result := 9; |
779 |
+ |
'a','A': Result := 10; |
780 |
+ |
'b','B': Result := 11; |
781 |
+ |
'c','C': Result := 12; |
782 |
+ |
'd','D': Result := 13; |
783 |
+ |
'e','E': Result := 14; |
784 |
+ |
'f','F': Result := 15; |
785 |
+ |
end; |
786 |
+ |
end; |
787 |
+ |
|
788 |
+ |
procedure RemoveWhiteSpace(var hexData: string); |
789 |
+ |
var i: integer; |
790 |
+ |
begin |
791 |
+ |
{Remove White Space} |
792 |
+ |
i := 1; |
793 |
+ |
while i <= length(hexData) do |
794 |
+ |
begin |
795 |
+ |
case hexData[i] of |
796 |
+ |
' ',#9,#10,#13: |
797 |
+ |
begin |
798 |
+ |
if i < Length(hexData) then |
799 |
+ |
Move(hexData[i+1],hexData[i],Length(hexData)-i); |
800 |
+ |
SetLength(hexData,Length(hexData)-1); |
801 |
+ |
end; |
802 |
+ |
else |
803 |
+ |
Inc(i); |
804 |
+ |
end; |
805 |
+ |
end; |
806 |
+ |
end; |
807 |
+ |
|
808 |
+ |
procedure WriteToBlob(hexData: string); |
809 |
+ |
var i,j : integer; |
810 |
+ |
blength: integer; |
811 |
+ |
P: PChar; |
812 |
+ |
begin |
813 |
+ |
RemoveWhiteSpace(hexData); |
814 |
+ |
if odd(length(hexData)) then |
815 |
+ |
ShowError(sBinaryBlockMustbeEven,[nil]); |
816 |
+ |
blength := Length(hexData) div 2; |
817 |
+ |
IBAlloc(FBlobBuffer,0,blength); |
818 |
+ |
j := 1; |
819 |
+ |
P := FBlobBuffer; |
820 |
+ |
for i := 1 to blength do |
821 |
+ |
begin |
822 |
+ |
P^ := char((nibble(hexData[j]) shl 4) or nibble(hexdata[j+1])); |
823 |
+ |
Inc(j,2); |
824 |
+ |
Inc(P); |
825 |
+ |
end; |
826 |
+ |
FBlobData[FCurrentBlob].BlobIntf.Write(FBlobBuffer^,blength); |
827 |
+ |
end; |
828 |
+ |
|
829 |
+ |
begin |
830 |
+ |
if tagValue = '' then Exit; |
831 |
+ |
case FXMLTagStack[FXMLTagIndex] of |
832 |
+ |
xtBlob: |
833 |
+ |
WriteToBlob(tagValue); |
834 |
+ |
|
835 |
+ |
xtElt: |
836 |
+ |
with FArrayData[FCurrentArray] do |
837 |
+ |
ArrayIntf.SetAsString(index,tagValue); |
838 |
+ |
|
839 |
+ |
end; |
840 |
+ |
end; |
841 |
+ |
|
842 |
+ |
procedure TSQLXMLReader.XMLTagInit(xmltag: TXMLTag); |
843 |
+ |
begin |
844 |
+ |
if FXMLTagIndex > MaxXMLTags then |
845 |
+ |
ShowError(sXMLStackOverFlow,[nil]); |
846 |
+ |
Inc(FXMLTagIndex); |
847 |
+ |
FXMLTagStack[FXMLTagIndex] := xmltag; |
848 |
+ |
FXMLString := ''; |
849 |
+ |
|
850 |
+ |
case xmltag of |
851 |
+ |
xtBlob: |
852 |
+ |
begin |
853 |
+ |
Inc(FCurrentBlob); |
854 |
+ |
SetLength(FBlobData,FCurrentBlob+1); |
855 |
+ |
FBlobData[FCurrentBlob].BlobIntf := nil; |
856 |
+ |
FBlobData[FCurrentBlob].SubType := 0; |
857 |
+ |
end; |
858 |
+ |
|
859 |
+ |
xtArray: |
860 |
+ |
begin |
861 |
+ |
Inc(FCurrentArray); |
862 |
+ |
SetLength(FArrayData,FCurrentArray+1); |
863 |
+ |
with FArrayData[FCurrentArray] do |
864 |
+ |
begin |
865 |
+ |
ArrayIntf := nil; |
866 |
+ |
SQLType := 0; |
867 |
+ |
dim := 0; |
868 |
+ |
Size := 0; |
869 |
+ |
Scale := 0; |
870 |
+ |
CharSet := 'NONE'; |
871 |
+ |
SetLength(Index,0); |
872 |
+ |
CurrentRow := -1; |
873 |
+ |
end; |
874 |
+ |
end; |
875 |
+ |
|
876 |
+ |
xtElt: |
877 |
+ |
with FArrayData[FCurrentArray] do |
878 |
+ |
Inc(CurrentRow) |
879 |
+ |
end; |
880 |
+ |
end; |
881 |
+ |
|
882 |
+ |
function TSQLXMLReader.XMLTagEnd(var xmltag: TXMLTag): boolean; |
883 |
+ |
begin |
884 |
+ |
if FXMLTagIndex = 0 then |
885 |
+ |
ShowError(sXMLStackUnderflow,[nil]); |
886 |
+ |
|
887 |
+ |
xmlTag := FXMLTagStack[FXMLTagIndex]; |
888 |
+ |
case FXMLTagStack[FXMLTagIndex] of |
889 |
+ |
xtBlob: |
890 |
+ |
FBlobData[FCurrentBlob].BlobIntf.Close; |
891 |
+ |
|
892 |
+ |
xtArray: |
893 |
+ |
FArrayData[FCurrentArray].ArrayIntf.SaveChanges; |
894 |
+ |
|
895 |
+ |
xtElt: |
896 |
+ |
Dec(FArrayData[FCurrentArray].CurrentRow); |
897 |
+ |
end; |
898 |
+ |
Dec(FXMLTagIndex); |
899 |
+ |
Result := FXMLTagIndex = 0; |
900 |
+ |
end; |
901 |
+ |
|
902 |
+ |
procedure TSQLXMLReader.XMLTagEnter; |
903 |
+ |
var aCharSetID: integer; |
904 |
+ |
begin |
905 |
+ |
if Database = nil then |
906 |
+ |
ShowError(sNoDatabase); |
907 |
+ |
if Transaction = nil then |
908 |
+ |
ShowError(sNoTransaction); |
909 |
+ |
case FXMLTagStack[FXMLTagIndex] of |
910 |
+ |
xtBlob: |
911 |
+ |
begin |
912 |
+ |
Database.Connected := true; |
913 |
+ |
Transaction.Active := true; |
914 |
+ |
FBlobData[FCurrentBlob].BlobIntf := Database.Attachment.CreateBlob( |
915 |
+ |
Transaction.TransactionIntf,FBlobData[FCurrentBlob].SubType); |
916 |
+ |
end; |
917 |
+ |
|
918 |
+ |
xtArray: |
919 |
+ |
with FArrayData[FCurrentArray] do |
920 |
+ |
begin |
921 |
+ |
Database.Connected := true; |
922 |
+ |
Transaction.Active := true; |
923 |
+ |
Database.Attachment.CharSetName2CharSetID(CharSet,aCharSetID); |
924 |
+ |
SetLength(Index,dim); |
925 |
+ |
ArrayIntf := Database.Attachment.CreateArray( |
926 |
+ |
Transaction.TransactionIntf, |
927 |
+ |
Database.Attachment.CreateArrayMetaData(SQLType, |
928 |
+ |
relationName,columnName,Scale,Size, |
929 |
+ |
aCharSetID,dim,bounds) |
930 |
+ |
); |
931 |
+ |
end; |
932 |
+ |
end; |
933 |
+ |
end; |
934 |
+ |
|
935 |
+ |
{This is where the XML tags are identified and the token stream modified in |
936 |
+ |
consequence} |
937 |
+ |
|
938 |
+ |
function TSQLXMLReader.TokenFound(var token: TSQLTokens): boolean; |
939 |
+ |
|
940 |
+ |
procedure NotAnXMLTag; |
941 |
+ |
begin |
942 |
+ |
begin |
943 |
+ |
if FXMLTagIndex = 0 then |
944 |
+ |
{nothing to do with XML so go back to processing SQL} |
945 |
+ |
begin |
946 |
+ |
QueueToken(token); |
947 |
+ |
ReleaseQueue(token); |
948 |
+ |
FXMLState := stNoXML |
949 |
+ |
end |
950 |
+ |
else |
951 |
+ |
begin |
952 |
+ |
{Not an XML tag, so just push back to XML Data} |
953 |
+ |
FXMLState := stXMLData; |
954 |
+ |
FXMLString += GetQueuedText; |
955 |
+ |
ResetQueue; |
956 |
+ |
end; |
957 |
+ |
end; |
958 |
+ |
end; |
959 |
+ |
|
960 |
+ |
var XMLTag: TXMLTag; |
961 |
+ |
begin |
962 |
+ |
Result := inherited TokenFound(token); |
963 |
+ |
if not Result then Exit; |
964 |
+ |
|
965 |
+ |
case FXMLState of |
966 |
+ |
stNoXML: |
967 |
+ |
if token = sqltLT then |
968 |
+ |
begin |
969 |
+ |
ResetQueue; |
970 |
+ |
QueueToken(token); {save in case this is not XML} |
971 |
+ |
FXMLState := stInTag; |
972 |
+ |
end; |
973 |
+ |
|
974 |
+ |
stInTag: |
975 |
+ |
{Opening '<' found, now looking for tag name or end tag marker} |
976 |
+ |
case token of |
977 |
+ |
sqltIdentifier: |
978 |
+ |
begin |
979 |
+ |
if FindTag(TokenText,XMLTag) then |
980 |
+ |
begin |
981 |
+ |
XMLTagInit(XMLTag); |
982 |
+ |
QueueToken(token); |
983 |
+ |
FXMLState := stInTagBody; |
984 |
+ |
end |
985 |
+ |
else |
986 |
+ |
NotAnXMLTag; |
987 |
+ |
end; |
988 |
+ |
|
989 |
+ |
sqltForwardSlash: |
990 |
+ |
FXMLState := stInEndTag; |
991 |
+ |
|
992 |
+ |
else |
993 |
+ |
NotAnXMLTag; |
994 |
+ |
end {case token}; |
995 |
+ |
|
996 |
+ |
stInTagBody: |
997 |
+ |
{Tag name found. Now looking for attribute or closing '>'} |
998 |
+ |
case token of |
999 |
+ |
sqltIdentifier: |
1000 |
+ |
begin |
1001 |
+ |
FAttributeName := TokenText; |
1002 |
+ |
QueueToken(token); |
1003 |
+ |
FXMLState := stAttribute; |
1004 |
+ |
end; |
1005 |
+ |
|
1006 |
+ |
sqltGT: |
1007 |
+ |
begin |
1008 |
+ |
ResetQueue; |
1009 |
+ |
XMLTagEnter; |
1010 |
+ |
FXMLState := stXMLData; |
1011 |
+ |
end; |
1012 |
+ |
|
1013 |
+ |
sqltSpace, |
1014 |
+ |
sqltCR, sqltEOL: |
1015 |
+ |
QueueToken(token); |
1016 |
+ |
|
1017 |
+ |
else |
1018 |
+ |
NotAnXMLTag; |
1019 |
+ |
end {case token}; |
1020 |
+ |
|
1021 |
+ |
stAttribute: |
1022 |
+ |
{Attribute name found. Must be followed by an '=', a '>' or another tag name} |
1023 |
+ |
case token of |
1024 |
+ |
sqltEquals: |
1025 |
+ |
begin |
1026 |
+ |
QueueToken(token); |
1027 |
+ |
FXMLState := stAttributeValue; |
1028 |
+ |
end; |
1029 |
+ |
|
1030 |
+ |
sqltSpace, |
1031 |
+ |
sqltCR, sqltEOL: |
1032 |
+ |
QueueToken(token); |
1033 |
+ |
|
1034 |
+ |
sqltIdentifier: |
1035 |
+ |
begin |
1036 |
+ |
ProcessAttributeValue(''); |
1037 |
+ |
FAttributeName := TokenText; |
1038 |
+ |
QueueToken(token); |
1039 |
+ |
FXMLState := stAttribute; |
1040 |
+ |
end; |
1041 |
+ |
|
1042 |
+ |
sqltGT: |
1043 |
+ |
begin |
1044 |
+ |
ProcessAttributeValue(''); |
1045 |
+ |
ResetQueue; |
1046 |
+ |
XMLTagEnter; |
1047 |
+ |
FXMLState := stXMLData; |
1048 |
+ |
end; |
1049 |
+ |
|
1050 |
+ |
else |
1051 |
+ |
NotAnXMLTag; |
1052 |
+ |
end; {case token} |
1053 |
+ |
|
1054 |
+ |
stAttributeValue: |
1055 |
+ |
{Looking for attribute value as a single identifier or a double quoted value} |
1056 |
+ |
case token of |
1057 |
+ |
sqltIdentifier,sqltIdentifierInDoubleQuotes: |
1058 |
+ |
begin |
1059 |
+ |
ProcessAttributeValue(TokenText); |
1060 |
+ |
QueueToken(token); |
1061 |
+ |
FXMLState := stInTagBody; |
1062 |
+ |
end; |
1063 |
+ |
|
1064 |
+ |
sqltSpace, |
1065 |
+ |
sqltCR, sqltEOL: |
1066 |
+ |
QueueToken(token); |
1067 |
+ |
|
1068 |
+ |
else |
1069 |
+ |
NotAnXMLTag; |
1070 |
+ |
end; {case token} |
1071 |
+ |
|
1072 |
+ |
stXMLData: |
1073 |
+ |
if token = sqltLT then |
1074 |
+ |
begin |
1075 |
+ |
QueueToken(token); {save in case this is not XML} |
1076 |
+ |
FXMLState := stInTag; |
1077 |
+ |
end |
1078 |
+ |
else |
1079 |
+ |
FXMLString += TokenText; |
1080 |
+ |
|
1081 |
+ |
stInEndTag: |
1082 |
+ |
{Opening '</' found, now looking for tag name} |
1083 |
+ |
case token of |
1084 |
+ |
sqltIdentifier: |
1085 |
+ |
begin |
1086 |
+ |
if FindTag(TokenText,XMLTag) and (XMLTag = FXMLTagStack[FXMLTagIndex]) then |
1087 |
+ |
begin |
1088 |
+ |
QueueToken(token); |
1089 |
+ |
FXMLState := stInEndTagBody; |
1090 |
+ |
end |
1091 |
+ |
else |
1092 |
+ |
ShowError(sInvalidEndTag,[TokenText]); |
1093 |
+ |
end; |
1094 |
+ |
else |
1095 |
+ |
NotAnXMLTag; |
1096 |
+ |
end {case token}; |
1097 |
+ |
|
1098 |
+ |
stInEndTagBody: |
1099 |
+ |
{End tag name found, now looping for closing '>'} |
1100 |
+ |
case Token of |
1101 |
+ |
sqltGT: |
1102 |
+ |
begin |
1103 |
+ |
ProcessTagValue(FXMLString); |
1104 |
+ |
if XMLTagEnd(XMLTag) then |
1105 |
+ |
begin |
1106 |
+ |
ResetQueue; |
1107 |
+ |
QueueToken(sqltColon,':'); |
1108 |
+ |
case XMLTag of |
1109 |
+ |
xtBlob: |
1110 |
+ |
QueueToken(sqltIdentifier,Format(ibx_blob+'%d',[FCurrentBlob])); |
1111 |
+ |
|
1112 |
+ |
xtArray: |
1113 |
+ |
QueueToken(sqltIdentifier, Format(ibx_array+'%d',[FCurrentArray])); |
1114 |
+ |
end; |
1115 |
+ |
ReleaseQueue(token); |
1116 |
+ |
FXMLState := stNoXML; |
1117 |
+ |
end |
1118 |
+ |
else |
1119 |
+ |
FXMLState := stXMLData; |
1120 |
+ |
end; |
1121 |
+ |
|
1122 |
+ |
sqltSpace, |
1123 |
+ |
sqltCR, sqltEOL: |
1124 |
+ |
QueueToken(token); |
1125 |
+ |
|
1126 |
+ |
else |
1127 |
+ |
ShowError(sBadEndTagClosing); |
1128 |
+ |
end; {case token} |
1129 |
+ |
|
1130 |
+ |
end {Case FState}; |
1131 |
+ |
|
1132 |
+ |
{Only allow token to be returned if not processing an XML tag} |
1133 |
+ |
|
1134 |
+ |
Result := FXMLState = stNoXML; |
1135 |
+ |
end; |
1136 |
+ |
|
1137 |
+ |
procedure TSQLXMLReader.ShowError(msg: string; params: array of const); |
1138 |
+ |
begin |
1139 |
+ |
raise EIBClientError.CreateFmt(GetErrorPrefix + msg,params); |
1140 |
+ |
end; |
1141 |
+ |
|
1142 |
+ |
procedure TSQLXMLReader.ShowError(msg: string); |
1143 |
+ |
begin |
1144 |
+ |
ShowError(msg,[nil]); |
1145 |
+ |
end; |
1146 |
+ |
|
1147 |
+ |
constructor TSQLXMLReader.Create; |
1148 |
+ |
begin |
1149 |
+ |
inherited; |
1150 |
+ |
FXMLState := stNoXML; |
1151 |
+ |
end; |
1152 |
+ |
|
1153 |
+ |
procedure TSQLXMLReader.FreeDataObjects; |
1154 |
+ |
begin |
1155 |
+ |
FXMLTagIndex := 0; |
1156 |
+ |
SetLength(FBlobData,0); |
1157 |
+ |
FCurrentBlob := -1; |
1158 |
+ |
SetLength(FArrayData,0); |
1159 |
+ |
FCurrentArray := -1; |
1160 |
+ |
end; |
1161 |
+ |
|
1162 |
+ |
class function TSQLXMLReader.FormatBlob(Field: ISQLData): string; |
1163 |
+ |
var TextOut: TStrings; |
1164 |
+ |
begin |
1165 |
+ |
TextOut := TStringList.Create; |
1166 |
+ |
try |
1167 |
+ |
TextOut.Add(Format('<blob subtype="%d">',[Field.getSubtype])); |
1168 |
+ |
StringToHex(Field.AsString,TextOut,BlobLineLength); |
1169 |
+ |
TextOut.Add('</blob>'); |
1170 |
+ |
Result := TextOut.Text; |
1171 |
+ |
finally |
1172 |
+ |
TextOut.Free; |
1173 |
+ |
end; |
1174 |
+ |
end; |
1175 |
+ |
|
1176 |
+ |
class function TSQLXMLReader.FormatArray(Database: TIBDatabase; ar: IArray |
1177 |
+ |
): string; |
1178 |
+ |
var index: array of integer; |
1179 |
+ |
TextOut: TStrings; |
1180 |
+ |
|
1181 |
+ |
procedure AddElements(dim: integer; indent:string = ' '); |
1182 |
+ |
var i: integer; |
1183 |
+ |
recurse: boolean; |
1184 |
+ |
begin |
1185 |
+ |
SetLength(index,dim+1); |
1186 |
+ |
recurse := dim < ar.GetDimensions - 1; |
1187 |
+ |
with ar.GetBounds[dim] do |
1188 |
+ |
for i := LowerBound to UpperBound do |
1189 |
+ |
begin |
1190 |
+ |
index[dim] := i; |
1191 |
+ |
if recurse then |
1192 |
+ |
begin |
1193 |
+ |
TextOut.Add(Format('%s<elt id="%d">',[indent,i])); |
1194 |
+ |
AddElements(dim+1,indent + ' '); |
1195 |
+ |
TextOut.Add('</elt>'); |
1196 |
+ |
end |
1197 |
+ |
else |
1198 |
+ |
if ((ar.GetSQLType = SQL_TEXT) or (ar.GetSQLType = SQL_VARYING)) and |
1199 |
+ |
(ar.GetCharSetID = 1) then |
1200 |
+ |
TextOut.Add(Format('%s<elt ix="%d">%s</elt>',[indent,i,StringToHex(ar.GetAsString(index))])) |
1201 |
+ |
else |
1202 |
+ |
TextOut.Add(Format('%s<elt ix="%d">%s</elt>',[indent,i,ar.GetAsString(index)])); |
1203 |
+ |
end; |
1204 |
+ |
end; |
1205 |
+ |
|
1206 |
+ |
var |
1207 |
+ |
s: string; |
1208 |
+ |
bounds: TArrayBounds; |
1209 |
+ |
i: integer; |
1210 |
+ |
boundsList: string; |
1211 |
+ |
begin |
1212 |
+ |
TextOut := TStringList.Create; |
1213 |
+ |
try |
1214 |
+ |
s := Format('<array dim = "%d" sqltype = "%d" length = "%d" relation_name = "%s" column_name = "%s"', |
1215 |
+ |
[ar.GetDimensions,ar.GetSQLType,ar.GetSize, |
1216 |
+ |
ar.GetTableName,ar.GetColumnName]); |
1217 |
+ |
case ar.GetSQLType of |
1218 |
+ |
SQL_DOUBLE, SQL_FLOAT, SQL_LONG, SQL_SHORT, SQL_D_FLOAT, SQL_INT64: |
1219 |
+ |
s += Format(' scale = "%d"',[ ar.GetScale]); |
1220 |
+ |
SQL_TEXT, |
1221 |
+ |
SQL_VARYING: |
1222 |
+ |
s += Format(' charset = "%s"',[Database.Attachment.GetCharsetName(ar.GetCharSetID)]); |
1223 |
+ |
end; |
1224 |
+ |
bounds := ar.GetBounds; |
1225 |
+ |
boundsList := ''; |
1226 |
+ |
for i := 0 to length(bounds) - 1 do |
1227 |
+ |
begin |
1228 |
+ |
if i <> 0 then boundsList += ','; |
1229 |
+ |
boundsList += Format('%d:%d',[bounds[i].LowerBound,bounds[i].UpperBound]); |
1230 |
+ |
end; |
1231 |
+ |
s += Format(' bounds="%s"',[boundsList]); |
1232 |
+ |
s += '>'; |
1233 |
+ |
TextOut.Add(s); |
1234 |
+ |
|
1235 |
+ |
SetLength(index,0); |
1236 |
+ |
AddElements(0); |
1237 |
+ |
TextOut.Add('</array>'); |
1238 |
+ |
Result := TextOut.Text; |
1239 |
+ |
finally |
1240 |
+ |
TextOut.Free; |
1241 |
+ |
end; end; |
1242 |
+ |
|
1243 |
+ |
procedure TSQLXMLReader.Reset; |
1244 |
+ |
begin |
1245 |
+ |
inherited Reset; |
1246 |
+ |
FreeDataObjects; |
1247 |
+ |
FXMLString := ''; |
1248 |
+ |
FreeMem(FBlobBuffer); |
1249 |
+ |
end; |
1250 |
+ |
|
1251 |
|
|
1252 |
|
|
1253 |
|
{ TIBXScript } |
1255 |
|
constructor TIBXScript.Create(aOwner: TComponent); |
1256 |
|
begin |
1257 |
|
inherited Create(aOwner); |
1258 |
< |
FSymbolStream := TBatchSymbolStream.Create; |
502 |
< |
FSymbolStream.OnNextLine := @EchoNextLine; |
1258 |
> |
SetSQLStatementReader(TBatchSQLStatementReader.Create); |
1259 |
|
end; |
1260 |
|
|
1261 |
|
function TIBXScript.PerformUpdate(SQLFile: string; aAutoDDL: boolean): boolean; |
1273 |
|
|
1274 |
|
function TIBXScript.RunScript(SQLFile: string): boolean; |
1275 |
|
begin |
1276 |
< |
TBatchSymbolStream(FSymbolStream).SetStreamSource(SQLFile); |
1276 |
> |
TBatchSQLStatementReader(FSQLReader).SetStreamSource(SQLFile); |
1277 |
|
Result := ProcessStream; |
1278 |
|
end; |
1279 |
|
|
1280 |
|
function TIBXScript.RunScript(SQLStream: TStream): boolean; |
1281 |
|
begin |
1282 |
< |
TBatchSymbolStream(FSymbolStream).SetStreamSource(SQLStream); |
1282 |
> |
TBatchSQLStatementReader(FSQLReader).SetStreamSource(SQLStream); |
1283 |
|
Result := ProcessStream; |
1284 |
|
end; |
1285 |
|
|
1286 |
|
function TIBXScript.RunScript(SQLLines: TStrings): boolean; |
1287 |
|
begin |
1288 |
< |
TBatchSymbolStream(FSymbolStream).SetStreamSource(SQLLines); |
1288 |
> |
TBatchSQLStatementReader(FSQLReader).SetStreamSource(SQLLines); |
1289 |
|
Result := ProcessStream; |
1290 |
|
end; |
1291 |
|
|
1292 |
|
function TIBXScript.ExecSQLScript(sql: string): boolean; |
537 |
– |
var s: TStringList; |
1293 |
|
begin |
1294 |
< |
s := TStringList.Create; |
1295 |
< |
try |
541 |
< |
s.Text := sql; |
542 |
< |
TBatchSymbolStream(FSymbolStream).SetStreamSource(s); |
543 |
< |
Result := ProcessStream; |
544 |
< |
finally |
545 |
< |
s.Free; |
546 |
< |
end; |
1294 |
> |
TBatchSQLStatementReader(FSQLReader).SetStringStreamSource(sql); |
1295 |
> |
Result := ProcessStream; |
1296 |
|
end; |
1297 |
|
|
1298 |
|
{ TCustomIBXScript } |
1328 |
|
FISQL.SQL.Text := stmt; |
1329 |
|
FISQL.Transaction := GetTransaction; |
1330 |
|
FISQL.Transaction.Active := true; |
1331 |
< |
FISQL.ParamCheck := not FIBSQLProcessor.HasBegin; {Probably PSQL} |
1331 |
> |
// FISQL.ParamCheck := not FSQLReader.HasBegin; {Probably PSQL} |
1332 |
|
FISQL.Prepare; |
1333 |
|
FISQL.Statement.EnableStatistics(ShowPerformanceStats); |
1334 |
|
|
1367 |
|
|
1368 |
|
function TCustomIBXScript.GetOnProgressEvent: TOnProgressEvent; |
1369 |
|
begin |
1370 |
< |
Result := FSymbolStream.OnProgressEvent; |
1370 |
> |
Result := FSQLReader.OnProgressEvent; |
1371 |
|
end; |
1372 |
|
|
1373 |
|
function TCustomIBXScript.GetTransaction: TIBTransaction; |
1400 |
|
if not (csLoading in ComponentState) and (FDatabase = AValue) then Exit; |
1401 |
|
FDatabase := AValue; |
1402 |
|
FISQL.Database := AValue; |
1403 |
< |
FIBXMLProcessor.Database := AValue; |
1403 |
> |
FSQLReader.Database := AValue; |
1404 |
|
FInternalTransaction.Active := false; |
1405 |
|
FInternalTransaction.DefaultDatabase := AValue; |
1406 |
|
end; |
1417 |
|
|
1418 |
|
procedure TCustomIBXScript.SetOnProgressEvent(AValue: TOnProgressEvent); |
1419 |
|
begin |
1420 |
< |
FSymbolStream.OnProgressEvent := AValue; |
1420 |
> |
FSQLReader.OnProgressEvent := AValue; |
1421 |
|
end; |
1422 |
|
|
1423 |
|
procedure TCustomIBXScript.SetParamValue(SQLVar: ISQLParam); |
1424 |
|
var BlobID: TISC_QUAD; |
1425 |
|
ix: integer; |
1426 |
|
begin |
1427 |
< |
if (SQLVar.SQLType = SQL_BLOB) and (Pos(ibx_blob,SQLVar.Name) = 1) then |
1427 |
> |
if (SQLVar.SQLType = SQL_BLOB) and (Pos(TSQLXMLReader.ibx_blob,SQLVar.Name) = 1) then |
1428 |
|
begin |
1429 |
< |
ix := StrToInt(system.copy(SQLVar.Name,length(ibx_blob)+1,length(SQLVar.Name)-length(ibx_blob))); |
1430 |
< |
SQLVar.AsBlob := FIBXMLProcessor.BlobData[ix].BlobIntf; |
1429 |
> |
ix := StrToInt(system.copy(SQLVar.Name,length(TSQLXMLReader.ibx_blob)+1,length(SQLVar.Name)-length(TSQLXMLReader.ibx_blob))); |
1430 |
> |
SQLVar.AsBlob := FSQLReader.BlobData[ix].BlobIntf; |
1431 |
|
Exit; |
1432 |
|
end |
1433 |
|
else |
1434 |
< |
if (SQLVar.SQLType = SQL_ARRAY) and (Pos(ibx_array,SQLVar.Name) = 1) then |
1434 |
> |
if (SQLVar.SQLType = SQL_ARRAY) and (Pos(TSQLXMLReader.ibx_array,SQLVar.Name) = 1) then |
1435 |
|
begin |
1436 |
< |
ix := StrToInt(system.copy(SQLVar.Name,length(ibx_array)+1,length(SQLVar.Name)-length(ibx_array))); |
1437 |
< |
SQLVar.AsArray := FIBXMLProcessor.ArrayData[ix].ArrayIntf; |
1436 |
> |
ix := StrToInt(system.copy(SQLVar.Name,length(TSQLXMLReader.ibx_array)+1,length(SQLVar.Name)-length(TSQLXMLReader.ibx_array))); |
1437 |
> |
SQLVar.AsArray := FSQLReader.ArrayData[ix].ArrayIntf; |
1438 |
|
Exit; |
1439 |
|
end; |
1440 |
|
|
1463 |
|
var stmt: string; |
1464 |
|
begin |
1465 |
|
Result := false; |
1466 |
< |
while FIBSQLProcessor.GetNextStatement(FSymbolStream,stmt) do |
1466 |
> |
while FSQLReader.GetNextStatement(stmt) do |
1467 |
|
try |
1468 |
+ |
stmt := trim(stmt); |
1469 |
|
// writeln('stmt = ',stmt); |
1470 |
< |
if trim(stmt) = '' then continue; |
1470 |
> |
if stmt = '' then continue; |
1471 |
|
if not ProcessStatement(stmt) then |
1472 |
|
ExecSQL(stmt); |
1473 |
|
|
1475 |
|
begin |
1476 |
|
with GetTransaction do |
1477 |
|
if InTransaction then Rollback; |
1478 |
< |
FSymbolStream.Terminator := DefaultTerminator; |
1478 |
> |
FSQLReader.Terminator := TSQLStatementReader.DefaultTerminator; |
1479 |
|
if assigned(OnErrorLog) then |
1480 |
|
begin |
1481 |
< |
Add2Log(Format(sStatementError,[FSymbolStream.GetErrorPrefix, |
1481 |
> |
Add2Log(Format(sStatementError,[FSQLReader.GetErrorPrefix, |
1482 |
|
E.Message,stmt]),true); |
1483 |
|
if StopOnFirstError then Exit; |
1484 |
|
end |
1489 |
|
Result := true; |
1490 |
|
end; |
1491 |
|
|
1492 |
+ |
procedure TCustomIBXScript.SetSQLStatementReader( |
1493 |
+ |
SQLStatementReader: TSQLStatementReader); |
1494 |
+ |
begin |
1495 |
+ |
FSQLReader := SQLStatementReader; |
1496 |
+ |
FSQLReader.OnNextLine := @EchoNextLine; |
1497 |
+ |
FSQLReader.Transaction := FInternalTransaction; |
1498 |
+ |
end; |
1499 |
+ |
|
1500 |
|
function TCustomIBXScript.ProcessStatement(stmt: string): boolean; |
1501 |
|
var command: string; |
1502 |
|
|
1608 |
|
LoginPrompt: boolean; |
1609 |
|
begin |
1610 |
|
Result := false; |
1611 |
< |
Terminator := FSymbolStream.Terminator; |
1611 |
> |
Terminator := FSQLReader.Terminator; |
1612 |
|
RegexObj := TRegExpr.Create; |
1613 |
|
try |
1614 |
|
{process create database} |
1626 |
|
OnCreateDatabase(self,FileName); |
1627 |
|
stmt := 'CREATE DATABASE ''' + FileName + '''' + system.copy(stmt,RegexObj.MatchPos[3], RegexObj.MatchLen[3]); |
1628 |
|
UpdateUserPassword; |
1629 |
< |
FDatabase.Connected := false; |
1629 |
> |
if FDatabase.Connected then |
1630 |
> |
FDatabase.Dropdatabase; |
1631 |
|
FDatabase.CreateDatabase(stmt); |
873 |
– |
FDatabase.Connected := false; |
874 |
– |
ExtractUserInfo; |
875 |
– |
FDatabase.Connected := true; |
1632 |
|
Result := true; |
1633 |
|
Exit; |
1634 |
|
end; |
1676 |
|
RegexObj.Expression := '^ *SET +TERM +(.) *(\' + Terminator + '|)'; |
1677 |
|
if RegexObj.Exec(stmt) then |
1678 |
|
begin |
1679 |
< |
FSymbolStream.Terminator := RegexObj.Match[1][1]; |
1679 |
> |
FSQLReader.Terminator := RegexObj.Match[1][1]; |
1680 |
|
Result := true; |
1681 |
|
Exit; |
1682 |
|
end; |
1702 |
|
begin |
1703 |
|
command := AnsiUpperCase(RegexObj.Match[1]); |
1704 |
|
param := trim(RegexObj.Match[2]); |
1705 |
+ |
if command = 'GENERATOR' then |
1706 |
+ |
begin |
1707 |
+ |
Result := false; |
1708 |
+ |
Exit; |
1709 |
+ |
end; |
1710 |
|
if command = 'AUTODDL' then |
1711 |
|
AutoDDL := ((RegexObj.MatchLen[2] = 0) and not AutoDDL) or |
1712 |
|
(RegexObj.MatchLen[2] > 0) and Toggle(param) |
1746 |
|
begin |
1747 |
|
if assigned(DataOutputFormatter) then |
1748 |
|
DataOutputFormatter.SetCommand(command,param,stmt,Result); |
1749 |
< |
if not Result and assigned(OnSetStatement) then |
1750 |
< |
OnSetStatement(self,command,param,stmt,Result) |
1751 |
< |
else |
1752 |
< |
raise Exception.CreateFmt(sInvalidSetStatement, [command,stmt]); |
1749 |
> |
if not Result then |
1750 |
> |
begin |
1751 |
> |
if assigned(OnSetStatement) then |
1752 |
> |
OnSetStatement(self,command,param,stmt,Result) |
1753 |
> |
else |
1754 |
> |
raise Exception.CreateFmt(sInvalidSetStatement, [command,stmt]); |
1755 |
> |
end; |
1756 |
|
Exit; |
1757 |
|
end; |
1758 |
|
Result := true; |
1768 |
|
begin |
1769 |
|
if FTransaction = AValue then Exit; |
1770 |
|
FTransaction := AValue; |
1771 |
< |
FIBXMLProcessor.Transaction := AValue; |
1771 |
> |
if FTransaction = nil then |
1772 |
> |
FSQLReader.Transaction := FInternalTransaction |
1773 |
> |
else |
1774 |
> |
FSQLReader.Transaction := FTransaction; |
1775 |
|
end; |
1776 |
|
|
1777 |
|
constructor TCustomIBXScript.Create(aOwner: TComponent); |
1782 |
|
FAutoDDL := true; |
1783 |
|
FISQL := TIBSQL.Create(self); |
1784 |
|
FISQL.ParamCheck := true; |
1018 |
– |
FIBXMLProcessor := TIBXMLProcessor.Create; |
1019 |
– |
FIBSQLProcessor := TIBSQLProcessor.Create(FIBXMLProcessor); |
1785 |
|
FInternalTransaction := TIBTransaction.Create(self); |
1786 |
|
FInternalTransaction.Params.Clear; |
1787 |
|
FInternalTransaction.Params.Add('concurrency'); |
1790 |
|
|
1791 |
|
destructor TCustomIBXScript.Destroy; |
1792 |
|
begin |
1793 |
< |
if FIBSQLProcessor <> nil then FIBSQLProcessor.Free; |
1029 |
< |
if FIBXMLProcessor <> nil then FIBXMLProcessor.Free; |
1030 |
< |
if FSymbolStream <> nil then FSymbolStream.Free; |
1793 |
> |
if FSQLReader <> nil then FSQLReader.Free; |
1794 |
|
if FISQL <> nil then FISQL.Free; |
1795 |
|
if FInternalTransaction <> nil then FInternalTransaction.Free; |
1796 |
|
inherited Destroy; |
1801 |
|
if assigned(DataOutputFormatter) then |
1802 |
|
DataOutputFormatter.DataOut(aSQLText,@Add2Log) |
1803 |
|
else |
1804 |
< |
FSymbolStream.ShowError(sNoSelectSQL,[nil]); |
1804 |
> |
FSQLReader.ShowError(sNoSelectSQL); |
1805 |
|
end; |
1806 |
|
|
1807 |
< |
{ TIBSQLProcessor } |
1045 |
< |
|
1046 |
< |
procedure TIBSQLProcessor.AddToSQL(const Symbol: string); |
1047 |
< |
begin |
1048 |
< |
FSQLText := FSQLText + Symbol; |
1049 |
< |
// writeln('SQL = ',FSQLText); |
1050 |
< |
end; |
1051 |
< |
|
1052 |
< |
procedure TIBSQLProcessor.SetState(AState: TSQLStates); |
1053 |
< |
begin |
1054 |
< |
if FStackIndex > 16 then |
1055 |
< |
FSymbolStream.ShowError(sStackOverFlow,[nil]); |
1056 |
< |
FStack[FStackIndex] := FState; |
1057 |
< |
Inc(FStackIndex); |
1058 |
< |
FState := AState |
1059 |
< |
end; |
1807 |
> |
{ TInteractiveSQLStatementReader } |
1808 |
|
|
1809 |
< |
function TIBSQLProcessor.PopState: TSQLStates; |
1809 |
> |
function TInteractiveSQLStatementReader.GetErrorPrefix: string; |
1810 |
|
begin |
1811 |
< |
if FStackIndex = 0 then |
1064 |
< |
FSymbolStream.ShowError(sStackUnderflow,[nil]); |
1065 |
< |
Dec(FStackIndex); |
1066 |
< |
Result := FStack[FStackIndex] |
1067 |
< |
end; |
1068 |
< |
|
1069 |
< |
constructor TIBSQLProcessor.Create(XMLProcessor: TIBXMLProcessor); |
1070 |
< |
begin |
1071 |
< |
inherited Create; |
1072 |
< |
FXMLProcessor := XMLProcessor; |
1811 |
> |
Result := ''; |
1812 |
|
end; |
1813 |
|
|
1814 |
< |
function TIBSQLProcessor.GetNextStatement(SymbolStream: TSymbolStream; |
1076 |
< |
var stmt: string): boolean; |
1077 |
< |
var Symbol: TSQLSymbol; |
1078 |
< |
NonSpace: boolean; |
1079 |
< |
Done: boolean; |
1814 |
> |
function TInteractiveSQLStatementReader.GetNextLine(var Line: string): boolean; |
1815 |
|
begin |
1816 |
< |
FSQLText := ''; |
1817 |
< |
FState := stInit; |
1818 |
< |
FHasBegin := false; |
1819 |
< |
FSymbolStream := SymbolStream; |
1820 |
< |
FXMLProcessor.NextStatement; |
1821 |
< |
SymbolStream.NextStatement; |
1087 |
< |
|
1088 |
< |
Result := true; |
1089 |
< |
Done := false; |
1090 |
< |
NonSpace := false; |
1091 |
< |
while not Done do |
1092 |
< |
with SymbolStream do |
1816 |
> |
if FNextStatement then |
1817 |
> |
write(FPrompt) |
1818 |
> |
else |
1819 |
> |
write(FContinuePrompt); |
1820 |
> |
Result := not system.EOF; |
1821 |
> |
if Result then |
1822 |
|
begin |
1823 |
< |
if FState = stError then |
1824 |
< |
ShowError(sErrorState,[nil]); |
1096 |
< |
Symbol := GetSymbol; |
1097 |
< |
// writeln('Symbol = ',Symbol,' Value = ',SymbolValue); |
1098 |
< |
if not (Symbol in [' ',sqEOL]) then |
1099 |
< |
NonSpace := true; |
1100 |
< |
|
1101 |
< |
case Symbol of |
1102 |
< |
sqTag: |
1103 |
< |
begin |
1104 |
< |
if FState in [stInSQL,stNested] then |
1105 |
< |
AddToSQL(FXMLProcessor.AnalyseXML(SymbolStream)); |
1106 |
< |
end; |
1107 |
< |
|
1108 |
< |
sqTerminator: |
1109 |
< |
case FState of |
1110 |
< |
stInit: {ignore empty statement}; |
1111 |
< |
|
1112 |
< |
stInSQL: |
1113 |
< |
Done := true; |
1114 |
< |
|
1115 |
< |
stNested: |
1116 |
< |
AddToSQL(Terminator); |
1117 |
< |
|
1118 |
< |
stInDeclaration: |
1119 |
< |
begin |
1120 |
< |
FState := PopState; |
1121 |
< |
AddToSQL(Terminator); |
1122 |
< |
end; |
1123 |
< |
|
1124 |
< |
else |
1125 |
< |
ShowError(sTerminatorUnknownState,[FState]); |
1126 |
< |
end; |
1127 |
< |
|
1128 |
< |
';': |
1129 |
< |
begin |
1130 |
< |
if FState = stInDeclaration then |
1131 |
< |
FState := PopState; |
1132 |
< |
AddToSQL(';'); |
1133 |
< |
end; |
1134 |
< |
|
1135 |
< |
'*': |
1136 |
< |
begin |
1137 |
< |
AddToSQL('*'); |
1138 |
< |
if FState = stInit then |
1139 |
< |
FState := stInSQL |
1140 |
< |
end; |
1141 |
< |
|
1142 |
< |
'/': |
1143 |
< |
begin |
1144 |
< |
AddToSQL('/'); |
1145 |
< |
if FState = stInit then |
1146 |
< |
FState := stInSQL |
1147 |
< |
end; |
1148 |
< |
|
1149 |
< |
sqComment, |
1150 |
< |
sqQuotedString, |
1151 |
< |
sqDoubleQuotedString: |
1152 |
< |
if FState <> stInit then |
1153 |
< |
AddToSQL(SymbolValue); |
1154 |
< |
|
1155 |
< |
sqCommentLine: |
1156 |
< |
if FState <> stInit then |
1157 |
< |
AddToSQL(SymbolValue + LineEnding); |
1158 |
< |
|
1159 |
< |
sqEnd: |
1160 |
< |
begin |
1161 |
< |
AddToSQL(SymbolValue); |
1162 |
< |
case FState of |
1163 |
< |
stNested: |
1164 |
< |
begin |
1165 |
< |
if FNested = 0 then |
1166 |
< |
begin |
1167 |
< |
FState := PopState; |
1168 |
< |
if not FInCase then |
1169 |
< |
begin |
1170 |
< |
FState := stInit; |
1171 |
< |
Done := true; |
1172 |
< |
end |
1173 |
< |
else |
1174 |
< |
FInCase := false; |
1175 |
< |
end |
1176 |
< |
else |
1177 |
< |
Dec(FNested) |
1178 |
< |
end; |
1179 |
< |
{Otherwise ignore} |
1180 |
< |
end |
1181 |
< |
end; |
1182 |
< |
|
1183 |
< |
sqBegin: |
1184 |
< |
begin |
1185 |
< |
FHasBegin := true; |
1186 |
< |
AddToSQL(SymbolValue); |
1187 |
< |
case FState of |
1188 |
< |
stNested: |
1189 |
< |
Inc(FNested); |
1190 |
< |
|
1191 |
< |
stInSQL, |
1192 |
< |
stInit: |
1193 |
< |
SetState(stNested); |
1194 |
< |
end |
1195 |
< |
end; |
1196 |
< |
|
1197 |
< |
sqCase: |
1198 |
< |
begin |
1199 |
< |
AddToSQL(SymbolValue); |
1200 |
< |
case FState of |
1201 |
< |
stNested: |
1202 |
< |
Inc(FNested); |
1203 |
< |
|
1204 |
< |
stInSQL, |
1205 |
< |
stInit: |
1206 |
< |
begin |
1207 |
< |
FInCase := true; |
1208 |
< |
SetState(stNested); |
1209 |
< |
end; |
1210 |
< |
end |
1211 |
< |
end; |
1212 |
< |
|
1213 |
< |
sqDeclare: |
1214 |
< |
begin |
1215 |
< |
AddToSQL(SymbolValue); |
1216 |
< |
if FState in [stInit,stInSQL] then |
1217 |
< |
SetState(stInDeclaration) |
1218 |
< |
end; |
1219 |
< |
|
1220 |
< |
sqString: |
1221 |
< |
begin |
1222 |
< |
AddToSQL(SymbolValue); |
1223 |
< |
if FState = stInit then |
1224 |
< |
FState := stInSQL |
1225 |
< |
end; |
1226 |
< |
|
1227 |
< |
sqEOL: |
1228 |
< |
begin |
1229 |
< |
case FState of |
1230 |
< |
stInit: |
1231 |
< |
{Do nothing}; |
1232 |
< |
else |
1233 |
< |
if NonSpace then AddToSQL(LineEnding); |
1234 |
< |
end; |
1235 |
< |
end; |
1236 |
< |
|
1237 |
< |
sqEOF: |
1238 |
< |
begin |
1239 |
< |
Done := true; |
1240 |
< |
Result := trim(FSQLText) <> ''; |
1241 |
< |
end |
1242 |
< |
else |
1243 |
< |
if FState <> stInit then |
1244 |
< |
AddToSQL(Symbol); |
1245 |
< |
end |
1246 |
< |
end; |
1247 |
< |
stmt := FSQLText; |
1248 |
< |
// writeln('stmt = ',stmt); |
1249 |
< |
end; |
1250 |
< |
|
1251 |
< |
{ TIBXMLProcessor } |
1252 |
< |
|
1253 |
< |
procedure TIBXMLProcessor.EndXMLTag(xmltag: TXMLTag); |
1254 |
< |
begin |
1255 |
< |
if FXMLTagIndex = 0 then |
1256 |
< |
FSymbolStream.ShowError(sXMLStackUnderflow,[nil]); |
1257 |
< |
if xmltag <> FXMLTagStack[FXMLTagIndex] then |
1258 |
< |
FSymbolStream.ShowError(sInvalidEndTag,[FSymbolStream.SymbolValue]); |
1259 |
< |
|
1260 |
< |
case FXMLTagStack[FXMLTagIndex] of |
1261 |
< |
xtBlob: |
1262 |
< |
FBlobData[FCurrentBlob].BlobIntf.Close; |
1263 |
< |
|
1264 |
< |
xtArray: |
1265 |
< |
FArrayData[FCurrentArray].ArrayIntf.SaveChanges; |
1266 |
< |
|
1267 |
< |
xtElt: |
1268 |
< |
Dec(FArrayData[FCurrentArray].CurrentRow); |
1269 |
< |
end; |
1270 |
< |
Dec(FXMLTagIndex); |
1271 |
< |
end; |
1272 |
< |
|
1273 |
< |
procedure TIBXMLProcessor.EnterTag; |
1274 |
< |
var aCharSetID: integer; |
1275 |
< |
begin |
1276 |
< |
case FXMLTagStack[FXMLTagIndex] of |
1277 |
< |
xtBlob: |
1278 |
< |
begin |
1279 |
< |
Database.Connected := true; |
1280 |
< |
Transaction.Active := true; |
1281 |
< |
FBlobData[FCurrentBlob].BlobIntf := Database.Attachment.CreateBlob( |
1282 |
< |
Transaction.TransactionIntf,FBlobData[FCurrentBlob].SubType); |
1283 |
< |
end; |
1284 |
< |
|
1285 |
< |
xtArray: |
1286 |
< |
with FArrayData[FCurrentArray] do |
1287 |
< |
begin |
1288 |
< |
Database.Connected := true; |
1289 |
< |
Transaction.Active := true; |
1290 |
< |
Database.Attachment.CharSetName2CharSetID(CharSet,aCharSetID); |
1291 |
< |
SetLength(Index,dim); |
1292 |
< |
ArrayIntf := Database.Attachment.CreateArray( |
1293 |
< |
Transaction.TransactionIntf, |
1294 |
< |
Database.Attachment.CreateArrayMetaData(SQLType, |
1295 |
< |
relationName,columnName,Scale,Size, |
1296 |
< |
aCharSetID,dim,bounds) |
1297 |
< |
); |
1298 |
< |
end; |
1823 |
> |
readln(Line); |
1824 |
> |
EchoNextLine(Line); |
1825 |
|
end; |
1826 |
|
end; |
1827 |
|
|
1828 |
< |
function TIBXMLProcessor.GetArrayData(index: integer): TArrayData; |
1303 |
< |
begin |
1304 |
< |
if (index < 0) or (index > ArrayDataCount) then |
1305 |
< |
FSymbolStream.ShowError(sArrayIndexError,[index]); |
1306 |
< |
Result := FArrayData[index]; |
1307 |
< |
end; |
1308 |
< |
|
1309 |
< |
function TIBXMLProcessor.GetArrayDataCount: integer; |
1310 |
< |
begin |
1311 |
< |
Result := Length(FArrayData); |
1312 |
< |
end; |
1313 |
< |
|
1314 |
< |
function TIBXMLProcessor.GetBlobData(index: integer): TBlobData; |
1828 |
> |
function TInteractiveSQLStatementReader.GetChar: char; |
1829 |
|
begin |
1830 |
< |
if (index < 0) or (index > BlobDataCount) then |
1831 |
< |
FSymbolStream.ShowError(sBlobIndexError,[index]); |
1832 |
< |
Result := FBlobData[index]; |
1833 |
< |
end; |
1320 |
< |
|
1321 |
< |
function TIBXMLProcessor.GetBlobDataCount: integer; |
1322 |
< |
begin |
1323 |
< |
Result := Length(FBlobData); |
1324 |
< |
end; |
1325 |
< |
|
1326 |
< |
procedure TIBXMLProcessor.ProcessTagValue(tagValue: string); |
1327 |
< |
|
1328 |
< |
function nibble(hex: char): byte; |
1329 |
< |
begin |
1330 |
< |
case hex of |
1331 |
< |
'0': Result := 0; |
1332 |
< |
'1': Result := 1; |
1333 |
< |
'2': Result := 2; |
1334 |
< |
'3': Result := 3; |
1335 |
< |
'4': Result := 4; |
1336 |
< |
'5': Result := 5; |
1337 |
< |
'6': Result := 6; |
1338 |
< |
'7': Result := 7; |
1339 |
< |
'8': Result := 8; |
1340 |
< |
'9': Result := 9; |
1341 |
< |
'a','A': Result := 10; |
1342 |
< |
'b','B': Result := 11; |
1343 |
< |
'c','C': Result := 12; |
1344 |
< |
'd','D': Result := 13; |
1345 |
< |
'e','E': Result := 14; |
1346 |
< |
'f','F': Result := 15; |
1347 |
< |
end; |
1348 |
< |
end; |
1349 |
< |
|
1350 |
< |
procedure RemoveWhiteSpace(var hexData: string); |
1351 |
< |
var i: integer; |
1830 |
> |
if Terminated then |
1831 |
> |
Result := #0 |
1832 |
> |
else |
1833 |
> |
if FLineIndex > Length(FLine) then |
1834 |
|
begin |
1835 |
< |
{Remove White Space} |
1836 |
< |
i := 1; |
1837 |
< |
while i <= length(hexData) do |
1838 |
< |
begin |
1839 |
< |
case hexData[i] of |
1358 |
< |
' ',#9,#10,#13: |
1359 |
< |
begin |
1360 |
< |
if i < Length(hexData) then |
1361 |
< |
Move(hexData[i+1],hexData[i],Length(hexData)-i); |
1362 |
< |
SetLength(hexData,Length(hexData)-1); |
1363 |
< |
end; |
1364 |
< |
else |
1365 |
< |
Inc(i); |
1366 |
< |
end; |
1367 |
< |
end; |
1368 |
< |
end; |
1369 |
< |
|
1370 |
< |
procedure WriteToBlob(hexData: string); |
1371 |
< |
var i,j : integer; |
1372 |
< |
blength: integer; |
1373 |
< |
P: PChar; |
1835 |
> |
Result := LF; |
1836 |
> |
FLineIndex := 0; |
1837 |
> |
end |
1838 |
> |
else |
1839 |
> |
if FLineIndex = 0 then |
1840 |
|
begin |
1841 |
< |
RemoveWhiteSpace(hexData); |
1842 |
< |
if odd(length(hexData)) then |
1377 |
< |
FSymbolStream.ShowError(sBinaryBlockMustbeEven,[nil]); |
1378 |
< |
blength := Length(hexData) div 2; |
1379 |
< |
IBAlloc(FBlobBuffer,0,blength); |
1380 |
< |
j := 1; |
1381 |
< |
P := FBlobBuffer; |
1382 |
< |
for i := 1 to blength do |
1383 |
< |
begin |
1384 |
< |
P^ := char((nibble(hexData[j]) shl 4) or nibble(hexdata[j+1])); |
1385 |
< |
Inc(j,2); |
1386 |
< |
Inc(P); |
1387 |
< |
end; |
1388 |
< |
FBlobData[FCurrentBlob].BlobIntf.Write(FBlobBuffer^,blength); |
1389 |
< |
end; |
1390 |
< |
|
1391 |
< |
begin |
1392 |
< |
if tagValue = '' then Exit; |
1393 |
< |
case FXMLTagStack[FXMLTagIndex] of |
1394 |
< |
xtBlob: |
1395 |
< |
WriteToBlob(tagValue); |
1396 |
< |
|
1397 |
< |
xtElt: |
1398 |
< |
with FArrayData[FCurrentArray] do |
1399 |
< |
ArrayIntf.SetAsString(index,tagValue); |
1400 |
< |
|
1401 |
< |
end; |
1402 |
< |
end; |
1403 |
< |
|
1404 |
< |
procedure TIBXMLProcessor.StartXMLTag(xmltag: TXMLTag); |
1405 |
< |
begin |
1406 |
< |
if FXMLTagIndex > 19 then |
1407 |
< |
FSymbolStream.ShowError(sXMLStackOverFlow,[nil]); |
1408 |
< |
Inc(FXMLTagIndex); |
1409 |
< |
FXMLTagStack[FXMLTagIndex] := xmltag; |
1410 |
< |
case xmltag of |
1411 |
< |
xtBlob: |
1412 |
< |
begin |
1413 |
< |
Inc(FCurrentBlob); |
1414 |
< |
SetLength(FBlobData,FCurrentBlob+1); |
1415 |
< |
FBlobData[FCurrentBlob].BlobIntf := nil; |
1416 |
< |
FBlobData[FCurrentBlob].SubType := 0; |
1417 |
< |
end; |
1418 |
< |
|
1419 |
< |
xtArray: |
1420 |
< |
begin |
1421 |
< |
Inc(FCurrentArray); |
1422 |
< |
SetLength(FArrayData,FCurrentArray+1); |
1423 |
< |
with FArrayData[FCurrentArray] do |
1424 |
< |
begin |
1425 |
< |
ArrayIntf := nil; |
1426 |
< |
SQLType := 0; |
1427 |
< |
dim := 0; |
1428 |
< |
Size := 0; |
1429 |
< |
Scale := 0; |
1430 |
< |
CharSet := 'NONE'; |
1431 |
< |
SetLength(Index,0); |
1432 |
< |
CurrentRow := -1; |
1433 |
< |
end; |
1434 |
< |
end; |
1435 |
< |
|
1436 |
< |
xtElt: |
1437 |
< |
with FArrayData[FCurrentArray] do |
1438 |
< |
Inc(CurrentRow); |
1439 |
< |
|
1440 |
< |
end; |
1441 |
< |
end; |
1442 |
< |
|
1443 |
< |
procedure TIBXMLProcessor.ProcessAttributeValue(attrValue: string); |
1444 |
< |
begin |
1445 |
< |
case FXMLTagStack[FXMLTagIndex] of |
1446 |
< |
xtBlob: |
1447 |
< |
if FAttributeName = 'subtype' then |
1448 |
< |
FBlobData[FCurrentBlob].SubType := StrToInt(attrValue) |
1449 |
< |
else |
1450 |
< |
FSymbolStream.ShowError(sXMLAttributeError,[FAttributeName,attrValue]); |
1451 |
< |
|
1452 |
< |
xtArray: |
1453 |
< |
if FAttributeName = 'sqltype' then |
1454 |
< |
FArrayData[FCurrentArray].SQLType := StrToInt(attrValue) |
1455 |
< |
else |
1456 |
< |
if FAttributeName = 'relation_name' then |
1457 |
< |
FArrayData[FCurrentArray].relationName := attrValue |
1458 |
< |
else |
1459 |
< |
if FAttributeName = 'column_name' then |
1460 |
< |
FArrayData[FCurrentArray].columnName := attrValue |
1461 |
< |
else |
1462 |
< |
if FAttributeName = 'dim' then |
1463 |
< |
FArrayData[FCurrentArray].Dim := StrToInt(attrValue) |
1464 |
< |
else |
1465 |
< |
if FAttributeName = 'length' then |
1466 |
< |
FArrayData[FCurrentArray].Size := StrToInt(attrValue) |
1467 |
< |
else |
1468 |
< |
if FAttributeName = 'scale' then |
1469 |
< |
FArrayData[FCurrentArray].Scale := StrToInt(attrValue) |
1470 |
< |
else |
1471 |
< |
if FAttributeName = 'charset' then |
1472 |
< |
FArrayData[FCurrentArray].CharSet := attrValue |
1841 |
> |
if not GetNextLine(FLine) then |
1842 |
> |
Result := #0 |
1843 |
|
else |
1844 |
< |
if FAttributeName = 'bounds' then |
1845 |
< |
ProcessBoundsList(attrValue) |
1844 |
> |
if Length(FLine) = 0 then |
1845 |
> |
Result := LF |
1846 |
|
else |
1477 |
– |
FSymbolStream.ShowError(sXMLAttributeError,[FAttributeName,attrValue]); |
1478 |
– |
|
1479 |
– |
xtElt: |
1480 |
– |
if FAttributeName = 'ix' then |
1481 |
– |
with FArrayData[FCurrentArray] do |
1482 |
– |
Index[CurrentRow] := StrToInt(attrValue) |
1483 |
– |
else |
1484 |
– |
FSymbolStream.ShowError(sXMLAttributeError,[FAttributeName,attrValue]); |
1485 |
– |
end; |
1486 |
– |
end; |
1487 |
– |
|
1488 |
– |
procedure TIBXMLProcessor.ProcessBoundsList(boundsList: string); |
1489 |
– |
var list: TStringList; |
1490 |
– |
i,j: integer; |
1491 |
– |
begin |
1492 |
– |
list := TStringList.Create; |
1493 |
– |
try |
1494 |
– |
list.Delimiter := ','; |
1495 |
– |
list.DelimitedText := boundsList; |
1496 |
– |
with FArrayData[FCurrentArray] do |
1847 |
|
begin |
1848 |
< |
if dim <> list.Count then |
1849 |
< |
FSymbolStream.ShowError(sInvalidBoundsList,[boundsList]); |
1850 |
< |
SetLength(bounds,dim); |
1851 |
< |
for i := 0 to list.Count - 1 do |
1852 |
< |
begin |
1853 |
< |
j := Pos(':',list[i]); |
1854 |
< |
if j = 0 then |
1855 |
< |
raise Exception.CreateFmt(sInvalidBoundsList,[boundsList]); |
1506 |
< |
bounds[i].LowerBound := StrToInt(system.copy(list[i],1,j-1)); |
1507 |
< |
bounds[i].UpperBound := StrToInt(system.copy(list[i],j+1,length(list[i])-j)); |
1508 |
< |
end; |
1509 |
< |
end; |
1510 |
< |
finally |
1511 |
< |
list.Free; |
1848 |
> |
Result := FLine[1]; |
1849 |
> |
FLineIndex := 2; |
1850 |
> |
end |
1851 |
> |
end |
1852 |
> |
else |
1853 |
> |
begin |
1854 |
> |
Result := FLine[FLineIndex]; |
1855 |
> |
Inc(FLineIndex); |
1856 |
|
end; |
1857 |
|
end; |
1858 |
|
|
1859 |
< |
constructor TIBXMLProcessor.Create; |
1859 |
> |
constructor TInteractiveSQLStatementReader.Create(aPrompt: string; aContinue: string); |
1860 |
|
begin |
1861 |
|
inherited Create; |
1862 |
< |
NextStatement; |
1863 |
< |
end; |
1864 |
< |
|
1865 |
< |
destructor TIBXMLProcessor.Destroy; |
1522 |
< |
begin |
1523 |
< |
FreeMem(FBlobBuffer); |
1524 |
< |
inherited Destroy; |
1862 |
> |
FPrompt := aPrompt; |
1863 |
> |
FLineIndex := 0; |
1864 |
> |
FNextStatement := true; |
1865 |
> |
FContinuePrompt := aContinue; |
1866 |
|
end; |
1867 |
|
|
1868 |
< |
function TIBXMLProcessor.AnalyseXML(SymbolStream: TSymbolStream): string; |
1869 |
< |
var Symbol: TSQLSymbol; |
1529 |
< |
Done: boolean; |
1530 |
< |
XMLString: string; |
1868 |
> |
function TInteractiveSQLStatementReader.GetNextStatement(var stmt: string |
1869 |
> |
): boolean; |
1870 |
|
begin |
1871 |
< |
Result := ''; |
1872 |
< |
XMLString := ''; |
1534 |
< |
Done := false; |
1535 |
< |
FState := stInTag; |
1536 |
< |
FSymbolStream := SymbolStream; |
1537 |
< |
with SymbolStream do |
1538 |
< |
begin |
1539 |
< |
StartXMLTag(XMLTag); |
1540 |
< |
while not Done do |
1541 |
< |
with SymbolStream do |
1542 |
< |
begin |
1543 |
< |
Symbol := GetSymbol; |
1544 |
< |
|
1545 |
< |
case Symbol of |
1546 |
< |
sqEOL: |
1547 |
< |
case FState of |
1548 |
< |
stQuotedAttributeValue, |
1549 |
< |
stTagged: |
1550 |
< |
XMLString += LineEnding; |
1551 |
< |
end; |
1552 |
< |
|
1553 |
< |
' ',sqTab: |
1554 |
< |
case FState of |
1555 |
< |
stQuotedAttributeValue, |
1556 |
< |
stTagged: |
1557 |
< |
XMLString += ' '; |
1558 |
< |
end; |
1559 |
< |
|
1560 |
< |
';': |
1561 |
< |
case FState of |
1562 |
< |
stQuotedAttributeValue, |
1563 |
< |
stTagged: |
1564 |
< |
XMLString += ';'; |
1565 |
< |
else |
1566 |
< |
ShowError(sXMLError,[Symbol]); |
1567 |
< |
end; |
1568 |
< |
|
1569 |
< |
'''': |
1570 |
< |
case FState of |
1571 |
< |
stQuotedAttributeValue, |
1572 |
< |
stTagged: |
1573 |
< |
XMLString += ''''; |
1574 |
< |
else |
1575 |
< |
ShowError(sXMLError,[Symbol]); |
1576 |
< |
end; |
1577 |
< |
|
1578 |
< |
'*': |
1579 |
< |
case FState of |
1580 |
< |
stQuotedAttributeValue, |
1581 |
< |
stTagged: |
1582 |
< |
XMLString += '*'; |
1583 |
< |
else |
1584 |
< |
ShowError(sXMLError,[Symbol]); |
1585 |
< |
end; |
1586 |
< |
|
1587 |
< |
'/': |
1588 |
< |
case FState of |
1589 |
< |
stQuotedAttributeValue, |
1590 |
< |
stTagged: |
1591 |
< |
XMLString += '/'; |
1592 |
< |
else |
1593 |
< |
ShowError(sXMLError,[Symbol]); |
1594 |
< |
end; |
1595 |
< |
|
1596 |
< |
'>': |
1597 |
< |
case FState of |
1598 |
< |
stEndTag: |
1599 |
< |
case XMLTag of |
1600 |
< |
xtBlob: |
1601 |
< |
begin |
1602 |
< |
Result := ':' + Format(ibx_blob+'%d',[FCurrentBlob]); |
1603 |
< |
Done := true; |
1604 |
< |
end; |
1605 |
< |
xtArray: |
1606 |
< |
begin |
1607 |
< |
Result := ':' + Format(ibx_array+'%d',[FCurrentArray]); |
1608 |
< |
Done := true; |
1609 |
< |
end; |
1610 |
< |
else |
1611 |
< |
FState := stTagged; |
1612 |
< |
end; |
1613 |
< |
|
1614 |
< |
stInTag: |
1615 |
< |
begin |
1616 |
< |
XMLString := ''; |
1617 |
< |
FState := stTagged; |
1618 |
< |
EnterTag; |
1619 |
< |
end; |
1620 |
< |
|
1621 |
< |
stQuotedAttributeValue, |
1622 |
< |
stTagged: |
1623 |
< |
XMLString += '>'; |
1624 |
< |
|
1625 |
< |
else |
1626 |
< |
ShowError(sXMLError,[Symbol]); |
1627 |
< |
end; |
1628 |
< |
|
1629 |
< |
sqTag: |
1630 |
< |
if FState = stTagged then |
1631 |
< |
begin |
1632 |
< |
FState := stInTag; |
1633 |
< |
StartXMLTag(XMLTag) |
1634 |
< |
end |
1635 |
< |
else |
1636 |
< |
ShowError(sXMLError,[Symbol]); |
1637 |
< |
|
1638 |
< |
sqEndTag: |
1639 |
< |
if FState = stTagged then |
1640 |
< |
begin |
1641 |
< |
ProcessTagValue(XMLString); |
1642 |
< |
EndXMLTag(XMLTag); |
1643 |
< |
FState := stEndTag; |
1644 |
< |
end |
1645 |
< |
else |
1646 |
< |
ShowError(sXMLError,[Symbol]); |
1647 |
< |
|
1648 |
< |
'=': |
1649 |
< |
case FState of |
1650 |
< |
stAttribute: |
1651 |
< |
FState := stAttributeValue; |
1652 |
< |
|
1653 |
< |
stQuotedAttributeValue, |
1654 |
< |
stTagged: |
1655 |
< |
XMLString += '='; |
1656 |
< |
|
1657 |
< |
else |
1658 |
< |
ShowError(sXMLError,[Symbol]); |
1659 |
< |
end; |
1660 |
< |
|
1661 |
< |
'"': |
1662 |
< |
case FState of |
1663 |
< |
stAttributeValue: |
1664 |
< |
begin |
1665 |
< |
XMLString := ''; |
1666 |
< |
FState := stQuotedAttributeValue; |
1667 |
< |
end; |
1668 |
< |
|
1669 |
< |
stQuotedAttributeValue: |
1670 |
< |
begin |
1671 |
< |
ProcessAttributeValue(XMLString); |
1672 |
< |
FState := stInTag; |
1673 |
< |
end; |
1674 |
< |
|
1675 |
< |
stTagged: |
1676 |
< |
XMLString += '"'; |
1677 |
< |
|
1678 |
< |
else |
1679 |
< |
ShowError(sXMLError,[Symbol]); |
1680 |
< |
end; |
1681 |
< |
|
1682 |
< |
sqString: |
1683 |
< |
case FState of |
1684 |
< |
stInTag: {attribute name} |
1685 |
< |
begin |
1686 |
< |
FAttributeName := SymbolValue; |
1687 |
< |
FState := stAttribute; |
1688 |
< |
end; |
1689 |
< |
|
1690 |
< |
stAttributeValue: |
1691 |
< |
begin |
1692 |
< |
ProcessAttributeValue(FString); |
1693 |
< |
FState := stInTag; |
1694 |
< |
end; |
1695 |
< |
|
1696 |
< |
stQuotedAttributeValue, |
1697 |
< |
stTagged: |
1698 |
< |
XMLString += SymbolValue; |
1699 |
< |
|
1700 |
< |
else |
1701 |
< |
ShowError(sXMLError,[Symbol]); |
1702 |
< |
end; |
1703 |
< |
else |
1704 |
< |
ShowError(sXMLError,[Symbol]); |
1705 |
< |
end |
1706 |
< |
end; |
1707 |
< |
end; |
1871 |
> |
Result := inherited GetNextStatement(stmt); |
1872 |
> |
FNextStatement := Result; |
1873 |
|
end; |
1874 |
|
|
1875 |
< |
procedure TIBXMLProcessor.NextStatement; |
1711 |
< |
begin |
1712 |
< |
FXMLTagIndex := 0; |
1713 |
< |
SetLength(FBlobData,0); |
1714 |
< |
FCurrentBlob := -1; |
1715 |
< |
SetLength(FArrayData,0); |
1716 |
< |
FCurrentArray := -1; |
1717 |
< |
end; |
1875 |
> |
{ TBatchSQLStatementReader } |
1876 |
|
|
1877 |
< |
class function TIBXMLProcessor.FormatBlob(Field: ISQLData): string; |
1720 |
< |
var TextOut: TStrings; |
1877 |
> |
function TBatchSQLStatementReader.GetChar: char; |
1878 |
|
begin |
1879 |
< |
TextOut := TStringList.Create; |
1880 |
< |
try |
1881 |
< |
TextOut.Add(Format('<blob subtype="%d">',[Field.getSubtype])); |
1882 |
< |
StringToHex(Field.AsString,TextOut,BlobLineLength); |
1726 |
< |
TextOut.Add('</blob>'); |
1727 |
< |
Result := TextOut.Text; |
1728 |
< |
finally |
1729 |
< |
TextOut.Free; |
1730 |
< |
end; |
1731 |
< |
end; |
1732 |
< |
|
1733 |
< |
class function TIBXMLProcessor.FormatArray(Database: TIBDatabase; ar: IArray |
1734 |
< |
): string; |
1735 |
< |
var index: array of integer; |
1736 |
< |
TextOut: TStrings; |
1737 |
< |
|
1738 |
< |
procedure AddElements(dim: integer; indent:string = ' '); |
1739 |
< |
var i: integer; |
1740 |
< |
recurse: boolean; |
1879 |
> |
if not EOF and assigned(FInStream) and not (FInStream.Position = FInStream.Size) then |
1880 |
> |
begin |
1881 |
> |
Result := char(FInStream.ReadByte); |
1882 |
> |
if Result = LF then |
1883 |
|
begin |
1884 |
< |
SetLength(index,dim+1); |
1885 |
< |
recurse := dim < ar.GetDimensions - 1; |
1886 |
< |
with ar.GetBounds[dim] do |
1887 |
< |
for i := LowerBound to UpperBound do |
1888 |
< |
begin |
1889 |
< |
index[dim] := i; |
1890 |
< |
if recurse then |
1891 |
< |
begin |
1750 |
< |
TextOut.Add(Format('%s<elt id="%d">',[indent,i])); |
1751 |
< |
AddElements(dim+1,indent + ' '); |
1752 |
< |
TextOut.Add('</elt>'); |
1753 |
< |
end |
1754 |
< |
else |
1755 |
< |
if ((ar.GetSQLType = SQL_TEXT) or (ar.GetSQLType = SQL_VARYING)) and |
1756 |
< |
(ar.GetCharSetID = 1) then |
1757 |
< |
TextOut.Add(Format('%s<elt ix="%d">%s</elt>',[indent,i,StringToHex(ar.GetAsString(index))])) |
1758 |
< |
else |
1759 |
< |
TextOut.Add(Format('%s<elt ix="%d">%s</elt>',[indent,i,ar.GetAsString(index)])); |
1760 |
< |
end; |
1761 |
< |
end; |
1762 |
< |
|
1763 |
< |
var |
1764 |
< |
s: string; |
1765 |
< |
bounds: TArrayBounds; |
1766 |
< |
i: integer; |
1767 |
< |
boundsList: string; |
1768 |
< |
begin |
1769 |
< |
TextOut := TStringList.Create; |
1770 |
< |
try |
1771 |
< |
s := Format('<array dim = "%d" sqltype = "%d" length = "%d" relation_name = "%s" column_name = "%s"', |
1772 |
< |
[ar.GetDimensions,ar.GetSQLType,ar.GetSize, |
1773 |
< |
ar.GetTableName,ar.GetColumnName]); |
1774 |
< |
case ar.GetSQLType of |
1775 |
< |
SQL_DOUBLE, SQL_FLOAT, SQL_LONG, SQL_SHORT, SQL_D_FLOAT, SQL_INT64: |
1776 |
< |
s += Format(' scale = "%d"',[ ar.GetScale]); |
1777 |
< |
SQL_TEXT, |
1778 |
< |
SQL_VARYING: |
1779 |
< |
s += Format(' charset = "%s"',[Database.Attachment.GetCharsetName(ar.GetCharSetID)]); |
1780 |
< |
end; |
1781 |
< |
bounds := ar.GetBounds; |
1782 |
< |
boundsList := ''; |
1783 |
< |
for i := 0 to length(bounds) - 1 do |
1884 |
> |
EchoNextLine(FCurLine); |
1885 |
> |
FCurLine := ''; |
1886 |
> |
if assigned(OnProgressEvent) then |
1887 |
> |
OnProgressEvent(self,false,FIndex+1); |
1888 |
> |
Inc(FLineIndex); |
1889 |
> |
FIndex := 1; |
1890 |
> |
end |
1891 |
> |
else |
1892 |
|
begin |
1893 |
< |
if i <> 0 then boundsList += ','; |
1894 |
< |
boundsList += Format('%d:%d',[bounds[i].LowerBound,bounds[i].UpperBound]); |
1893 |
> |
FCurLine += Result; |
1894 |
> |
Inc(FIndex); |
1895 |
|
end; |
1896 |
< |
s += Format(' bounds="%s"',[boundsList]); |
1789 |
< |
s += '>'; |
1790 |
< |
TextOut.Add(s); |
1791 |
< |
|
1792 |
< |
SetLength(index,0); |
1793 |
< |
AddElements(0); |
1794 |
< |
TextOut.Add('</array>'); |
1795 |
< |
Result := TextOut.Text; |
1796 |
< |
finally |
1797 |
< |
TextOut.Free; |
1798 |
< |
end; |
1799 |
< |
end; |
1800 |
< |
|
1801 |
< |
{ TInteractiveSymbolStream } |
1802 |
< |
|
1803 |
< |
function TInteractiveSymbolStream.GetErrorPrefix: string; |
1804 |
< |
begin |
1805 |
< |
Result := ''; |
1806 |
< |
end; |
1807 |
< |
|
1808 |
< |
function TInteractiveSymbolStream.GetNextLine(var Line: string): boolean; |
1809 |
< |
begin |
1810 |
< |
if FNextStatement then |
1811 |
< |
write(FPrompt) |
1812 |
< |
else |
1813 |
< |
write(FContinuePrompt); |
1814 |
< |
Result := not EOF; |
1815 |
< |
if Result then |
1816 |
< |
readln(Line); |
1817 |
< |
end; |
1818 |
< |
|
1819 |
< |
constructor TInteractiveSymbolStream.Create(aPrompt: string; aContinue: string); |
1820 |
< |
begin |
1821 |
< |
inherited Create; |
1822 |
< |
FPrompt := aPrompt; |
1823 |
< |
FContinuePrompt := aContinue; |
1824 |
< |
end; |
1825 |
< |
|
1826 |
< |
function TInteractiveSymbolStream.GetSymbol: TSQLSymbol; |
1827 |
< |
begin |
1828 |
< |
if Terminated then |
1829 |
< |
Result := sqEOF |
1896 |
> |
end |
1897 |
|
else |
1898 |
< |
Result := inherited GetSymbol; |
1898 |
> |
Result := #0; |
1899 |
|
end; |
1900 |
|
|
1901 |
< |
{ TBatchSymbolStream } |
1835 |
< |
|
1836 |
< |
function TBatchSymbolStream.GetErrorPrefix: string; |
1901 |
> |
function TBatchSQLStatementReader.GetErrorPrefix: string; |
1902 |
|
begin |
1903 |
|
Result := Format(sOnLineError,[FLineIndex,FIndex]); |
1904 |
|
end; |
1905 |
|
|
1906 |
< |
function TBatchSymbolStream.GetNextLine(var Line: string): boolean; |
1842 |
< |
begin |
1843 |
< |
Result := FLineIndex < FLines.Count; |
1844 |
< |
if Result then |
1845 |
< |
begin |
1846 |
< |
Line := FLines[FLineIndex]; |
1847 |
< |
// writeln('Next Line = ',Line); |
1848 |
< |
Inc(FLineIndex); |
1849 |
< |
if assigned(OnProgressEvent) then |
1850 |
< |
OnProgressEvent(self,false,1); |
1851 |
< |
end; |
1852 |
< |
end; |
1853 |
< |
|
1854 |
< |
constructor TBatchSymbolStream.Create; |
1906 |
> |
procedure TBatchSQLStatementReader.Reset; |
1907 |
|
begin |
1908 |
< |
inherited Create; |
1909 |
< |
FLines := TStringList.Create; |
1910 |
< |
end; |
1911 |
< |
|
1912 |
< |
destructor TBatchSymbolStream.Destroy; |
1913 |
< |
begin |
1914 |
< |
if assigned(FLines) then FLines.Free; |
1915 |
< |
inherited Destroy; |
1916 |
< |
end; |
1917 |
< |
|
1918 |
< |
procedure TBatchSymbolStream.SetStreamSource(Lines: TStrings); |
1919 |
< |
begin |
1920 |
< |
FLineIndex := 0; |
1921 |
< |
FLines.Assign(Lines); |
1908 |
> |
inherited Reset; |
1909 |
> |
if FOwnsInStream and assigned(FInStream) then |
1910 |
> |
FInStream.Free; |
1911 |
> |
FInStream := nil; |
1912 |
> |
FOwnsInStream := false; |
1913 |
> |
FLineIndex := 1; |
1914 |
> |
FIndex := 1; |
1915 |
> |
end; |
1916 |
> |
|
1917 |
> |
procedure TBatchSQLStatementReader.SetStreamSource(Lines: TStrings); |
1918 |
> |
begin |
1919 |
> |
Reset; |
1920 |
> |
FInStream := TMemoryStream.Create; |
1921 |
> |
FOwnsInStream := true; |
1922 |
> |
Lines.SaveToStream(FInStream); |
1923 |
> |
FInStream.Position := 0; |
1924 |
|
if assigned(OnProgressEvent) then |
1925 |
< |
OnProgressEvent(self,true,FLines.Count); |
1925 |
> |
OnProgressEvent(self,true,FInStream.Size); |
1926 |
|
end; |
1927 |
|
|
1928 |
< |
procedure TBatchSymbolStream.SetStreamSource(S: TStream); |
1928 |
> |
procedure TBatchSQLStatementReader.SetStreamSource(S: TStream); |
1929 |
|
begin |
1930 |
< |
FLineIndex := 0; |
1931 |
< |
FLines.LoadFromStream(S); |
1930 |
> |
Reset; |
1931 |
> |
FInStream := S; |
1932 |
|
if assigned(OnProgressEvent) then |
1933 |
< |
OnProgressEvent(self,true,FLines.Count); |
1933 |
> |
OnProgressEvent(self,true,S.Size - S.Position); |
1934 |
|
end; |
1935 |
|
|
1936 |
< |
procedure TBatchSymbolStream.SetStreamSource(FileName: string); |
1936 |
> |
procedure TBatchSQLStatementReader.SetStreamSource(FileName: string); |
1937 |
|
begin |
1938 |
< |
FLineIndex := 0; |
1939 |
< |
FLines.LoadFromFile(FileName); |
1938 |
> |
Reset; |
1939 |
> |
FInStream := TFileStream.Create(FileName,fmShareCompat); |
1940 |
> |
FOwnsInStream := true; |
1941 |
|
if assigned(OnProgressEvent) then |
1942 |
< |
OnProgressEvent(self,true,FLines.Count); |
1888 |
< |
end; |
1889 |
< |
|
1890 |
< |
{ TSymbolStream } |
1891 |
< |
|
1892 |
< |
function TSymbolStream.GetNextSymbol(C: char): TSQLSymbol; |
1893 |
< |
begin |
1894 |
< |
Result := sqNone; |
1895 |
< |
if C = FTerminator then |
1896 |
< |
Result := sqTerminator |
1897 |
< |
else |
1898 |
< |
case C of |
1899 |
< |
#0..#8,#10..#31,' ': |
1900 |
< |
Result := ' '; |
1901 |
< |
|
1902 |
< |
#9,';','"','''','/','-', |
1903 |
< |
'*','=','>','<',',': |
1904 |
< |
Result := C; |
1905 |
< |
else |
1906 |
< |
begin |
1907 |
< |
Result := sqString; |
1908 |
< |
FLastChar := C |
1909 |
< |
end |
1910 |
< |
end; |
1911 |
< |
end; |
1912 |
< |
|
1913 |
< |
function TSymbolStream.FindTag(tag: string; var xmlTag: TXMLTag): boolean; |
1914 |
< |
var i: integer; |
1915 |
< |
begin |
1916 |
< |
Result := false; |
1917 |
< |
for i := 0 to Length(XMLTagDefs) - 1 do |
1918 |
< |
if XMLTagDefs[i].TagValue = tag then |
1919 |
< |
begin |
1920 |
< |
xmlTag := XMLTagDefs[i].XMLTag; |
1921 |
< |
Result := true; |
1922 |
< |
break; |
1923 |
< |
end; |
1924 |
< |
end; |
1925 |
< |
|
1926 |
< |
constructor TSymbolStream.Create; |
1927 |
< |
begin |
1928 |
< |
inherited; |
1929 |
< |
FTerminator := DefaultTerminator; |
1930 |
< |
NextStatement; |
1931 |
< |
end; |
1932 |
< |
|
1933 |
< |
procedure TSymbolStream.ShowError(msg: string; params: array of const); |
1934 |
< |
begin |
1935 |
< |
raise EIBClientError.CreateFmt(GetErrorPrefix + msg,params); |
1936 |
< |
end; |
1937 |
< |
|
1938 |
< |
function TSymbolStream.GetSymbol: TSQLSymbol; |
1939 |
< |
var |
1940 |
< |
DelimitedText: string; |
1941 |
< |
CurState: (gsNone,gsInComment,gsInSingleQuotes,gsInDoubleQuotes); |
1942 |
< |
begin |
1943 |
< |
Result := sqNone; |
1944 |
< |
CurState := gsNone; |
1945 |
< |
DelimitedText := ''; |
1946 |
< |
if FNextSymbol <> sqNone then |
1947 |
< |
begin |
1948 |
< |
Result := FNextSymbol; |
1949 |
< |
if Result = sqString then |
1950 |
< |
FString := FLastChar |
1951 |
< |
else |
1952 |
< |
FString := ''; |
1953 |
< |
FNextSymbol := sqNone |
1954 |
< |
end; |
1955 |
< |
|
1956 |
< |
while FNextSymbol = sqNone do {find the next symbol} |
1957 |
< |
begin |
1958 |
< |
if FIndex > Length(FLine) then |
1959 |
< |
begin |
1960 |
< |
FNextSymbol := sqEOL; |
1961 |
< |
FIndex := 0; |
1962 |
< |
end |
1963 |
< |
else |
1964 |
< |
begin |
1965 |
< |
if FIndex = 0 then |
1966 |
< |
begin |
1967 |
< |
if not GetNextLine(FLine) then |
1968 |
< |
begin |
1969 |
< |
Result := sqEOF; |
1970 |
< |
FNextSymbol := sqNone; |
1971 |
< |
Exit; |
1972 |
< |
end; |
1973 |
< |
FIndex := 1; |
1974 |
< |
FNextStatement := false; |
1975 |
< |
if assigned(OnNextLine) then |
1976 |
< |
OnNextLine(self,FLine); |
1977 |
< |
if CurState <> gsNone then |
1978 |
< |
DelimitedText += LineEnding; |
1979 |
< |
if Length(FLine) = 0 then |
1980 |
< |
continue; |
1981 |
< |
end; |
1982 |
< |
if CurState <> gsNone then |
1983 |
< |
DelimitedText += FLine[FIndex]; |
1984 |
< |
FNextSymbol := GetNextSymbol(FLine[FIndex]); |
1985 |
< |
Inc(FIndex); |
1986 |
< |
end; |
1987 |
< |
|
1988 |
< |
case CurState of |
1989 |
< |
gsNone: |
1990 |
< |
begin |
1991 |
< |
{combine if possible} |
1992 |
< |
case Result of |
1993 |
< |
sqNone: |
1994 |
< |
begin |
1995 |
< |
Result := FNextSymbol; |
1996 |
< |
if FNextSymbol = sqString then |
1997 |
< |
FString := FLastChar; |
1998 |
< |
FNextSymbol := sqNone |
1999 |
< |
end; |
2000 |
< |
|
2001 |
< |
'/': |
2002 |
< |
if FXMLMode > 0 then |
2003 |
< |
break |
2004 |
< |
else |
2005 |
< |
if FNextSymbol = '*' then |
2006 |
< |
begin |
2007 |
< |
CurState := gsInComment; |
2008 |
< |
DelimitedText := '/*'; |
2009 |
< |
Result := sqNone; |
2010 |
< |
FNextSymbol := sqNone |
2011 |
< |
end |
2012 |
< |
else |
2013 |
< |
if FNextSymbol = '/' then |
2014 |
< |
begin |
2015 |
< |
FString := '/*' + system.copy(FLine,FIndex,length(FLine)- FIndex + 1) + ' */'; |
2016 |
< |
Result := sqCommentLine; |
2017 |
< |
FIndex := 0; |
2018 |
< |
FNextSymbol := sqNone |
2019 |
< |
end; |
2020 |
< |
|
2021 |
< |
'-': |
2022 |
< |
if FXMLMode > 0 then |
2023 |
< |
break |
2024 |
< |
else |
2025 |
< |
if FNextSymbol = '-' then |
2026 |
< |
begin |
2027 |
< |
FString := '--' + system.copy(FLine,FIndex,length(FLine)- FIndex + 1) ; |
2028 |
< |
Result := sqCommentLine; |
2029 |
< |
FIndex := 0; |
2030 |
< |
FNextSymbol := sqNone |
2031 |
< |
end; |
2032 |
< |
|
2033 |
< |
'<': |
2034 |
< |
if (FXMLMode > 0) and (FNextSymbol = '/') then |
2035 |
< |
begin |
2036 |
< |
Result := sqEndTag; |
2037 |
< |
FString := ''; |
2038 |
< |
FNextSymbol := sqNone |
2039 |
< |
end |
2040 |
< |
else |
2041 |
< |
if FNextSymbol = sqString then |
2042 |
< |
begin |
2043 |
< |
Result := sqTag; |
2044 |
< |
FString := FLastChar; |
2045 |
< |
FNextSymbol := sqNone |
2046 |
< |
end; |
2047 |
< |
|
2048 |
< |
'''': |
2049 |
< |
if FXMLMode > 0 then |
2050 |
< |
break |
2051 |
< |
else |
2052 |
< |
if FNextSymbol = '''' then |
2053 |
< |
begin |
2054 |
< |
Result := sqQuotedString; |
2055 |
< |
FString := ''''''; |
2056 |
< |
FNextSymbol := sqNone |
2057 |
< |
end |
2058 |
< |
else |
2059 |
< |
begin |
2060 |
< |
CurState := gsInSingleQuotes; |
2061 |
< |
DelimitedText := ''''; |
2062 |
< |
if FNextSymbol = sqEOL then |
2063 |
< |
DelimitedText += LineEnding |
2064 |
< |
else |
2065 |
< |
DelimitedText += FLine[FIndex-1]; |
2066 |
< |
Result := sqNone; |
2067 |
< |
FNextSymbol := sqNone |
2068 |
< |
end; |
2069 |
< |
|
2070 |
< |
'"': |
2071 |
< |
if FXMLMode > 0 then |
2072 |
< |
break |
2073 |
< |
else |
2074 |
< |
begin |
2075 |
< |
CurState := gsInDoubleQuotes; |
2076 |
< |
DelimitedText := '"'; |
2077 |
< |
if FNextSymbol = sqEOL then |
2078 |
< |
DelimitedText += LineEnding |
2079 |
< |
else |
2080 |
< |
DelimitedText += FLine[FIndex-1]; |
2081 |
< |
Result := sqNone; |
2082 |
< |
FNextSymbol := sqNone |
2083 |
< |
end; |
2084 |
< |
|
2085 |
< |
sqTag, |
2086 |
< |
sqEndTag, |
2087 |
< |
sqString: |
2088 |
< |
if FNextSymbol = sqString then |
2089 |
< |
begin |
2090 |
< |
FString := FString + FLastChar; |
2091 |
< |
FNextSymbol := sqNone |
2092 |
< |
end; |
2093 |
< |
end |
2094 |
< |
end; |
2095 |
< |
|
2096 |
< |
{Check for state exit condition} |
2097 |
< |
gsInSingleQuotes: |
2098 |
< |
if Result = '''' then |
2099 |
< |
begin |
2100 |
< |
CurState := gsNone; |
2101 |
< |
if FNextSymbol = sqEOL then |
2102 |
< |
FString := DelimitedText |
2103 |
< |
else |
2104 |
< |
FString := system.copy(DelimitedText,1,Length(DelimitedText)-1); |
2105 |
< |
Result := sqQuotedString; |
2106 |
< |
end; |
2107 |
< |
|
2108 |
< |
gsInDoubleQuotes: |
2109 |
< |
if Result = '"' then |
2110 |
< |
begin |
2111 |
< |
CurState := gsNone; |
2112 |
< |
if FNextSymbol = sqEOL then |
2113 |
< |
FString := DelimitedText |
2114 |
< |
else |
2115 |
< |
FString := system.copy(DelimitedText,1,Length(DelimitedText)-1); |
2116 |
< |
Result := sqDoubleQuotedString; |
2117 |
< |
end; |
2118 |
< |
|
2119 |
< |
gsInComment: |
2120 |
< |
if (Result = '*') and (FNextSymbol = '/') then |
2121 |
< |
begin |
2122 |
< |
CurState := gsNone; |
2123 |
< |
FString := DelimitedText; |
2124 |
< |
Result := sqComment; |
2125 |
< |
FNextSymbol := sqNone |
2126 |
< |
end; |
2127 |
< |
|
2128 |
< |
end; |
2129 |
< |
|
2130 |
< |
if (CurState <> gsNone) and (FNextSymbol <> sqNone) then |
2131 |
< |
begin |
2132 |
< |
Result := FNextSymbol; |
2133 |
< |
FNextSymbol := sqNone; |
2134 |
< |
end; |
2135 |
< |
end; |
2136 |
< |
|
2137 |
< |
if (Result = sqTag) and (FNextSymbol <> sqNone) then |
2138 |
< |
begin |
2139 |
< |
if FindTag(FString,FXMLTag) then |
2140 |
< |
Inc(FXMLMode) |
2141 |
< |
else |
2142 |
< |
Result := sqString; |
2143 |
< |
end |
2144 |
< |
else |
2145 |
< |
if (Result = sqEndTag) and (FNextSymbol <> sqNone) then |
2146 |
< |
begin |
2147 |
< |
if FindTag(FString,FXMLTag) then |
2148 |
< |
Dec(FXMLMode) |
2149 |
< |
else |
2150 |
< |
Result := sqString; |
2151 |
< |
end; |
2152 |
< |
|
2153 |
< |
if (FXMLMode = 0) and (Result = sqString) and (FString <> '') then |
2154 |
< |
begin |
2155 |
< |
if CompareText(FString,'begin') = 0 then |
2156 |
< |
Result := sqBegin |
2157 |
< |
else |
2158 |
< |
if CompareText(FString,'end') = 0 then |
2159 |
< |
Result := sqEnd |
2160 |
< |
else |
2161 |
< |
if CompareText(FString,'declare') = 0 then |
2162 |
< |
Result := sqDeclare |
2163 |
< |
else |
2164 |
< |
if CompareText(FString,'case') = 0 then |
2165 |
< |
Result := sqCase |
2166 |
< |
end; |
2167 |
< |
// writeln(Result,',',FString); |
1942 |
> |
OnProgressEvent(self,true,FInStream.Size); |
1943 |
|
end; |
1944 |
|
|
1945 |
< |
procedure TSymbolStream.NextStatement; |
1945 |
> |
procedure TBatchSQLStatementReader.SetStringStreamSource(S: string); |
1946 |
|
begin |
1947 |
< |
FXMLTag := xtNone; |
1948 |
< |
FNextStatement := true; |
1947 |
> |
Reset; |
1948 |
> |
FInStream := TStringStream.Create(S); |
1949 |
> |
FOwnsInStream := true; |
1950 |
> |
if assigned(OnProgressEvent) then |
1951 |
> |
OnProgressEvent(self,true,FInStream.Size); |
1952 |
|
end; |
1953 |
|
|
1954 |
|
end. |