Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 173895 Details for
Bug 319425
[compiler] JDT outputs corrupt .class file for problem type
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
.java that produces incorrect .class file.
RtSql.java (text/plain), 654.17 KB, created by
Fernando Colombo
on 2010-07-09 14:42:52 EDT
(
hide
)
Description:
.java that produces incorrect .class file.
Filename:
MIME Type:
Creator:
Fernando Colombo
Created:
2010-07-09 14:42:52 EDT
Size:
654.17 KB
patch
obsolete
>package br.com.senior.svcl.db; > >import static br.com.senior.svcl.base.Classes.*; >import static br.com.senior.svcl.base.Delphi.*; >import static br.com.senior.svcl.base.R900GPRConst.*; >import static br.com.senior.svcl.base.RtBaseUtil.*; >import static br.com.senior.svcl.base.RtDateUtil.*; >import static br.com.senior.svcl.base.RtInterfaces.*; >import static br.com.senior.svcl.base.RtIntfUtil.*; >import static br.com.senior.svcl.base.RtStrUtil.*; >import static br.com.senior.svcl.base.RtStringTranslator.*; >import static br.com.senior.svcl.base.RtTypes.*; >import static br.com.senior.svcl.base.SysInit.*; >import static br.com.senior.svcl.base.SysUtils.*; >import static br.com.senior.svcl.base.Windows.*; >import static br.com.senior.svcl.db.RtClass.*; >import static br.com.senior.svcl.db.RtCompiler.*; >import static br.com.senior.svcl.db.RtNativeInterfaces.*; >import static br.com.senior.svcl.db.RtOldCompilerUtil.*; >import static br.com.senior.svcl.db.RtSQLCompiler.*; >import static br.com.senior.svcl.db.RtStruct.*; >import static br.com.senior.svcl.db.RtStructCreator.*; >import static br.com.senior.svcl.db.RtToken.*; >import static br.com.senior.svcl.db.rtDBConst.*; >import static br.com.senior.svcl.db.rtsqlcmdparts.*; >import br.com.senior.svcl.base.DelphiSet; >import br.com.senior.svcl.base.RtStrUtil; >import br.com.senior.svcl.base.Util; >import br.com.senior.svcl.base.Classes.TComponent; >import br.com.senior.svcl.base.Classes.TList; >import br.com.senior.svcl.base.Classes.TNotifyEvent; >import br.com.senior.svcl.base.Classes.TPersistent; >import br.com.senior.svcl.base.Classes.TPersistentClass; >import br.com.senior.svcl.base.Classes.TReader; >import br.com.senior.svcl.base.Classes.TResourceStream; >import br.com.senior.svcl.base.Classes.TStream; >import br.com.senior.svcl.base.Classes.TStringList; >import br.com.senior.svcl.base.Classes.TStrings; >import br.com.senior.svcl.base.Classes.TWriter; >import br.com.senior.svcl.base.Delphi.TBoolean; >import br.com.senior.svcl.base.Delphi.TClass; >import br.com.senior.svcl.base.Delphi.TInt; >import br.com.senior.svcl.base.Delphi.TObject; >import br.com.senior.svcl.base.Delphi.TReference; >import br.com.senior.svcl.base.Delphi.TString; >import br.com.senior.svcl.base.Delphi.TVarRec; >import br.com.senior.svcl.base.RtBaseUtil.TRtOnUpdateProgress; >import br.com.senior.svcl.base.RtInterfaces.IRtCursor; >import br.com.senior.svcl.base.RtInterfaces.IRtDBBatchCommandProcessor; >import br.com.senior.svcl.base.RtInterfaces.IRtDBCommandProcessor; >import br.com.senior.svcl.base.RtInterfaces.IRtDBConnection; >import br.com.senior.svcl.base.RtInterfaces.IRtDBParam; >import br.com.senior.svcl.base.RtInterfaces.IRtDBSecurityManager; >import br.com.senior.svcl.base.RtInterfaces.IRtDatabaseDef; >import br.com.senior.svcl.base.RtInterfaces.IRtIndexDef; >import br.com.senior.svcl.base.RtInterfaces.IRtSQLStmt; >import br.com.senior.svcl.base.RtInterfaces.IRtSortInfo; >import br.com.senior.svcl.base.RtInterfaces.IRtStmt; >import br.com.senior.svcl.base.RtInterfaces.TRtTableInfo; >import br.com.senior.svcl.base.RtInterfaces.TTypeDesc; >import br.com.senior.svcl.base.RtTypes.TRtRecValueClass; >import br.com.senior.svcl.base.RtTypes.TRtSqlParam; >import br.com.senior.svcl.base.RtTypes.TRtSqlParams; >import br.com.senior.svcl.base.RtTypes.TRtSqlParamsClass; >import br.com.senior.svcl.base.SysUtils.DelphiException; >import br.com.senior.svcl.base.SysUtils.TExceptionClass; >import br.com.senior.svcl.db.RtAccess.EExAccess; >import br.com.senior.svcl.db.RtAccess.TRtDatabase; >import br.com.senior.svcl.db.RtAccess.TRtQuery; >import br.com.senior.svcl.db.RtAccess.TRtTranEvent; >import br.com.senior.svcl.db.RtBaseCursor.TRtCursorField; >import br.com.senior.svcl.db.RtClass.TContainerItem; >import br.com.senior.svcl.db.RtClass.TContainerItemClass; >import br.com.senior.svcl.db.RtClass.TKeyedContainerItem; >import br.com.senior.svcl.db.RtClass.TKeyedContainerItemClass; >import br.com.senior.svcl.db.RtClass.TKeyedListOwner; >import br.com.senior.svcl.db.RtClass.TKeyedListOwnerClass; >import br.com.senior.svcl.db.RtClass.TListOwner; >import br.com.senior.svcl.db.RtClass.TListOwnerClass; >import br.com.senior.svcl.db.RtClass.TNamedContainerItem; >import br.com.senior.svcl.db.RtClass.TNamedContainerItemClass; >import br.com.senior.svcl.db.RtClass.TNamedListOwner; >import br.com.senior.svcl.db.RtClass.TNamedListOwnerClass; >import br.com.senior.svcl.db.RtClass.TStringListOwner; >import br.com.senior.svcl.db.RtClass.TTypedListOwner; >import br.com.senior.svcl.db.RtClass.TTypedListOwnerClass; >import br.com.senior.svcl.db.RtCommProc.TRtDBBatchCommandProcessor; >import br.com.senior.svcl.db.RtCommProc.TRtDBCommandProcessor; >import br.com.senior.svcl.db.RtCompiler.ECCompiler; >import br.com.senior.svcl.db.RtCompiler.TRtCBNFData; >import br.com.senior.svcl.db.RtCompiler.TRtCCompiledNodeList; >import br.com.senior.svcl.db.RtCompiler.TRtCCompiler; >import br.com.senior.svcl.db.RtCompiler.TRtCCompilerShowErrorEvent; >import br.com.senior.svcl.db.RtDBKnl.ERtDBObjectNotFound; >import br.com.senior.svcl.db.RtDBKnl.TDBParamStrings; >import br.com.senior.svcl.db.RtDBKnl.TOnGetIRInfo; >import br.com.senior.svcl.db.RtDBKnl.TOnIdleTimeout; >import br.com.senior.svcl.db.RtDBKnl.TRtDBGenericFunctionsClass; >import br.com.senior.svcl.db.RtDBKnl.TRtDBKernel; >import br.com.senior.svcl.db.RtDBKnl.TRtDBKernelClass; >import br.com.senior.svcl.db.RtDBKnl.TRtDBKernelListClass; >import br.com.senior.svcl.db.RtDBKnl.TRtDBRawDatabase; >import br.com.senior.svcl.db.RtDBKnl.TRtDBRawSession; >import br.com.senior.svcl.db.RtNativeInterfaces.IRtBatchNativeStmtHelper; >import br.com.senior.svcl.db.RtNativeInterfaces.IRtDBNativeCommandProcessor; >import br.com.senior.svcl.db.RtNativeInterfaces.IRtDBNativeConnection; >import br.com.senior.svcl.db.RtNativeInterfaces.IRtNativeStmt; >import br.com.senior.svcl.db.RtNativeInterfaces.IRtNativeStmtHelper; >import br.com.senior.svcl.db.RtNativeInterfaces.TRtBatchNativeCtx; >import br.com.senior.svcl.db.RtParams.TRtParam; >import br.com.senior.svcl.db.RtRevEng.TRtDbCatalogsClass; >import br.com.senior.svcl.db.RtSQLCompiler.TRtSQLCompiler; >import br.com.senior.svcl.db.RtSQLCompiler.TRtSQLTokenItem; >import br.com.senior.svcl.db.RtSQLCompiler.TRtSQLTokenList; >import br.com.senior.svcl.db.RtSQLCompiler.TRtSQLTokenListClass; >import br.com.senior.svcl.db.RtSQLCompilerEx.TRtCCompiledNodeSQL; >import br.com.senior.svcl.db.RtSQLCompilerEx.TRtCCompilerSQL; >import br.com.senior.svcl.db.RtStruct.TRtDatabaseDef; >import br.com.senior.svcl.db.RtStruct.TRtDatabaseDefClass; >import br.com.senior.svcl.db.RtStruct.TRtEnumerationDef; >import br.com.senior.svcl.db.RtStruct.TRtFieldDef; >import br.com.senior.svcl.db.RtStruct.TRtIndexDef; >import br.com.senior.svcl.db.RtStruct.TRtIndexFieldDef; >import br.com.senior.svcl.db.RtStruct.TRtPhyBaseTypeClass; >import br.com.senior.svcl.db.RtStruct.TRtPhyNumberClass; >import br.com.senior.svcl.db.RtStruct.TRtPhyStringClass; >import br.com.senior.svcl.db.RtStruct.TRtRelationDef; >import br.com.senior.svcl.db.RtStruct.TRtStoredProcDef; >import br.com.senior.svcl.db.RtStruct.TRtStoredProcItem; >import br.com.senior.svcl.db.RtStruct.TRtTableDef; >import br.com.senior.svcl.db.RtStruct.TRtTriggerDef; >import br.com.senior.svcl.db.RtStruct.TRtUniqueConstraintDef; >import br.com.senior.svcl.db.RtStruct.TRtUniqueConstraintFieldDef; >import br.com.senior.svcl.db.RtStruct.TRtViewDef; >import br.com.senior.svcl.db.RtToken.TSimpleParser; >import br.com.senior.svcl.db.rtRec.TRtFullDatabaseDef; >import br.com.senior.svcl.db.rtRec.TRtFullFieldDef; >import br.com.senior.svcl.db.rtRec.TRtFullSessionDef; >import br.com.senior.svcl.db.rtRec.TRtFullTableDef; >import br.com.senior.svcl.db.rtRevDB.TRtDbRevEng; >import br.com.senior.svcl.db.rtsqlcmdparts.TNameExpr; >import br.com.senior.svcl.db.rtsqlcmdparts.TQualifiedNameExpr; >import br.com.senior.svcl.db.rtsqlcmdparts.TSelect; >import br.com.senior.svcl.db.rtsqlcmdparts.TSelectColumn; >import br.com.senior.svcl.db.rtsqlcmdparts.TStatement; >import br.com.senior.svcl.db.rtsqlcmdparts.TVisitProc; >import br.com.senior.svcl.db.rtsqlgen_senior.TRtSeniorSqlGeneratorClass; >import br.com.senior.svcl.db.rtsqlworks.TSQLStatement; >import br.com.senior.svcl.db.rtsqlworks.TSQLWorks; > >public final class RtSql { > > public interface TOnNotifyDBConnection { > > public void run(int aDBAccessKind, int aDBVersionKind); > } > > public interface TOnDBSQLGenerate { > > public String run(TStatement aStatement); > } > > public static class TRtCustomSQLClass extends TSQLContainerItemClass { > > public static final TRtCustomSQLClass SINGLETON = new TRtCustomSQLClass(); > > protected final TRtCustomSQL CreateWithDBVersionKind(int aDBVersionKind) { > return TRtCustomSQL.CreateWithDBVersionKind(aDBVersionKind); > } > > public TRtCustomSQL Create() { > return TRtCustomSQL.Create(); > } > > public TRtCustomSQL CreateSQL(TRtDBConnection AConn) { > return TRtCustomSQL.CreateSQL(AConn); > } > > public Class<? extends TRtCustomSQL> ClassInfo() { > return TRtCustomSQL.class; > } > } > > public static class TRtColumnSqlGeneratorClass extends TPersistentClass { > > public static final TRtColumnSqlGeneratorClass SINGLETON = new TRtColumnSqlGeneratorClass(); > > public String GenColumnName(TRtAddColumnItem aColumnItem) { > return aColumnItem.FColName; > } > > public String GenColumnDetailDataType(TRtAddColumnItem aColumnItem, IRtDatabaseDef aDataBaseDef, TString aKindName, TString aLength, TString aPrecision) { > String Result = ""; > aKindName.v = RtPhyFieldNames[aColumnItem.FColType]; > aLength.v = ""; > aPrecision.v = ""; > switch (aColumnItem.FColType) { > case rftString: > aLength.v = IntToStr(aColumnItem.FColLen); > aPrecision.v = ""; > Result = aKindName.v + SQL_LParenthesis + aLength.v + ToStr(SQL_RParenthesis); > break; > case rftNumber: > aLength.v = IntToStr(aColumnItem.FColLen); > Result = aKindName.v + SQL_LParenthesis + aLength.v; > if (aColumnItem.FColPrec != 0) { > aPrecision.v = IntToStr(aColumnItem.FColPrec); > Result = Result + SQL_Comma + SQL_Space + aPrecision.v; > } else { > aPrecision.v = ""; > } > Result = Result + ToStr(SQL_RParenthesis); > break; > default: > break; > } > return Result; > } > > public String GenColumnNotNull(TRtAddColumnItem aColumnItem) { > String Result = ""; > if (aColumnItem.FNotNull) { > Result = SQL_NOTNULL; > } else { > Result = SQL_NULL; > } > return Result; > } > > public String GenColumnStorage(TRtAddColumnItem aColumnItem, TRtCustomStorageList aStorage, String aTableName) { > return ""; > } > > public Class<? extends TRtColumnSqlGenerator> ClassInfo() { > return TRtColumnSqlGenerator.class; > } > } > > public static class TRtReplG6FunctionsClass extends TClass { > > private final class ClearOldTriggers_Context { > > private final TRtDBConnection aConn; > private final static String cDropTrigger = "drop trigger %s"; > private TStringList xTriggerList; > private TStringList xTableReplList; > private int i; > private IRtDBNativeCommandProcessor xCmdProc; > > public ClearOldTriggers_Context(TRtDBConnection aConn) { > this.aConn = aConn; > } > > public void execute() { > xTriggerList = aConn.GetTriggersFromDB(cREPLG6Prefix); > try { > if (xTriggerList.GetCount() > 0) { > xTableReplList = GetReplTables(aConn); > try { > xCmdProc = ((IRtDBNativeCommandProcessor) aConn.NewDBCommandProcessor()); > xCmdProc.SetNativeSQL(true); > i = 0; > while (i < xTriggerList.GetCount()) { > if (xTableReplList.IndexOf(xTriggerList.GetValue(xTriggerList.GetName(i))) == -1) { > xCmdProc.SetCommand(Format(cDropTrigger, new Object[] { xTriggerList.GetName(i) })); > xCmdProc.Execute(); > } > i++; > } > } finally { > xTableReplList.Destroy(); > } > } > } finally { > xTriggerList.Destroy(); > } > } > } > > private final class ClearTriggerFromTable_Context { > > private final String aTableName; > private final TRtDBConnection aConn; > private final static String cDropTrigger = "drop trigger %s"; > private TStringList xTriggerList; > private int i; > private IRtDBNativeCommandProcessor xCmdProc; > > public ClearTriggerFromTable_Context(String aTableName, TRtDBConnection aConn) { > this.aTableName = aTableName; > this.aConn = aConn; > } > > public void execute() { > xTriggerList = aConn.GetTriggersFromDB(cREPLG6Prefix + aTableName); > try { > xCmdProc = ((IRtDBNativeCommandProcessor) aConn.NewDBCommandProcessor()); > xCmdProc.SetNativeSQL(true); > i = 0; > while (i < xTriggerList.GetCount()) { > xCmdProc.SetCommand(Format(cDropTrigger, new Object[] { xTriggerList.GetName(i) })); > xCmdProc.Execute(); > i++; > } > } finally { > xTriggerList.Destroy(); > } > } > } > > public static final TRtReplG6FunctionsClass SINGLETON = new TRtReplG6FunctionsClass(); > > final void CreateTableTrigger(TRtDBConnection aConn, TRtTableDef aTableDef) { > IRtDBNativeCommandProcessor xCmdProc; > String xDroptrigger = ""; > if (aTableDef != null) { > xCmdProc = ((IRtDBNativeCommandProcessor) aConn.NewDBCommandProcessor()); > xCmdProc.SetNativeSQL(true); > xDroptrigger = GetDropTriggerCommand(aTableDef, ttvInsert); > if (!xDroptrigger.equals("")) { > xCmdProc.SetCommand(xDroptrigger); > xCmdProc.Execute(); > } > xDroptrigger = GetDropTriggerCommand(aTableDef, ttvUpdate); > if (!xDroptrigger.equals("")) { > xCmdProc.SetCommand(xDroptrigger); > xCmdProc.Execute(); > } > xDroptrigger = GetDropTriggerCommand(aTableDef, ttvDelete); > if (!xDroptrigger.equals("")) { > xCmdProc.SetCommand(xDroptrigger); > xCmdProc.Execute(); > } > xCmdProc.SetCommand(GenerateInsertReplTrigger(aConn, aTableDef)); > xCmdProc.Execute(); > xCmdProc.SetCommand(GenerateUpdateReplTrigger(aConn, aTableDef)); > xCmdProc.Execute(); > xCmdProc.SetCommand(GenerateDeleteReplTrigger(aConn, aTableDef)); > xCmdProc.Execute(); > } > } > > protected final TStringList GetReplTables(TRtDBConnection aConn) { > TStringList Result; > IRtDBNativeCommandProcessor xCmdProc; > IRtCursor xCursor; > Result = TStringList.Create(); > try { > if (aConn.TableExists("R900IG6")) { > xCmdProc = ((IRtDBNativeCommandProcessor) aConn.NewDBCommandProcessor()); > xCmdProc.SetNativeSQL(true); > xCmdProc.SetCommand("select TblNam from R900IG6 order by TblNam"); > xCursor = xCmdProc.Open(); > while (xCursor.Next()) { > Result.Add(xCursor.GetField(0).GetAsString()); > } > } > } catch (Throwable any) { > Result.Destroy(); > throw wrap(any); > } > return Result; > } > > protected String GenerateInsertReplTrigger(TRtDBConnection aDBConn, TRtTableDef aTableDef) { > throw DelphiException.Create(TransStr("TC643", "Integração não suportada para esse banco.", true)); > } > > protected String GenerateUpdateReplTrigger(TRtDBConnection aDBConn, TRtTableDef aTableDef) { > throw DelphiException.Create(TransStr("TC643", "Integração não suportada para esse banco.", true)); > } > > protected String GenerateDeleteReplTrigger(TRtDBConnection aDBConn, TRtTableDef aTableDef) { > throw DelphiException.Create(TransStr("TC643", "Integração não suportada para esse banco.", true)); > } > > protected String GetDropTriggerCommand(TRtTableDef aTableDef, int aTriggerEvent) { > return ""; > } > > public void CreateReplControlObjects(TRtDBConnection aConn) { > throw DelphiException.Create(TransStr("TC643", "Integração não suportada para esse banco.", true)); > } > > public void CreateReplTablesIntoTBS(TRtDBConnection aConn, TRtFullDatabaseDef aTBS) { > TStringList xReplTables; > TRtFullTableDef xTableDef; > TRtFullTableDef xReplTableDef; > TRtFullFieldDef xFieldDef; > TRtFullFieldDef xReplFieldDef; > int i; > int j; > xTableDef = aTBS.NewTableDef(cREPLG6Prefix + "CONTROLE"); > xFieldDef = xTableDef.NewFieldDef("SEQTRAN"); > xFieldDef.SetKind(TRtPhyNumberClass.SINGLETON); > xFieldDef.SetLength(9); > xFieldDef.SetPrecision(0); > xFieldDef.SetNotNull(true); > xFieldDef = xTableDef.NewFieldDef("SEQOP"); > xFieldDef.SetKind(TRtPhyNumberClass.SINGLETON); > xFieldDef.SetLength(9); > xFieldDef.SetPrecision(0); > xFieldDef.SetNotNull(true); > xFieldDef = xTableDef.NewFieldDef("CODOP"); > xFieldDef.SetKind(TRtPhyNumberClass.SINGLETON); > xFieldDef.SetLength(1); > xFieldDef.SetPrecision(0); > xFieldDef.SetNotNull(true); > xFieldDef = xTableDef.NewFieldDef("REPLTABLE"); > xFieldDef.SetKind(TRtPhyStringClass.SINGLETON); > xFieldDef.SetLength(26); > xFieldDef.SetPrecision(0); > xFieldDef.SetNotNull(true); > xFieldDef = xTableDef.NewFieldDef("TABELA"); > xFieldDef.SetKind(TRtPhyStringClass.SINGLETON); > xFieldDef.SetLength(18); > xFieldDef.SetPrecision(0); > xFieldDef.SetNotNull(true); > xFieldDef = xTableDef.NewFieldDef("CAMPOSALT"); > xFieldDef.SetKind(TRtPhyStringClass.SINGLETON); > xFieldDef.SetLength(1400); > xFieldDef.SetPrecision(0); > xFieldDef = xTableDef.NewFieldDef("STATUS"); > xFieldDef.SetKind(TRtPhyNumberClass.SINGLETON); > xFieldDef.SetLength(1); > xFieldDef.SetPrecision(0); > xTableDef.SetPrimaryKey("SEQTRAN;SEQOP"); > xReplTables = GetReplTables(aConn); > try { > for (i = 0; i <= xReplTables.GetCount() - 1; ++i) { > xTableDef = aTBS.TableByName(xReplTables.Get(i)); > if (xTableDef != null) { > xReplTableDef = aTBS.NewTableDef(cREPLG6Prefix + xTableDef.GetName()); > xReplFieldDef = xReplTableDef.NewFieldDef("SeqTran"); > xReplFieldDef.SetKind(TRtPhyNumberClass.SINGLETON); > xReplFieldDef.SetLength(9); > xReplFieldDef.SetPrecision(0); > xReplFieldDef.SetNotNull(true); > xReplFieldDef = xReplTableDef.NewFieldDef("SeqOp"); > xReplFieldDef.SetKind(TRtPhyNumberClass.SINGLETON); > xReplFieldDef.SetLength(9); > xReplFieldDef.SetPrecision(0); > xReplFieldDef.SetNotNull(true); > for (j = 0; j <= xTableDef.GetFieldCount() - 1; ++j) { > xFieldDef = xTableDef.GetField(j); > xReplFieldDef = xReplTableDef.NewFieldDef(xFieldDef.GetName()); > xReplFieldDef.SetKind(xFieldDef.GetKind()); > xReplFieldDef.SetLength(xFieldDef.GetLength()); > xReplFieldDef.SetPrecision(xFieldDef.GetPrecision()); > xReplFieldDef.SetNotNull(xFieldDef.getNotNull()); > xReplFieldDef.SetOptions(xFieldDef.GetOptions()); > } > xReplTableDef.SetPrimaryKey("SeqTran;SeqOp"); > } > } > } finally { > xReplTables.Destroy(); > } > } > > public void DropReplTablesFromTBS(TRtDBConnection aConn, TRtFullDatabaseDef aTBS) { > TStringList xReplTables; > TRtFullTableDef xTableDef; > int i; > xTableDef = aTBS.TableByName(cREPLG6Prefix + "CONTROLE"); > xTableDef.Free(); > xReplTables = GetReplTables(aConn); > try { > for (i = 0; i <= xReplTables.GetCount() - 1; ++i) { > xTableDef = aTBS.TableByName(cREPLG6Prefix + xReplTables.Get(i)); > xTableDef.Free(); > } > } finally { > xReplTables.Destroy(); > } > } > > public void ClearOldTriggers(TRtDBConnection aConn) { > ClearOldTriggers_Context ctx = new ClearOldTriggers_Context(aConn); > ctx.execute(); > } > > public void ClearTriggerFromTable(String aTableName, TRtDBConnection aConn) { > ClearTriggerFromTable_Context ctx = new ClearTriggerFromTable_Context(aTableName, aConn); > ctx.execute(); > } > > public final void CreateTriggers(TRtDBConnection aConn, TRtFullDatabaseDef aTBS) { > TStringList xReplTables; > TBoolean xEnabled = new TBoolean(); > int i; > xReplTables = GetReplTables(aConn); > try { > for (i = 0; i <= xReplTables.GetCount() - 1; ++i) { > if (!(aConn.TriggerExists(cREPLG6Prefix + xReplTables.Get(i) + "_I", xReplTables.Get(i), xEnabled) && xEnabled.v) || !(aConn.TriggerExists(cREPLG6Prefix + xReplTables.Get(i) + "_U", xReplTables.Get(i), xEnabled) && xEnabled.v) || !(aConn.TriggerExists(cREPLG6Prefix + xReplTables.Get(i) + "_D", xReplTables.Get(i), xEnabled) && xEnabled.v)) { > CreateTableTrigger(aConn, aTBS.TableByName(xReplTables.Get(i))); > } > } > } finally { > xReplTables.Destroy(); > } > } > > public void ExecBeforeBeginTran(IRtDBConnection aConn) { > } > > public void ExecBeforeCommit(IRtDBConnection aConn) { > } > > public void ExecAfterEndTran(IRtDBConnection aConn) { > } > > public boolean GetInReplG6(TRtDBConnection aConn) { > return false; > } > > public boolean ExistsTablesToRepl(TRtDBConnection aConn) { > return false; > } > > public void InitControlObjects(TRtDBConnection aConn) { > throw DelphiException.Create(TransStr("TC643", "Integração não suportada para esse banco.", true)); > } > > public void DisableRepl(TRtDBConnection aConn) { > } > > public Class<? extends TRtReplG6Functions> ClassInfo() { > return TRtReplG6Functions.class; > } > } > > public static final class EMoveDataIgnoreRowClass extends TExceptionClass { > > public static final EMoveDataIgnoreRowClass SINGLETON = new EMoveDataIgnoreRowClass(); > > public Class<? extends EMoveDataIgnoreRow> ClassInfo() { > return EMoveDataIgnoreRow.class; > } > } > > public static final class EMoveDataIgnoreRow extends DelphiException { > > public EMoveDataIgnoreRowClass ClassType() { > return EMoveDataIgnoreRowClass.SINGLETON; > } > } > > public interface TRtSQLAssignTableDefEvent { > > public void run(TRtCustomSQL ASql, TRtTableDef OldTblDef, TRtTableDef NewTblDef); > } > > public interface TRtHasCriticalChange { > > public boolean run(TRtAlterTable aAlterTable); > } > > public interface TRtSQLMustDropTableEvent { > > public void run(TRtTableDef OldTblDef, TBoolean LDrop); > } > > public interface TRtSQLMustRenameTableEvent { > > public void run(TRtTableDef NewTblDef, TString NewTableName); > } > > public interface TRtSQLMustDropStoredProcEvent { > > public void run(TRtStoredProcItem OldStoredProcItem, TBoolean LDrop); > } > > public interface TRtSQLMustDropViewEvent { > > public void run(TRtViewDef OldViewDef, TBoolean LDrop); > } > > public interface TRtSQLMustCreateViewEvent { > > public void run(TRtViewDef NewViewDef, TBoolean LCreate); > } > > public interface TRtSQLVerifyAssignObjectDef { > > public void run(TObject aObjectDef, TBoolean aForceDrop); > } > > public interface TRtDDLErrorEvent { > > public void run(TRtCustomDDL ADDL, TBoolean LRetry, int AAltStep, TRtQuery ACur, br.com.senior.svcl.db.RtAccess.TRtUpdate aNewRec); > } > > public interface TRtDDLStepEvent { > > public void run(TRtCustomDDL ADDL, int AAltStep, TRtQuery ACur, br.com.senior.svcl.db.RtAccess.TRtUpdate ANewRec); > } > > public interface TRtOnStoredProcMoveData { > > public void run(TRtDBConnection aConnection, String aTableName, boolean aCreateSP, TRtStoredProcDef aStoredProcDef); > } > > public interface TRtOnExecStoredProcMoveData { > > public void run(br.com.senior.svcl.db.RtAccess.TRtUpdate aStoredProc); > } > > public interface TRtOnCustomAlterTableUpdateData { > > public boolean run(TRtUpdate aUpdateObject, TRtDBConnection aConn); > } > > public interface TRtOnDeleteStorage { > > public void run(TRtDBConnection aDBConnection, String aStorage); > } > > public interface TRtOnAddStorageIndexClustered { > > public void run(TRtDBConnection aDBConnection, String aTable, String aIndexName, boolean isPk); > } > > public interface TRtOnAddStorageLockEscalation { > > public void run(TRtDBConnection aDBConnection, String aTable, String aOpt); > } > > public interface TRtOnApplyLockEscalationInDb { > > public void run(TRtDBConnection aDBConnection, String aTable, String aOpt); > } > > public interface TRtDBInitializeProc { > > public void run(TRtDBConnection aConn); > } > > public static final class TRtSqlDriver { > > public TRtCustomSQLClass[] SQLClasses = new TRtCustomSQLClass[0]; > public TClass DBCatalogsClass; > public TRtColumnSqlGeneratorClass ColumnSqlGeneratorClass; > public TRtDBInitializeProc DBInitProc; > public TRtSQLFunctionTableList FuncList; > public Object PLGenerator; > public TRtDBGenericFunctionsClass DBGenericFunctionsClass; > public TRtReplG6FunctionsClass ReplG6FunctionsClass; > public TRtHasCriticalChange OnHasCriticalChange; > > final void assign(TRtSqlDriver other) { > SQLClasses = other.SQLClasses; > DBCatalogsClass = other.DBCatalogsClass; > ColumnSqlGeneratorClass = other.ColumnSqlGeneratorClass; > DBInitProc = other.DBInitProc; > FuncList = other.FuncList; > PLGenerator = other.PLGenerator; > DBGenericFunctionsClass = other.DBGenericFunctionsClass; > ReplG6FunctionsClass = other.ReplG6FunctionsClass; > OnHasCriticalChange = other.OnHasCriticalChange; > } > > public TRtSqlDriver(TRtCustomSQLClass[] SQLClasses, TClass DBCatalogsClass, TRtColumnSqlGeneratorClass ColumnSqlGeneratorClass, TRtDBInitializeProc DBInitProc, TRtSQLFunctionTableList FuncList, Object PLGenerator, TRtDBGenericFunctionsClass DBGenericFunctionsClass, TRtReplG6FunctionsClass ReplG6FunctionsClass, TRtHasCriticalChange OnHasCriticalChange) { > this.SQLClasses = SQLClasses; > this.DBCatalogsClass = DBCatalogsClass; > this.ColumnSqlGeneratorClass = ColumnSqlGeneratorClass; > this.DBInitProc = DBInitProc; > this.FuncList = FuncList; > this.PLGenerator = PLGenerator; > this.DBGenericFunctionsClass = DBGenericFunctionsClass; > this.ReplG6FunctionsClass = ReplG6FunctionsClass; > this.OnHasCriticalChange = OnHasCriticalChange; > } > > public TRtSqlDriver() { > } > } > > public static final class TRtDatabaseServerClass extends TContainerItemClass { > > public static final TRtDatabaseServerClass SINGLETON = new TRtDatabaseServerClass(); > > public TRtDatabaseServer Create() { > return TRtDatabaseServer.Create(); > } > > public final TRtDatabaseServer GlobalInstance() { > return vDBServer; > } > > public Class<? extends TRtDatabaseServer> ClassInfo() { > return TRtDatabaseServer.class; > } > } > > public static final class TRtDatabaseServer extends TContainerItem { > > TListOwner FDBConnections; > TRtSqlDriver[] FSqlDrivers = new TRtSqlDriver[0]; > private final TRtDBKernelClass[] FSqlKnlClasses = new TRtDBKernelClass[0]; > private final TDBParamStrings[][] FConnectionParams = null; > private TRtCBNFData FBNFData; > private TList FRtSQLFunctionTableList; > private TList FParamsList; > > final TRtDBRawDatabase NewRawDataBase(int aDBAccessKind, int aDBVersionKind, TDBParamStrings aParams, IRtDBConnection aConn) { > TRtDBRawDatabase Result; > TRtDBKernel xDbKnl; > TRtDBKernelClass xDbKnlClass; > TRtDBRawSession xDBRawSession; > boolean xIsNewKernel; > boolean xIsNewRawSession; > xDbKnlClass = GetSqlKnl(aDBAccessKind); > xDbKnl = TRtDBKernelListClass.SINGLETON.GlobalInstance().DBKernelByClassName(xDbKnlClass.ClassName()); > if (xDbKnl == null) { > xDbKnl = TRtDBKernelListClass.SINGLETON.GlobalInstance().AddDBKernel(xDbKnlClass); > xIsNewKernel = true; > } else { > xIsNewKernel = false; > } > try { > if (xDbKnl.getDBRawSessionList().GetCount() == 0) { > xDBRawSession = xDbKnl.NewDBRawSession(); > xIsNewRawSession = true; > } else { > xIsNewRawSession = false; > xDBRawSession = xDbKnl.getDBRawSessionList().GetDBRawSession(0); > } > try { > Result = xDBRawSession.NewDBRawDataBase(aDBAccessKind, aDBVersionKind, aParams, aConn, GetDbGenericFunctionsClass(aDBVersionKind)); > } catch (Throwable any) { > if (xIsNewRawSession) { > xDbKnl.DeleteDBRawSession(xDBRawSession); > } > throw wrap(any); > } > } catch (Throwable any) { > if (xIsNewKernel) { > TRtDBKernelListClass.SINGLETON.GlobalInstance().DeleteDBKernel(xDbKnl); > } > throw wrap(any); > } > return Result; > } > > final void AddConnectionItem(TRtDBConnection AConn) { > FDBConnections.Add(AConn); > AConn.SetFOwner(FDBConnections); > } > > private final String GetNextDBConnectionName() { > String Result = ""; > int i; > if (FDBConnections.GetCount() == 0) { > Result = cDefaultDbConnectionName; > } else { > i = 0; > do { > i++; > Result = cDefaultDbConnectionName + IntToStr(i); > } while (GetDbConnectionByName(Result) != null); > } > return Result; > } > > public final TRtDBConnection GetDbConnectionByName(String Index) { > TRtDBConnection Result; > int i; > Result = null; > for (i = 0; i <= FDBConnections.GetCount() - 1; ++i) { > if (SameText((((TRtDBConnection) FDBConnections.Get(i))).getName(), Index)) { > Result = ((TRtDBConnection) FDBConnections.Get(i)); > break; > } > } > return Result; > } > > public final TRtSqlDriver GetSqlDriver(int aDBVersionKind) { > TRtSqlDriver Result = null; > Result = FSqlDrivers[aDBVersionKind]; > Assert(Result != null, Format(TransStr("TC640", "Driver \"%s\" não registrado.", true), new Object[] { cDBVersionKindNameArray[aDBVersionKind] })); > return Result; > } > > private final TRtDBKernelClass GetSqlKnl(int aDBAccessKind) { > TRtDBKernelClass Result; > Result = FSqlKnlClasses[aDBAccessKind]; > Assert(Result != null, Format(TransStr("TC641", "Kernel \"%s\" não registrado.", true), new Object[] { cDBAccessKindNameNameArray[aDBAccessKind] })); > return Result; > } > > public final TDBParamStrings GetConnectionParams(int aDBAccessKind, int aDBVersionKind) { > TDBParamStrings Result; > Result = FConnectionParams[aDBAccessKind][aDBVersionKind]; > Assert(Result != null, Format(TransStr("TC642", "Parâmetros de conexão para o banco \"%s\" via \"%s\" não registrados", true), new Object[] { cDBVersionKindNameArray[aDBVersionKind], cDBAccessKindNameNameArray[aDBAccessKind] })); > return Result; > } > > public void runCreate() { > TResourceStream Stream; > super.runCreate(); > FParamsList = TList.Create(); > FRtSQLFunctionTableList = TList.Create(); > FDBConnections = ((TListOwner) Creator(this, TListOwnerClass.SINGLETON)); > FBNFData = TRtCBNFData.Create(); > Stream = TResourceStream.Create(HInstance, "PLBNF", RT_RCDATA); > try { > FBNFData.LoadFromStream(Stream); > } finally { > Stream.Destroy(); > } > } > > public static TRtDatabaseServer Create() { > TRtDatabaseServer Result; > Result = new TRtDatabaseServer(); > Result.runCreate(); > return Result; > } > > public void Destroy() { > int i; > for (i = 0; i <= FParamsList.getCount() - 1; ++i) { > ((TObject) FParamsList.getList()[i]).Free(); > } > for (i = 0; i <= FRtSQLFunctionTableList.getCount() - 1; ++i) { > ((TObject) FRtSQLFunctionTableList.getList()[i]).Free(); > } > FParamsList.Free(); > FRtSQLFunctionTableList.Free(); > FDBConnections.Free(); > FBNFData.Free(); > super.Destroy(); > } > > public final void AssignDbConnectionsNameList(TStrings aStrings) { > int i; > for (i = 0; i <= FDBConnections.GetCount() - 1; ++i) { > aStrings.Add((((TRtDBConnection) FDBConnections.Get(i))).getName()); > } > } > > public final TRtDBConnection NewDBConnection(int aDBAccessKind, int aDBVersionKind) { > TRtDBConnection Result; > String DBConnName = ""; > DBConnName = GetNextDBConnectionName(); > Result = ((TRtDBConnection) Creator(this, TRtDBConnectionClass.SINGLETON)); > Result.InitConnection(this, aDBAccessKind, aDBVersionKind); > Result.SetName(DBConnName); > return Result; > } > > public final TRtDBConnection NewNamedDBConnection(String aName, int aDBAccessKind, int aDBVersionKind) { > TRtDBConnection Result; > if (GetDbConnectionByName(aName) != null) { > throw DelphiException.CreateFmt(TransStr("TC633", "Já existe uma conexão de banco de dados com este nome(%s)", true), new Object[] { aName }); > } > Result = NewDBConnection(aDBAccessKind, aDBVersionKind); > Result.SetName(aName); > return Result; > } > > public final void RegisterSqlDriver(int aDBVersionKind, TRtSqlDriver aSqlDriver) { > Assert(FSqlDrivers[aDBVersionKind] == null, TransStr("TC634", "Erro no Registro dos Driver SQL", true)); > FSqlDrivers[aDBVersionKind] = aSqlDriver; > } > > public final void RegisterSqlKnl(int aDBAccessKind, TRtDBKernelClass aDbKernelClass) { > Assert(FSqlKnlClasses[aDBAccessKind] == null, TransStr("TC635", "Erro no Registro do Kernel de Acesso", true)); > FSqlKnlClasses[aDBAccessKind] = aDbKernelClass; > } > > public final void RegisterConnectionParams(int aDBAccessKind, int aDBVersionKind, TDBParamStrings aDBParamStrings) { > Assert(FConnectionParams[aDBAccessKind][aDBVersionKind] == null, "Erro no Registro dos parâmetros de conexão"); > FConnectionParams[aDBAccessKind][aDBVersionKind] = aDBParamStrings; > } > > public final void UnregisterSqlDriver(int aDBVersionKind) { > Assert(FSqlDrivers[aDBVersionKind] != null, TransStr("TC634", "Erro no Registro dos Driver SQL", true)); > FSqlDrivers[aDBVersionKind] = null; > } > > public final void UnregisterSqlKnl(int aDBAccessKind) { > Assert(FSqlKnlClasses[aDBAccessKind] != null, TransStr("TC635", "Erro no Registro do Kernel de Acesso", true)); > FSqlKnlClasses[aDBAccessKind] = null; > } > > public final void UnregisterConnectionParams(int aDBAccessKind, int aDBVersionKind) { > Assert(FConnectionParams[aDBAccessKind][aDBVersionKind] != null, "Erro no Registro dos parâmetros de conexão"); > FConnectionParams[aDBAccessKind][aDBVersionKind] = null; > } > > public final TClass GetDbCatalogsClass(int aDBVersionKind) { > TClass Result; > Result = GetSqlDriver(aDBVersionKind).DBCatalogsClass; > Assert(Result != null, Format(TransStr("TC636", "Catálogos para o Driver \"%s\" não registrado.", true), new Object[] { cDBVersionKindNameArray[aDBVersionKind] })); > return Result; > } > > public final TRtDBGenericFunctionsClass GetDbGenericFunctionsClass(int aDBVersionKind) { > TRtDBGenericFunctionsClass Result; > Result = GetSqlDriver(aDBVersionKind).DBGenericFunctionsClass; > Assert(Result != null, Format(TransStr("TC637", "Funções Genéricas para o Driver \"%s\" não registradas.", true), new Object[] { cDBVersionKindNameArray[aDBVersionKind] })); > return Result; > } > > public final TRtReplG6FunctionsClass GetReplG6FunctionsClass(int aDBVersionKind) { > TRtReplG6FunctionsClass Result; > Result = GetSqlDriver(aDBVersionKind).ReplG6FunctionsClass; > Assert(Result != null, Format(TransStr("TC638", "Funções de replicação G6 para o Driver \"%s\" não registradas.", true), new Object[] { cDBVersionKindNameArray[aDBVersionKind] })); > return Result; > } > > public final TRtColumnSqlGeneratorClass GetColumnSqlGeneratorClass(int aDBVersionKind) { > TRtColumnSqlGeneratorClass Result; > Result = GetSqlDriver(aDBVersionKind).ColumnSqlGeneratorClass; > Assert(Result != null, Format(TransStr("TC639", "Gerador Sql de Colunas para o Driver \"%s\" não registrado.", true), new Object[] { cDBVersionKindNameArray[aDBVersionKind] })); > return Result; > } > > public final void SetColumnSqlGeneratorClass(int aDBVersionKind, TRtColumnSqlGeneratorClass aColumnSqlGeneratorClass) { > GetSqlDriver(aDBVersionKind).ColumnSqlGeneratorClass = aColumnSqlGeneratorClass; > } > > public final TRtCustomSQL InstanceOfSQLClass(int aSQLClassesKind, int aDBVersionKind) { > TRtSqlDriver xSqlDriver = null; > xSqlDriver = GetSqlDriver(aDBVersionKind); > return xSqlDriver.SQLClasses[aSQLClassesKind].CreateWithDBVersionKind(aDBVersionKind); > } > > public final boolean DbDriverIsRegistred(int aDBAccessKind, int aDBVersionKind) { > return FConnectionParams[aDBAccessKind][aDBVersionKind] != null; > } > > public final String GetDbDriverDescription(int aDBVersionKind) { > return cDBVersionKindNameArray[aDBVersionKind]; > } > > public final TRtDBInitializeProc GetDbInitializeProc(int aDBVersionKind) { > return GetSqlDriver(aDBVersionKind).DBInitProc; > } > > public final TRtSQLFunctionTableList GetDbDriverFunctions(int aDBVersionKind) { > return GetSqlDriver(aDBVersionKind).FuncList; > } > > public final Object GetDbPLGenerator(int aDBVersionKind) { > return GetSqlDriver(aDBVersionKind).PLGenerator; > } > > public final TRtCBNFData GetCBNFDataPtr() { > return FBNFData; > } > > public final TRtDBRawDatabase GetRawDataBaseFromAcessDatabase(TRtDatabase aDataBase) { > TRtDBRawDatabase Result; > int i; > i = 0; > while (i < FDBConnections.GetCount() && (((TRtDBConnection) FDBConnections.Get(i)).IsOpen() && ((TRtDBConnection) FDBConnections.Get(i)).GetAccess() != aDataBase || !((TRtDBConnection) FDBConnections.Get(i)).IsOpen())) { > i++; > } > if (i < FDBConnections.GetCount()) { > Result = ((TRtDBConnection) FDBConnections.Get(i)).FRawDatabase; > } else { > Result = null; > } > return Result; > } > > public final TRtDatabaseServer GlobalInstance() { > return ClassType().GlobalInstance(); > } > > public TRtDatabaseServerClass ClassType() { > return TRtDatabaseServerClass.SINGLETON; > } > } > > public static final class TCustomAlterDefIndexClusterClass extends TClass { > > public static final TCustomAlterDefIndexClusterClass SINGLETON = new TCustomAlterDefIndexClusterClass(); > > public final TCustomAlterDefIndexCluster Create(TRtDBConnection aConnection) { > return TCustomAlterDefIndexCluster.Create(aConnection); > } > > public Class<? extends TCustomAlterDefIndexCluster> ClassInfo() { > return TCustomAlterDefIndexCluster.class; > } > } > > public static final class TCustomAlterDefIndexCluster extends TObject { > > protected TRtDBConnection FConnection; > > public final void runCreate(TRtDBConnection aConnection) { > FConnection = aConnection; > } > > public static TCustomAlterDefIndexCluster Create(TRtDBConnection aConnection) { > TCustomAlterDefIndexCluster Result; > Result = new TCustomAlterDefIndexCluster(); > Result.runCreate(aConnection); > return Result; > } > > public void AddDefaultIndexCluster(String aTableName, String aIndexValue) { > } > > public void RemoveDefaultIndexCluster(String aTableName) { > } > > public void SaveAlterDefaultIndexClustered() { > } > > public TCustomAlterDefIndexClusterClass ClassType() { > return TCustomAlterDefIndexClusterClass.SINGLETON; > } > } > > public static class TRtReplG6Functions extends TObject { > > //private final void CreateTableTrigger(TRtDBConnection aConn, TRtTableDef aTableDef) { > // ClassType().CreateTableTrigger(aConn, aTableDef); > //} > > protected final TStringList GetReplTables(TRtDBConnection aConn) { > return ClassType().GetReplTables(aConn); > } > > protected String GenerateInsertReplTrigger(TRtDBConnection aDBConn, TRtTableDef aTableDef) { > return ClassType().GenerateInsertReplTrigger(aDBConn, aTableDef); > } > > protected String GenerateUpdateReplTrigger(TRtDBConnection aDBConn, TRtTableDef aTableDef) { > return ClassType().GenerateUpdateReplTrigger(aDBConn, aTableDef); > } > > protected String GenerateDeleteReplTrigger(TRtDBConnection aDBConn, TRtTableDef aTableDef) { > return ClassType().GenerateDeleteReplTrigger(aDBConn, aTableDef); > } > > protected String GetDropTriggerCommand(TRtTableDef aTableDef, int aTriggerEvent) { > return ClassType().GetDropTriggerCommand(aTableDef, aTriggerEvent); > } > > public void CreateReplControlObjects(TRtDBConnection aConn) { > ClassType().CreateReplControlObjects(aConn); > } > > public void CreateReplTablesIntoTBS(TRtDBConnection aConn, TRtFullDatabaseDef aTBS) { > ClassType().CreateReplTablesIntoTBS(aConn, aTBS); > } > > public void DropReplTablesFromTBS(TRtDBConnection aConn, TRtFullDatabaseDef aTBS) { > ClassType().DropReplTablesFromTBS(aConn, aTBS); > } > > public final void ClearOldTriggers(TRtDBConnection aConn) { > ClassType().ClearOldTriggers(aConn); > } > > public final void ClearTriggerFromTable(String aTableName, TRtDBConnection aConn) { > ClassType().ClearTriggerFromTable(aTableName, aConn); > } > > public final void CreateTriggers(TRtDBConnection aConn, TRtFullDatabaseDef aTBS) { > ClassType().CreateTriggers(aConn, aTBS); > } > > public void ExecBeforeBeginTran(IRtDBConnection aConn) { > ClassType().ExecBeforeBeginTran(aConn); > } > > public void ExecBeforeCommit(IRtDBConnection aConn) { > ClassType().ExecBeforeCommit(aConn); > } > > public void ExecAfterEndTran(IRtDBConnection aConn) { > ClassType().ExecAfterEndTran(aConn); > } > > public boolean GetInReplG6(TRtDBConnection aConn) { > return ClassType().GetInReplG6(aConn); > } > > public boolean ExistsTablesToRepl(TRtDBConnection aConn) { > return ClassType().ExistsTablesToRepl(aConn); > } > > public void InitControlObjects(TRtDBConnection aConn) { > ClassType().InitControlObjects(aConn); > } > > public void DisableRepl(TRtDBConnection aConn) { > ClassType().DisableRepl(aConn); > } > > public TRtReplG6FunctionsClass ClassType() { > return TRtReplG6FunctionsClass.SINGLETON; > } > } > > public interface TOnForceAlterTableMode { > > public boolean run(TRtAlterTable aAlterTable, TInt aMode); > } > > public interface TRtGetConversionProp { > > public Object run(int aPropID); > } > > public interface TRtOnGetTableSecurityValues { > > public DelphiSet run(String aTableName, String[] aFieldsNames); > } > > public interface TRtOnGetFieldSecurityValues { > > public DelphiSet run(String aTableName, String aFieldName); > } > > public interface TRtOnGetTableEventValues { > > public DelphiSet run(String aTableName); > } > > public interface TRtOnCreateTemporaryTables { > > public void run(); > } > > public interface TRtOnTableIsTemporary { > > public boolean run(String aTableName); > } > > public static final class TRtDBConnectionClass extends TContainerItemClass { > > public static final TRtDBConnectionClass SINGLETON = new TRtDBConnectionClass(); > > protected final TRtDBConnection CreateConnection(TRtDatabaseServer AOwner, int aDBAccessKind, int aDBVersionKind) { > return TRtDBConnection.CreateConnection(AOwner, aDBAccessKind, aDBVersionKind); > } > > public TRtDBConnection Create() { > return TRtDBConnection.Create(); > } > > public Class<? extends TRtDBConnection> ClassInfo() { > return TRtDBConnection.class; > } > } > > public static final class TRtDBConnection2 extends TContainerItem implements IRtDBConnection, IRtDBNativeConnection { > > > public static TRtDBConnection2 Create() { > return new TRtDBConnection2(); > } > > @Override > public DelphiSet AcceptStrFunctions(int aSize) { > // TODO Implement method IRtDBConnection.AcceptStrFunctions. > throw new RuntimeException("Pending implementation: IRtDBConnection.AcceptStrFunctions"); > // return null; > } > > @Override > public void Commit() { > // TODO Implement method IRtDBConnection.Commit. > throw new RuntimeException("Pending implementation: IRtDBConnection.Commit"); > // > } > > @Override > public int ExecuteDML(String aCommand, Object aParams) { > // TODO Implement method IRtDBConnection.ExecuteDML. > throw new RuntimeException("Pending implementation: IRtDBConnection.ExecuteDML"); > // return 0; > } > > @Override > public int ExecuteDMLByConst(String aCommand, Object[] aParams) { > // TODO Implement method IRtDBConnection.ExecuteDMLByConst. > throw new RuntimeException("Pending implementation: IRtDBConnection.ExecuteDMLByConst"); > // return 0; > } > > @Override > public IRtCursor ExecuteSQL(String aCommand, Object aParams, boolean aBidirectionalCursor) { > // TODO Implement method IRtDBConnection.ExecuteSQL. > throw new RuntimeException("Pending implementation: IRtDBConnection.ExecuteSQL"); > // return null; > } > > @Override > public IRtCursor ExecuteSQL(String aCommand, Object aParams) { > // TODO Implement method IRtDBConnection.ExecuteSQL. > throw new RuntimeException("Pending implementation: IRtDBConnection.ExecuteSQL"); > // return null; > } > > @Override > public IRtCursor ExecuteSQLByConst(String aCommand, Object[] aParams, boolean aBidirectionalCursor) { > // TODO Implement method IRtDBConnection.ExecuteSQLByConst. > throw new RuntimeException("Pending implementation: IRtDBConnection.ExecuteSQLByConst"); > // return null; > } > > @Override > public IRtCursor ExecuteSQLByConst(String aCommand, Object[] aParams) { > // TODO Implement method IRtDBConnection.ExecuteSQLByConst. > throw new RuntimeException("Pending implementation: IRtDBConnection.ExecuteSQLByConst"); > // return null; > } > > @Override > public void FreeIDValue(String aID) { > // TODO Implement method IRtDBConnection.FreeIDValue. > throw new RuntimeException("Pending implementation: IRtDBConnection.FreeIDValue"); > // > } > > @Override > public void FreeKeyValue(String aTableName, Object[] aValues) { > // TODO Implement method IRtDBConnection.FreeKeyValue. > throw new RuntimeException("Pending implementation: IRtDBConnection.FreeKeyValue"); > // > } > > @Override > public boolean GetCanUseInCompare(TTypeDesc aTypeDesc) { > // TODO Implement method IRtDBConnection.GetCanUseInCompare. > throw new RuntimeException("Pending implementation: IRtDBConnection.GetCanUseInCompare"); > // return false; > } > > @Override > public double GetDBDateTime() { > // TODO Implement method IRtDBConnection.GetDBDateTime. > throw new RuntimeException("Pending implementation: IRtDBConnection.GetDBDateTime"); > // return 0; > } > > @Override > public IRtDatabaseDef GetDatabaseDef() { > // TODO Implement method IRtDBConnection.GetDatabaseDef. > throw new RuntimeException("Pending implementation: IRtDBConnection.GetDatabaseDef"); > // return null; > } > > @Override > public int GetNextIDValue(boolean aUseSameTransaction, String aID, int aIncrement) { > // TODO Implement method IRtDBConnection.GetNextIDValue. > throw new RuntimeException("Pending implementation: IRtDBConnection.GetNextIDValue"); > // return 0; > } > > @Override > public int GetNextIDValue(String aID) { > // TODO Implement method IRtDBConnection.GetNextIDValue. > throw new RuntimeException("Pending implementation: IRtDBConnection.GetNextIDValue"); > // return 0; > } > > @Override > public int GetNextKeyValue(boolean aUseSameTransaction, String aTableName, Object[] aValues, int aIncrement, boolean aIgnoreOldValues) { > // TODO Implement method IRtDBConnection.GetNextKeyValue. > throw new RuntimeException("Pending implementation: IRtDBConnection.GetNextKeyValue"); > // return 0; > } > > @Override > public int GetNextKeyValue(String aTableName, Object[] aValues) { > // TODO Implement method IRtDBConnection.GetNextKeyValue. > throw new RuntimeException("Pending implementation: IRtDBConnection.GetNextKeyValue"); > // return 0; > } > > @Override > public IRtDBConnection GetParallel() { > // TODO Implement method IRtDBConnection.GetParallel. > throw new RuntimeException("Pending implementation: IRtDBConnection.GetParallel"); > // return null; > } > > @Override > public int GetRowSetSize() { > // TODO Implement method IRtDBConnection.GetRowSetSize. > throw new RuntimeException("Pending implementation: IRtDBConnection.GetRowSetSize"); > // return 0; > } > > @Override > public IRtDBSecurityManager GetSecurityManager() { > // TODO Implement method IRtDBConnection.GetSecurityManager. > throw new RuntimeException("Pending implementation: IRtDBConnection.GetSecurityManager"); > // return null; > } > > @Override > public IRtSortInfo GetSortInfo() { > // TODO Implement method IRtDBConnection.GetSortInfo. > throw new RuntimeException("Pending implementation: IRtDBConnection.GetSortInfo"); > // return null; > } > > @Override > public int GetTransactionLevel() { > // TODO Implement method IRtDBConnection.GetTransactionLevel. > throw new RuntimeException("Pending implementation: IRtDBConnection.GetTransactionLevel"); > // return 0; > } > > @Override > public IRtDBBatchCommandProcessor NewDBBatchCommandProcessor() { > // TODO Implement method IRtDBConnection.NewDBBatchCommandProcessor. > throw new RuntimeException("Pending implementation: IRtDBConnection.NewDBBatchCommandProcessor"); > // return null; > } > > @Override > public IRtDBCommandProcessor NewDBCommandProcessor() { > // TODO Implement method IRtDBConnection.NewDBCommandProcessor. > throw new RuntimeException("Pending implementation: IRtDBConnection.NewDBCommandProcessor"); > // return null; > } > > @Override > public IRtStmt NewStmtFromCommand(String aCommand) { > // TODO Implement method IRtDBConnection.NewStmtFromCommand. > throw new RuntimeException("Pending implementation: IRtDBConnection.NewStmtFromCommand"); > // return null; > } > > @Override > public void Rollback() { > // TODO Implement method IRtDBConnection.Rollback. > throw new RuntimeException("Pending implementation: IRtDBConnection.Rollback"); > // > } > > @Override > public void SetRowSetSize(int aValue) { > // TODO Implement method IRtDBConnection.SetRowSetSize. > throw new RuntimeException("Pending implementation: IRtDBConnection.SetRowSetSize"); > // > } > > @Override > public void SetSecurityManager(IRtDBSecurityManager aSecurityManager) { > // TODO Implement method IRtDBConnection.SetSecurityManager. > throw new RuntimeException("Pending implementation: IRtDBConnection.SetSecurityManager"); > // > } > > @Override > public void StartTransaction() { > // TODO Implement method IRtDBConnection.StartTransaction. > throw new RuntimeException("Pending implementation: IRtDBConnection.StartTransaction"); > // > } > > @Override > public IRtDBConnection iClone() { > // TODO Implement method IRtDBConnection.iClone. > throw new RuntimeException("Pending implementation: IRtDBConnection.iClone"); > // return null; > } > > @Override > public void BeginBusinessOperation(int BusinessTransactionId) { > // TODO Implement method IRtDBCustomConnection.BeginBusinessOperation. > throw new RuntimeException("Pending implementation: IRtDBCustomConnection.BeginBusinessOperation"); > // > } > > @Override > public void CommitBusinessOperation(String UndoData) { > // TODO Implement method IRtDBCustomConnection.CommitBusinessOperation. > throw new RuntimeException("Pending implementation: IRtDBCustomConnection.CommitBusinessOperation"); > // > } > > @Override > public void CommitBusinessTransaction() { > // TODO Implement method IRtDBCustomConnection.CommitBusinessTransaction. > throw new RuntimeException("Pending implementation: IRtDBCustomConnection.CommitBusinessTransaction"); > // > } > > @Override > public int CurrentBusinessTransactionId() { > // TODO Implement method IRtDBCustomConnection.CurrentBusinessTransactionId. > throw new RuntimeException("Pending implementation: IRtDBCustomConnection.CurrentBusinessTransactionId"); > // return 0; > } > > @Override > public void RollbackBusinessOperation() { > // TODO Implement method IRtDBCustomConnection.RollbackBusinessOperation. > throw new RuntimeException("Pending implementation: IRtDBCustomConnection.RollbackBusinessOperation"); > // > } > > @Override > public void RollbackBusinessTransaction() { > // TODO Implement method IRtDBCustomConnection.RollbackBusinessTransaction. > throw new RuntimeException("Pending implementation: IRtDBCustomConnection.RollbackBusinessTransaction"); > // > } > > @Override > public int StartBusinessTransaction() { > // TODO Implement method IRtDBCustomConnection.StartBusinessTransaction. > throw new RuntimeException("Pending implementation: IRtDBCustomConnection.StartBusinessTransaction"); > // return 0; > } > > @Override > public <T> int QueryInterface(Class<T> IID, TReference<T> Obj) { > // TODO Implement method IUnknown.QueryInterface. > throw new RuntimeException("Pending implementation: IUnknown.QueryInterface"); > // return 0; > } > > @Override > public int _AddRef() { > // TODO Implement method IUnknown._AddRef. > throw new RuntimeException("Pending implementation: IUnknown._AddRef"); > // return 0; > } > > @Override > public int _Release() { > // TODO Implement method IUnknown._Release. > throw new RuntimeException("Pending implementation: IUnknown._Release"); > // return 0; > } > > @Override > public DelphiSet GetAccessOptions(int aStmtKind, TRtTableInfo[] aTableInfo) { > // TODO Implement method IRtDBNativeConnection.GetAccessOptions. > throw new RuntimeException("Pending implementation: IRtDBNativeConnection.GetAccessOptions"); > // return null; > } > > @Override > public int GetDBType() { > // TODO Implement method IRtDBNativeConnection.GetDBType. > throw new RuntimeException("Pending implementation: IRtDBNativeConnection.GetDBType"); > // return 0; > } > > @Override > public boolean GetSupportNestedTransaction() { > // TODO Implement method IRtDBNativeConnection.GetSupportNestedTransaction. > throw new RuntimeException("Pending implementation: IRtDBNativeConnection.GetSupportNestedTransaction"); > // return false; > } > > @Override > public String NativeParsedBatchSqlFromStmt(IRtNativeStmt aStmt, int[] aParamsPosArray) { > // TODO Implement method IRtDBNativeConnection.NativeParsedBatchSqlFromStmt. > throw new RuntimeException("Pending implementation: IRtDBNativeConnection.NativeParsedBatchSqlFromStmt"); > // return null; > } > > @Override > public String NativeParsedSqlFromStmt(IRtNativeStmt aStmt, int[] aParamsPosArray) { > // TODO Implement method IRtDBNativeConnection.NativeParsedSqlFromStmt. > throw new RuntimeException("Pending implementation: IRtDBNativeConnection.NativeParsedSqlFromStmt"); > // return null; > } > > @Override > public String NativeSqlFromStmt(IRtNativeStmt aStmt) { > // TODO Implement method IRtDBNativeConnection.NativeSqlFromStmt. > throw new RuntimeException("Pending implementation: IRtDBNativeConnection.NativeSqlFromStmt"); > // return null; > } > > @Override > public IRtBatchNativeStmtHelper NewBatchNativeStmtHelper(TRtBatchNativeCtx aCtx) { > // TODO Implement method IRtDBNativeConnection.NewBatchNativeStmtHelper. > throw new RuntimeException("Pending implementation: IRtDBNativeConnection.NewBatchNativeStmtHelper"); > // return null; > } > > @Override > public IRtNativeStmt NewNativeStmtFromCommand(String aCommand) { > // TODO Implement method IRtDBNativeConnection.NewNativeStmtFromCommand. > throw new RuntimeException("Pending implementation: IRtDBNativeConnection.NewNativeStmtFromCommand"); > // return null; > } > > @Override > public IRtNativeStmtHelper NewNativeStmtHelper() { > // TODO Implement method IRtDBNativeConnection.NewNativeStmtHelper. > throw new RuntimeException("Pending implementation: IRtDBNativeConnection.NewNativeStmtHelper"); > // return null; > } > > public void Open() { > } > > public TRtDatabase GetAccess() { > return null; > } > > } > > public static final class TRtDBConnection extends TContainerItem implements IRtDBConnection, IRtDBNativeConnection { > > private final class QueryInterface_Context<T> { > > private final Class<T> IID; > private final TReference<T> Obj; > private int Result; > private final static int E_NOINTERFACE = (int) 0x80004002L; > > public QueryInterface_Context(Class<T> IID, TReference<T> Obj) { > this.IID = IID; > this.Obj = Obj; > } > > public int execute() { > if (GetInterface(IID, Obj)) { > Result = 0; > } else { > Result = E_NOINTERFACE; > } > return Result; > } > } > > private final class MonitorTableVerify_Context { > > private final int aCommandKind; > private final String aTableName; > private boolean Result; > private final int[] cEvents = new int[] { (int) -1, (int) -1, tdloInsert, tdloUpdate, tdloDelete, (int) -1 }; > > public MonitorTableVerify_Context(int aCommandKind, String aTableName) { > this.aCommandKind = aCommandKind; > this.aTableName = aTableName; > } > > public boolean execute() { > Result = false; > if (cEvents[aCommandKind] != (int) -1 && FOnGetTableEventValues != null) { > Result = FOnGetTableEventValues.run(aTableName).contains(cEvents[aCommandKind]); > } > return Result; > } > } > > private final class AccessTableVerify_Context { > > private final int aCommandKind; > private final TRtTableInfo aTableInfo; > private final TRtTableInfo aAccessDenied; > private boolean Result; > > private int TablePermissionsByCommandKind(int aCommandKind) { > int Result; > if (aCommandKind == nskSelect) { > Result = tdpSelect; > } else if (aCommandKind == nskInsert) { > Result = tdpInsert; > } else if (aCommandKind == nskUpdate) { > Result = tdpUpdate; > } else if (aCommandKind == nskDelete) { > Result = tdpDelete; > } else { > throw DelphiException.Create(TransStr("TC644", "Tipo de comando não cadastrado para verificação de permissão", true)); > } > return Result; > } > > public AccessTableVerify_Context(int aCommandKind, TRtTableInfo aTableInfo, TRtTableInfo aAccessDenied) { > this.aCommandKind = aCommandKind; > this.aTableInfo = aTableInfo; > this.aAccessDenied = aAccessDenied; > } > > public boolean execute() { > Result = true; > if (FOnGetTableSecurityValues != null) { > Result = FOnGetTableSecurityValues.run(aTableInfo.TableName, aTableInfo.FieldsNames).contains(TablePermissionsByCommandKind(aCommandKind)); > if (!Result) { > aAccessDenied.TableName = aTableInfo.TableName; > } > } > return Result; > } > } > > private final class StartBusinessTransaction_Context { > > private int NextCodTra() { > int Result; > IRtDBCommandProcessor Cmd; > IRtCursor Cursor; > StartTransaction(); > Cmd = NewDBCommandProcessor(); > Cmd.SetCommand("update R999TPX set CodPrxTra = CodPrxTra + 1"); > Cmd.Prepare(); > switch (Cmd.Execute()) { > case 0: > Result = 1; > Cmd.SetCommand("insert into R999TPX (CodPrxTra) values (1)"); > Cmd.Prepare(); > if (Cmd.Execute() != 1) { > throw DelphiException.Create("Erro ao adquirir um novo identificador de transação de negócios."); > } > break; > case 1: > Cmd.SetCommand("select CodPrxTra from R999TPX"); > Cmd.Prepare(); > Cursor = Cmd.Open(); > try { > if (!Cursor.Next()) { > Assert(false); > } > Result = Cursor.FieldByName("CodPrxTra").GetAsInteger(); > } finally { > Cursor.Close(); > } > break; > default: > Rollback(); > throw DelphiException.Create("Multiplas linhas afetadas."); > } > Commit(); > return Result; > } > > private IRtDBCommandProcessor Cmd; > private int CodPrxTra; > > public StartBusinessTransaction_Context() { > } > > public int execute() { > CheckNotInBusinessTransaction(); > CheckNotInBusinessOperation(); > CheckNotInTransaction(); > try { > CodPrxTra = NextCodTra(); > } catch (EExAccess E) { > CodPrxTra = NextCodTra(); > } > BeginTran(); > Cmd = NewDBCommandProcessor(); > Cmd.SetCommand("insert R999TRA (CodTra, DesTra) values (:CodTra, :DesTra)"); > Cmd.ParamByName("CodTra").SetAsInteger(CodPrxTra); > Cmd.ParamByName("DesTra").SetAsString("ACTIVE"); > Cmd.Prepare(); > if (Cmd.Execute() != 1) { > throw DelphiException.Create("Erro ao inicar a transação de negócio."); > } > FInBusinessTransaction = true; > FBusinessTransactionId = CodPrxTra; > return FBusinessTransactionId; > } > } > > private final class CommitBusinessOperation_Context { > > private final String UndoData; > > private int NextCodTraDet() { > int Result; > IRtDBCommandProcessor Cmd; > IRtCursor C; > Cmd = NewDBCommandProcessor(); > Cmd.SetCommand("insert into R999TRD (CodTra, CodTraDet) values (:CodTra, -1)"); > Cmd.ParamByName("CodTra").SetAsInteger(FBusinessTransactionId); > Cmd.Prepare(); > Cmd.Execute(); > Cmd.SetCommand("select max(CodTraDet) from R999TRD where CodTra = :CodTra and CodTraDet > -1"); > Cmd.ParamByName("CodTra").SetAsInteger(FBusinessTransactionId); > Cmd.Prepare(); > C = Cmd.Open(); > try { > if (C.Next()) { > Result = C.GetField(0).GetAsInteger() + 1; > } else { > Result = 1; > } > } finally { > C.Close(); > } > Cmd.SetCommand("delete from R999TRD where CodTra = :CodTra and CodTraDet = -1"); > Cmd.ParamByName("CodTra").SetAsInteger(FBusinessTransactionId); > Cmd.Prepare(); > Cmd.Execute(); > return Result; > } > > private IRtDBCommandProcessor Cmd; > private int CodTraDet; > > public CommitBusinessOperation_Context(String UndoData) { > this.UndoData = UndoData; > } > > public void execute() { > CheckNotInBusinessTransaction(); > CheckInBusinessOperation(); > CheckRootTransactionLevel(); > CodTraDet = NextCodTraDet(); > Cmd = NewDBCommandProcessor(); > Cmd.SetCommand("insert into R999TRD (CodTra, CodTraDet, BinTraDet) values (:CodTra, :CodTraDet, :BinTraDet)"); > Cmd.ParamByName("CodTra").SetAsInteger(FBusinessTransactionId); > Cmd.ParamByName("CodTraDet").SetAsInteger(CodTraDet); > Cmd.ParamByName("BinTraDet").SetAsBlob(UndoData); > Cmd.Prepare(); > if (Cmd.Execute() != 1) { > throw DelphiException.Create("Erro ao finalizar a operação de negócio."); > } > FInBusinessOperation = false; > try { > Commit(); > } catch (Throwable any) { > FInBusinessOperation = true; > throw wrap(any); > } > FBusinessTransactionId = -1; > } > } > > private final class AssignFromDatabaseDef_Context { > > private final int aLevelAlterTableMode; > private final TRtDatabaseDef NewDbDef; > private final DelphiSet AAssOpt; > private final TRtGetConversionProp aGetConversionProp; > private int i; > private TRtCustomSQL ASQL; > private TRtAlterTable AT; > private final TBoolean LDrop = new TBoolean(); > private final TBoolean LCreate = new TBoolean(); > private final TString NewTblName = new TString(); > private String xDBNameSpecificSP = ""; > private TRtTableDef ATmpTblDef; > private TRtTableDef ATblDef; > private TRtStoredProcItem ASPItem; > private TRtStoredProcItem AOldSPItem; > private TRtViewDef AViewDef; > private TRtViewDef AOldViewDef; > private TStringList xForceDropTableList; > private TStringList xExcludeForceAlterTableList; > > private void ProcessAlterTables() { > TInt xMode = new TInt(); > int i; > for (i = 0; i <= FSQLList.GetCount() - 1; ++i) { > ASQL = ((TRtCustomSQL) FSQLList.Get(i)); > if (ASQL instanceof TRtAlterTable) { > if (getOnForceAlterTableMode() != null && xExcludeForceAlterTableList.IndexOf(((TRtAlterTable) ASQL).GetTableName()) == -1) { > xMode.v = ((TRtAlterTable) ASQL).GetAlterTableMode(); > if (getOnForceAlterTableMode().run((TRtAlterTable) ASQL, xMode)) { > ((TRtAlterTable) ASQL).SetAlterTableMode(xMode.v); > } > } > if (((TRtAlterTable) ASQL).GetAlterTableMode() == atmAlterTable) { > if (((TRtAlterTable) ASQL).GetDATNeedForceModifyAllFks()) { > ((TRtAlterTable) ASQL).ForceModifyAllFks(); > } > ((TRtAlterTable) ASQL).ForceModifyAllTriggers(); > } > ((TRtAlterTable) ASQL).DoImplicitChanges(); > } > } > } > > private boolean ViewsxSPsChanged() { > TBoolean Result = new TBoolean(); > TRtStoredProcDef xProcDef; > int i; > for (i = 0; i <= FPhyDatabase.GetViewCount() - 1; ++i) { > Result.v = NewDbDef.ViewByName(FPhyDatabase.GetView(i).GetName()) == null; > if (!Result.v && getOnVerifyAssignObjectDef() != null) { > getOnVerifyAssignObjectDef().run(FPhyDatabase.GetView(i), Result); > } > if (Result.v) { > return Result.v; > } > } > for (i = 0; i <= NewDbDef.GetViewCount() - 1; ++i) { > AViewDef = NewDbDef.GetView(i); > AOldViewDef = FPhyDatabase.ViewByName(AViewDef.GetName()); > Result.v = AOldViewDef == null || CompareText(AViewDef.getSelectSQL(), AOldViewDef.getSelectSQL()) != 0; > if (Result.v) { > return Result.v; > } > } > for (i = 0; i <= FPhyDatabase.GetStoredProcCount() - 1; ++i) { > Result.v = NewDbDef.StoredProcByName(FPhyDatabase.GetStoredProc(i).GetName()) == null; > if (Result.v) { > return Result.v; > } > } > for (i = 0; i <= NewDbDef.GetStoredProcCount() - 1; ++i) { > ASPItem = NewDbDef.GetStoredProc(i).GetSpecificCodes(xDBNameSpecificSP, NewDbDef.getCustomerCode()); > xProcDef = FPhyDatabase.StoredProcByName(ASPItem.GetOwnerStoredProcDef().GetName()); > if (xProcDef != null) { > AOldSPItem = xProcDef.GetSpecificCodes(xDBNameSpecificSP, FPhyDatabase.getCustomerCode()); > } else { > AOldSPItem = null; > } > Result.v = ASPItem == null || AOldSPItem == null; > if (Result.v) { > if (ASPItem == AOldSPItem) { > continue; > } > return Result.v; > } > Result.v = CompareText(ASPItem.GetDatabaseName(), AOldSPItem.GetDatabaseName()) != 0 || CompareText(ASPItem.getCode(), AOldSPItem.getCode()) != 0; > if (Result.v) { > return Result.v; > } > } > Result.v = false; > return Result.v; > } > > private void ProcessDropTable(TRtTableDef _TblDef) { > TRtAlterTable AT; > int i; > TRtRelationDef xRelDef; > TRtForeignKeyItem xRelItem; > if (AAssOpt.contains(raaForeignKeys)) { > if (_TblDef.GetRelationCount() > 0) { > AT = SQLAlterTable(); > AT.setLevelAlterTableMode(aLevelAlterTableMode); > AT.SetTableName(_TblDef.GetName()); > for (i = 0; i <= _TblDef.GetRelationCount() - 1; ++i) { > xRelDef = ATblDef.GetRelation(i); > if (CompareText(xRelDef.getForeignTable().GetName(), _TblDef.GetName()) == 0) { > xRelItem = AT.FForeignKeys.AddForeignKey(xRelDef.GetName(), xRelDef.getReferenceTable().GetName()); > xRelItem.SetOption(rcaDrop); > xRelItem.FForeignTable = xRelDef.getForeignTable().GetName(); > } > } > } > } > } > > private boolean xUseNewOperationKind; > > public AssignFromDatabaseDef_Context(int aLevelAlterTableMode, TRtDatabaseDef NewDbDef, DelphiSet AAssOpt, TRtGetConversionProp aGetConversionProp) { > this.aLevelAlterTableMode = aLevelAlterTableMode; > this.NewDbDef = NewDbDef; > this.AAssOpt = AAssOpt; > this.aGetConversionProp = aGetConversionProp; > } > > public void execute() { > if (FSQLList.GetCount() > 0) { > throw DelphiException.Create(TransStr("TC650", "Já existem objetos SQL sobre esta conexão.", true)); > } > if (NewDbDef == null) { > throw DelphiException.Create(TransStr("TC651", "Parâmetro para o DatabaseDef é nulo.", true)); > } > Assert(aGetConversionProp != null, TransStr("TC5145", "aGetConversionProp não pode ser nulo.")); > xUseNewOperationKind = VarToBoolean(aGetConversionProp.run(cpiUseNewOperationKind)); > SetNewDatabase(NewDbDef); > try { > xExcludeForceAlterTableList = TStringList.Create(); > try { > xDBNameSpecificSP = GetDBNameSpecificSPByDBVersionKind(FDBVersionKind); > xForceDropTableList = TStringList.Create(); > try { > for (i = 0; i <= FPhyDatabase.GetTableCount() - 1; ++i) { > ATblDef = FPhyDatabase.GetTable(i); > LDrop.v = false; > if (getOnVerifyAssignObjectDef() != null) { > getOnVerifyAssignObjectDef().run(ATblDef, LDrop); > if (LDrop.v) { > xForceDropTableList.Add(ATblDef.GetName()); > } > } > if (NewDbDef.TableByName(ATblDef.GetName()) == null || LDrop.v) { > LDrop.v = true; > if (!FDisableEvents && FOnMustDropTable != null) { > FOnMustDropTable.run(ATblDef, LDrop); > } > if (LDrop.v) { > ASQL = SQLDropTable(); > ((TRtDropTable) ASQL).SetTableName(ATblDef.GetName()); > ((TRtDropTable) ASQL).SetRIntOpt(rroCascade); > ProcessDropTable(ATblDef); > xExcludeForceAlterTableList.Add(ATblDef.GetName()); > } > } > } > for (i = 0; i <= NewDbDef.GetTableCount() - 1; ++i) { > ATblDef = NewDbDef.GetTable(i); > NewTblName.v = ""; > if (!FDisableEvents && FOnMustRenameTable != null) { > FOnMustRenameTable.run(ATblDef, NewTblName); > } > if (!StrIsBlank(NewTblName.v)) { > ASQL = SQLRenameTable(); > ((TRtRenameTable) ASQL).SetTableName(ATblDef.GetName()); > ((TRtRenameTable) ASQL).SetNewTableName(NewTblName.v); > } else { > ASQL = null; > try { > if (FPhyDatabase.TableByName(ATblDef.GetName()) == null) { > ASQL = SQLCreateTable(); > ((TRtCreateTable) ASQL).AssignFromTableDef(ATblDef, AAssOpt); > if (AAssOpt.contains(raaForeignKeys) && ((TRtCreateTable) ASQL).GetOperations(raaForeignKeys) != DelphiSet.get() || ((TRtCreateTable) ASQL).GetOperations(raaTriggers) != DelphiSet.get()) { > ASQL.Free(); > ASQL = SQLCreateTable(); > ((TRtCreateTable) ASQL).AssignFromTableDef(ATblDef, AAssOpt.sub(DelphiSet.get(raaForeignKeys, raaTriggers))); > ATmpTblDef = FPhyDatabase.NewTableDef(ATblDef.GetName()); > ((TRtCreateTable) ASQL).AssignToTableDef(ATmpTblDef, AAssOpt.sub(DelphiSet.get(raaForeignKeys, raaTriggers))); > AT = SQLAlterTable(); > AT.setLevelAlterTableMode(aLevelAlterTableMode); > AT.AssignFromTableDef(ATblDef, DelphiSet.get(raaForeignKeys, raaTriggers)); > } > xExcludeForceAlterTableList.Add(ATblDef.GetName()); > } else { > ASQL = SQLAlterTable(); > ((TRtAlterTable) ASQL).setUseNewOperationKind(xUseNewOperationKind); > if (xForceDropTableList.IndexOf(ATblDef.GetName()) == -1) { > ((TRtAlterTable) ASQL).setLevelAlterTableMode(aLevelAlterTableMode); > ((TRtAlterTable) ASQL).AssignFromTableDef(ATblDef, AAssOpt); > } > } > if (!ASQL.GetHasOperation() && (!VersionTBSRotGreaterOrEqual(FNewDatabase, 5, 5, 0, 21) || getStorage().StorageByName(DBGenericFunctions().GetPartitionTableName(ATblDef.GetName())) == null)) { > ASQL.Free(); > } > } catch (Throwable any) { > ASQL.Free(); > throw wrap(any); > } > } > } > } finally { > xForceDropTableList.Destroy(); > } > ProcessAlterTables(); > } finally { > xExcludeForceAlterTableList.Free(); > } > if (FSQLList.GetCount() > 0 || ViewsxSPsChanged()) { > if (AAssOpt.contains(raaStoredProcedures)) { > for (i = 0; i <= FPhyDatabase.GetStoredProcCount() - 1; ++i) { > ASPItem = FPhyDatabase.GetStoredProc(i).GetSpecificCodes(xDBNameSpecificSP, FPhyDatabase.getCustomerCode()); > if (ASPItem != null) { > LDrop.v = true; > if (!FDisableEvents && FOnMustDropStoredProc != null) { > FOnMustDropStoredProc.run(ASPItem, LDrop); > } > if (LDrop.v) { > ASQL = SQLDropProcedure(); > ((TRtDropProcedure) ASQL).SetProcedureName(ASPItem.GetOwnerStoredProcDef().GetName()); > } > } > } > for (i = 0; i <= NewDbDef.GetStoredProcCount() - 1; ++i) { > ASPItem = NewDbDef.GetStoredProc(i).GetSpecificCodes(xDBNameSpecificSP, NewDbDef.getCustomerCode()); > if (ASPItem != null) { > ASQL = null; > try { > ASQL = SQLCreateProcedure(); > ((TRtCreateProcedure) ASQL).AssignFromStoredProcItem(ASPItem); > } catch (Throwable any) { > ASQL.Free(); > throw wrap(any); > } > } > } > } > if (AAssOpt.contains(raaViews)) { > for (i = 0; i <= FPhyDatabase.GetViewCount() - 1; ++i) { > AViewDef = FPhyDatabase.GetView(i); > LDrop.v = true; > if (!FDisableEvents && FOnMustDropView != null) { > FOnMustDropView.run(AViewDef, LDrop); > } > if (LDrop.v) { > ASQL = SQLDropView(); > ((TRtDropView) ASQL).setViewName(AViewDef.GetName()); > } > } > for (i = 0; i <= NewDbDef.GetViewCount() - 1; ++i) { > AViewDef = NewDbDef.GetView(i); > LCreate.v = true; > if (FOnMustCreateView != null) { > FOnMustCreateView.run(AViewDef, LCreate); > } > if (LCreate.v) { > ASQL = null; > try { > ASQL = SQLCreateView(); > ((TRtCreateView) ASQL).setViewName(AViewDef.GetName()); > switch (AViewDef.getSQLKind()) { > case skSenior2: > ((TRtCreateView) ASQL).SetSelect_SeniorSQL_2(CompileViewSelect(NewDbDef, AViewDef.GetName(), AViewDef.getSelectSQL())); > break; > case skSenior1: > ((TRtCreateView) ASQL).SetSelect_SeniorSQL_1(((TRtSelect) SQLObjectFrom(AViewDef.getSelectSQL()))); > break; > case skNative: > ((TRtCreateView) ASQL).setSelect_NativeSQL(AViewDef.getSelectSQL()); > break; > default: > break; > } > } catch (Throwable any) { > ASQL.Free(); > throw wrap(any); > } > } > } > } > } > } finally { > SetNewDatabase(null); > } > } > } > > private TRtOnCreateTemporaryTables FOnCreateTemporaryTables; > private TRtOnTableIsTemporary FOnTableIsTemporary; > > public final boolean GetSupportNestedTransaction() { > return FRawDatabase.GetNestedTrans(); > } > > public final IRtNativeStmtHelper NewNativeStmtHelper() { > CheckIsOpen(); > return FRawDatabase.NewNativeStmtHelper(); > } > > public final IRtBatchNativeStmtHelper NewBatchNativeStmtHelper(TRtBatchNativeCtx aCtx) { > CheckIsOpen(); > return FRawDatabase.NewBatchNativeStmtHelper(aCtx); > } > > public final IRtNativeStmt NewNativeStmtFromCommand(String aCommand) { > return GetSQLWorks().CompileStatement(aCommand); > } > > public final String NativeSqlFromStmt(IRtNativeStmt aStmt) { > return DBGenericFunctions().SeniorSqlToNativeSql((TStatement) aStmt.CompiledData()); > } > > public final String NativeParsedSqlFromStmt(IRtNativeStmt aStmt, int[] aParamsPosArray) { > return DBGenericFunctions().SeniorSqlToNativeParsedSql((TStatement) aStmt.CompiledData(), FRawDatabase.GetParamMark(), aParamsPosArray); > } > > public final String NativeParsedBatchSqlFromStmt(IRtNativeStmt aStmt, int[] aParamsPosArray) { > throw DelphiException.Create("Unsupported Operation"); > } > > public final IRtDBConnection iClone() { > return CloneConnection(); > } > > public final IRtDBConnection GetParallel() { > FParallelTimer.Free(); > if (FParallelConn == null) { > FParallelConn = iClone(); > } > FParallelTimer = TParallelTimer.CreateTimer(this); > return FParallelConn; > } > > public final void StartTransaction() { > BeginTran(); > } > > public final IRtDBCommandProcessor NewDBCommandProcessor() { > CheckIsOpen(); > return TRtDBCommandProcessor.Create(this); > } > > public final IRtDBBatchCommandProcessor NewDBBatchCommandProcessor() { > CheckIsOpen(); > return TRtDBBatchCommandProcessor.Create(this); > } > > //private final IRtCursor IExecuteSQL(String aCommand, Object aParams, boolean aBidirectionalCursor) { > // return ExecuteSQL(SeniorSql_2ToNativeSql(aCommand), aParams); > //} > > //private final IRtCursor IExecuteSQL(String aCommand, Object aParams) { > // return IExecuteSQL(aCommand, aParams, false); > //} > > //private final IRtCursor IExecuteSQLByConst(String aCommand, Object[] aParams, boolean aBidirectionalCursor) { > // return ExecuteSQLByConst(SeniorSql_2ToNativeSql(aCommand), aParams, aBidirectionalCursor); > //} > > //private final IRtCursor IExecuteSQLByConst(String aCommand, Object[] aParams) { > // return IExecuteSQLByConst(aCommand, aParams, false); > //} > > public final int GetTransactionLevel() { > return FRawDatabase.GetTransactionLevel(); > } > > public final IRtDatabaseDef GetDatabaseDef() { > return getPhyDatabase(); > } > > public final int GetRowSetSize() { > return FRowSetSize; > } > > public final IRtDBSecurityManager GetSecurityManager() { > return FIRtSecurityManager; > } > > public final void SetRowSetSize(int aValue) { > FRowSetSize = aValue; > } > > public final void SetSecurityManager(IRtDBSecurityManager aSecurityManager) { > FIRtSecurityManager = aSecurityManager; > } > > public final DelphiSet AcceptStrFunctions(int aSize) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetAcceptStrFunctions(aSize); > } > > public final boolean GetCanUseInCompare(TTypeDesc aTypeDesc) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetCanUseInCompare(aTypeDesc); > } > > public final IRtSortInfo GetSortInfo() { > return RtStrUtil.GetSortInfo(getName()); > } > > public final int ExecuteDML(String aCommand, Object aParams) { > IRtDBCommandProcessor xDBCmdPrcr; > int i; > int j; > xDBCmdPrcr = NewDBCommandProcessor(); > xDBCmdPrcr.SetCommand(aCommand); > j = xDBCmdPrcr.GetValueCount() - 1; > if (j >= 0) { > if (VarIsArray(aParams)) { > for (i = 0; i <= j; ++i) { > xDBCmdPrcr.GetParam(i).SetAsVariant(VarArrayGet(aParams, i)); > } > } else { > xDBCmdPrcr.GetParam(0).SetAsVariant(aParams); > } > } > return xDBCmdPrcr.Execute(); > } > > public final int ExecuteDMLByConst(String aCommand, Object[] aParams) { > return ExecuteDML(aCommand, ArrayOfConstToVarArray(aParams)); > } > > public final IRtCursor ExecuteSQL(String aCommand, Object aParams, boolean aBidirectionalCursor) { > IRtCursor Result; > TRtQuery xQuery; > int i; > int j; > xQuery = GetAccess().NewQuery(); > try { > xQuery.SetCommand(aCommand); > j = xQuery.GetParamCount() - 1; > if (j >= 0) { > if (VarIsArray(aParams)) { > i = VarArrayHighBound(aParams, 1); > if (i < j) { > j = i; > } > for (i = 0; i <= j; ++i) { > xQuery.GetParams(i).SetAsVariant(VarArrayGet(aParams, i)); > } > } else { > xQuery.GetParams(0).SetAsVariant(aParams); > } > } > } catch (Throwable any) { > xQuery.Destroy(); > throw wrap(any); > } > Result = xQuery; > Result.Open(); > return Result; > } > > public final IRtCursor ExecuteSQL(String aCommand, Object aParams) { > return ExecuteSQL(aCommand, aParams, false); > } > > public final IRtCursor ExecuteSQLByConst(String aCommand, Object[] aParams, boolean aBidirectionalCursor) { > return ExecuteSQL(aCommand, ArrayOfConstToVarArray(aParams)); > } > > public final IRtCursor ExecuteSQLByConst(String aCommand, Object[] aParams) { > return ExecuteSQLByConst(aCommand, aParams, false); > } > > public final int GetNextKeyValue(boolean aUseSameTransaction, String aTableName, Object[] aValues, int aIncrement, boolean aIgnoreOldValues) { > TStringList xCacheSelects; > IRtIndexDef xIndexDef; > String[] xStrValues = null; > String xSelectFmt = ""; > int i; > xIndexDef = GetPKFromTable(this, aTableName); > xStrValues = GenerateNextValueStrKeyValues(xIndexDef, aValues); > if (!aIgnoreOldValues) { > xCacheSelects = GetCacheSelectNextValue(); > xSelectFmt = xCacheSelects.GetValue(aTableName); > if (xSelectFmt.equals("")) { > xSelectFmt = DBGenericFunctions().GenNextValueSelectFmt(xIndexDef); > xCacheSelects.SetValue(aTableName, xSelectFmt); > } > for (i = 0; i <= xIndexDef.GetIndexFieldCount() - 2; ++i) { > xSelectFmt = StringReplace(xSelectFmt, "$param", xStrValues[i], DelphiSet.get()); > } > } else { > xSelectFmt = " "; > } > return DBGenericFunctions().GetNextValue(this, GenerateNextValueKey(aTableName, xStrValues), xSelectFmt, aIncrement, aUseSameTransaction || GetTransactionLevel() == 0); > } > > public final int GetNextKeyValue(String aTableName, Object[] aValues) { > return GetNextKeyValue(false, aTableName, aValues, 1, false); > } > > public final void FreeKeyValue(String aTableName, Object[] aValues) { > String[] xStrValues = null; > xStrValues = GenerateNextValueStrKeyValues(GetPKFromTable(this, aTableName), aValues); > DBGenericFunctions().FreeNextValueKey(this, GenerateNextValueKey(aTableName, xStrValues)); > } > > public final int GetNextIDValue(boolean aUseSameTransaction, String aID, int aIncrement) { > return DBGenericFunctions().GetNextValue(this, aID, " ", aIncrement, aUseSameTransaction || GetTransactionLevel() == 0); > } > > public final int GetNextIDValue(String aID) { > return GetNextIDValue(false, aID, 1); > } > > public final void FreeIDValue(String aID) { > DBGenericFunctions().FreeNextValueKey(this, aID); > } > > final DelphiSet GetAccessOptions(IRtSQLStmt aSQLStmt) { > IRtNativeStmt xStmt; > xStmt = (IRtNativeStmt) aSQLStmt; > return GetAccessOptions(xStmt.NativeStmtKind(), aSQLStmt.GetTableInfoArray()); > } > > public final void SetOnCreateTemporaryTables(TRtOnCreateTemporaryTables Value) { > FOnCreateTemporaryTables.run(); > } > > public final void SetOnTableIsTemporary(TRtOnTableIsTemporary Value) { > FOnTableIsTemporary = Value; > } > > public <T> int QueryInterface(Class<T> IID, TReference<T> Obj) { > QueryInterface_Context ctx = new QueryInterface_Context(IID, Obj); > return ctx.execute(); > } > > int FDBVersionKind; > private int FDBAccessKind; > private double FDBDateTime; > private long FTickCount; > private boolean FGetDateFromDB; > private String FName; > private String FCompilErrs; > private int FSQLProcessMode; > private TRtCustomStorageList FStorageList; > private TRtCustomTablePrivilegesList FTablePrivilegesList; > private TStringList FSortLanguageList; > private TComponent FComponentOwner; > private int FRowSetSize; > private TSQLWorks FSQLWorks; > private IRtDBSecurityManager FIRtSecurityManager; > TRtOnGetTableSecurityValues FOnGetTableSecurityValues; > private TRtOnGetFieldSecurityValues FOnGetFieldSecurityValues; > TRtOnGetTableEventValues FOnGetTableEventValues; > TObject FParallelTimer; > IRtDBConnection FParallelConn; > private TStringList FCacheSelectNextValue; > private TRtOnDeleteStorage FOnDeleteStorage; > private TRtOnAddStorageIndexClustered FOnAddStorageIndexClustered; > private TRtOnAddStorageLockEscalation FOnAddStorageLockEscalation; > private TRtOnApplyLockEscalationInDb FOnApplyLockEscalationInDb; > private TCustomAlterDefIndexCluster FCustomAlterDefValue; > > private final TStringList GetCacheSelectNextValue() { > if (FCacheSelectNextValue == null) { > FCacheSelectNextValue = TStringList.Create(); > } > return FCacheSelectNextValue; > } > > private boolean MonitorTableVerify(int aCommandKind, String aTableName) { > MonitorTableVerify_Context ctx = new MonitorTableVerify_Context(aCommandKind, aTableName); > return ctx.execute(); > } > > private boolean AccessTableVerify(int aCommandKind, TRtTableInfo aTableInfo, TRtTableInfo aAccessDenied) { > AccessTableVerify_Context ctx = new AccessTableVerify_Context(aCommandKind, aTableInfo, aAccessDenied); > return ctx.execute(); > } > > private final void CheckOnOffIrEvent() { > if (FRawDatabase != null && getPhyDatabase() == null) { > FRawDatabase.setOnGetIRInfo(null); > } else if (FRawDatabase != null && getPhyDatabase() != null) { > TOnGetIRInfo proc = new TOnGetIRInfo() { > > public boolean run(String aIrName, TString aToTableName, TString aToFields, TString aFromTableName, TString aFromFields) { > return getPhyDatabase().GetIrInfo(aIrName, aToTableName, aToFields, aFromTableName, aFromFields); > } > > }; > FRawDatabase.setOnGetIRInfo(proc); > } > } > > private final TRtDatabaseServer CheckOwnerServer() { > return ((TRtDatabaseServer) CheckTypedOwner(TRtDatabaseServerClass.SINGLETON)); > } > > public final void SetSQLProcessMode(int Value) { > FSQLProcessMode = Value; > } > > final void CatchErrors(String AErrMess, int aErrCode) { > if (aErrCode != CERR_COMPILEERR) { > FCompilErrs = FCompilErrs + AErrMess + EOL; > } > } > > public final TRtCCompiler GetSQLCompiler() { > if (FSQLCompiler == null) { > FSQLCompiler = TRtCCompilerSQL.Create(); > ((TRtCCompilerSQL) FSQLCompiler).setCompileToEOF(true); > ((TRtCCompilerSQL) FSQLCompiler).SetBNFData(TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetCBNFDataPtr()); > TRtCCompilerShowErrorEvent proc = new TRtCCompilerShowErrorEvent() { > > public void run(String AErrMess, int aErrCode) { > CatchErrors(AErrMess, aErrCode); > } > > }; > ((TRtCCompilerSQL) FSQLCompiler).setOnShowError(proc); > } > FCompilErrs = ""; > return FSQLCompiler; > } > > public final TRtDatabase GetAccess() { > CheckIsOpen(); > if (FRtDatabase == null) { > FRtDatabase = FRawDatabase.GetAccess(); > FRtDatabase.setDatabaseDef(FPhyDatabase); > } > return FRtDatabase; > } > > public final void SetUseShortMessageError(boolean Value) { > FRawDatabase.setUseShortMessageError(Value); > } > > public final boolean GetUseShortMessageError() { > return FRawDatabase.getUseShortMessageError(); > } > > public final void SetName(String Value) { > TRtDBConnection xDBConnection; > xDBConnection = CheckOwnerServer().GetDbConnectionByName(Value); > if (xDBConnection == null) { > FName = Value; > } else if (xDBConnection != this) { > throw DelphiException.CreateFmt(TransStr("TC633", "Já existe uma conexão de banco de dados com este nome(%s)", true), new Object[] { Value }); > } > } > > public final int GetDBType() { > return DbVersionKindWithDBAccessKind(FDBVersionKind, FDBAccessKind); > } > > public final String GetUserName() { > String Result = ""; > switch (getDBAccessKind()) { > case dbakBDE: > Result = getParam().GetValues(cBDEUserName); > break; > case dbakDBXpressBorland: > case dbakDBXpressODBC: > Result = getParam().GetValues(cDBXUserName); > break; > case dbakOCI: > Result = getParam().GetValues(cOCIUserName); > break; > default: > break; > } > return Result; > } > > public final String GetPassword() { > String Result = ""; > switch (getDBAccessKind()) { > case dbakBDE: > Result = getParam().GetValues(cBDEPassWord); > break; > case dbakDBXpressBorland: > case dbakDBXpressODBC: > Result = getParam().GetValues(cDBXPassword); > break; > case dbakOCI: > Result = getParam().GetValues(cOCIPassword); > break; > default: > break; > } > return Result; > } > > private final double DWordToDateTime(long MSec) { > return (double) MSec / 86400000; > } > > private final double GetDBDateTimeWithTimeZone() { > double Result; > long xTickCount; > xTickCount = GetTickCount(); > Result = FDBDateTime + DWordToDateTime(xTickCount - FTickCount); > if (FGetDateFromDB || FTickCount == 0 || FTickCount > xTickCount || Trunc(FDBDateTime) != Trunc(Result)) { > FTickCount = xTickCount; > FDBDateTime = (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).CurrentDateWithTimeZone(this); > Result = FDBDateTime; > } > return Result; > } > > private final double GetDBDateTimeWithoutTimeZone() { > double Result; > long xTickCount; > xTickCount = GetTickCount(); > if (FGetDateFromDB || FTickCount == 0 || FTickCount > xTickCount) { > FTickCount = xTickCount; > FDBDateTime = (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).CurrentDate(this); > Result = FDBDateTime; > } else { > Result = FDBDateTime + DWordToDateTime(xTickCount - FTickCount); > } > return Result; > } > > public final void SetUseTimeZone(boolean aUseTimeZone) { > if (FUseTimeZone != aUseTimeZone) { > FTickCount = 0; > FUseTimeZone = aUseTimeZone; > DBGenericFunctions().SetUseTimeZoneSqlGenerator(FUseTimeZone); > } > } > > protected TRtDatabaseServer FOwner; > protected TRtDBRawDatabase FRawDatabase; > protected TRtDatabase FRtDatabase; > protected TDBParamStrings FParams; > protected TRtDBInitializeProc FDBInitProc; > protected TListOwner FSQLList; > protected TRtDatabaseDef FPhyDatabase; > protected TRtDatabaseDef FNewDatabase; > protected boolean FCheckedDataTableSpace; > protected String FDataTableSpace; > protected boolean FCheckedIndexTableSpace; > protected String FIndexTableSpace; > protected boolean FIgnoreSortErrors; > protected TRtCCompiler FSQLCompiler; > protected boolean FNotUpdatePhyDatabase; > protected boolean FDisableEvents; > protected TRtSQLAssignTableDefEvent FOnBeforeAssignFromTableDef; > protected TRtSQLAssignTableDefEvent FOnAfterAssignFromTableDef; > protected TRtSQLAssignTableDefEvent FOnBeforeAssignToTableDef; > protected TRtSQLAssignTableDefEvent FOnAfterAssignToTableDef; > protected TRtSQLMustDropTableEvent FOnMustDropTable; > protected TRtSQLMustDropStoredProcEvent FOnMustDropStoredProc; > protected TRtSQLMustDropViewEvent FOnMustDropView; > protected TRtSQLMustCreateViewEvent FOnMustCreateView; > protected TRtSQLMustRenameTableEvent FOnMustRenameTable; > protected TRtDDLErrorEvent FOnDDLError; > protected TRtDDLStepEvent FOnBeforeDDLStep; > protected TOnForceAlterTableMode FOnForceAlterTableMode; > protected boolean FUseTimeZone; > protected TRtSQLVerifyAssignObjectDef FOnVerifyAssignObjectDef; > protected String FDBUserID; > > protected final void InitConnection(TRtDatabaseServer aOwner, int aDBAccessKind, int aDBVersionKind) { > TDBParamStrings xParams; > FOwner = aOwner; > FDBAccessKind = aDBAccessKind; > FDBVersionKind = aDBVersionKind; > aOwner.AddConnectionItem(this); > xParams = aOwner.GetConnectionParams(FDBAccessKind, FDBVersionKind); > if (xParams != null) { > FParams.Assign(xParams); > } > FDBInitProc = aOwner.GetDbInitializeProc(FDBVersionKind); > if (vOnCreateDBConnection != null) { > vOnCreateDBConnection.run(FDBAccessKind, FDBVersionKind); > } > } > > public final String GetDataTableSpace() { > if (!FCheckedDataTableSpace && !FDataTableSpace.equals("")) { > if (!(((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(getDBVersionKind()))).IsValidTableSpace(this, FDataTableSpace)) { > FDataTableSpace = ""; > } > FCheckedDataTableSpace = true; > } > return FDataTableSpace; > } > > public final void SetDataTableSpace(String aDataTableSpace) { > FCheckedDataTableSpace = FCheckedDataTableSpace && CompareText(FDataTableSpace, Trim(aDataTableSpace)) == 0; > FDataTableSpace = Trim(aDataTableSpace); > } > > public final String GetIndexTableSpace() { > if (!FCheckedIndexTableSpace && !FIndexTableSpace.equals("")) { > if (!(((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(getDBVersionKind()))).IsValidTableSpace(this, FIndexTableSpace)) { > FIndexTableSpace = ""; > } > FCheckedIndexTableSpace = true; > } > return FIndexTableSpace; > } > > public final void SetIndexTableSpace(String aIndexTableSpace) { > FCheckedIndexTableSpace = FCheckedIndexTableSpace && CompareText(FIndexTableSpace, Trim(aIndexTableSpace)) == 0; > FIndexTableSpace = Trim(aIndexTableSpace); > } > > protected final void AddSQL(TRtCustomSQL ASql) { > if (FPhyDatabase == null) { > if (!(ASql instanceof TRtCreateTable) && !(ASql instanceof TRtCreateIndex) && !(ASql instanceof TRtCreateProcedure) && !(ASql instanceof TRtDropProcedure) && !(ASql instanceof TRtCreateView) && !(ASql instanceof TRtDropView) && ASql instanceof TRtCustomDDL) { > throw DelphiException.Create(TransStr("TC645", "É necessário definir o Database físico.", true)); > } > } > ASql.InitSQLKernel(this); > FSQLList.Add(ASql); > ASql.SetFOwner(FSQLList); > } > > public final void SetPhyDatabase(TRtDatabaseDef Value) { > if (FSQLList.GetCount() > 0) { > throw DelphiException.Create(TransStr("TC646", "Já existem objetos SQL em uso.", true)); > } > FreeAndNil(AsVar(FSQLWorks)); > FPhyDatabase = Value; > CheckOnOffIrEvent(); > if (FRtDatabase != null) { > FRtDatabase.setDatabaseDef(FPhyDatabase); > } > } > > public final void SetNewDatabase(TRtDatabaseDef Value) { > FNewDatabase = Value; > } > > public final TRtDatabaseDef GetNewDatabase() { > TRtDatabaseDef Result; > Result = FNewDatabase; > if (Result == null) { > Result = FPhyDatabase; > } > return Result; > } > > protected final TSQLStatement InternalSelectSQLSenior_2(TRtDatabaseDef aDatabase, String aSelectSQLSenior_2, boolean aConsistTypes) { > TSQLStatement Result; > TSQLWorks xSQLWorks; > xSQLWorks = TSQLWorks.Create(aDatabase); > try { > xSQLWorks.SetConsistTypes(aConsistTypes); > Result = xSQLWorks.CompileStatement(aSelectSQLSenior_2); > if (getRawDatabase().GetTransactionLevel() > 0 && vUseRowLockForDML) { > if (Result.getStatement().Kind == skUpdate) { > Result.getStatement().Update.TableRef.XLock = true; > } else if (Result.getStatement().Kind == skDelete) { > Result.getStatement().Delete.TableRef.XLock = true; > } > } > } finally { > xSQLWorks.Free(); > } > return Result; > } > > protected final TSQLStatement InternalSelectSQLSenior_2(TRtDatabaseDef aDatabase, String aSelectSQLSenior_2) { > return InternalSelectSQLSenior_2(aDatabase, aSelectSQLSenior_2, true); > } > > protected final void CheckIsOpen() { > if (!IsOpen()) { > throw DelphiException.Create(TransStr("TC652", "A conexão está fechada.", true)); > } > } > > public final boolean GetInTransaction() { > CheckIsOpen(); > return FRawDatabase.GetInTransaction(); > } > > public final int GetSQLObjectCount() { > return FSQLList.GetCount(); > } > > public final TRtCustomSQL GetSQLObjects(int Index) { > return ((TRtCustomSQL) FSQLList.Get(Index)); > } > > protected final void ExecuteInitSqlCommands() { > TReference<IRtDBNativeCommandProcessor> xNativeComProc = new TReference<IRtDBNativeCommandProcessor>(); > IRtDBCommandProcessor xComProc; > String xCommands = ""; > TInt xPChar = new TInt(); > String xCommand = ""; > int i; > i = getParam().IndexOfName(cGlobalInitSqlCommands); > if (i != -1) { > xCommands = getParam().GetValuesByIndex(i); > xPChar.v = 0; > xCommand = StrGetNextToken(xCommands, xPChar, ";"); > xComProc = NewDBCommandProcessor(); > xComProc.QueryInterface(IRtDBNativeCommandProcessor.class, xNativeComProc); > Assert(xNativeComProc.v != null, TransStr("TC647", "IRtDBNativeCommandProcessor não suportado", true)); > xNativeComProc.v.SetNativeSQL(true); > while (!xCommand.equals("")) { > xNativeComProc.v.SetCommand(xCommand); > try { > xNativeComProc.v.Execute(); > } catch (DelphiException E) { > //Application.MessageBox(((CharPointer) TransStrFmt("TC3293", "Erro executando comandos de inicialização%0:s Verifique o seu Arquivo de configuração(*.CFG)%1:s Error(\"%2:s\")", new Object[] { '\r', '\r', E.getMessage() }, true)), ((CharPointer) TransStr("TC89", "Erro")), MB_OK | MB_ICONERROR); > throw pending(); > } > xCommand = StrGetNextToken(xCommand, xPChar, ";"); > } > } > RegisterSortInfo(getName(), (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetSortInfo(this, FIgnoreSortErrors)); > } > > public final TSQLWorks GetSQLWorks() { > if (FSQLWorks == null) { > FSQLWorks = TSQLWorks.Create(FPhyDatabase); > } > return FSQLWorks; > } > > public final int GetDBKind() { > return DbVersionKindToDbKind(getDBVersionKind()); > } > > public final int GetDBConnectedVersionKind() { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetDbVersionKind(this); > } > > public final boolean GetEnabledSortLanguage() { > return FSortLanguageList != null; > } > > public final void SetEnabledSortLanguage(boolean aValue) { > if (aValue) { > if (FSortLanguageList == null) { > FSortLanguageList = TStringList.Create(); > } > } else { > FreeAndNil(AsVar(FSortLanguageList)); > } > } > > public final boolean GetUseCollationRule() { > boolean Result; > Result = false; > try { > if (DelphiSet.get(dbkOracle, dbkSQLServer, dbkDB2, dbkSybSvr).contains(DbVersionKindToDbKind(FDBVersionKind))) { > Result = StrToIntDef(DoR900GPRGetFlagValue(this, cFlagSortMode), 0) >= StrToInt(cFlagSortMode_CollationRule); > } > } catch (ERtDBObjectNotFound any) {} > return Result; > } > > public final void SetUseCollationRule(boolean aValue) { > try { > if (DoR900GPRGetFlagValue(this, cFlagSortMode).equals(ToStr(cFlagSortMode_BD))) { > throw DelphiException.Create(TransStr("TC675", "Já está sendo usado linguagem do banco de dados para ordenação, por isso a regra não pode ser configurada.", true)); > } > if (aValue) { > DoR900GPRSetFlag(this, cFlagSortMode, ToStr(cFlagSortMode_CollationRule)); > } else { > DoR900GPRSetFlag(this, cFlagSortMode, ToStr(cFlagSortMode_Binary)); > } > } catch (ERtDBObjectNotFound any) {} > } > > public final String GetCollationRule(int aRuleCode) { > String Result = ""; > IRtDBCommandProcessor xCmdProc; > IRtCursor xCursor; > TStringList xText; > xCmdProc = NewDBCommandProcessor(); > xCmdProc.SetCommand("select SeqRul, RulStr from R999RUL where CodRul = :CodRul order by SeqRul"); > xCmdProc.GetParam(0).SetAsInteger(aRuleCode); > xCursor = xCmdProc.Open(); > xText = TStringList.Create(); > try { > while (xCursor.Next()) { > xText.Add(xCursor.GetField(1).GetAsString()); > } > Result = xText.GetTextStr(); > } finally { > xText.Destroy(); > } > return Result; > } > > public final void SetCollationRule(int aRuleCode, String aRuleText) { > IRtDBCommandProcessor xCmdProc; > TStringList xText; > int i; > xCmdProc = NewDBCommandProcessor(); > xCmdProc.SetCommand("delete R999RUL where CodRul = :CodRul"); > xCmdProc.GetParam(0).SetAsInteger(aRuleCode); > xCmdProc.Execute(); > xCmdProc.SetCommand("insert into R999RUL (CodRul, SeqRul, RulStr) values (:CodRul, :SeqRul, :RulStr)"); > xCmdProc.GetParam(0).SetAsInteger(aRuleCode); > xText = TStringList.Create(); > try { > xText.SetTextStr(aRuleText); > i = 0; > while (i < xText.GetCount()) { > xCmdProc.GetParam(1).SetAsInteger(i); > xCmdProc.GetParam(2).SetAsString(xText.Get(i)); > xCmdProc.Execute(); > i++; > } > } finally { > xText.Destroy(); > } > } > > protected final void runCreateConnection(TRtDatabaseServer AOwner, int aDBAccessKind, int aDBVersionKind) { > runCreate(); > InitConnection(AOwner, aDBAccessKind, aDBVersionKind); > } > > protected static TRtDBConnection CreateConnection(TRtDatabaseServer AOwner, int aDBAccessKind, int aDBVersionKind) { > TRtDBConnection Result; > Result = new TRtDBConnection(); > Result.runCreateConnection(AOwner, aDBAccessKind, aDBVersionKind); > return Result; > } > > boolean FInBusinessTransaction; > boolean FInBusinessOperation; > int FBusinessTransactionId; > private TRtTranEvent fBeforeCommitRollback = new TRtTranEvent() { > > public void run(IRtDBConnection aConn) { > BeforeCommitRollbackEvent(aConn); > } > > }; > private TRtTranEvent fExecBeforeCommit = new TRtTranEvent() { > > public void run(IRtDBConnection aConn) { > ReplG6Functions().ExecBeforeCommit(aConn); > } > }; > private TRtTranEvent BeforeBeginTran = new TRtTranEvent() { > > public void run(IRtDBConnection aConn) { > ReplG6Functions().ExecBeforeBeginTran(aConn); > } > > }; > private TRtTranEvent AfterEndTran = new TRtTranEvent() { > > public void run(IRtDBConnection aConn) { > ReplG6Functions().ExecAfterEndTran(aConn); > } > }; > > final void CheckNotInBusinessTransaction() { > if (FInBusinessTransaction) { > throw DelphiException.Create(TransStr("TC6534", "Existe uma transação de negócio ativa.")); > } > } > > final void CheckNotInBusinessOperation() { > if (FInBusinessOperation) { > throw DelphiException.Create(TransStr("TC6535", "Existe uma operação de negócio ativa.")); > } > } > > private final void CheckInBusinessTransaction() { > if (!FInBusinessTransaction) { > throw DelphiException.Create(TransStr("TC6536", "Não existe uma transação de negócio ativa.")); > } > } > > final void CheckInBusinessOperation() { > if (!FInBusinessOperation) { > throw DelphiException.Create(TransStr("TC6537", "Não existe uma operação de negócio ativa.")); > } > } > > final void CheckNotInTransaction() { > if (GetInTransaction()) { > throw DelphiException.Create(TransStr("TC6538", "Já existe uma transação ativa.")); > } > } > > final void CheckRootTransactionLevel() { > if (FRawDatabase.GetTransactionLevel() > 1) { > throw DelphiException.Create(TransStr("TC6540", "Operação não permitida. Existem outras transações ativas.")); > } > } > > private final void CheckCommitRollbackPermission() { > if ((FInBusinessTransaction || FInBusinessOperation) && FRawDatabase.GetTransactionLevel() == 1) { > throw DelphiException.Create(TransStr("TC6539", "Operação não permitida sobre uma transação de negócio.")); > } > } > > final void BeforeCommitRollbackEvent(IRtDBConnection aConn) { > CheckCommitRollbackPermission(); > } > > public int StartBusinessTransaction() { > StartBusinessTransaction_Context ctx = new StartBusinessTransaction_Context(); > return ctx.execute(); > } > > public final int CurrentBusinessTransactionId() { > int Result; > if (FInBusinessTransaction) { > Result = FBusinessTransactionId; > } else { > Result = -1; > } > return Result; > } > > public final void CommitBusinessTransaction() { > IRtDBCommandProcessor Cmd; > CheckInBusinessTransaction(); > CheckNotInBusinessOperation(); > CheckRootTransactionLevel(); > Cmd = NewDBCommandProcessor(); > Cmd.SetCommand("delete from R999TRD where CodTra = :CodTra"); > Cmd.ParamByName("CodTra").SetAsInteger(FBusinessTransactionId); > Cmd.Prepare(); > Cmd.Execute(); > Cmd.SetCommand("delete from R999TRA where CodTra = :CodTra"); > Cmd.ParamByName("CodTra").SetAsInteger(FBusinessTransactionId); > Cmd.Prepare(); > if (Cmd.Execute() != 1) { > throw DelphiException.Create("Erro ao finalizar a transação de negócio."); > } > FInBusinessTransaction = false; > try { > Commit(); > } catch (Throwable any) { > FInBusinessTransaction = true; > throw wrap(any); > } > FBusinessTransactionId = -1; > } > > public final void RollbackBusinessTransaction() { > CheckInBusinessTransaction(); > CheckNotInBusinessOperation(); > CheckRootTransactionLevel(); > FInBusinessTransaction = false; > try { > Rollback(); > } catch (Throwable any) { > FInBusinessTransaction = true; > throw wrap(any); > } > FBusinessTransactionId = -1; > FInBusinessTransaction = false; > } > > public final void BeginBusinessOperation(int BusinessTransactionId) { > CheckNotInBusinessTransaction(); > CheckNotInBusinessOperation(); > CheckNotInTransaction(); > BeginTran(); > FInBusinessOperation = true; > FBusinessTransactionId = BusinessTransactionId; > } > > public void CommitBusinessOperation(String UndoData) { > CommitBusinessOperation_Context ctx = new CommitBusinessOperation_Context(UndoData); > ctx.execute(); > } > > public final void RollbackBusinessOperation() { > CheckNotInBusinessTransaction(); > CheckInBusinessOperation(); > CheckRootTransactionLevel(); > FInBusinessOperation = false; > try { > Rollback(); > } catch (Throwable any) { > FInBusinessOperation = true; > throw wrap(any); > } > FBusinessTransactionId = -1; > } > > public void runCreate() { > super.runCreate(); > FRawDatabase = null; > FRtDatabase = null; > FPhyDatabase = null; > FParams = TDBParamStrings.Create(); > FSQLList = ((TListOwner) Creator(this, TListOwnerClass.SINGLETON)); > SetSQLProcessMode(spmIndividual); > FStorageList = TRtCustomStorageList.Create(this); > FTablePrivilegesList = TRtCustomTablePrivilegesList.Create(); > FIgnoreSortErrors = true; > FDBDateTime = 0.0; > FTickCount = 0; > FGetDateFromDB = false; > FDBUserID = ""; > FOnGetTableSecurityValues = null; > FOnGetFieldSecurityValues = null; > FOnGetTableEventValues = null; > FInBusinessTransaction = false; > FInBusinessOperation = false; > FBusinessTransactionId = -1; > } > > public static TRtDBConnection Create() { > TRtDBConnection Result; > Result = new TRtDBConnection(); > Result.runCreate(); > return Result; > } > > public void Destroy() { > int xDBAccessKind; > int xDBVersionKind; > xDBAccessKind = FDBAccessKind; > xDBVersionKind = FDBVersionKind; > if (IsOpen()) { > Close(); > } > FSQLWorks.Free(); > FSQLList.Free(); > FParams.Free(); > FStorageList.Free(); > FTablePrivilegesList.Free(); > FreeAndNil(AsVar(FSortLanguageList)); > ((TRtCCompilerSQL) FSQLCompiler).Free(); > FCacheSelectNextValue.Free(); > super.Destroy(); > if (vOnDestroyDBConnection != null) { > vOnDestroyDBConnection.run(xDBAccessKind, xDBVersionKind); > } > } > > public final void Open() { > if (!IsOpen()) { > DBGenericFunctions().CheckKernelOptions(FDBAccessKind, FDBVersionKind); > FRawDatabase = (((TRtDatabaseServer) CheckOwnerServer())).NewRawDataBase(FDBAccessKind, FDBVersionKind, FParams, this); > try { > CheckOnOffIrEvent(); > if (FDBInitProc != null) { > FDBInitProc.run(this); > } > ExecuteInitSqlCommands(); > if (ReplG6Functions().GetInReplG6(this) && ReplG6Functions().ExistsTablesToRepl(this)) { > EnableReplG6(); > } > try { > if (FDBVersionKind != dbvkSenior) { > FGetDateFromDB = SameText(DoR900GPRGetFlagValue(this, cGetDateTimeFromDB), cGetDateTimeFromDBTrue); > } else { > FGetDateFromDB = false; > } > } catch (Throwable any) { > FGetDateFromDB = false; > } > } catch (Throwable any) { > Close(); > throw wrap(any); > } > GetAccess().getBeforeCommit().AddEvent(fBeforeCommitRollback); > GetAccess().getBeforeRollBack().AddEvent(fBeforeCommitRollback); > } > } > > public final void Close() { > if (IsOpen()) { > GetAccess().getBeforeCommit().RemoveEvent(fBeforeCommitRollback); > GetAccess().getBeforeRollBack().RemoveEvent(fBeforeCommitRollback); > FRawDatabase.getDBRawSessionOwner().DeleteDBRawDataBase(FRawDatabase); > FRawDatabase = null; > FRtDatabase = null; > CheckOnOffIrEvent(); > } > } > > public final boolean IsOpen() { > return FRawDatabase != null; > } > > public final TRtDBConnection CloneConnection() { > TRtDBConnection Result; > Result = (((TRtDatabaseServer) GetTypedOwner(TRtDatabaseServerClass.SINGLETON))).NewDBConnection(FDBAccessKind, FDBVersionKind); > Result.FIgnoreSortErrors = FIgnoreSortErrors; > Result.FParams.Assign(FParams); > Result.SetPhyDatabase(FPhyDatabase); > if (IsOpen()) { > Result.Open(); > } > return Result; > } > > public void Assign(TPersistent Source) { > if (Source instanceof TRtDBConnection) { > if (IsOpen()) { > Close(); > } > FSQLList.Clear(); > SetPhyDatabase(((TRtDBConnection) Source).FPhyDatabase); > FParams.Assign(((TRtDBConnection) Source).FParams); > FSQLList.Assign(((TRtDBConnection) Source).FSQLList); > } else { > super.Assign(Source); > } > } > > public void ReadData(TReader Reader) { > Assert(false, "TRtDBConnection.ReadData"); > } > > public void WriteData(TWriter Writer) { > Assert(false, "TRtDBConnection.WriteData"); > } > > public final void BeginTran() { > CheckIsOpen(); > FRawDatabase.BeginTransaction(); > } > > public final void Commit() { > CheckIsOpen(); > FRawDatabase.Commit(); > } > > public final void Rollback() { > CheckIsOpen(); > FRawDatabase.RollBack(); > } > > public final double GetDBDateTime() { > double Result; > if (FUseTimeZone) { > Result = GetDBDateTimeWithTimeZone(); > } else { > Result = GetDBDateTimeWithoutTimeZone(); > } > return Result; > } > > public final String GetDBUserID() { > if (FDBUserID.equals("")) { > FDBUserID = (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetDBUserID(this, this.GetUserName()); > } > return FDBUserID; > } > > public final String GetDBUserInfoForBaseType() { > return GetDBUserID(); > } > > public final double GetDBUserCreatedDate() { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetDBUserCreatedDate(this); > } > > public final boolean TableExists(String ATableName) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).TableExists(this, ATableName); > } > > public final boolean SynonymExists(String ATableName) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).SynonymExists(this, ATableName); > } > > public final boolean StoredProcExists(String ASPName, TBoolean _enabled) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).SPExists(this, ASPName, _enabled); > } > > public final boolean ViewExists(String _ViewName, TBoolean _enabled) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).ViewExists(this, _ViewName, _enabled); > } > > public final boolean TriggerExists(String _TriggerName, String _TableName, TBoolean _Enabled) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).TriggerExists(this, _TriggerName, _TableName, _Enabled); > } > > public final TStringList GetStoredProcsFromDB() { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetStoredProcs(this); > } > > public final TStringList GetTriggersFromDB(String aTriggersPrefix) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetTriggers(this, aTriggersPrefix); > } > > public final TStringList GetTriggersFromDB() { > return GetTriggersFromDB(""); > } > > public final TStringList GetViewsFromDB(String aPrefixName) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetViews(this, aPrefixName); > } > > public final void AddTemporaryTable(String aTableName) { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).AddTableAsTemporary(this, aTableName); > } > > public final String GetOldTablesPattern() { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetOldTablesPattern(); > } > > public final String GetErrTablesPattern() { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetErrTablesPattern(); > } > > public final TStrings GetTablesFromDB(String aPattern) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetTables(this, aPattern); > } > > public final void DropAllTriggersFromDB(TStrings AScript, TStrings ALog, TRtOnUpdateProgress aOnProgress) { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).DropAllTriggersFromDB(this, AScript, ALog, aOnProgress); > } > > public final void DropAllStoredProcsFromDB(TStrings AScript, TStrings ALog, TRtOnUpdateProgress aOnProgress) { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).DropAllStoredProcsFromDB(this, AScript, ALog, aOnProgress); > } > > public final void DropViewsFromDB(String aPrefixName, TStrings aScript, TStrings aLog, TRtOnUpdateProgress aOnProgress) { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).DropViewsFromDB(this, aPrefixName, aScript, aLog, aOnProgress); > } > > public final DelphiSet GetAccessOptions(int aStmtKind, TRtTableInfo[] aTableInfo) { > DelphiSet Result = DelphiSet.get(); > TRtTableInfo xTableDenied = new TRtTableInfo(); > int i; > Result = DelphiSet.get(); > for (i = Low(aTableInfo); i <= High(aTableInfo); ++i) { > if (!Result.contains(aoLog) && MonitorTableVerify(aStmtKind, aTableInfo[i].TableName)) { > Result = Result.add(DelphiSet.get(aoLog)); > } > if (!AccessTableVerify(aStmtKind, aTableInfo[i], xTableDenied)) { > Result = Result.add(DelphiSet.get(aoAccessDenied)); > } > } > return Result; > } > > public final void LoadNativeStoredProc() { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).LoadNativeStoredProc(this); > } > > public final boolean LoadSortLanguage() { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).LoadSortLanguage(this); > } > > public final void LoadStorageFromPhyDataBase() { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).LoadStorageFromPhyDataBase(this); > } > > public final void LoadStorageFromDB() { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).LoadStorageFromDB(this); > } > > public final String LoadStorageFromStream(TStream aStream, String aDBVersionKindName) { > aDBVersionKindName = (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).LoadStorageFromStream(this, aStream, aDBVersionKindName); > return aDBVersionKindName; > } > > public final void SaveStorageFromDBToStream(TStream aStream) { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).SaveStorageFromDBToStream(this, aStream); > } > > public final void LoadPrivilegesFromPhyDatabase() { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).LoadPrivilegesFromPhyDatabase(this); > } > > public final TRtDbRevEng GetDbAnalyzer(TRtDatabaseDef ADatabase) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetDbAnalyzer(this, ADatabase); > } > > public final void CreateUser(TStrings aParams) { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).CreateUser(this, aParams); > } > > public final void ConsistViews(TRtDatabaseDef _OldDataBase, TRtDatabaseDef _NewDataBase) { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).ConsistViews(this, _OldDataBase, _NewDataBase); > } > > public final void ConsistViewsToUser(TRtDatabaseDef _DataBase) { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).ConsistViewsToUser(this, _DataBase); > } > > public final int GetDBViewsStatus(String aViewName) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetDBViewStatus(this, aViewName); > } > > public final IRtCursor GetTableListWithIncompatiblePhyTypes(TRtDatabaseDef _DataBase) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetTableListWithIncompatiblePhyTypes(this, _DataBase); > } > > public final void ConsistStoredProc(TRtDatabaseDef _OldDataBase, TRtDatabaseDef _NewDataBase, TRtGetConversionProp aGetConversionProp) { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).ConsistStoredProc(this, _OldDataBase, _NewDataBase, aGetConversionProp); > } > > public final int GetDBStoredProcStatus(String aStoredProcName) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetDBStoredProcsStatus(this, aStoredProcName); > } > > public final void ConsistDependences(TRtDatabaseDef _OldDataBase, TRtDatabaseDef _NewDataBase) { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).ConsistDependences(this, _OldDataBase, _NewDataBase); > } > > public final void ConsistTriggers(TRtDatabaseDef _OldDataBase, TRtDatabaseDef _NewDataBase) { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).ConsistTriggers(this, _OldDataBase, _NewDataBase); > } > > public final int GetDBTriggerStatus(TRtTableDef aTableDef, String aTableName, String aTriggerName) { > return (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).GetDBTriggerStatus(this, aTableDef, aTableName, aTriggerName); > } > > public final void ConsistTriggerFromTableDef(TRtTableDef _TableDef, int _Option) { > (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).ConsistTriggerFromTableDef(this, _TableDef, _Option); > } > > public final void CreateTableFromDef(TRtTableDef TblDef) { > CheckIsOpen(); > { > TRtCreateTable context = ((TRtCreateTable) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckCreateTable, FDBVersionKind)); > try { > context.AssignFromTableDef(TblDef, DelphiSet.getRange(raaColumns, raaForeignKeys)); > context.ExecuteUpd(); > } finally { > context.Free(); > } > } > } > > public final void AlterTableFromDef(TRtTableDef NewTblDef) { > CheckIsOpen(); > { > TRtAlterTable context = ((TRtAlterTable) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckAlterTable, FDBVersionKind)); > try { > context.AssignFromTableDef(NewTblDef, DelphiSet.getRange(raaColumns, raaForeignKeys)); > context.ExecuteUpd(); > } finally { > context.Free(); > } > } > } > > public void AssignFromDatabaseDef(int aLevelAlterTableMode, TRtDatabaseDef NewDbDef, DelphiSet AAssOpt, TRtGetConversionProp aGetConversionProp) { > AssignFromDatabaseDef_Context ctx = new AssignFromDatabaseDef_Context(aLevelAlterTableMode, NewDbDef, AAssOpt, aGetConversionProp); > ctx.execute(); > } > > public final void DisableForeignKeys(TRtTableDef TblDef) { > int I; > CheckIsOpen(); > { > TRtCreateTable context = ((TRtCreateTable) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckAlterTable, FDBVersionKind)); > try { > context.AssignFromTableDef(TblDef, DelphiSet.get(raaForeignKeys)); > for (I = 0; I <= context.FForeignKeys.GetCount() - 1; ++I) { > context.FForeignKeys.GetItem(I).FOption = rcaDrop; > } > context.ExecuteUpd(); > } finally { > context.Free(); > } > } > } > > public final void EnableForeignKeys(TRtTableDef TblDef) { > CheckIsOpen(); > { > TRtCreateTable context = ((TRtCreateTable) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckAlterTable, FDBVersionKind)); > try { > context.AssignFromTableDef(TblDef, DelphiSet.get(raaForeignKeys)); > context.ExecuteUpd(); > } finally { > context.Free(); > } > } > } > > public final void DisableAllForeignKeys() { > int I; > CheckIsOpen(); > for (I = 0; I <= FPhyDatabase.GetTableCount() - 1; ++I) { > DisableForeignKeys(FPhyDatabase.GetTable(I)); > } > } > > public final void EnableAllForeignKeys() { > int I; > CheckIsOpen(); > for (I = 0; I <= FPhyDatabase.GetTableCount() - 1; ++I) { > EnableForeignKeys(FPhyDatabase.GetTable(I)); > } > } > > public final String SeniorSqlToNativeSql(String aSql) { > String Result = ""; > TRtCustomSQL SqlObject; > TStringList SourceParams; > TStringList ReplaceParams; > int i; > int ii; > String Par = ""; > String Rep = ""; > String xSql = ""; > xSql = aSql; > SourceParams = TStringList.Create(); > ReplaceParams = TStringList.Create(); > i = Pos("{", xSql); > while (i > 0) { > Par = ""; > Rep = ":P" + IntToStr(SourceParams.GetCount()); > ii = Pos('}', xSql) - i + 1; > if (ii == 0) { > ii = Length(xSql) - i + 1; > } > Par = Copy(xSql, i, ii); > SourceParams.Add(Par); > ReplaceParams.Add(Rep); > xSql = Delete(xSql, i, ii); > xSql = Insert(Rep, xSql, i); > i = Pos("{", xSql); > } > SqlObject = SQLObjectFrom(xSql); > try { > Result = SqlObject.GenSQL(); > while (SourceParams.GetCount() > 0) { > Par = ReplaceParams.Get(0); > Rep = SourceParams.Get(0); > i = Pos(Par, Result); > if (i == 0) { > i = Pos(LowerCase(Par), Result); > Rep = LowerCase(Rep); > } > ii = Length(Par); > Result = Delete(Result, i, ii); > Result = Insert(Rep, Result, i); > SourceParams.Delete(0); > ReplaceParams.Delete(0); > } > } finally { > SqlObject.Free(); > SourceParams.Free(); > ReplaceParams.Free(); > } > return Result; > } > > public final String SeniorSqlToNativeSql(TStatement aStatement) { > return DBGenericFunctions().SeniorSqlToNativeSql(aStatement); > } > > public final String SeniorSql_2ToNativeSql(String aSqlSenior_2, boolean aConsistTypes) { > String Result = ""; > TSQLStatement xSQLStatement; > xSQLStatement = SelectSQLSenior_2(aSqlSenior_2, aConsistTypes); > try { > Result = SeniorSqlToNativeSql(xSQLStatement.getStatement()); > } finally { > xSQLStatement.Free(); > } > return Result; > } > > public final String SeniorSql_2ToNativeSql(String aSqlSenior_2) { > return SeniorSql_2ToNativeSql(aSqlSenior_2, true); > } > > public final IRtStmt NewStmtFromCommand(String aCommand) { > return NewNativeStmtFromCommand(aCommand); > } > > public final void ClearSQLObjects() { > FSQLList.Clear(); > } > > public final TSQLStatement SelectSQLSenior_2(String aSelectSQLSenior_2, boolean aConsistTypes) { > return InternalSelectSQLSenior_2(getPhyDatabase(), aSelectSQLSenior_2, aConsistTypes); > } > > public final TSQLStatement SelectSQLSenior_2(String aSelectSQLSenior_2) { > return SelectSQLSenior_2(aSelectSQLSenior_2, true); > } > > public final TRtCustomSQL SQLObjectFrom(String ASql) { > TRtCustomSQL Result; > TRtCCompiledNodeList CompiledList; > if (TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetCBNFDataPtr() == null) { > throw DelphiException.Create(TransStr("TC653", "Não foi definido nenhum arquivo de layout de compilação.", true)); > } > Result = null; > (((TRtCCompilerSQL) GetSQLCompiler())).SetPhyDatabase(FPhyDatabase); > try { > CompiledList = (((TRtCCompilerSQL) GetSQLCompiler())).Compile(ASql); > if (CompiledList == null) { > Abort(); > } > try { > if (CompiledList.GetItems(0).getSubNodes().GetItems(0) instanceof TRtCCompiledNodeSQL) { > Result = (((TRtCCompiledNodeSQL) CompiledList.GetItems(0).getSubNodes().GetItems(0))).CreateSQL(this, Result); > } > if (Result instanceof TRtSelect) { > try { > ((TRtSelect) Result).CheckUnresolvedRefs(); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > } > } finally { > CompiledList.Free(); > } > } catch (ECCompiler E) { > throw DelphiException.Create(TransStr("TC654", "Erro na compilação: ", true) + EOL + FCompilErrs); > } catch (DelphiException E) { > throw DelphiException.Create(TransStr("TC654", "Erro na compilação: ", true) + EOL + E.getMessage()); > } > return Result; > } > > public final TRtCustomSQL AddCopySQLObject(TRtCustomSQL ASql) { > TRtCustomSQL Result; > if (ASql == null) { > throw DelphiException.Create(TransStr("TC537", "Parâmetro nulo.", true)); > } > Result = TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(ASql.GetSQLClassesKind(), FDBVersionKind); > try { > AddSQL(Result); > Result.Assign(ASql); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtCreateTable SQLCreateTable() { > TRtCreateTable Result; > Result = ((TRtCreateTable) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckCreateTable, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtAlterTable SQLAlterTable() { > TRtAlterTable Result; > Result = ((TRtAlterTable) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckAlterTable, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtDropTable SQLDropTable() { > TRtDropTable Result; > Result = ((TRtDropTable) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckDropTable, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtCreateTrigger SQLCreateTrigger() { > TRtCreateTrigger Result; > Result = ((TRtCreateTrigger) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckCreateTrigger, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtDropTrigger SQLDropTrigger() { > TRtDropTrigger Result; > Result = ((TRtDropTrigger) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckDropTrigger, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtCreateProcedure SQLCreateProcedure() { > TRtCreateProcedure Result; > Result = ((TRtCreateProcedure) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckCreateProcedure, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtDropProcedure SQLDropProcedure() { > TRtDropProcedure Result; > Result = ((TRtDropProcedure) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckDropProcedure, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtRenameTable SQLRenameTable() { > TRtRenameTable Result; > Result = ((TRtRenameTable) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckRenameTable, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtCreateIndex SQLCreateIndex() { > TRtCreateIndex Result; > Result = ((TRtCreateIndex) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckCreateIndex, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtDropIndex SQLDropIndex() { > TRtDropIndex Result; > Result = ((TRtDropIndex) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckDropIndex, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtCreateView SQLCreateView() { > TRtCreateView Result; > Result = ((TRtCreateView) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckCreateView, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtDropView SQLDropView() { > TRtDropView Result; > Result = ((TRtDropView) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckDropView, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtBeginTran SQLBeginTran() { > TRtBeginTran Result; > Result = ((TRtBeginTran) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckBeginTran, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtSetTransaction SQLSetTransaction() { > TRtSetTransaction Result; > Result = ((TRtSetTransaction) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckSetTransaction, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtSavePoint SQLSavePoint() { > TRtSavePoint Result; > Result = ((TRtSavePoint) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckSavePoint, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtRollBack SQLRollBack() { > TRtRollBack Result; > Result = ((TRtRollBack) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckRollBack, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtCommit SQLCommit() { > TRtCommit Result; > Result = ((TRtCommit) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckCommit, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtDeleteFrom SQLDeleteFrom() { > TRtDeleteFrom Result; > Result = ((TRtDeleteFrom) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckDeleteFrom, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtInsertSelectInto SQLInsertSelectInto() { > TRtInsertSelectInto Result; > Result = ((TRtInsertSelectInto) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckInsertSelectInto, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtInsertInto SQLInsertInto() { > TRtInsertInto Result; > Result = ((TRtInsertInto) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckInsertInto, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtUpdate SQLUpdate() { > TRtUpdate Result; > Result = ((TRtUpdate) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckUpdate, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtSelect SQLSelect() { > TRtSelect Result; > Result = ((TRtSelect) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckSelect, FDBVersionKind)); > try { > AddSQL(Result); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtDBGenericFunctionsClass DBGenericFunctions() { > return TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbGenericFunctionsClass(getDBVersionKind()); > } > > public final TRtReplG6FunctionsClass ReplG6Functions() { > return TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetReplG6FunctionsClass(getDBVersionKind()); > } > > public final boolean DisableReplG6() { > boolean Result; > Result = GetAccess().getBeforeBeginTran() != null; > if (Result) { > GetAccess().setBeforeBeginTran(null); > GetAccess().setAfterEndTran(null); > GetAccess().getBeforeCommit().RemoveEvent(fExecBeforeCommit); > ReplG6Functions().DisableRepl(this); > } > return Result; > } > > public final void EnableReplG6() { > try { > ReplG6Functions().InitControlObjects(this); > GetAccess().setBeforeBeginTran(BeforeBeginTran); > GetAccess().getBeforeCommit().AddEvent(fExecBeforeCommit); > GetAccess().setAfterEndTran(AfterEndTran); > } catch (Throwable any) { > //Application.MessageBox(((CharPointer) TransStrFmt("TC3294", "A base de dados está marcada para integração com G6, mas alguns objetos estão " + "corrompidos ou não foram encontrados.%0:s" + "É necessário executar uma consistência de base para corrigir esta situação.", new Object[] { '\r' }, true)), ((CharPointer) TransStr("TC89", "Erro")), MB_OK | MB_ICONERROR); > throw pending(); > } > } > > public final void DisableDBTrace() { > getRawDatabase().DisableDBTrace(); > } > > public final void EnableDBTrace() { > getRawDatabase().EnableDBTrace(); > } > > public final void SetIdleTimeoutEvent(TOnIdleTimeout aEvent) { > //getRawDatabase().SetOnIdleTimeout(aEvent); > throw pending(); > } > > public final String TranslateTemporaryTableName(String aTableName) { > String Result = ""; > Result = aTableName; > if (getOnTableIsTemporary() != null && getOnTableIsTemporary().run(aTableName)) { > Result = (((TRtDbCatalogsClass) TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetDbCatalogsClass(FDBVersionKind))).TranslateTemporaryTableName(aTableName); > } > return Result; > } > > public TRtDBConnectionClass ClassType() { > return TRtDBConnectionClass.SINGLETON; > } > > public int getSQLProcessMode() { > return FSQLProcessMode; > } > > public void setDisableEvents(boolean value) { > FDisableEvents = value; > } > > public boolean getDisableEvents() { > return FDisableEvents; > } > > public void setOnBeforeAssignFromTableDef(TRtSQLAssignTableDefEvent value) { > FOnBeforeAssignFromTableDef = value; > } > > public TRtSQLAssignTableDefEvent getOnBeforeAssignFromTableDef() { > return FOnBeforeAssignFromTableDef; > } > > public void setOnAfterAssignFromTableDef(TRtSQLAssignTableDefEvent value) { > FOnAfterAssignFromTableDef = value; > } > > public TRtSQLAssignTableDefEvent getOnAfterAssignFromTableDef() { > return FOnAfterAssignFromTableDef; > } > > public void setOnBeforeAssignToTableDef(TRtSQLAssignTableDefEvent value) { > FOnBeforeAssignToTableDef = value; > } > > public TRtSQLAssignTableDefEvent getOnBeforeAssignToTableDef() { > return FOnBeforeAssignToTableDef; > } > > public void setOnAfterAssignToTableDef(TRtSQLAssignTableDefEvent value) { > FOnAfterAssignToTableDef = value; > } > > public TRtSQLAssignTableDefEvent getOnAfterAssignToTableDef() { > return FOnAfterAssignToTableDef; > } > > public void setOnMustDropTable(TRtSQLMustDropTableEvent value) { > FOnMustDropTable = value; > } > > public TRtSQLMustDropTableEvent getOnMustDropTable() { > return FOnMustDropTable; > } > > public void setOnMustRenameTable(TRtSQLMustRenameTableEvent value) { > FOnMustRenameTable = value; > } > > public TRtSQLMustRenameTableEvent getOnMustRenameTable() { > return FOnMustRenameTable; > } > > public void setOnMustDropStoredProc(TRtSQLMustDropStoredProcEvent value) { > FOnMustDropStoredProc = value; > } > > public TRtSQLMustDropStoredProcEvent getOnMustDropStoredProc() { > return FOnMustDropStoredProc; > } > > public void setOnMustDropView(TRtSQLMustDropViewEvent value) { > FOnMustDropView = value; > } > > public TRtSQLMustDropViewEvent getOnMustDropView() { > return FOnMustDropView; > } > > public void setOnMustCreateView(TRtSQLMustCreateViewEvent value) { > FOnMustCreateView = value; > } > > public TRtSQLMustCreateViewEvent getOnMustCreateView() { > return FOnMustCreateView; > } > > public void setOnDDLError(TRtDDLErrorEvent value) { > FOnDDLError = value; > } > > public TRtDDLErrorEvent getOnDDLError() { > return FOnDDLError; > } > > public void setOnBeforeDDLStep(TRtDDLStepEvent value) { > FOnBeforeDDLStep = value; > } > > public TRtDDLStepEvent getOnBeforeDDLStep() { > return FOnBeforeDDLStep; > } > > public void setOnForceAlterTableMode(TOnForceAlterTableMode value) { > FOnForceAlterTableMode = value; > } > > public TOnForceAlterTableMode getOnForceAlterTableMode() { > return FOnForceAlterTableMode; > } > > public TDBParamStrings getParam() { > return FParams; > } > > public TRtDatabaseDef getPhyDatabase() { > return FPhyDatabase; > } > > public void setNotUpdatePhyDatabase(boolean value) { > FNotUpdatePhyDatabase = value; > } > > public boolean getNotUpdatePhyDatabase() { > return FNotUpdatePhyDatabase; > } > > public TRtDBRawDatabase getRawDatabase() { > return FRawDatabase; > } > > public TRtCustomStorageList getStorage() { > return FStorageList; > } > > public TRtCustomTablePrivilegesList getPrivileges() { > return FTablePrivilegesList; > } > > public TStringList getSortLanguageList() { > return FSortLanguageList; > } > > public String getName() { > return FName; > } > > public void setComponentOwner(TComponent value) { > FComponentOwner = value; > } > > public TComponent getComponentOwner() { > return FComponentOwner; > } > > public void setOnVerifyAssignObjectDef(TRtSQLVerifyAssignObjectDef value) { > FOnVerifyAssignObjectDef = value; > } > > public TRtSQLVerifyAssignObjectDef getOnVerifyAssignObjectDef() { > return FOnVerifyAssignObjectDef; > } > > public void setIgnoreSortErrors(boolean value) { > FIgnoreSortErrors = value; > } > > public boolean getIgnoreSortErrors() { > return FIgnoreSortErrors; > } > > public int getDBVersionKind() { > return FDBVersionKind; > } > > public int getDBAccessKind() { > return FDBAccessKind; > } > > public boolean getUseTimeZone() { > return FUseTimeZone; > } > > public boolean getGetDateFromDB() { > return FGetDateFromDB; > } > > public void setOnGetTableSecurityValues(TRtOnGetTableSecurityValues value) { > FOnGetTableSecurityValues = value; > } > > public TRtOnGetTableSecurityValues getOnGetTableSecurityValues() { > return FOnGetTableSecurityValues; > } > > public void setOnGetFieldSecurityValues(TRtOnGetFieldSecurityValues value) { > FOnGetFieldSecurityValues = value; > } > > public TRtOnGetFieldSecurityValues getOnGetFieldSecurityValues() { > return FOnGetFieldSecurityValues; > } > > public void setOnGetTableEventValues(TRtOnGetTableEventValues value) { > FOnGetTableEventValues = value; > } > > public TRtOnGetTableEventValues getOnGetTableEventValues() { > return FOnGetTableEventValues; > } > > public void setOnDeleteStorage(TRtOnDeleteStorage value) { > FOnDeleteStorage = value; > } > > public TRtOnDeleteStorage getOnDeleteStorage() { > return FOnDeleteStorage; > } > > public void setOnAddStorageIndexClustered(TRtOnAddStorageIndexClustered value) { > FOnAddStorageIndexClustered = value; > } > > public TRtOnAddStorageIndexClustered getOnAddStorageIndexClustered() { > return FOnAddStorageIndexClustered; > } > > public void setOnAddStorageLockEscalation(TRtOnAddStorageLockEscalation value) { > FOnAddStorageLockEscalation = value; > } > > public TRtOnAddStorageLockEscalation getOnAddStorageLockEscalation() { > return FOnAddStorageLockEscalation; > } > > public void setOnApplyLockEscalationInDb(TRtOnApplyLockEscalationInDb value) { > FOnApplyLockEscalationInDb = value; > } > > public TRtOnApplyLockEscalationInDb getOnApplyLockEscalationInDb() { > return FOnApplyLockEscalationInDb; > } > > public void setCustomAlterDefValue(TCustomAlterDefIndexCluster value) { > FCustomAlterDefValue = value; > } > > public TCustomAlterDefIndexCluster getCustomAlterDefValue() { > return FCustomAlterDefValue; > } > > public TRtOnTableIsTemporary getOnTableIsTemporary() { > return FOnTableIsTemporary; > } > > public int _AddRef() { > return 0; > } > > public int _Release() { > return 0; > } > > } > > public static class TSQLContainerItemClass extends TContainerItemClass { > > public static final TSQLContainerItemClass SINGLETON = new TSQLContainerItemClass(); > > public TSQLContainerItem Create() { > return TSQLContainerItem.Create(); > } > > public Class<? extends TSQLContainerItem> ClassInfo() { > return TSQLContainerItem.class; > } > } > > public static class TSQLContainerItem extends TContainerItem { > > protected void CheckUnprepare() { > _CheckUnprepare(this); > } > > public void Destroy() { > CheckUnprepare(); > super.Destroy(); > } > > public void Assign(TPersistent Source) { > if (Source instanceof TSQLContainerItem) { > CheckUnprepare(); > } else { > super.Assign(Source); > } > } > > public void ReadData(TReader Reader) { > CheckUnprepare(); > super.ReadData(Reader); > } > > public static TSQLContainerItem Create() { > TSQLContainerItem Result; > Result = new TSQLContainerItem(); > Result.runCreate(); > return Result; > } > > public TSQLContainerItemClass ClassType() { > return TSQLContainerItemClass.SINGLETON; > } > } > > public static class TSQLTypedListOwnerClass extends TTypedListOwnerClass { > > public static final TSQLTypedListOwnerClass SINGLETON = new TSQLTypedListOwnerClass(); > > public Class<? extends TSQLTypedListOwner> ClassInfo() { > return TSQLTypedListOwner.class; > } > } > > public static abstract class TSQLTypedListOwner extends TTypedListOwner { > > protected void CheckUnprepare() { > _CheckUnprepare(this); > } > > public void Destroy() { > CheckUnprepare(); > super.Destroy(); > } > > public void Delete(int AIndex) { > super.Delete(AIndex); > CheckUnprepare(); > } > > public void Assign(TPersistent Source) { > CheckUnprepare(); > super.Assign(Source); > } > > public void ReadData(TReader Reader) { > CheckUnprepare(); > super.ReadData(Reader); > } > > public TSQLTypedListOwnerClass ClassType() { > return TSQLTypedListOwnerClass.SINGLETON; > } > } > > public static class TSQLKeyedContainerItemClass extends TKeyedContainerItemClass { > > public static final TSQLKeyedContainerItemClass SINGLETON = new TSQLKeyedContainerItemClass(); > > public TSQLKeyedContainerItem Create() { > return TSQLKeyedContainerItem.Create(); > } > > public Class<? extends TSQLKeyedContainerItem> ClassInfo() { > return TSQLKeyedContainerItem.class; > } > } > > public static class TSQLKeyedContainerItem extends TKeyedContainerItem { > > protected void CheckUnprepare() { > _CheckUnprepare(this); > } > > protected void SetKey(Object Value) { > CheckUnprepare(); > super.SetKey(Value); > } > > public void Destroy() { > CheckUnprepare(); > super.Destroy(); > } > > public void Assign(TPersistent Source) { > CheckUnprepare(); > super.Assign(Source); > } > > public void ReadData(TReader Reader) { > CheckUnprepare(); > super.ReadData(Reader); > } > > public static TSQLKeyedContainerItem Create() { > TSQLKeyedContainerItem Result; > Result = new TSQLKeyedContainerItem(); > Result.runCreate(); > return Result; > } > > public TSQLKeyedContainerItemClass ClassType() { > return TSQLKeyedContainerItemClass.SINGLETON; > } > } > > public static class TSQLKeyedListOwnerClass extends TKeyedListOwnerClass { > > public static final TSQLKeyedListOwnerClass SINGLETON = new TSQLKeyedListOwnerClass(); > > public TSQLKeyedListOwner Create() { > return TSQLKeyedListOwner.Create(); > } > > public Class<? extends TSQLKeyedListOwner> ClassInfo() { > return TSQLKeyedListOwner.class; > } > } > > public static class TSQLKeyedListOwner extends TKeyedListOwner { > > protected void CheckUnprepare() { > _CheckUnprepare(this); > } > > public void Destroy() { > CheckUnprepare(); > super.Destroy(); > } > > public void Delete(int AIndex) { > super.Delete(AIndex); > CheckUnprepare(); > } > > public void Assign(TPersistent Source) { > CheckUnprepare(); > super.Assign(Source); > } > > public void ReadData(TReader Reader) { > CheckUnprepare(); > super.ReadData(Reader); > } > > public static TSQLKeyedListOwner Create() { > TSQLKeyedListOwner Result; > Result = new TSQLKeyedListOwner(); > Result.runCreate(); > return Result; > } > > public TSQLKeyedListOwnerClass ClassType() { > return TSQLKeyedListOwnerClass.SINGLETON; > } > } > > public static class TSQLNamedContainerItemClass extends TNamedContainerItemClass { > > public static final TSQLNamedContainerItemClass SINGLETON = new TSQLNamedContainerItemClass(); > > public TSQLNamedContainerItem Create() { > return TSQLNamedContainerItem.Create(); > } > > public Class<? extends TSQLNamedContainerItem> ClassInfo() { > return TSQLNamedContainerItem.class; > } > } > > public static class TSQLNamedContainerItem extends TNamedContainerItem { > > protected void CheckUnprepare() { > _CheckUnprepare(this); > } > > protected void SetKey(Object Value) { > CheckUnprepare(); > super.SetKey(Value); > } > > public void Destroy() { > CheckUnprepare(); > super.Destroy(); > } > > public void Assign(TPersistent Source) { > CheckUnprepare(); > super.Assign(Source); > } > > public void ReadData(TReader Reader) { > CheckUnprepare(); > super.ReadData(Reader); > } > > public static TSQLNamedContainerItem Create() { > TSQLNamedContainerItem Result; > Result = new TSQLNamedContainerItem(); > Result.runCreate(); > return Result; > } > > public TSQLNamedContainerItemClass ClassType() { > return TSQLNamedContainerItemClass.SINGLETON; > } > } > > public static class TSQLNamedListOwnerClass extends TNamedListOwnerClass { > > public static final TSQLNamedListOwnerClass SINGLETON = new TSQLNamedListOwnerClass(); > > public TSQLNamedListOwner Create() { > return TSQLNamedListOwner.Create(); > } > > public Class<? extends TSQLNamedListOwner> ClassInfo() { > return TSQLNamedListOwner.class; > } > } > > public static class TSQLNamedListOwner extends TNamedListOwner { > > protected void CheckUnprepare() { > _CheckUnprepare(this); > } > > public void Destroy() { > CheckUnprepare(); > super.Destroy(); > } > > public void Delete(int AIndex) { > super.Delete(AIndex); > CheckUnprepare(); > } > > public void Assign(TPersistent Source) { > CheckUnprepare(); > super.Assign(Source); > } > > public void ReadData(TReader Reader) { > CheckUnprepare(); > super.ReadData(Reader); > } > > public static TSQLNamedListOwner Create() { > TSQLNamedListOwner Result; > Result = new TSQLNamedListOwner(); > Result.runCreate(); > return Result; > } > > public TSQLNamedListOwnerClass ClassType() { > return TSQLNamedListOwnerClass.SINGLETON; > } > } > > public static final class TRtParamSelectItemClass extends TSQLNamedContainerItemClass { > > public static final TRtParamSelectItemClass SINGLETON = new TRtParamSelectItemClass(); > > public final TRtParamSelectItem CreateParam(TRtCustomSQL AOwner, String AName) { > return TRtParamSelectItem.CreateParam(AOwner, AName); > } > > public Class<? extends TRtParamSelectItem> ClassInfo() { > return TRtParamSelectItem.class; > } > } > > public static final class TRtParamSelectItem extends TSQLNamedContainerItem { > > protected TRtSelect FSelect; > > protected final void CheckInitSelect() { > if (FSelect == null) { > FSelect = ((TRtSelect) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckSelect, (((TRtCustomSQL) CheckTypedOwner(TRtCustomSQLClass.SINGLETON))).FDBVersionKind)); > FSelect.SetFOwner(this); > } > } > > public final TRtSelect GetSelect() { > CheckInitSelect(); > return FSelect; > } > > public final void SetSelect(TRtSelect AValue) { > CheckUnprepare(); > CheckInitSelect(); > FSelect.Assign(AValue); > } > > public final void runCreateParam(TRtCustomSQL AOwner, String AName) { > super.runCreate(); > FSelect = ((TRtSelect) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckSelect, AOwner.GetOwnerConnection().getDBVersionKind())); > FSelect.SetFOwner(this); > if (!StrIsBlank(AName)) { > SetName(AName); > AOwner.AddSelectParamItem(this); > } > } > > public static TRtParamSelectItem CreateParam(TRtCustomSQL AOwner, String AName) { > TRtParamSelectItem Result; > Result = new TRtParamSelectItem(); > Result.runCreateParam(AOwner, AName); > return Result; > } > > public void Destroy() { > if (FSelect != null) { > FSelect.Free(); > } > super.Destroy(); > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtParamSelectItem) { > CheckInitSelect(); > FSelect.Assign(((TRtParamSelectItem) Source).GetSelect()); > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > CheckInitSelect(); > FSelect.ReadData(Reader); > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > CheckInitSelect(); > FSelect.WriteData(Writer); > } > > public TRtParamSelectItemClass ClassType() { > return TRtParamSelectItemClass.SINGLETON; > } > } > > public static final class TRtParamSelectListClass extends TSQLNamedListOwnerClass { > > public static final TRtParamSelectListClass SINGLETON = new TRtParamSelectListClass(); > > public Class<? extends TRtParamSelectList> ClassInfo() { > return TRtParamSelectList.class; > } > } > > public static final class TRtParamSelectList extends TSQLNamedListOwner { > > protected TContainerItemClass AllocItemType() { > return TRtParamSelectItemClass.SINGLETON; > } > > public final TRtParamSelectItem GetItem(int Index) { > return ((TRtParamSelectItem) Get(Index)); > } > > public final TRtParamSelectItem ItemByName(String AName) { > return ((TRtParamSelectItem) super.ItemByName(AName)); > } > > public TRtParamSelectListClass ClassType() { > return TRtParamSelectListClass.SINGLETON; > } > } > > public static class TRtCustomSQL extends TSQLContainerItem { > > short FAssigning; > > public boolean GetHasOperation() { > return false; > } > > protected int FReadVersion; > protected boolean FUsesScriptTerminator; > protected int FDBVersionKind; > protected TRtSqlParams FParams; > protected TRtParamSelectList FSelectParams; > protected String FSql; > protected TRtDatabaseDef FUseDataBaseDef; > > protected String GenSQL() { > return ""; > } > > public final String GenSQLScript() { > String Result = ""; > FUsesScriptTerminator = true; > try { > Result = StrReplaceStr(GenSQL(), ToStr(SQLEOC_SEP), EOL); > Result = StrBreakLine(Result, " ,", 250, 0, kblNone); > } finally { > FUsesScriptTerminator = false; > } > return Result; > } > > public final String GetSQL() { > String Result = ""; > FSql = GenSQL(); > if (getUsesScriptTerminator() && !FSql.equals("")) { > Result = StrReplaceStr(FSql, ToStr(SQLEOC_SEP), EOL); > } else { > Result = FSql; > } > return Result; > } > > protected boolean GetConvertSQLToAccess() { > return true; > } > > protected final String GetSQLToAccess(String aSQL) { > String Result = ""; > TSimpleParser xParser; > String xToken = ""; > if (GetConvertSQLToAccess()) { > xParser = TSimpleParser.Create(aSQL); > try { > Result = ""; > while (xParser.GetCurrentTokenKind() != tkEOF) { > Result = Result + StringOfChar(' ', xParser.GetChrCountBtwTokens()); > xToken = xParser.GetCurrentToken(); > if (xParser.GetCurrentTokenKind() == tkSimbol && SameText(xToken, ':')) { > xParser.NexToken(); > xToken = '{' + xParser.GetCurrentToken() + "}"; > } > Result = Result + xToken; > xParser.NexToken(); > } > } finally { > xParser.Free(); > } > } else { > Result = aSQL; > } > return Result; > } > > protected void UpdatePhyDatabase() { > } > > protected final TRtCustomSQL GetRootSQL() { > TRtCustomSQL Result; > TRtCustomSQL AOwnerSQL; > AOwnerSQL = ((TRtCustomSQL) GetTypedOwner(TRtCustomSQLClass.SINGLETON)); > Result = AOwnerSQL; > while (AOwnerSQL != null) { > AOwnerSQL = ((TRtCustomSQL) AOwnerSQL.GetTypedOwner(TRtCustomSQLClass.SINGLETON)); > if (AOwnerSQL != null) { > Result = AOwnerSQL; > } > } > return Result; > } > > public final TRtSqlParams GetParams() { > TRtSqlParams Result; > TRtCustomSQL AOwnerSQL; > AOwnerSQL = GetRootSQL(); > if (AOwnerSQL != null) { > Result = AOwnerSQL.GetParams(); > } else { > Result = FParams; > } > return Result; > } > > public final TRtParamSelectList GetSelectParams() { > TRtParamSelectList Result; > TRtCustomSQL AOwnerSQL; > AOwnerSQL = GetRootSQL(); > if (AOwnerSQL != null) { > Result = AOwnerSQL.GetSelectParams(); > } else { > Result = FSelectParams; > } > return Result; > } > > protected final void AddSelectParamItem(TRtParamSelectItem AParam) { > GetSelectParams().Add(AParam); > } > > protected final TRtDatabaseDef CheckGetDatabaseDef() { > TRtDatabaseDef Result; > Result = GetDatabaseDef(); > if (Result == null) { > throw DelphiException.Create(TransStr("TC656", "Database (TBS) não encontrado.", true)); > } > return Result; > } > > protected final TRtDatabaseDef GetDatabaseDef() { > TRtDatabaseDef Result; > TRtDBConnection AConn; > if (FUseDataBaseDef != null) { > Result = FUseDataBaseDef; > } else { > AConn = GetOwnerConnection(); > if (AConn != null) { > Result = AConn.FPhyDatabase; > } else { > Result = null; > } > } > return Result; > } > > public TRtDBConnection GetOwnerConnection() { > return ((TRtDBConnection) GetTypedOwner(TRtDBConnectionClass.SINGLETON)); > } > > public final boolean GetNotUpdatePhyDatabase() { > return GetOwnerConnection().FNotUpdatePhyDatabase; > } > > protected Object VersionInfo(int InfoType, Object Version) { > Object Result = null; > Result = null; > switch (InfoType) { > case vitVersioned: > Result = (Object) 1; > break; > case vitGetVersionLen: > Result = ((Object) SizeOf(FReadVersion)); > break; > case vitGetReadVersion: > Result = FReadVersion; > break; > case vitSetReadVersion: > //Move(Version, FReadVersion, SizeOf(FReadVersion)); > FReadVersion = ToInt((byte[]) Version); > break; > case vitGetWriteVersion: > if (FReadVersion >= NUM_DATA_VERSION1 && FReadVersion <= CUR_DATA_VERSION) { > Result = FReadVersion; > } else { > Result = WRITE_VERSION; > } > break; > default: > break; > } > return Result; > } > > protected void CheckConnected() { > throw DelphiException.Create(TransStr("TC657", "Objeto SQL não conectado ao banco.", true)); > } > > protected void InternalUnPrepare() { > CheckConnected(); > } > > public boolean GetPrepared() { > return false; > } > > protected void InitSQLKernel(TRtDBConnection aDbConn) { > } > > protected final void LoadParamToAccess(TRtSqlParam aParam, TRtParam aParamAccess) { > if (aParam.GetIsNull()) { > switch (aParam.getDataType()) { > case rdtBoolean: > aParamAccess.GetTypeDesc().assign(cTypeDescBoolean); > break; > case rdtChar: > case rdtPChar: > case rdtText: > aParamAccess.GetTypeDesc().assign(cTypeDescString); > break; > case rdtByte: > case rdtShortint: > case rdtSmallint: > case rdtWord: > case rdtLongint: > aParamAccess.GetTypeDesc().assign(cTypeDescInteger); > break; > case rdtSingle: > case rdtDouble: > case rdtExtended: > case rdtComp: > case rdtCurrency: > aParamAccess.GetTypeDesc().assign(cTypeDescDouble); > break; > case rdtDate: > case rdtTime: > case rdtDateTime: > aParamAccess.GetTypeDesc().assign(cTypeDescDate); > break; > case rdtBlob: > case rdtImage: > aParamAccess.GetTypeDesc().assign(cTypeDescBlob); > break; > default: > break; > } > aParamAccess.SetToNull(); > } else { > switch (aParam.getDataType()) { > case rdtBoolean: > aParamAccess.SetAsBoolean(aParam.GetBoolean()); > break; > case rdtChar: > case rdtPChar: > case rdtText: > aParamAccess.SetAsString(aParam.GetString()); > break; > case rdtByte: > case rdtShortint: > case rdtSmallint: > case rdtWord: > case rdtLongint: > aParamAccess.SetAsInteger(aParam.GetLongint()); > break; > case rdtSingle: > case rdtDouble: > case rdtExtended: > case rdtComp: > case rdtCurrency: > aParamAccess.SetAsFloat(aParam.GetExtended()); > break; > case rdtDate: > aParamAccess.SetAsDateTime(TRtRecValueClass.SINGLETON.RtDateToDateTime(aParam.GetDate())); > break; > case rdtTime: > aParamAccess.SetAsDateTime(TRtRecValueClass.SINGLETON.RtTimeToDateTime(aParam.GetTime())); > break; > case rdtDateTime: > aParamAccess.SetAsDateTime(aParam.GetDateTime()); > break; > case rdtBlob: > case rdtImage: > aParamAccess.SetAsBlob(aParam.GetBlob()); > break; > default: > throw DelphiException.CreateFmt(TransStr("TC658", "Erro na conversão do parâmetro %s tipo %s para um parâmetro do RtAccess", true), new Object[] { aParam.GetName(), TRtDataTypeNames[aParam.getDataType()] }); > } > } > } > > protected final void runCreateWithDBVersionKind(int aDBVersionKind) { > FDBVersionKind = aDBVersionKind; > runCreate(); > } > > protected static TRtCustomSQL CreateWithDBVersionKind(int aDBVersionKind) { > TRtCustomSQL Result; > Result = new TRtCustomSQL(); > Result.runCreateWithDBVersionKind(aDBVersionKind); > return Result; > } > > protected final int GetSQLClassesKind() { > int Result; > if (this instanceof TRtCreateTable) { > Result = sckCreateTable; > } else if (this instanceof TRtAlterTable) { > Result = sckAlterTable; > } else if (this instanceof TRtCreateIndex) { > Result = sckCreateIndex; > } else if (this instanceof TRtDropIndex) { > Result = sckDropIndex; > } else if (this instanceof TRtCreateTrigger) { > Result = sckCreateTrigger; > } else if (this instanceof TRtDropTrigger) { > Result = sckDropTrigger; > } else if (this instanceof TRtCreateProcedure) { > Result = sckCreateProcedure; > } else if (this instanceof TRtDropProcedure) { > Result = sckDropProcedure; > } else if (this instanceof TRtCreateView) { > Result = sckCreateView; > } else if (this instanceof TRtDropView) { > Result = sckDropView; > } else if (this instanceof TRtDropTable) { > Result = sckDropTable; > } else if (this instanceof TRtRenameTable) { > Result = sckRenameTable; > } else if (this instanceof TRtBeginTran) { > Result = sckBeginTran; > } else if (this instanceof TRtSetTransaction) { > Result = sckSetTransaction; > } else if (this instanceof TRtSavePoint) { > Result = sckSavePoint; > } else if (this instanceof TRtRollBack) { > Result = sckRollBack; > } else if (this instanceof TRtCommit) { > Result = sckCommit; > } else if (this instanceof TRtDeleteFrom) { > Result = sckDeleteFrom; > } else if (this instanceof TRtInsertSelectInto) { > Result = sckInsertSelectInto; > } else if (this instanceof TRtInsertInto) { > Result = sckInsertInto; > } else if (this instanceof TRtUpdate) { > Result = sckUpdate; > } else if (this instanceof TRtSelect) { > Result = sckSelect; > } else { > Result = sckSelect; > Assert(false, "class not fount"); > } > return Result; > } > > protected final boolean GetIsIncremental(String aTableName, String aFieldName) { > boolean Result; > TRtFullDatabaseDef xDataBaseDef; > TRtFullTableDef xTableDef; > TRtFullFieldDef xFieldDef; > Result = false; > xDataBaseDef = GetDefaultNewDatabaseDef(); > if (xDataBaseDef != null) { > xTableDef = xDataBaseDef.TableByName(aTableName); > if (xTableDef != null) { > xFieldDef = xTableDef.FieldByName(aFieldName); > if (xFieldDef != null) { > Result = xFieldDef.getIncrementInDb(); > } > } > } > return Result; > } > > public void runCreate() { > super.runCreate(); > InitSQLKernel(null); > FParams = ((TRtSqlParams) Creator(this, TRtSqlParamsClass.SINGLETON)); > FSelectParams = ((TRtParamSelectList) Creator(this, TRtParamSelectListClass.SINGLETON)); > FReadVersion = CUR_DATA_VERSION; > FUseDataBaseDef = null; > } > > public static TRtCustomSQL Create() { > TRtCustomSQL Result; > Result = new TRtCustomSQL(); > Result.runCreate(); > return Result; > } > > public void runCreateSQL(TRtDBConnection AConn) { > super.runCreate(); > FDBVersionKind = AConn.FDBVersionKind; > FParams = ((TRtSqlParams) Creator(this, TRtSqlParamsClass.SINGLETON)); > FSelectParams = ((TRtParamSelectList) Creator(this, TRtParamSelectListClass.SINGLETON)); > FReadVersion = CUR_DATA_VERSION; > AConn.AddSQL(this); > FUseDataBaseDef = null; > } > > public static TRtCustomSQL CreateSQL(TRtDBConnection AConn) { > TRtCustomSQL Result; > Result = new TRtCustomSQL(); > Result.runCreateSQL(AConn); > return Result; > } > > public void Destroy() { > FSelectParams.Free(); > FParams.Free(); > super.Destroy(); > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > if (Source instanceof TRtCustomSQL) { > FReadVersion = ((TRtCustomSQL) Source).FReadVersion; > FSql = ((TRtCustomSQL) Source).FSql; > if (GetRootSQL() == null) { > FParams.Assign(((TRtCustomSQL) Source).FParams); > FSelectParams.Assign(((TRtCustomSQL) Source).FSelectParams); > } > } > super.Assign(Source); > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > TRtParamSelectItem SelItem; > boolean LWasOwned; > FAssigning++; > try { > super.ReadData(Reader); > LWasOwned = Reader.ReadBoolean(); > if (!LWasOwned) { > FParams.ReadData(Reader); > { > TReader context_Reader = Reader; > FSelectParams.Clear(); > context_Reader.ReadListBegin(); > while (!context_Reader.EndOfList()) { > SelItem = TRtParamSelectItem.CreateParam(this, TempName()); > try { > SelItem.ReadData(Reader); > } catch (Throwable any) { > SelItem.Free(); > } > } > context_Reader.ReadListEnd(); > FSql = context_Reader.ReadString(); > } > } > } finally { > FAssigning--; > } > } > > public void ReadDataOnConnection(TRtDBConnection AConn, TReader Reader) { > TRtDBConnection ACurConn; > ACurConn = GetOwnerConnection(); > if (ACurConn == null) { > if (AConn != null && AConn != ACurConn) { > // ACurConn.AddSQL(this); > throw new NullPointerException(); > } > } > ReadData(Reader); > } > > public void WriteData(TWriter Writer) { > int i; > boolean LWasOwned; > super.WriteData(Writer); > LWasOwned = GetRootSQL() != null; > Writer.WriteBoolean(LWasOwned); > if (!LWasOwned) { > FParams.WriteData(Writer); > { > TWriter context_Writer = Writer; > context_Writer.WriteListBegin(); > for (i = 0; i <= FSelectParams.GetCount() - 1; ++i) { > FSelectParams.GetItem(i).WriteData(Writer); > } > context_Writer.WriteListEnd(); > context_Writer.WriteString(FSql); > } > } > } > > public final void UnPrepare() { > InternalUnPrepare(); > } > > public TRtCustomSQLClass ClassType() { > return TRtCustomSQLClass.SINGLETON; > } > > public void setUsesScriptTerminator(boolean value) { > FUsesScriptTerminator = value; > } > > public boolean getUsesScriptTerminator() { > return FUsesScriptTerminator; > } > > public int getDBVersionKind() { > return FDBVersionKind; > } > > public void setUseDataBaseDef(TRtDatabaseDef value) { > FUseDataBaseDef = value; > } > > public TRtDatabaseDef getUseDataBaseDef() { > return FUseDataBaseDef; > } > } > > public static class TRtCustomSelectSQLClass extends TRtCustomSQLClass { > > public static final TRtCustomSelectSQLClass SINGLETON = new TRtCustomSelectSQLClass(); > > public TRtCustomSelectSQL CreateSQL(TRtDBConnection AConn) { > return TRtCustomSelectSQL.CreateSQL(AConn); > } > > public TRtCustomSelectSQL Create() { > return TRtCustomSelectSQL.Create(); > } > > public Class<? extends TRtCustomSelectSQL> ClassInfo() { > return TRtCustomSelectSQL.class; > } > } > > public static class TRtCustomSelectSQL extends TRtCustomSQL { > > private final class InternalPrepareQuery_Context { > > private void iLoadParams() { > TRtSqlParam xParam; > TRtParam xParamAccess; > int i; > for (i = 0; i <= FParams.GetCount() - 1; ++i) { > xParam = FParams.GetItem(i); > xParamAccess = FQuery.ParamByName(xParam.GetName()); > LoadParamToAccess(xParam, xParamAccess); > } > } > > public InternalPrepareQuery_Context() { > } > > public void execute() { > if (!GetPrepared()) { > CheckConnected(); > FQuery.SetCommand(GetSQLToAccess(FSql)); > iLoadParams(); > FQuery.Prepare(); > } > } > } > > TRtQuery FQuery; > > protected void CheckConnected() { > if (FQuery == null) { > super.CheckConnected(); > } > } > > protected void InternalPrepareQuery() { > InternalPrepareQuery_Context ctx = new InternalPrepareQuery_Context(); > ctx.execute(); > } > > protected void InternalUnPrepare() { > if (GetPrepared()) { > CheckConnected(); > if (FQuery.GetActive()) { > FQuery.Close(); > } > FQuery.UnPrepare(); > } > } > > public boolean GetPrepared() { > return FQuery != null && FQuery.GetPrepared(); > } > > protected void InitSQLKernel(TRtDBConnection aDbConn) { > if (FQuery != null) { > FQuery.Free(); > FQuery = null; > } > if (aDbConn != null && aDbConn.IsOpen()) { > if (getDBVersionKind() != aDbConn.getDBVersionKind()) { > throw DelphiException.CreateFmt(TransStr("TC659", "Driver deveria se \"%s\" e não \"%s\".", true), new Object[] { cDBVersionKindNameArray[getDBVersionKind()], cDBVersionKindNameArray[aDbConn.getDBVersionKind()] }); > } > FQuery = aDbConn.GetAccess().NewQuery(); > } > } > > public void runCreateSQL(TRtDBConnection AConn) { > super.runCreateSQL(AConn); > FQuery = AConn.GetAccess().NewQuery(); > } > > public static TRtCustomSelectSQL CreateSQL(TRtDBConnection AConn) { > TRtCustomSelectSQL Result; > Result = new TRtCustomSelectSQL(); > Result.runCreateSQL(AConn); > return Result; > } > > public void Destroy() { > FQuery.Free(); > FQuery = null; > super.Destroy(); > } > > public final TRtQuery GetRtQuery() { > if (!GetPrepared()) { > FSql = GenSQL(); > InternalPrepareQuery(); > } > return FQuery; > } > > public static TRtCustomSelectSQL Create() { > TRtCustomSelectSQL Result; > Result = new TRtCustomSelectSQL(); > Result.runCreate(); > return Result; > } > > public TRtCustomSelectSQLClass ClassType() { > return TRtCustomSelectSQLClass.SINGLETON; > } > } > > public interface TRtOnErrorExecutingMultipleSQLs { > > public void run(int aSubStep); > } > > public static class TRtCustomUpdateSQLClass extends TRtCustomSQLClass { > > public static final TRtCustomUpdateSQLClass SINGLETON = new TRtCustomUpdateSQLClass(); > > public TRtCustomUpdateSQL CreateSQL(TRtDBConnection AConn) { > return TRtCustomUpdateSQL.CreateSQL(AConn); > } > > public Class<? extends TRtCustomUpdateSQL> ClassInfo() { > return TRtCustomUpdateSQL.class; > } > } > > public static class TRtCustomUpdateSQL extends TRtCustomSQL { > > private final class InternalPrepareUpdate_Context { > > private void iLoadParams() { > TRtSqlParam xParam; > TRtParam xParamAccess; > int i; > for (i = 0; i <= FParams.GetCount() - 1; ++i) { > xParam = FParams.GetItem(i); > xParamAccess = FUpdate.FindParam(xParam.GetName()); > if (xParamAccess != null) { > LoadParamToAccess(xParam, xParamAccess); > } > } > } > > public InternalPrepareUpdate_Context() { > } > > public void execute() { > if (!GetPrepared()) { > CheckConnected(); > FUpdate.SetCommand(GetSQLToAccess(FSql)); > iLoadParams(); > FUpdate.Prepare(); > } > } > } > > br.com.senior.svcl.db.RtAccess.TRtUpdate FUpdate; > private TRtOnErrorExecutingMultipleSQLs FOnErrorExecutingMultipleSQLs; > > protected void CheckConnected() { > if (FUpdate == null) { > super.CheckConnected(); > } > } > > protected String ExecuteMultipleSQLs(String ASql, int aInitSubStep, String ALastSQLs) { > int xCount; > TInt p = new TInt(); > ALastSQLs = ""; > CheckConnected(); > xCount = 0; > p.v = 0; > while (p.v != -1) { > FSql = TrimRight(StrGetNextToken(ASql, p, SQLEOC_SEP)); > if (!FSql.equals("") && xCount >= aInitSubStep) { > ALastSQLs = ALastSQLs + FSql + EOL; > try { > InternalExecuteUpdate(); > } catch (Throwable any) { > if (FOnErrorExecutingMultipleSQLs != null) { > FOnErrorExecutingMultipleSQLs.run(xCount); > } > throw wrap(any); > } > } > xCount++; > } > FUpdate.UnPrepare(); > return ALastSQLs; > } > > protected void InternalPrepareUpdate() { > InternalPrepareUpdate_Context ctx = new InternalPrepareUpdate_Context(); > ctx.execute(); > } > > protected final void InternalExecuteUpdate() { > FUpdate.UnPrepare(); > InternalPrepareUpdate(); > if (FUseDataBaseDef != null && GetOwnerConnection().FRtDatabase != null) { > GetOwnerConnection().FRtDatabase.setDatabaseDef(FUseDataBaseDef); > } > try { > FUpdate.Execute(); > } finally { > if (FUseDataBaseDef != null && GetOwnerConnection().FRtDatabase != null) { > GetOwnerConnection().FRtDatabase.setDatabaseDef(GetOwnerConnection().getPhyDatabase()); > } > } > } > > protected void InternalUnPrepare() { > if (GetPrepared()) { > CheckConnected(); > FUpdate.UnPrepare(); > } > } > > public boolean GetPrepared() { > return FUpdate != null && FUpdate.GetPrepared(); > } > > protected void InitSQLKernel(TRtDBConnection aDbConn) { > if (FUpdate != null) { > FUpdate.Free(); > FUpdate = null; > } > if (aDbConn != null && aDbConn.IsOpen()) { > if (getDBVersionKind() != aDbConn.getDBVersionKind()) { > throw DelphiException.CreateFmt(TransStr("TC659", "Driver deveria se \"%s\" e não \"%s\".", true), new Object[] { cDBVersionKindNameArray[getDBVersionKind()], cDBVersionKindNameArray[aDbConn.getDBVersionKind()] }); > } > FUpdate = aDbConn.GetAccess().NewUpdate(); > } > } > > public void runCreateSQL(TRtDBConnection AConn) { > super.runCreateSQL(AConn); > FUpdate = AConn.GetAccess().NewUpdate(); > } > > public static TRtCustomUpdateSQL CreateSQL(TRtDBConnection AConn) { > TRtCustomUpdateSQL Result; > Result = new TRtCustomUpdateSQL(); > Result.runCreateSQL(AConn); > return Result; > } > > public void Destroy() { > FUpdate.Free(); > FUpdate = null; > super.Destroy(); > } > > public void ExecuteUpd() { > FSql = GetSQL(); > InternalExecuteUpdate(); > FUpdate.UnPrepare(); > } > > public final br.com.senior.svcl.db.RtAccess.TRtUpdate GetRtUpdate() { > if (!GetPrepared() && Trim(FSql).equals("")) { > FSql = GetSQL(); > } > InternalPrepareUpdate(); > return FUpdate; > } > > public TRtCustomUpdateSQLClass ClassType() { > return TRtCustomUpdateSQLClass.SINGLETON; > } > > public void setOnErrorExecutingMultipleSQLs(TRtOnErrorExecutingMultipleSQLs value) { > FOnErrorExecutingMultipleSQLs = value; > } > > public TRtOnErrorExecutingMultipleSQLs getOnErrorExecutingMultipleSQLs() { > return FOnErrorExecutingMultipleSQLs; > } > } > > public static class TRtColumnSqlGenerator extends TPersistent { > > public String GenColumnName(TRtAddColumnItem aColumnItem) { > return ClassType().GenColumnName(aColumnItem); > } > > public String GenColumnDetailDataType(TRtAddColumnItem aColumnItem, IRtDatabaseDef aDataBaseDef, TString aKindName, TString aLength, TString aPrecision) { > return ClassType().GenColumnDetailDataType(aColumnItem, aDataBaseDef, aKindName, aLength, aPrecision); > } > > public String GenColumnNotNull(TRtAddColumnItem aColumnItem) { > return ClassType().GenColumnNotNull(aColumnItem); > } > > public String GenColumnStorage(TRtAddColumnItem aColumnItem, TRtCustomStorageList aStorage, String aTableName) { > return ClassType().GenColumnStorage(aColumnItem, aStorage, aTableName); > } > > public TRtColumnSqlGeneratorClass ClassType() { > return TRtColumnSqlGeneratorClass.SINGLETON; > } > } > > public static class TRtAddColumnItemClass extends TSQLNamedContainerItemClass { > > public static final TRtAddColumnItemClass SINGLETON = new TRtAddColumnItemClass(); > > public final TRtAddColumnItem CreateAdd(TRtAddColumnsList AOwner, String AColName, int AColType, int AColLen, int AColPrec, boolean LNotNull) { > return TRtAddColumnItem.CreateAdd(AOwner, AColName, AColType, AColLen, AColPrec, LNotNull); > } > > public TRtAddColumnItem Create() { > return TRtAddColumnItem.Create(); > } > > public Class<? extends TRtAddColumnItem> ClassInfo() { > return TRtAddColumnItem.class; > } > } > > public static class TRtAddColumnItem extends TSQLNamedContainerItem { > > protected int FDBVersionKind; > protected int FOption; > protected String FColName; > protected int FColType; > protected int FColLen; > protected int FColPrec; > protected boolean FNotNull; > > protected void SetOption(int Value) { > CheckUnprepare(); > SetName(IntToStr((int) Value) + FColName); > FOption = Value; > } > > public final void SetColName(String Value) { > CheckUnprepare(); > SetName(IntToStr((int) FOption) + Value); > FColName = Value; > } > > public final void SetColType(int Value) { > CheckUnprepare(); > FColType = Value; > } > > public final void SetColLen(int Value) { > CheckUnprepare(); > FColLen = Value; > } > > public final void SetColPrec(short Value) { > CheckUnprepare(); > FColPrec = Value; > } > > public final void SetNotNull(boolean Value) { > CheckUnprepare(); > FNotNull = Value; > } > > protected final void InitAdd(TRtAddColumnsList aOwner, String AColName, int aColType, int aColLen, int aColPrec, boolean LNotNull) { > FOption = rcaAdd; > FColName = AColName; > FColType = aColType; > FColLen = (int) aColLen; > FColPrec = (short) aColPrec; > FNotNull = LNotNull; > FDBVersionKind = aOwner.FDBVersionKind; > SetName(IntToStr((int) FOption) + FColName); > aOwner.AddItem(this); > } > > public final void runCreateAdd(TRtAddColumnsList AOwner, String AColName, int AColType, int AColLen, int AColPrec, boolean LNotNull) { > super.runCreate(); > InitAdd(AOwner, AColName, AColType, AColLen, AColPrec, LNotNull); > } > > public static TRtAddColumnItem CreateAdd(TRtAddColumnsList AOwner, String AColName, int AColType, int AColLen, int AColPrec, boolean LNotNull) { > TRtAddColumnItem Result; > Result = new TRtAddColumnItem(); > Result.runCreateAdd(AOwner, AColName, AColType, AColLen, AColPrec, LNotNull); > return Result; > } > > public final String GenSql(IRtDatabaseDef aDataBaseDef, TRtCustomStorageList aStorage, String aTableName) { > return GenSqlEx(DelphiSet.get(cgsoColumnName, cgsoColumnType, cgsoColumnNotNull, cgsoColumnStorage), aDataBaseDef, aStorage, aTableName); > } > > public final String GenSqlEx(DelphiSet aColumnGenSqlOptionSet, IRtDatabaseDef aDataBaseDef, TRtCustomStorageList aStorage, String aTableName) { > String Result = ""; > TString xKindName = new TString(); > TString xLeng = new TString(); > TString xPrec = new TString(); > TRtColumnSqlGeneratorClass vColumnSqlGeneratorClass; > vColumnSqlGeneratorClass = TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetColumnSqlGeneratorClass(FDBVersionKind); > if (aColumnGenSqlOptionSet.contains(cgsoColumnName)) { > Result = vColumnSqlGeneratorClass.GenColumnName(this) + ToStr(SQL_Space); > } else { > Result = ""; > } > if (aColumnGenSqlOptionSet.contains(cgsoColumnType)) { > Result = Result + vColumnSqlGeneratorClass.GenColumnDetailDataType(this, aDataBaseDef, xKindName, xLeng, xPrec) + ToStr(SQL_Space); > } > if (aColumnGenSqlOptionSet.contains(cgsoColumnNotNull)) { > Result = Result + vColumnSqlGeneratorClass.GenColumnNotNull(this); > } > if (aColumnGenSqlOptionSet.contains(cgsoColumnStorage)) { > Result = Result + vColumnSqlGeneratorClass.GenColumnStorage(this, aStorage, aTableName); > } > return TrimRight(Result); > } > > public final void GenSqlKind(IRtDatabaseDef aDataBaseDef, TString aKindName, TString aLength, TString aPrecision, TString aNull) { > TRtColumnSqlGeneratorClass vColumnSqlGeneratorClass; > vColumnSqlGeneratorClass = TRtDatabaseServerClass.SINGLETON.GlobalInstance().GetColumnSqlGeneratorClass(FDBVersionKind); > vColumnSqlGeneratorClass.GenColumnDetailDataType(this, aDataBaseDef, aKindName, aLength, aPrecision); > aNull.v = vColumnSqlGeneratorClass.GenColumnNotNull(this); > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtAddColumnItem) { > FOption = ((TRtAddColumnItem) Source).FOption; > FColName = ((TRtAddColumnItem) Source).FColName; > FColType = ((TRtAddColumnItem) Source).FColType; > FColLen = ((TRtAddColumnItem) Source).FColLen; > FColPrec = ((TRtAddColumnItem) Source).FColPrec; > FNotNull = ((TRtAddColumnItem) Source).FNotNull; > } > } > > public final void AssignFromFieldDef(TRtFieldDef AFldDef) { > CheckUnprepare(); > { > TRtFieldDef context_AFldDef = AFldDef; > FColName = context_AFldDef.GetName(); > FColType = context_AFldDef.GetFullKind().GetEnumType(); > FColLen = context_AFldDef.GetLength(); > FColPrec = context_AFldDef.GetPrecision(); > FNotNull = context_AFldDef.getNotNull(); > } > } > > public final void AssignToFieldDef(TRtFieldDef AFldDef) { > AFldDef.SetFullKind(TRtPhyBaseTypeClass.SINGLETON.ClassFromEnumType(FColType), "", FColLen, FColPrec); > AFldDef.SetNotNull(FNotNull); > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > { > TReader context_Reader = Reader; > context_Reader.Read(AsVar(FOption), SizeOf(FOption)); > FColName = context_Reader.ReadString(); > context_Reader.Read(AsVar(FColType), SizeOf(FColType)); > context_Reader.Read(AsVar(FColLen), SizeOf_UShort); > context_Reader.Read(AsVar(FColPrec), SizeOf_UByte); > FNotNull = context_Reader.ReadBoolean(); > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > { > TWriter context_Writer = Writer; > context_Writer.Write(AsConst(FOption), SizeOf(FOption)); > context_Writer.WriteString(FColName); > context_Writer.Write(AsConst(FColType), SizeOf(FColType)); > context_Writer.Write(AsConst(FColLen), SizeOf_UShort); > context_Writer.Write(AsConst(FColPrec), SizeOf_UByte); > context_Writer.WriteBoolean(FNotNull); > } > } > > public static TRtAddColumnItem Create() { > TRtAddColumnItem Result; > Result = new TRtAddColumnItem(); > Result.runCreate(); > return Result; > } > > public TRtAddColumnItemClass ClassType() { > return TRtAddColumnItemClass.SINGLETON; > } > > public int getOption() { > return FOption; > } > > public String getColName() { > return FColName; > } > > public int getColType() { > return FColType; > } > > public int getColLength() { > return FColLen; > } > > public int getColPrecision() { > return FColPrec; > } > > public boolean getNotNull() { > return FNotNull; > } > } > > public static final class TRtModifyColumnItemClass extends TRtAddColumnItemClass { > > public static final TRtModifyColumnItemClass SINGLETON = new TRtModifyColumnItemClass(); > > public final TRtModifyColumnItem CreateModify(TRtModifyColumnsList AOwner, String AOldColName, String ANewColName, int AColType, int AColLen, int AColPrec, boolean LNotNull, boolean LNotNullChanged) { > return TRtModifyColumnItem.CreateModify(AOwner, AOldColName, ANewColName, AColType, AColLen, AColPrec, LNotNull, LNotNullChanged); > } > > public final TRtModifyColumnItem CreateDrop(TRtModifyColumnsList AOwner, String AColName) { > return TRtModifyColumnItem.CreateDrop(AOwner, AColName); > } > > public Class<? extends TRtModifyColumnItem> ClassInfo() { > return TRtModifyColumnItem.class; > } > } > > public static final class TRtModifyColumnItem extends TRtAddColumnItem { > > public final boolean GetCriticalChange() { > boolean Result; > TRtAlterTable OwnerAT; > TRtTableDef OldTblDef; > TRtFieldDef AFldDef; > boolean LDropColumnOnUC; > boolean LChangeColumnType; > boolean LDecraseColumnSize; > boolean LNewNotNullColumn; > String s = ""; > String xPhyNativeKindName = ""; > Result = false; > OwnerAT = ((TRtAlterTable) GetTypedOwner(TRtAlterTableClass.SINGLETON)); > LDropColumnOnUC = false; > LChangeColumnType = false; > LDecraseColumnSize = false; > LNewNotNullColumn = false; > switch (getOption()) { > case rcaDrop: > if (Result) { > OldTblDef = OwnerAT.GetOwnerConnection().FPhyDatabase.CheckTableByName(OwnerAT.FTableName); > AFldDef = OldTblDef.FieldByName(getColName()); > LDropColumnOnUC = AFldDef.GetIsUniqueKey() || AFldDef.GetIsPrimaryKey() || AFldDef.GetIsUniqueConstraint(); > } > break; > case rcaModify: > if (!LChangeColumnType) { > if (GetIsRenamingCol()) { > s = getOldColName(); > } else { > s = getColName(); > } > OldTblDef = OwnerAT.GetOwnerConnection().FPhyDatabase.CheckTableByName(OwnerAT.FTableName); > AFldDef = OldTblDef.FieldByName(s); > LNewNotNullColumn = !AFldDef.getNotNull() && FNotNull; > if (AFldDef.GetPhyNativeStrKindName().equals("")) { > LChangeColumnType = AFldDef.GetFullKind().GetEnumType() != getColType(); > } else { > xPhyNativeKindName = OwnerAT.GetOwnerConnection().GetNewDatabase().CheckTableByName(OwnerAT.FTableName).CheckFieldByName(getOldColName()).GetPhyNativeStrKindName(); > LChangeColumnType = !SameText(AFldDef.GetPhyNativeStrKindName(), xPhyNativeKindName); > } > LDecraseColumnSize = !LChangeColumnType && (AFldDef.GetLength() - AFldDef.GetPrecision() > getColLength() - getColPrecision() || AFldDef.GetPrecision() > getColPrecision()); > } > break; > default: > LNewNotNullColumn = FNotNull; > break; > } > return Result || LDropColumnOnUC || LChangeColumnType || LDecraseColumnSize || LNewNotNullColumn || OwnerAT.MaxRestrictionGenCriticalChanges(); > } > > public final void SetOption(int Value) { > CheckUnprepare(); > FOption = Value; > } > > public final void SetOldColName(String Value) { > CheckUnprepare(); > FOldColName = Value; > } > > protected String FOldColName; > protected boolean FNotNullChanged; > > protected final void InitModify(TRtModifyColumnsList AOwner, String AOldColName, String ANewColName, int AColType, int AColLen, int AColPrec, boolean LNotNull, boolean LNotNullChanged) { > FOption = rcaModify; > FOldColName = AOldColName; > FColName = ANewColName; > FColType = AColType; > FColLen = (int) AColLen; > FColPrec = (short) AColPrec; > FNotNull = LNotNull; > FNotNullChanged = LNotNullChanged; > FDBVersionKind = AOwner.FDBVersionKind; > SetName(IntToStr((int) FOption) + FColName); > AOwner.AddItem(this); > } > > protected final void InitDrop(TRtModifyColumnsList AOwner, String AColName) { > FOption = rcaDrop; > FColName = AColName; > SetName(IntToStr((int) FOption) + FColName); > AOwner.AddItem(this); > } > > public final boolean GetIsRenamingCol() { > return !StrIsBlank(getOldColName()) && CompareText(getOldColName(), getColName()) != 0; > } > > public final void SetNotNullChanged(boolean Value) { > CheckUnprepare(); > FNotNullChanged = Value; > } > > public final void runCreateModify(TRtModifyColumnsList AOwner, String AOldColName, String ANewColName, int AColType, int AColLen, int AColPrec, boolean LNotNull, boolean LNotNullChanged) { > super.runCreate(); > InitModify(AOwner, AOldColName, ANewColName, AColType, AColLen, AColPrec, LNotNull, LNotNullChanged); > } > > public static TRtModifyColumnItem CreateModify(TRtModifyColumnsList AOwner, String AOldColName, String ANewColName, int AColType, int AColLen, int AColPrec, boolean LNotNull, boolean LNotNullChanged) { > TRtModifyColumnItem Result; > Result = new TRtModifyColumnItem(); > Result.runCreateModify(AOwner, AOldColName, ANewColName, AColType, AColLen, AColPrec, LNotNull, LNotNullChanged); > return Result; > } > > public final void runCreateDrop(TRtModifyColumnsList AOwner, String AColName) { > super.runCreate(); > InitDrop(AOwner, AColName); > } > > public static TRtModifyColumnItem CreateDrop(TRtModifyColumnsList AOwner, String AColName) { > TRtModifyColumnItem Result; > Result = new TRtModifyColumnItem(); > Result.runCreateDrop(AOwner, AColName); > return Result; > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtModifyColumnItem) { > FOldColName = ((TRtModifyColumnItem) Source).FOldColName; > FNotNullChanged = ((TRtModifyColumnItem) Source).FNotNullChanged; > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > { > TReader context_Reader = Reader; > FOldColName = context_Reader.ReadString(); > FNotNullChanged = context_Reader.ReadBoolean(); > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > { > TWriter context_Writer = Writer; > context_Writer.WriteString(FOldColName); > context_Writer.WriteBoolean(FNotNullChanged); > } > } > > public TRtModifyColumnItemClass ClassType() { > return TRtModifyColumnItemClass.SINGLETON; > } > > public int getOption() { > return FOption; > } > > public String getOldColName() { > return FOldColName; > } > > public boolean getNotNullChanged() { > return FNotNullChanged; > } > } > > public static class TRtAddColumnsListClass extends TSQLNamedListOwnerClass { > > public static final TRtAddColumnsListClass SINGLETON = new TRtAddColumnsListClass(); > > public TRtAddColumnsList Create() { > return TRtAddColumnsList.Create(); > } > > public Class<? extends TRtAddColumnsList> ClassInfo() { > return TRtAddColumnsList.class; > } > } > > public static class TRtAddColumnsList extends TSQLNamedListOwner { > > protected int FDBVersionKind; > > protected TContainerItemClass AllocItemType() { > return TRtAddColumnItemClass.SINGLETON; > } > > public TRtAddColumnItem GetItem(int Index) { > return ((TRtAddColumnItem) Get(Index)); > } > > public TRtAddColumnItem AddColumn(String ANewColName, int AColType, int AColLen, int AColPrec, boolean LNotNull) { > TRtAddColumnItem Result; > CheckUnprepare(); > Result = ((TRtAddColumnItem) AllocItemType().Create()); > Result.InitAdd(this, ANewColName, AColType, AColLen, AColPrec, LNotNull); > return Result; > } > > public TRtAddColumnItem ItemByName(String AName, int AOption) { > return ((TRtAddColumnItem) super.ItemByName(IntToStr((int) AOption) + AName)); > } > > public final int IndexByName(String AName, int AOption) { > return super.IndexByName(IntToStr((int) AOption) + AName); > } > > public final int RemoveByName(String AName, int AOption) { > return super.RemoveByName(IntToStr((int) AOption) + AName); > } > > public TRtAddColumnItem ItemByColumnName(String AName) { > TRtAddColumnItem Result; > int i; > i = IndexByColumnName(AName); > if (i >= 0) { > Result = this.GetItem(i); > } else { > Result = null; > } > return Result; > } > > public final int IndexByColumnName(String AName) { > int Result; > int i; > for (i = 0; i <= GetCount() - 1; ++i) { > if (CompareText(this.GetItem(i).getColName(), AName) == 0) { > Result = i; > return Result; > } > } > return -1; > } > > public final int RemoveByColumnName(String AName) { > int Result; > Result = IndexByColumnName(AName); > if (Result >= 0) { > Delete(Result); > } > return Result; > } > > public static TRtAddColumnsList Create() { > TRtAddColumnsList Result; > Result = new TRtAddColumnsList(); > Result.runCreate(); > return Result; > } > > public TRtAddColumnsListClass ClassType() { > return TRtAddColumnsListClass.SINGLETON; > } > } > > public static final class TRtModifyColumnsListClass extends TRtAddColumnsListClass { > > public static final TRtModifyColumnsListClass SINGLETON = new TRtModifyColumnsListClass(); > > public Class<? extends TRtModifyColumnsList> ClassInfo() { > return TRtModifyColumnsList.class; > } > } > > public static final class TRtModifyColumnsList extends TRtAddColumnsList { > > protected TContainerItemClass AllocItemType() { > return TRtModifyColumnItemClass.SINGLETON; > } > > public final TRtModifyColumnItem GetItem(int Index) { > return ((TRtModifyColumnItem) Get(Index)); > } > > public final TRtModifyColumnItem AddColumn(String ANewColName, int AColType, int AColLen, int AColPrec, boolean LNotNull) { > return ((TRtModifyColumnItem) super.AddColumn(ANewColName, AColType, AColLen, AColPrec, LNotNull)); > } > > public final TRtModifyColumnItem ModifyColumn(String AOldColName, String ANewColName, int AColType, int AColLen, int AColPrec, boolean LNotNull, boolean LNotNullChanged) { > TRtModifyColumnItem Result; > CheckUnprepare(); > Result = ((TRtModifyColumnItem) AllocItemType().Create()); > Result.InitModify(this, AOldColName, ANewColName, AColType, AColLen, AColPrec, LNotNull, LNotNullChanged); > return Result; > } > > public final TRtModifyColumnItem DropColumn(String AColName) { > TRtModifyColumnItem Result; > CheckUnprepare(); > Result = ((TRtModifyColumnItem) AllocItemType().Create()); > Result.InitDrop(this, AColName); > return Result; > } > > public final TRtModifyColumnItem ItemByName(String AName, int AOption) { > return ((TRtModifyColumnItem) super.ItemByName(AName, AOption)); > } > > public final TRtModifyColumnItem ItemByColumnName(String AName) { > return ((TRtModifyColumnItem) super.ItemByColumnName(AName)); > } > > public final TRtModifyColumnItem ItemByOldColumnName(String AName) { > TRtModifyColumnItem Result; > int i; > i = IndexByOldColumnName(AName); > if (i >= 0) { > Result = this.GetItem(i); > } else { > Result = null; > } > return Result; > } > > public final int IndexByOldColumnName(String AName) { > int Result; > int i; > for (i = 0; i <= GetCount() - 1; ++i) { > if (CompareText(this.GetItem(i).getOldColName(), AName) == 0) { > Result = i; > return Result; > } > } > return -1; > } > > public final int RemoveByOldColumnName(String AName) { > int Result; > Result = IndexByOldColumnName(AName); > if (Result >= 0) { > Delete(Result); > } > return Result; > } > > public TRtModifyColumnsListClass ClassType() { > return TRtModifyColumnsListClass.SINGLETON; > } > } > > public static class TRtSingleIndexColumnItem extends TSQLContainerItem { > > String FColName; > > public final void SetColName(String Value) { > CheckUnprepare(); > FColName = Value; > } > > public final void runCreateColumn(TRtSingleIndexItem AOwner, String AColName) { > super.runCreate(); > FColName = AColName; > AOwner.AddItem(this); > } > > public static TRtSingleIndexColumnItem CreateColumn(TRtSingleIndexItem AOwner, String AColName) { > TRtSingleIndexColumnItem Result; > Result = new TRtSingleIndexColumnItem(); > Result.runCreateColumn(AOwner, AColName); > return Result; > } > > public void Assign(TPersistent Source) { > if (Source instanceof TRtSingleIndexColumnItem) { > FColName = ((TRtSingleIndexColumnItem) Source).FColName; > } else { > super.Assign(Source); > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > { > TReader context_Reader = Reader; > FColName = context_Reader.ReadString(); > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > { > TWriter context_Writer = Writer; > context_Writer.WriteString(FColName); > } > } > > public static TRtSingleIndexColumnItem Create() { > TRtSingleIndexColumnItem Result; > Result = new TRtSingleIndexColumnItem(); > Result.runCreate(); > return Result; > } > > public TRtSingleIndexColumnItemClass ClassType() { > return TRtSingleIndexColumnItemClass.SINGLETON; > } > > public String getColName() { > return FColName; > } > } > > public static class TRtSingleIndexColumnItemClass extends TSQLContainerItemClass { > > public static final TRtSingleIndexColumnItemClass SINGLETON = new TRtSingleIndexColumnItemClass(); > > public final TRtSingleIndexColumnItem CreateColumn(TRtSingleIndexItem AOwner, String AColName) { > return TRtSingleIndexColumnItem.CreateColumn(AOwner, AColName); > } > > public TRtSingleIndexColumnItem Create() { > return TRtSingleIndexColumnItem.Create(); > } > > public Class<? extends TRtSingleIndexColumnItem> ClassInfo() { > return TRtSingleIndexColumnItem.class; > } > } > > public static final class TRtIndexColumnItem extends TRtSingleIndexColumnItem { > > private int FOrder; > > public final void SetOrder(int Value) { > CheckUnprepare(); > FOrder = Value; > } > > public final void runCreateColumn(TRtIndexItem AOwner, String AColName, int AOrder) { > super.runCreate(); > FColName = AColName; > FOrder = AOrder; > AOwner.AddItem(this); > } > > public static TRtIndexColumnItem CreateColumn(TRtIndexItem AOwner, String AColName, int AOrder) { > TRtIndexColumnItem Result; > Result = new TRtIndexColumnItem(); > Result.runCreateColumn(AOwner, AColName, AOrder); > return Result; > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtIndexColumnItem) { > FOrder = ((TRtIndexColumnItem) Source).FOrder; > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > { > TReader context_Reader = Reader; > context_Reader.Read(AsVar(FOrder), SizeOf(FOrder)); > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > { > TWriter context_Writer = Writer; > context_Writer.Write(AsConst(FOrder), SizeOf(FOrder)); > } > } > > public TRtIndexColumnItemClass ClassType() { > return TRtIndexColumnItemClass.SINGLETON; > } > > public int getOrder() { > return FOrder; > } > } > > public static final class TRtIndexColumnItemClass extends TRtSingleIndexColumnItemClass { > > public static final TRtIndexColumnItemClass SINGLETON = new TRtIndexColumnItemClass(); > > public final TRtIndexColumnItem CreateColumn(TRtIndexItem AOwner, String AColName, int AOrder) { > return TRtIndexColumnItem.CreateColumn(AOwner, AColName, AOrder); > } > > public Class<? extends TRtIndexColumnItem> ClassInfo() { > return TRtIndexColumnItem.class; > } > } > > public static class TRtSingleIndexColumnListClass extends TSQLTypedListOwnerClass { > > public static final TRtSingleIndexColumnListClass SINGLETON = new TRtSingleIndexColumnListClass(); > > public Class<? extends TRtSingleIndexColumnList> ClassInfo() { > return TRtSingleIndexColumnList.class; > } > } > > public static class TRtSingleIndexColumnList extends TSQLTypedListOwner { > > protected TContainerItemClass AllocItemType() { > return TRtSingleIndexColumnItemClass.SINGLETON; > } > > public TRtSingleIndexColumnItem GetItem(int Index) { > return ((TRtSingleIndexColumnItem) Get(Index)); > } > > public TRtSingleIndexColumnListClass ClassType() { > return TRtSingleIndexColumnListClass.SINGLETON; > } > } > > public static final class TRtIndexColumnListClass extends TRtSingleIndexColumnListClass { > > public static final TRtIndexColumnListClass SINGLETON = new TRtIndexColumnListClass(); > > public Class<? extends TRtIndexColumnList> ClassInfo() { > return TRtIndexColumnList.class; > } > } > > public static final class TRtIndexColumnList extends TRtSingleIndexColumnList { > > protected TContainerItemClass AllocItemType() { > return TRtIndexColumnItemClass.SINGLETON; > } > > public final TRtIndexColumnItem GetItem(int Index) { > return ((TRtIndexColumnItem) Get(Index)); > } > > public TRtIndexColumnListClass ClassType() { > return TRtIndexColumnListClass.SINGLETON; > } > } > > public static class TRtSingleIndexItemClass extends TSQLNamedContainerItemClass { > > public static final TRtSingleIndexItemClass SINGLETON = new TRtSingleIndexItemClass(); > > public TRtSingleIndexItem Create() { > return TRtSingleIndexItem.Create(); > } > > public final TRtSingleIndexItem CreateParented(TRtSingleIndexItemList AOwner, String IndexName) { > return TRtSingleIndexItem.CreateParented(AOwner, IndexName); > } > > public Class<? extends TRtSingleIndexItem> ClassInfo() { > return TRtSingleIndexItem.class; > } > } > > public static class TRtSingleIndexItem extends TSQLNamedContainerItem { > > int FOption; > TRtSingleIndexColumnList FColumns; > > final void AddItem(TRtSingleIndexColumnItem AItem) { > CheckUnprepare(); > FColumns.Add(AItem); > } > > final void Init(TRtSingleIndexItemList AOwner, String IndexName) { > SetName(IndexName); > if (AOwner != null) { > AOwner.AddItem(this); > } > FColumns = ((TRtSingleIndexColumnList) Creator(this, TRtSingleIndexColumnListClass.SINGLETON)); > } > > public final void SetOption(int AOption) { > if (AOption != rcaAdd && GetTypedOwner(TRtAlterTableClass.SINGLETON) == null) { > throw DelphiException.Create(TransStr("TC660", "Opção suportada só sobre TRtAlterTable.", true)); > } > FOption = AOption; > CheckUnprepare(); > } > > public void runCreate() { > super.runCreate(); > FColumns = ((TRtSingleIndexColumnList) Creator(this, TRtSingleIndexColumnListClass.SINGLETON)); > } > > public static TRtSingleIndexItem Create() { > TRtSingleIndexItem Result; > Result = new TRtSingleIndexItem(); > Result.runCreate(); > return Result; > } > > public final void runCreateParented(TRtSingleIndexItemList AOwner, String IndexName) { > super.runCreate(); > Init(AOwner, IndexName); > } > > public static TRtSingleIndexItem CreateParented(TRtSingleIndexItemList AOwner, String IndexName) { > TRtSingleIndexItem Result; > Result = new TRtSingleIndexItem(); > Result.runCreateParented(AOwner, IndexName); > return Result; > } > > public void Destroy() { > FColumns.Free(); > super.Destroy(); > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtSingleIndexItem) { > FOption = ((TRtSingleIndexItem) Source).FOption; > FColumns.Assign(((TRtSingleIndexItem) Source).FColumns); > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > Reader.Read(AsVar(FOption), SizeOf(FOption)); > FColumns.ReadData(Reader); > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.Write(AsConst(FOption), SizeOf(FOption)); > FColumns.WriteData(Writer); > } > > public TRtSingleIndexColumnItem ItemByColumnName(String AColName) { > TRtSingleIndexColumnItem Result; > int i; > i = IndexByColumnName(AColName); > if (i >= 0) { > Result = FColumns.GetItem(i); > } else { > Result = null; > } > return Result; > } > > public final int IndexByColumnName(String AColName) { > int Result; > int i; > for (i = 0; i <= FColumns.GetCount() - 1; ++i) { > if (CompareText(FColumns.GetItem(i).getColName(), AColName) == 0) { > Result = i; > return Result; > } > } > return -1; > } > > public final int RemoveByColumnName(String AColName) { > int Result; > Result = IndexByColumnName(AColName); > if (Result >= 0) { > FColumns.Delete(Result); > } > return Result; > } > > public final void AddColumn(String AColName) { > TRtSingleIndexColumnItemClass AClass; > CheckUnprepare(); > AClass = ((TRtSingleIndexColumnItemClass) FColumns.AllocItemType()); > AClass.CreateColumn(this, AColName); > } > > public final void AddAllColumns(String AColNames) { > TInt p = new TInt(); > String s = ""; > CheckUnprepare(); > p.v = 0; > s = StrGetNextToken(AColNames, p, ';'); > while (!StrIsBlank(s)) { > AddColumn(s); > s = StrGetNextToken(AColNames, p, ';'); > } > } > > public TRtSingleIndexItemClass ClassType() { > return TRtSingleIndexItemClass.SINGLETON; > } > > public int getOption() { > return FOption; > } > > public TRtSingleIndexColumnList getColumns() { > return FColumns; > } > } > > public static final class TRtIndexItemClass extends TRtSingleIndexItemClass { > > public static final TRtIndexItemClass SINGLETON = new TRtIndexItemClass(); > > public final TRtIndexItem CreateParented(TRtIndexItemList AOwner, String IndexName, boolean LUnique) { > return TRtIndexItem.CreateParented(AOwner, IndexName, LUnique); > } > > public TContainerItem Creator(TPersistent AOwner, TContainerItemClass AType) { > if (AType == TRtSingleIndexColumnListClass.SINGLETON) { > AType = TRtIndexColumnListClass.SINGLETON; > } > return super.Creator(AOwner, AType); > } > > public Class<? extends TRtIndexItem> ClassInfo() { > return TRtIndexItem.class; > } > } > > public static final class TRtIndexItem extends TRtSingleIndexItem { > > boolean FUnique; > > final void Init(TRtIndexItemList AOwner, String IndexName, boolean LUnique) { > super.Init(AOwner, IndexName); > FUnique = LUnique; > } > > public final TRtIndexColumnList GetColumns() { > return (TRtIndexColumnList) FColumns; > } > > public final void SetUnique(boolean Value) { > CheckUnprepare(); > FUnique = Value; > } > > public final void runCreateParented(TRtIndexItemList AOwner, String IndexName, boolean LUnique) { > super.runCreate(); > Init(AOwner, IndexName, LUnique); > } > > public static TRtIndexItem CreateParented(TRtIndexItemList AOwner, String IndexName, boolean LUnique) { > TRtIndexItem Result; > Result = new TRtIndexItem(); > Result.runCreateParented(AOwner, IndexName, LUnique); > return Result; > } > > public TContainerItem Creator(TPersistent AOwner, TContainerItemClass AType) { > return ClassType().Creator(AOwner, AType); > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtIndexItem) { > FUnique = ((TRtIndexItem) Source).FUnique; > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > FUnique = Reader.ReadBoolean(); > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.WriteBoolean(FUnique); > } > > public final TRtIndexColumnItem ItemByColumnName(String AColName) { > return ((TRtIndexColumnItem) super.ItemByColumnName(AColName)); > } > > public final void AddColumnOrdered(String AColName, int AOrder) { > TRtIndexColumnItemClass AClass; > CheckUnprepare(); > AClass = ((TRtIndexColumnItemClass) FColumns.AllocItemType()); > AClass.CreateColumn(this, AColName, AOrder); > } > > public TRtIndexItemClass ClassType() { > return TRtIndexItemClass.SINGLETON; > } > > public int getOption() { > return FOption; > } > > public boolean getUnique() { > return FUnique; > } > } > > public static class TRtSingleIndexItemListClass extends TSQLNamedListOwnerClass { > > public static final TRtSingleIndexItemListClass SINGLETON = new TRtSingleIndexItemListClass(); > > public Class<? extends TRtSingleIndexItemList> ClassInfo() { > return TRtSingleIndexItemList.class; > } > } > > public static class TRtSingleIndexItemList extends TSQLNamedListOwner { > > protected TContainerItemClass AllocItemType() { > return TRtSingleIndexItemClass.SINGLETON; > } > > public TRtSingleIndexItem GetItem(int Index) { > return ((TRtSingleIndexItem) Get(Index)); > } > > protected final TRtSingleIndexItem AddUniqueConstraint(String IndexName) { > CheckUnprepare(); > return ((TRtSingleIndexItem) AddNewItem(IndexName)); > } > > public TRtSingleIndexItem ItemByName(String IndexName) { > return ((TRtSingleIndexItem) super.ItemByName(IndexName)); > } > > public TRtSingleIndexItemListClass ClassType() { > return TRtSingleIndexItemListClass.SINGLETON; > } > } > > public static final class TRtIndexItemListClass extends TRtSingleIndexItemListClass { > > public static final TRtIndexItemListClass SINGLETON = new TRtIndexItemListClass(); > > public Class<? extends TRtIndexItemList> ClassInfo() { > return TRtIndexItemList.class; > } > } > > public static final class TRtIndexItemList extends TRtSingleIndexItemList { > > protected TContainerItemClass AllocItemType() { > return TRtIndexItemClass.SINGLETON; > } > > public final TRtIndexItem GetItem(int Index) { > return ((TRtIndexItem) Get(Index)); > } > > public final TRtIndexItem AddIndex(String IndexName, boolean LUnique) { > TRtIndexItem Result; > CheckUnprepare(); > Result = ((TRtIndexItem) AddNewItem(IndexName)); > Result.FUnique = LUnique; > return Result; > } > > public final TRtIndexItem ItemByName(String IndexName) { > return ((TRtIndexItem) super.ItemByName(IndexName)); > } > > public TRtIndexItemListClass ClassType() { > return TRtIndexItemListClass.SINGLETON; > } > } > > public static final class TRtForeignKeyColumnItemClass extends TSQLNamedContainerItemClass { > > public static final TRtForeignKeyColumnItemClass SINGLETON = new TRtForeignKeyColumnItemClass(); > > public final TRtForeignKeyColumnItem CreateParented(TRtForeignKeyItem AOwner, String AThsColName, String AOthColName) { > return TRtForeignKeyColumnItem.CreateParented(AOwner, AThsColName, AOthColName); > } > > public Class<? extends TRtForeignKeyColumnItem> ClassInfo() { > return TRtForeignKeyColumnItem.class; > } > } > > public static final class TRtForeignKeyColumnItem extends TSQLNamedContainerItem { > > String FThsColName; > String FOthColName; > > public final void SetThsColName(String Value) { > CheckUnprepare(); > SetName(Value + FOthColName); > FThsColName = Value; > } > > public final void SetOthColName(String Value) { > CheckUnprepare(); > SetName(FThsColName + Value); > FOthColName = Value; > } > > final void Init(TRtForeignKeyItem AOwner, String AThsColName, String AOthColName) { > FThsColName = AThsColName; > FOthColName = AOthColName; > SetName(FThsColName + FOthColName); > AOwner.AddItem(this); > } > > public final void runCreateParented(TRtForeignKeyItem AOwner, String AThsColName, String AOthColName) { > super.runCreate(); > Init(AOwner, AThsColName, AOthColName); > } > > public static TRtForeignKeyColumnItem CreateParented(TRtForeignKeyItem AOwner, String AThsColName, String AOthColName) { > TRtForeignKeyColumnItem Result; > Result = new TRtForeignKeyColumnItem(); > Result.runCreateParented(AOwner, AThsColName, AOthColName); > return Result; > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtForeignKeyColumnItem) { > FThsColName = ((TRtForeignKeyColumnItem) Source).FThsColName; > FOthColName = ((TRtForeignKeyColumnItem) Source).FOthColName; > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > { > TReader context_Reader = Reader; > FThsColName = context_Reader.ReadString(); > FOthColName = context_Reader.ReadString(); > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > { > TWriter context_Writer = Writer; > context_Writer.WriteString(FThsColName); > context_Writer.WriteString(FOthColName); > } > } > > public TRtForeignKeyColumnItemClass ClassType() { > return TRtForeignKeyColumnItemClass.SINGLETON; > } > > public String getThsColName() { > return FThsColName; > } > > public String getOthColName() { > return FOthColName; > } > } > > public static final class TRtForeignKeyColumnListClass extends TSQLNamedListOwnerClass { > > public static final TRtForeignKeyColumnListClass SINGLETON = new TRtForeignKeyColumnListClass(); > > public Class<? extends TRtForeignKeyColumnList> ClassInfo() { > return TRtForeignKeyColumnList.class; > } > } > > public static final class TRtForeignKeyColumnList extends TSQLNamedListOwner { > > protected TContainerItemClass AllocItemType() { > return TRtForeignKeyColumnItemClass.SINGLETON; > } > > public final TRtForeignKeyColumnItem GetItem(int Index) { > return ((TRtForeignKeyColumnItem) Get(Index)); > } > > public TRtForeignKeyColumnListClass ClassType() { > return TRtForeignKeyColumnListClass.SINGLETON; > } > } > > public static final class TRtForeignKeyItemClass extends TSQLNamedContainerItemClass { > > public static final TRtForeignKeyItemClass SINGLETON = new TRtForeignKeyItemClass(); > > public TRtForeignKeyItem Create() { > return TRtForeignKeyItem.Create(); > } > > public final TRtForeignKeyItem CreateParented(TRtForeignKeyList AOwner, String AConstraintName) { > return TRtForeignKeyItem.CreateParented(AOwner, AConstraintName); > } > > public Class<? extends TRtForeignKeyItem> ClassInfo() { > return TRtForeignKeyItem.class; > } > } > > public static final class TRtForeignKeyItem extends TSQLNamedContainerItem { > > int FOption; > private TRtForeignKeyColumnList FColRelList; > String FForeignTable; > private String FReferenceTable; > > final void AddItem(TRtForeignKeyColumnItem AItem) { > CheckUnprepare(); > FColRelList.AddItem(AItem); > } > > final void Init(TRtForeignKeyList AOwner, String AConstraintName) { > SetName(AConstraintName); > if (AOwner != null) { > AOwner.AddItem(this); > } > } > > public final void SetOption(int AOption) { > if (AOption != rcaAdd && GetTypedOwner(TRtAlterTableClass.SINGLETON) == null) { > throw DelphiException.Create(TransStr("TC660", "Opção suportada só sobre TRtAlterTable.", true)); > } > FOption = AOption; > CheckUnprepare(); > } > > public final void SetReferenceTable(String Value) { > CheckUnprepare(); > FReferenceTable = Value; > } > > public final void SetForeignTable(String Value) { > CheckUnprepare(); > FForeignTable = Value; > } > > public final String GetForeignTable() { > String Result = ""; > if (StrIsBlank(FForeignTable)) { > Result = (((TRtCreateTable) GetTypedOwner(TRtCreateTableClass.SINGLETON))).GetTableName(); > } else { > Result = FForeignTable; > } > return Result; > } > > public void runCreate() { > super.runCreate(); > FColRelList = ((TRtForeignKeyColumnList) Creator(this, TRtForeignKeyColumnListClass.SINGLETON)); > } > > public static TRtForeignKeyItem Create() { > TRtForeignKeyItem Result; > Result = new TRtForeignKeyItem(); > Result.runCreate(); > return Result; > } > > public final void runCreateParented(TRtForeignKeyList AOwner, String AConstraintName) { > runCreate(); > Init(AOwner, AConstraintName); > } > > public static TRtForeignKeyItem CreateParented(TRtForeignKeyList AOwner, String AConstraintName) { > TRtForeignKeyItem Result; > Result = new TRtForeignKeyItem(); > Result.runCreateParented(AOwner, AConstraintName); > return Result; > } > > public void Destroy() { > FColRelList.Free(); > super.Destroy(); > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtForeignKeyItem) { > FOption = ((TRtForeignKeyItem) Source).FOption; > FForeignTable = ((TRtForeignKeyItem) Source).FForeignTable; > FReferenceTable = ((TRtForeignKeyItem) Source).FReferenceTable; > FColRelList.Assign(((TRtForeignKeyItem) Source).FColRelList); > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > Reader.Read(AsVar(FOption), SizeOf(FOption)); > FForeignTable = Reader.ReadString(); > FReferenceTable = Reader.ReadString(); > FColRelList.ReadData(Reader); > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.Write(AsConst(FOption), SizeOf(FOption)); > Writer.WriteString(FForeignTable); > Writer.WriteString(FReferenceTable); > FColRelList.WriteData(Writer); > } > > public final int IndexByColumnNames(String ThsColName, String OthColName) { > int Result; > for (Result = 0; Result <= FColRelList.GetCount() - 1; ++Result) { > { > TRtForeignKeyColumnItem context_GetItem = FColRelList.GetItem(Result); > if (CompareText(context_GetItem.FThsColName, context_GetItem.getThsColName()) == 0 && CompareText(context_GetItem.FOthColName, context_GetItem.getOthColName()) == 0) { > return Result; > } > } > } > return -1; > } > > public final int RemoveByColumnNames(String ThsColName, String OthColName) { > int Result; > Result = IndexByColumnNames(ThsColName, OthColName); > if (Result >= 0) { > FColRelList.Delete(Result); > } > return Result; > } > > public final int IndexByThsColumnName(String ThsColName) { > int Result; > for (Result = 0; Result <= FColRelList.GetCount() - 1; ++Result) { > if (CompareText(FColRelList.GetItem(Result).getThsColName(), ThsColName) == 0) { > return Result; > } > } > return -1; > } > > public final int RemoveByThsColumnName(String ThsColName) { > int Result; > Result = IndexByThsColumnName(ThsColName); > if (Result >= 0) { > FColRelList.Delete(Result); > } > return Result; > } > > public final int IndexByOthColumnName(String OthColName) { > int Result; > for (Result = 0; Result <= FColRelList.GetCount() - 1; ++Result) { > if (CompareText(FColRelList.GetItem(Result).getOthColName(), OthColName) == 0) { > return Result; > } > } > return -1; > } > > public final int RemoveByOthColumnName(String OthColName) { > int Result; > Result = IndexByOthColumnName(OthColName); > if (Result >= 0) { > FColRelList.Delete(Result); > } > return Result; > } > > public final void AddColumns(String ThsColName, String OthColName) { > CheckUnprepare(); > (((TRtForeignKeyColumnItem) FColRelList.AllocItemType().Create())).Init(this, ThsColName, OthColName); > } > > public TRtForeignKeyItemClass ClassType() { > return TRtForeignKeyItemClass.SINGLETON; > } > > public int getOption() { > return FOption; > } > > public String getReferenceTable() { > return FReferenceTable; > } > > public TRtForeignKeyColumnList getColumns() { > return FColRelList; > } > } > > public static final class TRtForeignKeyListClass extends TSQLNamedListOwnerClass { > > public static final TRtForeignKeyListClass SINGLETON = new TRtForeignKeyListClass(); > > public Class<? extends TRtForeignKeyList> ClassInfo() { > return TRtForeignKeyList.class; > } > } > > public static final class TRtForeignKeyList extends TSQLNamedListOwner { > > protected TContainerItemClass AllocItemType() { > return TRtForeignKeyItemClass.SINGLETON; > } > > public final TRtForeignKeyItem GetItem(int Index) { > return ((TRtForeignKeyItem) Get(Index)); > } > > public final TRtForeignKeyItem AddForeignKey(String AConstraintName, String AReferenceTable) { > TRtForeignKeyItem Result; > CheckUnprepare(); > Result = ((TRtForeignKeyItem) AddNewItem(AConstraintName)); > Result.SetReferenceTable(AReferenceTable); > return Result; > } > > public final TRtForeignKeyItem ItemByName(String ConstraintName) { > return ((TRtForeignKeyItem) super.ItemByName(ConstraintName)); > } > > public TRtForeignKeyListClass ClassType() { > return TRtForeignKeyListClass.SINGLETON; > } > } > > public static final class TRtTriggerItemClass extends TSQLNamedContainerItemClass { > > public static final TRtTriggerItemClass SINGLETON = new TRtTriggerItemClass(); > > public TRtTriggerItem Create() { > return TRtTriggerItem.Create(); > } > > public Class<? extends TRtTriggerItem> ClassInfo() { > return TRtTriggerItem.class; > } > } > > public static final class TRtTriggerItem extends TSQLNamedContainerItem { > > protected String FCode; > protected TRtCCompiledNodeList FCompiledCode; > protected int FOption; > protected boolean FForEachRow; > > public void SetName(String Value) { > if (StrIsBlank(GetName())) { > super.SetName(Value); > } > } > > public final void SetCode(String Value) { > TString AName = new TString(); > TString ATableName = new TString(); > DelphiSet AEvents = DelphiSet.get(); > TBoolean AForEachRow = new TBoolean(); > TRtTableSQL ATableSql; > TRtCCompiledNodeList ACCode; > CheckUnprepare(); > if (StrIsBlank(Value)) { > if (FCompiledCode != null) { > FCompiledCode.Free(); > } > FCompiledCode = null; > } else if (CompareText(Value, FCode) != 0 || FCompiledCode == null) { > ACCode = TriggerCreatorFunc(Value, AName, ATableName, AEvents, AForEachRow); > try { > super.SetName(AName.v); > ATableSql = ((TRtTableSQL) GetTypedOwner(TRtTableSQLClass.SINGLETON)); > if (ATableSql != null) { > if (StrIsBlank(ATableSql.GetName())) { > ATableSql.SetTableName(ATableName.v); > } else if (CompareText(ATableSql.GetName(), ATableName.v) != 0) { > throw DelphiException.CreateFmt(TransStr("TC661", "Nome da tabela \"%s\", referenciada pela trigger \"%s\" não confere com a tabela \"%s\".", true), new Object[] { ATableName.v, GetName(), ATableSql.GetName() }); > } > } > } catch (Throwable any) { > ACCode.Free(); > throw wrap(any); > } > if (FCompiledCode != null) { > FCompiledCode.Free(); > } > FCompiledCode = ACCode; > } > FCode = Value; > } > > public final void SetOption(int AOption) { > CheckUnprepare(); > FOption = AOption; > } > > protected final void Init(TRtTriggerItemList AOwner, String ATriggerName) { > CheckUnprepare(); > FCode = ""; > if (FCompiledCode != null) { > FCompiledCode.Free(); > FCompiledCode = null; > } > SetName(ATriggerName); > if (AOwner != null) { > AOwner.AddItem(this); > } > } > > public void Destroy() { > if (FCompiledCode != null) { > FCompiledCode.Free(); > FCompiledCode = null; > } > super.Destroy(); > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtTriggerItem) { > FCode = ((TRtTriggerItem) Source).FCode; > FForEachRow = ((TRtTriggerItem) Source).FForEachRow; > if (((TRtTriggerItem) Source).FCompiledCode != null) { > if (FCompiledCode == null) { > FCompiledCode = TRtCCompiledNodeList.Create(); > } > FCompiledCode.Assign(((TRtTriggerItem) Source).FCompiledCode); > } else if (FCompiledCode != null) { > FCompiledCode.Free(); > FCompiledCode = null; > } > FOption = ((TRtTriggerItem) Source).FOption; > } > } > > public void ReadData(TReader Reader) { > boolean LHasCompiledCode; > super.ReadData(Reader); > FCode = Reader.ReadString(); > LHasCompiledCode = Reader.ReadBoolean(); > if (LHasCompiledCode) { > if (FCompiledCode == null) { > FCompiledCode = TRtCCompiledNodeList.Create(); > } > FCompiledCode.ReadData(Reader); > } else if (FCompiledCode != null) { > FCompiledCode.Free(); > FCompiledCode = null; > } > Reader.Read(AsVar(FOption), SizeOf(FOption)); > FForEachRow = Reader.ReadBoolean(); > } > > public void WriteData(TWriter Writer) { > boolean LHasCompiledCode; > super.WriteData(Writer); > Writer.WriteString(FCode); > LHasCompiledCode = FCompiledCode != null; > Writer.WriteBoolean(LHasCompiledCode); > if (LHasCompiledCode) { > FCompiledCode.WriteData(Writer); > } > Writer.Write(AsConst(FOption), SizeOf(FOption)); > Writer.WriteBoolean(FForEachRow); > } > > public final void AssignFromTriggerDef(TRtTriggerDef ATrgDef) { > String ATableName = ""; > TRtTableSQL ATableSql; > CheckUnprepare(); > ATableName = ATrgDef.GetTable().GetName(); > ATableSql = ((TRtTableSQL) GetTypedOwner(TRtTableSQLClass.SINGLETON)); > if (ATableSql != null) { > if (StrIsBlank(ATableSql.GetName())) { > ATableSql.SetTableName(ATableName); > } else if (CompareText(ATableSql.GetName(), ATableName) != 0) { > throw DelphiException.CreateFmt(TransStr("TC661", "Nome da tabela \"%s\", referenciada pela trigger \"%s\" não confere com a tabela \"%s\".", true), new Object[] { ATableName, GetName(), ATableSql.GetName() }); > } > } > if (FCompiledCode != null) { > FCompiledCode.Free(); > } > FCompiledCode = null; > FCode = ATrgDef.getCode(); > FForEachRow = ATrgDef.getForEachRow(); > super.SetName(ATrgDef.GetName()); > } > > public final void CheckCompiledCode() { > if (FCompiledCode == null) { > SetCode(FCode); > } > } > > public static TRtTriggerItem Create() { > TRtTriggerItem Result; > Result = new TRtTriggerItem(); > Result.runCreate(); > return Result; > } > > public TRtTriggerItemClass ClassType() { > return TRtTriggerItemClass.SINGLETON; > } > > public String getCode() { > return FCode; > } > > public int getOption() { > return FOption; > } > > public TRtCCompiledNodeList getCompiledCode() { > return FCompiledCode; > } > > public boolean getForEachRow() { > return FForEachRow; > } > } > > public static final class TRtTriggerItemListClass extends TSQLNamedListOwnerClass { > > public static final TRtTriggerItemListClass SINGLETON = new TRtTriggerItemListClass(); > > public Class<? extends TRtTriggerItemList> ClassInfo() { > return TRtTriggerItemList.class; > } > } > > public static final class TRtTriggerItemList extends TSQLNamedListOwner { > > protected TContainerItemClass AllocItemType() { > return TRtTriggerItemClass.SINGLETON; > } > > public final TRtTriggerItem GetItem(int Index) { > return ((TRtTriggerItem) Get(Index)); > } > > protected final TRtTriggerItem AddNewItem(String _TrgName, boolean _ForEachRow) { > TRtTriggerItem Result; > int i; > Result = TRtTriggerItem.Create(); > Result.SetName(_TrgName); > Result.FForEachRow = _ForEachRow; > i = 0; > while (i < GetCount() && !GetItem(i).getForEachRow()) { > i++; > } > super.InsertItem(i, Result); > return Result; > } > > public final TRtTriggerItem AddTrigger(String ATrgName, String ACode, boolean _ForEachRow) { > TRtTriggerItem Result; > CheckUnprepare(); > Result = AddNewItem(ATrgName, _ForEachRow); > try { > Result.SetCode(ACode); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtTriggerItem AddTriggerFromTriggerDef(TRtTriggerDef ATrgDef) { > TRtTriggerItem Result; > CheckUnprepare(); > Result = AddNewItem(ATrgDef.GetName(), ATrgDef.getForEachRow()); > try { > Result.AssignFromTriggerDef(ATrgDef); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public final TRtTriggerItem ItemByName(String AName) { > return ((TRtTriggerItem) super.ItemByName(AName)); > } > > public TRtTriggerItemListClass ClassType() { > return TRtTriggerItemListClass.SINGLETON; > } > } > > public static class TRtTableSQLClass extends TRtCustomUpdateSQLClass { > > public static final TRtTableSQLClass SINGLETON = new TRtTableSQLClass(); > > protected TRtTableSQL CreateSQL(TRtDBConnection AConn, String ATableName) { > return TRtTableSQL.CreateSQL(AConn, ATableName); > } > > public TRtTableSQL Create() { > return TRtTableSQL.Create(); > } > > public Class<? extends TRtTableSQL> ClassInfo() { > return TRtTableSQL.class; > } > } > > public static class TRtTableSQL extends TRtCustomUpdateSQL { > > private String FTableName; > > public boolean GetHasOperation() { > return !StrIsBlank(GetName()); > } > > public final void SetTableName(String Value) { > CheckUnprepare(); > FTableName = Value; > } > > public final String GetName() { > return FTableName; > } > > protected void runCreateSQL(TRtDBConnection AConn, String ATableName) { > super.runCreateSQL(AConn); > FTableName = ATableName; > } > > protected static TRtTableSQL CreateSQL(TRtDBConnection AConn, String ATableName) { > TRtTableSQL Result; > Result = new TRtTableSQL(); > Result.runCreateSQL(AConn, ATableName); > return Result; > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtTableSQL) { > FTableName = ((TRtTableSQL) Source).FTableName; > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > FTableName = Reader.ReadString(); > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.WriteString(FTableName); > } > > public static TRtTableSQL Create() { > TRtTableSQL Result; > Result = new TRtTableSQL(); > Result.runCreate(); > return Result; > } > > public TRtTableSQLClass ClassType() { > return TRtTableSQLClass.SINGLETON; > } > } > > public static class TRtDDLFunctions extends TPersistent { > > public void CreateTriggers(TRtDBConnection _Connection, TRtTableDef _TableDef, TRtOnUpdateProgress _OnCompleted, TStrings _Script, boolean _reRaise) { > throw abstractCall(); > } > > public void DropTriggers(TRtDBConnection _Connection, TRtTableDef _TableDef, TRtOnUpdateProgress _OnCompleted, TStrings _Script, boolean _reRaise) { > throw abstractCall(); > } > > public void DisableConstraints(TRtDBConnection aConnection, TRtTableDef aTableDef, TStrings aScript, boolean areRaise) { > throw abstractCall(); > } > > public void EnableConstraints(TRtDBConnection aConnection, TStrings aTableList, TRtOnUpdateProgress aOnCompleted, TStrings aScript) { > throw abstractCall(); > } > > public TRtDDLFunctionsClass ClassType() { > return TRtDDLFunctionsClass.SINGLETON; > } > } > > public static class TRtDDLFunctionsClass extends TPersistentClass { > > public static final TRtDDLFunctionsClass SINGLETON = new TRtDDLFunctionsClass(); > > public void CreateTriggers(TRtDBConnection _Connection, TRtTableDef _TableDef, TRtOnUpdateProgress _OnCompleted, TStrings _Script, boolean _reRaise) { > throw abstractCall(); > } > > public void DropTriggers(TRtDBConnection _Connection, TRtTableDef _TableDef, TRtOnUpdateProgress _OnCompleted, TStrings _Script, boolean _reRaise) { > throw abstractCall(); > } > > public void DisableConstraints(TRtDBConnection aConnection, TRtTableDef aTableDef, TStrings aScript, boolean areRaise) { > throw abstractCall(); > } > > public void EnableConstraints(TRtDBConnection aConnection, TStrings aTableList, TRtOnUpdateProgress aOnCompleted, TStrings aScript) { > throw abstractCall(); > } > > public Class<? extends TRtDDLFunctions> ClassInfo() { > return TRtDDLFunctions.class; > } > } > > public static class TRtCustomDDLClass extends TRtCustomUpdateSQLClass { > > public static final TRtCustomDDLClass SINGLETON = new TRtCustomDDLClass(); > > public TRtCustomDDL CreateSQL(TRtDBConnection AConn) { > return TRtCustomDDL.CreateSQL(AConn); > } > > public Class<? extends TRtCustomDDL> ClassInfo() { > return TRtCustomDDL.class; > } > } > > public static abstract class TRtCustomDDL extends TRtCustomUpdateSQL { > > private TRtDDLErrorEvent FOnDDLError; > private TRtDDLStepEvent FOnBeforeDDLStep; > > public final void SetOnDDLError(TRtDDLErrorEvent Value) { > FOnDDLError = Value; > } > > public final TRtDDLErrorEvent GetOnDDLError() { > TRtDDLErrorEvent Result; > if (FOnDDLError != null) { > Result = FOnDDLError; > } else { > Result = GetOwnerConnection().FOnDDLError; > } > return Result; > } > > public final void SetOnBeforeDDLStep(TRtDDLStepEvent Value) { > FOnBeforeDDLStep = Value; > } > > public final TRtDDLStepEvent GetOnBeforeDDLStep() { > TRtDDLStepEvent Result; > if (FOnBeforeDDLStep != null) { > Result = FOnBeforeDDLStep; > } else { > Result = GetOwnerConnection().FOnBeforeDDLStep; > } > return Result; > } > > protected final boolean DoOnDDLError(int AAltStep, TRtQuery aCurRec, br.com.senior.svcl.db.RtAccess.TRtUpdate ANewRec) { > TRtDDLErrorEvent Event; > TBoolean LRetry = new TBoolean(); > Event = GetOnDDLError(); > if (Event != null) { > Event.run(this, LRetry, AAltStep, aCurRec, ANewRec); > } > return LRetry.v; > } > > protected final boolean DoOnDDLError(int AAltStep, TRtQuery aCurRec) { > return DoOnDDLError(AAltStep, aCurRec, null); > } > > protected final boolean DoOnDDLError(int AAltStep) { > return DoOnDDLError(AAltStep, null, null); > } > > protected final boolean DoOnDDLError() { > return DoOnDDLError(atsNone, null, null); > } > > protected final void DoOnBeforeDDLStep(int AAltStep, TRtQuery aCurRec, br.com.senior.svcl.db.RtAccess.TRtUpdate aNewRec) { > TRtDDLStepEvent Event; > Event = GetOnBeforeDDLStep(); > if (Event != null) { > Event.run(this, AAltStep, aCurRec, aNewRec); > } > } > > protected final void DoOnBeforeDDLStep(int AAltStep, TRtQuery aCurRec) { > DoOnBeforeDDLStep(AAltStep, aCurRec, null); > } > > protected final void DoOnBeforeDDLStep(int AAltStep) { > DoOnBeforeDDLStep(AAltStep, null, null); > } > > protected final void DoOnBeforeDDLStep() { > DoOnBeforeDDLStep(atsNone, null, null); > } > > protected final void InternalExecuteWithRetry() { > boolean LRetry; > DoOnBeforeDDLStep(); > while (true) { > try { > InternalExecuteUpdate(); > break; > } catch (Throwable any) { > LRetry = DoOnDDLError(); > if (LRetry) { > continue; > } else { > throw wrap(any); > } > } > } > } > > public abstract String GetName(); > > public void ExecuteUpd() { > String ASql = ""; > String ALastSQLs = ""; > boolean LRetry; > DoOnBeforeDDLStep(); > ASql = GenSQL(); > while (true) { > try { > ALastSQLs = ExecuteMultipleSQLs(ASql, 0, ALastSQLs); > UpdatePhyDatabase(); > break; > } catch (Throwable any) { > LRetry = DoOnDDLError(); > if (LRetry) { > continue; > } else { > throw wrap(any); > } > } > } > } > > public static TRtCustomDDL CreateSQL(TRtDBConnection AConn) { > // TRtCustomDDL Result; > // Result = new TRtCustomDDL(); > // Result.runCreateSQL(AConn); > // return Result; > throw pending(); > } > > public TRtCustomDDLClass ClassType() { > return TRtCustomDDLClass.SINGLETON; > } > } > > public static class TRtCustomDDLTableClass extends TRtCustomDDLClass { > > public static final TRtCustomDDLTableClass SINGLETON = new TRtCustomDDLTableClass(); > > protected TRtCustomDDLTable CreateSQL(TRtDBConnection AConn, String ATableName) { > return TRtCustomDDLTable.CreateSQL(AConn, ATableName); > } > > public TRtCustomDDLTable Create() { > return TRtCustomDDLTable.Create(); > } > > public Class<? extends TRtCustomDDLTable> ClassInfo() { > return TRtCustomDDLTable.class; > } > } > > public static class TRtCustomDDLTable extends TRtCustomDDL { > > String FTableName; > > public boolean GetHasOperation() { > return !StrIsBlank(GetTableName()); > } > > public final void SetTableName(String Value) { > CheckUnprepare(); > FTableName = Value; > } > > protected void runCreateSQL(TRtDBConnection AConn, String ATableName) { > super.runCreateSQL(AConn); > FTableName = ATableName; > } > > protected static TRtCustomDDLTable CreateSQL(TRtDBConnection AConn, String ATableName) { > TRtCustomDDLTable Result; > Result = new TRtCustomDDLTable(); > Result.runCreateSQL(AConn, ATableName); > return Result; > } > > public String GetName() { > return FTableName; > } > > public final String GetTableName() { > return FTableName; > } > > public final TRtTableDef CheckTableDef(boolean aNewDatabase, boolean aRaiseNotFound) { > TRtTableDef Result; > TRtDatabaseDef xDatabasedef; > if (aNewDatabase) { > xDatabasedef = GetOwnerConnection().GetNewDatabase(); > } else { > xDatabasedef = GetOwnerConnection().getPhyDatabase(); > } > Assert(xDatabasedef != null, TransStrFmt("TC3295", "Database não informado - CheckTable(%0:s)", new Object[] { ClassName() }, true)); > Result = xDatabasedef.TableByName(GetTableName()); > if (aRaiseNotFound && Result == null) { > throw DelphiException.CreateFmt(TransStr("TC662", "Tabela %s não encontrada para %s", true), new Object[] { GetTableName(), ClassName() }); > } > return Result; > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtCustomDDLTable) { > FTableName = ((TRtCustomDDLTable) Source).FTableName; > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > FTableName = Reader.ReadString(); > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.WriteString(FTableName); > } > > public static TRtCustomDDLTable Create() { > TRtCustomDDLTable Result; > Result = new TRtCustomDDLTable(); > Result.runCreate(); > return Result; > } > > public TRtCustomDDLTableClass ClassType() { > return TRtCustomDDLTableClass.SINGLETON; > } > } > > public static class TRtAliasedTableSQLClass extends TRtTableSQLClass { > > public static final TRtAliasedTableSQLClass SINGLETON = new TRtAliasedTableSQLClass(); > > protected TRtAliasedTableSQL CreateSQL(TRtDBConnection AConn, String ATableName, String AAlias) { > return TRtAliasedTableSQL.CreateSQL(AConn, ATableName, AAlias); > } > > public TRtAliasedTableSQL Create() { > return TRtAliasedTableSQL.Create(); > } > > public Class<? extends TRtAliasedTableSQL> ClassInfo() { > return TRtAliasedTableSQL.class; > } > } > > public static class TRtAliasedTableSQL extends TRtTableSQL { > > protected String FALias; > > protected void runCreateSQL(TRtDBConnection AConn, String ATableName, String AAlias) { > super.runCreateSQL(AConn, ATableName); > FALias = AAlias; > } > > protected static TRtAliasedTableSQL CreateSQL(TRtDBConnection AConn, String ATableName, String AAlias) { > TRtAliasedTableSQL Result; > Result = new TRtAliasedTableSQL(); > Result.runCreateSQL(AConn, ATableName, AAlias); > return Result; > } > > public final void SetAlias(String Value) { > CheckUnprepare(); > FALias = Value; > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtAliasedTableSQL) { > FALias = ((TRtAliasedTableSQL) Source).FALias; > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > FALias = Reader.ReadString(); > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.WriteString(FALias); > } > > public static TRtAliasedTableSQL Create() { > TRtAliasedTableSQL Result; > Result = new TRtAliasedTableSQL(); > Result.runCreate(); > return Result; > } > > public TRtAliasedTableSQLClass ClassType() { > return TRtAliasedTableSQLClass.SINGLETON; > } > > public String getAlias() { > return FALias; > } > } > > public static class TRtCreateTableClass extends TRtCustomDDLTableClass { > > public static final TRtCreateTableClass SINGLETON = new TRtCreateTableClass(); > > public TRtCreateTable Create() { > return TRtCreateTable.Create(); > } > > public final TRtCreateTable CreateSQL(TRtDBConnection AConn, String ATableName) { > return TRtCreateTable.CreateSQL(AConn, ATableName); > } > > public Class<? extends TRtCreateTable> ClassInfo() { > return TRtCreateTable.class; > } > } > > public static class TRtCreateTable extends TRtCustomDDLTable { > > public boolean GetHasOperation() { > int Op; > DelphiSet aSet = DelphiSet.get(); > aSet = DelphiSet.get(); > for (Op = RtSql.Low_TRtCrtAltAssignOption; Op <= RtSql.High_TRtCrtAltAssignOption; ++Op) { > aSet = aSet.add(GetOperations(Op)); > } > return aSet != DelphiSet.get() && super.GetHasOperation(); > } > > protected TRtAddColumnsList FColumns; > protected TRtSingleIndexItem FPrimaryKey; > protected TRtSingleIndexItemList FUniqueConstraints; > protected TRtIndexItemList FIndexes; > protected TRtForeignKeyList FForeignKeys; > protected TRtTriggerItemList FTriggers; > protected String FDataTableSpace; > protected String FIndexTableSpace; > > protected void UpdatePhyDatabase() { > TRtDatabaseDef ADbDef; > TRtTableDef ATblDef; > ADbDef = GetDatabaseDef(); > if (ADbDef != null && !GetNotUpdatePhyDatabase()) { > ATblDef = ADbDef.TableByName(FTableName); > if (ATblDef == null) { > ATblDef = ADbDef.NewTableDef(FTableName); > } > AssignToTableDef(ATblDef, DelphiSet.getRange(raaColumns, raaForeignKeys)); > } > } > > protected final void Init() { > FColumns = ((TRtAddColumnsList) Creator(this, TRtAddColumnsListClass.SINGLETON)); > FColumns.FDBVersionKind = getDBVersionKind(); > FPrimaryKey = ((TRtSingleIndexItem) Creator(this, TRtSingleIndexItemClass.SINGLETON)); > FUniqueConstraints = ((TRtSingleIndexItemList) Creator(this, TRtSingleIndexItemListClass.SINGLETON)); > FIndexes = ((TRtIndexItemList) Creator(this, TRtIndexItemListClass.SINGLETON)); > FForeignKeys = ((TRtForeignKeyList) Creator(this, TRtForeignKeyListClass.SINGLETON)); > FTriggers = ((TRtTriggerItemList) Creator(this, TRtTriggerItemListClass.SINGLETON)); > } > > public TRtAddColumnsList GetColumn() { > return FColumns; > } > > public final TRtSingleIndexItem GetPrimaryKey() { > return FPrimaryKey; > } > > public final TRtSingleIndexItem GetUniqueConstraint(String AName) { > TRtSingleIndexItem Result; > Result = FUniqueConstraints.ItemByName(AName); > if (Result == null) { > Result = ((TRtSingleIndexItem) Creator(null, TRtSingleIndexItemClass.SINGLETON)); > Result.Init(FUniqueConstraints, AName); > } > return Result; > } > > public final TRtIndexItem GetUniqueKey(String AName) { > TRtIndexItem Result; > Result = ((TRtIndexItem) FIndexes.ItemByName(AName)); > if (Result != null) { > if (!Result.getUnique()) { > throw DelphiException.CreateFmt(TransStr("TC663", "%s não é um índice único.", true), new Object[] { AName }); > } > } else { > Result = ((TRtIndexItem) Creator(null, TRtIndexItemClass.SINGLETON)); > Result.Init(FIndexes, AName, true); > } > return Result; > } > > public final TRtIndexItem GetIndex(String AName) { > TRtIndexItem Result; > Result = ((TRtIndexItem) FIndexes.ItemByName(AName)); > if (Result != null) { > if (Result.getUnique()) { > throw DelphiException.CreateFmt(TransStr("TC664", "%s é um índice único.", true), new Object[] { AName }); > } > } else { > Result = ((TRtIndexItem) Creator(null, TRtIndexItemClass.SINGLETON)); > Result.Init(FIndexes, AName, false); > } > return Result; > } > > public final TRtForeignKeyItem GetForeignKey(String AName) { > TRtForeignKeyItem Result; > Result = FForeignKeys.ItemByName(AName); > if (Result == null) { > Result = ((TRtForeignKeyItem) Creator(null, TRtForeignKeyItemClass.SINGLETON)); > Result.Init(FForeignKeys, AName); > } > return Result; > } > > public final TRtTriggerItem GetTrigger(String AName) { > TRtTriggerItem Result; > Result = FTriggers.ItemByName(AName); > if (Result == null) { > Result = ((TRtTriggerItem) Creator(null, TRtTriggerItemClass.SINGLETON)); > Result.Init(FTriggers, AName); > } > return Result; > } > > protected final void _AssignToTableDef(TRtTableDef ATblDef, DelphiSet AAssOpt, boolean LAlter) { > int i; > int c; > String s = ""; > TRtTableDef OldTblDef; > TRtTableDef RelTblDef; > TRtFieldDef AFldDef; > TRtIndexDef ANdxDef; > TRtUniqueConstraintDef AUniqueDef; > TRtRelationDef ARelDef; > TRtDatabaseDef ADbDef; > if (LAlter) { > OldTblDef = CheckGetDatabaseDef().CheckTableByName(FTableName); > if (OldTblDef != ATblDef) { > ATblDef.SetName(TempName()); > ATblDef.setFixedName(true); > ATblDef.Assign(OldTblDef); > } > } else { > OldTblDef = null; > } > if (!GetOwnerConnection().FDisableEvents && GetOwnerConnection().FOnBeforeAssignToTableDef != null) { > GetOwnerConnection().FOnBeforeAssignToTableDef.run(this, OldTblDef, ATblDef); > } > if (AAssOpt.contains(raaColumns)) { > if (!LAlter) { > ATblDef.ClearFields(); > } > for (i = 0; i <= FColumns.GetCount() - 1; ++i) { > if (LAlter && (((TRtModifyColumnItem) FColumns.GetItem(i))).GetIsRenamingCol()) { > s = (((TRtModifyColumnItem) FColumns.GetItem(i))).getOldColName(); > } else { > s = FColumns.GetItem(i).getColName(); > } > { > TRtAddColumnItem context_GetItem = FColumns.GetItem(i); > if (context_GetItem.getOption() == rcaDrop) { > if (LAlter) { > ATblDef.DropFieldDef(s); > } > continue; > } > if (LAlter) { > AFldDef = ATblDef.FieldByName(s); > } else { > AFldDef = null; > } > if (AFldDef == null) { > AFldDef = ATblDef.NewFieldDef(context_GetItem.getColName()); > } else { > AFldDef.SetName(context_GetItem.getColName()); > } > try { > AFldDef.SetFullKind(TRtPhyBaseTypeClass.SINGLETON.ClassFromEnumType(context_GetItem.FColType), "", context_GetItem.FColLen, context_GetItem.FColPrec); > AFldDef.SetNotNull(context_GetItem.FNotNull); > } catch (Throwable any) { > ATblDef.DropFieldDef(context_GetItem.getColName()); > throw wrap(any); > } > } > } > } > for (i = 0; i <= FIndexes.GetCount() - 1; ++i) { > if (!LAlter) { > if (AAssOpt.contains(raaUniqueKeys)) { > ATblDef.ClearIndexes(true); > } > if (AAssOpt.contains(raaIndexes)) { > ATblDef.ClearIndexes(false); > } > } > { > TRtIndexItem item = FIndexes.GetItem(i); > if (item.getUnique()) { > if (!AAssOpt.contains(raaUniqueKeys)) { > continue; > } > } else if (!AAssOpt.contains(raaIndexes)) { > continue; > } > if (LAlter) { > ATblDef.DropIndexDef(item.GetName()); > } > if (FIndexes.GetItem(i).FOption == rcaDrop) { > continue; > } > ANdxDef = ATblDef.NewIndexDef(item.GetName(), ""); > try { > for (c = 0; c <= item.GetColumns().GetCount() - 1; ++c) { > { > TRtIndexColumnItem column = item.GetColumns().GetItem(c); > ANdxDef.NewFieldDef(column.getColName(), column.getOrder() == risDesc); > } > } > } catch (Throwable any) { > ATblDef.DropIndexDef(item.GetName()); > } > } > } > if (AAssOpt.contains(raaPrimaryKey)) { > s = ""; > if (!(this instanceof TRtAlterTable) || ((TRtAlterTable) this).GetPrimaryKey().getOption() != rcaDrop) { > for (i = 0; i <= FPrimaryKey.getColumns().GetCount() - 1; ++i) { > { > TRtSingleIndexColumnItem context_GetItem = FPrimaryKey.getColumns().GetItem(i); > if (!s.equals("")) { > s = s + ";"; > } > s = s + context_GetItem.getColName(); > } > } > if (!s.equals("")) { > ATblDef.SetPrimaryKey(s); > } > } else { > ATblDef.SetPrimaryKey(""); > } > } > if (AAssOpt.contains(raaUniqueConstraints)) { > for (i = 0; i <= FUniqueConstraints.GetCount() - 1; ++i) { > if (!LAlter) { > ATblDef.ClearUniqueConstraints(); > } > { > TRtSingleIndexItem item = FUniqueConstraints.GetItem(i); > if (LAlter) { > ATblDef.DropUniqueConstraintDef(item.GetName()); > } > if (item.FOption == rcaDrop) { > continue; > } > AUniqueDef = ATblDef.NewUniqueConstraintDef(item.GetName(), ""); > try { > for (c = 0; c <= item.getColumns().GetCount() - 1; ++c) { > { > TRtSingleIndexColumnItem column = item.getColumns().GetItem(c); > AUniqueDef.NewFieldDef(column.getColName()); > } > } > } catch (Throwable any) { > ATblDef.DropUniqueConstraintDef(item.GetName()); > } > } > } > } > if (AAssOpt.contains(raaTriggers)) { > for (i = 0; i <= FTriggers.GetCount() - 1; ++i) { > if (!LAlter) { > ATblDef.ClearTriggers(); > } > { > TRtTriggerItem context_GetItem = FTriggers.GetItem(i); > if (LAlter) { > ATblDef.DropTriggerDef(context_GetItem.GetName()); > } > if (context_GetItem.FOption == rcaDrop) { > continue; > } > ATblDef.NewTriggerDef(context_GetItem.FCode); > } > } > } > if (AAssOpt.contains(raaForeignKeys)) { > if (!LAlter) { > ATblDef.ClearRelations(); > } > ADbDef = ((TRtDatabaseDef) ATblDef.GetTypedOwner(TRtDatabaseDefClass.SINGLETON)); > for (i = 0; i <= FForeignKeys.GetCount() - 1; ++i) { > { > TRtForeignKeyItem item = FForeignKeys.GetItem(i); > if (LAlter) { > ADbDef.DropRelationDef(item.GetName()); > } > if (item.FOption == rcaDrop) { > continue; > } > RelTblDef = ADbDef.TableByName(item.getReferenceTable()); > ARelDef = ADbDef.NewRelationDef(item.GetName(), item.GetForeignTable(), item.getReferenceTable()); > try { > s = ""; > for (c = 0; c <= item.getColumns().GetCount() - 1; ++c) { > { > TRtForeignKeyColumnItem column = item.getColumns().GetItem(c); > ARelDef.AddForeignField(column.getThsColName()); > if (!s.equals("")) { > s = s + ";"; > } > s = s + column.getOthColName(); > } > } > AUniqueDef = RelTblDef.GetUniqueDefForFields(s); > if (AUniqueDef != null) { > ARelDef.SetReferenceUniqueDef(AUniqueDef.GetName()); > } > } catch (Throwable any) { > ADbDef.DropRelationDef(item.GetName()); > throw wrap(any); > } > } > } > } > if (!GetOwnerConnection().FDisableEvents && GetOwnerConnection().FOnAfterAssignToTableDef != null) { > GetOwnerConnection().FOnAfterAssignToTableDef.run(this, OldTblDef, ATblDef); > } > } > > public String GetDataTableSpace() { > String Result = ""; > if (StrIsBlank(FDataTableSpace)) { > Result = TrimRight(GetOwnerConnection().GetDataTableSpace()); > } else { > Result = TrimRight(FDataTableSpace); > } > return Result; > } > > public final String GetIndexTableSpace() { > String Result = ""; > if (StrIsBlank(FIndexTableSpace)) { > Result = TrimRight(GetOwnerConnection().GetIndexTableSpace()); > } else { > Result = TrimRight(FIndexTableSpace); > } > return Result; > } > > public final void SetDataTableSpace(String Value) { > CheckUnprepare(); > FDataTableSpace = Value; > } > > public final void SetIndexTableSpace(String Value) { > CheckUnprepare(); > FIndexTableSpace = Value; > } > > public void runCreate() { > super.runCreate(); > Init(); > } > > public static TRtCreateTable Create() { > TRtCreateTable Result; > Result = new TRtCreateTable(); > Result.runCreate(); > return Result; > } > > public final void runCreateSQL(TRtDBConnection AConn, String ATableName) { > super.runCreateSQL(AConn, ATableName); > Init(); > } > > public static TRtCreateTable CreateSQL(TRtDBConnection AConn, String ATableName) { > TRtCreateTable Result; > Result = new TRtCreateTable(); > Result.runCreateSQL(AConn, ATableName); > return Result; > } > > public void Destroy() { > FColumns.Free(); > FPrimaryKey.Free(); > FUniqueConstraints.Free(); > FIndexes.Free(); > FForeignKeys.Free(); > FTriggers.Free(); > super.Destroy(); > } > > public void ExecuteUpd() { > String ASql = ""; > String ALastSQLs = ""; > String ExceptMessage = ""; > boolean LRetry; > DoOnBeforeDDLStep(); > ASql = GenSQL(); > while (true) { > try { > ALastSQLs = ExecuteMultipleSQLs(ASql, 0, ALastSQLs); > UpdatePhyDatabase(); > break; > } catch (DelphiException E) { > LRetry = DoOnDDLError(); > if (LRetry) { > continue; > } else { > ExceptMessage = TransStrFmt("TC3296", "Não foi possível criar a tabela: %0:s - [%1:s, %2:s] - \"%3:s\"", new Object[] { GetTableName(), StrReplaceStr(FSql, SQLEOC_SEP, EOL), StrReplaceStr(ALastSQLs, SQLEOC_SEP, EOL), E.getMessage() }, true); > E.setMessage(ExceptMessage); > throw wrap(E); > } > } > } > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtCreateTable) { > FColumns.Assign(((TRtCreateTable) Source).FColumns); > FPrimaryKey.Assign(((TRtCreateTable) Source).FPrimaryKey); > FUniqueConstraints.Assign(((TRtCreateTable) Source).FUniqueConstraints); > FIndexes.Assign(((TRtCreateTable) Source).FIndexes); > FForeignKeys.Assign(((TRtCreateTable) Source).FForeignKeys); > FTriggers.Assign(((TRtCreateTable) Source).FTriggers); > FDataTableSpace = ((TRtCreateTable) Source).FDataTableSpace; > FIndexTableSpace = ((TRtCreateTable) Source).FIndexTableSpace; > } > } finally { > FAssigning--; > } > } > > public Object AssignFromTableDef(TRtTableDef ATblDef, DelphiSet AAssOpt) { > int i; > int c; > TRtIndexItem NdxItem; > TRtSingleIndexItem UniqueItem; > int AOrder; > TRtForeignKeyItem RelItem; > Clear(); > FTableName = ATblDef.GetName(); > if (!GetOwnerConnection().FDisableEvents && GetOwnerConnection().FOnBeforeAssignFromTableDef != null) { > GetOwnerConnection().FOnBeforeAssignFromTableDef.run(this, null, ATblDef); > } > if (AAssOpt.contains(raaColumns)) { > for (i = 0; i <= ATblDef.GetFieldCount() - 1; ++i) { > { > TRtFieldDef context_GetField = ATblDef.GetField(i); > FColumns.AddColumn(context_GetField.GetName(), context_GetField.GetFullKind().GetEnumType(), context_GetField.GetLength(), context_GetField.GetPrecision(), context_GetField.getNotNull()); > } > } > } > for (i = 0; i <= ATblDef.GetIndexCount() - 1; ++i) { > { > TRtIndexDef context_GetIndex = (TRtIndexDef) ATblDef.GetIndex(i); > if (context_GetIndex.GetIsUnique()) { > if (!AAssOpt.contains(raaUniqueKeys)) { > continue; > } > } else if (!AAssOpt.contains(raaIndexes)) { > continue; > } > NdxItem = FIndexes.AddIndex(context_GetIndex.GetName(), context_GetIndex.GetIsUnique()); > for (c = 0; c <= context_GetIndex.GetFieldCount() - 1; ++c) { > { > TRtIndexFieldDef context_GetField = context_GetIndex.GetField(c); > if (context_GetField.getDescendent()) { > AOrder = risDesc; > } else { > AOrder = risAsc; > } > NdxItem.AddColumnOrdered(context_GetField.getField().GetName(), AOrder); > } > } > } > } > if (AAssOpt.contains(raaForeignKeys)) { > for (i = 0; i <= ATblDef.GetRelationCount() - 1; ++i) { > { > TRtRelationDef context_GetRelation = ATblDef.GetRelation(i); > if (CompareText(context_GetRelation.getForeignTable().GetName(), FTableName) == 0) { > RelItem = FForeignKeys.AddForeignKey(context_GetRelation.GetName(), context_GetRelation.getReferenceTable().GetName()); > for (c = 0; c <= context_GetRelation.GetFieldCount() - 1; ++c) { > RelItem.AddColumns(context_GetRelation.GetForeignField(c).GetName(), context_GetRelation.GetReferenceField(c).GetName()); > } > } > } > } > } > if (AAssOpt.contains(raaPrimaryKey)) { > FPrimaryKey.SetName(ATblDef.GetPrimaryKeyName()); > for (i = 0; i <= ATblDef.GetKeyCount() - 1; ++i) { > FPrimaryKey.AddColumn(ATblDef.GetPrimaryKeyField(i).GetName()); > } > } > if (AAssOpt.contains(raaUniqueConstraints)) { > for (i = 0; i <= ATblDef.GetUniqueConstraintCount() - 1; ++i) { > { > TRtUniqueConstraintDef context_GetUniqueConstraint = ATblDef.GetUniqueConstraint(i); > UniqueItem = FUniqueConstraints.AddUniqueConstraint(context_GetUniqueConstraint.GetName()); > for (c = 0; c <= context_GetUniqueConstraint.GetFieldCount() - 1; ++c) { > { > TRtUniqueConstraintFieldDef context_GetField = context_GetUniqueConstraint.GetField(c); > UniqueItem.AddColumn(context_GetField.getField().GetName()); > } > } > } > } > } > if (AAssOpt.contains(raaTriggers)) { > for (i = 0; i <= ATblDef.GetTriggerCount() - 1; ++i) { > FTriggers.AddTriggerFromTriggerDef(ATblDef.GetTrigger(i)); > } > } > if (!GetOwnerConnection().FDisableEvents && GetOwnerConnection().FOnAfterAssignFromTableDef != null) { > GetOwnerConnection().FOnAfterAssignFromTableDef.run(this, null, ATblDef); > } > return null; > } > > public void AssignToTableDef(TRtTableDef ATblDef, DelphiSet AAssOpt) { > _AssignToTableDef(ATblDef, AAssOpt, false); > } > > public final void Clear() { > CheckUnprepare(); > FTableName = ""; > FColumns.Clear(); > FPrimaryKey.FColumns.Clear(); > FPrimaryKey.FOption = rcaAdd; > FUniqueConstraints.Clear(); > FIndexes.Clear(); > FForeignKeys.Clear(); > FTriggers.Clear(); > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > FColumns.ReadData(Reader); > FPrimaryKey.ReadData(Reader); > FUniqueConstraints.ReadData(Reader); > FIndexes.ReadData(Reader); > FForeignKeys.ReadData(Reader); > FTriggers.ReadData(Reader); > FDataTableSpace = Reader.ReadString(); > FIndexTableSpace = Reader.ReadString(); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > FColumns.WriteData(Writer); > FPrimaryKey.WriteData(Writer); > FUniqueConstraints.WriteData(Writer); > FIndexes.WriteData(Writer); > FForeignKeys.WriteData(Writer); > FTriggers.WriteData(Writer); > Writer.WriteString(FDataTableSpace); > Writer.WriteString(FIndexTableSpace); > } > > public final void RemoveUniqueConstraintByName(String AName) { > CheckUnprepare(); > FUniqueConstraints.RemoveByName(AName); > } > > public final void RemoveAnyIndexByName(String AName) { > CheckUnprepare(); > FIndexes.RemoveByName(AName); > } > > public final void RemoveForeignKeyByName(String AName) { > CheckUnprepare(); > FForeignKeys.RemoveByName(AName); > } > > public final DelphiSet GetOperations(int Op) { > DelphiSet Result = DelphiSet.get(); > int i; > Result = DelphiSet.get(); > switch (Op) { > case raaColumns: > for (i = 0; i <= FColumns.GetCount() - 1; ++i) { > Result = Result.add(DelphiSet.get(FColumns.GetItem(i).getOption())); > } > break; > case raaPrimaryKey: > if (FPrimaryKey.getOption() != rcaAdd || FPrimaryKey.getColumns().GetCount() != 0) { > Result = DelphiSet.get(FPrimaryKey.getOption()); > } > break; > case raaUniqueKeys: > for (i = 0; i <= FIndexes.GetCount() - 1; ++i) { > if (FIndexes.GetItem(i).getUnique()) { > Result = Result.add(DelphiSet.get(FIndexes.GetItem(i).getOption())); > } > } > break; > case raaIndexes: > for (i = 0; i <= FIndexes.GetCount() - 1; ++i) { > if (!FIndexes.GetItem(i).getUnique()) { > Result = Result.add(DelphiSet.get(FIndexes.GetItem(i).getOption())); > } > } > break; > case raaUniqueConstraints: > for (i = 0; i <= FUniqueConstraints.GetCount() - 1; ++i) { > Result = Result.add(DelphiSet.get(FUniqueConstraints.GetItem(i).getOption())); > } > break; > case raaForeignKeys: > for (i = 0; i <= FForeignKeys.GetCount() - 1; ++i) { > Result = Result.add(DelphiSet.get(FForeignKeys.GetItem(i).getOption())); > } > break; > case raaTriggers: > for (i = 0; i <= FTriggers.GetCount() - 1; ++i) { > Result = Result.add(DelphiSet.get(FTriggers.GetItem(i).getOption())); > } > break; > default: > break; > } > return Result; > } > > public final int GetOperationsCount(int Op, DelphiSet AltSet) { > int Result; > int i; > Result = 0; > switch (Op) { > case raaColumns: > for (i = 0; i <= FColumns.GetCount() - 1; ++i) { > if (AltSet.contains(FColumns.GetItem(i).getOption())) { > Result++; > } > } > break; > case raaPrimaryKey: > if (FPrimaryKey.getOption() != rcaAdd || FPrimaryKey.getColumns().GetCount() != 0) { > if (AltSet.contains(FPrimaryKey.getOption())) { > Result++; > } > } > break; > case raaUniqueKeys: > for (i = 0; i <= FIndexes.GetCount() - 1; ++i) { > if (FIndexes.GetItem(i).getUnique()) { > if (AltSet.contains(FIndexes.GetItem(i).getOption())) { > Result++; > } > } > } > break; > case raaIndexes: > for (i = 0; i <= FIndexes.GetCount() - 1; ++i) { > if (!FIndexes.GetItem(i).getUnique()) { > if (AltSet.contains(FIndexes.GetItem(i).getOption())) { > Result++; > } > } > } > break; > case raaUniqueConstraints: > for (i = 0; i <= FUniqueConstraints.GetCount() - 1; ++i) { > if (AltSet.contains(FUniqueConstraints.GetItem(i).getOption())) { > Result++; > } > } > break; > case raaForeignKeys: > for (i = 0; i <= FForeignKeys.GetCount() - 1; ++i) { > if (AltSet.contains(FForeignKeys.GetItem(i).getOption())) { > Result++; > } > } > break; > case raaTriggers: > for (i = 0; i <= FTriggers.GetCount() - 1; ++i) { > if (AltSet.contains(FTriggers.GetItem(i).getOption())) { > Result++; > } > } > break; > default: > break; > } > return Result; > } > > public TRtCreateTableClass ClassType() { > return TRtCreateTableClass.SINGLETON; > } > > public TRtSingleIndexItemList getUniqueConstraintList() { > return FUniqueConstraints; > } > > public TRtIndexItemList getIndexList() { > return FIndexes; > } > > public TRtForeignKeyList getForeignKeyList() { > return FForeignKeys; > } > > public TRtTriggerItemList getTriggerList() { > return FTriggers; > } > } > > public static final class TRtAlterTableClass extends TRtCreateTableClass { > > public static final TRtAlterTableClass SINGLETON = new TRtAlterTableClass(); > > public TRtAlterTable Create() { > return TRtAlterTable.Create(); > } > > public TContainerItem Creator(TPersistent AOwner, TContainerItemClass AType) { > if (AType == TRtAddColumnsListClass.SINGLETON) { > AType = TRtModifyColumnsListClass.SINGLETON; > } > return super.Creator(AOwner, AType); > } > > public Class<? extends TRtAlterTable> ClassInfo() { > return TRtAlterTable.class; > } > } > > public static final class TRtAlterTable extends TRtCreateTable { > > private final class ForceModifyAllFks_Context { > > private TRtDBConnection DBConn; > private TRtTableDef OldTblDef; > private TRtRelationDef ARelDef; > private TRtForeignKeyItem RelItem; > private int i; > > private TRtAlterTable GetOtherAlterTableForFk() { > TRtAlterTable Result; > TRtCustomSQL AObj; > int i; > Result = null; > for (i = 0; i <= DBConn.FSQLList.GetCount() - 1; ++i) { > AObj = ((TRtCustomSQL) DBConn.FSQLList.Get(i)); > if (AObj instanceof TRtAlterTable && CompareText(ARelDef.getForeignTable().GetName(), ((TRtAlterTable) AObj).GetTableName()) == 0) { > Result = (TRtAlterTable) AObj; > break; > } > } > if (Result == null) { > Result = DBConn.SQLAlterTable(); > Result.SetTableName(ARelDef.getForeignTable().GetName()); > } > return Result; > } > > private void ModifyFk() { > TRtAlterTable AT; > int i; > if (CompareText(ARelDef.getForeignTable().GetName(), FTableName) != 0 && DBConn.getSQLProcessMode() == spmGroup) { > AT = GetOtherAlterTableForFk(); > } else { > AT = TRtAlterTable.this; > } > if (AT != null && AT.FForeignKeys.ItemByName(ARelDef.GetName()) == null) { > RelItem = AT.FForeignKeys.AddForeignKey(ARelDef.GetName(), ARelDef.getReferenceTable().GetName()); > RelItem.FForeignTable = ARelDef.getForeignTable().GetName(); > if (HasDropTable(DBConn, AT.GetTableName())) { > RelItem.SetOption(rcaDrop); > } else { > RelItem.SetOption(rcaModify); > for (i = 0; i <= ARelDef.GetFieldCount() - 1; ++i) { > RelItem.AddColumns(ARelDef.GetForeignField(i).GetName(), ARelDef.GetReferenceField(i).GetName()); > } > } > } > } > > public ForceModifyAllFks_Context() { > } > > public void execute() { > DBConn = GetOwnerConnection(); > OldTblDef = CheckGetDatabaseDef().TableByName(FTableName); > if (OldTblDef == null) { > return; > } > for (i = 0; i <= OldTblDef.GetRelationCount() - 1; ++i) { > ARelDef = OldTblDef.GetRelation(i); > if (FForeignKeys.ItemByName(ARelDef.GetName()) == null) { > ModifyFk(); > } > } > } > } > > private final class ForceModifyAllTriggers_Context { > > private TRtDBConnection DBConn; > private TRtTableDef OldTblDef; > private TRtTriggerDef ATrgDef; > private int i; > > private void ModifyTrigger() { > if (HasDropTable(DBConn, GetTableName())) { > FTriggers.AddTrigger(ATrgDef.GetName(), "", ATrgDef.getForEachRow()).FOption = rcaDrop; > } else { > FTriggers.AddTriggerFromTriggerDef(ATrgDef).FOption = rcaModify; > } > } > > public ForceModifyAllTriggers_Context() { > } > > public void execute() { > DBConn = GetOwnerConnection(); > OldTblDef = CheckGetDatabaseDef().TableByName(FTableName); > if (OldTblDef == null) { > return; > } > for (i = 0; i <= OldTblDef.GetTriggerCount() - 1; ++i) { > ATrgDef = OldTblDef.GetTrigger(i); > if (FTriggers.ItemByName(ATrgDef.GetName()) == null) { > ModifyTrigger(); > } > } > } > } > > private final class CheckGetAlterTableMode_Context { > > private int Result; > private int i; > private boolean LCriticalColumnChange; > private boolean LNewUC; > > private boolean CheckChanges() { > return LCriticalColumnChange || LNewUC; > } > > public CheckGetAlterTableMode_Context() { > } > > public int execute() { > LCriticalColumnChange = false; > LNewUC = false; > i = 0; > while (i < GetColumn().GetCount() && !CheckChanges()) { > LCriticalColumnChange = GetColumn().GetItem(i).GetCriticalChange(); > i++; > } > LNewUC = FPrimaryKey.getOption() == rcaModify || FPrimaryKey.getOption() == rcaAdd && FPrimaryKey.getColumns().GetCount() > 0; > i = 0; > while (!CheckChanges() && i < FIndexes.GetCount()) { > LNewUC = FIndexes.GetItem(i).getUnique() && DelphiSet.get(rcaAdd, rcaModify).contains(FIndexes.GetItem(i).getOption()); > i++; > } > i = 0; > while (!CheckChanges() && i < FUniqueConstraints.GetCount()) { > LNewUC = DelphiSet.get(rcaAdd, rcaModify).contains(FUniqueConstraints.GetItem(i).getOption()); > i++; > } > if (CheckChanges()) { > Result = atmCursor; > } else { > Result = atmAlterTable; > } > return Result; > } > } > > private final class TranslateOldFieldValue_Context { > > private final TRtFieldDef AFld; > private final TRtModifyColumnItem ACol; > private final String AColName; > private String Result = ""; > > private String GetConvFunctionForType(int AType, String AColName) { > String Result = ""; > int OldType; > Result = AColName; > OldType = AFld.GetFullKind().GetEnumType(); > switch (AType) { > case rftString: > switch (OldType) { > case rftNumber: > case rftBoolean: > Result = SQL_Convert + SQL_LParenthesis + SQLNumberToChar + SQL_Comma + AColName + ToStr(SQL_RParenthesis); > break; > case rftDate: > case rftTime: > Result = SQL_Convert + SQL_LParenthesis + SQLDateToChar + SQL_Comma + AColName + ToStr(SQL_RParenthesis); > break; > default: > break; > } > break; > case rftNumber: > switch (OldType) { > case rftString: > Result = SQL_Convert + SQL_LParenthesis + SQLCharToNumber + SQL_Comma + AColName + ToStr(SQL_RParenthesis); > break; > default: > break; > } > break; > case rftDate: > case rftTime: > switch (OldType) { > case rftString: > Result = SQL_Convert + SQL_LParenthesis + SQLCharToDate + SQL_Comma + AColName + ToStr(SQL_RParenthesis); > break; > default: > break; > } > break; > default: > break; > } > return Result; > } > > public TranslateOldFieldValue_Context(TRtFieldDef AFld, TRtModifyColumnItem ACol, String AColName) { > this.AFld = AFld; > this.ACol = ACol; > this.AColName = AColName; > } > > public String execute() { > if (ACol.getColType() != AFld.GetFullKind().GetEnumType()) { > Result = GetConvFunctionForType(ACol.getColType(), AColName); > } else if (ACol.getColType() == rftNumber && AFld.GetPrecision() > ACol.getColPrecision()) { > if (ACol.getColPrecision() == 0) { > Result = "\"TRUNCATE\"(" + AColName + ",0)"; > } else { > Result = "ROUND(" + AColName + SQL_Comma + IntToStr(ACol.getColPrecision()) + ")"; > } > } else { > Result = AColName; > } > return Result; > } > } > > private final class GenSQLObjectsStep_Context { > > private final class GetFieldPairs_Context { > > private final boolean LInsertIntoSelect; > private int I; > private TRtAddColumnItem ACol; > private TRtModifyColumnItem Col; > private TRtModifyColumnItem OldCol; > private TRtFieldDef AFldDef; > private TRtCreateTable ACrtTbl; > > private void IncSelFlds(String AColName) { > if (AInsSelFlds != null) { > AInsSelFlds.Sel.Add(AColName); > } > } > > private void IncInsFlds(String AColName) { > if (AInsSelFlds != null) { > AInsSelFlds.Ins.Add(AColName); > } > } > > private void IncSel(String AColName) { > if (ASel.IndexOf(AColName) < 0) { > ASel.Add(AColName); > } > } > > private boolean ChangeColType(TRtModifyColumnItem ACol) { > return ACol.getColType() != AFldDef.GetFullKind().GetEnumType(); > } > > public GetFieldPairs_Context(boolean LInsertIntoSelect) { > this.LInsertIntoSelect = LInsertIntoSelect; > } > > public int execute() { > GetOldTableDef(); > for (I = 0; I <= OldTblDef.GetFieldCount() - 1; ++I) { > AFldDef = OldTblDef.GetField(I); > Col = GetColumn().ItemByColumnName(AFldDef.GetName()); > OldCol = GetColumn().ItemByOldColumnName(AFldDef.GetName()); > if (Col == null && OldCol == null || Col != null && Col.getOption() != rcaDrop && OldCol == null) { > if (LInsertIntoSelect && Col != null && Col.getOption() == rcaModify) { > try { > ASel.Add(TranslateOldFieldValue(AFldDef, Col, AFldDef.GetName())); > } catch (Throwable any) { > continue; > } > } else { > ASel.Add(AFldDef.GetName()); > } > AIns.Add(AFldDef.GetName()); > IncSelFlds(AFldDef.GetName()); > IncInsFlds(AFldDef.GetName()); > if (Col != null && ChangeColType(Col)) { > AInsTypes.Add(((Object) TRtPhyBaseTypeClass.SINGLETON.ParamTypeFromPhyType(Col.getColType(), Col.getColLength(), Col.getColPrecision()))); > } else { > AInsTypes.Add((Object) rdtUnknown); > } > } else if (OldCol != null) { > try { > if (LInsertIntoSelect) { > ASel.Add(TranslateOldFieldValue(AFldDef, OldCol, OldCol.getOldColName())); > } else { > ASel.Add(OldCol.getOldColName()); > } > } catch (Throwable any) { > continue; > } > AIns.Add(OldCol.getColName()); > IncSelFlds(OldCol.getOldColName()); > IncInsFlds(OldCol.getColName()); > if (ChangeColType(OldCol)) { > AInsTypes.Add(((Object) TRtPhyBaseTypeClass.SINGLETON.ParamTypeFromPhyType(OldCol.getColType(), OldCol.getColLength(), OldCol.getColPrecision()))); > } else { > AInsTypes.Add((Object) rdtUnknown); > } > } > } > if (!LInsertIntoSelect) { > ACrtTbl = ((TRtCreateTable) AsCreateTable()); > try { > for (i = 0; i <= ACrtTbl.GetColumn().GetCount() - 1; ++i) { > ACol = ACrtTbl.GetColumn().GetItem(I); > if (AIns.IndexOf(ACol.getColName()) < 0) { > AIns.Add(ACol.getColName()); > AInsTypes.Add(((Object) TRtPhyBaseTypeClass.SINGLETON.ParamTypeFromPhyType(ACol.getColType(), ACol.getColLength(), ACol.getColPrecision()))); > } > } > } finally { > ACrtTbl.Free(); > } > for (i = 0; i <= OldTblDef.GetFieldCount() - 1; ++i) { > IncSel(OldTblDef.GetField(I).GetName()); > } > } > return AIns.GetCount(); > } > } > > private final int AStep; > private final int AAlterTableMode; > private final int ASeq; > private TList Result; > TRtTableDef OldTblDef; > TStringList ASel; > TStringList AIns; > TInsSelFieldPairs AInsSelFlds; > TList AInsTypes; > int i; > > void GetOldTableDef() { > if (OldTblDef == null) { > OldTblDef = CheckGetDatabaseDef().TableByName(FTableName); > } > } > > private boolean HasAlterTableFor(String ATableName) { > boolean Result; > TRtDBConnection DBConn; > TRtCustomSQL AObj; > int i; > DBConn = GetOwnerConnection(); > if (CompareText(FTableName, ATableName) != 0 && DBConn.getSQLProcessMode() == spmGroup) { > for (i = 0; i <= DBConn.FSQLList.GetCount() - 1; ++i) { > AObj = ((TRtCustomSQL) DBConn.FSQLList.Get(i)); > Result = AObj instanceof TRtAlterTable && CompareText(((TRtAlterTable) AObj).GetTableName(), ATableName) == 0; > if (Result) { > return Result; > } > } > } > return false; > } > > private TRtCustomSQL AsDropTriggers() { > TRtCustomSQL Result; > int i; > TRtTriggerItem STrgItem; > TRtTriggerItem DTrgItem; > Result = GetOwnerConnection().SQLAlterTable(); > try { > ((TRtAlterTable) Result).SetTableName(FTableName); > for (i = 0; i <= FTriggers.GetCount() - 1; ++i) { > STrgItem = FTriggers.GetItem(i); > if (STrgItem.getOption() != rcaAdd) { > DTrgItem = ((TRtAlterTable) Result).FTriggers.AddTrigger(STrgItem.GetName(), "", STrgItem.getForEachRow()); > DTrgItem.SetOption(rcaDrop); > } > } > if (((TRtAlterTable) Result).FTriggers.GetCount() == 0) { > Abort(); > } > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsDropFks(int ASeq) { > TRtCustomSQL Result; > int i; > int iSeq; > TRtForeignKeyItem SFkItem; > TRtForeignKeyItem DFkItem; > Result = GetOwnerConnection().SQLAlterTable(); > try { > ((TRtAlterTable) Result).SetTableName(FTableName); > iSeq = 0; > for (i = 0; i <= FForeignKeys.GetCount() - 1; ++i) { > SFkItem = FForeignKeys.GetItem(i); > if (SFkItem.getOption() != rcaAdd) { > iSeq++; > if (ASeq == 0 || ASeq == iSeq) { > if (HasAlterTableFor(SFkItem.GetForeignTable())) { > continue; > } > DFkItem = ((TRtAlterTable) Result).FForeignKeys.AddForeignKey(SFkItem.GetName(), SFkItem.getReferenceTable()); > DFkItem.SetForeignTable(SFkItem.GetForeignTable()); > DFkItem.SetOption(rcaDrop); > } > } > } > if (((TRtAlterTable) Result).FForeignKeys.GetCount() == 0) { > Abort(); > } > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsDropInnerConstraints() { > TRtCustomSQL Result; > int i; > GetOldTableDef(); > Result = GetOwnerConnection().SQLAlterTable(); > try { > ((TRtAlterTable) Result).SetTableName(FTableName); > if (OldTblDef.GetHasPrimaryKey()) { > ((TRtAlterTable) Result).GetPrimaryKey().SetName(OldTblDef.GetPrimaryKeyName()); > ((TRtAlterTable) Result).GetPrimaryKey().SetOption(rcaDrop); > } > for (i = 0; i <= OldTblDef.GetIndexCount() - 1; ++i) { > ((TRtAlterTable) Result).FIndexes.AddIndex(OldTblDef.GetIndex(i).GetName(), OldTblDef.GetIndex(i).GetIsUnique()).SetOption(rcaDrop); > } > for (i = 0; i <= OldTblDef.GetUniqueConstraintCount() - 1; ++i) { > ((TRtAlterTable) Result).FUniqueConstraints.AddUniqueConstraint(OldTblDef.GetUniqueConstraint(i).GetName()).SetOption(rcaDrop); > } > if (((TRtAlterTable) Result).GetPrimaryKey().getOption() != rcaDrop && ((TRtAlterTable) Result).FIndexes.GetCount() == 0 && ((TRtAlterTable) Result).FUniqueConstraints.GetCount() == 0) { > Abort(); > } > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsRenameTableNewToOld() { > TRtCustomSQL Result; > Result = GetOwnerConnection().SQLRenameTable(); > try { > ((TRtRenameTable) Result).SetTableName(GetTableName()); > ((TRtRenameTable) Result).SetNewTableName(GetOldTableName()); > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > TRtCustomSQL AsCreateTable() { > TRtCustomSQL Result; > Result = GetOwnerConnection().SQLCreateTable(); > try { > if (getKeepPKInOLDTable() || GetUseNewOperationKind()) { > AssignToCreateTable((TRtCreateTable) Result, DelphiSet.get(raaColumns)); > } else { > AssignToCreateTable((TRtCreateTable) Result, DelphiSet.get(raaColumns, raaPrimaryKey, raaUniqueKeys, raaIndexes, raaUniqueConstraints)); > } > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsCreateErrTable() { > TRtCustomSQL Result; > GetOldTableDef(); > Result = GetOwnerConnection().SQLCreateTable(); > try { > Result.setUseDataBaseDef(GetOwnerConnection().getPhyDatabase()); > ((TRtCreateTable) Result).AssignFromTableDef(OldTblDef, DelphiSet.get(raaColumns)); > ((TRtCreateTable) Result).SetTableName(GetErrTableName()); > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsRecreateFks(int ASeq) { > TRtCustomSQL Result; > int i; > int iSeq; > TRtForeignKeyItem SFkItem; > TRtForeignKeyItem DFkItem; > Result = GetOwnerConnection().SQLAlterTable(); > try { > ((TRtAlterTable) Result).SetTableName(FTableName); > iSeq = 0; > for (i = 0; i <= FForeignKeys.GetCount() - 1; ++i) { > SFkItem = FForeignKeys.GetItem(i); > if (SFkItem.getOption() != rcaDrop) { > iSeq++; > if (ASeq == 0 || ASeq == iSeq) { > if (HasAlterTableFor(SFkItem.GetForeignTable())) { > continue; > } > DFkItem = ((TRtAlterTable) Result).FForeignKeys.AddForeignKey(SFkItem.GetName(), SFkItem.getReferenceTable()); > DFkItem.Assign(SFkItem); > DFkItem.SetOption(rcaAdd); > } > } > } > if (((TRtAlterTable) Result).FForeignKeys.GetCount() == 0) { > Abort(); > } > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsRecreateTriggers() { > TRtCustomSQL Result; > int i; > TRtTriggerItem STrgItem; > TRtTriggerItem DTrgItem; > Result = GetOwnerConnection().SQLAlterTable(); > try { > ((TRtAlterTable) Result).SetTableName(FTableName); > for (i = 0; i <= FTriggers.GetCount() - 1; ++i) { > STrgItem = FTriggers.GetItem(i); > if (STrgItem.getOption() != rcaDrop) { > DTrgItem = ((TRtAlterTable) Result).FTriggers.AddTrigger(STrgItem.GetName(), "", STrgItem.getForEachRow()); > DTrgItem.Assign(STrgItem); > DTrgItem.SetOption(rcaAdd); > } > } > if (((TRtAlterTable) Result).FTriggers.GetCount() == 0) { > Abort(); > } > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsDropTable() { > TRtCustomSQL Result; > Result = GetOwnerConnection().SQLDropTable(); > try { > ((TRtDropTable) Result).SetTableName(GetOldTableName()); > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsCreatePK() { > TRtCustomSQL Result; > TRtTableDef xTableDef; > int i; > int j; > TRtIndexItem xIndex; > TRtSingleIndexItem xUC; > Result = GetOwnerConnection().SQLAlterTable(); > try { > ((TRtAlterTable) Result).SetTableName(GetTableName()); > xTableDef = GetOwnerConnection().GetNewDatabase().TableByName(GetTableName()); > ((TRtAlterTable) Result).GetPrimaryKey().AddAllColumns(xTableDef.GetPrimaryKeyStr()); > ((TRtAlterTable) Result).GetPrimaryKey().SetName(xTableDef.GetPrimaryKeyName()); > ((TRtAlterTable) Result).GetPrimaryKey().SetOption(rcaAdd); > for (i = 0; i <= xTableDef.GetIndexCount() - 1; ++i) { > xIndex = ((TRtAlterTable) Result).getIndexList().AddIndex(xTableDef.GetIndex(i).GetName(), xTableDef.GetIndex(i).GetIsUnique()); > xIndex.SetOption(rcaAdd); > for (j = 0; j <= ((TRtIndexDef) xTableDef.GetIndex(i)).GetFieldCount() - 1; ++j) { > if (((TRtIndexDef) xTableDef.GetIndex(i)).GetField(j).getDescendent()) { > xIndex.AddColumnOrdered(((TRtIndexDef) xTableDef.GetIndex(i)).GetField(j).getField().GetName(), risDesc); > } else { > xIndex.AddColumnOrdered(((TRtIndexDef) xTableDef.GetIndex(i)).GetField(j).getField().GetName(), risAsc); > } > } > } > for (i = 0; i <= xTableDef.GetUniqueConstraintCount() - 1; ++i) { > xUC = getUniqueConstraintList().AddUniqueConstraint(xTableDef.GetUniqueConstraint(i).GetName()); > xUC.SetOption(rcaAdd); > for (j = 0; j <= xTableDef.GetUniqueConstraint(i).GetFieldCount() - 1; ++j) { > xUC.AddColumn(xTableDef.GetUniqueConstraint(i).GetField(j).getField().GetName()); > } > } > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private int GetFieldPairs(boolean LInsertIntoSelect) { > GetFieldPairs_Context ctx = new GetFieldPairs_Context(LInsertIntoSelect); > return ctx.execute(); > } > > private TRtCustomSQL AsSelectOld() { > TRtCustomSQL Result; > int i; > Result = GetOwnerConnection().SQLSelect(); > try { > ((TRtSelect) Result).getFrom().AddTable(GetOldTableName()); > for (i = 0; i <= ASel.GetCount() - 1; ++i) { > ((TRtSelect) Result).getColumns().AddColumn(ASel.Get(i)); > } > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsInsertNew() { > TRtCustomSQL Result; > int i; > String STmp = ""; > Result = GetOwnerConnection().SQLInsertInto(); > try { > Result.setUseDataBaseDef(GetOwnerConnection().GetNewDatabase()); > ((TRtInsertInto) Result).SetTableName(FTableName); > for (i = 0; i <= AIns.GetCount() - 1; ++i) { > STmp = AIns.Get(i); > ((TRtInsertInto) Result).getColumns().SetColumnExp(STmp, ':' + STmp); > ((TRtInsertInto) Result).GetParams().GetItem(i).SetDataType(((Number) AInsTypes.Get(i)).intValue()); > } > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsInsertErr() { > TRtCustomSQL Result; > int i; > TRtFieldDef AFldDef; > GetOldTableDef(); > Result = GetOwnerConnection().SQLInsertInto(); > try { > Result.setUseDataBaseDef(GetOwnerConnection().getPhyDatabase()); > ((TRtInsertInto) Result).SetTableName(GetErrTableName()); > for (i = 0; i <= OldTblDef.GetFieldCount() - 1; ++i) { > AFldDef = OldTblDef.GetField(i); > ((TRtInsertInto) Result).getColumns().SetColumnExp(AFldDef.GetName(), ':' + AFldDef.GetName()); > ((TRtInsertInto) Result).GetParams().GetItem(i).SetDataType(TRtPhyBaseTypeClass.SINGLETON.ParamTypeFromPhyType(AFldDef.GetFullKind().GetEnumType(), AFldDef.GetLength(), AFldDef.GetPrecision())); > } > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsRenameTableErrToOld() { > TRtCustomSQL Result; > Result = GetOwnerConnection().SQLRenameTable(); > try { > ((TRtRenameTable) Result).SetTableName(GetErrTableName()); > ((TRtRenameTable) Result).SetNewTableName(GetOldTableName()); > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsDeleteAllFromErr() { > TRtCustomSQL Result; > Result = GetOwnerConnection().SQLDeleteFrom(); > try { > ((TRtDeleteFrom) Result).SetTableName(GetErrTableName()); > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsDeleteAllFromNew() { > TRtCustomSQL Result; > Result = GetOwnerConnection().SQLDeleteFrom(); > try { > ((TRtDeleteFrom) Result).SetTableName(GetTableName()); > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsDropErrTable() { > TRtCustomSQL Result; > Result = GetOwnerConnection().SQLDropTable(); > try { > ((TRtDropTable) Result).SetTableName(GetErrTableName()); > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > private TRtCustomSQL AsInsertSelect() { > TRtCustomSQL Result; > TRtSelect Select; > int i; > Select = ((TRtSelect) AsSelectOld()); > try { > Result = GetOwnerConnection().SQLInsertSelectInto(); > try { > ((TRtInsertSelectInto) Result).SetTableName(FTableName); > for (i = 0; i <= AIns.GetCount() - 1; ++i) { > ((TRtInsertSelectInto) Result).getColumns().Add(AIns.Get(i)); > } > ((TRtInsertSelectInto) Result).SetSelect(Select); > } catch (Throwable any) { > Result.Free(); > Result = null; > } > } finally { > Select.Free(); > } > return Result; > } > > public GenSQLObjectsStep_Context(int AStep, int AAlterTableMode, int ASeq) { > this.AStep = AStep; > this.AAlterTableMode = AAlterTableMode; > this.ASeq = ASeq; > } > > public TList execute() { > Result = TList.Create(); > OldTblDef = null; > AInsSelFlds = null; > switch (AStep) { > case atsDropTriggers: > Result.Add(AsDropTriggers()); > break; > case atsDropFks: > Result.Add(AsDropFks(ASeq)); > break; > case atsRenameTable: > if (!(getKeepPKInOLDTable() || GetUseNewOperationKind())) { > Result.Add(AsDropInnerConstraints()); > } > Result.Add(AsRenameTableNewToOld()); > break; > case atsRecreateTable: > Result.Add(AsCreateTable()); > break; > case atsMoveData: > AInsSelFlds = TInsSelFieldPairs.Create(); > ASel = TStringList.Create(); > AIns = TStringList.Create(); > AInsTypes = TList.Create(); > try { > if (AAlterTableMode == atmInsertIntoSelect) { > if (GetFieldPairs(true) > 0) { > Result.Add(AsInsertSelect()); > } > } else { > AInsSelFlds = TInsSelFieldPairs.Create(); > try { > if (GetFieldPairs(false) > 0) { > Result.Add(AsCreateErrTable()); > Result.Add(AsSelectOld()); > Result.Add(AsInsertNew()); > Result.Add(AsInsertErr()); > Result.Add(AsRenameTableErrToOld()); > Result.Add(AsDeleteAllFromErr()); > Result.Add(AsDeleteAllFromNew()); > Result.Add(AsDropErrTable()); > Result.Add(AInsSelFlds); > } else { > AInsSelFlds.Free(); > } > } catch (Throwable any) { > AInsSelFlds.Free(); > throw wrap(any); > } > } > } finally { > AInsTypes.Free(); > AIns.Free(); > ASel.Free(); > } > break; > case atsRecreateFks: > Result.Add(AsRecreateFks(ASeq)); > break; > case atsRecreateTriggers: > Result.Add(AsRecreateTriggers()); > break; > case atsDropOldTable: > Result.Add(AsDropTable()); > break; > case atsCreatePkIdxInNewTable: > Result.Add(AsCreatePK()); > break; > case atsCustomAlterTable_1: > case atsCustomAlterTable_Data: > case atsCustomAlterTable_3: > throw DelphiException.Create(TransStr("TC4931", "Alteração customizada não pode ser usada por esse banco de dados.", true)); > default: > break; > } > if (Result.getCount() == 0) { > Result.Free(); > Result = null; > } else { > for (i = 0; i <= Result.getCount() - 1; ++i) { > if (Result.Get(i) != null && ((TObject) Result.Get(i)) instanceof TRtCustomSQL) { > (((TRtCustomSQL) Result.Get(i))).FUsesScriptTerminator = FUsesScriptTerminator; > } else { > break; > } > } > } > return Result; > } > } > > private final class DoImplicitChanges_Context { > > private int i; > private int c; > private int j; > private String TmpName = ""; > private String AColName = ""; > private String ANewColName = ""; > private boolean LRenameCol; > private boolean LDuplName; > private TList AList; > private TRtDBConnection DBConn; > private TRtTableDef OldTblDef; > private TRtModifyColumnItem ColItem; > private TRtIndexDef ANdxDef; > private TRtIndexItem NdxItem; > private TRtUniqueConstraintDef AUniqueDef; > private TRtSingleIndexItem UniqueItem; > private TRtRelationDef ARelDef; > private int AOrder; > > private void ProcessIndex(boolean LUnique) { > int i; > NdxItem = FIndexes.ItemByName(ANdxDef.GetName()); > if (NdxItem != null) { > if (NdxItem.getOption() != rcaDrop && !LDuplName) { > NdxItem.SetOption(rcaModify); > if (ColItem.getOption() == rcaDrop || LRenameCol) { > i = 0; > while (i < NdxItem.GetColumns().GetCount()) { > if (CompareText(NdxItem.GetColumns().GetItem(i).getColName(), AColName) == 0) { > if (LRenameCol) { > NdxItem.GetColumns().GetItem(i).SetColName(ANewColName); > i++; > } else { > NdxItem.GetColumns().GetItem(i).Free(); > } > } else { > i++; > } > } > } > } > } else { > NdxItem = FIndexes.AddIndex(ANdxDef.GetName(), LUnique); > NdxItem.FOption = rcaModify; > for (i = 0; i <= ANdxDef.GetFieldCount() - 1; ++i) { > { > TRtIndexFieldDef context_GetField = ANdxDef.GetField(i); > if (CompareText(context_GetField.getField().GetName(), AColName) == 0) { > if (ColItem.getOption() == rcaDrop) { > continue; > } > TmpName = ANewColName; > } else { > TmpName = context_GetField.getField().GetName(); > } > if (context_GetField.getDescendent()) { > AOrder = risDesc; > } else { > AOrder = risAsc; > } > NdxItem.AddColumnOrdered(TmpName, AOrder); > } > } > } > if (NdxItem.GetColumns().GetCount() == 0 && NdxItem.getOption() == rcaModify) { > NdxItem.SetOption(rcaDrop); > } > } > > private boolean ExistsAlterTableForFk(String ATableName, String AFkName) { > boolean Result; > TObject AObj; > int i; > TRtForeignKeyItem AFkItem; > if (DBConn.getSQLProcessMode() == spmGroup) { > for (i = 0; i <= DBConn.FSQLList.GetCount() - 1; ++i) { > AObj = DBConn.FSQLList.Get(i); > if (AObj instanceof TRtAlterTable) { > AFkItem = ((TRtAlterTable) AObj).FForeignKeys.ItemByName(AFkName); > Result = AFkItem != null && CompareText(AFkItem.GetForeignTable(), ATableName) == 0; > if (Result) { > return Result; > } > } > } > } else { > AFkItem = FForeignKeys.ItemByName(AFkName); > Result = AFkItem != null && CompareText(AFkItem.GetForeignTable(), ATableName) == 0; > if (Result) { > return Result; > } > } > return false; > } > > private TRtAlterTable NewAT(String ATableName) { > TRtAlterTable Result; > int i; > TObject AObj; > for (i = 0; i <= DBConn.FSQLList.GetCount() - 1; ++i) { > AObj = DBConn.FSQLList.Get(i); > if (AObj instanceof TRtAlterTable && CompareText(((TRtAlterTable) AObj).GetTableName(), ATableName) == 0) { > Result = (TRtAlterTable) AObj; > return Result; > } > } > Result = DBConn.SQLAlterTable(); > Result.SetTableName(ATableName); > return Result; > } > > private void ProcessForeignKeyList() { > int i; > int c; > TRtForeignKeyItem AFkItem; > TRtAlterTable AT; > if (AList != null) { > try { > for (i = 0; i <= AList.getCount() - 1; ++i) { > ARelDef = ((TRtRelationDef) AList.Get(i)); > if (!ExistsAlterTableForFk(ARelDef.getForeignTable().GetName(), ARelDef.GetName())) { > if (DBConn.getSQLProcessMode() == spmGroup && CompareText(ARelDef.getForeignTable().GetName(), FTableName) != 0) { > AT = NewAT(ARelDef.getForeignTable().GetName()); > } else { > AT = TRtAlterTable.this; > } > AFkItem = AT.getForeignKeyList().AddForeignKey(ARelDef.GetName(), ARelDef.getReferenceTable().GetName()); > AFkItem.SetForeignTable(ARelDef.getForeignTable().GetName()); > if (DBConn.getSQLProcessMode() == spmGroup && FAssignConsistent && !HasDropTable(DBConn, AFkItem.GetForeignTable())) { > AFkItem.SetReferenceTable(ARelDef.getReferenceTable().GetName()); > AFkItem.SetOption(rcaModify); > for (c = 0; c <= ARelDef.GetFieldCount() - 1; ++c) { > AFkItem.AddColumns(ARelDef.GetForeignField(c).GetName(), ARelDef.GetReferenceField(c).GetName()); > } > } else { > AFkItem.SetOption(rcaDrop); > } > } > } > } finally { > AList.Free(); > } > } > } > > private void ProcessForeignKeysOnUC(String AConstraintName) { > AList = OldTblDef.GetForeignKeysForUniqueConstraintDef(AConstraintName); > ProcessForeignKeyList(); > } > > private void ProcessForeignKeysOnColumn(String AColName) { > AList = OldTblDef.GetForeignKeysForField(AColName); > ProcessForeignKeyList(); > } > > public DoImplicitChanges_Context() { > } > > public void execute() { > FInnerJob++; > try { > DBConn = GetOwnerConnection(); > OldTblDef = CheckGetDatabaseDef().TableByName(FTableName); > if (OldTblDef == null) { > return; > } > for (i = 0; i <= GetColumn().GetCount() - 1; ++i) { > ColItem = GetColumn().GetItem(i); > if (ColItem.getOption() == rcaAdd) { > continue; > } > LRenameCol = ColItem.GetIsRenamingCol(); > if (LRenameCol) { > AColName = ColItem.getOldColName(); > LDuplName = GetColumn().ItemByName(AColName, rcaAdd) != null; > } else { > AColName = ColItem.getColName(); > LDuplName = false; > } > ANewColName = ColItem.getColName(); > AList = OldTblDef.GetIndexesForField(AColName); > if (AList != null) { > try { > for (c = 0; c <= AList.getCount() - 1; ++c) { > ANdxDef = ((TRtIndexDef) AList.Get(c)); > ProcessIndex(false); > } > } finally { > AList.Free(); > } > } > AList = OldTblDef.GetUniqueKeysForField(AColName); > if (AList != null) { > try { > for (c = 0; c <= AList.getCount() - 1; ++c) { > ANdxDef = ((TRtIndexDef) AList.Get(c)); > ProcessIndex(true); > } > } finally { > AList.Free(); > } > } > AList = OldTblDef.GetUniqueConstraintsForField(AColName); > if (AList != null) { > try { > for (c = 0; c <= AList.getCount() - 1; ++c) { > AUniqueDef = ((TRtUniqueConstraintDef) AList.Get(c)); > UniqueItem = FUniqueConstraints.ItemByName(AUniqueDef.GetName()); > if (UniqueItem != null) { > if (UniqueItem.getOption() != rcaDrop && !LDuplName) { > UniqueItem.SetOption(rcaModify); > if (ColItem.getOption() == rcaDrop || LRenameCol) { > j = 0; > while (j < UniqueItem.getColumns().GetCount()) { > if (CompareText(UniqueItem.getColumns().GetItem(j).getColName(), AColName) == 0) { > if (LRenameCol) { > UniqueItem.getColumns().GetItem(j).SetColName(ANewColName); > j++; > } else { > UniqueItem.getColumns().GetItem(j).Free(); > } > } else { > j++; > } > } > } > } > } else { > UniqueItem = FUniqueConstraints.AddUniqueConstraint(AUniqueDef.GetName()); > UniqueItem.FOption = rcaModify; > for (j = 0; j <= AUniqueDef.GetFieldCount() - 1; ++j) { > { > TRtUniqueConstraintFieldDef context_GetField = AUniqueDef.GetField(j); > if (CompareText(context_GetField.getField().GetName(), AColName) == 0) { > if (ColItem.getOption() == rcaDrop) { > continue; > } > TmpName = ANewColName; > } else { > TmpName = context_GetField.getField().GetName(); > } > UniqueItem.AddColumn(TmpName); > } > } > } > if (UniqueItem.getColumns().GetCount() == 0 && UniqueItem.getOption() == rcaModify) { > UniqueItem.SetOption(rcaDrop); > } > } > } finally { > AList.Free(); > } > } > if (OldTblDef.GetIsInPrimaryKey(AColName) && FPrimaryKey.getOption() != rcaDrop && !LDuplName) { > if (FPrimaryKey.getColumns().GetCount() > 0) { > FPrimaryKey.SetOption(rcaModify); > if (ColItem.getOption() == rcaDrop || LRenameCol) { > j = 0; > while (j < FPrimaryKey.getColumns().GetCount()) { > if (CompareText(FPrimaryKey.getColumns().GetItem(j).getColName(), AColName) == 0) { > if (LRenameCol) { > FPrimaryKey.getColumns().GetItem(j).SetColName(ANewColName); > j++; > } else { > FPrimaryKey.getColumns().GetItem(j).Free(); > } > } else { > j++; > } > } > } > } else { > FPrimaryKey.SetOption(rcaModify); > for (j = 0; j <= OldTblDef.GetKeyCount() - 1; ++j) { > { > TRtFieldDef context_GetPrimaryKeyField = OldTblDef.GetPrimaryKeyField(j); > if (CompareText(context_GetPrimaryKeyField.GetName(), AColName) == 0) { > if (ColItem.getOption() == rcaDrop) { > continue; > } > TmpName = ANewColName; > } else { > TmpName = context_GetPrimaryKeyField.GetName(); > } > FPrimaryKey.AddColumn(TmpName); > } > } > FPrimaryKey.SetName(OldTblDef.GetPrimaryKeyName()); > } > if (FPrimaryKey.getColumns().GetCount() == 0 && FPrimaryKey.FOption == rcaModify) { > FPrimaryKey.SetOption(rcaDrop); > } > } > ProcessForeignKeysOnColumn(AColName); > } > if (DelphiSet.get(rcaDrop, rcaModify).contains(FPrimaryKey.FOption)) { > ProcessForeignKeysOnUC(FPrimaryKey.GetName()); > } > for (i = 0; i <= FIndexes.GetCount() - 1; ++i) { > NdxItem = FIndexes.GetItem(i); > if (NdxItem.getUnique() && DelphiSet.get(rcaDrop, rcaModify).contains(NdxItem.getOption())) { > ProcessForeignKeysOnUC(NdxItem.GetName()); > } > } > for (i = 0; i <= FUniqueConstraints.GetCount() - 1; ++i) { > UniqueItem = FUniqueConstraints.GetItem(i); > if (DelphiSet.get(rcaDrop, rcaModify).contains(UniqueItem.getOption())) { > ProcessForeignKeysOnUC(UniqueItem.GetName()); > } > } > if (GetAlterTableMode() != atmAlterTable) { > if (GetAlterTableMode() != atmCustomDB) { > ForceModifyAllFks(); > } > ForceModifyAllTriggers(); > } > } finally { > FInnerJob--; > } > } > } > > private final class ExecuteStepEx_Context { > > private final class ExecuteMoveData_Context { > > private void AddParamsValues(TRtQuery aCur, br.com.senior.svcl.db.RtAccess.TRtUpdate aUpd, TInsSelFieldPairs aInsSelFlds) { > TRtParam xParam; > TRtCursorField xField; > int i; > int c; > for (i = 0; i <= aUpd.GetParamCount() - 1; ++i) { > xParam = aUpd.GetParams(i); > if (aInsSelFlds != null && aInsSelFlds.Ins.IndexOf(xParam.GetName()) >= 0) { > c = aInsSelFlds.Ins.IndexOf(xParam.GetName()); > xField = aCur.FindField(aInsSelFlds.Sel.Get(c)); > } else { > xField = aCur.FindField(xParam.GetName()); > } > try { > if (xField != null) { > if (DelphiSet.get(varEmpty, varNull, varUnknown).contains(xParam.GetTypeDesc().vType)) { > xParam.GetTypeDesc().assign(xField.GetTypeDesc()); > } > xParam.SetAsVariant(xField.GetAsVariant()); > } > } catch (Throwable any) { > xParam.SetToNull(); > } > } > } > > private TList AList; > private TRtSelect ASelOld; > private TRtQuery aCur; > private TRtInsertInto aNewInsInto; > private TRtInsertInto AErrInsInto; > private br.com.senior.svcl.db.RtAccess.TRtUpdate AInsNew; > private br.com.senior.svcl.db.RtAccess.TRtUpdate AInsErr; > private TRtDeleteFrom ADelErr; > private TRtDeleteFrom ADelNew; > private TRtRenameTable ARenErrToOld; > private TRtCreateTable ACrtErr; > private TRtDropTable ADropErr; > private TInsSelFieldPairs AInsSelFlds; > private boolean LRetry; > private boolean LInsError; > private boolean LMustIns; > private int NMoves; > private int NErrCount; > > private void DoAriseErrTable() { > TRtDBConnection DBConn; > boolean LMustCreateErr; > DBConn = GetOwnerConnection(); > if (DBConn.TableExists(GetErrTableName())) { > LMustCreateErr = false; > if (DBConn.TableExists(GetOldTableName())) { > ADelErr.ExecuteUpd(); > ADelNew.ExecuteUpd(); > } else { > ARenErrToOld.ExecuteUpd(); > LMustCreateErr = true; > } > } else { > LMustCreateErr = true; > } > if (LMustCreateErr) { > ACrtErr.ExecuteUpd(); > } > } > > private TRtStoredProcDef xSpDef; > private br.com.senior.svcl.db.RtAccess.TRtUpdate xExecSP; > private TRtParam xParam; > private int i; > private TRtTableDef xTblDef; > private TRtFieldDef xFldDef; > > public ExecuteMoveData_Context() { > } > > public void execute() { > AList = GenSQLObjectsStep(atsMoveData, atmCursor, 0); > if (AList != null) { > try { > ACrtErr = ((TRtCreateTable) AList.Get(0)); > ASelOld = ((TRtSelect) AList.Get(1)); > aNewInsInto = ((TRtInsertInto) AList.Get(2)); > AErrInsInto = ((TRtInsertInto) AList.Get(3)); > ARenErrToOld = ((TRtRenameTable) AList.Get(4)); > ADelErr = ((TRtDeleteFrom) AList.Get(5)); > ADelNew = ((TRtDeleteFrom) AList.Get(6)); > ADropErr = ((TRtDropTable) AList.Get(7)); > AInsSelFlds = ((TInsSelFieldPairs) AList.Get(8)); > DoAriseErrTable(); > try { > if (FOnStoredProcMoveData != null) { > xSpDef = null; > FOnStoredProcMoveData.run(GetOwnerConnection(), GetTableName(), true, xSpDef); > if (xSpDef == null) { > throw DelphiException.CreateFmt(TransStr("TC665", "Procedure para operação de move data da tabela %s não retornada", true), new Object[] { GetTableName() }); > } > xExecSP = GetOwnerConnection().GetAccess().NewUpdate(); > try { > xExecSP.SetStoredProc(UpperCase(xSpDef.GetName())); > if (getOnBeforeExecStoredProcMoveData() != null) { > getOnBeforeExecStoredProcMoveData().run(xExecSP); > } > xExecSP.Execute(); > xParam = xExecSP.ParamByName(cParamNameErrorLineCountInSPMoveData); > if (xParam == null || xParam.GetAsInteger() == 0) { > ADropErr.ExecuteUpd(); > } else { > LRetry = DoOnDDLError(atsMoveData, null, xExecSP); > } > FOnStoredProcMoveData.run(GetOwnerConnection(), GetTableName(), false, xSpDef); > } finally { > xExecSP.Free(); > } > } else { > aCur = ASelOld.GetRtQuery(); > aCur.SetBidirectional(false); > aCur.Open(); > AInsNew = aNewInsInto.GetRtUpdate(); > AInsNew.Prepare(); > xTblDef = GetOwnerConnection().GetNewDatabase().CheckTableByName(GetTableName()); > for (i = 0; i <= GetColumn().GetCount() - 1; ++i) { > if (GetColumn().GetItem(i).getOption() == rcaAdd && GetColumn().GetItem(i).getNotNull()) { > xParam = AInsNew.FindParam(GetColumn().GetItem(i).getColName()); > if (xParam != null) { > xFldDef = xTblDef.FieldByName(GetColumn().GetItem(i).getColName()); > xParam.SetAsVariant(NullValue(xFldDef.GetTypeDesc().vType)); > } > } > } > AInsErr = AErrInsInto.GetRtUpdate(); > AInsErr.Prepare(); > NMoves = 0; > NErrCount = 0; > GetOwnerConnection().BeginTran(); > try { > while (!aCur.GetEOF()) { > AddParamsValues(aCur, AInsNew, AInsSelFlds); > LMustIns = true; > try { > DoOnBeforeDDLStep(atsMoveData, aCur, AInsNew); > } catch (EMoveDataIgnoreRow any) { > LMustIns = false; > LRetry = DoOnDDLError(atsMoveData, aCur, AInsNew); > } catch (Throwable any) { > throw wrap(any); > } > LInsError = false; > if (LMustIns) { > while (true) { > try { > if (aNewInsInto.getUseDataBaseDef() != null && GetOwnerConnection().FRtDatabase != null) { > GetOwnerConnection().FRtDatabase.setDatabaseDef(aNewInsInto.getUseDataBaseDef()); > } > try { > AInsNew.Execute(); > } finally { > if (aNewInsInto.getUseDataBaseDef() != null && GetOwnerConnection().FRtDatabase != null) { > GetOwnerConnection().FRtDatabase.setDatabaseDef(GetOwnerConnection().getPhyDatabase()); > } > } > break; > } catch (Throwable any) { > LRetry = DoOnDDLError(atsMoveData, aCur, AInsNew); > if (LRetry) { > continue; > } else { > LInsError = true; > break; > } > } > } > } > if (LInsError) { > AddParamsValues(aCur, AInsErr, null); > if (AErrInsInto.getUseDataBaseDef() != null && GetOwnerConnection().FRtDatabase != null) { > GetOwnerConnection().FRtDatabase.setDatabaseDef(AErrInsInto.getUseDataBaseDef()); > } > try { > AInsErr.Execute(); > NErrCount++; > } finally { > if (AErrInsInto.getUseDataBaseDef() != null && GetOwnerConnection().FRtDatabase != null) { > GetOwnerConnection().FRtDatabase.setDatabaseDef(GetOwnerConnection().getPhyDatabase()); > } > } > } > if (NMoves != 0 && NMoves % 0x80 == 0x0) { > GetOwnerConnection().Commit(); > GetOwnerConnection().BeginTran(); > } > NMoves++; > aCur.Next(); > } > if (NErrCount == 0) { > GetOwnerConnection().Commit(); > ADropErr.ExecuteUpd(); > } > } finally { > if (GetOwnerConnection().GetInTransaction()) { > GetOwnerConnection().Commit(); > } > } > } > } finally { > AInsSelFlds.Free(); > ADropErr.Free(); > ADelNew.Free(); > ADelErr.Free(); > ARenErrToOld.Free(); > AErrInsInto.Free(); > aNewInsInto.Free(); > ASelOld.Free(); > ACrtErr.Free(); > } > } finally { > AList.Free(); > } > } > } > } > > private final int aStep; > private final int ASeq; > private final int aInitSubStep; > > private void ExecuteMoveData() { > ExecuteMoveData_Context ctx = new ExecuteMoveData_Context(); > ctx.execute(); > } > > private String OldSQL = ""; > private String ASql = ""; > private String ALastSQLs = ""; > private String ExceptMessage = ""; > private int AMode; > private int iStep; > private boolean LRetry; > private TRtTableDef xTableDef; > > public ExecuteStepEx_Context(int aStep, int ASeq, int aInitSubStep) { > this.aStep = aStep; > this.ASeq = ASeq; > this.aInitSubStep = aInitSubStep; > } > > public void execute() { > switch (aStep) { > case atsMoveData: > ExecuteMoveData(); > break; > case atsAllSteps: > AMode = GetAlterTableMode(); > if (AMode == atmCustomDB) { > throw DelphiException.Create(TransStrFmt("TC428", "Alteração customizada pelo banco deve ser tratada pela classe específica do banco: %0:s", new Object[] { ClassName() }, true)); > } > ExecuteStep(atsDropTriggers, 0); > ExecuteStep(atsDropFks, 0); > if (AMode == atmCursor) { > for (iStep = atsRenameTable; iStep <= atsDropOldTable; ++iStep) { > ExecuteStep(iStep, 0); > } > if (GetUseNewOperationKind()) { > xTableDef = GetOwnerConnection().GetNewDatabase().TableByName(GetTableName()); > if (xTableDef.GetHasPrimaryKey() || xTableDef.GetHasIndex() || xTableDef.GetHasUniqueIndex() || xTableDef.GetHasUniqueConstraint()) { > ExecuteStep(atsCreatePkIdxInNewTable); > } > } > } else { > ExecuteStep(atsAlterTable, 0); > } > ExecuteStep(atsRecreateFks, 0); > ExecuteStep(atsRecreateTriggers, 0); > UpdatePhyDatabase(); > break; > default: > OldSQL = FSql; > try { > DoOnBeforeDDLStep(aStep); > ASql = GenSQLStep(aStep, ASeq); > while (true) { > try { > if (aStep == atsRecreateTriggers) { > ALastSQLs = ExecuteRecreateTriggers(ASql, ALastSQLs); > } else { > ALastSQLs = ExecuteMultipleSQLs(ASql, aInitSubStep, ALastSQLs); > } > break; > } catch (DelphiException E) { > LRetry = DoOnDDLError(aStep); > if (LRetry) { > continue; > } else { > ExceptMessage = TransStrFmt("TC3297", "Mensagem: %0:s%1:sComando: %2:s%3:s%4:s%5:sGrupo de comandos relacionados:%6:s%7:s", new Object[] { GetATOperation(aStep, new Object[] { GetTableName() }), EOL, StrBreakLine(StrReplaceStr(FSql, SQLEOC_SEP, EOL), " ", 80, 4, kblNone), EOL, StrBreakLine(E.getMessage(), " ", 80, 4, kblNone), EOL, EOL, StrBreakLine(StrReplaceStr(ALastSQLs, SQLEOC_SEP, EOL), " ", 80, 4, kblNone) }, true); > E.setMessage(ExceptMessage); > throw wrap(E); > } > } > } > } finally { > FSql = OldSQL; > } > break; > } > } > } > > private int FLevelAlterTableMode; > private int FAlterTableMode; > short FInnerJob; > boolean FAssignConsistent; > private boolean FKeepPKInOLDTable; > private TNotifyEvent FOnCommitMoveData; > TRtOnStoredProcMoveData FOnStoredProcMoveData; > private TRtOnExecStoredProcMoveData FOnBeforeExecStoredProcMoveData; > private TRtOnCustomAlterTableUpdateData FOnCustomAlterTableUpdateData; > > public final int GetAlterTableMode() { > int AMode; > if (FAlterTableMode != atmCursor) { > AMode = CheckGetAlterTableMode(); > } else { > AMode = atmCursor; > } > if (FAlterTableMode != AMode && AMode != atmAlterTable) { > FAlterTableMode = AMode; > } > return FAlterTableMode; > } > > public final void SetAlterTableMode(int Value) { > FAlterTableMode = Value; > } > > final String GetOldTableName() { > return GetTableName() + "_OLD"; > } > > final String GetErrTableName() { > return GetTableName() + "_ERR"; > } > > void ForceModifyAllFks() { > ForceModifyAllFks_Context ctx = new ForceModifyAllFks_Context(); > ctx.execute(); > } > > void ForceModifyAllTriggers() { > ForceModifyAllTriggers_Context ctx = new ForceModifyAllTriggers_Context(); > ctx.execute(); > } > > public final boolean GetUsingCursor() { > return GetAlterTableMode() == atmCursor; > } > > public final void SetUsingCursor(boolean Value) { > int AMode; > if (Value) { > SetAlterTableMode(atmCursor); > } else { > AMode = CheckGetAlterTableMode(); > if (AMode == atmCursor) { > AMode = atmAlterTable; > } > SetAlterTableMode(AMode); > } > } > > protected boolean FUseNewOperationKind; > > public boolean GetUseNewOperationKind() { > return false; > } > > protected boolean GetDATNeedForceModifyAllFks() { > return true; > } > > protected final boolean MaxRestrictionGenCriticalChanges() { > boolean Result; > int i; > TRtSqlDriver xSqlDriver = null; > Result = false; > if (getLevelAlterTableMode() == latmMaxRestriction) { > for (i = rtDBConst.Low_TDBVersionKind; i <= rtDBConst.High_TDBVersionKind; ++i) { > xSqlDriver = TRtDatabaseServerClass.SINGLETON.GlobalInstance().FSqlDrivers[i]; > if (xSqlDriver != null && xSqlDriver.OnHasCriticalChange != null && xSqlDriver.OnHasCriticalChange.run(this)) { > Result = true; > return Result; > } > } > } > return Result; > } > > protected boolean GetConvertSQLToAccess() { > return false; > } > > protected void CheckUnprepare() { > super.CheckUnprepare(); > if (FInnerJob == 0) { > FAssignConsistent = false; > } > } > > protected int CheckGetAlterTableMode() { > CheckGetAlterTableMode_Context ctx = new CheckGetAlterTableMode_Context(); > return ctx.execute(); > } > > protected void UpdatePhyDatabase() { > TRtTableDef ATblDef; > if (!GetNotUpdatePhyDatabase()) { > ATblDef = CheckGetDatabaseDef().TableByName(FTableName); > if (ATblDef != null) { > AssignToTableDef(ATblDef, DelphiSet.getRange(raaColumns, raaForeignKeys)); > } > } > } > > public final TRtModifyColumnsList GetColumn() { > return ((TRtModifyColumnsList) super.GetColumn()); > } > > protected final boolean AssignFksFromTableDef(TRtTableDef _NewTableDef, int _AFkOption) { > boolean Result; > boolean LModify; > TBoolean xForceDrop = new TBoolean(); > int i; > int c; > TRtTableDef OldTblDef; > int AOption; > TRtRelationDef ARelDef; > TRtForeignKeyItem RelItem; > TStringList xForceDropFKList; > OldTblDef = CheckGetDatabaseDef().CheckTableByName(_NewTableDef.GetName()); > FForeignKeys.Clear(); > xForceDropFKList = TStringList.Create(); > try { > if (!GetOwnerConnection().FDisableEvents && GetOwnerConnection().FOnBeforeAssignFromTableDef != null) { > GetOwnerConnection().FOnBeforeAssignFromTableDef.run(this, OldTblDef, _NewTableDef); > } > if (DelphiSet.get(rcaDrop, rcaModify).contains(_AFkOption)) { > for (i = 0; i <= OldTblDef.GetRelationCount() - 1; ++i) { > { > TRtRelationDef context_GetRelation = OldTblDef.GetRelation(i); > if (CompareText(context_GetRelation.getForeignTable().GetName(), FTableName) == 0) { > xForceDrop.v = false; > if (GetOwnerConnection().getOnVerifyAssignObjectDef() != null) { > GetOwnerConnection().getOnVerifyAssignObjectDef().run(OldTblDef.GetRelation(i), xForceDrop); > if (xForceDrop.v) { > xForceDropFKList.Add(OldTblDef.GetRelation(i).GetName()); > } > } > if (_NewTableDef.RelationByName(context_GetRelation.GetName()) == null || xForceDrop.v) { > FForeignKeys.AddForeignKey(context_GetRelation.GetName(), context_GetRelation.getReferenceTable().GetName()).FOption = rcaDrop; > } > } > } > } > } > for (i = 0; i <= _NewTableDef.GetRelationCount() - 1; ++i) { > { > TRtRelationDef context_GetRelation = _NewTableDef.GetRelation(i); > if (xForceDropFKList.IndexOf(context_GetRelation.GetName()) == -1) { > if (CompareText(context_GetRelation.getForeignTable().GetName(), FTableName) != 0) { > continue; > } > ARelDef = OldTblDef.RelationByName(context_GetRelation.GetName()); > LModify = false; > if (ARelDef != null) { > LModify = CompareText(context_GetRelation.getForeignTable().GetName(), ARelDef.getForeignTable().GetName()) != 0 || CompareText(context_GetRelation.getReferenceTable().GetName(), ARelDef.getReferenceTable().GetName()) != 0 || context_GetRelation.GetFieldCount() != ARelDef.GetFieldCount(); > if (!LModify) { > for (c = 0; c <= context_GetRelation.GetFieldCount() - 1; ++c) { > LModify = CompareText(context_GetRelation.GetForeignField(c).GetName(), ARelDef.GetForeignField(c).GetName()) != 0 || CompareText(context_GetRelation.GetReferenceField(c).GetName(), ARelDef.GetReferenceField(c).GetName()) != 0; > if (LModify) { > break; > } > } > } > } > AOption = rcaModify; > if (!LModify) { > if (ARelDef != null) { > continue; > } > AOption = rcaAdd; > } > if (_AFkOption == rcaDrop) { > if (AOption == rcaModify) { > AOption = rcaDrop; > } else { > continue; > } > } else if (_AFkOption == rcaAdd) { > AOption = rcaAdd; > } > RelItem = FForeignKeys.AddForeignKey(context_GetRelation.GetName(), context_GetRelation.getReferenceTable().GetName()); > RelItem.FOption = AOption; > if (AOption != rcaDrop) { > for (c = 0; c <= context_GetRelation.GetFieldCount() - 1; ++c) { > RelItem.AddColumns(context_GetRelation.GetForeignField(c).GetName(), context_GetRelation.GetReferenceField(c).GetName()); > } > } > } > } > } > } finally { > xForceDropFKList.Destroy(); > } > Result = FForeignKeys.GetCount() > 0; > if (!GetOwnerConnection().FDisableEvents && GetOwnerConnection().FOnAfterAssignFromTableDef != null) { > GetOwnerConnection().FOnAfterAssignFromTableDef.run(this, OldTblDef, _NewTableDef); > } > return Result; > } > > protected final boolean AssignTriggersFromTableDef(TRtTableDef _NewTableDef, int _ATrgOption) { > boolean Result; > int i; > TRtTableDef OldTblDef; > TRtTriggerItem ATrgItem; > boolean LModify; > OldTblDef = CheckGetDatabaseDef().CheckTableByName(_NewTableDef.GetName()); > FTriggers.Clear(); > if (!GetOwnerConnection().FDisableEvents && GetOwnerConnection().FOnBeforeAssignFromTableDef != null) { > GetOwnerConnection().FOnBeforeAssignFromTableDef.run(this, OldTblDef, _NewTableDef); > } > if (DelphiSet.get(rcaDrop, rcaModify).contains(_ATrgOption)) { > for (i = 0; i <= OldTblDef.GetTriggerCount() - 1; ++i) { > if (_ATrgOption == rcaDrop || _NewTableDef.TriggerByName(OldTblDef.GetTrigger(i).GetName()) == null) { > FTriggers.AddTrigger(OldTblDef.GetTrigger(i).GetName(), "", OldTblDef.GetTrigger(i).getForEachRow()).FOption = rcaDrop; > } > } > } > if (DelphiSet.get(rcaAdd, rcaModify).contains(_ATrgOption)) { > for (i = 0; i <= _NewTableDef.GetTriggerCount() - 1; ++i) { > LModify = _ATrgOption == rcaModify && OldTblDef.TriggerByName(_NewTableDef.GetTrigger(i).GetName()) != null; > ATrgItem = FTriggers.AddTriggerFromTriggerDef(_NewTableDef.GetTrigger(i)); > if (LModify) { > ATrgItem.FOption = rcaModify; > } > } > } > Result = FTriggers.GetCount() > 0; > if (!GetOwnerConnection().FDisableEvents && GetOwnerConnection().FOnAfterAssignFromTableDef != null) { > GetOwnerConnection().FOnAfterAssignFromTableDef.run(this, OldTblDef, _NewTableDef); > } > return Result; > } > > protected String TranslateOldFieldValue(TRtFieldDef AFld, TRtModifyColumnItem ACol, String AColName) { > TranslateOldFieldValue_Context ctx = new TranslateOldFieldValue_Context(AFld, ACol, AColName); > return ctx.execute(); > } > > protected String GenSQL() { > DoImplicitChanges(); > return GenPlainAlterTable(); > } > > protected String GenSQLStep(int AStep, int ASeq) { > String Result = ""; > TList AList; > int AMode; > int iStep; > String s = ""; > int i; > TRtTableDef xTableDef; > switch (AStep) { > case atsAlterTable: > Result = ""; > break; > case atsAllSteps: > AMode = GetAlterTableMode(); > if (AMode == atmCustomDB) { > throw DelphiException.Create(TransStrFmt("TC428", "Alteração customizada pelo banco deve ser tratada pela classe específica do banco: %0:s", new Object[] { ClassName() }, true)); > } > Result = GenSQLStep(atsDropTriggers, 0) + ToStr(SQLEOC_SEP); > Result = Result + GenSQLStep(atsDropFks, 0) + ToStr(SQLEOC_SEP); > if (AMode == atmCursor) { > for (iStep = atsRenameTable; iStep <= atsDropOldTable; ++iStep) { > Result = Result + GenSQLStep(iStep, 0) + ToStr(SQLEOC_SEP); > } > if (GetUseNewOperationKind()) { > xTableDef = GetOwnerConnection().GetNewDatabase().TableByName(GetTableName()); > if (xTableDef.GetHasPrimaryKey() || xTableDef.GetHasIndex() || xTableDef.GetHasIndex() || xTableDef.GetHasUniqueConstraint()) { > Result = Result + GenSQLStep(atsCreatePkIdxInNewTable, 0) + ToStr(SQLEOC_SEP); > } > } > } else { > Result = Result + GenSQLStep(atsAlterTable, 0) + ToStr(SQLEOC_SEP); > } > Result = Result + GenSQLStep(atsRecreateFks, 0) + ToStr(SQLEOC_SEP); > Result = Result + GenSQLStep(atsRecreateTriggers, 0) + ToStr(SQLEOC_SEP); > break; > default: > AList = GenSQLObjectsStep(AStep, atmInsertIntoSelect, ASeq); > if (AList != null) { > try { > Result = ""; > for (i = 0; i <= AList.getCount() - 1; ++i) { > if (AList.Get(i) != null) { > if (((TObject) AList.Get(i)) instanceof TRtAlterTable) { > Result = Result + (((TRtAlterTable) AList.Get(i))).GenPlainAlterTable() + ToStr(SQLEOC_SEP); > } else { > s = (((TRtCustomSQL) AList.Get(i))).GenSQL(); > Result = Result + s + ToStr(SQLEOC_SEP); > } > } > } > } finally { > for (i = 0; i <= AList.getCount() - 1; ++i) { > if (AList.Get(i) != null) { > (((TRtCustomSQL) AList.Get(i))).Free(); > } else { > break; > } > } > AList.Free(); > } > } else { > Result = ""; > } > break; > } > return Result; > } > > public String GetSQLStep(int AStep, int ASeq) { > return StrReplaceStr(GenSQLStep(AStep, ASeq), ToStr(SQLEOC_SEP), EOL); > } > > public final String GetSQLStepScript(int AStep, int ASeq) { > String Result = ""; > FUsesScriptTerminator = true; > try { > Result = StrReplaceStr(GenSQLStep(AStep, ASeq), ToStr(SQLEOC_SEP), EOL); > Result = StrBreakLine(Result, " ,", 250, 0, kblNone); > } finally { > FUsesScriptTerminator = false; > } > return Result; > } > > protected String GenPlainAlterTable() { > return ""; > } > > protected TList GenSQLObjectsStep(int AStep, int AAlterTableMode, int ASeq) { > GenSQLObjectsStep_Context ctx = new GenSQLObjectsStep_Context(AStep, AAlterTableMode, ASeq); > return ctx.execute(); > } > > protected final TList GenSQLObjectsStep(int AStep, int AAlterTableMode) { > return GenSQLObjectsStep(AStep, AAlterTableMode, 0); > } > > protected final TList GenSQLObjectsStep(int AStep) { > return GenSQLObjectsStep(AStep, atmInsertIntoSelect, 0); > } > > protected void DoImplicitChanges() { > DoImplicitChanges_Context ctx = new DoImplicitChanges_Context(); > ctx.execute(); > } > > protected final String ExecuteRecreateTriggers(String ASql, String ALastSQLs) { > TInt p = new TInt(); > ALastSQLs = ""; > CheckConnected(); > p.v = 0; > while (p.v != -1) { > FSql = TrimRight(StrGetNextToken(ASql, p, SQLEOC_SEP)); > if (!FSql.equals("")) { > ALastSQLs = ALastSQLs + FSql + EOL; > FUpdate.UnPrepare(); > FUpdate.SetCommand(FSql); > FUpdate.Execute(); > } > } > FUpdate.UnPrepare(); > return ALastSQLs; > } > > public void runCreate() { > super.runCreate(); > FLevelAlterTableMode = latmDefault; > setKeepPKInOLDTable(false); > FUseNewOperationKind = false; > } > > public static TRtAlterTable Create() { > TRtAlterTable Result; > Result = new TRtAlterTable(); > Result.runCreate(); > return Result; > } > > public void ExecuteStep(int aStep, int aInitSubStep) { > ExecuteStepEx(aStep, 0, aInitSubStep); > } > > public void ExecuteStep(int aStep) { > ExecuteStep(aStep, 0); > } > > public void ExecuteStepEx(int aStep, int ASeq, int aInitSubStep) { > ExecuteStepEx_Context ctx = new ExecuteStepEx_Context(aStep, ASeq, aInitSubStep); > ctx.execute(); > } > > public void ExecuteStepEx(int aStep, int ASeq) { > ExecuteStepEx(aStep, ASeq, 0); > } > > public void ExecuteUpd() { > String ASql = ""; > String ALastSQLs = ""; > String ExceptMessage = ""; > boolean LRetry; > DoOnBeforeDDLStep(); > ASql = GenSQL(); > while (true) { > try { > ALastSQLs = ExecuteMultipleSQLs(ASql, 0, ALastSQLs); > UpdatePhyDatabase(); > break; > } catch (DelphiException E) { > LRetry = DoOnDDLError(); > if (LRetry) { > continue; > } else { > ExceptMessage = TransStrFmt("TC3297", "Mensagem: %0:s%1:sComando: %2:s%3:s%4:s%5:sGrupo de comandos relacionados:%6:s%7:s", new Object[] { GetATOperation(atsAlterTable, new Object[] { GetTableName() }), EOL, StrBreakLine(StrReplaceStr(FSql, SQLEOC_SEP, EOL), " ", 80, 4, kblNone), EOL, StrBreakLine(E.getMessage(), " ", 80, 4, kblNone), EOL, EOL, StrBreakLine(StrReplaceStr(ALastSQLs, SQLEOC_SEP, EOL), " ", 80, 4, kblNone) }, true); > E.setMessage(ExceptMessage); > throw wrap(E); > } > } > } > } > > public final DelphiSet AssignFromTableDef(TRtTableDef _NewTableDef, DelphiSet _AAssOpt) { > DelphiSet Result = DelphiSet.get(); > boolean LModify; > boolean LEvent; > TBoolean xForceDrop = new TBoolean(); > int AOrder; > int AOption; > int i; > int c; > TRtTableDef OldTblDef; > TRtFieldDef aNewFldDef; > TRtFieldDef aOldFldDef; > TRtIndexDef ANdxDef; > TRtUniqueConstraintDef AUniqueDef; > TRtIndexItem NdxItem; > TRtSingleIndexItem UniqueItem; > TRtAddColumnsList vColumns; > TStringList xForceDropList; > TString xKindName = new TString(); > TString xLength = new TString(); > TString xPrecision = new TString(); > TString xNull = new TString(); > boolean xGenOldStrKind; > boolean xGenNewStrKind; > OldTblDef = CheckGetDatabaseDef().CheckTableByName(_NewTableDef.GetName()); > Clear(); > Result = DelphiSet.get(); > FTableName = _NewTableDef.GetName(); > if (!GetOwnerConnection().FDisableEvents && GetOwnerConnection().FOnBeforeAssignFromTableDef != null) { > GetOwnerConnection().FOnBeforeAssignFromTableDef.run(this, OldTblDef, _NewTableDef); > } > xForceDropList = TStringList.Create(); > try { > if (_AAssOpt.contains(raaColumns)) { > for (i = 0; i <= OldTblDef.GetFieldCount() - 1; ++i) { > xForceDrop.v = false; > if (GetOwnerConnection().getOnVerifyAssignObjectDef() != null) { > GetOwnerConnection().getOnVerifyAssignObjectDef().run(OldTblDef.GetField(i), xForceDrop); > if (xForceDrop.v) { > xForceDropList.Add(OldTblDef.GetField(i).GetName()); > } > } > if (_NewTableDef.FieldByName(OldTblDef.GetField(i).GetName()) == null || xForceDrop.v) { > GetColumn().DropColumn(OldTblDef.GetField(i).GetName()); > } > } > vColumns = TRtAddColumnsList.Create(); > vColumns.SetFOwner(this); > vColumns.FDBVersionKind = FColumns.FDBVersionKind; > try { > for (i = 0; i <= _NewTableDef.GetFieldCount() - 1; ++i) { > aNewFldDef = _NewTableDef.GetField(i); > if (xForceDropList.IndexOf(aNewFldDef.GetName()) == -1) { > aOldFldDef = OldTblDef.FieldByName(aNewFldDef.GetName()); > if (aOldFldDef != null) { > xGenNewStrKind = aNewFldDef.GetPhyNativeStrFullKind().equals(""); > if (xGenNewStrKind) { > vColumns.AddColumn(aNewFldDef.GetName(), aNewFldDef.GetFullKind().GetEnumType(), aNewFldDef.GetLength(), aNewFldDef.GetPrecision(), aNewFldDef.getNotNull()).GenSqlKind(_NewTableDef.GetDatabase(), xKindName, xLength, xPrecision, xNull); > aNewFldDef.SetPhyNativeStrKind(xKindName.v, xLength.v, xPrecision.v, xNull.v); > vColumns.Clear(); > } > xGenOldStrKind = aOldFldDef.GetPhyNativeStrFullKind().equals(""); > if (xGenOldStrKind) { > vColumns.AddColumn(aOldFldDef.GetName(), aOldFldDef.GetFullKind().GetEnumType(), aOldFldDef.GetLength(), aOldFldDef.GetPrecision(), aOldFldDef.getNotNull()).GenSqlKind(_NewTableDef.GetDatabase(), xKindName, xLength, xPrecision, xNull); > aOldFldDef.SetPhyNativeStrKind(xKindName.v, xLength.v, xPrecision.v, xNull.v); > vColumns.Clear(); > } > if (CompareText(aNewFldDef.GetPhyNativeStrFullKind(), aOldFldDef.GetPhyNativeStrFullKind()) != 0) { > GetColumn().ModifyColumn(aNewFldDef.GetName(), aNewFldDef.GetName(), aNewFldDef.GetFullKind().GetEnumType(), aNewFldDef.GetLength(), aNewFldDef.GetPrecision(), aNewFldDef.getNotNull(), aNewFldDef.getNotNull() != aOldFldDef.getNotNull()); > } > if (xGenNewStrKind) { > aNewFldDef.SetPhyNativeStrKind("", "", "", ""); > } > if (xGenOldStrKind) { > aOldFldDef.SetPhyNativeStrKind("", "", "", ""); > } > } else { > GetColumn().AddColumn(aNewFldDef.GetName(), aNewFldDef.GetFullKind().GetEnumType(), aNewFldDef.GetLength(), aNewFldDef.GetPrecision(), aNewFldDef.getNotNull()); > } > } > } > } finally { > vColumns.Free(); > } > if (GetColumn().GetCount() > 0) { > Result = Result.add(DelphiSet.get(raaColumns)); > } > } > xForceDropList.Clear(); > for (i = 0; i <= OldTblDef.GetIndexCount() - 1; ++i) { > { > TRtIndexDef context_GetIndex = (TRtIndexDef) OldTblDef.GetIndex(i); > if (context_GetIndex.getUnique()) { > if (!_AAssOpt.contains(raaUniqueKeys)) { > continue; > } > } else if (!_AAssOpt.contains(raaIndexes)) { > continue; > } > xForceDrop.v = false; > if (GetOwnerConnection().getOnVerifyAssignObjectDef() != null) { > GetOwnerConnection().getOnVerifyAssignObjectDef().run((TObject) OldTblDef.GetIndex(i), xForceDrop); > if (xForceDrop.v) { > xForceDropList.Add(OldTblDef.GetIndex(i).GetName()); > } > } > if (_NewTableDef.IndexByName(context_GetIndex.GetName()) == null || xForceDrop.v) { > FIndexes.AddIndex(context_GetIndex.GetName(), context_GetIndex.getUnique()).FOption = rcaDrop; > } > } > } > for (i = 0; i <= _NewTableDef.GetIndexCount() - 1; ++i) { > { > TRtIndexDef context_GetIndex = (TRtIndexDef) _NewTableDef.GetIndex(i); > if (xForceDropList.IndexOf(context_GetIndex.GetName()) == -1) { > if (context_GetIndex.getUnique()) { > if (!_AAssOpt.contains(raaUniqueKeys)) { > continue; > } > } else if (!_AAssOpt.contains(raaIndexes)) { > continue; > } > ANdxDef = OldTblDef.IndexByName(context_GetIndex.GetName()); > LModify = false; > if (ANdxDef != null) { > LModify = context_GetIndex.getUnique() != ANdxDef.getUnique() || context_GetIndex.GetFieldCount() != ANdxDef.GetFieldCount(); > if (!LModify) { > for (c = 0; c <= context_GetIndex.GetFieldCount() - 1; ++c) { > LModify = CompareText(context_GetIndex.GetField(c).getField().GetName(), ANdxDef.GetField(c).getField().GetName()) != 0 || context_GetIndex.GetField(c).getDescendent() != ANdxDef.GetField(c).getDescendent(); > if (LModify) { > break; > } > } > } > } > AOption = rcaModify; > if (!LModify) { > if (ANdxDef != null) { > continue; > } > AOption = rcaAdd; > } > NdxItem = FIndexes.AddIndex(context_GetIndex.GetName(), context_GetIndex.getUnique()); > NdxItem.FOption = AOption; > for (c = 0; c <= context_GetIndex.GetFieldCount() - 1; ++c) { > { > TRtIndexFieldDef context_GetField = context_GetIndex.GetField(c); > if (context_GetField.getDescendent()) { > AOrder = risDesc; > } else { > AOrder = risAsc; > } > NdxItem.AddColumnOrdered(context_GetField.getField().GetName(), AOrder); > } > } > } > } > } > if (FIndexes.GetCount() > 0) { > for (i = 0; i <= FIndexes.GetCount() - 1; ++i) { > if (FIndexes.GetItem(i).getUnique()) { > Result = Result.add(DelphiSet.get(raaUniqueKeys)); > } else { > Result = Result.add(DelphiSet.get(raaIndexes)); > } > } > } > xForceDropList.Clear(); > if (_AAssOpt.contains(raaUniqueConstraints)) { > for (i = 0; i <= OldTblDef.GetUniqueConstraintCount() - 1; ++i) { > AUniqueDef = OldTblDef.GetUniqueConstraint(i); > if (_NewTableDef.UniqueConstraintByName(AUniqueDef.GetName()) == null) { > UniqueItem = FUniqueConstraints.AddUniqueConstraint(AUniqueDef.GetName()); > UniqueItem.FOption = rcaDrop; > for (c = 0; c <= AUniqueDef.GetFieldCount() - 1; ++c) { > { > TRtUniqueConstraintFieldDef context_GetField = AUniqueDef.GetField(c); > UniqueItem.AddColumn(context_GetField.getField().GetName()); > } > } > } > } > for (i = 0; i <= _NewTableDef.GetUniqueConstraintCount() - 1; ++i) { > { > TRtUniqueConstraintDef context_GetUniqueConstraint = _NewTableDef.GetUniqueConstraint(i); > AUniqueDef = OldTblDef.UniqueConstraintByName(context_GetUniqueConstraint.GetName()); > LModify = false; > if (AUniqueDef != null) { > LModify = context_GetUniqueConstraint.GetFieldCount() != AUniqueDef.GetFieldCount(); > if (!LModify) { > for (c = 0; c <= context_GetUniqueConstraint.GetFieldCount() - 1; ++c) { > LModify = CompareText(context_GetUniqueConstraint.GetField(c).getField().GetName(), AUniqueDef.GetField(c).getField().GetName()) != 0; > if (LModify) { > break; > } > } > } > } > AOption = rcaModify; > if (!LModify) { > if (AUniqueDef != null) { > continue; > } > AOption = rcaAdd; > } > UniqueItem = FUniqueConstraints.AddUniqueConstraint(context_GetUniqueConstraint.GetName()); > UniqueItem.FOption = AOption; > for (c = 0; c <= context_GetUniqueConstraint.GetFieldCount() - 1; ++c) { > { > TRtUniqueConstraintFieldDef context_GetField = context_GetUniqueConstraint.GetField(c); > UniqueItem.AddColumn(context_GetField.getField().GetName()); > } > } > } > } > if (FUniqueConstraints.GetCount() > 0) { > Result = Result.add(DelphiSet.get(raaUniqueConstraints)); > } > } > if (_AAssOpt.contains(raaTriggers)) { > LEvent = GetOwnerConnection().getDisableEvents(); > try { > GetOwnerConnection().setDisableEvents(true); > if (AssignTriggersFromTableDef(_NewTableDef, rcaModify)) { > Result = Result.add(DelphiSet.get(raaTriggers)); > } > } finally { > GetOwnerConnection().setDisableEvents(LEvent); > } > } > if (_AAssOpt.contains(raaForeignKeys)) { > LEvent = GetOwnerConnection().getDisableEvents(); > try { > GetOwnerConnection().setDisableEvents(true); > if (AssignFksFromTableDef(_NewTableDef, rcaModify)) { > Result = Result.add(DelphiSet.get(raaForeignKeys)); > } > } finally { > GetOwnerConnection().setDisableEvents(LEvent); > } > } > if (_AAssOpt.contains(raaPrimaryKey)) { > if (CompareText(_NewTableDef.GetPrimaryKeyStr(), OldTblDef.GetPrimaryKeyStr()) != 0) { > if (_NewTableDef.GetKeyCount() > 0) { > for (i = 0; i <= _NewTableDef.GetKeyCount() - 1; ++i) { > FPrimaryKey.AddColumn(_NewTableDef.GetPrimaryKeyField(i).GetName()); > } > if (OldTblDef.GetKeyCount() > 0) { > FPrimaryKey.FOption = rcaModify; > } else { > FPrimaryKey.FOption = rcaAdd; > } > FPrimaryKey.SetName(_NewTableDef.GetPrimaryKeyName()); > Result = Result.add(DelphiSet.get(raaPrimaryKey)); > } else if (OldTblDef.GetKeyCount() > 0) { > FPrimaryKey.FOption = rcaDrop; > FPrimaryKey.SetName(OldTblDef.GetPrimaryKeyName()); > Result = Result.add(DelphiSet.get(raaPrimaryKey)); > } > } > } > } finally { > xForceDropList.Destroy(); > } > FAssignConsistent = true; > if (!GetOwnerConnection().FDisableEvents && GetOwnerConnection().FOnAfterAssignFromTableDef != null) { > GetOwnerConnection().FOnAfterAssignFromTableDef.run(this, OldTblDef, _NewTableDef); > } > return Result; > } > > public final void AssignToTableDef(TRtTableDef ATblDef, DelphiSet AAssOpt) { > _AssignToTableDef(ATblDef, AAssOpt, true); > } > > public final void AssignToCreateTable(TRtCreateTable ACreateTbl, DelphiSet AAssOpt) { > TRtTableDef ATblDef; > int i; > String s = ""; > TRtModifyColumnItem SColItem; > TRtAddColumnItem DColItem; > TRtIndexItem SNdxItem; > TRtIndexItem DNdxItem; > TRtSingleIndexItem SUniqueItem; > TRtSingleIndexItem DUniqueItem; > TRtTriggerItem STriggerItem; > TRtTriggerItem DTriggerItem; > TRtForeignKeyItem SFkItem; > TRtForeignKeyItem DFkItem; > ATblDef = CheckGetDatabaseDef().TableByName(FTableName); > ACreateTbl.AssignFromTableDef(ATblDef, AAssOpt); > if (AAssOpt.contains(raaColumns)) { > for (i = 0; i <= FColumns.GetCount() - 1; ++i) { > SColItem = GetColumn().GetItem(i); > if (SColItem.GetIsRenamingCol()) { > s = SColItem.getOldColName(); > } else { > s = SColItem.getColName(); > } > if (SColItem.getOption() == rcaDrop) { > ACreateTbl.FColumns.RemoveByColumnName(s); > continue; > } > DColItem = ACreateTbl.FColumns.ItemByColumnName(s); > if (DColItem == null) { > ACreateTbl.FColumns.AddColumn(SColItem.FColName, SColItem.FColType, SColItem.FColLen, SColItem.FColPrec, SColItem.getNotNull()); > } else { > DColItem.Assign(SColItem); > DColItem.FOption = rcaAdd; > } > } > } > for (i = 0; i <= FIndexes.GetCount() - 1; ++i) { > SNdxItem = FIndexes.GetItem(i); > if (SNdxItem.getUnique()) { > if (!AAssOpt.contains(raaUniqueKeys)) { > continue; > } > } else if (!AAssOpt.contains(raaIndexes)) { > continue; > } > ACreateTbl.FIndexes.RemoveByName(SNdxItem.GetName()); > if (SNdxItem.getOption() == rcaDrop) { > continue; > } > DNdxItem = ACreateTbl.FIndexes.AddIndex(SNdxItem.GetName(), SNdxItem.getUnique()); > DNdxItem.Assign(SNdxItem); > DNdxItem.FOption = rcaAdd; > } > if (AAssOpt.contains(raaPrimaryKey)) { > s = ""; > if (FPrimaryKey.getOption() != rcaDrop) { > if (FPrimaryKey.getColumns().GetCount() > 0) { > ACreateTbl.FPrimaryKey.Assign(FPrimaryKey); > ACreateTbl.FPrimaryKey.FOption = rcaAdd; > } > } else { > ACreateTbl.FPrimaryKey.SetName(""); > ACreateTbl.FPrimaryKey.getColumns().Clear(); > } > } > if (AAssOpt.contains(raaUniqueConstraints)) { > for (i = 0; i <= FUniqueConstraints.GetCount() - 1; ++i) { > SUniqueItem = FUniqueConstraints.GetItem(i); > ACreateTbl.FUniqueConstraints.RemoveByName(SUniqueItem.GetName()); > if (SUniqueItem.getOption() == rcaDrop) { > continue; > } > DUniqueItem = ACreateTbl.FUniqueConstraints.AddUniqueConstraint(SUniqueItem.GetName()); > DUniqueItem.Assign(SUniqueItem); > DUniqueItem.FOption = rcaAdd; > } > } > if (AAssOpt.contains(raaTriggers)) { > for (i = 0; i <= FTriggers.GetCount() - 1; ++i) { > STriggerItem = FTriggers.GetItem(i); > ACreateTbl.FTriggers.RemoveByName(STriggerItem.GetName()); > if (STriggerItem.getOption() == rcaDrop) { > continue; > } > DTriggerItem = ACreateTbl.FTriggers.AddTrigger(STriggerItem.GetName(), "", STriggerItem.getForEachRow()); > DTriggerItem.Assign(STriggerItem); > DTriggerItem.FOption = rcaAdd; > } > } > if (AAssOpt.contains(raaForeignKeys)) { > for (i = 0; i <= FForeignKeys.GetCount() - 1; ++i) { > SFkItem = FForeignKeys.GetItem(i); > ACreateTbl.FForeignKeys.RemoveByName(SFkItem.GetName()); > if (SFkItem.getOption() == rcaDrop) { > continue; > } > DFkItem = ACreateTbl.FForeignKeys.AddForeignKey(SFkItem.GetName(), SFkItem.getReferenceTable()); > DFkItem.Assign(SFkItem); > DFkItem.FOption = rcaAdd; > } > } > } > > public final void AssignToCreateTable(TRtCreateTable ACreateTbl) { > AssignToCreateTable(ACreateTbl, DelphiSet.getRange(raaColumns, raaForeignKeys)); > } > > public final void FixRenameColumn(String OldColName, String NewColName) { > TRtModifyColumnItem OldCol; > TRtModifyColumnItem NewCol; > OldCol = GetColumn().ItemByColumnName(OldColName); > NewCol = GetColumn().ItemByColumnName(NewColName); > if (NewCol != null) { > if (OldCol != null) { > OldCol.Free(); > } > if (NewCol.getOption() != rcaModify) { > NewCol.SetOption(rcaModify); > NewCol.SetOldColName(OldColName); > } > } else { > if (OldCol != null) { > GetColumn().ModifyColumn(OldColName, NewColName, OldCol.FColType, OldCol.FColLen, OldCol.FColPrec, OldCol.FNotNull, OldCol.FNotNullChanged); > OldCol.Free(); > } else { > GetColumn().ModifyColumn(OldColName, NewColName, rftUnknown, 0, 0, false, false); > } > } > } > > public TContainerItem Creator(TPersistent AOwner, TContainerItemClass AType) { > return ClassType().Creator(AOwner, AType); > } > > public TRtAlterTableClass ClassType() { > return TRtAlterTableClass.SINGLETON; > } > > public void setKeepPKInOLDTable(boolean value) { > FKeepPKInOLDTable = value; > } > > public boolean getKeepPKInOLDTable() { > return FKeepPKInOLDTable; > } > > public void setLevelAlterTableMode(int value) { > FLevelAlterTableMode = value; > } > > public int getLevelAlterTableMode() { > return FLevelAlterTableMode; > } > > public void setUseNewOperationKind(boolean value) { > FUseNewOperationKind = value; > } > > public void setOnCommitMoveData(TNotifyEvent value) { > FOnCommitMoveData = value; > } > > public TNotifyEvent getOnCommitMoveData() { > return FOnCommitMoveData; > } > > public void setOnStoredProcMoveData(TRtOnStoredProcMoveData value) { > FOnStoredProcMoveData = value; > } > > public TRtOnStoredProcMoveData getOnStoredProcMoveData() { > return FOnStoredProcMoveData; > } > > public void setOnBeforeExecStoredProcMoveData(TRtOnExecStoredProcMoveData value) { > FOnBeforeExecStoredProcMoveData = value; > } > > public TRtOnExecStoredProcMoveData getOnBeforeExecStoredProcMoveData() { > return FOnBeforeExecStoredProcMoveData; > } > > public void setOnCustomAlterTableUpdateData(TRtOnCustomAlterTableUpdateData value) { > FOnCustomAlterTableUpdateData = value; > } > > public TRtOnCustomAlterTableUpdateData getOnCustomAlterTableUpdateData() { > return FOnCustomAlterTableUpdateData; > } > } > > public static class TRtCreateIndexClass extends TRtCustomDDLTableClass { > > public static final TRtCreateIndexClass SINGLETON = new TRtCreateIndexClass(); > > public TRtCreateIndex Create() { > return TRtCreateIndex.Create(); > } > > public final TRtCreateIndex CreateSQL(TRtDBConnection AConn, String ATableName, String AIndexName, boolean LUnique) { > return TRtCreateIndex.CreateSQL(AConn, ATableName, AIndexName, LUnique); > } > > public Class<? extends TRtCreateIndex> ClassInfo() { > return TRtCreateIndex.class; > } > } > > public static class TRtCreateIndex extends TRtCustomDDLTable { > > private String FIndexTableSpace; > private TRtIndexItem FIndex; > > public boolean GetHasOperation() { > return super.GetHasOperation() && !StrIsBlank(FIndex.GetName()) && FIndex.GetColumns().GetCount() > 0; > } > > public final void SetIndexTableSpace(String Value) { > CheckUnprepare(); > FIndexTableSpace = Value; > } > > protected void UpdatePhyDatabase() { > TRtDatabaseDef ADbDef; > TRtTableDef ATblDef; > TRtIndexDef ANdxDef; > int c; > ADbDef = GetDatabaseDef(); > if (ADbDef != null && !GetNotUpdatePhyDatabase()) { > ATblDef = ADbDef.TableByName(FTableName); > if (ATblDef != null) { > { > TRtIndexItem context_FIndex = FIndex; > ATblDef.DropIndexDef(context_FIndex.GetName()); > ANdxDef = ATblDef.NewIndexDef(context_FIndex.GetName(), ""); > try { > for (c = 0; c <= context_FIndex.GetColumns().GetCount() - 1; ++c) { > { > TRtIndexColumnItem context_GetItem = context_FIndex.GetColumns().GetItem(c); > ANdxDef.NewFieldDef(context_GetItem.getColName(), context_GetItem.getOrder() == risDesc); > } > } > } catch (Throwable any) { > ATblDef.DropIndexDef(context_FIndex.GetName()); > } > } > } > } > } > > public final String GetIndexTableSpace() { > String Result = ""; > if (StrIsBlank(FIndexTableSpace)) { > Result = TrimRight(GetOwnerConnection().GetIndexTableSpace()); > } else { > Result = TrimRight(FIndexTableSpace); > } > return Result; > } > > public String GetName() { > return FIndex.GetName(); > } > > public void runCreate() { > super.runCreate(); > FIndex = ((TRtIndexItem) Creator(this, TRtIndexItemClass.SINGLETON)); > } > > public static TRtCreateIndex Create() { > TRtCreateIndex Result; > Result = new TRtCreateIndex(); > Result.runCreate(); > return Result; > } > > public final void runCreateSQL(TRtDBConnection AConn, String ATableName, String AIndexName, boolean LUnique) { > super.runCreateSQL(AConn, ATableName); > FIndex = ((TRtIndexItem) Creator(this, TRtIndexItemClass.SINGLETON)); > FIndex.Init(null, AIndexName, LUnique); > } > > public static TRtCreateIndex CreateSQL(TRtDBConnection AConn, String ATableName, String AIndexName, boolean LUnique) { > TRtCreateIndex Result; > Result = new TRtCreateIndex(); > Result.runCreateSQL(AConn, ATableName, AIndexName, LUnique); > return Result; > } > > public void Destroy() { > FIndex.Free(); > super.Destroy(); > } > > public void ExecuteUpd() { > String ExceptMessage = ""; > try { > super.ExecuteUpd(); > } catch (DelphiException E) { > ExceptMessage = TransStrFmt("TC3298", "Não foi possível criar o índice para a tabela: %0:s - [%1:s] - \"%2:s\"", new Object[] { GetTableName(), StrReplaceStr(FSql, SQLEOC_SEP, EOL), E.getMessage() }, true); > E.setMessage(ExceptMessage); > throw wrap(E); > } > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtCreateIndex) { > FIndex.Assign(((TRtCreateIndex) Source).FIndex); > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > FIndex.ReadData(Reader); > FIndexTableSpace = Reader.ReadString(); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > FIndex.WriteData(Writer); > Writer.WriteString(FIndexTableSpace); > } > > public TRtCreateIndexClass ClassType() { > return TRtCreateIndexClass.SINGLETON; > } > > public TRtIndexItem getIndex() { > return FIndex; > } > } > > public static class TRtDropIndexClass extends TRtCustomDDLTableClass { > > public static final TRtDropIndexClass SINGLETON = new TRtDropIndexClass(); > > public final TRtDropIndex CreateSQL(TRtDBConnection AConn, String ATableName, String AIndexName) { > return TRtDropIndex.CreateSQL(AConn, ATableName, AIndexName); > } > > public Class<? extends TRtDropIndex> ClassInfo() { > return TRtDropIndex.class; > } > } > > public static class TRtDropIndex extends TRtCustomDDLTable { > > private String FIndexName; > > public boolean GetHasOperation() { > return super.GetHasOperation() && !StrIsBlank(getIndexName()); > } > > public final void SetIndexName(String Value) { > CheckUnprepare(); > FIndexName = Value; > } > > protected void UpdatePhyDatabase() { > TRtTableDef ATblDef; > if (!GetNotUpdatePhyDatabase()) { > ATblDef = CheckGetDatabaseDef().TableByName(FTableName); > if (ATblDef != null) { > ATblDef.DropIndexDef(FIndexName); > } > } > } > > public String GetName() { > return FIndexName; > } > > public final void runCreateSQL(TRtDBConnection AConn, String ATableName, String AIndexName) { > super.runCreateSQL(AConn, ATableName); > FIndexName = AIndexName; > } > > public static TRtDropIndex CreateSQL(TRtDBConnection AConn, String ATableName, String AIndexName) { > TRtDropIndex Result; > Result = new TRtDropIndex(); > Result.runCreateSQL(AConn, ATableName, AIndexName); > return Result; > } > > public void ExecuteUpd() { > String ExceptMessage = ""; > try { > super.ExecuteUpd(); > } catch (DelphiException E) { > ExceptMessage = TransStrFmt("TC3299", "Não foi possível excluir o índice %0:s da tabela: %1:s - [%2:s] - \"%3:s\"", new Object[] { getIndexName(), GetTableName(), StrReplaceStr(FSql, SQLEOC_SEP, EOL), E.getMessage() }, true); > E.setMessage(ExceptMessage); > throw wrap(E); > } > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtDropIndex) { > FIndexName = ((TRtDropIndex) Source).FIndexName; > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > FIndexName = Reader.ReadString(); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.WriteString(FIndexName); > } > > public TRtDropIndexClass ClassType() { > return TRtDropIndexClass.SINGLETON; > } > > public String getIndexName() { > return FIndexName; > } > } > > public static class TRtCreateTriggerClass extends TRtCustomDDLTableClass { > > public static final TRtCreateTriggerClass SINGLETON = new TRtCreateTriggerClass(); > > public TRtCreateTrigger Create() { > return TRtCreateTrigger.Create(); > } > > public final TRtCreateTrigger CreateSQL(TRtDBConnection AConn, String ACode) { > return TRtCreateTrigger.CreateSQL(AConn, ACode); > } > > public Class<? extends TRtCreateTrigger> ClassInfo() { > return TRtCreateTrigger.class; > } > } > > public static class TRtCreateTrigger extends TRtCustomDDLTable { > > private TRtTriggerItem FTrigger; > > public boolean GetHasOperation() { > return !StrIsBlank(FTrigger.getCode()); > } > > protected void UpdatePhyDatabase() { > TRtDatabaseDef ADbDef; > TRtTableDef ATblDef; > ADbDef = GetDatabaseDef(); > if (ADbDef != null && !GetNotUpdatePhyDatabase()) { > ATblDef = ADbDef.TableByName(FTableName); > if (ATblDef != null) { > ATblDef.DropTriggerDef(FTrigger.GetName()); > ATblDef.NewTriggerDef(FTrigger.getCode()); > } > } > } > > public String GetName() { > return FTrigger.GetName(); > } > > protected void InternalPrepareUpdate() { > if (!GetPrepared()) { > CheckConnected(); > FUpdate.SetCommand(FSql); > FUpdate.Prepare(); > } > } > > public void runCreate() { > super.runCreate(); > FTrigger = ((TRtTriggerItem) Creator(this, TRtTriggerItemClass.SINGLETON)); > } > > public static TRtCreateTrigger Create() { > TRtCreateTrigger Result; > Result = new TRtCreateTrigger(); > Result.runCreate(); > return Result; > } > > public final void runCreateSQL(TRtDBConnection AConn, String ACode) { > super.runCreateSQL(AConn, ""); > FTrigger = ((TRtTriggerItem) Creator(this, TRtTriggerItemClass.SINGLETON)); > FTrigger.SetCode(ACode); > } > > public static TRtCreateTrigger CreateSQL(TRtDBConnection AConn, String ACode) { > TRtCreateTrigger Result; > Result = new TRtCreateTrigger(); > Result.runCreateSQL(AConn, ACode); > return Result; > } > > public void Destroy() { > FTrigger.Free(); > super.Destroy(); > } > > public void ExecuteUpd() { > String ExceptMessage = ""; > try { > super.ExecuteUpd(); > } catch (DelphiException E) { > ExceptMessage = TransStrFmt("TC3300", "Não foi possível criar a trigger para a tabela: %0:s - [Trigger: %1:s] - \"%2:s\"", new Object[] { GetTableName(), GetName(), E.getMessage() }, true); > E.setMessage(ExceptMessage); > throw wrap(E); > } > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtCreateTrigger) { > FTrigger.Assign(((TRtCreateTrigger) Source).FTrigger); > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > FTrigger.ReadData(Reader); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > FAssigning++; > try { > super.WriteData(Writer); > FTrigger.WriteData(Writer); > } finally { > FAssigning--; > } > } > > public TRtCreateTriggerClass ClassType() { > return TRtCreateTriggerClass.SINGLETON; > } > > public TRtTriggerItem getTrigger() { > return FTrigger; > } > } > > public static class TRtDropTriggerClass extends TRtCustomDDLTableClass { > > public static final TRtDropTriggerClass SINGLETON = new TRtDropTriggerClass(); > > public final TRtDropTrigger CreateSQL(TRtDBConnection AConn, String ATableName, String ATriggerName) { > return TRtDropTrigger.CreateSQL(AConn, ATableName, ATriggerName); > } > > public Class<? extends TRtDropTrigger> ClassInfo() { > return TRtDropTrigger.class; > } > } > > public static class TRtDropTrigger extends TRtCustomDDLTable { > > private String FTriggerName; > > public boolean GetHasOperation() { > return super.GetHasOperation() && !StrIsBlank(GetName()); > } > > public final void SetTriggerName(String Value) { > CheckUnprepare(); > FTriggerName = Value; > } > > protected void UpdatePhyDatabase() { > TRtTableDef ATblDef; > if (!GetNotUpdatePhyDatabase()) { > ATblDef = CheckGetDatabaseDef().TableByName(FTableName); > if (ATblDef != null) { > ATblDef.DropTriggerDef(FTriggerName); > } > } > } > > public String GetName() { > return FTriggerName; > } > > public final void runCreateSQL(TRtDBConnection AConn, String ATableName, String ATriggerName) { > super.runCreateSQL(AConn, ATableName); > FTriggerName = ATriggerName; > } > > public static TRtDropTrigger CreateSQL(TRtDBConnection AConn, String ATableName, String ATriggerName) { > TRtDropTrigger Result; > Result = new TRtDropTrigger(); > Result.runCreateSQL(AConn, ATableName, ATriggerName); > return Result; > } > > public void ExecuteUpd() { > String ExceptMessage = ""; > try { > super.ExecuteUpd(); > } catch (DelphiException E) { > ExceptMessage = TransStrFmt("TC3301", "Não foi possível excluir a trigger %0:s da tabela: %1:s - [%2:s] - \"%3:s\"", new Object[] { GetName(), GetTableName(), StrReplaceStr(FSql, SQLEOC_SEP, EOL), E.getMessage() }, true); > E.setMessage(ExceptMessage); > throw wrap(E); > } > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtDropTrigger) { > FTriggerName = ((TRtDropTrigger) Source).FTriggerName; > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > FTriggerName = Reader.ReadString(); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.WriteString(FTriggerName); > } > > public TRtDropTriggerClass ClassType() { > return TRtDropTriggerClass.SINGLETON; > } > } > > public static class TRtCreateProcedureClass extends TRtCustomDDLClass { > > public static final TRtCreateProcedureClass SINGLETON = new TRtCreateProcedureClass(); > > public final TRtCreateProcedure CreateSQL(TRtDBConnection AConn, String ACode) { > return TRtCreateProcedure.CreateSQL(AConn, ACode); > } > > public Class<? extends TRtCreateProcedure> ClassInfo() { > return TRtCreateProcedure.class; > } > } > > public static class TRtCreateProcedure extends TRtCustomDDL { > > private String FProcedureName; > private TRtCCompiledNodeList FCompiledCode; > > public final String GetCode() { > String Result = ""; > if (!FSpecificCode) { > Result = FCode; > } else { > Result = ""; > } > return Result; > } > > public final void SetCode(String Value) { > TString AName = new TString(); > TString Dummy = new TString(); > TRtCCompiledNodeList ACCode; > CheckUnprepare(); > if (StrIsBlank(Value)) { > if (FCompiledCode != null) { > FCompiledCode.Free(); > } > FCompiledCode = null; > FProcedureName = ""; > } else if (FSpecificCode || CompareText(Value, FCode) != 0 || FCompiledCode == null) { > ACCode = StoredProcedureCreatorFunc(Value, AName, Dummy); > FProcedureName = AName.v; > if (FCompiledCode != null) { > FCompiledCode.Free(); > } > FCompiledCode = ACCode; > } > FCode = Value; > FSpecificCode = false; > } > > protected boolean FSpecificCode; > protected String FCode; > > protected void UpdatePhyDatabase() { > TRtDatabaseDef ADbDef; > ADbDef = GetDatabaseDef(); > if (ADbDef != null && !GetNotUpdatePhyDatabase()) { > ADbDef.DropStoredProcDef(FProcedureName); > ADbDef.NewStoredProcDef(FCode); > } > } > > public String GetName() { > return FProcedureName; > } > > protected void InternalPrepareUpdate() { > if (!GetPrepared()) { > CheckConnected(); > FUpdate.SetCommand(FSql); > FUpdate.Prepare(); > } > } > > public final void runCreateSQL(TRtDBConnection AConn, String ACode) { > super.runCreateSQL(AConn); > SetCode(ACode); > } > > public static TRtCreateProcedure CreateSQL(TRtDBConnection AConn, String ACode) { > TRtCreateProcedure Result; > Result = new TRtCreateProcedure(); > Result.runCreateSQL(AConn, ACode); > return Result; > } > > public void Destroy() { > if (FCompiledCode != null) { > FCompiledCode.Free(); > FCompiledCode = null; > } > super.Destroy(); > } > > public void ExecuteUpd() { > String ExceptMessage = ""; > try { > super.ExecuteUpd(); > } catch (DelphiException E) { > ExceptMessage = TransStrFmt("TC3302", "Não foi possível criar a procedure %0:s - \"%1:s\"", new Object[] { FProcedureName, E.getMessage() }, true); > E.setMessage(ExceptMessage); > throw wrap(E); > } > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtCreateProcedure) { > FCode = ((TRtCreateProcedure) Source).FCode; > FProcedureName = ((TRtCreateProcedure) Source).FProcedureName; > if (((TRtCreateProcedure) Source).FCompiledCode != null) { > if (FCompiledCode == null) { > FCompiledCode = TRtCCompiledNodeList.Create(); > } > FCompiledCode.Assign(((TRtCreateProcedure) Source).FCompiledCode); > } else if (FCompiledCode != null) { > FCompiledCode.Free(); > FCompiledCode = null; > } > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > boolean LHasCompiledCode; > FAssigning++; > try { > super.ReadData(Reader); > FCode = Reader.ReadString(); > FProcedureName = Reader.ReadString(); > LHasCompiledCode = Reader.ReadBoolean(); > if (LHasCompiledCode) { > if (FCompiledCode == null) { > FCompiledCode = TRtCCompiledNodeList.Create(); > } > FCompiledCode.ReadData(Reader); > } else if (FCompiledCode != null) { > FCompiledCode.Free(); > FCompiledCode = null; > } > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > boolean LHasCompiledCode; > FAssigning++; > try { > super.WriteData(Writer); > Writer.WriteString(FCode); > Writer.WriteString(FProcedureName); > LHasCompiledCode = FCompiledCode != null; > Writer.WriteBoolean(LHasCompiledCode); > if (LHasCompiledCode) { > FCompiledCode.WriteData(Writer); > } > } finally { > FAssigning--; > } > } > > public boolean GetHasOperation() { > return !StrIsBlank(FCode); > } > > public final void AssignFromStoredProcDef(TRtStoredProcDef ASPDef) { > AssignFromStoredProcItem(ASPDef.GetSpecificCodes(GetDBNameSpecificSPByDBVersionKind(GetOwnerConnection().FDBVersionKind), ASPDef.GetDatabase().getCustomerCode())); > } > > public final void AssignFromStoredProcItem(TRtStoredProcItem ASPItem) { > CheckUnprepare(); > if (FCompiledCode != null) { > FCompiledCode.Free(); > } > FCompiledCode = null; > FCode = ASPItem.getCode(); > FProcedureName = ASPItem.GetOwnerStoredProcDef().GetName(); > FSpecificCode = !ASPItem.GetDatabaseName().equals(cdbspSenior); > } > > public final void CheckCompiledCode() { > if (FCompiledCode == null && !FSpecificCode) { > SetCode(FCode); > } > } > > public final String GetSpecificCode() { > String Result = ""; > if (FSpecificCode) { > Result = FCode; > } else { > Result = ""; > } > return Result; > } > > public final void SetSpecificCode(String AProcName, String AProcCode) { > CheckUnprepare(); > if (FCompiledCode != null) { > FCompiledCode.Free(); > } > FCompiledCode = null; > FProcedureName = AProcName; > FCode = AProcCode; > FSpecificCode = true; > } > > public TRtCreateProcedureClass ClassType() { > return TRtCreateProcedureClass.SINGLETON; > } > > public TRtCCompiledNodeList getCompiledCode() { > return FCompiledCode; > } > } > > public static class TRtDropProcedureClass extends TRtCustomDDLClass { > > public static final TRtDropProcedureClass SINGLETON = new TRtDropProcedureClass(); > > public final TRtDropProcedure CreateSQL(TRtDBConnection AConn, String AProcedureName) { > return TRtDropProcedure.CreateSQL(AConn, AProcedureName); > } > > public Class<? extends TRtDropProcedure> ClassInfo() { > return TRtDropProcedure.class; > } > } > > public static class TRtDropProcedure extends TRtCustomDDL { > > private String FProcedureName; > > public boolean GetHasOperation() { > return !StrIsBlank(FProcedureName); > } > > public final void SetProcedureName(String Value) { > CheckUnprepare(); > FProcedureName = Value; > } > > protected void UpdatePhyDatabase() { > TRtDatabaseDef ADbDef; > ADbDef = GetDatabaseDef(); > if (ADbDef != null && !GetNotUpdatePhyDatabase()) { > ADbDef.DropStoredProcDef(FProcedureName); > } > } > > public String GetName() { > return FProcedureName; > } > > public final void runCreateSQL(TRtDBConnection AConn, String AProcedureName) { > super.runCreateSQL(AConn); > FProcedureName = AProcedureName; > } > > public static TRtDropProcedure CreateSQL(TRtDBConnection AConn, String AProcedureName) { > TRtDropProcedure Result; > Result = new TRtDropProcedure(); > Result.runCreateSQL(AConn, AProcedureName); > return Result; > } > > public void ExecuteUpd() { > String ExceptMessage = ""; > try { > super.ExecuteUpd(); > } catch (DelphiException E) { > ExceptMessage = TransStrFmt("TC3303", "Não foi possível excluir a procedure %0:s - [%1:s] - \"%2:s\"", new Object[] { FProcedureName, StrReplaceStr(FSql, SQLEOC_SEP, EOL), E.getMessage() }, true); > E.setMessage(ExceptMessage); > throw wrap(E); > } > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtDropProcedure) { > FProcedureName = ((TRtDropProcedure) Source).FProcedureName; > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > FProcedureName = Reader.ReadString(); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.WriteString(FProcedureName); > } > > public TRtDropProcedureClass ClassType() { > return TRtDropProcedureClass.SINGLETON; > } > } > > public static final class TRtCreateViewClass extends TRtCustomDDLClass { > > public static final TRtCreateViewClass SINGLETON = new TRtCreateViewClass(); > > public final TRtCreateView CreateSQL(TRtDBConnection AConn, String AViewName) { > return TRtCreateView.CreateSQL(AConn, AViewName); > } > > public Class<? extends TRtCreateView> ClassInfo() { > return TRtCreateView.class; > } > } > > public static final class TRtCreateView extends TRtCustomDDL { > > protected String FViewName; > protected TRtSelect FSelect_SeniorSQL_1; > protected TSQLStatement FSelect_SeniorSQL_2; > protected String FSelect_NativeSQL; > > protected void UpdatePhyDatabase() { > TRtDatabaseDef ADbDef; > ADbDef = GetDatabaseDef(); > if (ADbDef != null && !GetNotUpdatePhyDatabase()) { > ADbDef.DropViewDef(FViewName); > if (FSelect_SeniorSQL_1 != null) { > ADbDef.NewViewDef(GetOwnerConnection(), FViewName, FSelect_SeniorSQL_1.GenBaseSQL(), skSenior1); > } else if (FSelect_SeniorSQL_2 != null) { > ADbDef.NewViewDef(GetOwnerConnection(), FViewName, TRtSeniorSqlGeneratorClass.SINGLETON.GenerateStatement(FSelect_SeniorSQL_2.getStatement()), skSenior2); > } else { > ADbDef.NewViewDef(GetOwnerConnection(), FViewName, FSelect_NativeSQL, skNative); > } > } > } > > public String GetName() { > return FViewName; > } > > public final void SetSelect_SeniorSQL_1(TRtSelect Value) { > CheckUnprepare(); > FreeAndNil(AsVar(FSelect_SeniorSQL_2)); > if (FSelect_SeniorSQL_1 == null) { > if (Value != null) { > FSelect_SeniorSQL_1 = ((TRtSelect) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckSelect, getDBVersionKind())); > FSelect_SeniorSQL_1.SetFOwner(this); > } > } > if (Value == null) { > FreeAndNil(AsVar(FSelect_SeniorSQL_1)); > } else { > FSelect_SeniorSQL_1.Assign(Value); > FSelectParams.Assign(Value.GetSelectParams()); > FParams.Assign(Value.GetParams()); > } > } > > public final void SetSelect_SeniorSQL_2(TSQLStatement aValue) { > FreeAndNil(AsVar(FSelect_SeniorSQL_1)); > FreeAndNil(AsVar(FSelect_SeniorSQL_2)); > FSelect_SeniorSQL_2 = aValue; > } > > protected String GenAliasList() { > String Result = ""; > TSelectColumn xPColumn = null; > int i; > Result = ""; > if (FSelect_SeniorSQL_1 != null) { > if (FSelect_SeniorSQL_1.FColumns.GetCount() > 0) { > Result = FSelect_SeniorSQL_1.FColumns.GetItem(0).CalculatedAsName(); > for (i = 1; i <= FSelect_SeniorSQL_1.FColumns.GetCount() - 1; ++i) { > Result = Result + SQL_Comma + FSelect_SeniorSQL_1.FColumns.GetItem(i).CalculatedAsName(); > } > } > } else { > xPColumn = FSelect_SeniorSQL_2.getStatement().Select.FirstSelect.FirstColumn; > while (xPColumn != null) { > Result = Result + xPColumn.Alias + ToStr(SQL_Comma); > xPColumn = xPColumn.Next; > } > Result = Delete(Result, Length(Result), 1); > } > return Result; > } > > protected String GenViewDef() { > return SQL_Create + SQL_Space + SQL_View + SQL_Space + FViewName + SQL_Space + SQL_LParenthesis + GenAliasList() + SQL_RParenthesis + SQL_Space + SQL_As + SQL_EOL; > } > > protected String GenNativeCreateViewCmd() { > return SQL_Create + SQL_Space + SQL_View + SQL_Space + FViewName + SQL_Space + SQL_As + SQL_Space + FSelect_NativeSQL; > } > > protected String GenSQL() { > String Result = ""; > if (FSelect_SeniorSQL_1 == null && FSelect_SeniorSQL_2 == null && Trim(FSelect_NativeSQL).equals("")) { > throw DelphiException.Create(TransStr("TC666", "Seleção para view não definida.", true)); > } > if (FSelect_SeniorSQL_1 != null) { > Result = GenViewDef(); > if (!getUsesScriptTerminator()) { > Result = Result + FSelect_SeniorSQL_1.GetSQL(); > } else { > Result = Result + FSelect_SeniorSQL_1.GenSQLScript(); > } > } else if (FSelect_SeniorSQL_2 != null) { > Result = Result + GetOwnerConnection().SeniorSqlToNativeSql(FSelect_SeniorSQL_2.getStatement()); > if (getUsesScriptTerminator()) { > Result = StrBreakLine(Result, "", 250, 0, kblNone); > } > } else { > Result = Result + GenNativeCreateViewCmd(); > } > return Result; > } > > protected void InternalPrepareUpdate() { > if (!GetPrepared()) { > CheckConnected(); > FUpdate.SetCommand(FSql); > FUpdate.Prepare(); > } > } > > public final void runCreateSQL(TRtDBConnection AConn, String AViewName) { > super.runCreateSQL(AConn); > FViewName = AViewName; > } > > public static TRtCreateView CreateSQL(TRtDBConnection AConn, String AViewName) { > TRtCreateView Result; > Result = new TRtCreateView(); > Result.runCreateSQL(AConn, AViewName); > return Result; > } > > public void ExecuteUpd() { > String ExceptMessage = ""; > try { > super.ExecuteUpd(); > } catch (DelphiException E) { > ExceptMessage = TransStrFmt("TC3304", "Não foi possível criar a view %0:s - [%1:s] - \"%2:s\"", new Object[] { FViewName, StrReplaceStr(FSql, SQLEOC_SEP, EOL), E.getMessage() }, true); > E.setMessage(ExceptMessage); > throw wrap(E); > } > } > > public void Destroy() { > FreeAndNil(AsVar(FSelect_SeniorSQL_1)); > FreeAndNil(AsVar(FSelect_SeniorSQL_2)); > super.Destroy(); > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtCreateView) { > FViewName = ((TRtCreateView) Source).FViewName; > SetSelect_SeniorSQL_1(((TRtCreateView) Source).FSelect_SeniorSQL_1); > SetSelect_SeniorSQL_2(null); > if (((TRtCreateView) Source).FSelect_SeniorSQL_2 != null) { > throw DelphiException.Create(TransStr("TC667", "<TRtCreateView.Assign> não implementado para SeniorSQL_2", true)); > } > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > FViewName = Reader.ReadString(); > if (Reader.ReadBoolean()) { > if (FSelect_SeniorSQL_1 == null) { > FSelect_SeniorSQL_1 = ((TRtSelect) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckSelect, getDBVersionKind())); > FSelect_SeniorSQL_1.SetFOwner(this); > } > FSelect_SeniorSQL_1.ReadData(Reader); > } else if (FSelect_SeniorSQL_1 != null) { > FSelect_SeniorSQL_1.Free(); > FSelect_SeniorSQL_1 = null; > } > } > > public void WriteData(TWriter Writer) { > boolean HasSelect; > super.WriteData(Writer); > Writer.WriteString(FViewName); > HasSelect = FSelect_SeniorSQL_1 != null; > Writer.WriteBoolean(HasSelect); > if (HasSelect) { > FSelect_SeniorSQL_1.WriteData(Writer); > } > } > > public boolean GetHasOperation() { > return !StrIsBlank(FViewName) && FSelect_SeniorSQL_1 != null && FSelect_SeniorSQL_1.GetHasOperation(); > } > > public final void AssignFromViewDef(TRtViewDef AViewDef) { > TRtSelect ASel; > setViewName(AViewDef.GetName()); > switch (AViewDef.getSQLKind()) { > case skSenior2: > SetSelect_SeniorSQL_2(CompileViewSelect(AViewDef.GetDatabase(), AViewDef.GetName(), AViewDef.getSelectSQL())); > break; > case skSenior1: > ASel = ((TRtSelect) GetOwnerConnection().SQLObjectFrom(AViewDef.getSelectSQL())); > try { > SetSelect_SeniorSQL_1(ASel); > } finally { > ASel.Free(); > } > break; > case skNative: > FSelect_NativeSQL = AViewDef.getSelectSQL(); > break; > default: > break; > } > } > > public TRtCreateViewClass ClassType() { > return TRtCreateViewClass.SINGLETON; > } > > public void setViewName(String value) { > FViewName = value; > } > > public String getViewName() { > return FViewName; > } > > public TRtSelect getSelect_SeniorSQL_1() { > return FSelect_SeniorSQL_1; > } > > public TSQLStatement getSelect_SeniorSQL_2() { > return FSelect_SeniorSQL_2; > } > > public void setSelect_NativeSQL(String value) { > FSelect_NativeSQL = value; > } > > public String getSelect_NativeSQL() { > return FSelect_NativeSQL; > } > } > > public static class TRtDropViewClass extends TRtCustomDDLClass { > > public static final TRtDropViewClass SINGLETON = new TRtDropViewClass(); > > public final TRtDropView CreateSQL(TRtDBConnection AConn, String AViewName) { > return TRtDropView.CreateSQL(AConn, AViewName); > } > > public Class<? extends TRtDropView> ClassInfo() { > return TRtDropView.class; > } > } > > public static class TRtDropView extends TRtCustomDDL { > > private String FViewName; > > protected void UpdatePhyDatabase() { > TRtDatabaseDef ADbDef; > ADbDef = GetDatabaseDef(); > if (ADbDef != null && !GetNotUpdatePhyDatabase()) { > ADbDef.DropViewDef(FViewName); > } > } > > public String GetName() { > return FViewName; > } > > protected String GenSQL() { > return SQL_Drop + SQL_Space + SQL_View + SQL_Space + GetViewName(); > } > > public String GetViewName() { > return FViewName; > } > > public final void runCreateSQL(TRtDBConnection AConn, String AViewName) { > super.runCreateSQL(AConn); > FViewName = AViewName; > } > > public static TRtDropView CreateSQL(TRtDBConnection AConn, String AViewName) { > TRtDropView Result; > Result = new TRtDropView(); > Result.runCreateSQL(AConn, AViewName); > return Result; > } > > public void ExecuteUpd() { > String ExceptMessage = ""; > try { > super.ExecuteUpd(); > } catch (DelphiException E) { > ExceptMessage = TransStrFmt("TC3305", "Não foi possível excluir a view %0:s - [%1:s] - \"%2:s\"", new Object[] { FViewName, StrReplaceStr(FSql, SQLEOC_SEP, EOL), E.getMessage() }, true); > E.setMessage(ExceptMessage); > throw wrap(E); > } > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtDropView) { > FViewName = ((TRtDropView) Source).FViewName; > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > FViewName = Reader.ReadString(); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.WriteString(FViewName); > } > > public boolean GetHasOperation() { > return !StrIsBlank(FViewName); > } > > public TRtDropViewClass ClassType() { > return TRtDropViewClass.SINGLETON; > } > > public void setViewName(String value) { > FViewName = value; > } > } > > public static class TRtDropTableClass extends TRtCustomDDLTableClass { > > public static final TRtDropTableClass SINGLETON = new TRtDropTableClass(); > > public TRtDropTable Create() { > return TRtDropTable.Create(); > } > > public final TRtDropTable CreateSQL(TRtDBConnection AConn, String ATableName, int ARIntOpt) { > return TRtDropTable.CreateSQL(AConn, ATableName, ARIntOpt); > } > > public Class<? extends TRtDropTable> ClassInfo() { > return TRtDropTable.class; > } > } > > public static class TRtDropTable extends TRtCustomDDLTable { > > private int FRIntOpt; > > public final void SetRIntOpt(int Value) { > CheckUnprepare(); > FRIntOpt = Value; > } > > protected void UpdatePhyDatabase() { > if (!GetNotUpdatePhyDatabase()) { > CheckGetDatabaseDef().DropTableDef(FTableName); > } > } > > public void runCreate() { > super.runCreate(); > } > > public static TRtDropTable Create() { > TRtDropTable Result; > Result = new TRtDropTable(); > Result.runCreate(); > return Result; > } > > public final void runCreateSQL(TRtDBConnection AConn, String ATableName, int ARIntOpt) { > super.runCreateSQL(AConn, ATableName); > FRIntOpt = ARIntOpt; > } > > public static TRtDropTable CreateSQL(TRtDBConnection AConn, String ATableName, int ARIntOpt) { > TRtDropTable Result; > Result = new TRtDropTable(); > Result.runCreateSQL(AConn, ATableName, ARIntOpt); > return Result; > } > > public void ExecuteUpd() { > String ExceptMessage = ""; > try { > super.ExecuteUpd(); > } catch (DelphiException E) { > ExceptMessage = TransStrFmt("TC3306", "Não foi possível apagar a tabela: %0:s - [%1:s] - \"%2:s\"", new Object[] { GetTableName(), StrReplaceStr(FSql, SQLEOC_SEP, EOL), E.getMessage() }, true); > E.setMessage(ExceptMessage); > throw wrap(E); > } > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtDropTable) { > FRIntOpt = ((TRtDropTable) Source).FRIntOpt; > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > Reader.Read(AsVar(FRIntOpt), SizeOf(FRIntOpt)); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.Write(AsConst(FRIntOpt), SizeOf(FRIntOpt)); > } > > public TRtDropTableClass ClassType() { > return TRtDropTableClass.SINGLETON; > } > > public int getRIntOpt() { > return FRIntOpt; > } > } > > public static class TRtRenameTableClass extends TRtCustomDDLTableClass { > > public static final TRtRenameTableClass SINGLETON = new TRtRenameTableClass(); > > public TRtRenameTable Create() { > return TRtRenameTable.Create(); > } > > public final TRtRenameTable CreateSQL(TRtDBConnection AConn, String AOldTblName, String ANewTblNAme) { > return TRtRenameTable.CreateSQL(AConn, AOldTblName, ANewTblNAme); > } > > public Class<? extends TRtRenameTable> ClassInfo() { > return TRtRenameTable.class; > } > } > > public static class TRtRenameTable extends TRtCustomDDLTable { > > private String FNewTableName; > > public final void SetNewTableName(String Value) { > CheckUnprepare(); > FNewTableName = Value; > } > > public boolean GetHasOperation() { > return super.GetHasOperation() && !StrIsBlank(GetNewTableName()); > } > > protected void UpdatePhyDatabase() { > TRtTableDef ATblDef; > if (!GetNotUpdatePhyDatabase()) { > ATblDef = CheckGetDatabaseDef().TableByName(FTableName); > if (ATblDef != null) { > ATblDef.SetName(FNewTableName); > } > } > } > > public String GetNewTableName() { > return FNewTableName; > } > > public void runCreate() { > super.runCreate(); > } > > public static TRtRenameTable Create() { > TRtRenameTable Result; > Result = new TRtRenameTable(); > Result.runCreate(); > return Result; > } > > public final void runCreateSQL(TRtDBConnection AConn, String AOldTblName, String ANewTblNAme) { > super.runCreateSQL(AConn, AOldTblName); > FNewTableName = ANewTblNAme; > } > > public static TRtRenameTable CreateSQL(TRtDBConnection AConn, String AOldTblName, String ANewTblNAme) { > TRtRenameTable Result; > Result = new TRtRenameTable(); > Result.runCreateSQL(AConn, AOldTblName, ANewTblNAme); > return Result; > } > > public void ExecuteUpd() { > String ExceptMessage = ""; > try { > super.ExecuteUpd(); > } catch (DelphiException E) { > ExceptMessage = TransStrFmt("TC3307", "Não foi possível renomear a tabela: %0:s - [%1:s] - \"%2:s\"", new Object[] { GetTableName(), StrReplaceStr(FSql, SQLEOC_SEP, EOL), E.getMessage() }, true); > E.setMessage(ExceptMessage); > throw wrap(E); > } > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtRenameTable) { > FNewTableName = ((TRtRenameTable) Source).FNewTableName; > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > FNewTableName = Reader.ReadString(); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.WriteString(FNewTableName); > } > > public TRtRenameTableClass ClassType() { > return TRtRenameTableClass.SINGLETON; > } > } > > public static final class TRtSQLFunctionTableItemClass extends TNamedContainerItemClass { > > public static final TRtSQLFunctionTableItemClass SINGLETON = new TRtSQLFunctionTableItemClass(); > > public TRtSQLFunctionTableItem Create() { > return TRtSQLFunctionTableItem.Create(); > } > > public Class<? extends TRtSQLFunctionTableItem> ClassInfo() { > return TRtSQLFunctionTableItem.class; > } > } > > public static final class TRtSQLFunctionTableItem extends TNamedContainerItem { > > private TList FList; > > public final int GetCount() { > return FList.getCount(); > } > > public final int GetTypes(int Index) { > return (int) (GetIntegers(Index) & ~RT_OPTIONAL_PARAM); > } > > public final void SetTypes(int Index, int Value) { > FList.Put(Index, (Object) (int) Value); > } > > public final int GetIntegers(int Index) { > return ((Number) FList.Get(Index)).intValue(); > } > > public final void SetIntegers(int Index, int Value) { > FList.Put(Index, (Object) Value); > } > > public final boolean GetOptionals(int Index) { > return (GetIntegers(Index) | RT_OPTIONAL_PARAM) != 0; > } > > public void runCreate() { > super.runCreate(); > FList = TList.Create(); > } > > public static TRtSQLFunctionTableItem Create() { > TRtSQLFunctionTableItem Result; > Result = new TRtSQLFunctionTableItem(); > Result.runCreate(); > return Result; > } > > public void Destroy() { > FList.Free(); > super.Destroy(); > } > > public void Assign(TPersistent Source) { > int i; > super.Assign(Source); > if (Source instanceof TRtSQLFunctionTableItem) { > FList.Clear(); > for (i = 0; i <= ((TRtSQLFunctionTableItem) Source).FList.getCount() - 1; ++i) { > FList.Add(((TRtSQLFunctionTableItem) Source).FList.Get(i)); > } > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > { > TReader context_Reader = Reader; > FList.Clear(); > context_Reader.ReadListBegin(); > while (!context_Reader.EndOfList()) { > FList.Add(((Object) context_Reader.ReadInteger())); > } > context_Reader.ReadListEnd(); > } > } > > public void WriteData(TWriter Writer) { > int i; > super.WriteData(Writer); > { > TWriter context_Writer = Writer; > FList.Clear(); > context_Writer.WriteListBegin(); > for (i = 0; i <= FList.getCount() - 1; ++i) { > context_Writer.WriteInteger(((Number) FList.Get(i)).intValue()); > } > context_Writer.WriteListEnd(); > } > } > > public final int AddType(int Value) { > return AddInteger((int) Value); > } > > public final void AddTypes(int[] AValues) { > int i; > for (i = 0; i <= AValues.length - 1; ++i) { > AddType(AValues[i]); > } > } > > public final int AddInteger(int Value) { > return FList.Add((Object) Value); > } > > public final void AddIntegers(int[] AValues) { > int i; > for (i = 0; i <= AValues.length - 1; ++i) { > AddInteger(AValues[i]); > } > } > > public final void Delete(int Index) { > FList.Delete(Index); > } > > public final void Clear() { > FList.Clear(); > } > > public TRtSQLFunctionTableItemClass ClassType() { > return TRtSQLFunctionTableItemClass.SINGLETON; > } > } > > public static final class TRtSQLFunctionTableListClass extends TNamedListOwnerClass { > > public static final TRtSQLFunctionTableListClass SINGLETON = new TRtSQLFunctionTableListClass(); > > public TRtSQLFunctionTableList Create() { > return TRtSQLFunctionTableList.Create(); > } > > public Class<? extends TRtSQLFunctionTableList> ClassInfo() { > return TRtSQLFunctionTableList.class; > } > } > > public static final class TRtSQLFunctionTableList extends TNamedListOwner { > > protected TContainerItemClass AllocItemType() { > return TRtSQLFunctionTableItemClass.SINGLETON; > } > > public final TRtSQLFunctionTableItem GetItem(int Index) { > return ((TRtSQLFunctionTableItem) Get(Index)); > } > > public static TRtSQLFunctionTableList Create() { > TRtSQLFunctionTableList Result; > Result = new TRtSQLFunctionTableList(); > Result.runCreate(); > return Result; > } > > public TRtSQLFunctionTableListClass ClassType() { > return TRtSQLFunctionTableListClass.SINGLETON; > } > } > > public static class TRtWhereItemClass extends TSQLContainerItemClass { > > public static final TRtWhereItemClass SINGLETON = new TRtWhereItemClass(); > > public TRtWhereItem Create() { > return TRtWhereItem.Create(); > } > > public final TRtWhereItem CreateParented(TContainerItem AOwner) { > return TRtWhereItem.CreateParented(AOwner); > } > > public Class<? extends TRtWhereItem> ClassInfo() { > return TRtWhereItem.class; > } > } > > public static class TRtWhereItem extends TSQLContainerItem { > > public final String GetWhereSeniorSQL() { > String Result = ""; > TRtCustomSQL xRootSQL; > xRootSQL = GetRootSQL(); > if (xRootSQL != null) { > Result = GetWhere(xRootSQL, this); > } else { > Result = ""; > } > return Result; > } > > protected String FExpression; > protected TRtSQLTokenList FTokens; > protected String FParamList; > > public final String GetExpression() { > String Result = ""; > String STmp = ""; > Result = FExpression; > if (StrIsBlank(Result)) { > STmp = FTokens.GetAsString(); > Result = Trim(STmp); > } > return Result; > } > > public void SetExpression(String Value) { > _SetExpression(Value, true); > } > > protected final void _SetExpression(String Value, boolean LCondition) { > TRtSQLTokenList ATokens; > CheckUnprepare(); > DropParamsFromOwnerSQLClass(null); > TString temp = new TString(""); > ATokens = CompileSQLExp(Value, temp, LCondition); > FParamList = temp.v; > if (ATokens != null) { > try { > FTokens.Assign(ATokens); > AddParamsToOwnerSQLClass(null); > } finally { > ATokens.Free(); > } > } > FExpression = Value; > } > > public void SetTokens(TRtSQLTokenList Value) { > TRtCustomSQL ARootSQL; > boolean LRootAssigning; > CheckUnprepare(); > ARootSQL = GetRootSQL(); > LRootAssigning = ARootSQL != null && ARootSQL.FAssigning > 0; > if (Value == null) { > throw DelphiException.Create(TransStr("TC537", "Parâmetro nulo.", true)); > } > if (!LRootAssigning) { > DropParamsFromOwnerSQLClass(null); > } > FParamList = Value.GetEncodedParams(); > FTokens.Assign(Value); > if (!LRootAssigning) { > AddParamsToOwnerSQLClass(null); > } > FExpression = Value.GetAsString(); > } > > protected final void AddParamsToOwnerSQLClass(TRtCustomSQL ASql) { > String AParamDef = ""; > String AName = ""; > int AType; > int ALen; > TInt p = new TInt(); > TInt p1 = new TInt(); > if (ASql == null) { > ASql = GetRootSQL(); > } > if (ASql == null) { > return; > } > p.v = 0; > AParamDef = StrGetNextToken(FParamList, p, ';'); > while (!AParamDef.equals("")) { > p1.v = 0; > AName = StrGetNextToken(AParamDef, p1, ','); > AType = ((int) StrToInt(StrGetNextToken(AParamDef, p1, ','))); > ALen = StrToInt(StrGetNextToken(AParamDef, p1, ',')); > if (AType == rdtObject) { > if (ASql.FSelectParams.ItemByName(AName) == null) { > ASql.FSelectParams.AddNewItem(AName); > } > } else { > if (ASql.GetParams().ItemByName(AName) == null) { > ASql.GetParams().AddNewItem(AName, AType, ALen); > } > } > AParamDef = StrGetNextToken(FParamList, p, ';'); > } > } > > protected final void DropParamsFromOwnerSQLClass(TRtCustomSQL ASql) { > String AParamDef = ""; > String AName = ""; > int AType; > TInt p = new TInt(); > TInt p1 = new TInt(); > int i; > if (ASql == null) { > ASql = GetRootSQL(); > } > if (ASql == null) { > return; > } > p.v = 0; > AParamDef = StrGetNextToken(FParamList, p, ';'); > while (!AParamDef.equals("")) { > p1.v = 0; > AName = StrGetNextToken(AParamDef, p1, ','); > AType = StrToInt(StrGetNextToken(AParamDef, p1, ',')); > if (AType == rdtObject) { > i = ASql.FSelectParams.IndexByName(AName); > if (i >= 0) { > ASql.FSelectParams.ClearItem(i); > } > } else { > ASql.GetParams().RemoveItemByName(AName); > } > AParamDef = StrGetNextToken(FParamList, p, ';'); > } > } > > protected final TRtCustomSQL GetRootSQL() { > TRtCustomSQL Result; > TRtCustomSQL ASql; > Result = ((TRtCustomSQL) GetTypedOwner(TRtCustomSQLClass.SINGLETON)); > ASql = Result; > while (ASql != null) { > ASql = ((TRtCustomSQL) ASql.GetTypedOwner(TRtCustomSQLClass.SINGLETON)); > if (ASql != null) { > Result = ASql; > } > } > return Result; > } > > public void runCreate() { > super.runCreate(); > FTokens = ((TRtSQLTokenList) Creator(this, TRtSQLTokenListClass.SINGLETON)); > } > > public static TRtWhereItem Create() { > TRtWhereItem Result; > Result = new TRtWhereItem(); > Result.runCreate(); > return Result; > } > > public final void runCreateParented(TContainerItem AOwner) { > super.runCreate(); > SetFOwner(AOwner); > FTokens = ((TRtSQLTokenList) Creator(this, TRtSQLTokenListClass.SINGLETON)); > } > > public static TRtWhereItem CreateParented(TContainerItem AOwner) { > TRtWhereItem Result; > Result = new TRtWhereItem(); > Result.runCreateParented(AOwner); > return Result; > } > > public void Destroy() { > FTokens.Free(); > super.Destroy(); > } > > public void Assign(TPersistent Source) { > if (Source instanceof TRtWhereItem) { > SetTokens(((TRtWhereItem) Source).FTokens); > FExpression = ((TRtWhereItem) Source).FExpression; > } else { > super.Assign(Source); > } > } > > public void ReadData(TReader Reader) { > TRtSQLTokenList ATokens; > ATokens = TRtSQLTokenList.Create(); > try { > ATokens.ReadData(Reader); > FExpression = Reader.ReadString(); > SetTokens(ATokens); > } finally { > ATokens.Free(); > } > } > > public void WriteData(TWriter Writer) { > FTokens.WriteData(Writer); > Writer.WriteString(FExpression); > } > > public TRtWhereItemClass ClassType() { > return TRtWhereItemClass.SINGLETON; > } > > public TRtSQLTokenList getTokens() { > return FTokens; > } > } > > public static final class TRtExpressionItemClass extends TRtWhereItemClass { > > public static final TRtExpressionItemClass SINGLETON = new TRtExpressionItemClass(); > > public Class<? extends TRtExpressionItem> ClassInfo() { > return TRtExpressionItem.class; > } > } > > public static final class TRtExpressionItem extends TRtWhereItem { > > public void SetExpression(String Value) { > _SetExpression(Value, false); > } > > public TRtExpressionItemClass ClassType() { > return TRtExpressionItemClass.SINGLETON; > } > } > > public static final class TRtExpressionListClass extends TSQLTypedListOwnerClass { > > public static final TRtExpressionListClass SINGLETON = new TRtExpressionListClass(); > > public Class<? extends TRtExpressionList> ClassInfo() { > return TRtExpressionList.class; > } > } > > public static final class TRtExpressionList extends TSQLTypedListOwner { > > protected TContainerItemClass AllocItemType() { > return TRtExpressionItemClass.SINGLETON; > } > > public final TRtExpressionItem GetItems(int Index) { > return ((TRtExpressionItem) Get(Index)); > } > > public final TRtExpressionItem AddVariable(String AExp) { > TRtExpressionItem Result; > CheckUnprepare(); > Result = ((TRtExpressionItem) Creator(null, AllocItemType())); > try { > Result.SetExpression(AExp); > if (Result.getTokens().GetCount() == 1 && Result.getTokens().GetItem(0).getTokType() == rstIdColumn) { > AExp = Result.getTokens().GetItem(0).getToken(); > Result.getTokens().Delete(0); > Result.getTokens().AddTokenTyped(AExp, rstIdVariable, rssLValue); > } > Add(Result); > } catch (Throwable any) { > Result.SetFOwner(null); > Result.Destroy(); > throw wrap(any); > } > return Result; > } > > public TRtExpressionListClass ClassType() { > return TRtExpressionListClass.SINGLETON; > } > } > > public static final class TRtWhereCurrentOfItemClass extends TRtWhereItemClass { > > public static final TRtWhereCurrentOfItemClass SINGLETON = new TRtWhereCurrentOfItemClass(); > > public Class<? extends TRtWhereCurrentOfItem> ClassInfo() { > return TRtWhereCurrentOfItem.class; > } > } > > public static final class TRtWhereCurrentOfItem extends TRtWhereItem { > > public final void SetCurrentOf(String Value) { > CheckUnprepare(); > FTokens.Clear(); > FExpression = Value; > } > > public final String GetCurrentOf() { > String Result = ""; > if (FTokens.GetCount() > 0) { > Result = ""; > } else { > Result = FExpression; > } > return Result; > } > > public TRtWhereCurrentOfItemClass ClassType() { > return TRtWhereCurrentOfItemClass.SINGLETON; > } > } > > public static final class TRtBeginTranClass extends TRtCustomUpdateSQLClass { > > public static final TRtBeginTranClass SINGLETON = new TRtBeginTranClass(); > > public Class<? extends TRtBeginTran> ClassInfo() { > return TRtBeginTran.class; > } > } > > public static final class TRtBeginTran extends TRtCustomUpdateSQL { > > public void ExecuteUpd() { > throw DelphiException.Create(STORED_PROC_ERR_MESS); > } > > public TRtBeginTranClass ClassType() { > return TRtBeginTranClass.SINGLETON; > } > } > > public static class TRtSetTransactionClass extends TRtCustomUpdateSQLClass { > > public static final TRtSetTransactionClass SINGLETON = new TRtSetTransactionClass(); > > public final TRtSetTransaction CreateSQL(TRtDBConnection AConn, int AIsolationLevel) { > return TRtSetTransaction.CreateSQL(AConn, AIsolationLevel); > } > > public TRtSetTransaction Create() { > return TRtSetTransaction.Create(); > } > > public Class<? extends TRtSetTransaction> ClassInfo() { > return TRtSetTransaction.class; > } > } > > public static class TRtSetTransaction extends TRtCustomUpdateSQL { > > private int FIsolationLevel; > > public final void SetIsolationLevel(int Value) { > CheckUnprepare(); > FIsolationLevel = Value; > } > > public final void runCreateSQL(TRtDBConnection AConn, int AIsolationLevel) { > super.runCreateSQL(AConn); > FIsolationLevel = AIsolationLevel; > } > > public static TRtSetTransaction CreateSQL(TRtDBConnection AConn, int AIsolationLevel) { > TRtSetTransaction Result; > Result = new TRtSetTransaction(); > Result.runCreateSQL(AConn, AIsolationLevel); > return Result; > } > > public void ExecuteUpd() { > throw DelphiException.Create(STORED_PROC_ERR_MESS); > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtSetTransaction) { > FIsolationLevel = ((TRtSetTransaction) Source).FIsolationLevel; > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > Reader.Read(AsVar(FIsolationLevel), SizeOf(FIsolationLevel)); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.Write(AsConst(FIsolationLevel), SizeOf(FIsolationLevel)); > } > > public static TRtSetTransaction Create() { > TRtSetTransaction Result; > Result = new TRtSetTransaction(); > Result.runCreate(); > return Result; > } > > public TRtSetTransactionClass ClassType() { > return TRtSetTransactionClass.SINGLETON; > } > > public int getIsolationLevel() { > return FIsolationLevel; > } > } > > public static class TRtSavePointClass extends TRtCustomUpdateSQLClass { > > public static final TRtSavePointClass SINGLETON = new TRtSavePointClass(); > > public final TRtSavePoint CreateSQL(TRtDBConnection AConn, String ASavePoint) { > return TRtSavePoint.CreateSQL(AConn, ASavePoint); > } > > public TRtSavePoint Create() { > return TRtSavePoint.Create(); > } > > public Class<? extends TRtSavePoint> ClassInfo() { > return TRtSavePoint.class; > } > } > > public static class TRtSavePoint extends TRtCustomUpdateSQL { > > private String FSavePoint; > > public final void SetSavePoint(String Value) { > CheckUnprepare(); > FSavePoint = Value; > } > > public boolean GetHasOperation() { > return !StrIsBlank(getSavePoint()); > } > > public final void runCreateSQL(TRtDBConnection AConn, String ASavePoint) { > super.runCreateSQL(AConn); > FSavePoint = ASavePoint; > } > > public static TRtSavePoint CreateSQL(TRtDBConnection AConn, String ASavePoint) { > TRtSavePoint Result; > Result = new TRtSavePoint(); > Result.runCreateSQL(AConn, ASavePoint); > return Result; > } > > public void ExecuteUpd() { > throw DelphiException.Create(STORED_PROC_ERR_MESS); > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtSavePoint) { > FSavePoint = ((TRtSavePoint) Source).FSavePoint; > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > FSavePoint = Reader.ReadString(); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.WriteString(FSavePoint); > } > > public static TRtSavePoint Create() { > TRtSavePoint Result; > Result = new TRtSavePoint(); > Result.runCreate(); > return Result; > } > > public TRtSavePointClass ClassType() { > return TRtSavePointClass.SINGLETON; > } > > public String getSavePoint() { > return FSavePoint; > } > } > > public static class TRtRollBackClass extends TRtSavePointClass { > > public static final TRtRollBackClass SINGLETON = new TRtRollBackClass(); > > public TRtRollBack Create() { > return TRtRollBack.Create(); > } > > public Class<? extends TRtRollBack> ClassInfo() { > return TRtRollBack.class; > } > } > > public static class TRtRollBack extends TRtSavePoint { > > public boolean GetHasOperation() { > return true; > } > > public void ExecuteUpd() { > throw DelphiException.Create(STORED_PROC_ERR_MESS); > } > > public static TRtRollBack Create() { > TRtRollBack Result; > Result = new TRtRollBack(); > Result.runCreate(); > return Result; > } > > public TRtRollBackClass ClassType() { > return TRtRollBackClass.SINGLETON; > } > } > > public static class TRtCommitClass extends TRtCustomUpdateSQLClass { > > public static final TRtCommitClass SINGLETON = new TRtCommitClass(); > > public TRtCommit Create() { > return TRtCommit.Create(); > } > > public Class<? extends TRtCommit> ClassInfo() { > return TRtCommit.class; > } > } > > public static class TRtCommit extends TRtCustomUpdateSQL { > > public boolean GetHasOperation() { > return true; > } > > public void ExecuteUpd() { > throw DelphiException.Create(STORED_PROC_ERR_MESS); > } > > public static TRtCommit Create() { > TRtCommit Result; > Result = new TRtCommit(); > Result.runCreate(); > return Result; > } > > public TRtCommitClass ClassType() { > return TRtCommitClass.SINGLETON; > } > } > > public static class TRtDeleteFromClass extends TRtTableSQLClass { > > public static final TRtDeleteFromClass SINGLETON = new TRtDeleteFromClass(); > > public TRtDeleteFrom Create() { > return TRtDeleteFrom.Create(); > } > > public final TRtDeleteFrom CreateSQL(TRtDBConnection AConn, String ATableName) { > return TRtDeleteFrom.CreateSQL(AConn, ATableName); > } > > public Class<? extends TRtDeleteFrom> ClassInfo() { > return TRtDeleteFrom.class; > } > } > > public static class TRtDeleteFrom extends TRtTableSQL { > > protected TRtWhereCurrentOfItem FWhere; > > protected String GenSQL() { > String Result = ""; > String s = ""; > Result = SQL_DeleteFrom + GetName(); > s = BreakLine(GetWhere(this, getWhere())); > if (!StrIsBlank(s)) { > Result = Result + SQL_Space + SQL_Where + s; > } > if (getUsesScriptTerminator()) { > Result = Result + ToStr(SQL_ScriptTerminator); > } > return Result; > } > > public void runCreate() { > super.runCreate(); > FWhere = ((TRtWhereCurrentOfItem) Creator(this, TRtWhereCurrentOfItemClass.SINGLETON)); > } > > public static TRtDeleteFrom Create() { > TRtDeleteFrom Result; > Result = new TRtDeleteFrom(); > Result.runCreate(); > return Result; > } > > public final void runCreateSQL(TRtDBConnection AConn, String ATableName) { > super.runCreateSQL(AConn, ATableName); > FWhere = ((TRtWhereCurrentOfItem) Creator(this, TRtWhereCurrentOfItemClass.SINGLETON)); > } > > public static TRtDeleteFrom CreateSQL(TRtDBConnection AConn, String ATableName) { > TRtDeleteFrom Result; > Result = new TRtDeleteFrom(); > Result.runCreateSQL(AConn, ATableName); > return Result; > } > > public void Destroy() { > FWhere.Free(); > super.Destroy(); > } > > public void ExecuteUpd() { > if (!StrIsBlank(FWhere.GetCurrentOf())) { > throw DelphiException.Create(STORED_PROC_ERR_MESS); > } > super.ExecuteUpd(); > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtDeleteFrom) { > FWhere.Assign(((TRtDeleteFrom) Source).FWhere); > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > FWhere.ReadData(Reader); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > FWhere.WriteData(Writer); > } > > public TRtDeleteFromClass ClassType() { > return TRtDeleteFromClass.SINGLETON; > } > > public TRtWhereCurrentOfItem getWhere() { > return FWhere; > } > } > > public static final class TRtSetColumnValueClass extends TSQLNamedContainerItemClass { > > public static final TRtSetColumnValueClass SINGLETON = new TRtSetColumnValueClass(); > > public TRtSetColumnValue Create() { > return TRtSetColumnValue.Create(); > } > > public final TRtSetColumnValue CreateSetValue(TRtSetColumnList AOwner, String AColName, Object AValue) { > return TRtSetColumnValue.CreateSetValue(AOwner, AColName, AValue); > } > > public final TRtSetColumnValue CreateSetExp(TRtSetColumnList AOwner, String AColName, String AExp) { > return TRtSetColumnValue.CreateSetExp(AOwner, AColName, AExp); > } > > public Class<? extends TRtSetColumnValue> ClassInfo() { > return TRtSetColumnValue.class; > } > } > > public static final class TRtSetColumnValue extends TSQLNamedContainerItem { > > private Object FValue; > private TRtExpressionItem FExp; > > public final void SetValue(Object Value) { > CheckUnprepare(); > FValue = Value; > } > > public void SetName(String Value) { > if (StrIsBlank(GetName())) { > super.SetName(Value); > } > } > > public final boolean GetIsExp() { > return FExp.getTokens().GetCount() != 0; > } > > public void runCreate() { > super.runCreate(); > FExp = ((TRtExpressionItem) Creator(this, TRtExpressionItemClass.SINGLETON)); > } > > public static TRtSetColumnValue Create() { > TRtSetColumnValue Result; > Result = new TRtSetColumnValue(); > Result.runCreate(); > return Result; > } > > public final void runCreateSetValue(TRtSetColumnList AOwner, String AColName, Object AValue) { > super.runCreate(); > SetName(AColName); > FValue = AValue; > FExp = ((TRtExpressionItem) Creator(this, TRtExpressionItemClass.SINGLETON)); > AOwner.AddItem(this); > } > > public static TRtSetColumnValue CreateSetValue(TRtSetColumnList AOwner, String AColName, Object AValue) { > TRtSetColumnValue Result; > Result = new TRtSetColumnValue(); > Result.runCreateSetValue(AOwner, AColName, AValue); > return Result; > } > > public final void runCreateSetExp(TRtSetColumnList AOwner, String AColName, String AExp) { > super.runCreate(); > SetName(AColName); > FExp = ((TRtExpressionItem) Creator(this, TRtExpressionItemClass.SINGLETON)); > AOwner.AddItem(this); > if (!StrIsBlank(AExp)) { > FExp.SetExpression(AExp); > } > } > > public static TRtSetColumnValue CreateSetExp(TRtSetColumnList AOwner, String AColName, String AExp) { > TRtSetColumnValue Result; > Result = new TRtSetColumnValue(); > Result.runCreateSetExp(AOwner, AColName, AExp); > return Result; > } > > public void Destroy() { > if (FExp != null) { > FExp.Free(); > } > super.Destroy(); > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtSetColumnValue) { > FExp.Assign(((TRtSetColumnValue) Source).FExp); > FValue = ((TRtSetColumnValue) Source).FValue; > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > FExp.ReadData(Reader); > byte[] tmp = new byte[SizeOf_Variant]; > Reader.Read(tmp, tmp.length); > FValue = ToVariant(tmp); > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > { > TWriter context_Writer = Writer; > FExp.WriteData(Writer); > context_Writer.Write(VarToBytes(FValue), SizeOf_Variant); > } > } > > public TRtSetColumnValueClass ClassType() { > return TRtSetColumnValueClass.SINGLETON; > } > > public Object getValue() { > return FValue; > } > > public TRtExpressionItem getExp() { > return FExp; > } > } > > public static final class TRtSetColumnListClass extends TSQLNamedListOwnerClass { > > public static final TRtSetColumnListClass SINGLETON = new TRtSetColumnListClass(); > > public final TRtSetColumnList CreateParented(TRtCustomSQL AOwner) { > return TRtSetColumnList.CreateParented(AOwner); > } > > public Class<? extends TRtSetColumnList> ClassInfo() { > return TRtSetColumnList.class; > } > } > > public static final class TRtSetColumnList extends TSQLNamedListOwner { > > protected TContainerItemClass AllocItemType() { > return TRtSetColumnValueClass.SINGLETON; > } > > public final TRtSetColumnValue GetItem(int Index) { > return ((TRtSetColumnValue) Get(Index)); > } > > public final void runCreateParented(TRtCustomSQL AOwner) { > super.runCreate(); > SetFOwner(AOwner); > } > > public static TRtSetColumnList CreateParented(TRtCustomSQL AOwner) { > TRtSetColumnList Result; > Result = new TRtSetColumnList(); > Result.runCreateParented(AOwner); > return Result; > } > > public final void SetColumnValue(String AColName, Object AValue) { > CheckUnprepare(); > TRtSetColumnValue.CreateSetValue(this, AColName, AValue); > } > > public final void SetColumnExp(String AColName, String AExp) { > CheckUnprepare(); > TRtSetColumnValue.CreateSetExp(this, AColName, AExp); > } > > public TRtSetColumnListClass ClassType() { > return TRtSetColumnListClass.SINGLETON; > } > } > > public static class TRtInsertSelectIntoClass extends TRtTableSQLClass { > > public static final TRtInsertSelectIntoClass SINGLETON = new TRtInsertSelectIntoClass(); > > public TRtInsertSelectInto Create() { > return TRtInsertSelectInto.Create(); > } > > public final TRtInsertSelectInto CreateSQL(TRtDBConnection AConn, String ATableName) { > return TRtInsertSelectInto.CreateSQL(AConn, ATableName); > } > > public Class<? extends TRtInsertSelectInto> ClassInfo() { > return TRtInsertSelectInto.class; > } > } > > public static class TRtInsertSelectInto extends TRtTableSQL { > > private final class GenSQL_Context { > > private String Result = ""; > > private String GetColumnsIdentifier() { > String Result = ""; > int i; > Result = ""; > if (getColumns().GetCount() > 0) { > Result = getColumns().Get(0); > for (i = 1; i <= getColumns().GetCount() - 1; ++i) { > Result = Result + SQL_Comma + getColumns().Get(i); > } > } > if (!StrIsBlank(Result)) { > Result = "" + SQL_Space + SQL_LParenthesis + Result + ToStr(SQL_RParenthesis); > } > return Result; > } > > private String GetQuerySpecification() { > String Result = ""; > if (getSelect() == null) { > Result = ""; > } else { > Result = "" + SQL_Space + SQL_LParenthesis + getSelect().GetSQL() + ToStr(SQL_RParenthesis); > } > return Result; > } > > public GenSQL_Context() { > } > > public String execute() { > Result = SQL_InsertInto + GetName() + SQL_Space + BreakLine(GetColumnsIdentifier()) + BreakLine(GetQuerySpecification()); > if (getUsesScriptTerminator()) { > Result = Result + ToStr(SQL_ScriptTerminator); > } > return Result; > } > } > > public boolean GetHasOperation() { > return super.GetHasOperation() && FSelect != null && FSelect.GetHasOperation(); > } > > protected TStringListOwner FColumns; > protected TRtSelect FSelect; > > protected final void Init() { > FSelect = ((TRtSelect) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckSelect, getDBVersionKind())); > FSelect.SetFOwner(this); > FColumns = TStringListOwner.Create(); > FColumns.setDuplicates(dupError); > } > > public final void SetSelect(TRtSelect Value) { > CheckUnprepare(); > FSelect.Assign(Value); > } > > protected String GenSQL() { > GenSQL_Context ctx = new GenSQL_Context(); > return ctx.execute(); > } > > public void runCreate() { > super.runCreate(); > Init(); > } > > public static TRtInsertSelectInto Create() { > TRtInsertSelectInto Result; > Result = new TRtInsertSelectInto(); > Result.runCreate(); > return Result; > } > > public final void runCreateSQL(TRtDBConnection AConn, String ATableName) { > super.runCreateSQL(AConn, ATableName); > Init(); > } > > public static TRtInsertSelectInto CreateSQL(TRtDBConnection AConn, String ATableName) { > TRtInsertSelectInto Result; > Result = new TRtInsertSelectInto(); > Result.runCreateSQL(AConn, ATableName); > return Result; > } > > public void Destroy() { > FSelect.Free(); > FColumns.Free(); > super.Destroy(); > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtInsertSelectInto) { > FColumns.Assign(((TRtInsertSelectInto) Source).FColumns); > FSelect.Assign(((TRtInsertSelectInto) Source).FSelect); > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > FColumns.ReadData(Reader); > FSelect.ReadData(Reader); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > FColumns.WriteData(Writer); > FSelect.WriteData(Writer); > } > > public TRtInsertSelectIntoClass ClassType() { > return TRtInsertSelectIntoClass.SINGLETON; > } > > public TStringListOwner getColumns() { > return FColumns; > } > > public TRtSelect getSelect() { > return FSelect; > } > } > > public static class TRtInsertIntoClass extends TRtTableSQLClass { > > public static final TRtInsertIntoClass SINGLETON = new TRtInsertIntoClass(); > > protected final String GetColumnValue(TRtSetColumnValue Column, TRtDatabaseDef DataBaseDef) { > String Result = ""; > TRtTableDef TableDef; > String Aux = ""; > TRtSetColumnList ListOwner; > TRtFieldDef FieldDef; > int AFldType; > ListOwner = ((TRtSetColumnList) Column.GetTypedOwner(TRtSetColumnListClass.SINGLETON)); > Aux = (((TRtTableSQL) ListOwner.GetTypedOwner(TRtTableSQLClass.SINGLETON))).GetName(); > TableDef = DataBaseDef.TableByName(Aux); > if (TableDef != null) { > FieldDef = TableDef.FieldByName(Column.GetName()); > } else { > FieldDef = null; > } > if (FieldDef != null) { > AFldType = FieldDef.GetFullKind().GetEnumType(); > } else { > AFldType = rftUnknown; > } > Aux = VarToStr(Column.getValue()); > switch (AFldType) { > case rftString: > Result = SQL_Quotes + Aux + ToStr(SQL_Quotes); > break; > case rftNumber: > while (Pos(',', Aux) != 0) { > Aux = Util.setChar(Aux, Pos(",", Aux), SQL_DecimalSeparator); > } > Result = Aux; > break; > case rftBoolean: > if (VarToBoolean(VarAsType(Column.getValue(), varBoolean))) { > Result = SQL_True; > } else { > Result = SQL_FALSE; > } > break; > case rftDate: > Result = FormatDateTime("dd;mm;yyyy,hh:nn:ss", ((Number) Column.getValue()).doubleValue()); > break; > case rftTime: > Result = Aux; > break; > case rftBlob: > case rftText: > case rftImage: > Result = ToStr(SQL_Quotes) + SQL_Quotes; > break; > default: > Result = Aux; > break; > } > return Result; > } > > public TRtInsertInto Create() { > return TRtInsertInto.Create(); > } > > public final TRtInsertInto CreateSQL(TRtDBConnection AConn, String ATableName) { > return TRtInsertInto.CreateSQL(AConn, ATableName); > } > > public Class<? extends TRtInsertInto> ClassInfo() { > return TRtInsertInto.class; > } > } > > public static class TRtInsertInto extends TRtTableSQL { > > private final class GenSQL_Context { > > private String Result = ""; > > private String GetColumnsIdentifier() { > String Result = ""; > int i; > Result = ""; > if (getColumns().GetCount() > 0) { > Result = getColumns().GetItem(0).GetName(); > for (i = 1; i <= getColumns().GetCount() - 1; ++i) { > Result = Result + SQL_Comma + getColumns().GetItem(i).GetName(); > } > } > if (!StrIsBlank(Result)) { > Result = "" + SQL_Space + SQL_LParenthesis + Result + ToStr(SQL_RParenthesis); > } > return Result; > } > > private String GetInsertValues() { > String Result = ""; > int i; > Result = ToStr(SQL_LParenthesis); > for (i = 0; i <= getColumns().GetCount() - 1; ++i) { > if (!getColumns().GetItem(i).GetIsExp()) { > Result = Result + TRtInsertIntoClass.SINGLETON.GetColumnValue(getColumns().GetItem(i), CheckGetDatabaseDef()); > } else { > Result = Result + TranslateExpression(TRtInsertInto.this, getColumns().GetItem(i).getExp().getTokens()); > } > if (i < getColumns().GetCount() - 1) { > Result = Result + ToStr(SQL_Comma); > } > } > Result = Result + ToStr(SQL_RParenthesis); > if (Length(Result) == 2) { > Result = ""; > } > return Result; > } > > public GenSQL_Context() { > } > > public String execute() { > Result = SQL_InsertInto + GetName() + BreakLine(GetColumnsIdentifier()) + SQL_Values + BreakLine(GetInsertValues()); > if (getUsesScriptTerminator()) { > Result = Result + ToStr(SQL_ScriptTerminator); > } > return Result; > } > } > > public boolean GetHasOperation() { > return super.GetHasOperation() && FColumns != null && FColumns.GetCount() > 0; > } > > protected TRtSetColumnList FColumns; > > protected final String GetColumnValue(TRtSetColumnValue Column, TRtDatabaseDef DataBaseDef) { > return ClassType().GetColumnValue(Column, DataBaseDef); > } > > protected String GenSQL() { > GenSQL_Context ctx = new GenSQL_Context(); > return ctx.execute(); > } > > public void runCreate() { > super.runCreate(); > FColumns = ((TRtSetColumnList) Creator(this, TRtSetColumnListClass.SINGLETON)); > } > > public static TRtInsertInto Create() { > TRtInsertInto Result; > Result = new TRtInsertInto(); > Result.runCreate(); > return Result; > } > > public final void runCreateSQL(TRtDBConnection AConn, String ATableName) { > super.runCreateSQL(AConn, ATableName); > FColumns = ((TRtSetColumnList) Creator(this, TRtSetColumnListClass.SINGLETON)); > } > > public static TRtInsertInto CreateSQL(TRtDBConnection AConn, String ATableName) { > TRtInsertInto Result; > Result = new TRtInsertInto(); > Result.runCreateSQL(AConn, ATableName); > return Result; > } > > public void Destroy() { > FColumns.Free(); > super.Destroy(); > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtInsertInto) { > FColumns.Assign(((TRtInsertInto) Source).FColumns); > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > FColumns.ReadData(Reader); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > FColumns.WriteData(Writer); > } > > public TRtInsertIntoClass ClassType() { > return TRtInsertIntoClass.SINGLETON; > } > > public TRtSetColumnList getColumns() { > return FColumns; > } > } > > public static final class TRtUpdateClass extends TRtAliasedTableSQLClass { > > public static final TRtUpdateClass SINGLETON = new TRtUpdateClass(); > > public TRtUpdate Create() { > return TRtUpdate.Create(); > } > > public final TRtUpdate CreateSQL(TRtDBConnection AConn, String ATableName, String AAlias) { > return TRtUpdate.CreateSQL(AConn, ATableName, AAlias); > } > > public Class<? extends TRtUpdate> ClassInfo() { > return TRtUpdate.class; > } > } > > public static final class TRtUpdate extends TRtAliasedTableSQL { > > private final class GenSQL_Context { > > private String Result = ""; > > private String GetExpression() { > String Result = ""; > int I; > Result = ""; > for (I = 0; I <= getColumns().GetCount() - 1; ++I) { > if (!getColumns().GetItem(I).GetIsExp()) { > Result = Result + getColumns().GetItem(I).GetName() + '=' + TRtInsertIntoClass.SINGLETON.GetColumnValue(getColumns().GetItem(I), CheckGetDatabaseDef()); > } else { > Result = Result + getColumns().GetItem(I).GetName() + '=' + TranslateExpression(TRtUpdate.this, getColumns().GetItem(I).getExp().getTokens()); > } > if (I < getColumns().GetCount() - 1) { > Result = Result + ToStr(SQL_Comma); > } > } > return Result; > } > > public GenSQL_Context() { > } > > public String execute() { > Result = SQL_Update + GetName(); > if (!StrIsBlank(getAlias())) { > Result = Result + SQL_Space + getAlias(); > } > Result = Result + SQL_Set + BreakLine(GetExpression()) + BreakLine(GetWhere(TRtUpdate.this, getWhere())); > if (getUsesScriptTerminator()) { > Result = Result + ToStr(SQL_ScriptTerminator); > } > return Result; > } > } > > public boolean GetHasOperation() { > return super.GetHasOperation() && FColumns != null && FColumns.GetCount() > 0; > } > > protected TRtSetColumnList FColumns; > protected TRtWhereCurrentOfItem FWhere; > > protected final void Init() { > FColumns = ((TRtSetColumnList) Creator(this, TRtSetColumnListClass.SINGLETON)); > FWhere = ((TRtWhereCurrentOfItem) Creator(this, TRtWhereCurrentOfItemClass.SINGLETON)); > } > > protected String GenSQL() { > GenSQL_Context ctx = new GenSQL_Context(); > return ctx.execute(); > } > > public void runCreate() { > super.runCreate(); > Init(); > } > > public static TRtUpdate Create() { > TRtUpdate Result; > Result = new TRtUpdate(); > Result.runCreate(); > return Result; > } > > public final void runCreateSQL(TRtDBConnection AConn, String ATableName, String AAlias) { > super.runCreateSQL(AConn, ATableName, AAlias); > Init(); > } > > public static TRtUpdate CreateSQL(TRtDBConnection AConn, String ATableName, String AAlias) { > TRtUpdate Result; > Result = new TRtUpdate(); > Result.runCreateSQL(AConn, ATableName, AAlias); > return Result; > } > > public void ExecuteUpd() { > if (!StrIsBlank(FWhere.GetCurrentOf())) { > throw DelphiException.Create(STORED_PROC_ERR_MESS); > } > super.ExecuteUpd(); > } > > public void Destroy() { > FWhere.Free(); > FColumns.Free(); > super.Destroy(); > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtUpdate) { > FWhere.Assign(((TRtUpdate) Source).FWhere); > FColumns.Assign(((TRtUpdate) Source).FColumns); > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > FWhere.ReadData(Reader); > FColumns.ReadData(Reader); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > FWhere.WriteData(Writer); > FColumns.WriteData(Writer); > } > > public TRtUpdateClass ClassType() { > return TRtUpdateClass.SINGLETON; > } > > public TRtSetColumnList getColumns() { > return FColumns; > } > > public TRtWhereCurrentOfItem getWhere() { > return FWhere; > } > } > > public static final class TRtSelColumnsItemClass extends TSQLNamedContainerItemClass { > > public static final TRtSelColumnsItemClass SINGLETON = new TRtSelColumnsItemClass(); > > public final TRtSelColumnsItem CreateColumnAs(TRtSelColumnsList AOwner, String AAlias, String AColName, String AAsName, boolean LGroupBy) { > return TRtSelColumnsItem.CreateColumnAs(AOwner, AAlias, AColName, AAsName, LGroupBy); > } > > public final TRtSelColumnsItem CreateExpAs(TRtSelColumnsList AOwner, TRtSQLTokenList AExpTokens, String AAsName, boolean LGroupBy) { > return TRtSelColumnsItem.CreateExpAs(AOwner, AExpTokens, AAsName, LGroupBy); > } > > public final TRtSelColumnsItem CreateEnumDescription(TRtSelColumnsList AOwner, TRtSelColumnsItem AEnumKey, String AEnumName) { > return TRtSelColumnsItem.CreateEnumDescription(AOwner, AEnumKey, AEnumName); > } > > public Class<? extends TRtSelColumnsItem> ClassInfo() { > return TRtSelColumnsItem.class; > } > } > > public static final class TRtSelColumnsItem extends TSQLNamedContainerItem { > > protected String FColName; > protected TRtSQLTokenList FExpTokens; > protected boolean FIsGroupBy; > protected String FFromAlias; > protected TRtSelTableItem FFromItem; > protected TRtSelColumnsItem FEnumKey; > protected String FEnumName; > > public void SetName(String Value) { > if (StrIsBlank(GetName())) { > super.SetName(Value); > } > } > > public final boolean GetIsExp() { > return FExpTokens != null; > } > > protected final TRtSelect CheckOwnerSelect() { > return ((TRtSelect) CheckTypedOwner(TRtSelectClass.SINGLETON)); > } > > public final boolean GetIsEnumDescription() { > return !StrIsBlank(FEnumName); > } > > public final String GetBaseColumnName() { > String Result = ""; > int APos; > APos = Pos(".", FColName); > if (APos > 0) { > Result = Copy(FColName, APos + 1, Length(FColName) - APos); > } else { > Result = FColName; > } > return Result; > } > > public final void runCreateColumnAs(TRtSelColumnsList AOwner, String AAlias, String AColName, String AAsName, boolean LGroupBy) { > super.runCreate(); > FColName = AColName; > FIsGroupBy = LGroupBy; > SetName(AAsName); > FFromAlias = AAlias; > AOwner.AddItem(this); > } > > public static TRtSelColumnsItem CreateColumnAs(TRtSelColumnsList AOwner, String AAlias, String AColName, String AAsName, boolean LGroupBy) { > TRtSelColumnsItem Result; > Result = new TRtSelColumnsItem(); > Result.runCreateColumnAs(AOwner, AAlias, AColName, AAsName, LGroupBy); > return Result; > } > > public final void runCreateExpAs(TRtSelColumnsList AOwner, TRtSQLTokenList AExpTokens, String AAsName, boolean LGroupBy) { > super.runCreate(); > FExpTokens = AExpTokens; > FExpTokens.SetFOwner(this); > FIsGroupBy = LGroupBy; > SetName(AAsName); > AOwner.AddItem(this); > } > > public static TRtSelColumnsItem CreateExpAs(TRtSelColumnsList AOwner, TRtSQLTokenList AExpTokens, String AAsName, boolean LGroupBy) { > TRtSelColumnsItem Result; > Result = new TRtSelColumnsItem(); > Result.runCreateExpAs(AOwner, AExpTokens, AAsName, LGroupBy); > return Result; > } > > public final void runCreateEnumDescription(TRtSelColumnsList AOwner, TRtSelColumnsItem AEnumKey, String AEnumName) { > super.runCreate(); > FIsGroupBy = false; > FEnumKey = AEnumKey; > FEnumName = AEnumName; > SetName(AEnumName + '_' + AEnumKey.GetName()); > AOwner.AddItem(this); > } > > public static TRtSelColumnsItem CreateEnumDescription(TRtSelColumnsList AOwner, TRtSelColumnsItem AEnumKey, String AEnumName) { > TRtSelColumnsItem Result; > Result = new TRtSelColumnsItem(); > Result.runCreateEnumDescription(AOwner, AEnumKey, AEnumName); > return Result; > } > > public void Destroy() { > int i; > TRtSelect AOwner; > TRtSelColumnsList AList; > TRtSelColumnsItem AItem; > if (FExpTokens != null) { > FExpTokens.Free(); > } > if (GetFOwner() instanceof TRtSelColumnsList) { > AOwner = CheckOwnerSelect(); > i = 0; > while (i < AOwner.FOrderBy.GetCount()) { > if (AOwner.FOrderBy.GetItem(i).FColItem == this) { > AOwner.FOrderBy.GetItem(i).Free(); > } else { > i++; > } > } > if (StrIsBlank(FEnumName)) { > AList = ((TRtSelColumnsList) GetFOwner()); > i = 0; > while (i < AList.GetCount()) { > AItem = AList.GetItem(i); > if (AItem != null && AItem.FEnumKey == this) { > AItem.FEnumKey = null; > } > i++; > } > } > } > super.Destroy(); > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtSelColumnsItem) { > FColName = ((TRtSelColumnsItem) Source).FColName; > FIsGroupBy = ((TRtSelColumnsItem) Source).FIsGroupBy; > if (((TRtSelColumnsItem) Source).FExpTokens != null) { > if (FExpTokens == null) { > FExpTokens = ((TRtSQLTokenList) ((TRtSelColumnsItem) Source).FExpTokens.CloneParented(this)); > } else { > FExpTokens.Assign(((TRtSelColumnsItem) Source).FExpTokens); > } > } else if (FExpTokens != null) { > FExpTokens.Free(); > FExpTokens = null; > } > FFromAlias = ((TRtSelColumnsItem) Source).FFromAlias; > FFromItem = null; > if (((TRtSelColumnsItem) Source).FEnumKey != null) { > FEnumKey = (((TRtSelColumnsList) GetFOwner())).ItemByAsName(((TRtSelColumnsItem) Source).FEnumKey.GetName()); > } else { > FEnumKey = null; > } > FEnumName = ((TRtSelColumnsItem) Source).FEnumName; > } > } > > public void ReadData(TReader Reader) { > String AEnumAsName = ""; > super.ReadData(Reader); > { > TReader context_Reader = Reader; > FColName = context_Reader.ReadString(); > FIsGroupBy = context_Reader.ReadBoolean(); > if (context_Reader.ReadBoolean()) { > if (FExpTokens == null) { > FExpTokens = ((TRtSQLTokenList) Creator(this, TRtSQLTokenListClass.SINGLETON)); > } > FExpTokens.ReadData(Reader); > } else if (FExpTokens != null) { > FExpTokens.Free(); > FExpTokens = null; > } > FFromAlias = context_Reader.ReadString(); > FFromItem = null; > AEnumAsName = context_Reader.ReadString(); > if (!StrIsBlank(AEnumAsName)) { > FEnumKey = (((TRtSelColumnsList) GetFOwner())).ItemByAsName(AEnumAsName); > } else { > FEnumKey = null; > } > FEnumName = context_Reader.ReadString(); > } > } > > public void WriteData(TWriter Writer) { > String AEnumAsName = ""; > boolean LExp; > super.WriteData(Writer); > { > TWriter context_Writer = Writer; > context_Writer.WriteString(FColName); > context_Writer.WriteBoolean(FIsGroupBy); > LExp = FExpTokens != null; > context_Writer.WriteBoolean(LExp); > if (LExp) { > FExpTokens.WriteData(Writer); > } > context_Writer.WriteString(FFromAlias); > if (FEnumKey != null) { > AEnumAsName = FEnumKey.GetName(); > } else { > AEnumAsName = ""; > } > context_Writer.WriteString(AEnumAsName); > context_Writer.WriteString(FEnumName); > } > } > > public final String CalculatedAsName() { > String Result = ""; > TRtSelect OwnerSelect; > boolean LSingleTable; > Result = ""; > OwnerSelect = CheckOwnerSelect(); > if (OwnerSelect.getFrom().GetCount() == 1 && !StrIsBlank(OwnerSelect.getFrom().GetItem(0).getTableName())) { > LSingleTable = true; > } else { > LSingleTable = false; > } > if (FFromItem != null) { > if (!LSingleTable) { > Result = FFromItem.GetName(); > } > } > if (!StrIsBlank(GetName())) { > if (CompareText(GetName(), getColumnName()) == 0) { > Result = Result + GetName(); > } else { > Result = GetName(); > } > } else { > Result = Result + getColumnName(); > } > return Result; > } > > public TRtSelColumnsItemClass ClassType() { > return TRtSelColumnsItemClass.SINGLETON; > } > > public String getFromAlias() { > return FFromAlias; > } > > public TRtSelTableItem getFromItem() { > return FFromItem; > } > > public String getColumnName() { > return FColName; > } > > public TRtSelColumnsItem getEnumKey() { > return FEnumKey; > } > > public String getEnumName() { > return FEnumName; > } > > public boolean getIsGroupBy() { > return FIsGroupBy; > } > > public TRtSQLTokenList getExpTokens() { > return FExpTokens; > } > } > > public static final class TRtSelColumnsListClass extends TSQLNamedListOwnerClass { > > public static final TRtSelColumnsListClass SINGLETON = new TRtSelColumnsListClass(); > > public final TRtSelColumnsList CreateParented(TRtSelect AOwner) { > return TRtSelColumnsList.CreateParented(AOwner); > } > > public Class<? extends TRtSelColumnsList> ClassInfo() { > return TRtSelColumnsList.class; > } > } > > public static final class TRtSelColumnsList extends TSQLNamedListOwner { > > protected TContainerItemClass AllocItemType() { > return TRtSelColumnsItemClass.SINGLETON; > } > > public final TRtSelColumnsItem GetItem(int Index) { > return ((TRtSelColumnsItem) Get(Index)); > } > > protected final TRtSelect CheckOwnerSelect() { > return ((TRtSelect) CheckTypedOwner(TRtSelectClass.SINGLETON)); > } > > public final int GetGroupByCount() { > int Result; > Result = 0; > while (Result < GetCount() && this.GetItem(Result).FIsGroupBy) { > Result++; > } > return Result; > } > > protected final void CheckCanGroupBy() { > if (GetCount() != 0) { > if (!this.GetItem(GetCount() - 1).getIsGroupBy()) { > throw DelphiException.Create(TransStr("TC670", "Tentativa de agrupamento colunas fora de sequência.", true)); > } > } > } > > protected final TRtSelColumnsItem ItemByFromAlias(String AFromAlias) { > TRtSelColumnsItem Result; > int i; > for (i = 0; i <= GetCount() - 1; ++i) { > if (CompareText(this.GetItem(i).FFromAlias, AFromAlias) == 0) { > Result = this.GetItem(i); > return Result; > } > } > return null; > } > > public final void runCreateParented(TRtSelect AOwner) { > super.runCreate(); > SetFOwner(AOwner); > } > > public static TRtSelColumnsList CreateParented(TRtSelect AOwner) { > TRtSelColumnsList Result; > Result = new TRtSelColumnsList(); > Result.runCreateParented(AOwner); > return Result; > } > > public final void AddAllColumns(String ATblName, String AAlias) { > TRtSelect OwnerSelect; > TRtSelTableItem ATblItem; > TRtTableDef ATblDef; > TRtDatabaseDef ADbDef; > int i; > String AColName = ""; > String AAsName = ""; > boolean LSingleAsName; > CheckUnprepare(); > OwnerSelect = CheckOwnerSelect(); > ATblItem = OwnerSelect.FFrom.NewTableAs(ATblName, AAlias); > LSingleAsName = GetCount() == 0 && OwnerSelect.FFrom.GetCount() <= 1; > AAlias = ATblItem.GetName(); > ADbDef = OwnerSelect.GetDatabaseDef(); > if (ADbDef != null) { > ATblDef = ADbDef.TableByName(ATblItem.getTableName()); > } else { > ATblDef = null; > } > if (ATblDef != null) { > for (i = 0; i <= ATblDef.GetFieldCount() - 1; ++i) { > AColName = AAlias + '.' + ATblDef.GetField(i).GetName(); > if (LSingleAsName) { > AAsName = ATblDef.GetField(i).GetName(); > } else { > AAsName = AAlias + '_' + ATblDef.GetField(i).GetName(); > AAsName = StrReplaceStr(AAsName, "\"", ""); > } > if (ItemByName(AColName) == null) { > TRtSelColumnsItem.CreateColumnAs(this, AAlias, AColName, AAsName, false); > } > } > } else { > TRtSelColumnsItem.CreateColumnAs(this, AAlias, AAlias + ".*", "", false); > } > } > > public final void AddPrimaryKeyColumns(String ATblName, String AAlias) { > TRtSelect OwnerSelect; > TRtSelTableItem ATblItem; > TRtTableDef ATblDef; > int i; > String AColName = ""; > String AAsName = ""; > boolean LSingleAsName; > CheckUnprepare(); > OwnerSelect = CheckOwnerSelect(); > ATblItem = OwnerSelect.FFrom.NewTableAs(ATblName, AAlias); > LSingleAsName = GetCount() == 0 && OwnerSelect.FFrom.GetCount() <= 1; > AAlias = ATblItem.GetName(); > ATblDef = OwnerSelect.CheckGetDatabaseDef().CheckTableByName(ATblItem.getTableName()); > for (i = 0; i <= ATblDef.GetKeyCount() - 1; ++i) { > AColName = AAlias + '.' + ATblDef.GetPrimaryKeyField(i).GetName(); > if (LSingleAsName) { > AAsName = ATblDef.GetPrimaryKeyField(i).GetName(); > } else { > AAsName = AAlias + '_' + ATblDef.GetPrimaryKeyField(i).GetName(); > AAsName = StrReplaceStr(AAsName, "\"", ""); > } > if (ItemByName(AColName) == null) { > TRtSelColumnsItem.CreateColumnAs(this, AAlias, AColName, AAsName, false); > } > } > } > > public final TRtSelColumnsItem AddColumn(String AColName) { > return AddColumnAs(AColName, AColName); > } > > public final TRtSelColumnsItem AddColumnAs(String AColName, String AAsName) { > TRtSelColumnsItem Result; > TString AAlias = new TString(); > TRtSQLTokenList ATokens; > TRtSelFromItem FFrom; > int APos; > CheckUnprepare(); > if (StrIsBlank(AAsName)) { > AAsName = AColName; > } > APos = Pos(".", AAsName); > while (APos > 0) { > AAsName = Util.setChar(AAsName, APos, '_'); > APos = Pos(".", AAsName); > } > AAsName = StrReplaceStr(AAsName, "\"", ""); > ATokens = null; > ParseColName(AColName, AAlias, ATokens); > FFrom = CheckOwnerSelect().FFrom; > if (!StrIsBlank(AAlias.v)) { > FFrom.NewTableAs(AAlias.v, AAlias.v); > } else if (FFrom.GetCount() > 0) { > AAlias.v = FFrom.GetItem(0).GetName(); > } > if (ATokens == null) { > Result = TRtSelColumnsItem.CreateColumnAs(this, AAlias.v, AColName, AAsName, false); > } else { > if (CompareText(AColName, AAsName) == 0) { > AAsName = TempExp(); > } > Result = TRtSelColumnsItem.CreateExpAs(this, ATokens, AAsName, false); > } > return Result; > } > > public final TRtSelColumnsItem AddEnumDescription(String AKeyAsName, String AEnumName) { > TRtSelect OwnerSelect; > TRtSelTableItem AFromItem; > TRtSelColumnsItem AEnumKey; > TRtEnumerationDef AEnumDef; > TRtDatabaseDef ADbDef; > TRtTableDef ATblDef; > TRtFieldDef AFldDef; > String ATblAlias = ""; > String ATblName = ""; > CheckUnprepare(); > OwnerSelect = CheckOwnerSelect(); > ADbDef = OwnerSelect.CheckGetDatabaseDef(); > AEnumKey = ItemByAsName(AKeyAsName); > if (AEnumKey == null) { > AEnumKey = ItemByColumnName(AKeyAsName); > } > if (AEnumKey == null) { > throw DelphiException.CreateFmt(TransStr("TC668", "Coluna não encontrada: \"%s\".", true), new Object[] { AKeyAsName }); > } > if (StrIsBlank(AEnumName) && !AEnumKey.GetIsExp()) { > ATblAlias = AEnumKey.FFromAlias; > ATblName = ""; > if (StrIsBlank(ATblAlias)) { > if (OwnerSelect.FFrom.GetCount() == 1) { > ATblName = OwnerSelect.FFrom.GetItem(0).FTableName; > } > } else { > AFromItem = OwnerSelect.FFrom.ItemByAlias(ATblAlias); > if (AFromItem == null) { > AFromItem = OwnerSelect.FFrom.ItemByTableName(ATblAlias); > } > if (AFromItem != null) { > ATblName = AFromItem.FTableName; > } > } > if (!StrIsBlank(ATblName)) { > ATblDef = ADbDef.TableByName(ATblName); > if (ATblDef != null) { > AFldDef = ATblDef.FieldByName(AEnumKey.GetBaseColumnName()); > if (AFldDef != null) { > AEnumName = AFldDef.GetKindName(); > } > } > } > } > AEnumDef = null; > if (!StrIsBlank(AEnumName)) { > AEnumDef = ADbDef.EnumerationByName(AEnumName); > } > if (AEnumDef == null) { > throw DelphiException.Create(TransStr("TC669", "Não foi possível encontrar um tipo Enumeração.", true)); > } > return TRtSelColumnsItem.CreateEnumDescription(this, AEnumKey, AEnumName); > } > > public final void SetGroupByColumns(int NCols) { > int i; > CheckUnprepare(); > for (i = 0; i <= GetCount() - 1; ++i) { > this.GetItem(i).FIsGroupBy = i < NCols; > } > } > > public final TRtSelColumnsItem ItemByAsName(String AName) { > return ((TRtSelColumnsItem) ItemByName(AName)); > } > > public final TRtSelColumnsItem ItemByColumnName(String AName) { > TRtSelColumnsItem Result; > int i; > for (i = 0; i <= GetCount() - 1; ++i) { > if (CompareText(this.GetItem(i).getColumnName(), AName) == 0 || CompareText(this.GetItem(i).getColumnName(), this.GetItem(i).FFromAlias + '.' + AName) == 0) { > Result = this.GetItem(i); > return Result; > } > } > return null; > } > > public final int RemoveByAsName(String AName) { > return RemoveByName(AName); > } > > public final int RemoveByColumnName(String AName) { > int Result; > Result = IndexOf(ItemByColumnName(AName)); > if (Result >= 0) { > Delete(Result); > } > return Result; > } > > public TRtSelColumnsListClass ClassType() { > return TRtSelColumnsListClass.SINGLETON; > } > } > > public static final class TRtOuterJoinItemClass extends TSQLContainerItemClass { > > public static final TRtOuterJoinItemClass SINGLETON = new TRtOuterJoinItemClass(); > > public TRtOuterJoinItem Create() { > return TRtOuterJoinItem.Create(); > } > > public final TRtOuterJoinItem CreateOuterJoin(TRtSelTableItem AOwner, TRtSelTableItem ARightTable, String ALeftFields, String ARightFields, int aOuterJoinOption) { > return TRtOuterJoinItem.CreateOuterJoin(AOwner, ARightTable, ALeftFields, ARightFields, aOuterJoinOption); > } > > public Class<? extends TRtOuterJoinItem> ClassInfo() { > return TRtOuterJoinItem.class; > } > } > > public static final class TRtOuterJoinItem extends TSQLContainerItem { > > private final class GetFieldsAsExprString_Context { > > private final String SJoinOp; > private String Result = ""; > > private String TableRef(int ATable) { > String Result = ""; > TRtSelTableItem ASelItem; > if (ATable == 0) { > ASelItem = ((TRtSelTableItem) GetFOwner()); > } else { > ASelItem = FRightTableItem; > } > if (!StrIsBlank(ASelItem.GetName())) { > Result = ASelItem.GetName(); > } else { > Result = ASelItem.FTableName; > } > return Result; > } > > private int i; > private String LTbl = ""; > private String RTbl = ""; > > public GetFieldsAsExprString_Context(String SJoinOp) { > this.SJoinOp = SJoinOp; > } > > public String execute() { > LTbl = TableRef(0); > RTbl = TableRef(1); > if (FLeftFields.GetCount() > 0) { > Result = LTbl + '.' + FLeftFields.Get(0) + SJoinOp + "= " + RTbl + '.' + FRightFields.Get(0); > for (i = 1; i <= FLeftFields.GetCount() - 1; ++i) { > Result = Result + " AND " + LTbl + '.' + FLeftFields.Get(i) + SJoinOp + "= " + RTbl + '.' + FRightFields.Get(i); > } > } else { > Result = ""; > } > return Result; > } > } > > protected int FOuterJoinOption; > protected TRtSelTableItem FRightTableItem; > protected TStringListOwner FLeftFields; > protected TStringListOwner FRightFields; > > public final int GetFieldCount() { > return FLeftFields.GetCount(); > } > > public final String GetLeftFields(int Index) { > return FLeftFields.Get(Index); > } > > public final String GetRightFields(int Index) { > return FRightFields.Get(Index); > } > > public void runCreate() { > super.runCreate(); > FLeftFields = TStringListOwner.Create(); > FRightFields = TStringListOwner.Create(); > FOuterJoinOption = ojLeft; > } > > public static TRtOuterJoinItem Create() { > TRtOuterJoinItem Result; > Result = new TRtOuterJoinItem(); > Result.runCreate(); > return Result; > } > > public final void runCreateOuterJoin(TRtSelTableItem AOwner, TRtSelTableItem ARightTable, String ALeftFields, String ARightFields, int aOuterJoinOption) { > runCreate(); > if (AOwner.FOuterJoin != null) { > AOwner.FOuterJoin.Free(); > } > AOwner.FOuterJoin = this; > FRightTableItem = ARightTable; > if (!StrIsBlank(ALeftFields) && !StrIsBlank(ARightFields)) { > AddAllFields(ALeftFields, ARightFields); > } > FOuterJoinOption = aOuterJoinOption; > } > > public static TRtOuterJoinItem CreateOuterJoin(TRtSelTableItem AOwner, TRtSelTableItem ARightTable, String ALeftFields, String ARightFields, int aOuterJoinOption) { > TRtOuterJoinItem Result; > Result = new TRtOuterJoinItem(); > Result.runCreateOuterJoin(AOwner, ARightTable, ALeftFields, ARightFields, aOuterJoinOption); > return Result; > } > > public void Destroy() { > FLeftFields.Free(); > FRightFields.Free(); > super.Destroy(); > } > > public String GetFieldsAsExprString(String SJoinOp) { > GetFieldsAsExprString_Context ctx = new GetFieldsAsExprString_Context(SJoinOp); > return ctx.execute(); > } > > public void Assign(TPersistent Source) { > TRtSelFromItem OwnerFromItem; > if (Source instanceof TRtOuterJoinItem) { > OwnerFromItem = ((TRtSelFromItem) CheckTypedOwner(TRtSelFromItemClass.SINGLETON)); > if (!StrIsBlank(((TRtOuterJoinItem) Source).FRightTableItem.GetName())) { > FRightTableItem = OwnerFromItem.ItemByAlias(((TRtOuterJoinItem) Source).FRightTableItem.GetName()); > } else { > FRightTableItem = OwnerFromItem.ItemByTableName(((TRtOuterJoinItem) Source).FRightTableItem.getTableName()); > } > FLeftFields.Assign(((TRtOuterJoinItem) Source).FLeftFields); > FRightFields.Assign(((TRtOuterJoinItem) Source).FRightFields); > } else { > super.Assign(Source); > } > } > > public void ReadData(TReader Reader) { > TRtSelFromItem OwnerFromItem; > String STable = ""; > super.ReadData(Reader); > STable = Reader.ReadString(); > OwnerFromItem = ((TRtSelFromItem) CheckTypedOwner(TRtSelFromItemClass.SINGLETON)); > FRightTableItem = OwnerFromItem.ItemByAlias(STable); > if (FRightTableItem == null) { > FRightTableItem = OwnerFromItem.ItemByTableName(STable); > } > FLeftFields.ReadData(Reader); > FRightFields.ReadData(Reader); > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > if (!StrIsBlank(FRightTableItem.GetName())) { > Writer.WriteString(FRightTableItem.GetName()); > } else { > Writer.WriteString(FRightTableItem.getTableName()); > } > FLeftFields.WriteData(Writer); > FRightFields.WriteData(Writer); > } > > public final void AddFields(String ALeftField, String ARightField) { > int pl; > int pr; > CheckUnprepare(); > pl = StrRScan(ALeftField, 0, '.'); > if (pl != -1) { > pl++; > } else { > pl = 0; > } > pr = StrRScan(ARightField, 0, '.'); > if (pr != -1) { > pr++; > } else { > pr = 0; > } > if (FLeftFields.IndexOf(StrPas(ALeftField, pl)) >= 0) { > throw DelphiException.CreateFmt(TransStr("TC4932", "Campo \"%0:s\" da tabela \"%1:s\" já foi incluso na cláusula OUTER JOIN.", true), new Object[] { pl, (((TRtSelTableItem) CheckTypedOwner(TRtSelTableItemClass.SINGLETON))).getTableName() }); > } > if (FRightFields.IndexOf(StrPas(ARightField, pr)) >= 0) { > throw DelphiException.CreateFmt(TransStr("TC4932", "Campo \"%0:s\" da tabela \"%1:s\" já foi incluso na cláusula OUTER JOIN.", true), new Object[] { pr, FRightTableItem.getTableName() }); > } > FLeftFields.Add(StrPas(ALeftField, pl)); > FRightFields.Add(StrPas(ARightField, pl)); > } > > public final void AddAllFields(String ALeftFields, String ARightFields) { > TInt pl = new TInt(); > TInt pr = new TInt(); > String sl = ""; > String sr = ""; > pl.v = 0; > pr.v = 0; > while (true) { > sl = StrGetNextToken(ALeftFields, pl, ";"); > sr = StrGetNextToken(ARightFields, pr, ";"); > if (StrIsBlank(sl) || StrIsBlank(sr)) { > break; > } > AddFields(sl, sr); > } > } > > public final void DeleteFields(int Index) { > CheckUnprepare(); > FLeftFields.Delete(Index); > FRightFields.Delete(Index); > } > > public TRtOuterJoinItemClass ClassType() { > return TRtOuterJoinItemClass.SINGLETON; > } > > public TRtSelTableItem getRightTableItem() { > return FRightTableItem; > } > > public int getOuterJoinOption() { > return FOuterJoinOption; > } > } > > public static final class TRtSelTableItemClass extends TSQLNamedContainerItemClass { > > public static final TRtSelTableItemClass SINGLETON = new TRtSelTableItemClass(); > > public final TRtSelTableItem CreateAddTable(TRtSelFromItem AOwner, String ATblName, String AAlias) { > return TRtSelTableItem.CreateAddTable(AOwner, ATblName, AAlias); > } > > public Class<? extends TRtSelTableItem> ClassInfo() { > return TRtSelTableItem.class; > } > } > > public static final class TRtSelTableItem extends TSQLNamedContainerItem { > > protected TRtOuterJoinItem FOuterJoin; > protected String FTableName; > > protected final TRtSelect CheckOwnerSelect() { > return ((TRtSelect) CheckTypedOwner(TRtSelectClass.SINGLETON)); > } > > protected final void FreeOuterJoin() { > if (FOuterJoin != null) { > FOuterJoin.Free(); > FOuterJoin = null; > } > } > > public final void runCreateAddTable(TRtSelFromItem AOwner, String ATblName, String AAlias) { > FTableName = ATblName; > if (StrIsBlank(AAlias)) { > SetName(ATblName); > } else { > SetName(AAlias); > } > AOwner.AddItem(this); > } > > public static TRtSelTableItem CreateAddTable(TRtSelFromItem AOwner, String ATblName, String AAlias) { > TRtSelTableItem Result; > Result = new TRtSelTableItem(); > Result.runCreateAddTable(AOwner, ATblName, AAlias); > return Result; > } > > public void Destroy() { > int i; > TRtSelColumnsList ACols; > TRtSelFromItem ATbls; > TRtSelTableItem ASelTbl; > ACols = CheckOwnerSelect().FColumns; > for (i = 0; i <= ACols.GetCount() - 1; ++i) { > if (ACols.GetItem(i).FFromItem == this) { > ACols.GetItem(i).FFromItem = null; > } > } > ATbls = CheckOwnerSelect().FFrom; > for (i = 0; i <= ATbls.GetCount() - 1; ++i) { > ASelTbl = ATbls.GetItem(i); > if (ASelTbl != null && ASelTbl.FOuterJoin != null && ASelTbl.FOuterJoin.FRightTableItem == this) { > ASelTbl.FreeOuterJoin(); > } > } > FreeOuterJoin(); > super.Destroy(); > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtSelTableItem) { > FTableName = ((TRtSelTableItem) Source).FTableName; > FreeOuterJoin(); > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > { > TReader context_Reader = Reader; > FTableName = context_Reader.ReadString(); > FreeOuterJoin(); > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > { > TWriter context_Writer = Writer; > context_Writer.WriteString(FTableName); > } > } > > public TRtSelTableItemClass ClassType() { > return TRtSelTableItemClass.SINGLETON; > } > > public String getTableName() { > return FTableName; > } > > public TRtOuterJoinItem getOuterJoin() { > return FOuterJoin; > } > } > > public static final class TRtSelFromItemClass extends TSQLNamedListOwnerClass { > > public static final TRtSelFromItemClass SINGLETON = new TRtSelFromItemClass(); > > public final TRtSelFromItem CreateParented(TRtSelect AOwner) { > return TRtSelFromItem.CreateParented(AOwner); > } > > public Class<? extends TRtSelFromItem> ClassInfo() { > return TRtSelFromItem.class; > } > } > > public static final class TRtSelFromItem extends TSQLNamedListOwner { > > protected TContainerItemClass AllocItemType() { > return TRtSelTableItemClass.SINGLETON; > } > > public final TRtSelTableItem GetItem(int Index) { > return ((TRtSelTableItem) Get(Index)); > } > > protected final TRtSelTableItem NewTableAs(String ATblName, String AAlias) { > TRtSelTableItem Result; > CheckUnprepare(); > if (!StrIsBlank(AAlias)) { > Result = ItemByAlias(AAlias); > if (Result == null) { > if (StrIsBlank(ATblName)) { > ATblName = AAlias; > } > Result = TRtSelTableItem.CreateAddTable(this, ATblName, AAlias); > } > } else { > AAlias = ATblName; > Result = ItemByAlias(AAlias); > if (Result == null) { > Result = ItemByTableName(ATblName); > if (Result == null) { > Result = TRtSelTableItem.CreateAddTable(this, ATblName, AAlias); > } > } > } > return Result; > } > > public final void runCreateParented(TRtSelect AOwner) { > super.runCreate(); > SetFOwner(AOwner); > } > > public static TRtSelFromItem CreateParented(TRtSelect AOwner) { > TRtSelFromItem Result; > Result = new TRtSelFromItem(); > Result.runCreateParented(AOwner); > return Result; > } > > public void Assign(TPersistent Source) { > int i; > super.Assign(Source); > if (Source instanceof TRtSelFromItem) { > for (i = 0; i <= GetCount() - 1; ++i) { > if (((TRtSelFromItem) Source).GetItem(i).FOuterJoin != null) { > GetItem(i).FOuterJoin = TRtOuterJoinItem.Create(); > GetItem(i).FOuterJoin.Assign(((TRtSelFromItem) Source).GetItem(i).FOuterJoin); > } > } > } > } > > public void ReadData(TReader Reader) { > int i; > super.ReadData(Reader); > for (i = 0; i <= GetCount() - 1; ++i) { > if (Reader.ReadBoolean()) { > GetItem(i).FOuterJoin = TRtOuterJoinItem.Create(); > GetItem(i).FOuterJoin.ReadData(Reader); > } > } > } > > public void WriteData(TWriter Writer) { > int i; > boolean LOJ; > super.WriteData(Writer); > for (i = 0; i <= GetCount() - 1; ++i) { > LOJ = GetItem(i).FOuterJoin != null; > Writer.WriteBoolean(LOJ); > if (LOJ) { > GetItem(i).FOuterJoin.WriteData(Writer); > } > } > } > > public final void AddTableAs(String ATblName, String AAlias) { > NewTableAs(ATblName, AAlias); > } > > public final void AddTable(String ATblName) { > NewTableAs(ATblName, ATblName); > } > > public final TRtOuterJoinItem OuterJoinTables(String ALeftAlias, String ARightAlias, String ALeftFields, String ARightFields, int aOuterJoinOption) { > TRtSelTableItem ALeftTbl; > TRtSelTableItem ARightTbl; > CheckUnprepare(); > ALeftTbl = ItemByAlias(ALeftAlias); > if (ALeftTbl == null) { > throw DelphiException.CreateFmt(TransStr("TC430", "Tabela \"%s\" não encontrada na clausula FROM.", true), new Object[] { ALeftAlias }); > } > ARightTbl = ItemByAlias(ARightAlias); > if (ARightTbl == null) { > throw DelphiException.CreateFmt(TransStr("TC430", "Tabela \"%s\" não encontrada na clausula FROM.", true), new Object[] { ARightAlias }); > } > return TRtOuterJoinItem.CreateOuterJoin(ALeftTbl, ARightTbl, ALeftFields, ARightFields, aOuterJoinOption); > } > > public final TRtSelTableItem ItemByAlias(String AName) { > return ((TRtSelTableItem) ItemByName(AName)); > } > > public final TRtSelTableItem ItemByTableName(String AName) { > TRtSelTableItem Result; > int i; > for (i = 0; i <= GetCount() - 1; ++i) { > if (CompareText(this.GetItem(i).getTableName(), AName) == 0) { > Result = this.GetItem(i); > return Result; > } > } > return null; > } > > public final int RemoveByAlias(String AName) { > return RemoveByName(AName); > } > > public final int RemoveByTableName(String AName) { > int Result; > Result = IndexOf(ItemByTableName(AName)); > if (Result >= 0) { > Delete(Result); > } > return Result; > } > > public TRtSelFromItemClass ClassType() { > return TRtSelFromItemClass.SINGLETON; > } > } > > public static final class TRtSelUnionItemClass extends TSQLNamedContainerItemClass { > > public static final TRtSelUnionItemClass SINGLETON = new TRtSelUnionItemClass(); > > public final TRtSelUnionItem CreateParented(TRtSelect AOwner) { > return TRtSelUnionItem.CreateParented(AOwner); > } > > public Class<? extends TRtSelUnionItem> ClassInfo() { > return TRtSelUnionItem.class; > } > } > > public static final class TRtSelUnionItem extends TSQLNamedContainerItem { > > private boolean FAll; > private TRtSelect FSelect; > > public final void SetAll(boolean Value) { > CheckUnprepare(); > FAll = Value; > } > > public final void SetSelect(TRtSelect Value) { > int xDBVersionKind; > CheckUnprepare(); > if (FSelect == null) { > if (Value != null) { > xDBVersionKind = CheckOwnerSelect().getDBVersionKind(); > if (xDBVersionKind == dbvkSenior && CheckOwnerSelect().GetOwnerConnection() != null) { > xDBVersionKind = CheckOwnerSelect().GetOwnerConnection().getDBVersionKind(); > } > FSelect = ((TRtSelect) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckSelect, xDBVersionKind)); > FSelect.SetFOwner(this); > } > } > if (Value == null) { > if (FSelect != null) { > FSelect.Free(); > FSelect = null; > } > } else { > FSelect.Assign(Value); > } > } > > protected final TRtSelect CheckOwnerSelect() { > return ((TRtSelect) CheckTypedOwner(TRtSelectClass.SINGLETON)); > } > > public final void runCreateParented(TRtSelect AOwner) { > super.runCreate(); > SetFOwner(AOwner); > } > > public static TRtSelUnionItem CreateParented(TRtSelect AOwner) { > TRtSelUnionItem Result; > Result = new TRtSelUnionItem(); > Result.runCreateParented(AOwner); > return Result; > } > > public void Destroy() { > if (FSelect != null) { > FSelect.Free(); > } > super.Destroy(); > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtSelUnionItem) { > FAll = ((TRtSelUnionItem) Source).FAll; > SetSelect(((TRtSelUnionItem) Source).FSelect); > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > { > TReader context_Reader = Reader; > FAll = context_Reader.ReadBoolean(); > if (context_Reader.ReadBoolean()) { > if (FSelect == null) { > FSelect = ((TRtSelect) TRtDatabaseServerClass.SINGLETON.GlobalInstance().InstanceOfSQLClass(sckSelect, CheckOwnerSelect().getDBVersionKind())); > FSelect.SetFOwner(this); > } > FSelect.ReadData(Reader); > } else if (FSelect != null) { > FSelect.Free(); > FSelect = null; > } > } > } > > public void WriteData(TWriter Writer) { > boolean HasSelect; > super.WriteData(Writer); > { > TWriter context_Writer = Writer; > context_Writer.WriteBoolean(FAll); > HasSelect = FSelect != null; > context_Writer.WriteBoolean(HasSelect); > if (HasSelect) { > FSelect.WriteData(Writer); > } > } > } > > public TRtSelUnionItemClass ClassType() { > return TRtSelUnionItemClass.SINGLETON; > } > > public boolean getAll() { > return FAll; > } > > public TRtSelect getSelect() { > return FSelect; > } > } > > public static final class TRtSelOrderByItemClass extends TSQLKeyedContainerItemClass { > > public static final TRtSelOrderByItemClass SINGLETON = new TRtSelOrderByItemClass(); > > protected String GetKeyAsString(Object AKey) { > return ((TRtSelColumnsItem) AKey).GetName(); > } > > public final TRtSelOrderByItem CreateOrderByName(TRtSelOrderByList AOwner, String AColName, int AOrder) { > return TRtSelOrderByItem.CreateOrderByName(AOwner, AColName, AOrder); > } > > public final TRtSelOrderByItem CreateOrderByNumber(TRtSelOrderByList AOwner, int AColNumber, int AOrder) { > return TRtSelOrderByItem.CreateOrderByNumber(AOwner, AColNumber, AOrder); > } > > public Class<? extends TRtSelOrderByItem> ClassInfo() { > return TRtSelOrderByItem.class; > } > } > > public static final class TRtSelOrderByItem extends TSQLKeyedContainerItem { > > protected int FOrder; > protected TRtSelColumnsItem FColItem; > > protected final TRtSelColumnsItem GetItemByName(String AColName) { > TRtSelColumnsItem Result; > Result = CheckOwnerSelect().FColumns.ItemByAsName(AColName); > if (Result == null) { > Result = CheckOwnerSelect().FColumns.ItemByColumnName(AColName); > } > return Result; > } > > protected String GetKeyAsString(Object AKey) { > return ClassType().GetKeyAsString(AKey); > } > > protected Object GetKey() { > return FColItem; > } > > public final int GetColumnNumber() { > return CheckOwnerSelect().FColumns.IndexOf(FColItem) + 1; > } > > protected final TRtSelect CheckOwnerSelect() { > return ((TRtSelect) CheckTypedOwner(TRtSelectClass.SINGLETON)); > } > > public final void runCreateOrderByName(TRtSelOrderByList AOwner, String AColName, int AOrder) { > super.runCreate(); > AOwner.AddItem(this); > FColItem = GetItemByName(AColName); > if (FColItem == null) { > throw DelphiException.CreateFmt(TransStr("TC671", "Não existe coluna com este nome: \"%s\".", true), new Object[] { AColName }); > } > FOrder = AOrder; > } > > public static TRtSelOrderByItem CreateOrderByName(TRtSelOrderByList AOwner, String AColName, int AOrder) { > TRtSelOrderByItem Result; > Result = new TRtSelOrderByItem(); > Result.runCreateOrderByName(AOwner, AColName, AOrder); > return Result; > } > > public final void runCreateOrderByNumber(TRtSelOrderByList AOwner, int AColNumber, int AOrder) { > super.runCreate(); > if (AColNumber <= 0 || AColNumber > AOwner.CheckOwnerSelect().FColumns.GetCount()) { > throw DelphiException.Create(TransStrFmt("TC3308", "Número de coluna fora dos limites: \"%d\".", new Object[] { AColNumber }, true)); > } > FColItem = AOwner.CheckOwnerSelect().FColumns.GetItem(AColNumber - 1); > FOrder = AOrder; > AOwner.AddItem(this); > } > > public static TRtSelOrderByItem CreateOrderByNumber(TRtSelOrderByList AOwner, int AColNumber, int AOrder) { > TRtSelOrderByItem Result; > Result = new TRtSelOrderByItem(); > Result.runCreateOrderByNumber(AOwner, AColNumber, AOrder); > return Result; > } > > public void Assign(TPersistent Source) { > super.Assign(Source); > if (Source instanceof TRtSelOrderByItem) { > FColItem = GetItemByName(((TRtSelOrderByItem) Source).FColItem.GetName()); > FOrder = ((TRtSelOrderByItem) Source).FOrder; > } > } > > public void ReadData(TReader Reader) { > super.ReadData(Reader); > { > TReader context_Reader = Reader; > FColItem = GetItemByName(context_Reader.ReadString()); > context_Reader.Read(AsVar(FOrder), SizeOf(FOrder)); > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > { > TWriter context_Writer = Writer; > context_Writer.WriteString(FColItem.GetName()); > context_Writer.Write(AsConst(FOrder), SizeOf(FOrder)); > } > } > > public TRtSelOrderByItemClass ClassType() { > return TRtSelOrderByItemClass.SINGLETON; > } > > public TRtSelColumnsItem getColumnItem() { > return FColItem; > } > > public int getOrder() { > return FOrder; > } > } > > public static final class TRtSelOrderByListClass extends TSQLKeyedListOwnerClass { > > public static final TRtSelOrderByListClass SINGLETON = new TRtSelOrderByListClass(); > > public final TRtSelOrderByList CreateParented(TRtSelect AOwner) { > return TRtSelOrderByList.CreateParented(AOwner); > } > > public Class<? extends TRtSelOrderByList> ClassInfo() { > return TRtSelOrderByList.class; > } > } > > public static final class TRtSelOrderByList extends TSQLKeyedListOwner { > > protected TContainerItemClass AllocItemType() { > return TRtSelOrderByItemClass.SINGLETON; > } > > public final TRtSelOrderByItem GetItem(int Index) { > return ((TRtSelOrderByItem) Get(Index)); > } > > protected final TRtSelect CheckOwnerSelect() { > return ((TRtSelect) CheckTypedOwner(TRtSelectClass.SINGLETON)); > } > > public final void runCreateParented(TRtSelect AOwner) { > super.runCreate(); > SetFOwner(AOwner); > } > > public static TRtSelOrderByList CreateParented(TRtSelect AOwner) { > TRtSelOrderByList Result; > Result = new TRtSelOrderByList(); > Result.runCreateParented(AOwner); > return Result; > } > > public final void AddColumnByName(String AColName, int AOrder) { > CheckUnprepare(); > TRtSelOrderByItem.CreateOrderByName(this, AColName, AOrder); > } > > public final void AddColumnByNumber(int AColNum, int AOrder) { > CheckUnprepare(); > TRtSelOrderByItem.CreateOrderByNumber(this, AColNum, AOrder); > } > > public final void AddColumnsByNames(String AColNames, int AOrder) { > TInt p = new TInt(); > String s = ""; > p.v = 0; > s = StrGetNextToken(AColNames, p, ";"); > while (!StrIsBlank(s)) { > AddColumnByName(s, AOrder); > s = StrGetNextToken(AColNames, p, ";"); > } > } > > public final void AddColumnsByNumbers(String AColNums, int AOrder) { > TInt p = new TInt(); > String s = ""; > p.v = 0; > s = StrGetNextToken(AColNums, p, ";"); > while (!StrIsBlank(s)) { > AddColumnByNumber(StrToInt(s), AOrder); > s = StrGetNextToken(AColNums, p, ";"); > } > } > > public final TRtSelOrderByItem ItemByName(String AColName) { > TRtSelOrderByItem Result; > int i; > for (i = 0; i <= GetCount() - 1; ++i) { > if (CompareText(this.GetItem(i).FColItem.GetName(), AColName) == 0) { > Result = this.GetItem(i); > return Result; > } > } > return null; > } > > public final TRtSelOrderByItem ItemByNumber(int AColNum) { > TRtSelOrderByItem Result; > int i; > for (i = 0; i <= GetCount() - 1; ++i) { > if (this.GetItem(i).GetColumnNumber() == AColNum) { > Result = this.GetItem(i); > return Result; > } > } > return null; > } > > public final int RemoveByName(String AColName) { > int Result; > Result = IndexOf(ItemByName(AColName)); > if (Result >= 0) { > Delete(Result); > } > return Result; > } > > public final int RemoveByNumber(int AColNum) { > int Result; > Result = IndexOf(ItemByNumber(AColNum)); > if (Result >= 0) { > Delete(Result); > } > return Result; > } > > public TRtSelOrderByListClass ClassType() { > return TRtSelOrderByListClass.SINGLETON; > } > } > > public static class TRtSelectClass extends TRtCustomSelectSQLClass { > > public static final TRtSelectClass SINGLETON = new TRtSelectClass(); > > public TRtSelect Create() { > return TRtSelect.Create(); > } > > public final TRtSelect CreateSQL(TRtDBConnection AConn) { > return TRtSelect.CreateSQL(AConn); > } > > public Class<? extends TRtSelect> ClassInfo() { > return TRtSelect.class; > } > } > > public static class TRtSelect extends TRtCustomSelectSQL { > > private final class GenBaseSQL_Context { > > private String Result = ""; > > private String ListColumns() { > String Result = ""; > int LastBreak; > int I; > String TableName = ""; > String AsName = ""; > String ColumnName = ""; > Result = ""; > LastBreak = 0; > for (I = 0; I <= getColumns().GetCount() - 1; ++I) { > if (LastBreak < I / 10 && I < getColumns().GetCount() - 1) { > LastBreak = I / 10; > Result = Result + SQL_EOL; > } > TableName = ""; > ColumnName = ""; > AsName = ""; > if (!getColumns().GetItem(I).GetIsEnumDescription()) { > if (!getColumns().GetItem(I).GetIsExp()) { > if (!StrIsBlank(getColumns().GetItem(I).getFromItem().GetName())) { > TableName = getColumns().GetItem(I).getFromItem().GetName(); > } else { > TableName = getColumns().GetItem(I).getFromItem().GetName(); > } > ColumnName = getColumns().GetItem(I).getColumnName(); > AsName = getColumns().GetItem(I).GetName(); > if (Pos(SQL_Point, ColumnName) == 0) { > Result = Result + TableName + SQL_Point + ColumnName + SQL_Space + AsName; > } else { > Result = Result + ColumnName + SQL_Space + AsName; > } > } else { > AsName = getColumns().GetItem(I).GetName(); > ColumnName = TranslateExpression(TRtSelect.this, getColumns().GetItem(I).getExpTokens()); > Result = Result + ColumnName + SQL_Space + AsName; > } > Result = TrimRight(Result) + ToStr(SQL_Comma); > } > } > if (!Result.equals("")) { > Result = Delete(Result, Length(Result), 1); > } > return Result; > } > > private String ListVariables() { > String Result = ""; > int I; > Result = ""; > if (FInto.GetCount() > 0) { > for (I = 0; I <= FInto.GetCount() - 1; ++I) { > Result = Result + TranslateExpression(TRtSelect.this, FInto.GetItems(I).getTokens()) + ToStr(SQL_Comma); > } > Result = Delete(Result, Length(Result), 1); > Result = SQL_Space + SQL_Into + Result; > } > return Result; > } > > private String GetFrom() { > String Result = ""; > int I; > Result = ""; > for (I = 0; I <= getFrom().GetCount() - 1; ++I) { > Result = Result + getFrom().GetItem(I).getTableName() + SQL_Space + getFrom().GetItem(I).GetName(); > Result = TrimRight(Result) + ToStr(SQL_Comma); > } > if (Length(Result) > 0) { > Result = Delete(Result, Length(Result), 1); > Result = SQL_Space + SQL_From + Result; > } > return Result; > } > > private String GetGroupByColumns() { > String Result = ""; > int I; > String s = ""; > Result = ""; > for (I = 0; I <= getColumns().GetCount() - 1; ++I) { > if (getColumns().GetItem(I).getIsGroupBy()) { > Result = Result + getColumns().GetItem(I).getColumnName() + ToStr(SQL_Comma); > } > } > if (Length(Result) != 0) { > Result = Delete(Result, Length(Result), 1); > Result = SQL_Space + SQL_GroupBy + Result; > s = BreakLine(GetWhere(TRtSelect.this, getHaving())); > if (!StrIsBlank(s)) { > Result = Result + SQL_Space + SQL_Having + s; > } > } > return Result; > } > > private String GetUnionClause() { > String Result = ""; > Result = ""; > if (getUnion().getSelect() != null) { > Result = SQL_Union; > if (getUnion().getAll()) { > Result = Result + SQL_All; > } > Result = Result + SQL_LParenthesis + getUnion().getSelect().GetSQL() + ToStr(SQL_RParenthesis); > } > return Result; > } > > private String GetOrderByColumns() { > String Result = ""; > int I; > Result = ""; > for (I = 0; I <= getOrderBy().GetCount() - 1; ++I) { > if (getOrderBy().GetItem(I).GetColumnNumber() != -1) { > Result = Result + IntToStr(getOrderBy().GetItem(I).GetColumnNumber()); > } else if (Length(getOrderBy().GetItem(I).getColumnItem().GetName()) != 0) { > Result = Result + getOrderBy().GetItem(I).getColumnItem().GetName(); > } else { > Result = Result + getOrderBy().GetItem(I).getColumnItem().getColumnName(); > } > if (getOrderBy().GetItem(I).getOrder() != risDesc) { > Result = Result + SQL_Space + SQL_ASC; > } else { > Result = Result + SQL_Space + SQL_DESC; > } > Result = Result + ToStr(SQL_Comma); > } > if (Length(Result) != 0) { > Result = Delete(Result, Length(Result), 1); > Result = SQL_Space + SQL_OrderBy + Result; > } > return Result; > } > > private String s = ""; > > public GenBaseSQL_Context() { > } > > public String execute() { > FixUnresolvedRefs(); > Result = SQL_Select + BreakLine(ListColumns()) + BreakLine(ListVariables()) + BreakLine(GetFrom()); > s = BreakLine(GetWhere(TRtSelect.this, getWhere())); > if (!StrIsBlank(s)) { > Result = Result + SQL_Space + SQL_Where + s; > } > Result = Result + BreakLine(GetGroupByColumns()) + BreakLine(GetUnionClause()) + BreakLine(GetOrderByColumns()); > if (getForUpdate()) { > Result = Result + SQL_Space + SQL_ForUpdate; > } > if (getUsesScriptTerminator()) { > Result = Result + ToStr(SQL_ScriptTerminator); > } > return Result; > } > } > > private boolean FDistinct; > > public final void SetDistinct(boolean Value) { > CheckUnprepare(); > FDistinct = Value; > } > > public boolean GetHasOperation() { > return FColumns.GetCount() > 0 && FInto.GetCount() > 0; > } > > protected TRtSelColumnsList FColumns; > protected TRtExpressionList FInto; > protected TRtSelFromItem FFrom; > protected TRtWhereItem FWhere; > protected TRtWhereItem FHaving; > protected TRtSelUnionItem FUnion; > protected TRtSelOrderByList FOrderBy; > protected boolean FForUpdate; > > protected final void Init() { > FColumns = ((TRtSelColumnsList) Creator(this, TRtSelColumnsListClass.SINGLETON)); > FInto = ((TRtExpressionList) Creator(this, TRtExpressionListClass.SINGLETON)); > FFrom = ((TRtSelFromItem) Creator(this, TRtSelFromItemClass.SINGLETON)); > FWhere = ((TRtWhereItem) Creator(this, TRtWhereItemClass.SINGLETON)); > FHaving = ((TRtWhereItem) Creator(this, TRtWhereItemClass.SINGLETON)); > FUnion = ((TRtSelUnionItem) Creator(this, TRtSelUnionItemClass.SINGLETON)); > FOrderBy = ((TRtSelOrderByList) Creator(this, TRtSelOrderByListClass.SINGLETON)); > } > > protected final void AddParamsToOwnerSQLClass(TRtCustomSQL ASql) { > int i; > for (i = 0; i <= FInto.GetCount() - 1; ++i) { > FInto.GetItems(i).AddParamsToOwnerSQLClass(ASql); > } > FWhere.AddParamsToOwnerSQLClass(ASql); > FHaving.AddParamsToOwnerSQLClass(ASql); > if (FUnion.getSelect() != null) { > FUnion.getSelect().AddParamsToOwnerSQLClass(ASql); > } > } > > protected final void DropParamsFromOwnerSQLClass(TRtCustomSQL ASql) { > int i; > for (i = 0; i <= FInto.GetCount() - 1; ++i) { > FInto.GetItems(i).DropParamsFromOwnerSQLClass(ASql); > } > FWhere.DropParamsFromOwnerSQLClass(ASql); > FHaving.DropParamsFromOwnerSQLClass(ASql); > if (FUnion.getSelect() != null) { > FUnion.getSelect().DropParamsFromOwnerSQLClass(ASql); > } > } > > protected final void _CheckUnresolvedRefs(boolean LFix) { > int i; > i = 0; > while (i < FColumns.GetCount()) { > { > TRtSelColumnsItem context_GetItem = FColumns.GetItem(i); > if (context_GetItem.GetIsExp() || context_GetItem.GetIsEnumDescription()) { > i++; > continue; > } > context_GetItem.FFromItem = FFrom.ItemByAlias(context_GetItem.FFromAlias); > if (context_GetItem.FFromItem == null) { > context_GetItem.FFromItem = FFrom.ItemByTableName(context_GetItem.FFromAlias); > } > if (context_GetItem.FFromItem == null) { > if (LFix) { > FColumns.GetItem(i).Free(); > } else { > ErrRef(context_GetItem.FFromAlias); > } > } else { > i++; > } > } > } > if (LFix) { > _CheckForOuterJoins(); > } > } > > protected void _CheckForOuterJoins() { > int i; > TRtSQLTokenList ATokens; > boolean LeftOJoin; > boolean xTokenTypeIsConst; > ATokens = FWhere.getTokens(); > i = 0; > while (i < ATokens.GetCount()) { > if (ATokens.GetItem(i).getTokType() == rstOpSQLJoin) { > if (ATokens.GetItem(i - 1).getTokType() == rstOpSQLOuterJoin) { > SetOuterJoinForField(ATokens.GetItem(i - 2).getToken(), ATokens.GetItem(i - 2).getTokType(), ATokens.GetItem(i + 1).getToken(), ATokens.GetItem(i + 1).getTokType(), ojLeft); > } > if (i + 2 < ATokens.GetCount() && ATokens.GetItem(i + 2).getTokType() == rstOpSQLOuterJoin) { > SetOuterJoinForField(ATokens.GetItem(i + 1).getToken(), ATokens.GetItem(i + 1).getTokType(), ATokens.GetItem(i - 1).getToken(), ATokens.GetItem(i - 1).getTokType(), ojRight); > } > } > i++; > } > i = 0; > while (i < ATokens.GetCount()) { > xTokenTypeIsConst = i < ATokens.GetCount() - 1 && DelphiSet.get(rstConstBoolean, rstConstInt, rstConstFloat, rstConstDate, rstConstTime, rstConstDateTime, rstConstString, rstConstNull).contains(ATokens.GetItem(i + 1).getTokType()); > if (ATokens.GetItem(i).getTokType() == rstOpSQLJoin && ATokens.GetItem(i - 1).getTokType() != rstOpSQLOuterJoin && (i + 2 >= ATokens.GetCount() || ATokens.GetItem(i + 2).getTokType() != rstOpSQLOuterJoin) && !xTokenTypeIsConst) { > if (IsOuterJoinField(ATokens.GetItem(i - 1).getToken(), ATokens.GetItem(i - 1).getTokType())) { > ATokens.InsertOuterJoin(i); > i++; > LeftOJoin = true; > } else { > LeftOJoin = false; > } > if (IsOuterJoinField(ATokens.GetItem(i + 1).getToken(), ATokens.GetItem(i + 1).getTokType())) { > if (LeftOJoin) { > throw DelphiException.Create(TransStr("TC672", "\"OUTER JOIN\" circular não suportado.", true)); > } > ATokens.InsertOuterJoin(i + 2); > i++; > } > } > i++; > } > } > > protected final TRtSelTableItem TableOfColumnRef(String aToken, int ATokType) { > TRtSelTableItem Result; > TRtSelColumnsItem ASelColItem; > String s = ""; > int APos; > Result = null; > s = ""; > if (ATokType == rstIdColumn) { > ASelColItem = FColumns.ItemByAsName(aToken); > if (ASelColItem == null) { > ASelColItem = FColumns.ItemByColumnName(aToken); > } > if (ASelColItem != null) { > Result = ASelColItem.FFromItem; > if (Result == null) { > s = ASelColItem.FFromAlias; > } else { > return Result; > } > } else { > return Result; > } > } else { > APos = Pos(".", aToken); > s = Copy(aToken, 1, APos - 1); > } > Result = FFrom.ItemByAlias(s); > if (Result == null) { > Result = FFrom.ItemByTableName(s); > } > return Result; > } > > protected final boolean IsOuterJoinField(String aToken, int ATokType) { > TRtSelTableItem ASelTblItem; > ASelTblItem = TableOfColumnRef(aToken, ATokType); > return ASelTblItem != null && ASelTblItem.FOuterJoin != null; > } > > protected final void SetOuterJoinForField(String ALeftToken, int ALeftTokType, String ARightToken, int ARightTokType, int aOuterJoinOption) { > TRtSelTableItem aLSelTblItem; > TRtSelTableItem aRSelTblItem; > aLSelTblItem = TableOfColumnRef(ALeftToken, ALeftTokType); > aRSelTblItem = TableOfColumnRef(ARightToken, ARightTokType); > if (aLSelTblItem != null && aLSelTblItem.getOuterJoin() == null && aRSelTblItem != null) { > (((TRtSelFromItem) aLSelTblItem.GetFOwner())).OuterJoinTables(aLSelTblItem.GetName(), aRSelTblItem.GetName(), ALeftToken, ARightToken, aOuterJoinOption); > } > } > > protected final void _CheckUnresolvedRefsOnExpressions(TRtWhereItem AWhere, boolean LFix) { > int i; > TInt p = new TInt(); > String AName = ""; > i = 0; > while (i < AWhere.FTokens.GetCount()) { > { > TRtSQLTokenItem context_GetItem = AWhere.FTokens.GetItem(i); > if (context_GetItem.getTokType() == rstIdTableColumn) { > p.v = 0; > AName = StrGetNextToken(context_GetItem.getToken(), p, '.'); > if (FFrom.ItemByAlias(AName) == null && FFrom.ItemByTableName(AName) == null && OwnerSQLToAlias(AName) == null) { > ErrRef(AName); > } else { > i++; > } > } else { > i++; > } > } > } > } > > protected final TRtCustomSQL OwnerSQLToAlias(String AAlias) { > TRtCustomSQL Result; > TRtCustomSQL AOwner; > Result = null; > AOwner = ((TRtCustomSQL) GetTypedOwner(TRtCustomSQLClass.SINGLETON)); > if (AOwner instanceof TRtSelect) { > if (((TRtSelect) AOwner).FFrom.ItemByAlias(AAlias) != null || ((TRtSelect) AOwner).FFrom.ItemByTableName(AAlias) != null) { > Result = AOwner; > } else { > Result = ((TRtSelect) AOwner).OwnerSQLToAlias(AAlias); > } > } else if (AOwner instanceof TRtAliasedTableSQL) { > if (CompareText(((TRtAliasedTableSQL) AOwner).getAlias(), AAlias) == 0 || CompareText(((TRtAliasedTableSQL) AOwner).GetName(), AAlias) == 0) { > Result = AOwner; > } > } else if (AOwner instanceof TRtAliasedTableSQL) { > if (CompareText(((TRtAliasedTableSQL) AOwner).GetName(), AAlias) == 0) { > Result = AOwner; > } > } > return Result; > } > > protected final void ErrRef(String AName) { > throw DelphiException.CreateFmt(TransStr("TC673", "Referência para \"%s\", não encontrada.", true), new Object[] { AName }); > } > > protected String GenSQL() { > return GenBaseSQL(); > } > > public String GenBaseSQL() { > GenBaseSQL_Context ctx = new GenBaseSQL_Context(); > return ctx.execute(); > } > > public final void SetForUpdate(boolean Value) { > CheckUnprepare(); > if (GetTypedOwner(TRtCustomSQLClass.SINGLETON) != null) { > FForUpdate = false; > } else { > FForUpdate = Value; > } > } > > public final boolean GetIsSubQuery() { > return GetRootSQL() != null; > } > > protected String GetDistinct() { > String Result = ""; > if (FDistinct) { > Result = "DISTINCT"; > } else { > Result = ""; > } > return Result; > } > > public void runCreate() { > super.runCreate(); > Init(); > } > > public static TRtSelect Create() { > TRtSelect Result; > Result = new TRtSelect(); > Result.runCreate(); > return Result; > } > > public final void runCreateSQL(TRtDBConnection AConn) { > super.runCreateSQL(AConn); > Init(); > } > > public static TRtSelect CreateSQL(TRtDBConnection AConn) { > TRtSelect Result; > Result = new TRtSelect(); > Result.runCreateSQL(AConn); > return Result; > } > > public void Destroy() { > FFrom.Free(); > FColumns.Free(); > FInto.Free(); > FWhere.Free(); > FHaving.Free(); > FUnion.Free(); > FOrderBy.Free(); > super.Destroy(); > } > > public final void CheckUnresolvedRefs() { > _CheckUnresolvedRefs(false); > } > > public final void FixUnresolvedRefs() { > _CheckUnresolvedRefs(true); > } > > public void Assign(TPersistent Source) { > FAssigning++; > try { > super.Assign(Source); > if (Source instanceof TRtSelect) { > FDistinct = ((TRtSelect) Source).FDistinct; > FFrom.Assign(((TRtSelect) Source).FFrom); > FWhere.Assign(((TRtSelect) Source).FWhere); > FColumns.Assign(((TRtSelect) Source).FColumns); > FInto.Assign(((TRtSelect) Source).FInto); > FUnion.Assign(((TRtSelect) Source).FUnion); > FOrderBy.Assign(((TRtSelect) Source).FOrderBy); > SetForUpdate(((TRtSelect) Source).FForUpdate); > } > } finally { > FAssigning--; > } > } > > public void ReadData(TReader Reader) { > FAssigning++; > try { > super.ReadData(Reader); > FDistinct = Reader.ReadBoolean(); > FFrom.ReadData(Reader); > FWhere.ReadData(Reader); > FColumns.ReadData(Reader); > FInto.ReadData(Reader); > FUnion.ReadData(Reader); > FOrderBy.ReadData(Reader); > SetForUpdate(Reader.ReadBoolean()); > } finally { > FAssigning--; > } > } > > public void WriteData(TWriter Writer) { > super.WriteData(Writer); > Writer.WriteBoolean(FDistinct); > FFrom.WriteData(Writer); > FWhere.WriteData(Writer); > FColumns.WriteData(Writer); > FInto.WriteData(Writer); > FUnion.WriteData(Writer); > FOrderBy.WriteData(Writer); > AddParamsToOwnerSQLClass(null); > Writer.WriteBoolean(FForUpdate); > } > > public TRtSelectClass ClassType() { > return TRtSelectClass.SINGLETON; > } > > public boolean getDistinct() { > return FDistinct; > } > > public TRtSelColumnsList getColumns() { > return FColumns; > } > > public TRtExpressionList getInto() { > return FInto; > } > > public TRtSelFromItem getFrom() { > return FFrom; > } > > public TRtWhereItem getWhere() { > return FWhere; > } > > public TRtWhereItem getHaving() { > return FHaving; > } > > public TRtSelUnionItem getUnion() { > return FUnion; > } > > public TRtSelOrderByList getOrderBy() { > return FOrderBy; > } > > public boolean getForUpdate() { > return FForUpdate; > } > } > > public static class TRtCustomStorageClass extends TClass { > > public static final TRtCustomStorageClass SINGLETON = new TRtCustomStorageClass(); > > public TRtCustomStorage Create(TRtCustomStorageList _Owner) { > return TRtCustomStorage.Create(_Owner); > } > > public Class<? extends TRtCustomStorage> ClassInfo() { > return TRtCustomStorage.class; > } > } > > public static class TRtCustomStorage extends TObject { > > private TRtCustomStorageList FOwner; > > public final String GetName() { > String Result = ""; > int i; > Result = ""; > if (FOwner != null) { > i = FOwner.FStorageList.IndexOfObject(this); > if (i >= 0) { > Result = FOwner.FStorageList.Get(i); > } > } > return Result; > } > > public String GetGeneralInfo() { > return ""; > } > > public void runCreate(TRtCustomStorageList _Owner) { > super.runCreate(); > FOwner = _Owner; > } > > public static TRtCustomStorage Create(TRtCustomStorageList _Owner) { > TRtCustomStorage Result; > Result = new TRtCustomStorage(); > Result.runCreate(_Owner); > return Result; > } > > public TRtCustomStorageClass ClassType() { > return TRtCustomStorageClass.SINGLETON; > } > } > > public static final class TRtCustomStorageListClass extends TClass { > > public static final TRtCustomStorageListClass SINGLETON = new TRtCustomStorageListClass(); > > public TRtCustomStorageList Create(TRtDBConnection _Owner) { > return TRtCustomStorageList.Create(_Owner); > } > > public Class<? extends TRtCustomStorageList> ClassInfo() { > return TRtCustomStorageList.class; > } > } > > public static final class TRtCustomStorageList extends TObject { > > TStringList FStorageList; > > public final TRtCustomStorage GetStorages(int _index) { > return ((TRtCustomStorage) FStorageList.GetObject(_index)); > } > > public final int GetCount() { > return FStorageList.GetCount(); > } > > public void runCreate(TRtDBConnection _Owner) { > super.runCreate(); > FStorageList = TStringList.Create(); > FStorageList.SetSorted(true); > FStorageList.setDuplicates(dupError); > } > > public static TRtCustomStorageList Create(TRtDBConnection _Owner) { > TRtCustomStorageList Result; > Result = new TRtCustomStorageList(); > Result.runCreate(_Owner); > return Result; > } > > public void Destroy() { > super.Destroy(); > ClearStorageList(); > FStorageList.Free(); > } > > public final TRtCustomStorage StorageByName(String _name) { > TRtCustomStorage Result; > int i; > i = FStorageList.IndexOf(_name); > if (i < 0) { > Result = null; > } else { > Result = ((TRtCustomStorage) FStorageList.GetObject(i)); > } > return Result; > } > > public final int Add(String _identity, TRtCustomStorage _CustomStorage) { > int Result; > try { > Result = FStorageList.AddObject(_identity, _CustomStorage); > } catch (DelphiException e) { > throw DelphiException.Create(TransStrFmt("TC6907", "Erro ao carregar storage do objeto %s: %s", new Object[] { _identity, e.getMessage() })); > } > return Result; > } > > public final void Delete(String _identity) { > int i; > i = FStorageList.IndexOf(_identity); > if (i > -1) { > FStorageList.Delete(i); > } > } > > public final void ClearStorageList() { > int i; > for (i = 0; i <= FStorageList.GetCount() - 1; ++i) { > ((TObject) FStorageList.GetObject(i)).Free(); > } > FStorageList.Clear(); > } > > public final boolean HasStorage() { > return FStorageList.GetCount() > 0; > } > > public TRtCustomStorageListClass ClassType() { > return TRtCustomStorageListClass.SINGLETON; > } > } > > public static class TRtCustomTablePrivilegesClass extends TClass { > > public static final TRtCustomTablePrivilegesClass SINGLETON = new TRtCustomTablePrivilegesClass(); > > public final TRtCustomTablePrivileges Create(TRtCustomTablePrivilegesList aOwner) { > return TRtCustomTablePrivileges.Create(aOwner); > } > > public Class<? extends TRtCustomTablePrivileges> ClassInfo() { > return TRtCustomTablePrivileges.class; > } > } > > public static class TRtCustomTablePrivileges extends TObject { > > private TRtCustomTablePrivilegesList FOwner; > > public final String GetName() { > String Result = ""; > int xIndex; > Result = ""; > if (FOwner != null) { > xIndex = FOwner.FPrivilegesList.IndexOfObject(this); > if (xIndex >= 0) { > Result = FOwner.FPrivilegesList.Get(xIndex); > } > } > return Result; > } > > public final void runCreate(TRtCustomTablePrivilegesList aOwner) { > super.runCreate(); > FOwner = aOwner; > } > > public static TRtCustomTablePrivileges Create(TRtCustomTablePrivilegesList aOwner) { > TRtCustomTablePrivileges Result; > Result = new TRtCustomTablePrivileges(); > Result.runCreate(aOwner); > return Result; > } > > public TRtCustomTablePrivilegesClass ClassType() { > return TRtCustomTablePrivilegesClass.SINGLETON; > } > } > > public static final class TRtCustomTablePrivilegesListClass extends TClass { > > public static final TRtCustomTablePrivilegesListClass SINGLETON = new TRtCustomTablePrivilegesListClass(); > > public final TRtCustomTablePrivilegesList Create() { > return TRtCustomTablePrivilegesList.Create(); > } > > public Class<? extends TRtCustomTablePrivilegesList> ClassInfo() { > return TRtCustomTablePrivilegesList.class; > } > } > > public static final class TRtCustomTablePrivilegesList extends TObject { > > TStringList FPrivilegesList; > > public final void runCreate() { > super.Create(); > FPrivilegesList = TStringList.Create(); > FPrivilegesList.SetSorted(true); > FPrivilegesList.setDuplicates(dupError); > } > > public static TRtCustomTablePrivilegesList Create() { > TRtCustomTablePrivilegesList Result; > Result = new TRtCustomTablePrivilegesList(); > Result.runCreate(); > return Result; > } > > public void Destroy() { > ClearPrivilegesList(); > FPrivilegesList.Destroy(); > super.Destroy(); > } > > public final void ClearPrivilegesList() { > int i; > for (i = 0; i <= FPrivilegesList.GetCount() - 1; ++i) { > ((TObject) FPrivilegesList.GetObject(i)).Free(); > } > FPrivilegesList.Clear(); > } > > public final int Add(String aTableName, TRtCustomTablePrivileges aCustomPrivileges) { > return FPrivilegesList.AddObject(aTableName, aCustomPrivileges); > } > > public final TRtCustomTablePrivileges PrivilegesByTableName(String aTableName) { > TRtCustomTablePrivileges Result; > int i; > i = FPrivilegesList.IndexOf(aTableName); > if (i < 0) { > Result = null; > } else { > Result = ((TRtCustomTablePrivileges) FPrivilegesList.GetObject(i)); > } > return Result; > } > > public TRtCustomTablePrivilegesListClass ClassType() { > return TRtCustomTablePrivilegesListClass.SINGLETON; > } > } > > private static final class CompileViewSelect_Context { > > private final TRtDatabaseDef aDataBaseDef; > private final String aViewName; > private final String aSelect_SeniorSQL_2; > private TSQLStatement Result; > private final static String cCreateView = "CREATE VIEW %s AS %s"; > private TSQLWorks xSQLWorks; > > public CompileViewSelect_Context(TRtDatabaseDef aDataBaseDef, String aViewName, String aSelect_SeniorSQL_2) { > this.aDataBaseDef = aDataBaseDef; > this.aViewName = aViewName; > this.aSelect_SeniorSQL_2 = aSelect_SeniorSQL_2; > } > > public TSQLStatement execute() { > xSQLWorks = TSQLWorks.Create(aDataBaseDef); > try { > Result = xSQLWorks.CompileStatement(Format(cCreateView, new Object[] { aViewName, aSelect_SeniorSQL_2 })); > } finally { > xSQLWorks.Free(); > } > return Result; > } > } > > private static final class TInsSelFieldPairsClass extends TClass { > > public static final TInsSelFieldPairsClass SINGLETON = new TInsSelFieldPairsClass(); > > public final TInsSelFieldPairs Create() { > return TInsSelFieldPairs.Create(); > } > > public Class<? extends TInsSelFieldPairs> ClassInfo() { > return TInsSelFieldPairs.class; > } > } > > private static final class TInsSelFieldPairs extends TObject { > > public TStringList Ins; > public TStringList Sel; > > public final void runCreate() { > super.runCreate(); > Ins = TStringList.Create(); > Sel = TStringList.Create(); > } > > public static TInsSelFieldPairs Create() { > TInsSelFieldPairs Result; > Result = new TInsSelFieldPairs(); > Result.runCreate(); > return Result; > } > > public void Destroy() { > Ins.Free(); > Sel.Free(); > super.Destroy(); > } > > public TInsSelFieldPairsClass ClassType() { > return TInsSelFieldPairsClass.SINGLETON; > } > } > > static final class TAuxAddField { > > public TList List; > public TRtDatabaseDef Database; > > final void assign(TAuxAddField other) { > List = other.List; > Database = other.Database; > } > > public TAuxAddField(TList List, TRtDatabaseDef Database) { > this.List = List; > this.Database = Database; > } > > public TAuxAddField() { > } > } > > private static final class DoVisitFindFields_Context { > > private final TAuxAddField aAuxAddField; > private final int aObjType; > private final Object aObj; > > private void AddField(TRtFieldDef aField) { > if (aAuxAddField.List.IndexOf(aField) == -1) { > aAuxAddField.List.Add(aField); > } > } > > public DoVisitFindFields_Context(TAuxAddField aAuxAddField, int aObjType, Object aObj) { > this.aAuxAddField = aAuxAddField; > this.aObjType = aObjType; > this.aObj = aObj; > } > > public void execute() { > switch (aObjType) { > case cST_NameExpr: > AddField(aAuxAddField.Database.CheckRowSetByName(((TNameExpr) aObj).Table.Name).CheckFieldByName(((TNameExpr) aObj).Name)); > break; > case cST_QualifiedNameExpr: > AddField(aAuxAddField.Database.CheckRowSetByName(((TQualifiedNameExpr) aObj).Table.Name).CheckFieldByName(((TQualifiedNameExpr) aObj).Name)); > break; > default: > break; > } > } > } > > private static final class TranslateExpression_Context { > > private final TRtCustomSQL SQL; > private final TRtSQLTokenList TokenList; > private String Result = ""; > > private String TranslateToken(TRtSQLTokenList TokenList, int i) { > String Result = ""; > TRtSQLTokenItem AToken; > AToken = TokenList.GetItem(i); > Result = ""; > long switcher = AToken.getTokType(); > if (switcher >= rstOpLogOr && switcher <= rstOpLogNot) { > Result = EOL + AToken.getToken(); > } else if (switcher == rstIdParamSubQuery) { > Result = ToStr(SQL_Space) + SQL.GetSelectParams().ItemByName(AToken.getToken()).GetSelect().GetSQL(); > } else if (switcher == rstConstString) { > Result = '\'' + AToken.getToken() + "'"; > } else if (switcher == rstConstDate) { > Result = SQL_Convert + SQL_LParenthesis + SQLCharToDate + SQL_Comma + SQL_Quotes + AToken.getToken() + SQL_Quotes + ToStr(SQL_RParenthesis); > } else if (switcher == rstOpColon) { > if (i + 1 >= TokenList.GetCount() || TokenList.GetItem(i).getTokType() != rstOpGroupLeft) { > Result = ToStr(SQL_Space) + AToken.getToken(); > } > } else { > Result = ToStr(SQL_Space) + AToken.getToken(); > } > return Result; > } > > private int i; > > public TranslateExpression_Context(TRtCustomSQL SQL, TRtSQLTokenList TokenList) { > this.SQL = SQL; > this.TokenList = TokenList; > } > > public String execute() { > Result = ""; > for (i = 0; i <= TokenList.GetCount() - 1; ++i) { > Result = Result + TranslateToken(TokenList, i); > } > return TrimLeft(Result); > } > } > > static final class TParallelTimerClass extends TClass { > > public static final TParallelTimerClass SINGLETON = new TParallelTimerClass(); > > final TParallelTimer CreateTimer(TRtDBConnection aConnection) { > return TParallelTimer.CreateTimer(aConnection); > } > > public Class<? extends TParallelTimer> ClassInfo() { > return TParallelTimer.class; > } > } > > static final class TParallelTimer extends TObject { > > private TRtDBConnection FConnection; > > protected final void runCreateTimer(TRtDBConnection aConnection) { > // super.runCreate(Application); > // SetEnabled(true); > // SetInterval(StrToInt(aConnection.getParam().GetValues(cParallelConTimmer)) * 1000); > // FConnection = aConnection; > // SetOnTimer(FreeConn); > throw pending(); > } > > static TParallelTimer CreateTimer(TRtDBConnection aConnection) { > TParallelTimer Result; > Result = new TParallelTimer(); > Result.runCreateTimer(aConnection); > return Result; > } > > final void FreeConn(TObject Sender) { > FConnection.FParallelTimer = null; > FConnection.FParallelConn = null; > Destroy(); > } > > public TParallelTimerClass ClassType() { > return TParallelTimerClass.SINGLETON; > } > } > > public final static String cREPLG6Prefix = "REPL_G6_"; > public final static byte cReplG6OpInsert = 0; > public final static byte cReplG6OpUpdate = 1; > public final static byte cReplG6OpDelete = 2; > public final static int rroNone = 0; > public final static int rroCascade = 1; > public final static int rroRestrict = 2; > public final static int Low_TRtRIntOtion = 0; > public final static int High_TRtRIntOtion = 2; > public final static int rcaAdd = 0; > public final static int rcaModify = 1; > public final static int rcaDrop = 2; > public final static int Low_TRtCrtAltOption = 0; > public final static int High_TRtCrtAltOption = 2; > public final static int raaColumns = 0; > public final static int raaPrimaryKey = 1; > public final static int raaUniqueKeys = 2; > public final static int raaIndexes = 3; > public final static int raaUniqueConstraints = 4; > public final static int raaTriggers = 5; > public final static int raaForeignKeys = 6; > public final static int raaViews = 7; > public final static int raaStoredProcedures = 8; > public final static int Low_TRtCrtAltAssignOption = 0; > public final static int High_TRtCrtAltAssignOption = 8; > public final static int tilDirtyRead = 0; > public final static int tilReadCommitted = 1; > public final static int tilRepeatableRead = 2; > public final static int Low_TRtTransIsolationLevel = 0; > public final static int High_TRtTransIsolationLevel = 2; > public final static int spmIndividual = 0; > public final static int spmGroup = 1; > public final static int Low_TRtSQLProcessMode = 0; > public final static int High_TRtSQLProcessMode = 1; > public final static int atmAlterTable = 0; > public final static int atmInsertIntoSelect = 1; > public final static int atmCustomDB = 2; > public final static int atmCursor = 3; > public final static int Low_TRtAlterTableMode = 0; > public final static int High_TRtAlterTableMode = 3; > public final static int latmDefault = 0; > public final static int latmMaxRestriction = 1; > public final static int Low_TRtLevelAlterTableMode = 0; > public final static int High_TRtLevelAlterTableMode = 1; > public final static int atsNone = 0; > public final static int atsDropTriggers = 1; > public final static int atsDropFks = 2; > public final static int atsRenameTable = 3; > public final static int atsRecreateTable = 4; > public final static int atsMoveData = 5; > public final static int atsDropOldTable = 6; > public final static int atsCreatePkIdxInNewTable = 7; > public final static int atsRecreateFks = 8; > public final static int atsRecreateTriggers = 9; > public final static int atsCustomAlterTable_1 = 10; > public final static int atsCustomAlterTable_Data = 11; > public final static int atsCustomAlterTable_3 = 12; > public final static int atsAlterTable = 13; > public final static int atsAllSteps = 14; > public final static int Low_TRtAlterTableStep = 0; > public final static int High_TRtAlterTableStep = 14; > public final static int cgsoColumnName = 0; > public final static int cgsoColumnType = 1; > public final static int cgsoColumnNotNull = 2; > public final static int cgsoColumnStorage = 3; > public final static int Low_TRtColumnGenSqlOption = 0; > public final static int High_TRtColumnGenSqlOption = 3; > public final static int sckCreateTable = 0; > public final static int sckAlterTable = 1; > public final static int sckCreateIndex = 2; > public final static int sckDropIndex = 3; > public final static int sckCreateTrigger = 4; > public final static int sckDropTrigger = 5; > public final static int sckCreateProcedure = 6; > public final static int sckDropProcedure = 7; > public final static int sckCreateView = 8; > public final static int sckDropView = 9; > public final static int sckDropTable = 10; > public final static int sckRenameTable = 11; > public final static int sckBeginTran = 12; > public final static int sckSetTransaction = 13; > public final static int sckSavePoint = 14; > public final static int sckRollBack = 15; > public final static int sckCommit = 16; > public final static int sckDeleteFrom = 17; > public final static int sckInsertSelectInto = 18; > public final static int sckInsertInto = 19; > public final static int sckUpdate = 20; > public final static int sckSelect = 21; > public final static int Low_TRtSQLClassesKind = 0; > public final static int High_TRtSQLClassesKind = 21; > public final static int soValid = 0; > public final static int soInvalid = 1; > public final static int soInexist = 2; > public final static int Low_TDBStatusObjects = 0; > public final static int High_TDBStatusObjects = 2; > public final static int otStoredProc = 0; > public final static int otTrigger = 1; > public final static int otView = 2; > public final static int Low_TDBObjectType = 0; > public final static int High_TDBObjectType = 2; > public final static int cpiUseNewOperationKind = 0; > public final static int cpiKeepTablesPrivileges = 1; > public final static int cpiNeedRecreateSPs = 2; > public final static int cpiInConsistBase = 3; > public final static int Low_TCnvPropIDs = 0; > public final static int High_TCnvPropIDs = 3; > public final static int ojLeft = 0; > public final static int ojRight = 1; > public final static int ojFull = 2; > public final static int Low_TOuterJoinOption = 0; > public final static int High_TOuterJoinOption = 2; > > public static TRtDBConnection GetDefaultDatabaseConnection() { > TRtDBConnection Result; > TRtDatabaseServer xServer; > Result = null; > xServer = TRtDatabaseServerClass.SINGLETON.GlobalInstance(); > if (xServer != null && xServer.FDBConnections.GetCount() > 0) { > Result = ((TRtDBConnection) xServer.FDBConnections.Get(0)); > } > Assert(Result != null, "GetDefaultDatabaseConnection = nil"); > return Result; > } > > public static TRtFullSessionDef GetDefaultSessionDef() { > return ((TRtFullSessionDef) GetDefaultDatabaseConnection().getPhyDatabase().GetSession()); > } > > public static TRtFullDatabaseDef GetDefaultDatabaseDef() { > return ((TRtFullDatabaseDef) GetDefaultDatabaseConnection().getPhyDatabase()); > } > > public static TRtFullDatabaseDef GetDefaultNewDatabaseDef() { > return ((TRtFullDatabaseDef) GetDefaultDatabaseConnection().GetNewDatabase()); > } > > public static void LoadReferencedFieldListFromSelectStmt(TRtDatabaseDef aDatabaseDef, TSelect aSelect, TList aFieldList) { > TAuxAddField xAuxAddField = new TAuxAddField(); > xAuxAddField.List = aFieldList; > xAuxAddField.Database = aDatabaseDef; > TVisitProc proc = new TVisitProc() { > > public void run(Object aData, int aObjType, Object aObj, TBoolean aGoDown) { > DoVisitFindFields((TAuxAddField) aData, aObjType, aObj); > } > > }; > VisitSelect(aSelect, proc, xAuxAddField); > } > > public static TSQLStatement CompileViewSelect(TRtDatabaseDef aDataBaseDef, String aViewName, String aSelect_SeniorSQL_2) { > CompileViewSelect_Context ctx = new CompileViewSelect_Context(aDataBaseDef, aViewName, aSelect_SeniorSQL_2); > return ctx.execute(); > } > > public static TSQLStatement CompileViewSelectWithUpdSelect(TRtDatabaseDef aDataBaseDef, String aViewName, TString aSelect_SeniorSQL_2) { > TSQLStatement Result; > TStatement aStatement = new TStatement(); > Result = CompileViewSelect(aDataBaseDef, aViewName, aSelect_SeniorSQL_2.v); > try { > aStatement.Kind = skSelect; > aStatement.Select = Result.getStatement().CreateView.Select; > aSelect_SeniorSQL_2.v = TRtSeniorSqlGeneratorClass.SINGLETON.GenerateStatement(aStatement); > } catch (Throwable any) { > Result.Free(); > throw wrap(any); > } > return Result; > } > > public static int OptionalType(int AType) { > return (int) ((int) AType | RT_OPTIONAL_PARAM); > } > > public static String GetStrFromListWithZeros(TStrings List) { > String Result = ""; > int i; > Result = List.GetTextStr(); > i = Pos("\0", Result); > while (i > 0) { > Result = Delete(Result, i, 1); > i = Pos("\0", Result); > } > return Result; > } > > public static void SetSessIdParam(IRtDBParam aParam, double aValue) { > if (Frac(aValue) == 0 && aValue < MaxInt) { > aParam.SetAsInteger((int) Trunc(aValue)); > } else { > aParam.SetAsFloat(aValue); > } > } > > public static TOnNotifyDBConnection vOnCreateDBConnection = null; > public static TOnNotifyDBConnection vOnDestroyDBConnection = null; > public final static String cDefaultDbConnectionName = "DefaultDbConnecion"; > public final static String cDefaultDatabaseDefName = "Base_Padrao"; > public final static String cParamNameErrorLineCountInSPMoveData = "aErrorLineCount"; > public final static String SQLYearPart = "yy"; > public final static String SQLMonthPart = "mm"; > public final static String SQLDayPart = "dd"; > public final static String SQLHourPart = "hh"; > public final static String SQLMinutePart = "mi"; > public final static String SQLSecondsPart = "ss"; > public final static String SQLCharToNumber = "CHAR_TO_NUMBER"; > public final static String SQLCharToDate = "CHAR_TO_DATE"; > public final static String SQLNumberToChar = "NUMBER_TO_CHAR"; > public final static String SQLDateToChar = "DATE_TO_CHAR"; > public final static String SQL_Convert = "CONVERT"; > public final static String SQLEOC_SEP = "\u0001"; > private final static int NUM_DATA_VERSION1 = 0x19980330; > private final static int CUR_DATA_VERSION = NUM_DATA_VERSION1; > private final static int WRITE_VERSION = CUR_DATA_VERSION; > private final static String STORED_PROC_ERR_MESS = "Atualmente, este comando só é suportado dentro de STORED PROCEDURES!"; > private final static String EOL = "\r\n"; > private final static String SQL_EOL = "\r\n "; > private final static char SQL_Space = ' '; > private final static char SQL_LParenthesis = '('; > private final static char SQL_RParenthesis = ')'; > private final static char SQL_Comma = ','; > private final static char SQL_Quotes = '\''; > private final static String SQL_True = "TRUE"; > private final static String SQL_FALSE = "FALSE"; > private final static char SQL_ScriptTerminator = ';'; > private final static char SQL_DecimalSeparator = '.'; > private final static char SQL_Point = '.'; > private final static String SQL_DeleteFrom = "DELETE FROM "; > private final static String SQL_InsertInto = "INSERT INTO "; > private final static String SQL_Update = "UPDATE "; > private final static String SQL_Select = "SELECT "; > private final static String SQL_Set = " SET "; > private final static String SQL_Values = " VALUES "; > private final static String SQL_CurrentOf = "CURRENT OF "; > private final static String SQL_Where = "WHERE "; > private final static String SQL_Having = "HAVING "; > private final static String SQL_From = "FROM "; > private final static String SQL_Into = "INTO "; > private final static String SQL_GroupBy = "GROUP BY "; > private final static String SQL_OrderBy = "ORDER BY "; > private final static String SQL_ForUpdate = "FOR UPDATE"; > private final static String SQL_Union = "UNION "; > private final static String SQL_All = "ALL "; > private final static String SQL_ASC = "ASC"; > private final static String SQL_DESC = "DESC"; > private final static String SQL_Create = "CREATE"; > private final static String SQL_View = "VIEW"; > private final static String SQL_As = "AS"; > private final static String SQL_Drop = "DROP"; > private final static String SQL_NULL = "NULL"; > private final static String SQL_NOT = "NOT"; > private final static String SQL_NOTNULL = SQL_NOT + SQL_Space + SQL_NULL; > static TRtDatabaseServer vDBServer = null; > private final static int RT_OPTIONAL_PARAM = 0x8000; > > static String GetATOperation(int aAlterTableStep, Object[] aNames) { > String Result = ""; > switch (aAlterTableStep) { > case atsNone: > Result = ""; > break; > case atsDropTriggers: > Result = TransStrFmt("TC3284", "Apagando triggers(s) da tabela %s", aNames); > break; > case atsDropFks: > Result = TransStrFmt("TC3285", "Apagando chave(s) estrangeira(s) da tabela %s", aNames); > break; > case atsRenameTable: > Result = TransStrFmt("TC3286", "Renomeando tabela %s", aNames); > break; > case atsRecreateTable: > Result = TransStrFmt("TC3287", "Criando nova tabela %s", aNames); > break; > case atsMoveData: > Result = TransStrFmt("TC3288", "Movendo dados da tabela %s", aNames); > break; > case atsDropOldTable: > Result = TransStrFmt("TC3289", "Apagando tabela %s", aNames); > break; > case atsCreatePkIdxInNewTable: > Result = TransStrFmt("TC5144", "Criando chave primária e índice(s) na tabela %s", aNames); > break; > case atsRecreateFks: > Result = TransStrFmt("TC3290", "Criando chave(s) estrangeira(s) da tabela %s", aNames); > break; > case atsRecreateTriggers: > Result = TransStrFmt("TC3291", "Criando triggers(s) da tabela %s", aNames); > break; > case atsCustomAlterTable_1: > case atsCustomAlterTable_Data: > case atsCustomAlterTable_3: > Result = TransStrFmt("TC427", "Alteração personalizada pelo banco na tabela %s", aNames); > break; > case atsAlterTable: > Result = TransStrFmt("TC3292", "Alterando tabela %s", aNames); > break; > case atsAllSteps: > Result = TransStrFmt("TC3292", "Alterando tabela %s", aNames); > break; > default: > break; > } > return Result; > } > > static void DoVisitFindFields(TAuxAddField aAuxAddField, int aObjType, Object aObj) { > DoVisitFindFields_Context ctx = new DoVisitFindFields_Context(aAuxAddField, aObjType, aObj); > ctx.execute(); > } > > public static TRtSQLTokenList CompileSQLExp(String AExp, TString AParams, boolean LCondition) { > TRtSQLTokenList ATokens; > TRtSQLCompiler AC; > AC = TRtSQLCompiler.Create(); > try { > ATokens = null; > try { > if (!LCondition) { > ATokens = AC.CompileExpression(AExp); > } else { > ATokens = AC.CompileCondition(AExp); > } > if (ATokens != null && AParams != null) { > AParams.v = ATokens.GetEncodedParams(); > } > } catch (Throwable any) { > ATokens.Free(); > throw wrap(any); > } > } finally { > AC.Free(); > } > return ATokens; > } > > static void ParseColName(String ASrcName, TString ATblName, TRtSQLTokenList ATokens) { > TInt p = new TInt(); > String AColName = ""; > ATokens = CompileSQLExp(ASrcName, null, false); > if (ATokens != null) { > if (ATokens.GetCount() == 1) { > { > TRtSQLTokenItem context_GetItem = ATokens.GetItem(0); > if (context_GetItem.getTokType() == rstIdColumn) { > ATblName.v = ""; > ATokens.Free(); > ATokens = null; > } else if (DelphiSet.get(rstIdTableColumn, rstIdSchemaTableColumn).contains(context_GetItem.getTokType())) { > AColName = context_GetItem.getToken(); > p.v = 0; > if (context_GetItem.getTokType() == rstIdSchemaTableColumn) { > StrGetNextToken(AColName, p, '.'); > } > ATblName.v = StrGetNextToken(AColName, p, '.'); > ATokens.Free(); > ATokens = null; > } > } > } > } else { > AColName = ASrcName; > if (Pos('.', AColName) > 0) { > p.v = 0; > ATblName.v = StrGetNextToken(AColName, p, '.'); > ASrcName = StrGetNextToken(AColName, p, '.'); > if (!StrIsBlank(ASrcName) && p.v != -1) { > ATblName.v = ASrcName; > } > } else { > ATblName.v = ""; > } > } > } > > private static TRtSQLFunctionTableList GetSQL92FunctionList() { > TRtSQLFunctionTableList Result; > Result = TRtSQLFunctionTableList.Create(); > try { > (((TRtSQLFunctionTableItem) Result.AddNewItem("MAX"))).AddTypes(new int[] { rftUnknown, rftUnknown }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("MIN"))).AddTypes(new int[] { rftUnknown, rftUnknown }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("COUNT"))).AddTypes(new int[] { rftUnknown, rftUnknown }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("AVG"))).AddTypes(new int[] { rftUnknown, rftUnknown }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("SUM"))).AddTypes(new int[] { rftUnknown, rftUnknown }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("CONCAT"))).AddTypes(new int[] { rftString, rftString, rftString }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("DIFFERENCE"))).AddTypes(new int[] { rftString, rftString, rftString }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("INSERT"))).AddTypes(new int[] { rftString, rftString, rftNumber, rftNumber, rftString }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("LCASE"))).AddTypes(new int[] { rftString, rftString }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("LEFT"))).AddTypes(new int[] { rftString, rftString, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("LENGTH"))).AddTypes(new int[] { rftNumber, rftString }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("LOCATE"))).AddTypes(new int[] { rftNumber, rftString, rftString, OptionalType(rftNumber) }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("LTRIM"))).AddTypes(new int[] { rftString, rftString }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("REPEAT"))).AddTypes(new int[] { rftString, rftString, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("REPLACE"))).AddTypes(new int[] { rftString, rftString, rftString, rftString }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("RIGHT"))).AddTypes(new int[] { rftString, rftString, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("RTRIM"))).AddTypes(new int[] { rftString, rftString }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("SPACE"))).AddTypes(new int[] { rftString, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("SUBSTRING"))).AddTypes(new int[] { rftString, rftString, rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("UCASE"))).AddTypes(new int[] { rftString, rftString }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("ABS"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("ACOS"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("ASIN"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("ATAN"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("ATAN2"))).AddTypes(new int[] { rftNumber, rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("CELING"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("COS"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("COT"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("EXP"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("FLOOR"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("LOG"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("LOG10"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("MOD"))).AddTypes(new int[] { rftNumber, rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("PI"))).AddTypes(new int[] { rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("POWER"))).AddTypes(new int[] { rftNumber, rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("RADIANS"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("DEGREES"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("RAND"))).AddTypes(new int[] { rftNumber, OptionalType(rftNumber) }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("ROUND"))).AddTypes(new int[] { rftNumber, rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("SIGN"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("SIN"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("SQRT"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("TAN"))).AddTypes(new int[] { rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("TRUNCATE"))).AddTypes(new int[] { rftNumber, rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("CURDATE"))).AddTypes(new int[] { rftDate }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("CURTIME"))).AddTypes(new int[] { rftTime }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("DAYNAME"))).AddTypes(new int[] { rftString, rftDate }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("DAYOFMONTH"))).AddTypes(new int[] { rftNumber, rftDate }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("DAYOFWEEK"))).AddTypes(new int[] { rftNumber, rftDate }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("HOUR"))).AddTypes(new int[] { rftNumber, rftTime }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("MINUTE"))).AddTypes(new int[] { rftNumber, rftTime }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("MONTH"))).AddTypes(new int[] { rftNumber, rftDate }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("MONTHNAME"))).AddTypes(new int[] { rftString, rftDate }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("NOW"))).AddTypes(new int[] { rftTime }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("QUARTER"))).AddTypes(new int[] { rftNumber, rftDate }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("SECOND"))).AddTypes(new int[] { rftNumber, rftTime }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("YEAR"))).AddTypes(new int[] { rftNumber, rftDate }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("DATETIME"))).AddTypes(new int[] { rftDate, rftNumber, rftNumber, rftNumber, rftNumber, rftNumber, rftNumber }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("DATETIMEADD"))).AddTypes(new int[] { rftDate, rftUnknown, rftNumber, rftDate }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("DATETIMEDIF"))).AddTypes(new int[] { rftNumber, rftUnknown, rftDate, rftDate }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("CONVERT"))).AddTypes(new int[] { rftUnknown, rftUnknown, rftUnknown }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("IFNULL"))).AddTypes(new int[] { rftUnknown, rftUnknown, rftUnknown }); > (((TRtSQLFunctionTableItem) Result.AddNewItem("USER"))).AddTypes(new int[] { rftString }); > } catch (Throwable any) { > Result.Free(); > Result = null; > } > return Result; > } > > static String TempName() { > Randomize(); > return "X" + IntToStr(Random(MaxInt)); > } > > static String TempExp() { > Randomize(); > return "EXP" + IntToStr(Random(MaxInt)); > } > > static String BreakLine(String s) { > String Result = ""; > if (!StrIsBlank(s)) { > Result = SQL_EOL + s; > } else { > Result = ""; > } > return Result; > } > > static String TranslateExpression(TRtCustomSQL SQL, TRtSQLTokenList TokenList) { > TranslateExpression_Context ctx = new TranslateExpression_Context(SQL, TokenList); > return ctx.execute(); > } > > static String GetWhere(TRtCustomSQL SQL, TRtWhereItem Where) { > String Result = ""; > Result = ""; > if (Where instanceof TRtWhereCurrentOfItem) { > if (!StrIsBlank(((TRtWhereCurrentOfItem) Where).GetCurrentOf())) { > Result = SQL_CurrentOf + ((TRtWhereCurrentOfItem) Where).GetCurrentOf(); > } else { > Result = TranslateExpression(SQL, Where.getTokens()); > } > } else { > Result = TranslateExpression(SQL, Where.getTokens()); > } > return Result; > } > > private static void IncompatibleDataError(Object aValue, TTypeDesc aTypeDesc) { > String xStr = ""; > xStr = VarToString(aValue); > throw DelphiException.Create("O valor " + xStr + " não é compatível com o typedesc " + TypeDescName(aTypeDesc)); > } > > private static String IntValAsTypeDesc(int aVal, TTypeDesc aTypeDesc) { > String Result = ""; > if (TypeDescIsNumeric(aTypeDesc)) { > Result = IntToStr(aVal); > } else if (TypeDescIsAlphaNumeric(aTypeDesc)) { > Result = QuotedStr(IntToStr(aVal)); > } else { > IncompatibleDataError(VarFromInt(aVal), aTypeDesc); > } > return Result; > } > > private static String StrValAsTypeDesc(String aVal, TTypeDesc aTypeDesc) { > String Result = ""; > if (TypeDescIsNumeric(aTypeDesc)) { > Result = IntToStr(StrToInt(aVal)); > } else if (TypeDescIsAlphaNumeric(aTypeDesc)) { > Result = QuotedStr(aVal); > } else { > IncompatibleDataError(VarFromString(aVal), aTypeDesc); > } > return Result; > } > > private static String FloatToDotStr(double aValue) { > String Result = ""; > char xOldDecimal; > xOldDecimal = DecimalSeparator; > try { > DecimalSeparator = '.'; > Result = FloatToStr(aValue); > } finally { > DecimalSeparator = xOldDecimal; > } > return Result; > } > > private static String ExtendedValToStr(double aValue, TTypeDesc aTypeDesc) { > String Result = ""; > if (TypeDescIsFloatPoint(aTypeDesc)) { > Result = FloatToDotStr(aValue); > } else if (TypeDescIsDateTime(aTypeDesc)) { > Result = DateToSQLSenior2DateConst(aValue); > } else if (TypeDescIsAlphaNumeric(aTypeDesc)) { > Result = QuotedStr(FloatToDotStr(aValue)); > } else { > IncompatibleDataError(aValue, aTypeDesc); > } > return Result; > } > > private static String TVarRecToKeyString(TVarRec aValue, TTypeDesc aTypeDesc) { > String Result = ""; > switch (aValue.VType) { > case vtInteger: > Result = IntValAsTypeDesc(aValue.VInteger, aTypeDesc); > break; > case vtChar: > Result = StrValAsTypeDesc("" + aValue.VChar, aTypeDesc); > break; > case vtString: > Result = StrValAsTypeDesc(aValue.VString, aTypeDesc); > break; > case vtPChar: > Result = StrValAsTypeDesc(StrPas(aValue.VPChar), aTypeDesc); > break; > case vtAnsiString: > Result = StrValAsTypeDesc(aValue.VAnsiString, aTypeDesc); > break; > case vtExtended: > Result = ExtendedValToStr(((Number) aValue.VExtended).doubleValue(), aTypeDesc); > break; > default: > throw DelphiException.Create("Tipo de const não suportado"); > } > return Result; > } > > static String[] GenerateNextValueStrKeyValues(IRtIndexDef aIndexDef, Object[] aValues) { > String[] Result = null; > int i; > if (aIndexDef.GetIndexFieldCount() - 2 != aValues.length - 1) { > throw DelphiException.Create("A Quantidade de valores passados para a tabela " + aIndexDef.GetTableDef().GetName() + " está incorreta!"); > } > Result = SetLength(Result, aValues.length - 1 + 1); > for (i = 0; i <= aValues.length - 1; ++i) { > Result[i] = TVarRecToKeyString(GetTVarRec(aValues[i]), aIndexDef.GetIndexFieldDef(i).GetFieldDef().GetTypeDesc()); > } > return Result; > } > > static String GenerateNextValueKey(String aTableName, String[] aValues) { > String Result = ""; > int i; > Result = aTableName; > for (i = 0; i <= High(aValues); ++i) { > Result = Result + '#' + aValues[i]; > } > return Result; > } > > static IRtIndexDef GetPKFromTable(TRtDBConnection aConn, String aTableName) { > IRtIndexDef Result; > Result = aConn.GetDatabaseDef().TableByName(aTableName).GetPrimaryKey(); > if (Result == null) { > throw DelphiException.Create("A Tabela " + aTableName + " não possui chave primária"); > } > return Result; > } > > static void _CheckUnprepare(TContainerItem AItem) { > TRtCustomSQL sql; > TRtCustomSQL sql2; > if (AItem instanceof TRtCustomSQL) { > sql = (TRtCustomSQL) AItem; > } else { > sql = ((TRtCustomSQL) AItem.GetTypedOwner(TRtCustomSQLClass.SINGLETON)); > } > if (sql != null) { > sql2 = sql.GetRootSQL(); > if (sql2 != null) { > sql = sql2; > } > } else { > return; > } > if (sql != null) { > sql.UnPrepare(); > } > } > > static boolean HasDropTable(TRtDBConnection DBConn, String ATableName) { > boolean Result; > TRtCustomSQL AObj; > int i; > if (DBConn.getSQLProcessMode() == spmGroup) { > for (i = 0; i <= DBConn.FSQLList.GetCount() - 1; ++i) { > AObj = ((TRtCustomSQL) DBConn.FSQLList.Get(i)); > Result = AObj instanceof TRtDropTable && CompareText(ATableName, ((TRtDropTable) AObj).GetTableName()) == 0; > if (Result) { > return Result; > } > } > } > return false; > } > > private static final TRtSqlDriver vSqlDriver = new TRtSqlDriver(); > private static TDBParamStrings vSeniorPadraoDBParams; > > private static void RegisterSeniorPadraoDBParams() { > vSeniorPadraoDBParams = TDBParamStrings.Create(); > TRtDatabaseServerClass.SINGLETON.GlobalInstance().RegisterConnectionParams(dbakPadrao, dbvkSenior, vSeniorPadraoDBParams); > } > > //private static void UnregisterSeniorPadraoDBParams() { > // TRtDatabaseServerClass.SINGLETON.GlobalInstance().UnregisterConnectionParams(dbakPadrao, dbvkSenior); > // FreeAndNil(AsVar(vSeniorPadraoDBParams)); > //} > > private static void RegisterSeniorSqlDriver() { > vSqlDriver.SQLClasses[sckCreateTable] = TRtCreateTableClass.SINGLETON; > vSqlDriver.SQLClasses[sckAlterTable] = TRtAlterTableClass.SINGLETON; > vSqlDriver.SQLClasses[sckCreateIndex] = TRtCreateIndexClass.SINGLETON; > vSqlDriver.SQLClasses[sckDropIndex] = TRtDropIndexClass.SINGLETON; > vSqlDriver.SQLClasses[sckCreateTrigger] = TRtCreateTriggerClass.SINGLETON; > vSqlDriver.SQLClasses[sckDropTrigger] = TRtDropTriggerClass.SINGLETON; > vSqlDriver.SQLClasses[sckCreateProcedure] = TRtCreateProcedureClass.SINGLETON; > vSqlDriver.SQLClasses[sckDropProcedure] = TRtDropProcedureClass.SINGLETON; > vSqlDriver.SQLClasses[sckCreateView] = TRtCreateViewClass.SINGLETON; > vSqlDriver.SQLClasses[sckDropView] = TRtDropViewClass.SINGLETON; > vSqlDriver.SQLClasses[sckDropTable] = TRtDropTableClass.SINGLETON; > vSqlDriver.SQLClasses[sckRenameTable] = TRtRenameTableClass.SINGLETON; > vSqlDriver.SQLClasses[sckBeginTran] = TRtBeginTranClass.SINGLETON; > vSqlDriver.SQLClasses[sckSetTransaction] = TRtSetTransactionClass.SINGLETON; > vSqlDriver.SQLClasses[sckSavePoint] = TRtSavePointClass.SINGLETON; > vSqlDriver.SQLClasses[sckRollBack] = TRtRollBackClass.SINGLETON; > vSqlDriver.SQLClasses[sckCommit] = TRtCommitClass.SINGLETON; > vSqlDriver.SQLClasses[sckDeleteFrom] = TRtDeleteFromClass.SINGLETON; > vSqlDriver.SQLClasses[sckInsertSelectInto] = TRtInsertSelectIntoClass.SINGLETON; > vSqlDriver.SQLClasses[sckInsertInto] = TRtInsertIntoClass.SINGLETON; > vSqlDriver.SQLClasses[sckUpdate] = TRtUpdateClass.SINGLETON; > vSqlDriver.SQLClasses[sckSelect] = TRtSelectClass.SINGLETON; > vSqlDriver.DBCatalogsClass = TRtDbCatalogsClass.SINGLETON; > vSqlDriver.ColumnSqlGeneratorClass = TRtColumnSqlGeneratorClass.SINGLETON; > vSqlDriver.DBInitProc = null; > vSqlDriver.FuncList = GetSQL92FunctionList(); > vSqlDriver.PLGenerator = null; > vSqlDriver.DBGenericFunctionsClass = TRtDBGenericFunctionsClass.SINGLETON; > vSqlDriver.ReplG6FunctionsClass = TRtReplG6FunctionsClass.SINGLETON; > TRtDatabaseServerClass.SINGLETON.GlobalInstance().RegisterSqlDriver(dbvkSenior, vSqlDriver); > } > > //private static void UnregisterSeniorSqlDriver() { > // TRtDatabaseServerClass.SINGLETON.GlobalInstance().UnregisterSqlDriver(dbvkSenior); > // FreeAndNil(AsVar(vSqlDriver.FuncList)); > //} > > private static void RegisterSeniorPadraoKernel() { > TRtDatabaseServerClass.SINGLETON.GlobalInstance().RegisterSqlKnl(dbakPadrao, TRtDBKernelClass.SINGLETON); > } > > //private static void UnregisterSeniorPadraoKernel() { > // TRtDatabaseServerClass.SINGLETON.GlobalInstance().UnregisterSqlKnl(dbakPadrao); > //} > > private static void InitRtSql() { > vDBServer = TRtDatabaseServer.Create(); > RegisterSeniorPadraoDBParams(); > RegisterSeniorSqlDriver(); > RegisterSeniorPadraoKernel(); > } > > //private static void FinalizeRtSql() { > // UnregisterSeniorPadraoDBParams(); > // UnregisterSeniorSqlDriver(); > // UnregisterSeniorPadraoKernel(); > // FreeAndNil(AsVar(vDBServer)); > //} > > static { > InitRtSql(); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 319425
:
173893
| 173895 |
173896
|
175251
|
175258
|
175288
|
175495