Get Compile Date and Time of OpenInsight Stored Procedure

Arev and OpenInsight both store a time stamp in the binary code of compiled stored procedures. It's difficult to view the compiled code in the system editor or debugger due to line marks and null characters causing the display to appear empty. In addition, the time stamp is also stored as an internal value which requires conversion to be useful.

The following code can be used to display the time stamp in human readable form simply by passing in the name of the routine.

Function CS_GetCompileDate(Routine)
* Read a compiled routine and extract the last compiled date and time stamp.
* Params:
* Routine - Name of the routine in the current OI application 
* Returns:
* Displays the date time in a message box. Also returns the value.
* Last Revised: 2016-04-17

Declare Function Read_Row, Index

*Name of the compiled routine. Assumes current application.
Convert @LOWER_CASE To @UPPER_CASE In Routine
Key = '$' : Routine : '*' : @APPID<1>

*Table containing compiled routines
OBJTableName = "SYSOBJ"

Open OBJTableName To Table Else 
	Call FSMsg()
	Return ''

Read ObjCode From Table, Key Else 
	Call Msg("Unable to read " : KEY : " from " : OBJTableName)
	Return ''

ObjCodeLen = Len(ObjCode)

*Find the last field in the record - it contains the date time
Chunk = ObjCode[-1,'B':@FM]

*Based on where the last field was, look backward a little further for the compile by ID
*It will be prefixed by two nulls
SearchToken = \00\:\00\

*Calculate the start of the two nulls from the end of the string
BackOffset = Len(Chunk) + Len(SearchToken)
BackOffset = -1 * BackOffset

*Extract from the start of the last field backward to the the start of the two nulls
CompiledBy = ObjCode[BackOffset, 'B':SearchToken]

*Trim the last field up to the first space to get only the date time
SearchToken = \00\
EndCodePos = Index(Chunk, SearchToken,1)

*Trim the chunk down, start at the character after the search token.
TimeChunk = Chunk[1, EndCodePos]

*Look for a NULL character at the end of the time chunk so we know where DateTime value ends
EndDelimPos = Index(TimeChunk, \00\, 1)

*Internal DateTime value ends 2 bytes before the end of the null char
DateTimeI = TimeChunk[1, (EndDelimPos - 2)]

*Convert to internal for display
DateTimeO = OConv(DateTimeI,'DT2/^H')

Call Msg("Progam last compiled " : DateTimeO : " by " : CompiledBy)
Return DateTimeO

After copying the code into your system you can call it from TCL (Press F5 when in OI development mode) and type:

run cs_getcompiledate YOUR_ROUTINE_NAME

The code will read the SYSOBJ table where YOUR_ROUTINE_NAME name is stored and display a message box with the last compiled date time stamp.

If you're working strictly in OpenInsight you can also use the GetLastUpdate method to find the last modified time of stored procedures and additional repository types. Thanks for the reminder Daniel!

Share this post

Comments (2)

  • anon

    Couldn't one use the Repository GetLastUpdate Method?

    Mar 23, 2016
  • Jared Bratu's picture

    Thanks for sharing, GetLastUpdate works too and for more types of repository resources than just compiled stored procedures. Getting the compiled date directly from the compiled code dates back to my days working in Arev before the repository came along.

    Jul 23, 2016

Leave a comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

About Us

Congruity Service is a technology solutions company bringing the best technology solutions to OpenInsight projects, Drupal sites, servers, networks, and your technology needs.