KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility Method to Find if a Table is Journaled
PRODUCT: 4D | VERSION: 14.x | PLATFORM: Mac & Win
Published On: December 10, 2015

Below is a utility method that will return a boolean output based on whether the passed table name is journaled or not.

// Method: IsTableJournaled
// Parameters:
// $1 - String Table Name
// Output:
// $0 = True: Is Journaled
// $0 = False: Is NOT Journaled
// Method does not check if table actually exists
//-----------------------------------------------------------------------

C_TEXT($1;$tableName_t)
C_BOOLEAN($0)
C_TEXT($struct_t;$xmlRef_t;$elemRef_t;$elemName_t;$value_t;$res_t)
C_BOOLEAN($stop_b;$failed_b)

EXPORT STRUCTURE($struct_t)
$xmlRef_t:=DOM Parse XML variable($struct_t)
DOM GET XML ELEMENT NAME($xmlRef_t;$elemName_t)
$tableName_t:=$1
If($elemName_t="base")
  $elemRef_t:=DOM Get first child XML element($xmlRef_t;$elemName_t)
  $stop_b:=False
  While($stop_b=False)
    If ($elemName_t="table")
      DOM GET XML ATTRIBUTE BY NAME($elemRef_t;"name";$value_t)
      If ($value_t=$tableName_t)
        ON ERR CALL("err_method")
        DOM GET XML ATTRIBUTE BY NAME($elemRef_t;"prevent_journaling";$res_t)
        If (ok=0)
          $res_t:="false"
        End if
        ON ERR CALL("")
        $stop_b:=True
      End if
    End if
    If($stop_b=False)
      $elemRef_t:=DOM Get next sibling XML element($elemRef_t;$elemName_t)
      If (OK=0)
        $stop_b:=True
      End if
    End if
  End while
End if

If($res_t="true")
  $0:=False
Else
  $0:=True
End if


"err_method" is used for the ON ERR CALL is a blank method to escape the error encountered when attribute is not found due to the default being false.