207 lines
8.6 KiB
Plaintext
207 lines
8.6 KiB
Plaintext
#+ DB schema - Constraints Management (dbdgii)
|
|
|
|
--------------------------------------------------------------------------------
|
|
--This code is generated with the template dbapp5.0
|
|
--Warning: Enter your changes within a <BLOCK> or <POINT> section, otherwise they will be lost.
|
|
{<POINT Name="user.comments">} {</POINT>}
|
|
|
|
--------------------------------------------------------------------------------
|
|
--Importing modules
|
|
IMPORT FGL libdbappCore
|
|
|
|
IMPORT FGL dbdgii
|
|
IMPORT FGL dbdgii_events
|
|
{<POINT Name="import">} {</POINT>}
|
|
|
|
--------------------------------------------------------------------------------
|
|
--Database schema
|
|
SCHEMA dbdgii
|
|
|
|
--------------------------------------------------------------------------------
|
|
--Functions
|
|
|
|
{<BLOCK Name="fct.empresastmp_checkTableConstraints">}
|
|
#+ Check constraints on the "empresastmp" table
|
|
#+
|
|
#+ @param p_forUpdate TRUE: for 'update' SQL operation, FALSE for 'insert' SQL operation
|
|
#+ @param p_data - a row data LIKE empresastmp.*
|
|
#+
|
|
#+ @returnType INTEGER, STRING
|
|
#+ @return ERROR_SUCCESS|ERROR_FAILURE, error message
|
|
PUBLIC FUNCTION dbdgii_dbxconstraints_empresastmp_checkTableConstraints(p_forUpdate, p_data)
|
|
DEFINE p_forUpdate BOOLEAN
|
|
DEFINE p_data RECORD LIKE empresastmp.*
|
|
DEFINE errNo INTEGER
|
|
DEFINE errMsg STRING
|
|
DEFINE l_errNo INTEGER
|
|
DEFINE l_errMsg STRING
|
|
{<POINT Name="fct.empresastmp_checkTableConstraints.define">} {</POINT>}
|
|
|
|
LET errNo = ERROR_SUCCESS
|
|
INITIALIZE errMsg TO NULL
|
|
{<POINT Name="fct.empresastmp_checkTableConstraints.init">} {</POINT>}
|
|
|
|
CALL dbdgii_dbxconstraints_empresastmp_rnc_checkColumnConstraints(p_data.rnc) RETURNING l_errNo, l_errMsg
|
|
CALL libdbapp_utilBuildErrorNoAndErrorMsg(errNo, errMsg, l_errNo, l_errMsg) RETURNING errNo, errMsg
|
|
|
|
CALL dbdgii_dbxconstraints_empresastmp_pk_empresastmp_checkUniqueConstraint(p_forUpdate, p_data.rnc) RETURNING l_errNo, l_errMsg
|
|
CALL libdbapp_utilBuildErrorNoAndErrorMsg(errNo, errMsg, l_errNo, l_errMsg) RETURNING errNo, errMsg
|
|
|
|
IF dbdgii_events.m_DbxDataEvent_empresastmp_CheckTableConstraints IS NOT NULL THEN
|
|
CALL dbdgii_events.m_DbxDataEvent_empresastmp_CheckTableConstraints(p_forUpdate, p_data.*)
|
|
RETURNING l_errNo, l_errMsg
|
|
END IF
|
|
CALL libdbapp_utilBuildErrorNoAndErrorMsg(errNo, errMsg, l_errNo, l_errMsg) RETURNING errNo, errMsg
|
|
|
|
{<POINT Name="fct.empresastmp_checkTableConstraints.user">} {</POINT>}
|
|
RETURN errNo, errMsg
|
|
END FUNCTION
|
|
{</BLOCK>} --fct.empresastmp_checkTableConstraints
|
|
|
|
{<BLOCK Name="fct.empresastmp_pk_empresastmp_checkUniqueConstraint">}
|
|
#+ Check the primary key uniqueness constraint on the "empresastmp"
|
|
#+
|
|
#+ @param p_forUpdate TRUE: for 'update' SQL operation, FALSE for 'insert' SQL operation
|
|
#+ @param p_key - Primary Key
|
|
#+
|
|
#+ @returnType INTEGER, STRING, STRING
|
|
#+ @return ERROR_SUCCESS|ERROR_FAILURE, error message
|
|
PUBLIC FUNCTION dbdgii_dbxconstraints_empresastmp_pk_empresastmp_checkUniqueConstraint(p_forUpdate, p_key)
|
|
DEFINE errNo INTEGER
|
|
DEFINE errMsg STRING
|
|
DEFINE p_forUpdate BOOLEAN
|
|
DEFINE p_key
|
|
RECORD
|
|
empresastmp_rnc LIKE empresastmp.rnc
|
|
END RECORD
|
|
DEFINE l_key
|
|
RECORD
|
|
empresastmp_rnc LIKE empresastmp.rnc
|
|
END RECORD
|
|
DEFINE l_where STRING
|
|
DEFINE l_sqlQuery STRING
|
|
DEFINE l_count INTEGER
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_checkUniqueConstraint.define">} {</POINT>}
|
|
|
|
LET errNo = ERROR_SUCCESS
|
|
INITIALIZE errMsg TO NULL
|
|
LET l_where = "WHERE empresastmp.rnc = ? "
|
|
LET l_sqlQuery = "SELECT COUNT(*), rnc FROM empresastmp ", l_where, " GROUP BY rnc"
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_checkUniqueConstraint.init">} {</POINT>}
|
|
TRY
|
|
PREPARE cur_empresastmp_pk_empresastmp_checkUniqueConstraint FROM l_sqlQuery
|
|
EXECUTE cur_empresastmp_pk_empresastmp_checkUniqueConstraint USING p_key.* INTO l_count, l_key.*
|
|
FREE cur_empresastmp_pk_empresastmp_checkUniqueConstraint
|
|
IF (NOT p_forUpdate AND l_count > 0) OR (p_forUpdate AND l_count > 0 AND p_key.* != l_key.*) THEN
|
|
CALL libdbapp_utilBuildErrorNoAndErrorMsg(errNo, errMsg, ERROR_FAILURE, "\n- rnc: " || ERROR_BAM_00002) RETURNING errNo, errMsg
|
|
END IF
|
|
CATCH
|
|
LET errNo = ERROR_FAILURE
|
|
END TRY
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_checkUniqueConstraint.user">} {</POINT>}
|
|
|
|
RETURN errNo, errMsg
|
|
END FUNCTION
|
|
{</BLOCK>} --fct.empresastmp_pk_empresastmp_checkUniqueConstraint
|
|
|
|
{<BLOCK Name="fct.empresastmp_rnc_checkColumnConstraints">}
|
|
#+ Check constraints on the "empresastmp.rnc" column
|
|
#+
|
|
#+ @param p_rnc - CHAR(11) - rnc
|
|
#+
|
|
#+ @returnType INTEGER, STRING
|
|
#+ @return ERROR_SUCCESS|ERROR_FAILURE, error message
|
|
PUBLIC FUNCTION dbdgii_dbxconstraints_empresastmp_rnc_checkColumnConstraints(p_rnc)
|
|
DEFINE errNo INTEGER
|
|
DEFINE errMsg STRING
|
|
DEFINE p_rnc LIKE empresastmp.rnc
|
|
{<POINT Name="fct.empresastmp_rnc_checkColumnConstraints.define">} {</POINT>}
|
|
|
|
LET errNo = ERROR_SUCCESS
|
|
INITIALIZE errMsg TO NULL
|
|
{<POINT Name="fct.empresastmp_rnc_checkColumnConstraints.init">} {</POINT>}
|
|
IF p_rnc IS NULL THEN
|
|
CALL libdbapp_utilBuildErrorNoAndErrorMsg(errNo, errMsg, ERROR_FAILURE, "\n- rnc: " || ERROR_BAM_00001) RETURNING errNo, errMsg
|
|
END IF
|
|
{<POINT Name="fct.empresastmp_rnc_checkColumnConstraints.user">} {</POINT>}
|
|
RETURN errNo, errMsg
|
|
END FUNCTION
|
|
{</BLOCK>} --fct.empresastmp_rnc_checkColumnConstraints
|
|
|
|
{<BLOCK Name="fct.empresastmp_pk_empresastmp_checkFKConstraint">}
|
|
#+ Check the Foreign Key existence constraint on the "empresastmp"
|
|
#+
|
|
#+ @param p_data - Primary Key
|
|
#+
|
|
#+ @returnType INTEGER, STRING
|
|
#+ @return ERROR_SUCCESS|ERROR_FAILURE, error message
|
|
PUBLIC FUNCTION dbdgii_dbxconstraints_empresastmp_pk_empresastmp_checkFKConstraint(p_data)
|
|
DEFINE errNo INTEGER
|
|
DEFINE errMsg STRING
|
|
DEFINE p_data
|
|
RECORD
|
|
empresastmp_rnc LIKE empresastmp.rnc
|
|
END RECORD
|
|
DEFINE l_where STRING
|
|
DEFINE l_sqlQuery STRING
|
|
DEFINE l_count INTEGER
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_checkFKConstraint.define">} {</POINT>}
|
|
|
|
LET errNo = ERROR_SUCCESS
|
|
INITIALIZE errMsg TO NULL
|
|
IF NOT (p_data.empresastmp_rnc IS NULL) THEN
|
|
LET l_where = "WHERE empresastmp.rnc = ? "
|
|
LET l_sqlQuery = "SELECT COUNT(*) FROM empresastmp ", l_where
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_checkFKConstraint.init">} {</POINT>}
|
|
TRY
|
|
PREPARE cur_empresastmp_pk_empresastmp_checkFKConstraint FROM l_sqlQuery
|
|
EXECUTE cur_empresastmp_pk_empresastmp_checkFKConstraint USING p_data.* INTO l_count
|
|
FREE cur_empresastmp_pk_empresastmp_checkFKConstraint
|
|
IF (l_count == 0) THEN
|
|
CALL libdbapp_utilBuildErrorNoAndErrorMsg(errNo, errMsg, ERROR_FAILURE, "\n- rnc: " || ERROR_BAM_00004) RETURNING errNo, errMsg
|
|
END IF
|
|
CATCH
|
|
LET errNo = ERROR_FAILURE
|
|
END TRY
|
|
END IF
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_checkFKConstraint.user">} {</POINT>}
|
|
RETURN errNo, errMsg
|
|
END FUNCTION
|
|
{</BLOCK>} --fct.empresastmp_pk_empresastmp_checkFKConstraint
|
|
|
|
{<BLOCK Name="fct.empresas_checkTableConstraints">}
|
|
#+ Check constraints on the "empresas" table
|
|
#+
|
|
#+ @param p_forUpdate TRUE: for 'update' SQL operation, FALSE for 'insert' SQL operation
|
|
#+ @param p_data - a row data LIKE empresas.*
|
|
#+
|
|
#+ @returnType INTEGER, STRING
|
|
#+ @return ERROR_SUCCESS|ERROR_FAILURE, error message
|
|
PUBLIC FUNCTION dbdgii_dbxconstraints_empresas_checkTableConstraints(p_forUpdate, p_data)
|
|
DEFINE p_forUpdate BOOLEAN
|
|
DEFINE p_data RECORD LIKE empresas.*
|
|
DEFINE errNo INTEGER
|
|
DEFINE errMsg STRING
|
|
DEFINE l_errNo INTEGER
|
|
DEFINE l_errMsg STRING
|
|
{<POINT Name="fct.empresas_checkTableConstraints.define">} {</POINT>}
|
|
|
|
LET errNo = ERROR_SUCCESS
|
|
INITIALIZE errMsg TO NULL
|
|
{<POINT Name="fct.empresas_checkTableConstraints.init">} {</POINT>}
|
|
|
|
IF dbdgii_events.m_DbxDataEvent_empresas_CheckTableConstraints IS NOT NULL THEN
|
|
CALL dbdgii_events.m_DbxDataEvent_empresas_CheckTableConstraints(p_forUpdate, p_data.*)
|
|
RETURNING l_errNo, l_errMsg
|
|
END IF
|
|
CALL libdbapp_utilBuildErrorNoAndErrorMsg(errNo, errMsg, l_errNo, l_errMsg) RETURNING errNo, errMsg
|
|
|
|
{<POINT Name="fct.empresas_checkTableConstraints.user">} {</POINT>}
|
|
RETURN errNo, errMsg
|
|
END FUNCTION
|
|
{</BLOCK>} --fct.empresas_checkTableConstraints
|
|
|
|
--------------------------------------------------------------------------------
|
|
--Add user functions
|
|
{<POINT Name="user.functions">} {</POINT>}
|