333 lines
15 KiB
Plaintext
333 lines
15 KiB
Plaintext
#+ DB schema - Data 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 libdbappSql
|
|
|
|
IMPORT FGL dbdgii
|
|
IMPORT FGL dbdgii_events
|
|
IMPORT FGL dbdgii_dbxconstraints
|
|
{<POINT Name="import">} {</POINT>}
|
|
|
|
--------------------------------------------------------------------------------
|
|
--Database schema
|
|
SCHEMA dbdgii
|
|
|
|
--------------------------------------------------------------------------------
|
|
--Functions
|
|
|
|
{<BLOCK Name="fct.empresastmp_pk_empresastmp_selectRowByKey">}
|
|
#+ Select a row identified by the primary key in the "empresastmp" table
|
|
#+
|
|
#+ @param p_key - Primary Key
|
|
#+ @param p_lock - Indicate if a lock is used in order to prevent several users editing the same rows at the same time
|
|
#+
|
|
#+ @returnType INTEGER, LIKE empresastmp.*
|
|
#+ @return ERROR_SUCCESS|ERROR_FAILURE|ERROR_NOTFOUND, RECORD LIKE empresastmp.*
|
|
PUBLIC FUNCTION dbdgii_dbxdata_empresastmp_pk_empresastmp_selectRowByKey(p_key, p_lock)
|
|
DEFINE p_key
|
|
RECORD
|
|
empresastmp_rnc LIKE empresastmp.rnc
|
|
END RECORD
|
|
DEFINE p_lock BOOLEAN
|
|
DEFINE l_data RECORD LIKE empresastmp.*
|
|
DEFINE l_supportLock BOOLEAN
|
|
DEFINE errNo INTEGER
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_selectRowByKey.define">} {</POINT>}
|
|
|
|
LET errNo = ERROR_SUCCESS
|
|
-- SQLite does not support the FOR UPDATE close in SELECT syntax
|
|
LET l_supportLock = (UPSHIFT(fgl_db_driver_type()) != "SQT")
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_selectRowByKey.init">} {</POINT>}
|
|
TRY
|
|
IF p_lock AND l_supportLock THEN
|
|
SELECT * INTO l_data.* FROM empresastmp
|
|
WHERE @empresastmp.rnc = p_key.empresastmp_rnc
|
|
FOR UPDATE
|
|
ELSE
|
|
SELECT * INTO l_data.* FROM empresastmp
|
|
WHERE @empresastmp.rnc = p_key.empresastmp_rnc
|
|
END IF
|
|
IF SQLCA.SQLCODE == NOTFOUND THEN
|
|
LET errNo = ERROR_NOTFOUND
|
|
END IF
|
|
CATCH
|
|
INITIALIZE l_data.* TO NULL
|
|
LET errNo = ERROR_FAILURE
|
|
END TRY
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_selectRowByKey.afterSelect">} {</POINT>}
|
|
RETURN errNo, l_data.*
|
|
END FUNCTION
|
|
{</BLOCK>} --fct.empresastmp_pk_empresastmp_selectRowByKey
|
|
|
|
{<BLOCK Name="fct.empresastmp_insertRowByKey">}
|
|
#+ Insert a row in the "empresastmp" table and return the primary key created
|
|
#+
|
|
#+ @param p_data - a row data LIKE empresastmp.*
|
|
#+
|
|
#+ @returnType INTEGER, STRING, CHAR(11)
|
|
#+ @return ERROR_SUCCESS|ERROR_FAILURE, error message, empresastmp.rnc
|
|
PRIVATE FUNCTION dbdgii_dbxdata_empresastmp_insertRowByKey(p_data)
|
|
DEFINE p_data RECORD LIKE empresastmp.*
|
|
DEFINE errNo INTEGER
|
|
DEFINE errMsg STRING
|
|
{<POINT Name="fct.empresastmp_insertRowByKey.define">} {</POINT>}
|
|
|
|
LET errNo = libdbapp_begin_work()
|
|
IF errNo == ERROR_SUCCESS THEN
|
|
{<POINT Name="fct.empresastmp_insertRowByKey.init">} {</POINT>}
|
|
|
|
IF dbdgii_events.m_DbxDataEvent_empresastmp_BeforeInsertRowByKey IS NOT NULL THEN
|
|
CALL dbdgii_events.m_DbxDataEvent_empresastmp_BeforeInsertRowByKey(p_data.*)
|
|
RETURNING errNo, errMsg, p_data.*
|
|
END IF
|
|
IF errNo == ERROR_SUCCESS THEN
|
|
CALL dbdgii_dbxconstraints.dbdgii_dbxconstraints_empresastmp_checkTableConstraints(FALSE, p_data.*) RETURNING errNo, errMsg
|
|
END IF
|
|
{<POINT Name="fct.empresastmp_insertRowByKey.beforeInsert" Aliases="fct.empresastmp_insertRowByKey.afterConstraints">} {</POINT>}
|
|
IF errNo == ERROR_SUCCESS THEN
|
|
TRY
|
|
INSERT INTO empresastmp VALUES (p_data.*)
|
|
CATCH
|
|
LET errNo = ERROR_FAILURE
|
|
END TRY
|
|
IF dbdgii_events.m_DbxDataEvent_empresastmp_AfterInsertRowByKey IS NOT NULL THEN
|
|
CALL dbdgii_events.m_DbxDataEvent_empresastmp_AfterInsertRowByKey(p_data.*)
|
|
RETURNING errNo, errMsg
|
|
END IF
|
|
{<POINT Name="fct.empresastmp_insertRowByKey.afterInsert">} {</POINT>}
|
|
END IF
|
|
IF errNo == ERROR_SUCCESS THEN
|
|
LET errNo = libdbapp_commit_work()
|
|
ELSE
|
|
CALL libdbapp_rollback_work()
|
|
END IF
|
|
END IF
|
|
RETURN errNo, errMsg, p_data.rnc
|
|
END FUNCTION
|
|
{</BLOCK>} --fct.empresastmp_insertRowByKey
|
|
|
|
{<BLOCK Name="fct.empresastmp_pk_empresastmp_insertRowByKey">}
|
|
#+ Insert a row in the "empresastmp" table and return the table keys
|
|
#+
|
|
#+ @param p_data - a row data LIKE empresastmp.*
|
|
#+
|
|
#+ @returnType INTEGER, STRING, CHAR(11)
|
|
#+ @return ERROR_SUCCESS|ERROR_FAILURE, error message, empresastmp.rnc
|
|
PUBLIC FUNCTION dbdgii_dbxdata_empresastmp_pk_empresastmp_insertRowByKey(p_data)
|
|
DEFINE p_data RECORD LIKE empresastmp.*
|
|
DEFINE errNo INTEGER
|
|
DEFINE errMsg STRING
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_insertRowByKey.define">} {</POINT>}
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_insertRowByKey.init">} {</POINT>}
|
|
|
|
CALL dbdgii_dbxdata_empresastmp_insertRowByKey(p_data.*) RETURNING errNo, errMsg, p_data.rnc
|
|
RETURN errNo, errMsg, p_data.rnc
|
|
END FUNCTION
|
|
{</BLOCK>} --fct.empresastmp_pk_empresastmp_insertRowByKey
|
|
|
|
{<BLOCK Name="fct.empresastmp_pk_empresastmp_updateRowByKey">}
|
|
#+ Update a row identified by the primary key in the "empresastmp" table
|
|
#+
|
|
#+ @param p_dataT0 - a row data LIKE empresastmp.*
|
|
#+ @param p_dataT1 - a row data LIKE empresastmp.*
|
|
#+
|
|
#+ @returnType INTEGER, STRING
|
|
#+ @return ERROR_SUCCESS|ERROR_FAILURE|ERROR_CONCURRENT_ACCESS_NOTFOUND|ERROR_CONCURRENT_ACCESS_FAILURE, error message
|
|
PUBLIC FUNCTION dbdgii_dbxdata_empresastmp_pk_empresastmp_updateRowByKey(p_dataT0, p_dataT1)
|
|
DEFINE p_dataT0 RECORD LIKE empresastmp.*
|
|
DEFINE p_dataT1 RECORD LIKE empresastmp.*
|
|
DEFINE l_key
|
|
RECORD
|
|
empresastmp_rnc LIKE empresastmp.rnc
|
|
END RECORD
|
|
DEFINE errNo INTEGER
|
|
DEFINE errMsg STRING
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_updateRowByKey.define">} {</POINT>}
|
|
LET l_key.empresastmp_rnc = p_dataT0.rnc
|
|
INITIALIZE errMsg TO NULL
|
|
LET errNo = libdbapp_begin_work()
|
|
IF errNo == ERROR_SUCCESS THEN
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_updateRowByKey.init">} {</POINT>}
|
|
TRY
|
|
LET errNo = dbdgii_dbxdata_empresastmp_pk_empresastmp_checkRowByKeyWithConcurrentAccess(p_dataT0.*, TRUE)
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_updateRowByKey.afterSelect">} {</POINT>}
|
|
IF errNo == ERROR_SUCCESS THEN
|
|
CALL dbdgii_dbxconstraints.dbdgii_dbxconstraints_empresastmp_checkTableConstraints(TRUE, p_dataT1.*) RETURNING errNo, errMsg
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_updateRowByKey.beforeUpdate" Aliases="fct.empresastmp_pk_empresastmp_updateRowByKey.afterConstraints">} {</POINT>}
|
|
IF errNo == ERROR_SUCCESS THEN
|
|
IF dbdgii_events.m_DbxDataEvent_empresastmp_BeforeUpdateRowByKey IS NOT NULL THEN
|
|
CALL dbdgii_events.m_DbxDataEvent_empresastmp_BeforeUpdateRowByKey(p_dataT1.*)
|
|
RETURNING errNo, errMsg
|
|
END IF
|
|
UPDATE empresastmp
|
|
SET empresastmp.* = p_dataT1.*
|
|
WHERE @empresastmp.rnc = l_key.empresastmp_rnc
|
|
END IF
|
|
END IF
|
|
CATCH
|
|
LET errNo = ERROR_FAILURE
|
|
END TRY
|
|
IF dbdgii_events.m_DbxDataEvent_empresastmp_AfterUpdateRowByKey IS NOT NULL THEN
|
|
CALL dbdgii_events.m_DbxDataEvent_empresastmp_AfterUpdateRowByKey(p_dataT1.*)
|
|
RETURNING errNo, errMsg
|
|
END IF
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_updateRowByKey.afterUpdate">} {</POINT>}
|
|
IF errNo == ERROR_SUCCESS THEN
|
|
LET errNo = libdbapp_commit_work()
|
|
ELSE
|
|
CALL libdbapp_rollback_work()
|
|
END IF
|
|
END IF
|
|
RETURN errNo, errMsg
|
|
END FUNCTION
|
|
{</BLOCK>} --fct.empresastmp_pk_empresastmp_updateRowByKey
|
|
|
|
{<BLOCK Name="fct.empresastmp_pk_empresastmp_deleteRowByKey">}
|
|
#+ Delete a row identified by the primary key in the "empresastmp" table
|
|
#+
|
|
#+ @param p_key - Primary Key
|
|
#+
|
|
#+ @returnType INTEGER
|
|
#+ @return ERROR_SUCCESS|ERROR_FAILURE|ERROR_DELETE_CASCADE_ROW_USED
|
|
PUBLIC FUNCTION dbdgii_dbxdata_empresastmp_pk_empresastmp_deleteRowByKey(p_key)
|
|
DEFINE p_key
|
|
RECORD
|
|
empresastmp_rnc LIKE empresastmp.rnc
|
|
END RECORD
|
|
DEFINE errNo INTEGER
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_deleteRowByKey.define">} {</POINT>}
|
|
|
|
LET errNo = libdbapp_begin_work()
|
|
IF errNo == ERROR_SUCCESS THEN
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_deleteRowByKey.init">} {</POINT>}
|
|
IF dbdgii_events.m_DbxDataEvent_empresastmp_BeforeDeleteRowByKey IS NOT NULL THEN
|
|
CALL dbdgii_events.m_DbxDataEvent_empresastmp_BeforeDeleteRowByKey(p_key.*)
|
|
RETURNING errNo
|
|
END IF
|
|
TRY
|
|
DELETE FROM empresastmp
|
|
WHERE @empresastmp.rnc = p_key.empresastmp_rnc
|
|
CATCH
|
|
LET errNo = ERROR_FAILURE
|
|
END TRY
|
|
IF dbdgii_events.m_DbxDataEvent_empresastmp_AfterDeleteRowByKey IS NOT NULL THEN
|
|
CALL dbdgii_events.m_DbxDataEvent_empresastmp_AfterDeleteRowByKey(p_key.*)
|
|
RETURNING errNo
|
|
END IF
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_deleteRowByKey.afterDelete">} {</POINT>}
|
|
IF errNo == ERROR_SUCCESS THEN
|
|
LET errNo = libdbapp_commit_work()
|
|
ELSE
|
|
CALL libdbapp_rollback_work()
|
|
END IF
|
|
END IF
|
|
RETURN errNo
|
|
END FUNCTION
|
|
{</BLOCK>} --fct.empresastmp_pk_empresastmp_deleteRowByKey
|
|
|
|
{<BLOCK Name="fct.empresastmp_pk_empresastmp_deleteRowByKeyWithConcurrentAccess">}
|
|
#+ Delete a row identified by the primary key in the "empresastmp" table if the concurrent access is success
|
|
#+
|
|
#+ @param p_dataT0 - a row data LIKE empresastmp.*
|
|
#+
|
|
#+ @returnType INTEGER
|
|
#+ @return ERROR_SUCCESS|ERROR_FAILURE|ERROR_CONCURRENT_ACCESS_NOTFOUND|ERROR_CONCURRENT_ACCESS_FAILURE|ERROR_DELETE_CASCADE_ROW_USED
|
|
PUBLIC FUNCTION dbdgii_dbxdata_empresastmp_pk_empresastmp_deleteRowByKeyWithConcurrentAccess(p_dataT0)
|
|
DEFINE p_dataT0 RECORD LIKE empresastmp.*
|
|
DEFINE l_key
|
|
RECORD
|
|
empresastmp_rnc LIKE empresastmp.rnc
|
|
END RECORD
|
|
DEFINE errNo INTEGER
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_deleteRowByKeyWithConcurrentAccess.define">} {</POINT>}
|
|
|
|
LET l_key.empresastmp_rnc = p_dataT0.rnc
|
|
LET errNo = libdbapp_begin_work()
|
|
IF errNo == ERROR_SUCCESS THEN
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_deleteRowByKeyWithConcurrentAccess.init">} {</POINT>}
|
|
LET errNo = dbdgii_dbxdata_empresastmp_pk_empresastmp_checkRowByKeyWithConcurrentAccess(p_dataT0.*, TRUE)
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_deleteRowByKeyWithConcurrentAccess.afterSelect">} {</POINT>}
|
|
IF errNo == ERROR_SUCCESS THEN
|
|
LET errNo = dbdgii_dbxdata_empresastmp_pk_empresastmp_deleteRowByKey(l_key.*)
|
|
END IF
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_deleteRowByKeyWithConcurrentAccess.afterDelete">} {</POINT>}
|
|
IF errNo == ERROR_SUCCESS THEN
|
|
LET errNo = libdbapp_commit_work()
|
|
ELSE
|
|
CALL libdbapp_rollback_work()
|
|
END IF
|
|
END IF
|
|
RETURN errNo
|
|
END FUNCTION
|
|
{</BLOCK>} --fct.empresastmp_pk_empresastmp_deleteRowByKeyWithConcurrentAccess
|
|
|
|
{<BLOCK Name="fct.empresastmp_pk_empresastmp_checkRowByKeyWithConcurrentAccess">}
|
|
#+ Check if a row identified by the primary key in the "empresastmp" table has been modified or deleted
|
|
#+
|
|
#+ @param p_dataT0 - a row data LIKE empresastmp.*
|
|
#+ @param p_lock - Indicate if a lock is used in order to prevent several users editing the same rows at the same time
|
|
#+
|
|
#+ @returnType INTEGER
|
|
#+ @return ERROR_SUCCESS|ERROR_FAILURE|ERROR_CONCURRENT_ACCESS_NOTFOUND|ERROR_CONCURRENT_ACCESS_FAILURE
|
|
PUBLIC FUNCTION dbdgii_dbxdata_empresastmp_pk_empresastmp_checkRowByKeyWithConcurrentAccess(p_dataT0, p_lock)
|
|
DEFINE p_dataT0 RECORD LIKE empresastmp.*
|
|
DEFINE l_dataT2 RECORD LIKE empresastmp.*
|
|
DEFINE l_key
|
|
RECORD
|
|
empresastmp_rnc LIKE empresastmp.rnc
|
|
END RECORD
|
|
DEFINE p_lock BOOLEAN
|
|
DEFINE errNo INTEGER
|
|
DEFINE errDiff INTEGER
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_checkRowByKeyWithConcurrentAccess.define">} {</POINT>}
|
|
|
|
LET l_key.empresastmp_rnc = p_dataT0.rnc
|
|
INITIALIZE l_dataT2.* TO NULL
|
|
LET errDiff = FALSE
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_checkRowByKeyWithConcurrentAccess.init">} {</POINT>}
|
|
CALL dbdgii_dbxdata_empresastmp_pk_empresastmp_selectRowByKey(l_key.*, p_lock) RETURNING errNo, l_dataT2.*
|
|
CASE errNo
|
|
WHEN ERROR_SUCCESS
|
|
LET errDiff = (p_dataT0.* != l_dataT2.*)
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_checkRowByKeyWithConcurrentAccess.afterSelect">} {</POINT>}
|
|
IF NOT errDiff THEN
|
|
LET errNo = ERROR_SUCCESS
|
|
ELSE
|
|
LET errNo = ERROR_CONCURRENT_ACCESS_FAILURE
|
|
END IF
|
|
WHEN ERROR_NOTFOUND
|
|
LET errNo = ERROR_CONCURRENT_ACCESS_NOTFOUND
|
|
END CASE
|
|
{<POINT Name="fct.empresastmp_pk_empresastmp_checkRowByKeyWithConcurrentAccess.afterCheck">} {</POINT>}
|
|
RETURN errNo
|
|
END FUNCTION
|
|
{</BLOCK>} --fct.empresastmp_pk_empresastmp_checkRowByKeyWithConcurrentAccess
|
|
|
|
{<BLOCK Name="fct.empresastmp_setDefaultValuesFromDBSchema">}
|
|
#+ Set data with the default values coming from the DB schema
|
|
#+
|
|
PUBLIC FUNCTION dbdgii_dbxdata_empresastmp_setDefaultValuesFromDBSchema()
|
|
DEFINE l_data RECORD LIKE empresastmp.*
|
|
{<POINT Name="fct.empresastmp_setDefaultValuesFromDBSchema.define">} {</POINT>}
|
|
|
|
INITIALIZE l_data.* TO NULL
|
|
{<POINT Name="fct.empresastmp_setDefaultValuesFromDBSchema.init">} {</POINT>}
|
|
IF dbdgii_events.m_DbxDataEvent_empresastmp_SetDefaultValues IS NOT NULL THEN
|
|
CALL dbdgii_events.m_DbxDataEvent_empresastmp_SetDefaultValues(l_data.*)
|
|
RETURNING l_data.*
|
|
END IF
|
|
RETURN l_data.*
|
|
END FUNCTION
|
|
{</BLOCK>} --fct.empresastmp_setDefaultValuesFromDBSchema
|
|
|
|
--------------------------------------------------------------------------------
|
|
--Add user functions
|
|
{<POINT Name="user.functions">} {</POINT>}
|