Hello, I have a function that checks if a column exists in the current database. This is required because in some instances that column might not exist. My current code works mostly fine, but it raises an error and that might break stuff. For example, calling this function during a DataFlex Reports RDS load event might stop the report or it could affect a BusinessProcess execution. I need something similar that doesn't raise an error in order to avoid it. I have tried to "silence" that error with some workarounds but it didn't work. Do you have any ideas to do that with no internal errors?
Current code:
Code:
Function DoesColumnExist Integer iTableNumber String sColumnName Returns Boolean
Handle hoErrorHandler
Boolean bExists
Integer iField
#IFDEF Is$WebApp
Move ghoWebErrorHandler to hoErrorHandler
#ELSE
Move Error_Object_Id to hoErrorHandler
#ENDIF
If (hoErrorHandler=0) Begin
Function_Return False
End
Move (Uppercase(sColumnName )) to sColumnName
Move False to Err
Send Ignore_Error of hoErrorHandler DFERR_CANT_FIND_FIELD
Field_Map iTableNumber sColumnName to iField
Send Trap_Error of hoErrorHandler DFERR_CANT_FIND_FIELD
Move (not (Err) and iField > 0) to bExists
Function_Return bExists
End_Function
* I know it can be done using SQL queries (I don't need it to work with the embbeded database) but I prefer to avoid it as a custom query for each database engine would be required.