253 |
|
TLogEvent = procedure(Sender: TObject; Msg: string) of Object; |
254 |
|
TOnSelectSQL = procedure (Sender: TObject; SQLText: string) of object; |
255 |
|
TOnSetStatement = procedure(Sender: TObject; command, aValue, stmt: string; var Done: boolean) of object; |
256 |
+ |
TOnCreateDatabase = procedure (Sender: TObject; var DatabaseFileName: string) of object; |
257 |
|
|
258 |
|
{ TCustomIBXScript } |
259 |
|
|
275 |
|
FDatabase: TIBDatabase; |
276 |
|
FDataOutputFormatter: TIBCustomDataOutput; |
277 |
|
FIgnoreGrants: boolean; |
278 |
+ |
FOnCreateDatabase: TOnCreateDatabase; |
279 |
|
FOnErrorLog: TLogEvent; |
280 |
|
FOnSelectSQL: TOnSelectSQL; |
281 |
|
FOnSetStatement: TOnSetStatement; |
327 |
|
property OnProgressEvent: TOnProgressEvent read GetOnProgressEvent write SetOnProgressEvent; {Progress Bar Support} |
328 |
|
property OnSelectSQL: TOnSelectSQL read FOnSelectSQL write FOnSelectSQL; {Handle Select SQL Statements} |
329 |
|
property OnSetStatement: TOnSetStatement read FOnSetStatement write FOnSetStatement; |
330 |
+ |
property OnCreateDatabase: TOnCreateDatabase read FOnCreateDatabase write FOnCreateDatabase; |
331 |
|
end; |
332 |
|
|
333 |
|
{ |
566 |
|
end; |
567 |
|
|
568 |
|
procedure TCustomIBXScript.DoReconnect; |
569 |
+ |
var LoginPrompt: boolean; |
570 |
|
begin |
571 |
|
with GetTransaction do |
572 |
|
if InTransaction then Commit; |
573 |
+ |
LoginPrompt := Database.LoginPrompt; |
574 |
+ |
Database.LoginPrompt := false; |
575 |
|
Database.Connected := false; |
576 |
|
Database.Connected := true; |
577 |
+ |
Database.LoginPrompt := LoginPrompt; |
578 |
|
GetTransaction.Active := true; |
579 |
|
end; |
580 |
|
|
656 |
|
|
657 |
|
procedure TCustomIBXScript.SetDatabase(AValue: TIBDatabase); |
658 |
|
begin |
659 |
< |
if FDatabase = AValue then Exit; |
659 |
> |
if not (csLoading in ComponentState) and (FDatabase = AValue) then Exit; |
660 |
|
FDatabase := AValue; |
661 |
|
FISQL.Database := AValue; |
662 |
|
FIBXMLProcessor.Database := AValue; |
730 |
|
|
731 |
|
except on E:Exception do |
732 |
|
begin |
733 |
< |
Add2Log(Format(sStatementError,[FSymbolStream.GetErrorPrefix, |
734 |
< |
E.Message,stmt]),true); |
735 |
< |
if StopOnFirstError then Exit; |
733 |
> |
if FInternalTransaction.InTransaction then |
734 |
> |
FInternalTransaction.Rollback; |
735 |
> |
if assigned(OnErrorLog) then |
736 |
> |
begin |
737 |
> |
Add2Log(Format(sStatementError,[FSymbolStream.GetErrorPrefix, |
738 |
> |
E.Message,stmt]),true); |
739 |
> |
if StopOnFirstError then Exit; |
740 |
> |
end |
741 |
> |
else |
742 |
> |
raise; |
743 |
|
end |
744 |
|
end; |
745 |
|
Result := true; |
852 |
|
charsetid: integer; |
853 |
|
param: string; |
854 |
|
Terminator: char; |
855 |
+ |
FileName: string; |
856 |
+ |
DBConnected: boolean; |
857 |
+ |
LoginPrompt: boolean; |
858 |
|
begin |
859 |
|
Result := false; |
860 |
|
ucStmt := AnsiUpperCase(stmt); |
862 |
|
RegexObj := TRegExpr.Create; |
863 |
|
try |
864 |
|
{process create database} |
865 |
< |
RegexObj.Expression := '^ *CREATE +(DATABASE|SCHEMA) +.*(\' + Terminator + '|)'; |
865 |
> |
RegexObj.Expression := '^ *CREATE +(DATABASE|SCHEMA) +''(.*)''(.*)(\' + Terminator + '|)'; |
866 |
|
if RegexObj.Exec(ucStmt) then |
867 |
|
begin |
868 |
+ |
FileName := system.copy(stmt,RegexObj.MatchPos[2], RegexObj.MatchLen[2]); |
869 |
+ |
if assigned(FOnCreateDatabase) then |
870 |
+ |
OnCreateDatabase(self,FileName); |
871 |
+ |
stmt := 'CREATE DATABASE ''' + FileName + '''' + system.copy(stmt,RegexObj.MatchPos[3], RegexObj.MatchLen[3]); |
872 |
+ |
ucStmt := AnsiUpperCase(stmt); |
873 |
|
UpdateUserPassword; |
874 |
|
FDatabase.Connected := false; |
875 |
|
FDatabase.CreateDatabase(stmt); |
972 |
|
begin |
973 |
|
if Database.Attachment.CharSetName2CharSetID(param,charsetid) then |
974 |
|
begin |
975 |
+ |
DBConnected := Database.Connected; |
976 |
+ |
LoginPrompt := Database.LoginPrompt; |
977 |
+ |
Database.LoginPrompt := false; |
978 |
+ |
Database.Connected := false; |
979 |
|
Database.Params.Values['lc_ctype'] := param; |
980 |
< |
if Database.Connected then |
981 |
< |
DoReconnect; |
980 |
> |
Database.Connected := DBConnected; |
981 |
> |
Database.LoginPrompt := LoginPrompt; |
982 |
|
end |
983 |
|
else |
984 |
|
raise Exception.CreateFmt(sInvalidCharacterSet, [param,stmt]); |