Skip to Content
Author's profile photo Former Member

Search for all tables that do not have the column “timeStamp”, and add it

I always add the field “timeStamp”, which i call it in my DBs “row_timestamp“, so to lessen my forgetfulness and to ease on my typing of it in each table, the following script will add it to all tables that do not have it.

also benefits for:

  Adding specific fields to all tables

Option Explicit
Dim mdl ' the current model
Dim fldr
Dim sSearchCode
Dim sSearchCodeExchange
Dim RQ
dim iCountAddedNewColumn, iCountNotAddedNewColumn, iCountEntities
dim FSO
dim txtStream
dim sCSVFile
' get the current active model
Set mdl = ActiveModel
call mainProcedure
' Main function
sub mainProcedure()
   If (mdl Is Nothing) Then
      MsgBox "There is no Active Model"
   End If
   If Not mdl.IsKindOf(PdCDM.cls_Model) Then
      MsgBox "This is not CDM"
      exit sub
   end if
   Set Fldr = ActiveDiagram.Parent
   RQ = MsgBox ("Starting at Folder: " & Fldr.Name & " Is Run ?", vbYesNo + vbInformation,"Confirmation")
   if RQ= VbNo then
      exit sub
   end if
   output  "Added Fields = " & iCountAddedNewColumn & " in " & iCountEntities & " Entities. and not changed = " &  iCountNotAddedNewColumn
end sub
' Receptively search for all tables, to add to them the required field
Sub searchAllTables(parentFolder_)
   Dim obj ' running object
   For Each obj In parentFolder_.children
      if obj.ClassName="Entity" then
         iCountEntities = iCountEntities + 1
         addColumnToEntity obj
      end if
   ' go into the sub-packages
   Dim innerFolder ' running folder
   For Each innerFolder In parentFolder_.Packages
      searchAllTables innerFolder
End Sub
' Check if the column is not found then add it
Sub addColumnToEntity(entity_)
   if entity_.ClassName <>"Entity" then exit sub
   'Export informations to the output list
   'output "Found "+entity_.ClassName+" "+entity_.Name+", Created by "+entity_.Creator+" On "+mid(Cstr(entity_.CreationDate),1,10) 
   Dim attr
   Dim isFound
   For Each attr In entity_.Attributes
      if attr.code = sSearchCode  then 'instr(1, attr.code, sSearchCode, 1)>0
         attr.Mandatory = false
         attr.code = sSearchCodeExchange
  exit for
      end if
   If isFound=false Then
      iCountAddedNewColumn= iCountAddedNewColumn + 1
      Set attr = entity_.Attributes.CreateNew  ' Creating Attribute
      attr.Name = "متغير عند تغيير السطر"
      attr.Code = sSearchCodeExchange
      attr.Mandatory = false
      'attr.Domain = "TypeTimeStamp_Dom"
      iCountNotAddedNewColumn= iCountNotAddedNewColumn + 1
   End If
End Sub

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.