SysUtils.Alert( 'Model ADO is being used for reverse engineering only.\r\nTo generate SQL script convert ADO model into model for desired databese.\r\n(Menu: "Model" - Item: "Database Convertion" )' );
<DESCRIPTION><![CDATA[The ADO template has been designed mainly for reverse engineering of those databases where CASE Studio does not support such option as a standard. After loading the database structure, transfer the created ADO model into the respective model. The ADO templates are not designed for creation of ER diagrams.
Create Trigger tur_%tablename% no cascade before update
of @forPFkCol("", "", colname, ", ", "" )
on %tablename% @showmessage("Trigger for %tablename% ")
referencing new as new_upd old as old_upd for each row mode db2sql
-- Restrict parent %ParentTableName% when child %ChildTableName% updated
when @forparent( "(", "",forrelpk("","",iff(ChildUpdRestrict,if(flag1," or %cr% ",setflag(1,true))+"( new_upd.%PkChildName% <> old_upd.%PkChildName% and exists (select 1 from %parenttablename% where %parenttablename%.%PkparentName% = old_upd.%PkChildName%))",""),"",""), "", ")" )
begin atomic
signal sqlstate '70002' ('Parent does not exist. Cannot update child.');
Create Trigger ti_%tablename% no cascade before insert
on %tablename% @showmessage("Trigger for %tablename% ")
referencing new as new_ins for each row mode db2sql
-- Restrict child %childtablename% when parent %parenttablename% insert
when @forparent( "(", "",iff(ChildInsRestrict,if(flag1," or %cr% ",setflag(1,true))+forrelpk("(","","new_ins.%PkChildName% is not null and%cr%","","")+forrelpk("not exists (select 1 from %parenttablename% where",""," %parenttablename%.%PkParentName% = new_ins.%PkChildName%"," and ","))"),""),"",")")
begin atomic
signal sqlstate '70001' ('Parent does not exist. Cannot insert child.');
Create Trigger td_%tablename% no cascade before delete
on %tablename% @showmessage("Trigger for %tablename%")
referencing old as old_del for each row mode db2sql
-- Restrict child %childtablename%, when parent %parenttablename% deleted
when @forchild( "(", "",iff(ParDelRestrict,if(flag1," or ",setflag(1,true))+"%cr% exists (select 1 from %childtablename% where "+forrelpk("","","(%childtablename%.%pkchildname%=old_del.%pkParentName%)"," and ",")"),""), "", ")" )
begin atomic
signal sqlstate '70007' ('Children still exist in child table. Cannot delete parent.');
<VALUE><![CDATA[if((sUserMajVer="") Or ((sUserMajVer="1") And (sUserMinVer="")),"","%cr%User Major Version %sUserMajVer%"+if(sUserMinVer<>"","%cr%User Minor Version %sUserMinVer%",""))
If Not qdf Is Nothing Then dbs.QueryDefs.Delete ( QueryName )
End Sub
{lDropTableGener}
' Drop relation
'===============
Sub DropRelation(RelName As String)
Set rel = Nothing
On Error Resume Next
Set rel = dbs.Relations(RelName)
On Error GoTo 0
If Not rel Is Nothing Then dbs.Relations.Delete ( RelName )
End Sub
' Drop table
'============
Sub DropTable(TableName As String)
Set tdf = Nothing
On Error Resume Next
Set tdf = dbs.TableDefs(TableName)
On Error GoTo 0
If Not tdf Is Nothing Then dbs.TableDefs.Delete ( TableName )
End Sub
{lDropIndexGener}
' Drop index
'============
Sub DropIndex(TableName As String, IndexName As String)
Set tdf = Nothing
Set idx = Nothing
On Error Resume Next
Set tdf = dbs.TableDefs(TableName)
Set idx = tdf.Indexes(IndexName)
On Error GoTo 0
If (Not tdf Is Nothing) And (Not idx Is Nothing) Then tdf.Indexes.Delete ( IndexName )
End Sub
{lTableGener}
' Add fields to table
'=====================
Sub AddFieldToTable(FieldName As String, DataType As String, SizeCol As Integer, Attributes As Long, DefaultValue As Variant, ValText As String, ValRule As String, NotN As Boolean)
Dim fld As DAO.Field
Set fld = tdf.CreateField( FieldName, DataType )
If SizeCol <> 0 Then fld.Size = SizeCol
If Attributes <> 0 Then fld.Attributes = Attributes
fld.Required = NotN
fld.DefaultValue = DefaultValue
fld.ValidationRule = ValRule
fld.ValidationText = ValText
tdf.Fields.Append fld
End Sub
' Add properties to table
'=========================
Sub AddPropertyToTable( PropertyName As String, Value As Variant, DataType As String)
Dim prp As DAO.Property
Set prp = tdf.CreateProperty(PropertyName, DataType, Value)
tdf.Properties.Append prp
End Sub
' Add properties to field
'=========================
Sub AddPropertyToField( FieldName As String, PropertyName As String, Value As Variant, DataType As String)
Dim prp As DAO.Property
Dim fld As DAO.Field
Set fld = tdf.Fields( FieldName )
Set prp = fld.CreateProperty(PropertyName, DataType, Value)
fld.Properties.Append prp
End Sub
{lPKGener or lIndexGener or lAlterKeysGener}
' Add fields to index
'=====================
Sub AddFieldToIndex( FieldName As String, Descending As Boolean )
Dim fld As DAO.Field
Set fld = idx.CreateField( FieldName )
If Descending = True Then fld.Attributes = dbDescending
idx.Fields.Append fld
End Sub
{lRefIntegGener}
' Add fields to relation
'========================
Sub AddFieldToRelation( PKField As String, FKField As String )
If Not qdf Is Nothing Then dbs.QueryDefs.Delete ( QueryName )
End Sub
{lDropTableGener}
' Drop relation
'===============
Sub DropRelation(RelName As String)
Set rel = Nothing
On Error Resume Next
Set rel = dbs.Relations(RelName)
On Error GoTo 0
If Not rel Is Nothing Then dbs.Relations.Delete ( RelName )
End Sub
' Drop table
'============
Sub DropTable(TableName As String)
Set tdf = Nothing
On Error Resume Next
Set tdf = dbs.TableDefs(TableName)
On Error GoTo 0
If Not tdf Is Nothing Then dbs.TableDefs.Delete ( TableName )
End Sub
{lDropIndexGener}
' Drop index
'============
Sub DropIndex(TableName As String, IndexName As String)
Set tdf = Nothing
Set idx = Nothing
On Error Resume Next
Set tdf = dbs.TableDefs(TableName)
Set idx = tdf.Indexes(IndexName)
On Error GoTo 0
If (Not tdf Is Nothing) And (Not idx Is Nothing) Then tdf.Indexes.Delete ( IndexName )
End Sub
{lTableGener}
' Add fields to table
'=====================
Sub AddFieldToTable(FieldName As String, DataType As String, SizeCol As Integer, Attributes As Long, DefaultValue As Variant, ValText As String, ValRule As String, NotN As Boolean)
Dim fld As Field
Set fld = tdf.CreateField( FieldName, DataType )
If SizeCol <> 0 Then fld.Size = SizeCol
If Attributes <> 0 Then fld.Attributes = Attributes
fld.Required = NotN
fld.DefaultValue = DefaultValue
fld.ValidationRule = ValRule
fld.ValidationText = ValText
tdf.Fields.Append fld
End Sub
' Add properties to table
'=========================
Sub AddPropertyToTable( PropertyName As String, Value As Variant, DataType As String)
Dim prp As Property
Set prp = tdf.CreateProperty(PropertyName, DataType, Value)
tdf.Properties.Append prp
End Sub
' Add properties to field
'=========================
Sub AddPropertyToField( FieldName As String, PropertyName As String, Value As Variant, DataType As String)
Dim prp As Property
Dim fld As Field
Set fld = tdf.Fields( FieldName )
Set prp = fld.CreateProperty(PropertyName, DataType, Value)
fld.Properties.Append prp
End Sub
{lPKGener or lIndexGener or lAlterKeysGener}
' Add fields to index
'=====================
Sub AddFieldToIndex( FieldName As String, Descending As Boolean )
Dim fld As Field
Set fld = idx.CreateField( FieldName )
If Descending = True Then fld.Attributes = dbDescending
idx.Fields.Append fld
End Sub
{lRefIntegGener}
' Add fields to relation
'========================
Sub AddFieldToRelation( PKField As String, FKField As String )
Alter table @macro(GenerateOwner)[%childtablename%] add @if(lFkAsConstraint and (not Empty(fRelName)),"Constraint [%frelname%]","") foreign key(@ForRelPk("","","["+PkChildName+"]",",","")) references [%parenttablename%] (@ForRelPk("","","["+PkParentName+"]",",","")) @macro(RefIntegrity2) @if(lNotForReplicationFk," NOT FOR REPLICATION","")%cr%go
if(not Empty(ConstraintDefault) and DefaultExist, " Constraint [%ConstraintDefault%]","")+
if(DefaultExist," Default "+DefaultValue ,"")+
if(Identity," Identity"+if(Empty(IdentitySeed) or Empty(IdentityIncrement),"","(%IdentitySeed%,%IdentityIncrement%)"+if(lNotForReplicationId," NOT FOR REPLICATION","")),"")+
if(lRowGuidCol," rowguidcol","")+
if(Column.DataTypeID<>200, if(NotNull," NOT NULL"," NULL"),"")+
if(not Empty(ConstraintDefault) and DefaultExist, " Constraint [%ConstraintDefault%]","")+
if(DefaultExist," Default "+DefaultValue ,"")+
if(Identity," Identity"+if(Empty(IdentitySeed) or Empty(IdentityIncrement),"","(%IdentitySeed%,%IdentityIncrement%)"+if(lNotForReplicationId," NOT FOR REPLICATION","")),"")+
if(lRowGuidCol," rowguidcol","")+
if(Column.DataTypeID<>200, if(NotNull," NOT NULL"," NULL"),"")+
<VALUE><![CDATA[@ForDict("","",if((empty(Default))or(empty(UTypeDefName)),"","Create default [%UTypeDefName%] as '%Default%'%cr%go%cr%")+if((empty(Check))or(empty(UTypeRuleName)),"","Create rule [%UTypeRuleName%] as %Check%%cr%go%cr%"),"","")
@ForTable("","",ForCol("","",if(Column.DataTypeId=0,"",if((empty(ConstraintDefault))or(empty(Default)),"","Create default "+macro(GenerateOwner)+"[%ConstraintDefault%] as '%Default%'%cr%go%cr%")+if((empty(ConstraintCheck))or(empty(Check)),"","Create rule "+macro(GenerateOwner)+"[%ConstraintCheck%] as %Check%%cr%go%cr%")),"",""),"","")
<VALUE><![CDATA[@ForTable("", "", if(lGenerOwner and not empty(Owner) and not Empty(EntDescription),"Exec sp_addextendedproperty 'MS_Description', '"+ScriptProc(DescriptionCRLFRemove,Main,EntDescription)+"', 'user', '%Owner%', 'table', '%tablename%', NULL, NULL%cr%go%cr%",""), "", "")
<VALUE><![CDATA[@ForDict("","",if((empty(Default))or(empty(UTypeDefName)),"","Create default [%UTypeDefName%] as '%Default%'%cr%go%cr%")+if((empty(Check))or(empty(UTypeRuleName)),"","Create rule [%UTypeRuleName%] as %Check%%cr%go%cr%"),"","")
@ForTable("","",ForCol("","",if(Column.DataTypeId=0,"",if((empty(ConstraintDefault))or(empty(Default)),"","Create default "+macro(GenerateOwner)+"[%ConstraintDefault%] as '%Default%'%cr%go%cr%")+if((empty(ConstraintCheck))or(empty(Check)),"","Create rule "+macro(GenerateOwner)+"[%ConstraintCheck%] as %Check%%cr%go%cr%")),"",""),"","")
<VALUE><![CDATA[if(lGenIndexFk and lGenIndexFk_R,"Alter table %childtablename% add Index IX_%frelname% ("+ForRelPk("","",PkChildName,",","")+");%cr%","")+
if ( Entity.Generate && Entity.Description != '' )
if ((owner=='') || ( Model.GetUserVariable('lGenerOwner')==0))
TextStream.Writeln( 'Comment on table '+qt+Entity.TableName+qt+" is '"+Entity.Description.replace(re,"''")+"'\n" + Model.GetUserVariable('term') );
else
TextStream.Writeln( 'Comment on table '+qt+owner+qt+'.'+qt+Entity.TableName+qt+" is '"+Entity.Description.replace(re,"''")+"'\n" + Model.GetUserVariable('term') );
<VALUE><![CDATA[if(lPermissExec,"Grant execute on "+ScriptProc(TextObjectNameQuotes,Main,ProcedureName)+" to %qt%%UserOrRoleName%%qt%%cr%%term%%cr%","")
<VALUE><![CDATA[@ForAlterKey("","","Create unique index %AlterKeyConstraintName% on %TableName% (%AlterKeyKeys%);"+cr+ShowMessage("Alternate key %AlterKeyConstraintName% for table %tablename%"),"","")
<VALUE><![CDATA[@ForAlterKey("","","Create unique index %AlterKeyConstraintName% on %TableName% (%AlterKeyKeys%);"+cr+ShowMessage("Alternate key %AlterKeyConstraintName% for table %tablename%"),"","")
Query.SQL = 'SELECT CH.CONSTNAME,CH.TABSCHEMA,CH.TABNAME,CAST(CH.TEXT AS LONG VARCHAR) AS TEXT,CC.COLNAME, '
+ '(SELECT COUNT(*) FROM SYSCAT.COLCHECKS CC2 WHERE CH.TABSCHEMA=CC2.TABSCHEMA AND CH.TABNAME=CC2.TABNAME AND CH.CONSTNAME=CC2.CONSTNAME) AS COLCOUNT '
+ 'FROM SYSCAT.CHECKS AS CH, SYSCAT.COLCHECKS AS CC '
Query2.SQL = 'select IDENT_SEED (\''+s.TableSchema+'.'+s.TableName+'\') as ident_seed,IDENT_INCR (\''+s.TableSchema+'.'+s.TableName+'\') as ident_incr';
Query.SQL = 'select distinct sc.constid, sc.id as id, so.name as name_constraint, so.type, so2.name as name_table, sc.colid, co.name as name_column, u.name as name_user, so.id as id2, '
+ 'from sysconstraints sc, sysobjects so, sysobjects so2, syscolumns co, sysusers u, syscomments t '
+ 'where (sc.status % 4) = 0 and sc.constid=so.id and sc.id=so2.id and co.colid=sc.colid and co.id = so2.id and u.uid=so2.uid and sc.constid=t.id and (so2.category & 0x2)!=2';
col = Schema.GetColumn(s.TableSchema+'.'+s.TableName+'.'+s.ColumnName);
if (col != null)
if (Query.GetFieldValue('CHECK_NOT_REPL') == 1)
col.SetUserVariable('lNotForReplicationCh',true);
Query.Next();
}
Query.Close();
}
//
Query.SQL = 'select distinct sc.constid, sc.id as id, so.name as name_constraint, so.type, so2.name as name_table, sc.colid, u.name as name_user, so.id as id2, '
+ '(SELECT COUNT(*) FROM '+cDataDict+'_CONS_COLUMNS CC2 WHERE CO.OWNER=CC2.OWNER AND CO.TABLE_NAME=CC2.TABLE_NAME AND CO.CONSTRAINT_NAME=CC2.CONSTRAINT_NAME) AS COLCOUNT,CO.SEARCH_CONDITION '
+ 'FROM '+cDataDict+'_CONSTRAINTS CO,'+cDataDict+'_CONS_COLUMNS CC '
+ 'WHERE CO.CONSTRAINT_TYPE=\'C\' AND (CO.CONSTRAINT_NAME = CC.CONSTRAINT_NAME)';
if ( lAllObjects )
Query.SQL += ' AND '+GetWhereCondition( 'CO.OWNER' );
Query.SQL += ' ORDER BY CO.OWNER,CO.TABLE_NAME,CC.COLUMN_NAME';
+ '(SELECT COUNT(*) FROM '+cDataDict+'_CONS_COLUMNS CC2 WHERE CO.OWNER=CC2.OWNER AND CO.TABLE_NAME=CC2.TABLE_NAME AND CO.CONSTRAINT_NAME=CC2.CONSTRAINT_NAME) AS COLCOUNT,CO.SEARCH_CONDITION '
+ 'FROM '+cDataDict+'_CONSTRAINTS CO,'+cDataDict+'_CONS_COLUMNS CC '
+ 'WHERE CO.CONSTRAINT_TYPE=\'C\' AND (CO.CONSTRAINT_NAME = CC.CONSTRAINT_NAME)';
if ( lAllObjects )
Query.SQL += ' AND '+GetWhereConditionSelected( 'CO.OWNER' );
Query.SQL += ' ORDER BY CO.OWNER,CO.TABLE_NAME,CC.COLUMN_NAME';
Query.SQL = 'select si.name as primary_name, object_name(constrid) as foreign_name, object_name(tableid) as referencing_table, object_name(reftabid) as referenced_table, '
+ 'sr.keycnt, sr.fokey1, sr.refkey1, u_t.name as referencing_owner, u_ref.name as referenced_owner, '
+ 'co_fo.name as referencing_column, co_ref.name as referenced_rolumn '
Variables.DefineVariable( 'lBindDataFlow', 'V²pis datov²ch tok∙ pod procesem',1 );
Variables.lBindDataFlow = true;
};
]]></VALUE>
<LANGUAGE>1</LANGUAGE>
<LANGUAGEWIN>csy</LANGUAGEWIN>
<CATEGORY>4</CATEGORY>
<MAINSCRIPT>1</MAINSCRIPT>
<EVENTSCRIPTTYPE>0</EVENTSCRIPTTYPE>
<DESCRIPTION><![CDATA[Zßkladnφ report k modelu datov²ch tok∙ optimalizovan² pro MS Word. Lze spustit i na jin²ch editorech, kterΘ podporujφ RTF. (nap°. 602Text,WordPad,StarOffice...)
ZaÜkrtnutφm polφΦka "Pou₧φvat odkazy v reportu" se lze rychle a pohodln∞ pohybovat v reportu k danΘmu objektu (pro editor MS WORD).]]></DESCRIPTION>
Variables.DefineVariable( 'lBindDataFlow', 'Summary of data flows under process', 1 );
Variables.lBindDataFlow = true;
};
]]></VALUE>
<LANGUAGE>1</LANGUAGE>
<LANGUAGEWIN>enu</LANGUAGEWIN>
<CATEGORY>4</CATEGORY>
<MAINSCRIPT>1</MAINSCRIPT>
<EVENTSCRIPTTYPE>0</EVENTSCRIPTTYPE>
<DESCRIPTION><![CDATA[Basic report to data flow model optimized for MS Word. Can be launched also under different editors supporting RTF (e.g. 602Text,WordPad,StarOffice...)
By checking field "Use references under report" you can move faster and easier inside of report towards a specified object (for editor MS WORD).]]></DESCRIPTION>
<DESCRIPTION><![CDATA[Zßkladnφ logick² entitn∞ relaΦnφ report optimalizovan² pro MS Word. Lze spustit i na jin²ch editorech, kterΘ podporujφ RTF. (nap°. 602Text,WordPad,StarOffice...)
ZaÜkrtnutφm polφΦka "Pou₧φvat odkazy v reportu" se lze rychle a pohodln∞ pohybovat v reportu k danΘmu objektu (pro editor MS WORD).]]></DESCRIPTION>
<DESCRIPTION><![CDATA[Basic logical entity-relationship report optimized for the MS Word. It can be run under any word editor supporting the RTF.
You can move fast and easily towards an object within the report just by checking the field "Use references inside of report" (applies to MS Word editor).]]></DESCRIPTION>