/*! \file gdagreater_pg.c
\brief gdagreater_pg.c is an API file for the PostgreSQL Database in GREAT-ER 2.
The Oracle API interface dagreater.c, which was generated by the TechniData AG,
was the base for the Development of this file. It presents the same functionality.
With gdagreater_pg.c it is possible to connect to a PostgreSQL database more than once per Session.
If you need only one connection at one time you are also able to use dagreater_pg.c directly.
dagreater_pg.c calls gdagreater_pg.c with with the same connection-string. In that case you don't have to
organize the connections.
The global changes that were made during porting the files are the following:
- Functions:
- SYSDATE -> CURRENT_TIMESTAMP
- NVL -> COALESCE
- TO_DATE -> TO_TIMESTAMP
- DECODE -> CASE WHEN .. THEN ..
- sequence.nextval -> NEXTVAL('sequence')
- sequence.curval -> CURVAL('sequence')
- Statements:
- ELSIF -> ELSE IF
- FROM DUAL -> -none-
- in PostgreSQL there is no chance to compare numeric values with 'like'. You have to compare on equality.
The C-Code hasn't been changed.
*/
/**************************************************************************
* DEFINE COMMANDS
**************************************************************************/
/**************************************************************************
* INCLUDE COMMANDS
**************************************************************************/
/* system includes */
#include
#include
#include
#include
#include
#include "libpq-fe.h"
#include "libpq/libpq-fs.h"
#include
#include
#include
/* PostgreSQL includes */
EXEC SQL INCLUDE sqlca;
/* constants for GREAT-ER API */
#include "dagreater_pg.h"
/* data types for GREAT-ER API */
#include "datypes_pg.h"
/* export of GREAT-ER API functions */
#include "gdaexplib_pg.h"
/**************************************************************************
* Global variables
**************************************************************************/
DA_T_db_user_info vg_db_user_info; /* information about currently
* login in database user */
DA_T_acc_right_info vg_acc_rght_info; /* access right info about last
* access master object (subst.,
* env.param., mod.param.,...) */
/**************************************************************************
* LIBRARY INTERAL (LOCAL) FUNCTIONS
**************************************************************************/
/*********************************************************************
* Name : lgda_set_db_errinfo
*
* Issue : 27-JUN-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Fill errinfo struct with information about last occured
* postgres error
*
*
* Parameter: vp_modulename (i) name of module in which error occured
* vp_errinfo (o) STRUCT filled with error information
*
* Return : ----
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
Output:
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation \n H.K. - Intevation
\date 27-JUN-2002
\brief Fill errinfo struct with information about last occured postgres error.
\param vp_modulname name of module in which error occured.
\return ---
*/
void lgda_set_db_errinfo(char *vp_modulename, DA_T_errinfo *vp_errinfo)
{
/* ----------------- *
* start of function
* ----------------- */
#if DEBUG_MODE_ON == 1
/* debug output */
DA_T_MODULE_NAME v_module = "lgda_set_db_errinfo";
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
/* set error type = POSTGRESQL */
vp_errinfo->err_type = DA_ERRTYP_PG;
/* set POSTGRESQL error number */
vp_errinfo->err_no = sqlca.sqlcode;
/* set error parameter by error-line and module in which error occured */
sprintf (vp_errinfo->err_param,"%s - LINE: %d\n%s", vp_modulename, errln,
sqlca.sqlerrm.sqlerrmc);
}
/*********************************************************************
* Name : lgda_chk_access_rights
*
* Issue : 19-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Check access rights (VIEW/EDIT) by passed access
* right information (data owner info). Access rights will
* be computed as followed:
*
* CONDITION RES. ACC. RGHT
* ========= ==============
* 1) is admin VIEW + EDIT
*
* 2) DATA OWNER = VIEW+EDIT
*
* 3) DATA PRIVS = 6 (view+edit for all users) VIEW+EDIT
*
* 4) is member of owner usr grp.
* + DATA PRIVS = 2..3 VIEW
* + DATA PRIVS = 4..6 VIEW+EDIT
*
* 5) is NOT member of owner usr grp.
* + DATA PRIVS = 3+5 VIEW
* + DATA PRIVS = 6 VIEW+EDIT
*
*
* Parameter: vp_data_user_id (i) data owner => USER-ID
* vp_data_usrgrp_id (i) data owner => GROUP-ID of owner
* user grp.
* vp_data_privs (i) data priv. to check (privs 1-6)
*
* Return : DA_A_NONE
* DA_A_VIEW
* DA_A_VIEWEDIT
*
* Globals : errln
* vg_db_user_info (i) -> general information about database
* user of current db-session
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-AUG-2002
\brief Check access rights (VIEW/EDIT) by passed access right information (data owner info).
\param vp_data_user_id data owner => USER-ID.
\param vp_data_usrgrp_id data owner => GROUP-ID of owner user grp.
\param vp_data_privs data priv. to check (privs 1-6)
\return DA_A_NONE \n DA_A_VIEW \n DA_A_VIEWEDIT
*/
int lgda_chk_access_rights(char *vp_data_user_id,
long vp_data_usrgrp_id,
long vp_data_privs)
{
/* ----------------- *
* start of function
* ----------------- */
#if DEBUG_MODE_ON == 1
/* debug output */
DA_T_MODULE_NAME v_module = "lgda_chk_access_rights";
lgda_write_debug_info(4, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
if (vg_db_user_info.admin == 1)
{
/* ------------------------------------------------- *
* 1) GREAT-ER TABLE OWNER =
* ------------------------------------------------- */
/* current db-user is GREAT-ER table owner => Acc right.: VIEW/EDIT */
return(DA_A_VIEWEDIT);
}
if (strcmp(vg_db_user_info.user_id, vp_data_user_id) == 0)
{
/* ------------------------------------------------- *
* 2) DATA OWNER =
* ------------------------------------------------- */
/* current db-user is owner of the data => Acc right.: VIEW/EDIT */
return(DA_A_VIEWEDIT);
}
if ( vp_data_privs == 6 )
{
/* ------------------------------------------------- *
* 3) DATA PRIVS = 6 (view+edit for all users)
* ------------------------------------------------- */
/* all users do have view+edit right for data => Acc right.: VIEW+EDIT */
return(DA_A_VIEWEDIT);
}
if (vg_db_user_info.group_id == vp_data_usrgrp_id)
{
/* ------------------------------------------------- *
* 4) is member of owner user grp.
* ------------------------------------------------- */
/* current user is a member of data OWNER user group */
switch (vp_data_privs) {
case 2 : /* privs. = 2..3 => grp. access right = VIEW */
case 3 :
return(DA_A_VIEW);
break;
case 4 : /* privs. = 4..6 => grp. access right = VIEW+EDIT */
case 5 :
case 6 : return(DA_A_VIEWEDIT);
break;
default: ;
}
}
if (vg_db_user_info.group_id != vp_data_usrgrp_id)
{
/* ------------------------------------------------------- *
* 5) is NOT a member of owner user grp.
* ------------------------------------------------------- */
/* current user is NOT a member of data OWNER user group */
switch (vp_data_privs) {
case 3 : /* privs. = 3+5 => general acc. right = VIEW */
case 5 :
return(DA_A_VIEW);
break;
case 6 : /* privs. = 6 => general acc. right = VIEW+EDIT */
return(DA_A_VIEWEDIT);
break;
default: ;
}
}
/* no condition did match => user has no access right for data */
return (DA_A_NONE);
}
/*********************************************************************
* Name : lgda_get_catch_access_right (CATCH_TAB)
*
* Issue : 19-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for catchment
*
* Parameter: vp_catch_id (i) CATCH_ID of catchment to check
* vp_catch_privs (i) Privs. of catchment
* vp_catch_user_id (i) Owner of catchment
* vp_access_right (o) access right for catchment
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. catchment)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
Output:
\li vp_access_right access right for catchment
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-AUG-2002
\brief Get access right for catchment.
\param vp_catch_id CATCH_ID of catchment to check
\param vp_catch_privs Privs. of catchment
\param vp_catch_user_id Owner of catchment
\return DA_SUCCESS \n DA_FAIL
*/
int lgda_get_catch_access_right(long vp_catch_id,
int vp_catch_privs,
char *vp_catch_user_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_get_catch_access_right";
int v_access_right = DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_user_id[31];
long h_group_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (vg_acc_rght_info.catch_dat.catch_id == vp_catch_id)
{
/* ------------------------------------------------
* 1) global acces right information is up to date
* ------------------------------------------------
* globale access right information do already contain
* access right for catchment
*/
*vp_access_right = vg_acc_rght_info.catch_dat.access_right;
}
else
{
/* ------------------------------------------
* 2) update global acces right information
* ------------------------------------------
* Globale access right information must be updated, because
* different catchment access right info is stored in globale
*/
strcpy (h_user_id, vp_catch_user_id);
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO user_not_found;
errln = 20;
EXEC SQL SELECT coalesce(GROUP_ID, -1)
INTO :h_group_id
FROM USER_TAB
WHERE USER_ID = :h_user_id;
if (NULL)
{
user_not_found:
h_group_id = -1;
}
/*
* set global with new access right info for catchment
*/
vg_acc_rght_info.catch_dat.catch_id = vp_catch_id;
vg_acc_rght_info.catch_dat.privs = vp_catch_privs;
vg_acc_rght_info.catch_dat.group_id = h_group_id;
strcpy (vg_acc_rght_info.catch_dat.user_id, vp_catch_user_id);
/* get access right for current catchment */
v_access_right= lgda_chk_access_rights(vg_acc_rght_info.catch_dat.user_id,
vg_acc_rght_info.catch_dat.group_id,
vg_acc_rght_info.catch_dat.privs);
/* set global with access right info */
vg_acc_rght_info.catch_dat.access_right = v_access_right;
/* return access right for catchment */
*vp_access_right = vg_acc_rght_info.catch_dat.access_right;
}
/* function success fully finished */
return (DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_get_stretch_access_right (STRETCH_TAB)
*
* Issue : 16-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for stretch. User is allowed to access
* the stretch when he has access right for linked catchment.
*
* Parameter: vp_catch_id (i) CATCH_ID of catchment to which
* stretch belongs
* vp_access_right (o) access right for stretch
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. stretch/catchment)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Get access right for stretch.
User is allowed to access the stretch when he has access right for linked catchment.
Output:
\li vp_access_right access right for stretch
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 16-AUG-2002
\param vp_catch_id CATCH_ID of catchment to which stretch belongs.
\return DA_SUCCESS \n DA_FAIL
*/
int lgda_get_stretch_access_right(long vp_catch_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_get_stretch_access_right";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_catch_id_qry;
long h_catch_id;
long h_catch_privs;
char h_catch_user_id[31];
short int h_ind_catch_id;
short int h_ind_catch_privs;
short int h_ind_catch_user_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (vg_acc_rght_info.catch_dat.catch_id == vp_catch_id)
{
/* ------------------------------------------------
* 1) global acces right information is up to date
* ------------------------------------------------
* globale access right information do already contain
* access right for stretch/catchment
*/
v_status = lgda_get_catch_access_right(vp_catch_id, -1, "",
vp_access_right, vp_errinfo);
}
else
{
/* ------------------------------------------
* 2) update global acces right information
* ------------------------------------------
* globale access right information must be updated, because
* different stretch/catchment access right info is stored
* in globale
*/
h_catch_id_qry = vp_catch_id;
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO catch_not_found;
errln = 20;
EXEC SQL SELECT CATCH_ID,
USER_ID,
PRIVS
INTO :h_catch_id INDICATOR :h_ind_catch_id,
:h_catch_user_id INDICATOR :h_ind_catch_user_id,
:h_catch_privs INDICATOR :h_ind_catch_privs
FROM CATCH_TAB
WHERE CATCH_ID = :h_catch_id_qry;
/* check indicator variables (in regard to NULL values) */
if (h_ind_catch_id == -1) h_catch_id = -1;
if (h_ind_catch_privs == -1) h_catch_privs = 1;
if (h_ind_catch_user_id == -1) strcpy(h_catch_user_id, "");
if (NULL)
{
catch_not_found:
h_catch_id = -1;
h_catch_privs = 1;
strcpy(h_catch_user_id, "");
}
/* get access right for stretch/catchment */
v_status = lgda_get_catch_access_right(h_catch_id,
h_catch_privs,
h_catch_user_id,
vp_access_right,
vp_errinfo);
}
/* function finished */
return (v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_get_disch_access_right (DISCH_TAB)
*
* Issue : 19-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for disch. User is allowed to access
* the disch when he has access right for linked catchment.
*
* Parameter: vp_catch_id (i) CATCH_ID of catchment to which
* disch belongs
* vp_access_right (o) access right for disch
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. disch/catchment)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Get access right for disch.
User is allowed to access the disch when he has access right for linked catchment.
Output:
\li vp_access_right access right for disch
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-AUG-2002
\param vp_catch_id CATCH_ID of catchment to which disch belongs.
\return DA_SUCCESS \n DA_FAIL
*/
int lgda_get_disch_access_right(long vp_catch_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_get_disch_access_right";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_catch_id_qry;
long h_catch_id;
long h_catch_privs;
char h_catch_user_id[31];
short int h_ind_catch_id;
short int h_ind_catch_privs;
short int h_ind_catch_user_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (vg_acc_rght_info.catch_dat.catch_id == vp_catch_id)
{
/* ------------------------------------------------
* 1) global access right information is up to date
* ------------------------------------------------
* globale access right information do already contain
* access right for disch/catchment
*/
v_status = lgda_get_catch_access_right(vp_catch_id, -1, "",
vp_access_right, vp_errinfo);
}
else
{
/* ------------------------------------------
* 2) update global acces right information
* ------------------------------------------
* globale access right information must be updated, because
* different disch/catchment access right info is stored
* in globale
*/
h_catch_id_qry = vp_catch_id;
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO catch_not_found;
errln = 20;
EXEC SQL SELECT CATCH_ID,
USER_ID,
PRIVS
INTO :h_catch_id INDICATOR :h_ind_catch_id,
:h_catch_user_id INDICATOR :h_ind_catch_user_id,
:h_catch_privs INDICATOR :h_ind_catch_privs
FROM CATCH_TAB
WHERE CATCH_ID = :h_catch_id_qry;
/* check indicator variables (in regard to NULL values) */
if (h_ind_catch_id == -1) h_catch_id = -1;
if (h_ind_catch_privs == -1) h_catch_privs = -1;
if (h_ind_catch_user_id == -1) strcpy(h_catch_user_id, "");
if (NULL)
{
catch_not_found:
h_catch_id = -1;
h_catch_privs = 1;
strcpy(h_catch_user_id, "");
}
/* get access right for disch/catchment */
v_status = lgda_get_catch_access_right(h_catch_id,
h_catch_privs,
h_catch_user_id,
vp_access_right,
vp_errinfo);
}
/* function finished */
return (v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_get_bin_obj_access_right (BIN_OBJ_TAB)
*
* Issue : 19-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for binary object
*
* Parameter: vp_bin_obj_id (i) BIN_OBJ_ID of binary object to check
* vp_bin_obj_privs (i) Privs. of binary object
* vp_bin_obj_user_id (i) Owner of binary object
* vp_access_right (o) access right for binary object
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. binary object)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
Output:
\li vp_access_right access right for binary object
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-AUG-2002
\brief Get access right for binary object.
\param vp_bin_obj_id BIN_OBJ_ID of binary object to check
\param vp_bin_obj_privs Privs. of binary object
\param vp_bin_obj_user_id Owner of binary object
\return DA_SUCCESS \n DA_FAIL
*/
int lgda_get_bin_obj_access_right(long vp_bin_obj_id,
int vp_bin_obj_privs,
char *vp_bin_obj_user_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_get_bin_obj_access_right";
int v_access_right = DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_user_id[31];
long h_group_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (vg_acc_rght_info.bin_obj_dat.bin_obj_id == vp_bin_obj_id)
{
/* ------------------------------------------------
* 1) global acces right information is up to date
* ------------------------------------------------
* globale access right information do already contain
* access right for binary object
*/
*vp_access_right = vg_acc_rght_info.bin_obj_dat.access_right;
}
else
{
/* ------------------------------------------
* 2) update global acces right information
* ------------------------------------------
* globale access right information must be updated, because
* different binary object access right info is stored in globale
*/
strcpy (h_user_id, vp_bin_obj_user_id);
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO user_not_found;
EXEC SQL SELECT COALESCE(GROUP_ID, -1)
INTO :h_group_id
FROM USER_TAB
WHERE USER_ID = :h_user_id;
if (NULL)
{
user_not_found:
h_group_id = -1;
}
/*
* set global with new binary object access right info
*/
vg_acc_rght_info.bin_obj_dat.bin_obj_id = vp_bin_obj_id;
vg_acc_rght_info.bin_obj_dat.privs = vp_bin_obj_privs;
vg_acc_rght_info.bin_obj_dat.group_id = h_group_id;
strcpy (vg_acc_rght_info.bin_obj_dat.user_id, vp_bin_obj_user_id);
/* get access right for current binary object and current database user */
v_access_right= lgda_chk_access_rights(vg_acc_rght_info.bin_obj_dat.user_id,
vg_acc_rght_info.bin_obj_dat.group_id,
vg_acc_rght_info.bin_obj_dat.privs);
/* set global access right info */
vg_acc_rght_info.bin_obj_dat.access_right = v_access_right;
/* return access right for binary object */
*vp_access_right = vg_acc_rght_info.bin_obj_dat.access_right;
}
/* function success fully finished */
return (DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_get_backgrd_join_access_right (BACKGRD_TAB)
*
* Issue : 19-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for backgrd. join information. User is
* allowed to access background join info, when he has access
* right for the binary object
*
* Parameter: vp_bin_obj_id (i) BIN_OBJ_ID of binary object to which
* backgrd. is joined.
* vp_bin_obj_privs (i) Privs. of binary objects
* vp_bin_obj_user_id(i) Owner of binary object
* vp_access_right (o) Access right for substance detail
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. binary object)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Get access right for backgrd.
join information. User is allowed to access background join info, when he has access right for the binary object.
Output:
\li vp_access_right access right for background join
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-AUG-2002
\param vp_bin_obj_id BIN_OBJ_ID of binary object to check
\param vp_bin_obj_privs Privs. of binary object
\param vp_bin_obj_user_id Owner of binary object
\return DA_SUCCESS \n DA_FAIL
*/
int lgda_get_backgrd_join_access_right(long vp_bin_obj_id,
long vp_bin_obj_privs,
char *vp_bin_obj_user_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
int v_status = DA_SUCCESS;
#if DEBUG_MODE_ON == 1
/* debug output */
DA_T_MODULE_NAME v_module = "lgda_get_backgrd_join_access_right";
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
/*
* Check access right for joined backgrd. object (BIN_OBJ_TAB)
* to get access right for backgrd. join.
*/
v_status = lgda_get_bin_obj_access_right(vp_bin_obj_id,
vp_bin_obj_privs,
vp_bin_obj_user_id,
vp_access_right,
vp_errinfo);
/* function finished */
return (v_status);
}
/*********************************************************************
* Name : lgda_get_subst_access_right (SUBST_TAB)
*
* Issue : 19-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for substance data
*
* Parameter: vp_subst_id (i) SUBST_ID of substance to check
* vp_subst_privs (i) Privs. of substance
* vp_subst_user_id (i) Owner of substance
* vp_access_right (o) Access right for substance
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. substance)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
Output:
\li vp_access_right access right for substance
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-AUG-2002
\brief Get access right for substance data.
\param vp_subst_id SUBST_ID of substance to check
\param vp_subst_privs Privs. of substance
\param vp_subst_user_id Owner of substance
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_get_subst_access_right(long vp_subst_id,
int vp_subst_privs,
char *vp_subst_user_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_get_subst_access_right";
int v_access_right = DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_user_id[31];
long h_group_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (vg_acc_rght_info.subst_dat.subst_id == vp_subst_id)
{
/* ------------------------------------------------
* 1) global Acces Right information is up to date
* ------------------------------------------------
* Globale access right information do already contain
* access right for substance
*/
*vp_access_right = vg_acc_rght_info.subst_dat.access_right;
}
else
{
/* ------------------------------------------
* 2) UPDATE global Acces Right information
* ------------------------------------------
* Globale access right information must be updated, because
* different substance access right info is stored in globale
*/
strcpy (h_user_id, vp_subst_user_id);
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO user_not_found;
EXEC SQL SELECT COALESCE(GROUP_ID, -1)
INTO :h_group_id
FROM USER_TAB
WHERE USER_ID = :h_user_id;
if (NULL)
{
user_not_found:
h_group_id = -1;
}
/*
* set global with new substance data access right info
*/
vg_acc_rght_info.subst_dat.subst_id = vp_subst_id;
vg_acc_rght_info.subst_dat.privs = vp_subst_privs;
vg_acc_rght_info.subst_dat.group_id = h_group_id;
strcpy (vg_acc_rght_info.subst_dat.user_id, vp_subst_user_id);
/* get access right for current substance */
v_access_right= lgda_chk_access_rights(vg_acc_rght_info.subst_dat.user_id,
vg_acc_rght_info.subst_dat.group_id,
vg_acc_rght_info.subst_dat.privs);
/* set global access right info */
vg_acc_rght_info.subst_dat.access_right = v_access_right;
/* return access right for subst. */
*vp_access_right = vg_acc_rght_info.subst_dat.access_right;
}
/* function success fully finished */
return (DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_get_subst_det_access_right (SUBST_DET_TAB)
*
* Issue : 19-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for substance detail. User is allowed to
* access substance detail when he has access right for
* linked substance.
*
* Parameter: vp_subst_id (i) SUBST_ID of subst. detail to check
* vp_access_right (o) Access right for substance detail
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. substance)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
Output:
\li vp_access_right access right for substance detail
\li vp_errinfo Error info in case error occured
\brief Get access right for substance detail.
User is allowed to access substance detail when he has access right for linked substance.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-AUG-2002
\param vp_subst_id SUBST_ID of subst. detail to check
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_get_subst_det_access_right(long vp_subst_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_get_subst_det_access_right";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_subst_id_qry;
long h_subst_id;
long h_subst_privs;
char h_subst_user_id[31];
short int h_ind_subst_id;
short int h_ind_subst_user_id;
short int h_ind_subst_privs;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (vg_acc_rght_info.subst_dat.subst_id == vp_subst_id)
{
/* ------------------------------------------------
* 1) global acces right information is up to date
* ------------------------------------------------
* Globale access right information do already contain
* access right for substance
*/
v_status = lgda_get_subst_access_right(vp_subst_id, -1, "",
vp_access_right, vp_errinfo);
}
else
{
/* ------------------------------------------
* 2) update global acces right information
* ------------------------------------------
* globale access right information must be updated, because
* different substance access right info is stored in globale
*/
h_subst_id_qry = vp_subst_id;
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO subst_not_found;
errln = 20;
EXEC SQL SELECT SUBST_ID,
USER_ID,
PRIVS
INTO :h_subst_id INDICATOR :h_ind_subst_id,
:h_subst_user_id INDICATOR :h_ind_subst_user_id,
:h_subst_privs INDICATOR :h_ind_subst_privs
FROM SUBST_TAB
WHERE SUBST_ID = :h_subst_id_qry;
/* check indicator variables (in regard to NULL values) */
if (h_ind_subst_id == -1) h_subst_id = -1;
if (h_ind_subst_privs == -1) h_subst_privs = -1;
if (h_ind_subst_user_id == -1) strcpy(h_subst_user_id, "");
if (NULL)
{
subst_not_found:
h_subst_id = -1;
h_subst_privs = -1;
strcpy(h_subst_user_id, "");
}
/* get access right for substance */
v_status = lgda_get_subst_access_right(h_subst_id,
h_subst_privs,
h_subst_user_id,
vp_access_right,
vp_errinfo);
}
/* function finished */
return (v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_get_env_access_right (ENV_TAB)
*
* Issue : 19-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for env. param. data
*
* Parameter: vp_env_id (i) ENV_ID of env. param. to check
* vp_env_privs (i) Privs. of env. param.
* vp_env_user_id (i) Owner of env. param.
* vp_access_right (o) Access right for env. param.
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. env. param.)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
Output:
\li vp_access_right access right for env. param
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-AUG-2002
\brief Get access right for env. param. data.
\param vp_env_id ENV_ID of env. param. to check
\param vp_env_privs Privs. of env. param.
\param vp_env_user_id Owner of env. param.
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_get_env_access_right (long vp_env_id,
int vp_env_privs,
char *vp_env_user_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_get_env_access_right";
int v_access_right = DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_user_id[31];
long h_group_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (vg_acc_rght_info.env_dat.env_id == vp_env_id)
{
/* ------------------------------------------------
* 1) global acces right information is up to date
* ------------------------------------------------
* globale access right information do already contain
* access right for env. param.
*/
*vp_access_right = vg_acc_rght_info.env_dat.access_right;
}
else
{
/* ------------------------------------------
* 2) update global acces right information
* ------------------------------------------
* globale access right information must be updated, because
* different env. param. access right info is stored in globale
*/
strcpy (h_user_id, vp_env_user_id);
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO user_not_found;
EXEC SQL SELECT COALESCE(GROUP_ID, -1)
INTO :h_group_id
FROM USER_TAB
WHERE USER_ID = :h_user_id;
if (NULL)
{
user_not_found:
h_group_id = -1;
}
/*
* set global with new env. param. data access right info
*/
vg_acc_rght_info.env_dat.env_id = vp_env_id;
vg_acc_rght_info.env_dat.privs = vp_env_privs;
vg_acc_rght_info.env_dat.group_id = h_group_id;
strcpy (vg_acc_rght_info.env_dat.user_id, vp_env_user_id);
/* get access right for current env. param. */
v_access_right= lgda_chk_access_rights(vg_acc_rght_info.env_dat.user_id,
vg_acc_rght_info.env_dat.group_id,
vg_acc_rght_info.env_dat.privs);
/* set global access right info */
vg_acc_rght_info.env_dat.access_right = v_access_right;
/* return access right for env. param. */
*vp_access_right = vg_acc_rght_info.env_dat.access_right;
}
/* function success fully finished */
return (DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_get_env_det_access_right (ENV_DET_TAB)
*
* Issue : 19-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for env. param. detail. User is allowed
* to access env. param. detail when he has access right for
* linked env. param. .
*
* Parameter: vp_env_id (i) ENV_ID of env. detail to check
* vp_access_right (o) Access right for env. param. detail
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. env. param.)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Get access right for env. param. detail.
User is allowed to access env. param. detail when he has access right for linked env. param. .
Output:
\li vp_access_right access right for env. param. detail
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-AUG-2002
\param vp_env_id ENV_ID of env. detail to check
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_get_env_det_access_right (long vp_env_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_get_env_det_access_right";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_env_id_qry;
long h_env_id;
long h_env_privs;
char h_env_user_id[31];
short int h_ind_env_id;
short int h_ind_env_user_id;
short int h_ind_env_privs;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (vg_acc_rght_info.env_dat.env_id == vp_env_id)
{
/* ------------------------------------------------
* 1) global acces right information is up to date
* ------------------------------------------------
* globale access right information do already contain
* access right for envance
*/
v_status = lgda_get_env_access_right(vp_env_id, -1, "",
vp_access_right, vp_errinfo);
}
else
{
/* ------------------------------------------
* 2) update global acces right information
* ------------------------------------------
* globale access right information must be updated, because
* different env. param. access right info is stored in globale
*/
h_env_id_qry = vp_env_id;
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO env_not_found;
errln = 20;
EXEC SQL SELECT ENV_ID,
USER_ID,
PRIVS
INTO :h_env_id INDICATOR :h_ind_env_id,
:h_env_user_id INDICATOR :h_ind_env_user_id,
:h_env_privs INDICATOR :h_ind_env_privs
FROM ENV_TAB
WHERE ENV_ID = :h_env_id_qry;
/* check indicator variables (in regard to NULL values) */
if (h_ind_env_id == -1) h_env_id = -1;
if (h_ind_env_privs == -1) h_env_privs = 1;
if (h_ind_env_user_id == -1) strcpy(h_env_user_id, "");
if (NULL)
{
env_not_found:
h_env_id = -1;
h_env_privs = 1;
strcpy(h_env_user_id, "");
}
/* get access right for env. param. */
v_status = lgda_get_env_access_right(h_env_id, h_env_privs,
h_env_user_id, vp_access_right,
vp_errinfo);
}
/* function finished */
return (v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_get_mod_access_right (MOD_TAB)
*
* Issue : 19-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for mod. param. data
*
* Parameter: vp_mod_id (i) MOD_ID of mod. param. to check
* vp_mod_privs (i) Privs. of mod. param.
* vp_mod_user_id (i) Owner of mod.
* vp_access_right (o) Access right for mod. param.
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. mod. param.)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
Output:
\li vp_access_right access right for mod. param.
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-AUG-2002
\brief Get access right for mod. param. data.
\param vp_mod_id MOD_ID of mod. param. to check
\param vp_mod_privs Privs. of mod. param.
\param vp_mod_user_id (i) Owner of mod.
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_get_mod_access_right (long vp_mod_id,
int vp_mod_privs,
char *vp_mod_user_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_get_mod_access_right";
int v_access_right = DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_user_id[31];
long h_group_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (vg_acc_rght_info.mod_dat.mod_id == vp_mod_id)
{
/* ------------------------------------------------
* 1) global acces right information is up to date
* ------------------------------------------------
* globale access right information do already contain
* access right for mod. param.
*/
*vp_access_right = vg_acc_rght_info.mod_dat.access_right;
}
else
{
/* ------------------------------------------
* 2) update global acces right information
* ------------------------------------------
* globale access right information must be updated, because
* different mod. param. access right info is stored in globale
*/
strcpy (h_user_id, vp_mod_user_id);
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO user_not_found;
EXEC SQL SELECT COALESCE(GROUP_ID, -1)
INTO :h_group_id
FROM USER_TAB
WHERE USER_ID = :h_user_id;
if (NULL)
{
user_not_found:
h_group_id = -1;
}
/*
* set global with new mod. param. data access right info
*/
vg_acc_rght_info.mod_dat.mod_id = vp_mod_id;
vg_acc_rght_info.mod_dat.privs = vp_mod_privs;
vg_acc_rght_info.mod_dat.group_id = h_group_id;
strcpy (vg_acc_rght_info.mod_dat.user_id, vp_mod_user_id);
/* get access right for current mod. param. */
v_access_right= lgda_chk_access_rights(vg_acc_rght_info.mod_dat.user_id,
vg_acc_rght_info.mod_dat.group_id,
vg_acc_rght_info.mod_dat.privs);
/* set global access right info */
vg_acc_rght_info.mod_dat.access_right = v_access_right;
/* return access right for mod. param. */
*vp_access_right = vg_acc_rght_info.mod_dat.access_right;
}
/* function success fully finished */
return (DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_get_mod_det_access_right (MOD_DET_TAB)
*
* Issue : 19-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for mod. param. detail. User is allowed
* to access mod. param. detail when he has access right for
* linked mod. param. .
*
* Parameter: vp_mod_id (i) MOD_ID of mod. detail to check
* vp_access_right (o) Access right for mod. param. detail
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. mod. param.)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Get access right for mod. param. detail.
User is allowed to access mod. param. detail when he has access right for linked mod. param. .
Output:
\li vp_access_right access right for mod. param. detail
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-AUG-2002
\param vp_mod_id MOD_ID of mod. detail to check
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_get_mod_det_access_right (long vp_mod_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_get_mod_det_access_right";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_mod_id_qry;
long h_mod_id;
long h_mod_privs;
char h_mod_user_id[31];
short int h_ind_mod_id;
short int h_ind_mod_user_id;
short int h_ind_mod_privs;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (vg_acc_rght_info.mod_dat.mod_id == vp_mod_id)
{
/* ------------------------------------------------
* 1) global acces right information is up to date
* ------------------------------------------------
* globale access right information do already contain
* access right for modance
*/
v_status = lgda_get_mod_access_right(vp_mod_id, -1, "",
vp_access_right, vp_errinfo);
}
else
{
/* ------------------------------------------
* 2) update global acces right information
* ------------------------------------------
* globale access right information must be updated, because
* different mod. param. access right info is stored in globale
*/
h_mod_id_qry = vp_mod_id;
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO mod_not_found;
errln = 20;
EXEC SQL SELECT mod_ID,
USER_ID,
PRIVS
INTO :h_mod_id INDICATOR :h_ind_mod_id,
:h_mod_user_id INDICATOR :h_ind_mod_user_id,
:h_mod_privs INDICATOR :h_ind_mod_privs
FROM mod_TAB
WHERE mod_ID = :h_mod_id_qry;
/* check indicator variables (in regard to NULL values) */
if (h_ind_mod_id == -1) h_mod_id = -1;
if (h_ind_mod_privs == -1) h_mod_privs = 1;
if (h_ind_mod_user_id == -1) strcpy(h_mod_user_id, "");
if (NULL)
{
mod_not_found:
h_mod_id = -1;
h_mod_privs = 1;
strcpy(h_mod_user_id, "");
}
/* get access right for mod. param. */
v_status = lgda_get_mod_access_right(h_mod_id, h_mod_privs,
h_mod_user_id, vp_access_right,
vp_errinfo);
}
/* function finished */
return (v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_get_sess_access_right (SESS_TAB)
*
* Issue : 19-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for session
*
* Parameter: vp_sess_id (i) SESS_ID of session
* vp_sess_privs (i) Privs. of session
* vp_sess_user_id (i) Owner of session
* vp_access_right (o) Access right for session
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. session)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
Output:
\li vp_access_right access right for session
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-AUG-2002
\brief Get access right for session.
\param vp_sess_id SESS_ID of session
\param vp_sess_privs Privs. of session
\param vp_sess_user_id Owner of session
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_get_sess_access_right (long vp_sess_id,
int vp_sess_privs,
char *vp_sess_user_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_get_sess_access_right";
int v_access_right = DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_user_id[31];
long h_group_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (vg_acc_rght_info.sess_dat.sess_id == vp_sess_id)
{
/* ------------------------------------------------
* 1) global acces right information is up to date
* ------------------------------------------------
* globale access right information do already contain
* access right for sess. param.
*/
*vp_access_right = vg_acc_rght_info.sess_dat.access_right;
}
else
{
/* ------------------------------------------
* 2) update global acces right information
* ------------------------------------------
* globale access right information must be updated, because
* different sess. param. access right info is stored in globale
*/
strcpy (h_user_id, vp_sess_user_id);
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO user_not_found;
EXEC SQL SELECT COALESCE(GROUP_ID, -1)
INTO :h_group_id
FROM USER_TAB
WHERE USER_ID = :h_user_id;
if (NULL)
{
user_not_found:
h_group_id = -1;
}
/*
* set global with new sess. param. data access right info
*/
vg_acc_rght_info.sess_dat.sess_id = vp_sess_id;
vg_acc_rght_info.sess_dat.privs = vp_sess_privs;
vg_acc_rght_info.sess_dat.group_id = h_group_id;
strcpy (vg_acc_rght_info.sess_dat.user_id, vp_sess_user_id);
/* get access right for current sess. param. */
v_access_right= lgda_chk_access_rights(vg_acc_rght_info.sess_dat.user_id,
vg_acc_rght_info.sess_dat.group_id,
vg_acc_rght_info.sess_dat.privs);
/* set global access right info */
vg_acc_rght_info.sess_dat.access_right = v_access_right;
/* return access right for sess. param. */
*vp_access_right = vg_acc_rght_info.sess_dat.access_right;
}
/* function success fully finished */
return (DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_get_market_access_right (MARKET_TAB)
*
* Issue : 20-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for market data
*
* Parameter: vp_market_id (i) MARKET_ID of market data
* vp_market_privs (i) Privs. of market data
* vp_market_user_id (i) Owner of market data
* vp_access_right (o) Access right for marketion
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. marketion)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
Output:
\li vp_access_right access right for marketion
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 20-AUG-2002
\brief Get access right for market data.
\param vp_market_id MARKET_ID of market data
\param vp_market_privs Privs. of market data
\param vp_market_user_id Owner of market data
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_get_market_access_right (long vp_market_id,
int vp_market_privs,
char *vp_market_user_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_get_market_access_right";
int v_access_right = DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_user_id[31];
long h_group_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (vg_acc_rght_info.market_dat.market_id == vp_market_id)
{
/* ------------------------------------------------
* 1) global acces right information is up to date
* ------------------------------------------------
* globale access right information do already contain
* access right for market data
*/
*vp_access_right = vg_acc_rght_info.market_dat.access_right;
}
else
{
/* ------------------------------------------
* 2) update global acces right information
* ------------------------------------------
* globale access right information must be updated, because
* different market data access right info is stored in globale
*/
strcpy (h_user_id, vp_market_user_id);
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO user_not_found;
EXEC SQL SELECT COALESCE(GROUP_ID, -1)
INTO :h_group_id
FROM USER_TAB
WHERE USER_ID = :h_user_id;
if (NULL)
{
user_not_found:
h_group_id = -1;
}
/*
* set global with new market. param. data access right info
*/
vg_acc_rght_info.market_dat.market_id = vp_market_id;
vg_acc_rght_info.market_dat.privs = vp_market_privs;
vg_acc_rght_info.market_dat.group_id = h_group_id;
strcpy (vg_acc_rght_info.market_dat.user_id, vp_market_user_id);
/* get access right for current market. param. */
v_access_right= lgda_chk_access_rights(vg_acc_rght_info.market_dat.user_id,
vg_acc_rght_info.market_dat.group_id,
vg_acc_rght_info.market_dat.privs);
/* set global access right info */
vg_acc_rght_info.market_dat.access_right = v_access_right;
/* return access right for market. param. */
*vp_access_right = vg_acc_rght_info.market_dat.access_right;
}
/* function success fully finished */
return (DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_get_res_access_right (RES_TAB,
* RES_STRETCH_TAB,
* RES_DISCH_TAB)
*
* Issue : 19-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for result data. User has access right
* for result data, when he has access rights for linked
* session
*
* Parameter: vp_res_id (i) RES_ID of result data to check
* vp_access_right (o) Access right for session
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. results)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Get access right for result data.
User has access right for result data, when he has access rights for linked session.
Output:
\li vp_access_right access right for result data
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-AUG-2002
\param vp_res_id RES_ID of result data to check
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_get_res_access_right (long vp_res_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_get_res_access_right";
int v_access_right = DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_group_id;
long h_res_id_qry;
long h_sess_id;
long h_sess_privs;
char h_sess_user_id[31];
short int h_ind_sess_id;
short int h_ind_sess_privs;
short int h_ind_sess_user_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (vg_acc_rght_info.res_dat.res_id == vp_res_id)
{
/* ------------------------------------------------
* 1) global acces right information is up to date
* ------------------------------------------------
* globale access right information do already contain
* access right for result
*/
*vp_access_right = vg_acc_rght_info.res_dat.access_right;
}
else
{
/* ------------------------------------------
* 2) update global acces right information
* ------------------------------------------
* globale access right information must be updated, because
* different result access right info is stored in globale
*/
h_res_id_qry = vp_res_id;
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO session_not_found;
errln = 20;
EXEC SQL SELECT SESS_ID,
USER_ID,
PRIVS
INTO :h_sess_id INDICATOR :h_ind_sess_id,
:h_sess_user_id INDICATOR :h_ind_sess_user_id,
:h_sess_privs INDICATOR :h_ind_sess_privs
FROM SESS_TAB
WHERE RES_ID = :h_res_id_qry;
if (h_ind_sess_id == -1) h_sess_id = -1;
if (h_ind_sess_privs == -1) h_sess_privs = 1;
if (h_ind_sess_user_id == -1) strcpy(h_sess_user_id, "");
if (NULL)
{
session_not_found:
h_sess_id = -1;
h_sess_privs = 1;
strcpy(h_sess_user_id, "");
}
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO user_not_found;
errln = 40;
EXEC SQL SELECT COALESCE(GROUP_ID, -1)
INTO :h_group_id
FROM USER_TAB
WHERE USER_ID = :h_sess_user_id;
if (NULL)
{
user_not_found:
h_group_id = -1;
}
/*
* set global with new result/session data access right info
*/
vg_acc_rght_info.res_dat.res_id = vp_res_id;
vg_acc_rght_info.res_dat.sess_id = h_sess_id;
vg_acc_rght_info.res_dat.sess_privs = h_sess_privs;
vg_acc_rght_info.res_dat.sess_group_id = h_group_id;
strcpy (vg_acc_rght_info.res_dat.sess_user_id, h_sess_user_id);
/* get access right for current result/session */
v_access_right= lgda_chk_access_rights(vg_acc_rght_info.res_dat.sess_user_id,
vg_acc_rght_info.res_dat.sess_group_id,
vg_acc_rght_info.res_dat.sess_privs);
/* set global access right info */
vg_acc_rght_info.res_dat.access_right = v_access_right;
/* return access right for result. */
*vp_access_right = vg_acc_rght_info.res_dat.access_right;
}
/* function success fully finished */
return (DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_get_sess_disch_access_right (SESS_DISCH_TAB)
*
* Issue : 04-SEP-2002 - S.F. - TechniData AG/Markdorf
*
* Purpose : Get access right for session discharge data
*
* Parameter: vp_sess_disch_id (i) SESS_DISCH_ID of s. discharge data
* vp_sess_disch_privs (i) Privs. of session discharge data
* vp_sess_disch_user_id (i) Owner of sesion discharge data
* vp_access_right (o) Access right for session discharge
* vp_errinfo (o) Error info in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
* vg_acc_rght_info (o) access right info about last selected
* data objects (i.e. session discharge)
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
Output:
\li vp_access_right access right for session discharge
\li vp_errinfo Error info in case error occured
\author S.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 04-SEP-2002
\brief Get access right for session discharge data.
\param vp_sess_disch_id SESS_DISCH_ID of s. discharge data
\param vp_sess_disch_privs Privs. of session discharge data
\param vp_sess_disch_user_id Owner of sesion discharge data
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_get_sess_disch_access_right (long vp_sess_disch_id,
int vp_sess_disch_privs,
char *vp_sess_disch_user_id,
int *vp_access_right,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_get_sess_disch_access_right";
int v_access_right = DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_user_id[31];
long h_group_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(3, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (vg_acc_rght_info.sess_disch_dat.sess_disch_id == vp_sess_disch_id)
{
/* ------------------------------------------------
* 1) global acces right information is up to date
* ------------------------------------------------
* globale access right information do already contain
* access right for session discharge data
*/
*vp_access_right = vg_acc_rght_info.sess_disch_dat.access_right;
}
else
{
/* ------------------------------------------
* 2) update global acces right information
* ------------------------------------------
* globale access right information must be updated, because
* different session discharge data access right info is stored in globale
*/
strcpy (h_user_id, vp_sess_disch_user_id);
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO user_not_found;
EXEC SQL SELECT COALESCE(GROUP_ID, -1)
INTO :h_group_id
FROM USER_TAB
WHERE USER_ID = :h_user_id;
if (NULL)
{
user_not_found:
h_group_id = -1;
}
/*
* set global with new session discharge. param. data access right info
*/
vg_acc_rght_info.sess_disch_dat.sess_disch_id = vp_sess_disch_id;
vg_acc_rght_info.sess_disch_dat.privs = vp_sess_disch_privs;
vg_acc_rght_info.sess_disch_dat.group_id = h_group_id;
strcpy (vg_acc_rght_info.sess_disch_dat.user_id, vp_sess_disch_user_id);
/* get access right for current session discharge. param. */
v_access_right= lgda_chk_access_rights(vg_acc_rght_info.sess_disch_dat.user_id,
vg_acc_rght_info.sess_disch_dat.group_id,
vg_acc_rght_info.sess_disch_dat.privs);
/* set global access right info */
vg_acc_rght_info.sess_disch_dat.access_right = v_access_right;
/* return access right for session discharge. param. */
*vp_access_right = vg_acc_rght_info.sess_disch_dat.access_right;
}
/* function success fully finished */
return (DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/* BLOB func's */
/*********************************************************************
* Name : lgda_chk_subst_det_master (SUBST_DET_TAB)
*
* Issue : 07-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Perform checks on substance detail data:
*
* a) check by FIELD_ID, BLOCK_ID if master record in table
* PARA_TREE_DEF_TAB exists. In case not -> return error!
*
* b) check by SUBST_ID if master record in table SUBST_TAB
* exists. In case not -> return error!
*
* Parameter: vp_subst_id (i) subst_id of master record in SUBST_TAB
* vp_field_id (i) field_id of master record in PARA_TREE...
* vp_block_id (i) block_id of master record in PARA_TREE...
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Perform checks on substance detail data:
\li check by FIELD_ID, BLOCK_ID if master record in table \n PARA_TREE_DEF_TAB exists. In case not -> return error!\li check by SUBST_ID if master record in table SUBST_TAB \n exists. In case not -> return error!
Output:
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 07-AUG-2002
\param vp_sess_disch_id SESS_DISCH_ID of s. discharge data
\param vp_sess_disch_privs Privs. of session discharge data
\param vp_sess_disch_user_id Owner of sesion discharge data
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_chk_subst_det_master (long vp_subst_id,
char *vp_field_id,
char *vp_block_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_chk_subst_det_master";
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_subst_id;
long h_subst_id_qry;
char h_field_id [31];
char h_field_id_qry[31];
char h_block_id_qry[31];
/* indicator variables */
short int h_ind_subst_id;
short int h_ind_field_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* ---------------------------------------------------------- *
* CHECK (1) -> chk. if master in SUBST_TAB exist
* ---------------------------------------------------------- */
h_subst_id_qry = vp_subst_id;
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO subst_master_not_found;
errln = 20;
EXEC SQL SELECT SUBST_ID
INTO :h_subst_id INDICATOR :h_ind_subst_id
FROM SUBST_TAB
WHERE SUBST_ID = :h_subst_id_qry
LIMIT 1;
if (NULL)
{
subst_master_not_found:
/* <<< ERROR : invalid/missing reference to master >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_MASTER;
strcpy(vp_errinfo->err_param,"(SUBST_TAB)");
return(DA_FAIL);
}
/* ---------------------------------------------------------- *
* PRE-CHECK (2) -> chk. if master in PARA_TREE_DEF_TAB is avail.
* ---------------------------------------------------------- */
strcpy(h_field_id_qry, vp_field_id);
strcpy(h_block_id_qry, vp_block_id);
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO para_tree_master_not_found;
errln = 40;
EXEC SQL SELECT FIELD_ID
INTO :h_field_id INDICATOR :h_ind_field_id
FROM PARA_TREE_DEF_TAB
WHERE FIELD_ID = :h_field_id_qry
AND BLOCK_ID = :h_block_id_qry
LIMIT 1;
if (NULL)
{
para_tree_master_not_found:
/* <<< ERROR : invalid/missing reference to master >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_MASTER;
strcpy(vp_errinfo->err_param,"(PARA_TREE_DEF_TAB)");
return(DA_FAIL);
}
/* all required master record do exist */
return(DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_chk_env_det_master (ENV_DET_TAB)
*
* Issue : 07-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Perform checks on environment detail data:
*
* a) check by FIELD_ID, BLOCK_ID if master record in table
* PARA_TREE_DEF_TAB exists. In case not -> return error!
*
* b) check by ENV_ID if master record in table ENV_TAB
* exists. In case not -> return error!
*
* Parameter: vp_env_id (i) env_id of master record in ENV_TAB
* vp_field_id (i) field_id of master record in PARA_TREE...
* vp_block_id (i) block_id of master record in PARA_TREE...
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Perform checks on environment detail data:
\li check by FIELD_ID, BLOCK_ID if master record in table \n PARA_TREE_DEF_TAB exists. In case not -> return error!\li check by ENV_ID if master record in table ENV_TAB \n exists. In case not -> return error!
Output:
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 07-AUG-2002
\param vp_env_id env_id of master record in ENV_TAB
\param vp_field_id field_id of master record in PARA_TREE...
\param vp_block_id block_id of master record in PARA_TREE...
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_chk_env_det_master (long vp_env_id,
char *vp_field_id,
char *vp_block_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_chk_env_det_master";
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_env_id;
long h_env_id_qry;
char h_field_id [31];
char h_field_id_qry[31];
char h_block_id_qry[31];
/* indicator variables */
short int h_ind_env_id;
short int h_ind_field_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* ---------------------------------------------------------- *
* CHECK (1) -> chk. if master in ENV_TAB exist
* ---------------------------------------------------------- */
h_env_id_qry = vp_env_id;
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO env_master_not_found;
errln = 20;
EXEC SQL SELECT ENV_ID
INTO :h_env_id INDICATOR :h_ind_env_id
FROM env_TAB
WHERE env_ID = :h_env_id_qry
LIMIT 1;
if (NULL)
{
env_master_not_found:
/* <<< ERROR : invalid/missing reference to master >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_MASTER;
strcpy(vp_errinfo->err_param,"(env_TAB)");
return(DA_FAIL);
}
/* ---------------------------------------------------------- *
* PRE-CHECK (2) -> chk. if master in PARA_TREE_DEF_TAB is avail.
* ---------------------------------------------------------- */
strcpy(h_field_id_qry, vp_field_id);
strcpy(h_block_id_qry, vp_block_id);
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO para_tree_master_not_found;
errln = 40;
EXEC SQL SELECT FIELD_ID
INTO :h_field_id INDICATOR :h_ind_field_id
FROM PARA_TREE_DEF_TAB
WHERE FIELD_ID = :h_field_id_qry
AND BLOCK_ID = :h_block_id_qry
LIMIT 1;
if (NULL)
{
para_tree_master_not_found:
/* <<< ERROR : invalid/missing reference to master >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_MASTER;
strcpy(vp_errinfo->err_param,"(PARA_TREE_DEF_TAB)");
return(DA_FAIL);
}
/* all required master record do exist */
return(DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_chk_mod_det_master (MOD_DET_TAB)
*
* Issue : 07-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Perform checks on model mode detail data:
*
* a) check by FIELD_ID, BLOCK_ID if master record in table
* PARA_TREE_DEF_TAB exists. In case not -> return error!
*
* b) check by MOD_ID if master record in table MOD_TAB
* exists. In case not -> return error!
*
* Parameter: vp_mod_id (i) mod_id of master record in MOD_TAB
* vp_field_id (i) field_id of master record in PARA_TREE...
* vp_block_id (i) block_id of master record in PARA_TREE...
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Perform checks on model mode detail data:
\li check by FIELD_ID, BLOCK_ID if master record in table \n PARA_TREE_DEF_TAB exists. In case not -> return error!\li check by MOD_ID if master record in table MOD_TAB \n exists. In case not -> return error!
Output:
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 07-AUG-2002
\param vp_mod_id mod_id of master record in MOD_TAB
\param vp_field_id field_id of master record in PARA_TREE...
\param vp_block_id block_id of master record in PARA_TREE...
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_chk_mod_det_master (long vp_mod_id, char *vp_field_id,
char *vp_block_id, DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_chk_mod_det_master";
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_mod_id;
long h_mod_id_qry;
char h_field_id [31];
char h_field_id_qry[31];
char h_block_id_qry[31];
/* indicator variables */
short int h_ind_mod_id;
short int h_ind_field_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* ---------------------------------------------------------- *
* CHECK (1) -> chk. if master in MOD_TAB exist
* ---------------------------------------------------------- */
h_mod_id_qry = vp_mod_id;
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO mod_master_not_found;
errln = 20;
EXEC SQL SELECT MOD_ID
INTO :h_mod_id INDICATOR :h_ind_mod_id
FROM MOD_TAB
WHERE MOD_ID = :h_mod_id_qry
LIMIT 1;
if (NULL)
{
mod_master_not_found:
/* <<< ERROR : invalid/missing reference to master >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_MASTER;
strcpy(vp_errinfo->err_param,"(MOD_TAB)");
return(DA_FAIL);
}
/* ---------------------------------------------------------- *
* PRE-CHECK (2) -> chk. if master in PARA_TREE_DEF_TAB is avail.
* ---------------------------------------------------------- */
strcpy(h_field_id_qry, vp_field_id);
strcpy(h_block_id_qry, vp_block_id);
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO para_tree_master_not_found;
errln = 40;
EXEC SQL SELECT FIELD_ID
INTO :h_field_id INDICATOR :h_ind_field_id
FROM PARA_TREE_DEF_TAB
WHERE FIELD_ID = :h_field_id_qry
AND BLOCK_ID = :h_block_id_qry
LIMIT 1;
if (NULL)
{
para_tree_master_not_found:
/* <<< ERROR : invalid/missing reference to master >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_MASTER;
strcpy(vp_errinfo->err_param,"(PARA_TREE_DEF_TAB)");
return(DA_FAIL);
}
/* all required master records do exist */
return(DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_chk_res_stretch_master (RES_STRETCH_TAB)
*
* Issue : 07-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Perform checks on result stretch data:
*
* - check by FIELD_ID, BLOCK_ID if master record in table
* PARA_TREE_DEF_TAB exists. In case not -> return error!
*
* Parameter: vp_field_id (i) field_id of master record in PARA_TREE...
* vp_block_id (i) block_id of master record in PARA_TREE...
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Perform checks on stretch data:
\li check by FIELD_ID, BLOCK_ID if master record in table \n PARA_TREE_DEF_TAB exists. In case not -> return error!
Output:
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 07-AUG-2002
\param vp_field_id field_id of master record in PARA_TREE...
\param vp_block_id block_id of master record in PARA_TREE...
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_chk_res_stretch_master (char *vp_field_id,
char *vp_block_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_chk_res_stretch_master";
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_field_id [31];
char h_field_id_qry[31];
char h_block_id_qry[31];
/* indicator variables */
short int h_ind_field_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* ---------------------------------------------------------- *
* PRE-CHECK -> chk. if master in PARA_TREE_DEF_TAB is avail.
* ---------------------------------------------------------- */
strcpy(h_field_id_qry, vp_field_id);
strcpy(h_block_id_qry, vp_block_id);
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO para_tree_master_not_found;
errln = 20;
EXEC SQL SELECT FIELD_ID
INTO :h_field_id INDICATOR :h_ind_field_id
FROM PARA_TREE_DEF_TAB
WHERE FIELD_ID = :h_field_id_qry
AND BLOCK_ID = :h_block_id_qry
LIMIT 1;
if (NULL)
{
para_tree_master_not_found:
/* <<< ERROR : invalid/missing reference to master >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_MASTER;
strcpy(vp_errinfo->err_param,"(PARA_TREE_DEF_TAB)");
return(DA_FAIL);
}
/* all required master records do exist */
return(DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_chk_res_disch_master (RES_DISCH_TAB)
*
* Issue : 07-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Perform checks on result stretch data:
*
* - check by FIELD_ID, BLOCK_ID if master record in table
* PARA_TREE_DEF_TAB exists. In case not -> return error!
*
* Parameter: vp_field_id (i) field_id of master record in PARA_TREE...
* vp_block_id (i) block_id of master record in PARA_TREE...
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Perform checks on stretch data:
\li check by FIELD_ID, BLOCK_ID if master record in table \n PARA_TREE_DEF_TAB exists. In case not -> return error!
Output:
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 07-AUG-2002
\param vp_field_id field_id of master record in PARA_TREE...
\param vp_block_id block_id of master record in PARA_TREE...
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_chk_res_disch_master (char *vp_field_id,
char *vp_block_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_chk_res_disch_master";
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_field_id [31];
char h_field_id_qry[31];
char h_block_id_qry[31];
/* indicator variables */
short int h_ind_field_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* ---------------------------------------------------------- *
* PRE-CHECK -> chk. if master in PARA_TREE_DEF_TAB is avail.
* ---------------------------------------------------------- */
strcpy(h_field_id_qry, vp_field_id);
strcpy(h_block_id_qry, vp_block_id);
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO para_tree_master_not_found;
errln = 20;
EXEC SQL SELECT FIELD_ID
INTO :h_field_id INDICATOR :h_ind_field_id
FROM PARA_TREE_DEF_TAB
WHERE FIELD_ID = :h_field_id_qry
AND BLOCK_ID = :h_block_id_qry
LIMIT 1;
if (NULL)
{
para_tree_master_not_found:
/* <<< ERROR : invalid/missing reference to master >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_MASTER;
strcpy(vp_errinfo->err_param,"(PARA_TREE_DEF_TAB)");
return(DA_FAIL);
}
/* all required master records do exist */
return(DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_chk_market_id (MARKET_TAB/SESS_TAB)
*
* Issue : 14-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Referenzial key constraint (MARKET_ID) not possible in
* SESS_TAB. Therefore check if specified MARKET_ID does
* already exist in MARKET_TAB by this function.
*
* Parameter: vp_market_id (i) MARKET_ID of record to check
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Referenzial key constraint (MARKET_ID) not possible in SESS_TAB.
Therefore check if specified MARKET_ID does already exist in MARKET_TAB by this function.
Output:
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 14-AUG-2002
\param vp_market_id MARKET_ID of record to check
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_chk_market_id (long vp_market_id, DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_chk_market_id";
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_market_id_qry;
long h_cnt;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* ---------------------------------------------------------- *
* PRE-CHECK -> chk. if market_id already exists in MARKET_TAB
* ---------------------------------------------------------- */
if (vp_market_id == -1)
{
/* SUCCESS: market_id == NULL => valid ID for SESS_TAB */
return(DA_SUCCESS);
}
h_market_id_qry = vp_market_id;
errln = 10;
EXEC SQL SELECT count(*)
INTO :h_cnt
FROM MARKET_TAB
WHERE MARKET_ID = :h_market_id_qry;
if (h_cnt > 0)
{
/* SUCCESS: market_id does exist in MARKET_TAB */
return(DA_SUCCESS);
}
else
{
/* ERROR : invalid market_id*/
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_REFERENCE;
strcpy(vp_errinfo->err_param,"(SESS_TAB - MARKET_ID)");
return(DA_FAIL);
}
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_chk_sess_disch_id (SESS_DISCH_TAB/SESS_TAB)
*
* Issue : 04-SEP-2002 - S.F. - TechniData AG/Markdorf
*
* Purpose : Referencial key constraint (SESS_DISCH_ID) not possible in
* SESS_TAB. Therefore check if specified SESS_DISCH_ID does
* already exist in SESS_DISCH_TAB by this function.
*
* Parameter: vp_sess_disch_id (i) SESS_DISCH_ID of record to check
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Referenzial key constraint (SESS_DISCH_ID) not possible in SESS_TAB.
Therefore check if specified SESS_DISCH_ID does already exist in SESS_DISCH_TAB by this function.
Output:
\li vp_errinfo Error info in case error occured
\author S.F. - TechniData AG/Markdorf \n H.K. - Intevation
\date 04-SEP-2002
\param vp_sess_disch_id SESS_DISCH_ID of record to check
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_chk_sess_disch_id (long vp_sess_disch_id, DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_chk_sess_disch_id";
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_sess_disch_id_qry;
long h_cnt;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* ------------------------------------------------------------------- *
* PRE-CHECK -> chk. if sess_disch_id already exists in SESS_DISCH_TAB
* ------------------------------------------------------------------- */
if (vp_sess_disch_id == -1)
{
/* SUCCESS: sess_disch_id == NULL => valid ID for SESS_TAB */
return(DA_SUCCESS);
}
h_sess_disch_id_qry = vp_sess_disch_id;
errln = 10;
EXEC SQL SELECT count(*)
INTO :h_cnt
FROM SESS_DISCH_TAB
WHERE SESS_DISCH_ID = :h_sess_disch_id_qry;
if (h_cnt > 0)
{
/* SUCCESS: sess_disch_id does exist in SESS_DISCH_TAB */
return(DA_SUCCESS);
}
else
{
/* ERROR : invalid sess_disch_id */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_REFERENCE;
strcpy(vp_errinfo->err_param,"(SESS_TAB - SESS_DISCH_ID)");
return(DA_FAIL);
}
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_chk_stretch_master (STRETCH_TAB)
*
* Issue : 20-MAY-2003 - S.F. - TechniData AG/Markdorf
*
* Purpose : Perform checks on stretch data:
*
* a) check by CATCH_ID if master record in table
* CATCH_TAB exists. In case not -> return error!
*
* b) check by STRETCH_CLASS_ID if referenced record in table
* STRETCH_CLASS_TAB exists. In case not -> return error!
*
* Parameter: vp_catch_id (i) catch_id of master record in CATCH_TAB
* vp_stretch_class_id (i) stretch_class_id of referenced record in
* STRETCH_CLASS_TAB
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Perform checks on stretch data:
\li check by CATCH_ID if master record in table \n CATCH_TAB exists. In case not -> return error! \li check by STRETCH_CLASS_ID if referenced record in table \n STRETCH_CLASS_TAB exists. In case not -> return error!
Output:
\li vp_errinfo Error info in case error occured
\author S.F. - TechniData AG/Markdorf \n H.K. - Intevation
\date 20-MAI-2003
\param vp_catch_id catch_id of master record in CATCH_TAB
\param vp_stretch_class_id stretch_class_id of referenced record in STRETCH_CLASS_TAB
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_chk_stretch_master (long vp_catch_id, long vp_stretch_class_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_chk_stretch_master";
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_catch_id;
long h_catch_id_qry;
long h_stretch_class_id;
long h_stretch_class_id_qry;
/* indicator variables */
short int h_ind_catch_id;
short int h_ind_stretch_class_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* ---------------------------------------------------------- *
* CHECK (1) -> chk. if master in CATCH_TAB exists
* ---------------------------------------------------------- */
h_catch_id_qry = vp_catch_id;
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO catch_master_not_found;
errln = 20;
EXEC SQL SELECT CATCH_ID
INTO :h_catch_id INDICATOR :h_ind_catch_id
FROM CATCH_TAB
WHERE CATCH_ID = :h_catch_id_qry
LIMIT 1;
if (NULL)
{
catch_master_not_found:
/* <<< ERROR : invalid/missing reference to master >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_MASTER;
strcpy(vp_errinfo->err_param,"(CATCH_TAB)");
return(DA_FAIL);
}
/* ---------------------------------------------------------- *
* PRE-CHECK (2) -> chk. if master in STRETCH_CLASS_TAB is avail.
* ---------------------------------------------------------- */
h_stretch_class_id_qry = vp_stretch_class_id;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO stretch_class_master_not_found;
errln = 40;
EXEC SQL SELECT STRETCH_CLASS_ID
INTO :h_stretch_class_id INDICATOR :h_ind_stretch_class_id
FROM STRETCH_CLASS_TAB
WHERE STRETCH_CLASS_ID = :h_stretch_class_id_qry
LIMIT 1;
if (NULL)
{
stretch_class_master_not_found:
/* <<< ERROR : invalid/missing reference to master >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_MASTER;
strcpy(vp_errinfo->err_param,"(STRETCH_CLASS_TAB)");
return(DA_FAIL);
}
/* all required master records do exist */
return(DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_chk_disch_master (DISCH_TAB)
*
* Issue : 20-MAY-2003 - S.F. - TechniData AG/Markdorf
*
* Purpose : Perform checks on discharge data:
*
* a) check by CATCH_ID if master record in table CATCH_TAB
* exists. In case not -> cancel insert!
*
* b) check by STRETCH_ID if referenced record in table
* STRETCH_TAB exists. In case not -> cancel insert!
*
*
* Parameter: vp_catch_id (i) catch_id of master record in CATCH_TAB
* vp_stretch_id (i) stretch_id of referenced record in
* STRETCH_TAB
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
\brief Perform checks on discharge data:
\li check by CATCH_ID if master record in table \n CATCH_TAB exists. In case not -> cancel insert! \li check by STRETCH_ID if referenced record in table \n STRETCH_TAB exists. In case not -> cancel insert!
Output:
\li vp_errinfo Error info in case error occured
\author S.F. - TechniData AG/Markdorf \n H.K. - Intevation
\date 20-MAI-2003
\param vp_catch_id catch_id of master record in CATCH_TAB
\param vp_stretch_id stretch_id of referenced record in STRETCH_TAB
\return DA_A_SUCCESS \n DA_FAIL
*/
int lgda_chk_disch_master (long vp_catch_id, long vp_stretch_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "lgda_chk_disch_master";
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_catch_id;
long h_catch_id_qry;
long h_stretch_id;
long h_stretch_id_qry;
/* indicator variables */
short int h_ind_catch_id;
short int h_ind_stretch_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* ---------------------------------------------------------- *
* CHECK (1) -> chk. if master in CATCH_TAB exists
* ---------------------------------------------------------- */
h_catch_id_qry = vp_catch_id;
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO catch_master_not_found;
errln = 20;
EXEC SQL SELECT CATCH_ID
INTO :h_catch_id INDICATOR :h_ind_catch_id
FROM CATCH_TAB
WHERE CATCH_ID = :h_catch_id_qry
LIMIT 1;
if (NULL)
{
catch_master_not_found:
/* <<< ERROR : invalid/missing reference to master >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_MASTER;
strcpy(vp_errinfo->err_param,"(CATCH_TAB)");
return(DA_FAIL);
}
/* ---------------------------------------------------------- *
* PRE-CHECK (2) -> chk. if master in STRETCH_TAB is avail.
* ---------------------------------------------------------- */
h_stretch_id_qry = vp_stretch_id;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO stretch_master_not_found;
errln = 40;
EXEC SQL SELECT STRETCH_ID
INTO :h_stretch_id INDICATOR :h_ind_stretch_id
FROM STRETCH_TAB
WHERE STRETCH_ID = :h_stretch_id_qry
LIMIT 1;
if (NULL)
{
stretch_master_not_found:
/* <<< ERROR : invalid/missing reference to master >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_MASTER;
strcpy(vp_errinfo->err_param,"(STRETCH_TAB)");
return(DA_FAIL);
}
/* all required master records do exist */
return(DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : lgda_get_access_right
*
* Issue : 19-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get access right for object, specified by "vp_obj_type" and
* "vp_obj_data"
*
*
* Parameter: vp_obj_type (i) Type of object to check (corresponds
* to name of affected database table)
* vp_obj_data (i) Pointer to struct containing detail
* information to object to check.
* vp_access_right (o) Access right for specified object
* vp_errinfo (o) Error information in case error occured
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
Output:
\li vp_access_right Access right for specified object
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-AUG-2002
\brief Get access right for object, specified by "vp_obj_type" and "vp_obj_data"
\param vp_obj_type Type of object to check (corresponds to name of affected database table).
\param vp_obj_data Pointer to struct containing detail information to object to check.
\param vp_access_right is internal and must not be given as Parameter.
\return DA_SUCCESS \n DA_FAIL.
*/
int lgda_get_access_right(char *vp_obj_type, void *vp_obj_data,
int *vp_access_right, DA_T_errinfo *vp_errinfo)
{
DA_T_catch *v_catch;
DA_T_stretch *v_stretch;
// not used: DA_T_stretch_class *v_stretch_class;
DA_T_disch *v_disch;
DA_T_bin_obj *v_bin_obj;
DA_T_backgrd_pg_h *v_backgrd;
DA_T_subst *v_subst;
DA_T_subst_det *v_subst_det;
DA_T_env *v_env;
DA_T_env_det *v_env_det;
DA_T_mod *v_mod;
DA_T_mod_det *v_mod_det;
DA_T_sess *v_sess;
DA_T_sess_disch *v_sess_disch;
DA_T_market *v_market;
DA_T_res *v_res;
DA_T_res_stretch *v_res_stretch;
DA_T_res_disch *v_res_disch;
int v_status = DA_SUCCESS;
/* ----------------- *
* start of function
* ----------------- */
#if DEBUG_MODE_ON == 1
/* debug output */
DA_T_MODULE_NAME v_module = "lgda_get_access_right";
lgda_write_debug_info(2, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
/*
* Implementation of Object specific access right check
*/
if (strcmp(vp_obj_type, DA_A_CATCH_TAB) == 0)
{
/* -------------------------- *
* DA_A_CATCH_TAB
* -------------------------- */
/* get access right for catchment */
v_catch = (DA_T_catch*) vp_obj_data;
v_status = lgda_get_catch_access_right(v_catch->catch_id,
v_catch->privs,
v_catch->user_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_STRETCH_TAB) == 0)
{
/* -------------------------- *
* DA_A_STRETCH_TAB
* -------------------------- */
/* get access right for stretch */
v_stretch = (DA_T_stretch*) vp_obj_data;
v_status = lgda_get_stretch_access_right(v_stretch->catch_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_DISCH_TAB) == 0)
{
/* -------------------------- *
* DA_A_DISCH_TAB
* -------------------------- */
/* get access right for disch */
v_disch = (DA_T_disch*) vp_obj_data;
v_status = lgda_get_disch_access_right(v_disch->catch_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_BIN_OBJ_TAB) == 0)
{
/* -------------------------- *
* DA_A_BIN_OBJ_TAB
* -------------------------- */
/* get access right for bin_obj */
v_bin_obj = (DA_T_bin_obj*) vp_obj_data;
v_status = lgda_get_bin_obj_access_right(v_bin_obj->bin_obj_id,
v_bin_obj->privs,
v_bin_obj->user_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_BACKGRD_TAB) == 0)
{
/* -------------------------- *
* DA_A_BACKGRD_JOIN_TAB
* -------------------------- */
/* get access right for background join */
v_backgrd = (DA_T_backgrd_pg_h*) vp_obj_data;
v_status = lgda_get_backgrd_join_access_right(v_backgrd->bin_obj_id,
v_backgrd->bin_obj_privs,
v_backgrd->bin_obj_user_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_SUBST_TAB) == 0)
{
/* -------------------------- *
* DA_A_SUBST_TAB
* -------------------------- */
/* get access right for substance */
v_subst = (DA_T_subst*) vp_obj_data;
v_status = lgda_get_subst_access_right(v_subst->subst_id,
v_subst->privs,
v_subst->user_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_SUBST_DET_TAB) == 0)
{
/* -------------------------- *
* DA_A_SUBST_DET_TAB
* -------------------------- */
/* get access right for substance detail */
v_subst_det = (DA_T_subst_det*) vp_obj_data;
v_status = lgda_get_subst_det_access_right(v_subst_det->subst_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_ENV_TAB) == 0)
{
/* -------------------------- *
* DA_A_ENV_TAB
* -------------------------- */
/* get access right for env. param. */
v_env = (DA_T_env*) vp_obj_data;
v_status = lgda_get_env_access_right(v_env->env_id,
v_env->privs,
v_env->user_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_ENV_DET_TAB) == 0)
{
/* -------------------------- *
* DA_A_ENV_DET_TAB
* -------------------------- */
/* get access right for env. param. detail */
v_env_det= (DA_T_env_det*) vp_obj_data;
v_status = lgda_get_env_det_access_right(v_env_det->env_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_MOD_TAB) == 0)
{
/* -------------------------- *
* DA_A_MOD_TAB
* -------------------------- */
/* get access right for mod. param. */
v_mod = (DA_T_mod*) vp_obj_data;
v_status = lgda_get_mod_access_right(v_mod->mod_id,
v_mod->privs,
v_mod->user_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_MOD_DET_TAB) == 0)
{
/* -------------------------- *
* DA_A_MOD_DET_TAB
* -------------------------- */
/* get access right for mod. param. detail */
v_mod_det= (DA_T_mod_det*) vp_obj_data;
v_status = lgda_get_mod_det_access_right(v_mod_det->mod_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_SESS_TAB) == 0)
{
/* -------------------------- *
* DA_A_SESS_TAB
* -------------------------- */
/* get access right for session */
v_sess = (DA_T_sess*) vp_obj_data;
v_status = lgda_get_sess_access_right(v_sess->sess_id,
v_sess->privs,
v_sess->user_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_SESS_DISCH_TAB) == 0)
{
/* -------------------------- *
* DA_A_SESS_DISCH_TAB
* -------------------------- */
/* get access right for s. discharge data */
v_sess_disch = (DA_T_sess_disch*) vp_obj_data;
v_status = lgda_get_sess_disch_access_right(v_sess_disch->sess_disch_id,
v_sess_disch->privs,
v_sess_disch->user_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_MARKET_TAB) == 0)
{
/* -------------------------- *
* DA_A_MARKET_TAB
* -------------------------- */
/* get access right for market data */
v_market = (DA_T_market*) vp_obj_data;
v_status = lgda_get_market_access_right(v_market->market_id,
v_market->privs,
v_market->user_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_RES_TAB) == 0)
{
/* -------------------------- *
* DA_A_RES_TAB
* -------------------------- */
/* get access right for result */
v_res = (DA_T_res*) vp_obj_data;
v_status = lgda_get_res_access_right(v_res->res_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_RES_STRETCH_TAB) == 0)
{
/* -------------------------- *
* DA_A_RES_STRETCH_TAB
* -------------------------- */
/* get access right for stretch result */
v_res_stretch = (DA_T_res_stretch*) vp_obj_data;
v_status = lgda_get_res_access_right(v_res_stretch->res_id,
vp_access_right,
vp_errinfo);
}
else if (strcmp(vp_obj_type, DA_A_RES_DISCH_TAB) == 0)
{
/* -------------------------- *
* DA_A_RES_DISCH_TAB
* -------------------------- */
/* get access right for disch result */
v_res_disch = (DA_T_res_disch*) vp_obj_data;
v_status = lgda_get_res_access_right(v_res_disch->res_id,
vp_access_right,
vp_errinfo);
}
else if ((strcmp(vp_obj_type, DA_A_PARA_TREE_TAB) == 0) ||
(strcmp(vp_obj_type, DA_A_STRETCH_CLASS_TAB) == 0))
{
/* -------------------------- *
* DA_A_PARA_TREE_TAB
* DA_A_STRETCH_CLASS_TAB
* -------------------------- */
/* data can only be maintained by administrator */
*vp_access_right = DA_A_VIEW;
}
else if ((strcmp(vp_obj_type, DA_A_USER_TAB) == 0) ||
(strcmp(vp_obj_type, DA_A_GROUP_TAB) == 0) ||
(strcmp(vp_obj_type, DA_A_GROUP_PRIV_TAB) == 0))
{
/* -------------------------- *
* DA_A_USER_TAB
* DA_A_GROUP_TAB
* DA_A_GROUP_PRIV_TAB
* -------------------------- */
/* data can only be maintained by administrator */
*vp_access_right = DA_A_VIEW;
}
else
{
/* return no access right */
*vp_access_right = DA_A_NONE;
}
/*
printf("--> %s : access right= %d\n", vp_obj_type, *vp_access_right);
*/
return (v_status);
}
/*********************************************************************
* Name : lgda_set_connection_values
*
* Issue : 05-NOV-2003 - H.Korte - Intevation
*
* Purpose : Set the specific data for database connection.
*
* Parameter: db_con (i) Pointer to Cennection
* vp_db_descr_string (i) connection target
* vp_username (i) user-id of database user
* vp_password (i) user-passwd of database user
* vp_errinfo (o) error info, just filled when
* error occurs (return=FAIL).
*
* Return : DA_SUCCESS
* DA_FAIL
*
* Globals : ---
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \internal
Output
\li vp_errinfo Error info in case error occured
\author H.K. - Intevation
\date 05-NOV-2003
\brief Sets the specific data for database connection.
\param db_con Pointer to connection
\param vp_db_descr_string connection target
\param vp_username username
\param vp_password password
\return DA_SUCCESS \n DA_FAIL.
*/
int lgda_set_connection_values(DB_con *db_con,
char *vp_db_descr,
char *vp_username,
char *vp_password,
DA_T_errinfo *vp_errinfo)
{
// not used: DA_T_MODULE_NAME v_module = "lgda_set_connection_values";
/* connection_target must be of the form: dbname@host:port, *
* dbname@host or dbname */
char *aet = "@";
char *dp = ":";
char *pos = NULL;
char *copy = NULL;
char *host = NULL;
char *port = NULL;
char *dbname = NULL;
db_con->connection_target = (char *)malloc(600 * sizeof(char));
if (strcmp(vp_db_descr,"") == 0)
strcpy(db_con->connection_target, "static_db@localhost:6544");
else
strcpy(db_con->connection_target, vp_db_descr);
copy = (char *)malloc(600 * sizeof(char));
if(copy == NULL)
return DA_FAIL;
strcpy (copy, db_con->connection_target);
if ((pos = strstr(copy,aet)) != NULL)
{
if((dbname = strtok(copy, aet)) != NULL)
{
db_con->db_name = (char *)malloc(50 * sizeof(char));
strcpy(db_con->db_name, dbname);
if((host = strtok(NULL, dp)) != NULL)
{
db_con->host = (char *)malloc(500 * sizeof(char));
strcpy(db_con->host, host);
if((port = strtok(NULL,dp)) != NULL)
{
db_con->port = (char *)malloc(50 * sizeof(char));
strcpy(db_con->port, port);
}
else
db_con->port = NULL;
}
else
{
host = strtok(NULL,"");
strcpy(db_con->host, host);
db_con->port = NULL;
}
}
}
else
{
db_con->db_name = (char *)malloc(50 * sizeof(char));
strcpy(db_con->db_name, vp_db_descr);
db_con->host = NULL;
db_con->port = NULL;
}
db_con->user_id = (char *)malloc(20 * sizeof(char));
strcpy(db_con->user_id, vp_username);
db_con->user_passwd = (char *)malloc(20 * sizeof(char));
strcpy(db_con->user_passwd, vp_password);
db_con->con_name = (char *)malloc(20 * sizeof(char));
strcpy(db_con->con_name, "conn");
free(copy);
return (DA_SUCCESS);
}
/**************************************************************************
* PUBLIC FUNCTIONS, INTERFACE FUNCTIONS
**************************************************************************/
EXEC SQL WHENEVER SQLERROR sqlprint;
EXEC SQL WHENEVER NOT FOUND sqlprint;
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* GENERAL FUNCTIONS
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_db_connect
*
* Issue : 09-SEPT-2003 - H.Korte - Intevation
*
* Purpose : Connect to GREAT-ER database (create DB session)
* After connect check if connected user is a valid
* GREAT-ER user (check USER_TAB). In case user is
* a valid user, then set global "vg_db_user_info" with
* information about connected database user.
*
* Parameter: vp_userid (i) user-id of database user
* vp_passwd (i) user-passwd of database user
* vp_connect_descr (i) database connect string
* vp_errinfo (o) error info, just filled when
* error occurs (return=FAIL).
*
* Return : success => DB_con*
* fail => NULL
*
* Globals : errln
* vg_db_user_info
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Connect to GREAT-ER database (create DB session).
After connect check if connected user is a valid GREAT-ER user (check USER_TAB). In case user is a valid user, then set global "vg_db_user_info" with information about connected database user.
Output
\li vp_errinfo Error info in case error occured
\author H.Korte - Intevation
\date 09-SEP-2003
\param vp_userid user-id of database user
\param vp_passwd user-passwd of database user
\param vp_connect_descr database connect string
\return Database connection (DB_con*) or NULL.
*/
DB_con* gda_db_connect(char *vp_userid,
char *vp_passwd,
char *vp_connect_descr,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_db_connect";
DA_T_errinfo *v_errinfo2 = NULL;
DB_con *db_con;
EXEC SQL BEGIN DECLARE SECTION;
long h_group_id;
char h_dbname [ 31];
char h_user_id [ 31];
char h_con_name [ 31];
char h_usrid_passwd[240];
short int h_ind_user_id;
EXEC SQL END DECLARE SECTION;
db_con = malloc(sizeof(DB_con));
if(!db_con)
return NULL;
lgda_set_connection_values(db_con, vp_connect_descr,
vp_userid, vp_passwd, vp_errinfo);
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_init_debug_info();
lgda_write_debug_info(1, v_module,
"User-ID :", db_con->user_id,
"Passwd :", db_con->user_passwd,
"Database:", db_con->db_name);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO not_a_valid_db_user;
strcpy(h_user_id, db_con->user_id);
strcpy(h_usrid_passwd, db_con->user_passwd);
strcpy(h_con_name, db_con->con_name);
strcpy(h_dbname, db_con->connection_target);
errln = 10;
EXEC SQL CONNECT TO :h_dbname AS :h_con_name USER :h_user_id USING :h_usrid_passwd;
if (!ECPGstatus(__LINE__, db_con->con_name))
{
return(NULL);
}
/* check if connected user is a valid GREAT-ER user and in case
* it is then set global with information about connected user
* user gets generally no administration (= table owner) rights
* if using this type of connect method */
errln = 20;
EXEC SQL WHENEVER NOT FOUND GOTO not_a_valid_greater_user;
EXEC SQL WHENEVER SQLERROR GOTO sql_error;
errln = 30;
EXEC SQL SELECT :h_user_id
INTO :h_user_id INDICATOR :h_ind_user_id;
errln = 40;
EXEC SQL SELECT GROUP_ID
INTO :h_group_id
FROM USER_TAB
WHERE USER_ID = :h_user_id;
strcpy(vg_db_user_info.user_id, h_user_id);
vg_db_user_info.group_id = h_group_id;
vg_db_user_info.admin = 0;
if(NULL){
not_a_valid_greater_user:
/*
* ERROR: no valid greater user
*/
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_DB_USER;
sprintf(vp_errinfo->err_param, "%s - (%s)", v_module, db_con->user_id);
/* disconnect from database */
gda_db_disconnect(db_con, v_errinfo2);
/* set return value */
return(NULL);
}
/* success fully connected to database */
return(db_con);
if(NULL){
not_a_valid_db_user:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
db_con = NULL;
return(db_con);
}
if(NULL){
sql_error:
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_disconnect(db_con, v_errinfo2);
return(NULL);
}
}
/*********************************************************************
* Name : gda_db_connect_admin
*
* Issue : 28-JAN-2003 - S.F. - TechniData AG/Markdorf
*
* Purpose : Connect to GREAT-ER database (create DB session)
* After connect check if connected user is a valid
* GREAT-ER user (check USER_TAB) and if the user is
* the GREAT-ER table owner. In case user is a valid
* GREAT-ER user, then set global "vg_db_user_info" with
* information about connected database user. In case
* user is not the GREAT-ER table owner, then set flag
* vp_admin to DA_NO.
*
*
* Parameter: vp_userid (i) user-id of database user
* vp_passwd (i) user-passwd of database user
* vp_connect_descr (i) database connect string
* vp_admin (o) database admin (table owner) flag
* vp_errinfo (o) error info, just filled when
* error occurs (return=FAIL).
*
* Return : success => DB_con*
* fail => NULL
*
* Globals : errln
* vg_db_user_info
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Connect Admin to GREAT-ER database (create DB session).
After connect check if connected user is a valid GREAT-ER user (check USER_TAB) ) and if the user is the GREAT-ER table owner. In case user is a valid GREAT-ER user, then set global "vg_db_user_info" with information about connected database user. In case user is not the GREAT-ER table owner, then set flag vp_admin to DA_NO.
Output
\li vp_errinfo Error info in case error occured
\author H.Korte - Intevation
\date 09-SEP-2003
\param vp_userid user-id of database user
\param vp_passwd user-passwd of database user
\param vp_connect_descr database connect string
\return Database connection (DB_con*) or NULL.
*/
DB_con * gda_db_connect_admin(char *vp_userid,
char *vp_passwd,
char *vp_connect_descr,
int *vp_admin,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_db_connect_admin";
DA_T_errinfo *v_errinfo2 = NULL;
int v_status = DA_SUCCESS;
DB_con *db_con;
EXEC SQL BEGIN DECLARE SECTION;
long h_group_id;
long h_count;
char h_user_id [ 31];
char h_con_name [ 31];
char dbname [ 31];
char h_usrid_passwd[240];
short int h_ind_user_id;
EXEC SQL END DECLARE SECTION;
db_con = malloc(sizeof(DB_con));
if(!db_con)
return (DA_FAIL);
db_con->con_name = "conn";
db_con->user_id = vp_userid;
db_con->user_passwd = vp_passwd;
db_con->db_name = vp_connect_descr;
/* Initialise admin flag */
*vp_admin = DA_FAIL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_init_debug_info();
lgda_write_debug_info(1, v_module,
"User-ID :", vp_userid,
"Passwd :", vp_passwd,
"Database:", vp_connect_descr);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* prepare login information */
if (strcmp(vp_connect_descr,"") == 0)
/* no database connect descriptor specified */
strcpy(dbname, "mydb");
else
/* database connect descriptor specified */
strcpy(dbname, vp_connect_descr);
strcpy(h_user_id, vp_userid);
strcpy(h_usrid_passwd, vp_passwd);
strcpy(h_con_name, db_con->con_name);
errln = 10;
EXEC SQL CONNECT TO :dbname AS :h_con_name USER :h_user_id;
if (!ECPGstatus(__LINE__, db_con->con_name))
{
return(NULL);
}
/* check if connected user is a valid GREAT-ER user and in case
* it is then set global with information about connected user
* if user is table owner, then set administration rights; this
* is only done inside this special connect method ! */
strcpy(h_user_id, vp_userid);
errln = 20;
EXEC SQL WHENEVER NOT FOUND GOTO not_a_valid_user;
errln = 30;
EXEC SQL SELECT UPPER(:h_user_id)
INTO :h_user_id INDICATOR :h_ind_user_id;
errln = 40;
EXEC SQL SELECT GROUP_ID
INTO :h_group_id
FROM USER_TAB
WHERE USER_ID = LOWER(:h_user_id);
strcpy(vg_db_user_info.user_id, h_user_id);
vg_db_user_info.group_id = h_group_id;
vg_db_user_info.admin = 0;
errln = 50;
/* Analogon zu Oracle-Version */
EXEC SQL SELECT COUNT(c.relname)
INTO :h_count
FROM pg_class c LEFT JOIN pg_user u ON c.relowner = u.usesysid
where c.relkind IN ('r','')
AND c.relname !~ '^pg_'
AND u.usename = :h_user_id
AND c.relname = 'CATCH_TAB';
if (NULL)
{
not_a_valid_user:
/*
* ERROR: no valid greater user
*/
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_DB_USER;
sprintf(vp_errinfo->err_param, "%s - (%s)", v_module, vp_userid);
/* disconnect from database */
v_status = gda_db_disconnect(db_con, v_errinfo2);
/* set return value */
v_status = DA_FAIL;
}
else
{
/*
* Set flag: current user is table owner
*/
if (h_count > 0)
{
*vp_admin = 1;
vg_db_user_info.admin = DA_SUCCESS;
}
}
/* success fully connected to database */
return(db_con);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(NULL);
}
/*********************************************************************
* Name : gda_db_disconnect
*
* Issue : 16-SEPT-2003 - H.Korte - Intevation
*
* Purpose : Disconnect from GREAT-ER database (close DB session)
* DON'T save last open transaction
*
* Parameter: vp_errinfo (o) error info, just filled when
* error occurs (return=FAIL).
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Disconnect from GREAT-ER database (close DB session).
DON'T save last open transaction.
Output
\li vp_errinfo Error info in case error occured
\author H.Korte - Intevation
\date 16-SEP-2003
\param db_con Pointer to connection
\return DA_SUCCESS \n DA_FAIL
*/
int gda_db_disconnect(DB_con *db_con, DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_db_disconnect";
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name [ 31];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
errln = 10;
/* PostgreSQL does not "rollback work release" to a savepoint.*
* The RELEASE statement in oracle terminates a user's *
* transaction and database session. */
strcpy(h_con_name, db_con->con_name);
gda_db_rollback(db_con,vp_errinfo);
EXEC SQL DISCONNECT :h_con_name;
free(db_con->connection_target);
free(db_con->db_name);
free(db_con->host);
free(db_con->port);
free(db_con->user_id);
free(db_con->user_passwd);
free(db_con->con_name);
free(db_con);
/* success fully disconnected from database */
return(DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_db_commit
*
* Issue : 27-JUN-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Commit current transaction in GREAT-ER database
*
*
* Parameter: vp_errinfo (o) error info, just filled when
* error occurs (return=FAIL).
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Commit current transaction in GREAT-ER database.
Output
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 27-JUN-2002
\param db_con Pointer to connection
\return DA_SUCCESS \n DA_FAIL
*/
int gda_db_commit(DB_con *db_con, DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_db_commit";
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name [ 31];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
errln = 10;
strcpy(h_con_name, db_con->con_name);
/* set the current db connection */
EXEC SQL SET CONNECTION TO :h_con_name;
EXEC SQL COMMIT WORK;
/* success fully connected to database */
return(DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_db_rollback
*
* Issue : 27-JUN-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Rollback current transaction in GREAT-ER database
*
*
* Parameter: vp_errinfo (o) error info, just filled when
* error occurs (return=FAIL).
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Rollback current transaction in GREAT-ER database.
Output
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 27-JUN-2002
\param db_con Pointer to connection
\return DA_SUCCESS \n DA_FAIL
*/
int gda_db_rollback(DB_con *db_con, DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_db_rollback";
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name [ 31];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
errln = 10;
strcpy(h_con_name, db_con->con_name);
/* set the current db connection */
EXEC SQL SET CONNECTION TO :h_con_name;
EXEC SQL ROLLBACK WORK;
/* success fully connected to database */
return(DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_get_version
*
* Issue : 05-NOV-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Return string with current GREAT-ER-Version
*
*
* Parameter: vp_ver (o) text with current GREAT-ER-Version
*
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Return string with current GREAT-ER-Version.
\author T.L. - TechniData AG/Markdorf \n H.K - Intevation
\date 30-SEP-2003
\param v_per points to the current version
\return ---
*/
void gda_get_version (char *vp_ver)
{
strcpy (vp_ver, "GREAT-ER-API with PostgreSQL Version 1.0-usf\n 2003 © TechniData AG\n 2004 © Intevation");
}
/*********************************************************************
* Name : gda_set_password
*
* Issue : 28-JAN-2003 - S.F. - TechniData AG/Markdorf
*
* Purpose : Set password for acutally connected user.
* It is not possible to set the database user
* password for a different user than the one
* actually logged in.
*
* Parameter: vp_userid (i) user-id of database user
* vp_passwd (i) user-passwd of database user
* vp_errinfo (o) error info, just filled when
* error occurs (return=FAIL).
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
* vg_db_user_info
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Set password for acutally connected user.
It is not possible to set the database user password for a different user than the one actually logged in.
Output
\li vp_errinfo Error info in case error occured
\author S.F. - TechniData AG/Markdorf \n H.K. - Intevation
\date 28-JAN-2003
\param db_con Pointer to connection
\param vp_userid user-id of database user
\param vp_passwd user-passwd of database user
\return DA_SUCCESS \n DA_FAIL
*/
int gda_set_password(DB_con *db_con, char *vp_userid, char *vp_passwd,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "da_set_password";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
char h_user_id [ 31];
char h_passwd [240];
char sql_statement[300];
char h_con_name [ 31];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_init_debug_info();
lgda_write_debug_info(1, v_module,
"User-ID :", vp_userid,
"New Passwd :", vp_passwd,
"Current user:", vg_db_user_info.user_id);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* check, if the given user is equal to the connected user */
if (strcmp(vp_userid, vg_db_user_info.user_id) == 0)
{
/* initialise information for change of password */
strcpy(h_user_id, vp_userid);
strcpy(h_passwd, vp_passwd);
strcpy(h_con_name, db_con->con_name);
sprintf(sql_statement, "ALTER USER %s IDENTIFIED BY %s",
h_user_id, h_passwd);
/* set the current db connection */
EXEC SQL SET CONNECTION TO :h_con_name;
errln = 10;
EXEC SQL EXECUTE IMMEDIATE :sql_statement;
errln = 20;
EXEC SQL WHENEVER NOT FOUND GOTO error;
}
else
{
/*
* INSUFFICIENT RIGHTS: No change of password is possible
*/
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_DB_USER;
sprintf(vp_errinfo->err_param, "%s - (%s)", v_module, vp_userid);
/* set return value */
v_status = DA_FAIL;
}
/* success fully password changed for current user */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: CATCH_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_catch (CATCH_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of catchments from CATCH_TAB.
*
* Query conditions:
* a) catch_id = -1, => return: 1..n records
* b) catch_id <>-1 => return: 1 record
*
* Parameter: vp_catch_id (i) ID of catchment(s) to select
* vp_catch (o) Return value (list of catchments)
* vp_errinfo (o) Error info in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of catchments from CATCH_TAB.
Query conditions:
\li catch_id = -1, => return: 1..n records
\li catch_id <>-1 => return: 1 record
Output
\li vp_catch Return value (list of catchments)
\li vp_errinfo Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param db_con Pointer to connection
\param vp_catch_id ID of catchment(s) to select
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_catch (DB_con *db_con, long vp_catch_id,
DA_T_catch **vp_catch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_catch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_catch v_catch_buf;
/* pointer to list root, list elements */
DA_T_catch *v_root_lst_ptr = NULL;
DA_T_catch *v_new_elem_ptr = NULL;
DA_T_catch *v_last_elem_ptr = NULL;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_catch_id_qry[240];
char h_fmt_date [ 30];
char h_query [2000];
struct DA_T_catch_pg_h{ /* type contains host variables for object data */
long catch_id;
char user_id [ 31];
char cre_date[ 21];
char mod_date[ 21];
char status [ 31];
int privs;
char name [256];
char remark [2001];
} h_catch;
char h_con_name[31];
struct DA_T_catch_pg_i{ /* indicator variables for host variable struct */
short int catch_id;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int name;
short int remark;
} h_ind_catch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for return values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* determine query condition
* a) catch_id = -1, => return: 1..n records
* b) catch_id <>-1 => return: 1 record
*/
if (vp_catch_id == -1)
{
/* case a) */
strcpy (h_catch_id_qry, "");
}
else
{
/* case b) */
sprintf(h_catch_id_qry, "WHERE CATCH_ID = %ld", vp_catch_id);
}
/*
* DECLARE CURSOR
* to select the catchment details from CATCH_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf(h_query,"SELECT CATCH_ID,"
"USER_ID,"
"CRE_DATE,"
"MOD_DATE,"
"STATUS,"
"PRIVS,"
"NAME,"
"REMARK "
" FROM CATCH_TAB "
"%s"
"ORDER BY CATCH_ID;", h_catch_id_qry);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE catch_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN catch_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH catch_csr INTO :h_catch INDICATOR :h_ind_catch;
/* check indicator variables (in regard to NULL values) */
if (h_ind_catch.catch_id == -1) h_catch.catch_id = -1;
if (h_ind_catch.privs == -1) h_catch.privs = 1;
if (h_ind_catch.name == -1) strcpy(h_catch.name, "");
if (h_ind_catch.user_id == -1) strcpy(h_catch.user_id, "");
if (h_ind_catch.cre_date == -1) strcpy(h_catch.cre_date, "");
if (h_ind_catch.mod_date == -1) strcpy(h_catch.mod_date, "");
if (h_ind_catch.status == -1) strcpy(h_catch.status, "");
if (h_ind_catch.remark == -1) strcpy(h_catch.remark, "");
/* copy result into temp. buffer */
v_catch_buf.catch_id = h_catch.catch_id;
v_catch_buf.privs = h_catch.privs;
strcpy(v_catch_buf.name, h_catch.name);
strcpy(v_catch_buf.user_id, h_catch.user_id);
strcpy(v_catch_buf.cre_date, h_catch.cre_date);
strcpy(v_catch_buf.mod_date, h_catch.mod_date);
strcpy(v_catch_buf.status, h_catch.status);
strcpy(v_catch_buf.remark, h_catch.remark);
v_catch_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_CATCH_TAB, (void*) &v_catch_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_catch*) malloc( sizeof(DA_T_catch) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT; /* I */
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC; /* 9000 */
sprintf(vp_errinfo->err_param,"%s - malloc(DA_T_catch)", v_module);
gda_free_catch(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_catch) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_catch_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE catch_csr;
/* return created result list */
(*vp_catch) = v_root_lst_ptr;
/* success fully connected to database */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE catch_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_catch (CATCH_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_catch()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_catch (i) pointer to "list of" catchment records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_catch()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param vp_catch pointer to "list of" catchment records
\return ---
*/
void gda_free_catch(DA_T_catch *vp_catch)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "da_free_catch";
#endif
/* pointer to list elements */
DA_T_catch *v_next_elem_ptr = NULL;
DA_T_catch *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_catch;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/*********************************************************************
* Name : gda_insert_catch (CATCH_TAB)
*
* Issue : 19-MAY-2003 - S.F. - TechniData AG/Markdorf
*
* Purpose : Insert record into CATCH_TAB. Return new "CATCH_ID" by
* passed struct, in case insert could successfully be done
*
* Parameter: vp_catch (i/o) data to insert into CATCH_TAB,
* OUTPUT:
* - catch_id = NEXTVAL('CATCH_SEQ')
* - cre_date = CURRENT_TIMESTAMP
* - mod_date = CURRENT_TIMESTAMP
* - user_id =
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
* vg_db_user_info(i) -> general information about database
* user of current db-session
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into CATCH_TAB.
Return new "CATCH_ID" by passed struct, in case insert could successfully be done.
Output
vp_errinfo - error information in case error occured will be saved in
\author S.F. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-MAY-2003
\param db_con Pointer to connection
\param vp_catch data to insert into CATCH_TAB \n OUTPUT: catch_id = NEXTVAL('CATCH_SEQ') cre_date = CURRENT_TIMESTAMP mod_date = CURRENT_TIMESTAMP user_id =
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_catch (DB_con *db_con, DA_T_catch *vp_catch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_catch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_catch_id_new;
char h_fmt_date[30];
char h_con_name[31];
struct DA_T_catch_pg_h{ /* type contains host variables for object data */
long catch_id;
char user_id [ 31];
char cre_date[ 21];
char mod_date[ 21];
char status [ 31];
int privs;
char name [256];
char remark [2001];
} h_catch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* current db-user becomes owner of the new data -> acc. rhgt=VIEW+EDIT */
v_access_right = DA_A_VIEWEDIT;
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* get new CATCH_ID */
errln = 10;
EXEC SQL SELECT to_char(CURRENT_TIMESTAMP, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_catch.cre_date,
:h_catch.mod_date;
/*
* copy passed record into host variable
*/
h_catch.privs = vp_catch->privs;
strcpy (h_catch.user_id , vg_db_user_info.user_id);
strcpy (h_catch.status , vp_catch->status);
strcpy (h_catch.name , vp_catch->name);
strcpy (h_catch.remark , vp_catch->remark);
/* Insert passed record */
errln = 20;
EXEC SQL INSERT INTO CATCH_TAB ( USER_ID,
CRE_DATE,
MOD_DATE,
STATUS,
PRIVS,
NAME,
REMARK )
VALUES ( :h_catch.user_id,
:h_catch.cre_date,
:h_catch.mod_date,
:h_catch.status,
:h_catch.privs,
:h_catch.name,
:h_catch.remark );
/* set return value (created CATCH_ID,...) into passed struct/record */
EXEC SQL SELECT CURRVAL('CATCH_SEQ') INTO :h_catch_id_new;
vp_catch->catch_id = h_catch_id_new;
strcpy(vp_catch->user_id, h_catch.user_id);
strcpy(vp_catch->cre_date, h_catch.cre_date);
strcpy(vp_catch->mod_date, h_catch.mod_date);
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_catch (CATCH_TAB)
*
* Issue : 11-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by CATCH_ID) in CATCH_TAB
* by data of passed record.
*
* Parameter: vp_catch (i) new catch data, containing CATCH_ID of
* record to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by CATCH_ID) in CATCH_TAB by data of passed record.
Output:
vp_errinfo - error information in case error occured will be saved in
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 11-OCT-2003
\param db_con Pointer to connection
\param vp_catch new catch data, containing CATCH_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_catch (DB_con *db_con, DA_T_catch *vp_catch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "da_update_catch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_fmt_date[30];
char h_con_name[31];
struct DA_T_catch_pg_h{ /* type contains host variables for object data */
long catch_id;
char user_id [ 31];
char cre_date[ 21];
char mod_date[ 21];
char status [ 31];
int privs;
char name [256];
char remark [2001];
} h_catch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_CATCH_TAB, (void*) vp_catch,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
EXEC SQL SELECT to_char(CURRENT_TIMESTAMP, :h_fmt_date) INTO :h_catch.mod_date;
h_catch.catch_id = vp_catch->catch_id;
strcpy (h_catch.user_id , vp_catch->user_id);
strcpy (h_catch.status , vp_catch->status);
h_catch.privs = vp_catch->privs;
strcpy (h_catch.name , vp_catch->name);
strcpy (h_catch.remark , vp_catch->remark);
/* update passed record in datebase, ignore CRE_DATE for update */
errln = 20;
EXEC SQL UPDATE CATCH_TAB
SET USER_ID = :h_catch.user_id,
MOD_DATE = :h_catch.mod_date,
STATUS = :h_catch.status,
PRIVS = :h_catch.privs,
NAME = :h_catch.name,
REMARK = :h_catch.remark
WHERE CATCH_ID = :h_catch.catch_id;
/* return new MOD_DATE by passed struct */
strcpy(vp_catch->mod_date, h_catch.mod_date);
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record snot updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_catch (CATCH_TAB)
*
* Issue : 11-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Delete record from CATCH_TAB specified by "catch_id"
*
* Parameter: vp_catch_id (i) CATCH_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from CATCH_TAB specified by "catch_id".
Output:
vp_errinfo - Error information in case error occured will be saved in
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 11-OCT-2003
\param db_con Pointer to connection
\param vp_catch_id new CATCH_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_catch ( DB_con *db_con, long vp_catch_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "da_delete_catch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
DA_T_catch v_catch_buf;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_fmt_date[30];
int h_count;
char h_con_name[31];
struct DA_T_catch_pg_h{ /* type contains host variables for object data */
long catch_id;
char user_id [ 31];
char cre_date[ 21];
char mod_date[ 21];
char status [ 31];
int privs;
char name [256];
char remark [2001];
} h_catch;
struct DA_T_catch_pg_i{ /* indicator variables for host variable struct */
short int catch_id;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int name;
short int remark;
} h_ind_catch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
errln = 10;
h_catch.catch_id = vp_catch_id;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
EXEC SQL SELECT COUNT (SESS_ID)
INTO :h_count
FROM SESS_TAB
WHERE CATCH_ID = :h_catch.catch_id;
if (h_count > 0)
{
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_CATCH_REF_DATA;
sprintf (vp_errinfo->err_param,"%s", v_module);
/* record not deleted */
return(DA_FAIL);
}
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
errln = 10;
EXEC SQL SELECT CATCH_ID,
USER_ID,
PRIVS
INTO :h_catch.catch_id INDICATOR :h_ind_catch.catch_id,
:h_catch.user_id INDICATOR :h_ind_catch.user_id,
:h_catch.privs INDICATOR :h_ind_catch.privs
FROM CATCH_TAB
WHERE CATCH_ID = :h_catch.catch_id;
/* check indicator variables (in regard to NULL values) */
if (h_ind_catch.catch_id == -1) h_catch.catch_id = -1;
if (h_ind_catch.user_id == -1) strcpy(h_catch.user_id, "");
if (h_ind_catch.privs == -1) h_catch.privs = 1;
/* copy result into temp. buffer */
v_catch_buf.catch_id = h_catch.catch_id;
strcpy (v_catch_buf.user_id , h_catch.user_id);
v_catch_buf.privs = h_catch.privs;
v_catch_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_CATCH_TAB, (void*) &v_catch_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* delete specified record */
errln = 20;
EXEC SQL DELETE FROM CATCH_TAB
WHERE CATCH_ID = :h_catch.catch_id;
EXEC SQL WHENEVER NOT FOUND GOTO backgrd_join_not_found;
/* delete referenced background join record */
errln = 30;
EXEC SQL DELETE FROM BACKGRD_JOIN_TAB
WHERE CATCH_ID = :h_catch.catch_id;
if (NULL)
{
backgrd_join_not_found:
NULL;
}
/* record successfully deleted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not deleted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: STRETCH_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_stretch (STRETCH_TAB)
*
* Issue : 02-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of stretches for specified catchment
*
* Query conditions:
* a) stretch_id = -1, catch_id >0 => return: 1..n records
* (all stretches for catchm.)
* b) stretch_id <>-1, catch_id >0 => return: 1 record
* (one stretch for catchm.)
*
* Parameter: vp_catch_id (i) ID of catchm. for which stretch(s)
* shall be selected
* vp_stretch_id (i) ID of stretch to select
* vp_stretch (o) Return value (list of stretches)
* vp_errinfo (o) Error info in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of stretches for specified catchment.
Query conditions:
stretch_id = -1, catch_id >0 => return: 1..n records (all stretches for catchm.)
stretch_id <>-1, catch_id >0 => return: 1 record (one stretch for catchm.)
Output:
vp_stretch - Return value (list of stretches)
vp_errinfo - Error information in case error occured will be saved in
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 02-AUG-2003
\param db_con Pointer to connection
\param vp_catch_id new CATCH_ID of record to delete
\param vp_stretch_id ID of stretch to select
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_stretch (DB_con *db_con,
long vp_catch_id,
long vp_stretch_id,
DA_T_stretch **vp_stretch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_stretch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_stretch v_stretch_buf;
/* pointer to list root, list elements */
DA_T_stretch *v_root_lst_ptr = NULL;
DA_T_stretch *v_new_elem_ptr = NULL;
DA_T_stretch *v_last_elem_ptr = NULL;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
char h_where_clause[100];
char h_query[2000];
struct DA_T_stretch_pg_h{ /* type contains host variables for object data */
long stretch_id;
long catch_id;
long stretch_class_id;
long up1_id;
long up2_id;
long down1_id;
long down2_id;
char name [256];
char type [ 12];
char q_val [256];
char q_dist [ 12];
char v_val [256];
char v_dist [ 12];
char l [ 41];
char d_val [256];
char d_dist [ 12];
char vol_val [256];
char vol_dist [ 12];
char baseflow [ 41];
char agriculture[41];
char natural_soil[41];
} h_stretch;
struct DA_T_stretch_pg_i{ /* indicator variables for host variable struct */
short int stretch_id;
short int catch_id;
short int stretch_class_id;
short int up1_id;
short int up2_id;
short int down1_id;
short int down2_id;
short int name;
short int type;
short int q_val;
short int q_dist;
short int v_val;
short int v_dist;
short int l;
short int d_val;
short int d_dist;
short int vol_val;
short int vol_dist;
short int baseflow;
short int agriculture;
short int natural_soil;
}h_ind_stretch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* determine query condition
* a) stretch_id = -1,catch_id >0 => return: 1..n records
* b) stretch_id <>-1,catch_id >0 => return: 1 record
*/
if (vp_stretch_id == -1)
{
/* case a) */
sprintf(h_where_clause,"CATCH_ID = %ld ", vp_catch_id);
}
else
{
/* case b) */
sprintf(h_where_clause,"CATCH_ID = %ld AND STRETCH_ID = %ld ", vp_catch_id, vp_stretch_id);
}
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the catchment details from STRETCH_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT STRETCH_ID,"
"CATCH_ID,"
"STRETCH_CLASS_ID,"
"UP1_ID,"
"UP2_ID,"
"DOWN1_ID,"
"DOWN2_ID,"
"NAME,"
"TYPE,"
"Q_VAL,"
"Q_DIST,"
"V_VAL,"
"V_DIST,"
"L,"
"D_VAL,"
"D_DIST,"
"VOL_VAL,"
"VOL_DIST,"
"BASEFLOW, "
"AGRICULTURE, "
"NATURAL_SOIL "
"FROM STRETCH_TAB "
"WHERE %s "
"ORDER BY STRETCH_ID", h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE stretch_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN stretch_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH stretch_csr INTO :h_stretch INDICATOR :h_ind_stretch;
/* check indicator variables (in regard to NULL values) */
if (h_ind_stretch.stretch_id == -1) h_stretch.stretch_id = -1;
if (h_ind_stretch.catch_id == -1) h_stretch.catch_id = -1;
if (h_ind_stretch.stretch_class_id == -1) h_stretch.stretch_class_id = -1;
if (h_ind_stretch.up1_id == -1) h_stretch.up1_id = -1;
if (h_ind_stretch.up2_id == -1) h_stretch.up2_id = -1;
if (h_ind_stretch.down1_id == -1) h_stretch.down1_id = -1;
if (h_ind_stretch.down2_id == -1) h_stretch.down2_id = -1;
if (h_ind_stretch.name == -1) strcpy(h_stretch.name, "");
if (h_ind_stretch.type == -1) strcpy(h_stretch.type, "");
if (h_ind_stretch.q_val == -1) strcpy(h_stretch.q_val, "");
if (h_ind_stretch.q_dist == -1) strcpy(h_stretch.q_dist, "");
if (h_ind_stretch.v_val == -1) strcpy(h_stretch.v_val, "");
if (h_ind_stretch.v_dist == -1) strcpy(h_stretch.v_dist, "");
if (h_ind_stretch.l == -1) strcpy(h_stretch.l, "");
if (h_ind_stretch.d_val == -1) strcpy(h_stretch.d_val, "");
if (h_ind_stretch.d_dist == -1) strcpy(h_stretch.d_dist, "");
if (h_ind_stretch.vol_val == -1) strcpy(h_stretch.vol_val, "");
if (h_ind_stretch.vol_dist == -1) strcpy(h_stretch.vol_dist, "");
if (h_ind_stretch.baseflow == -1) strcpy(h_stretch.baseflow, "");
if (h_ind_stretch.agriculture == -1) strcpy(h_stretch.agriculture, "");
if (h_ind_stretch.natural_soil == -1) strcpy(h_stretch.natural_soil, "");
/* copy result into temp. buffer */
v_stretch_buf.stretch_id = h_stretch.stretch_id;
v_stretch_buf.catch_id = h_stretch.catch_id;
v_stretch_buf.stretch_class_id = h_stretch.stretch_class_id;
v_stretch_buf.up1_id = h_stretch.up1_id;
v_stretch_buf.up2_id = h_stretch.up2_id;
v_stretch_buf.down1_id = h_stretch.down1_id;
v_stretch_buf.down2_id = h_stretch.down2_id;
strcpy(v_stretch_buf.name, h_stretch.name);
strcpy(v_stretch_buf.type, h_stretch.type);
strcpy(v_stretch_buf.q_val, h_stretch.q_val);
strcpy(v_stretch_buf.q_dist, h_stretch.q_dist);
strcpy(v_stretch_buf.v_val, h_stretch.v_val);
strcpy(v_stretch_buf.v_dist, h_stretch.v_dist);
strcpy(v_stretch_buf.l, h_stretch.l);
strcpy(v_stretch_buf.d_val, h_stretch.d_val);
strcpy(v_stretch_buf.d_dist, h_stretch.d_dist);
strcpy(v_stretch_buf.vol_val, h_stretch.vol_val);
strcpy(v_stretch_buf.vol_dist, h_stretch.vol_dist);
strcpy(v_stretch_buf.baseflow, h_stretch.baseflow);
strcpy(v_stretch_buf.agriculture, h_stretch.agriculture);
strcpy(v_stretch_buf.natural_soil,h_stretch.natural_soil);
v_stretch_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_STRETCH_TAB, (void*) &v_stretch_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_stretch*) malloc( sizeof(DA_T_stretch) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param,"%s - malloc(DA_T_stretch)", v_module);
gda_free_stretch(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_stretch) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_stretch_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE stretch_csr;
/* return created result list */
(*vp_stretch) = v_root_lst_ptr;
/* success fully connected to database */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE stretch_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_stretch (STRETCH_TAB)
*
* Issue : 02-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_stretch()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_stretch (i) pointer to "list of" stretch records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_stretch()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 02-AUG-2002
\param vp_stretch pointer to "list of" stretch records
\return ---
*/
void gda_free_stretch(DA_T_stretch *vp_stretch)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_stretch";
#endif
/* pointer to list elements */
DA_T_stretch *v_next_elem_ptr = NULL;
DA_T_stretch *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_stretch;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/*********************************************************************
* Name : gda_insert_stretch (STRETCH_TAB)
*
* Issue : 19-MAY-2003 - S.F. - TechniData AG/Markdorf
*
* Purpose : - Insert record into STRETCH_TAB. There is no new STRETCH_ID
* returned, because STRETCH_ID is stored as given by
* input parameter (due to catchment preprocessing).
*
* - Before INSERT is done
* a) check by CATCH_ID if master record in table CATCH_TAB
* exists. In case not -> cancel insert!
* b) check by STRETCH_CLASS_ID if referenced record in table
* STRETCH_CLASS_ID exists. In case not -> cancel insert!
*
* - Update "MOD_DATE" in master record (CATCH_TAB) by System Date
* (PostgreSQL equivalent is CURRENT_TIMESTAMP | Oracle -> CURRENT_TIMESTAMP)
*
*
* Parameter: vp_stretch (i/o) data to insert into STRETCH_TAB,
* Attention:
* stretch_id is not set by sequence,
* but as given by input data !
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into STRETCH_TAB.
There is no new STRETCH_ID returned, because STRETCH_ID is stored as given by input parameter (due to catchment preprocessing).
Before INSERT is done \n check by CATCH_ID if master record in table CATCH_TAB exists. In case not -> cancel insert! \n check by STRETCH_CLASS_ID if referenced record in table STRETCH_CLASS_ID exists. In case not -> cancel insert!
Update "MOD_DATE" in master record (CATCH_TAB) by System Date (PostgreSQL equivalent is CURRENT_TIMESTAMP | Oracle -> SYSDATE)
Output:
vp_errinfo - error information in case error occured
\author S.F. - TechniData AG/Markdorf \n H.K. - Intevation
\date 19-MAY-2003
\param db_con Pointer to connection
\param vp_stretch data to insert into STRETCH_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_stretch (DB_con *db_con,
DA_T_stretch *vp_stretch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "da_insert_stretch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_master_chk = DA_FAIL;
char v_errmsg[256];
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_catch_id_qry;
char h_fmt_date[30];
char h_con_name[31];
struct DA_T_stretch_pg_h{ /* type contains host variables for object data */
long stretch_id;
long catch_id;
long stretch_class_id;
long up1_id;
long up2_id;
long down1_id;
long down2_id;
char name [256];
char type [ 12];
char q_val [256];
char q_dist [ 12];
char v_val [256];
char v_dist [ 12];
char l [ 41];
char d_val [256];
char d_dist [ 12];
char vol_val [256];
char vol_dist [ 12];
char baseflow [ 41];
char agriculture[41];
char natural_soil[41];
}h_stretch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set date format mask */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
/* ------------------ *
* PRE-CHECKS
* ------------------ */
v_master_chk = lgda_chk_stretch_master(vp_stretch->catch_id,
vp_stretch->stretch_class_id,
vp_errinfo);
if (v_master_chk != DA_SUCCESS)
{
/* error during check of master record */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_STRETCH_TAB, (void*) vp_stretch,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
errln = 50;
h_stretch.stretch_id = vp_stretch->stretch_id;
h_stretch.catch_id = vp_stretch->catch_id;
h_stretch.stretch_class_id = vp_stretch->stretch_class_id;
h_stretch.up1_id = vp_stretch->up1_id;
h_stretch.up2_id = vp_stretch->up2_id;
h_stretch.down1_id = vp_stretch->down1_id;
h_stretch.down2_id = vp_stretch->down2_id;
strcpy(h_stretch.name , vp_stretch->name);
strcpy(h_stretch.type , vp_stretch->type);
strcpy(h_stretch.q_val , vp_stretch->q_val);
strcpy(h_stretch.q_dist , vp_stretch->q_dist);
strcpy(h_stretch.v_val , vp_stretch->v_val);
strcpy(h_stretch.v_dist , vp_stretch->v_dist);
strcpy(h_stretch.l , vp_stretch->l);
strcpy(h_stretch.d_val , vp_stretch->d_val);
strcpy(h_stretch.d_dist , vp_stretch->d_dist);
strcpy(h_stretch.vol_val , vp_stretch->vol_val);
strcpy(h_stretch.vol_dist , vp_stretch->vol_dist);
strcpy(h_stretch.baseflow , vp_stretch->baseflow);
strcpy(h_stretch.agriculture , vp_stretch->agriculture);
strcpy(h_stretch.natural_soil, vp_stretch->natural_soil);
EXEC SQL SET CONNECTION TO :h_con_name;
/* Insert passed record */
errln = 60;
EXEC SQL INSERT INTO STRETCH_TAB ( STRETCH_ID,
CATCH_ID,
STRETCH_CLASS_ID,
UP1_ID,
UP2_ID,
DOWN1_ID,
DOWN2_ID,
NAME,
TYPE,
Q_VAL,
Q_DIST,
V_VAL,
V_DIST,
L,
D_VAL,
D_DIST,
VOL_VAL,
VOL_DIST,
BASEFLOW,
AGRICULTURE,
NATURAL_SOIL )
VALUES (:h_stretch.stretch_id,
:h_stretch.catch_id,
:h_stretch.stretch_class_id,
:h_stretch.up1_id,
:h_stretch.up2_id,
:h_stretch.down1_id,
:h_stretch.down2_id,
:h_stretch.name,
:h_stretch.type,
:h_stretch.q_val,
:h_stretch.q_dist,
:h_stretch.v_val,
:h_stretch.v_dist,
:h_stretch.l,
:h_stretch.d_val,
:h_stretch.d_dist,
:h_stretch.vol_val,
:h_stretch.vol_dist,
:h_stretch.baseflow,
:h_stretch.agriculture,
:h_stretch.natural_soil
);
/* Update MOD_DATE in master (CATCH_TAB) */
h_catch_id_qry = vp_stretch->catch_id;
errln = 70;
EXEC SQL UPDATE CATCH_TAB
SET MOD_DATE = to_timestamp(to_char(CURRENT_TIMESTAMP, :h_fmt_date), :h_fmt_date)
WHERE CATCH_ID = :h_catch_id_qry;
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_stretch (STRETCH_TAB)
*
* Issue : 14-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by CATCH_ID, STRETCH_ID) in
* STRETCH_TAB with data of passed record.
*
* Parameter: vp_stretch (i) new stretch data, containing CATCH_ID and
* STRETCH_ID of record to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by CATCH_ID, STRETCH_ID) in STRETCH_TAB with data of passed record.
Output:
vp_errinfo - error information in case error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 14-OCT-2002
\param db_con Pointer to connection
\param vp_stretch new stretch data, containing CATCH_ID and STRETCH_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_stretch (DB_con *db_con, DA_T_stretch vp_stretch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "da_update_stretch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
struct DA_T_stretch_pg_h{ /* type contains host variables for object data */
long stretch_id;
long catch_id;
long stretch_class_id;
long up1_id;
long up2_id;
long down1_id;
long down2_id;
char name [256];
char type [ 12];
char q_val [256];
char q_dist [ 12];
char v_val [256];
char v_dist [ 12];
char l [ 41];
char d_val [256];
char d_dist [ 12];
char vol_val [256];
char vol_dist [ 12];
char baseflow [ 41];
char agriculture[41];
char natural_soil[41];
} h_stretch;
char h_fmt_date[30];
char h_con_name[31];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
/* get access right for data */
v_status = lgda_get_access_right(DA_A_STRETCH_TAB, (void*) &vp_stretch,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_stretch.stretch_id = vp_stretch.stretch_id;
h_stretch.catch_id = vp_stretch.catch_id;
h_stretch.stretch_class_id = vp_stretch.stretch_class_id;
h_stretch.up1_id = vp_stretch.up1_id;
h_stretch.up2_id = vp_stretch.up2_id;
h_stretch.down1_id = vp_stretch.down1_id;
h_stretch.down2_id = vp_stretch.down2_id;
strcpy (h_stretch.name , vp_stretch.name);
strcpy (h_stretch.type , vp_stretch.type);
strcpy (h_stretch.q_val , vp_stretch.q_val);
strcpy (h_stretch.q_dist , vp_stretch.q_dist);
strcpy (h_stretch.v_val , vp_stretch.v_val);
strcpy (h_stretch.v_dist , vp_stretch.v_dist);
strcpy (h_stretch.l , vp_stretch.l);
strcpy (h_stretch.d_val , vp_stretch.d_val);
strcpy (h_stretch.d_dist , vp_stretch.d_dist);
strcpy (h_stretch.vol_val , vp_stretch.vol_val);
strcpy (h_stretch.vol_dist , vp_stretch.vol_dist);
strcpy (h_stretch.baseflow , vp_stretch.baseflow);
strcpy (h_stretch.agriculture , vp_stretch.agriculture);
strcpy (h_stretch.natural_soil, vp_stretch.natural_soil);
EXEC SQL SET CONNECTION TO :h_con_name;
errln = 10;
EXEC SQL UPDATE STRETCH_TAB
SET STRETCH_CLASS_ID = :h_stretch.stretch_class_id,
UP1_ID = :h_stretch.up1_id,
UP2_ID = :h_stretch.up2_id,
DOWN1_ID = :h_stretch.down1_id,
DOWN2_ID = :h_stretch.down2_id,
NAME = :h_stretch.name,
TYPE = :h_stretch.type,
Q_VAL = :h_stretch.q_val,
Q_DIST = :h_stretch.q_dist,
V_VAL = :h_stretch.v_val,
V_DIST = :h_stretch.v_dist,
L = :h_stretch.l,
D_VAL = :h_stretch.d_val,
D_DIST = :h_stretch.d_dist,
VOL_VAL = :h_stretch.vol_val,
VOL_DIST = :h_stretch.vol_dist,
BASEFLOW = :h_stretch.baseflow,
AGRICULTURE = :h_stretch.agriculture,
NATURAL_SOIL = :h_stretch.natural_soil
WHERE CATCH_ID = :h_stretch.catch_id
AND STRETCH_ID = :h_stretch.stretch_id;
/* update mod_date of master record */
errln = 20;
EXEC SQL UPDATE CATCH_TAB
SET MOD_DATE = CURRENT_TIMESTAMP
WHERE CATCH_ID = :h_stretch.catch_id;
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record snot updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_stretch (STRETCH_TAB)
*
* Issue : 14-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Delete record from STRETCH_TAB specified by "STRETCH_ID"
* and "CATCH_ID".
*
* Parameter: vp_catch_id (i) CATCH_ID of record to delete
* vp_stretch_id (i) STRETCH_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from STRETCH_TAB specified by "STRETCH_ID" and "CATCH_ID".
Output:
vp_errinfo - error information in case error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 14-OCT-2002
\param db_con Pointer to connection
\param vp_catch_id CATCH_ID of record to delete
\param vp_stretch_id STRETCH_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_stretch (DB_con *db_con, long vp_catch_id,
long vp_stretch_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "da_delete_stretch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
DA_T_stretch v_stretch_buf;
EXEC SQL BEGIN DECLARE SECTION;
struct DA_T_stretch_pg_h{ /* type contains host variables for object data */
long stretch_id;
long catch_id;
long stretch_class_id;
long up1_id;
long up2_id;
long down1_id;
long down2_id;
char name [256];
char type [ 12];
char q_val [256];
char q_dist [ 12];
char v_val [256];
char v_dist [ 12];
char l [ 41];
char d_val [256];
char d_dist [ 12];
char vol_val [256];
char vol_dist [ 12];
char baseflow [ 41];
char agriculture[41];
char natural_soil[41];
} h_stretch;
char h_con_name[31];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* copy catch_id into temp. buffer */
v_stretch_buf.catch_id = vp_catch_id;
v_stretch_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_STRETCH_TAB, (void*) &v_stretch_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
h_stretch.stretch_id = vp_stretch_id;
h_stretch.catch_id = vp_catch_id;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* delete specified record */
errln = 10;
EXEC SQL DELETE FROM STRETCH_TAB
WHERE STRETCH_ID = :h_stretch.stretch_id
AND CATCH_ID = :h_stretch.catch_id;
/* update mod_date of master record */
errln = 20;
EXEC SQL UPDATE CATCH_TAB
SET MOD_DATE = CURRENT_TIMESTAMP
WHERE CATCH_ID = :h_stretch.catch_id;
/* record successfully deleted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not deleted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: STRETCH_CLASS_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_stretch_class (STRETCH_CLASS_TAB)
*
* Issue : 02-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of stretch classes for specified catchment,stretch
*
* Query conditions:
* a) stretch_class_id = -1; return: 1..n records
* b) stretch_class_id<> -1; return: 1 record
*
* Parameter: vp_stretch_class_id (i) ID stretch class to select
* vp_stretch_class (o) Return value (list of stretch
* classes)
* vp_errinfo (o) Error info in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of stretch classes for specified catchment,stretch.
Query conditions:
stretch_class_id = -1; return: 1..n records
stretch_class_id<> -1; return: 1 record
Output:
vp_stretch_class - Return value (list of stretch classes)
vp_errinfo - Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 02-AUG-2002
\param db_con Pointer to connection
\param vp_stretch_class_id ID stretch class to select
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_stretch_class (DB_con *db_con,
long vp_stretch_class_id,
DA_T_stretch_class **vp_stretch_class,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_stretch_class";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_stretch_class v_stretch_class_buf;
/* pointer to list root, list elements */
DA_T_stretch_class *v_root_lst_ptr = NULL;
DA_T_stretch_class *v_new_elem_ptr = NULL;
DA_T_stretch_class *v_last_elem_ptr = NULL;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
char h_where_clause[100];
char h_query[2000];
struct DA_T_stretch_class_pg_h{ /* type contains host variables for object data */
long stretch_class_id;
char name [256];
char ss_val [256];
char ss_dist[ 12];
char f_oc [ 41];
char ph_val [256];
char ph_dist[ 12];
char k_z [ 41];
char x [ 41];
char do_val [256];
char do_dist[ 12];
char temp_water_val [256];
char temp_water_dist[ 12];
char temp_air_val [256];
char temp_air_dist [ 12];
char v_sed [ 41];
char eps_sed [ 41];
char rho_sed [ 41];
char v_wind10_val [256];
char v_wind10_dist [ 12];
char remark [2001];
} h_stretch_class;
struct DA_T_stretch_class_pg_i{ /* indicator variables for host variable struct */
short int stretch_class_id;
short int name;
short int ss_val;
short int ss_dist;
short int f_oc;
short int ph_val;
short int ph_dist;
short int k_z;
short int x;
short int do_val;
short int do_dist;
short int temp_water_val;
short int temp_water_dist;
short int temp_air_val;
short int temp_air_dist;
short int v_sed;
short int eps_sed;
short int rho_sed;
short int v_wind10_val;
short int v_wind10_dist;
short int remark;
} h_ind_stretch_class;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* determine query condition
* a) stretch_class_id = -1; return: 1..n records
* b) stretch_class_id<> -1; return: 1 record
*/
if (vp_stretch_class_id == -1)
{
/* case a) */
strcpy(h_where_clause, "");
}
else
{
/* case b) */
sprintf(h_where_clause, "WHERE STRETCH_CLASS_ID = %ld", vp_stretch_class_id);
}
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the catchment details from STRETCH_CLASS_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT STRETCH_CLASS_ID, "
"NAME, "
"SS_VAL,"
"SS_DIST,"
"F_OC,"
"PH_VAL,"
"PH_DIST,"
"K_Z,"
"X,"
"DO_VAL,"
"DO_DIST,"
"TEMP_WATER_VAL,"
"TEMP_WATER_DIST,"
"TEMP_AIR_VAL,"
"TEMP_AIR_DIST,"
"V_SED,"
"EPS_SED,"
"RHO_SED,"
"V_WIND10_VAL,"
"V_WIND10_DIST,"
"REMARK "
"FROM STRETCH_CLASS_TAB "
"%s "
"ORDER BY STRETCH_CLASS_ID", h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE stretch_class_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN stretch_class_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH stretch_class_csr INTO :h_stretch_class INDICATOR :h_ind_stretch_class;
/* check indicator variables (in regard to NULL values) */
if (h_ind_stretch_class.stretch_class_id == -1) h_stretch_class.stretch_class_id = -1;
if (h_ind_stretch_class.name == -1) strcpy(h_stretch_class.name, "");
if (h_ind_stretch_class.ss_val == -1) strcpy(h_stretch_class.ss_val, "");
if (h_ind_stretch_class.ss_dist == -1) strcpy(h_stretch_class.ss_dist, "");
if (h_ind_stretch_class.f_oc == -1) strcpy(h_stretch_class.f_oc, "");
if (h_ind_stretch_class.ph_val == -1) strcpy(h_stretch_class.ph_val, "");
if (h_ind_stretch_class.ph_dist == -1) strcpy(h_stretch_class.ph_dist, "");
if (h_ind_stretch_class.k_z == -1) strcpy(h_stretch_class.k_z, "");
if (h_ind_stretch_class.x == -1) strcpy(h_stretch_class.x, "");
if (h_ind_stretch_class.do_val == -1) strcpy(h_stretch_class.do_val, "");
if (h_ind_stretch_class.do_dist == -1) strcpy(h_stretch_class.do_dist, "");
if (h_ind_stretch_class.temp_water_val == -1) strcpy(h_stretch_class.temp_water_val, "");
if (h_ind_stretch_class.temp_water_dist == -1) strcpy(h_stretch_class.temp_water_dist,"");
if (h_ind_stretch_class.temp_air_val == -1) strcpy(h_stretch_class.temp_air_val, "");
if (h_ind_stretch_class.temp_air_dist == -1) strcpy(h_stretch_class.temp_air_dist, "");
if (h_ind_stretch_class.v_sed == -1) strcpy(h_stretch_class.v_sed, "");
if (h_ind_stretch_class.eps_sed == -1) strcpy(h_stretch_class.eps_sed, "");
if (h_ind_stretch_class.rho_sed == -1) strcpy(h_stretch_class.rho_sed, "");
if (h_ind_stretch_class.v_wind10_val == -1) strcpy(h_stretch_class.v_wind10_val, "");
if (h_ind_stretch_class.v_wind10_dist == -1) strcpy(h_stretch_class.v_wind10_dist, "");
if (h_ind_stretch_class.remark == -1) strcpy(h_stretch_class.remark, "");
/* copy result into temp. buffer */
v_stretch_class_buf.stretch_class_id = h_stretch_class.stretch_class_id;
strcpy(v_stretch_class_buf.name , h_stretch_class.name);
strcpy(v_stretch_class_buf.ss_val , h_stretch_class.ss_val);
strcpy(v_stretch_class_buf.ss_dist , h_stretch_class.ss_dist);
strcpy(v_stretch_class_buf.f_oc , h_stretch_class.f_oc);
strcpy(v_stretch_class_buf.ph_val , h_stretch_class.ph_val);
strcpy(v_stretch_class_buf.ph_dist , h_stretch_class.ph_dist);
strcpy(v_stretch_class_buf.k_z , h_stretch_class.k_z);
strcpy(v_stretch_class_buf.x , h_stretch_class.x);
strcpy(v_stretch_class_buf.do_val , h_stretch_class.do_val);
strcpy(v_stretch_class_buf.do_dist , h_stretch_class.do_dist);
strcpy(v_stretch_class_buf.temp_water_val , h_stretch_class.temp_water_val);
strcpy(v_stretch_class_buf.temp_water_dist , h_stretch_class.temp_water_dist);
strcpy(v_stretch_class_buf.temp_air_val , h_stretch_class.temp_air_val);
strcpy(v_stretch_class_buf.temp_air_dist , h_stretch_class.temp_air_dist);
strcpy(v_stretch_class_buf.v_sed , h_stretch_class.v_sed);
strcpy(v_stretch_class_buf.eps_sed , h_stretch_class.eps_sed);
strcpy(v_stretch_class_buf.rho_sed , h_stretch_class.rho_sed);
strcpy(v_stretch_class_buf.v_wind10_val , h_stretch_class.v_wind10_val);
strcpy(v_stretch_class_buf.v_wind10_dist , h_stretch_class.v_wind10_dist);
strcpy(v_stretch_class_buf.remark , h_stretch_class.remark);
v_stretch_class_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_STRETCH_CLASS_TAB, (void*)
&v_stretch_class_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_stretch_class*) malloc( sizeof(DA_T_stretch_class) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param,"%s - malloc(DA_T_stretch_class)", v_module);
gda_free_stretch_class(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_stretch_class) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_stretch_class_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE stretch_class_csr;
/* return created result list */
(*vp_stretch_class) = v_root_lst_ptr;
/* success fully connected to database */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE stretch_class_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_stretch_class (STRETCH_CLASS_TAB)
*
* Issue : 02-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_stretch_class()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_stretch (i) pointer to "list of" stretch records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_stretch_class()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 02-AUG-2002
\param vp_stretch pointer to "list of" stretch records
\return ---
*/
void gda_free_stretch_class(DA_T_stretch_class *vp_stretch_class)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_stretch_class";
#endif
/* pointer to list elements */
DA_T_stretch_class *v_next_elem_ptr = NULL;
DA_T_stretch_class *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_stretch_class;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: DISCH_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_disch (DISCH_TAB)
*
* Issue : 02-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of discharges (disches)
*
* Query conditions:
* a) catch_id_id > 0; disch_id > 0, stretch_id > 0 => 1 rec.
* b) catch_id_id > 0; disch_id > 0, stretch_id = -1 => 1 rec.
* c) catch_id_id > 0; disch_id =-1, stretch_id > 0 => 1 rec.
* d) catch_id_id > 0; disch_id =-1, stretch_id = -1 => 1..n rec.
*
* Parameter: vp_catch_id (i) ID of catchment to which stretch of
* disch is linked
* vp_stretch_id (i) ID of stretch to which disch is linked
* vp_disch_id (i) ID of requested disch
* vp_disch (o) Return value (list of discharge)
* vp_errinfo (o) Error info in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of discharges (disches).
Query conditions:
catch_id_id > 0; disch_id > 0, stretch_id > 0 => 1 rec.
catch_id_id > 0; disch_id > 0, stretch_id = -1 => 1 rec.
catch_id_id > 0; disch_id =-1, stretch_id > 0 => 1 rec.
catch_id_id > 0; disch_id =-1, stretch_id = -1 => 1..n rec.
Output:
vp_disch - Return value (list of discharge)
vp_errinfo - Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 02-AUG-2002
\param db_con Pointer to connection
\param vp_catch_id ID of catchment to which stretch of disch is linked
\param vp_stretch_id ID of stretch to which disch is linked
\param vp_disch_id D of requested disch
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_disch (DB_con *db_con,
long vp_catch_id,
long vp_stretch_id,
long vp_disch_id,
DA_T_disch **vp_disch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_disch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_disch v_disch_buf;
/* pointer to list root, list elements */
DA_T_disch *v_root_lst_ptr = NULL;
DA_T_disch *v_new_elem_ptr = NULL;
DA_T_disch *v_last_elem_ptr = NULL;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
char h_where_clause[100];
char h_query[2000];
struct DA_T_disch_pg_h{ /* type contains host variables for object data */
long disch_id;
long stretch_id;
long catch_id;
char name [256];
char pop [ 41];
char paved_surface[41];
char roof [ 41];
char roof_indust[ 41];
char street [ 41];
char srt [ 41];
char flow_val [256];
char flow_dist [ 12];
char mlss [ 41];
char vol_vk [ 41];
char vol_bb [ 41];
char f_mix [ 41];
char type [ 41];
char vol_sewer [ 41];
char remark [2001];
}h_disch;
struct DA_T_disch_pg_i{ /* indicator variables for host variable struct */
short int disch_id;
short int stretch_id;
short int catch_id;
short int name;
short int pop;
short int paved_surface;
short int roof;
short int roof_indust;
short int street;
short int srt;
short int flow_val;
short int flow_dist;
short int mlss;
short int vol_vk;
short int vol_bb;
short int f_mix;
short int type;
short int vol_sewer;
short int remark;
} h_ind_disch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* determine query condition
* a) catch_id > 0; disch_id > 0, stretch_id > 0 => 1 rec.
* b) catch_id > 0; disch_id > 0, stretch_id = -1 => 1 rec.
* c) catch_id > 0; disch_id =-1, stretch_id > 0 => 1 rec.
* d) catch_id > 0; disch_id =-1, stretch_id = -1 => 1..n rec.
*/
if (vp_catch_id != -1 && vp_stretch_id != -1 && vp_disch_id != -1)
sprintf(h_where_clause,"WHERE DISCH_ID = %ld AND CATCH_ID = %ld AND STRETCH_ID = %ld ",
vp_disch_id, vp_catch_id, vp_stretch_id);
else if (vp_catch_id != -1 && vp_stretch_id == -1 && vp_disch_id != -1)
sprintf(h_where_clause,"WHERE CATCH_ID = %ld AND DISCH_ID = %ld ", vp_catch_id, vp_disch_id);
else if (vp_catch_id != -1 && vp_stretch_id != -1 && vp_disch_id == -1)
sprintf(h_where_clause,"WHERE CATCH_ID = %ld AND STRETCH_ID = %ld ", vp_catch_id, vp_stretch_id);
else if (vp_catch_id != -1 && vp_stretch_id == -1 && vp_disch_id == -1)
sprintf(h_where_clause,"WHERE CATCH_ID = %ld", vp_catch_id);
else if (vp_catch_id == -1 && vp_stretch_id != -1 && vp_disch_id != -1)
sprintf(h_where_clause,"WHERE DISCH_ID = %ld AND STRETCH_ID = %ld ", vp_disch_id, vp_stretch_id);
else if (vp_catch_id == -1 && vp_stretch_id != -1 && vp_disch_id == -1)
sprintf(h_where_clause,"WHERE STRETCH_ID = %ld ", vp_stretch_id);
else if (vp_catch_id == -1 && vp_stretch_id == -1 && vp_disch_id != -1)
sprintf(h_where_clause,"WHERE DISCH_ID = %ld ", vp_disch_id);
else
strcpy(h_where_clause,"");
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the catchment details from DISCH_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT DISCH_ID,"
"STRETCH_ID,"
"CATCH_ID,"
"NAME,"
"POP,"
"PAVED_SURFACE,"
"ROOF,"
"ROOF_INDUST,"
"STREET,"
"SRT,"
"FLOW_VAL,"
"FLOW_DIST,"
"MLSS,"
"VOL_VK,"
"VOL_BB,"
"F_MIX,"
"TYPE,"
"VOL_SEWER,"
"REMARK "
"FROM DISCH_TAB "
"%s "
"ORDER BY DISCH_ID, STRETCH_ID, CATCH_ID", h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE disch_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN disch_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH disch_csr INTO :h_disch INDICATOR :h_ind_disch;
/* check indicator variables (in regard to NULL values) */
if (h_ind_disch.disch_id == -1) h_disch.disch_id = -1;
if (h_ind_disch.stretch_id == -1) h_disch.stretch_id = -1;
if (h_ind_disch.catch_id == -1) h_disch.catch_id = -1;
if (h_ind_disch.name == -1) strcpy(h_disch.name, "");
if (h_ind_disch.pop == -1) strcpy(h_disch.pop, "");
if (h_ind_disch.paved_surface == -1) strcpy(h_disch.paved_surface, "");
if (h_ind_disch.roof == -1) strcpy(h_disch.roof, "");
if (h_ind_disch.roof_indust == -1) strcpy(h_disch.roof_indust,"");
if (h_ind_disch.street == -1) strcpy(h_disch.street, "");
if (h_ind_disch.srt == -1) strcpy(h_disch.srt, "");
if (h_ind_disch.flow_val == -1) strcpy(h_disch.flow_val, "");
if (h_ind_disch.flow_dist == -1) strcpy(h_disch.flow_dist, "");
if (h_ind_disch.mlss == -1) strcpy(h_disch.mlss, "");
if (h_ind_disch.vol_vk == -1) strcpy(h_disch.vol_vk, "");
if (h_ind_disch.vol_bb == -1) strcpy(h_disch.vol_bb, "");
if (h_ind_disch.f_mix == -1) strcpy(h_disch.f_mix, "");
if (h_ind_disch.type == -1) strcpy(h_disch.type, "");
if (h_ind_disch.vol_sewer == -1) strcpy(h_disch.vol_sewer, "");
if (h_ind_disch.remark == -1) strcpy(h_disch.remark, "");
/* copy result into temp. buffer */
v_disch_buf.disch_id = h_disch.disch_id;
v_disch_buf.stretch_id = h_disch.stretch_id;
v_disch_buf.catch_id = h_disch.catch_id;
strcpy(v_disch_buf.name , h_disch.name);
strcpy(v_disch_buf.pop , h_disch.pop);
strcpy(v_disch_buf.paved_surface , h_disch.paved_surface);
strcpy(v_disch_buf.roof , h_disch.roof);
strcpy(v_disch_buf.roof_indust , h_disch.roof_indust);
strcpy(v_disch_buf.street , h_disch.street);
strcpy(v_disch_buf.srt , h_disch.srt);
strcpy(v_disch_buf.flow_val , h_disch.flow_val);
strcpy(v_disch_buf.flow_dist , h_disch.flow_dist);
strcpy(v_disch_buf.mlss , h_disch.mlss);
strcpy(v_disch_buf.vol_vk , h_disch.vol_vk);
strcpy(v_disch_buf.vol_bb , h_disch.vol_bb);
strcpy(v_disch_buf.f_mix , h_disch.f_mix);
strcpy(v_disch_buf.type , h_disch.type);
strcpy(v_disch_buf.vol_sewer , h_disch.vol_sewer);
strcpy(v_disch_buf.remark , h_disch.remark);
v_disch_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_DISCH_TAB, (void*) &v_disch_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_disch*) malloc( sizeof(DA_T_disch) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param,"%s - malloc(DA_T_disch)", v_module);
gda_free_disch(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_disch) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_disch_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE disch_csr;
/* return created result list */
(*vp_disch) = v_root_lst_ptr;
/* success fully connected to database */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE disch_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_disch (DISCH_TAB)
*
* Issue : 02-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_disch()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_stretch (i) pointer to "list of" disch records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_disch()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 02-AUG-2002
\param vp_catch pointer to "list of" disch records
\return ---
*/
void gda_free_disch(DA_T_disch *vp_disch)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_disch";
#endif
/* pointer to list elements */
DA_T_disch *v_next_elem_ptr = NULL;
DA_T_disch *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_disch;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/*********************************************************************
* Name : gda_insert_disch (DISCH_TAB)
*
* Issue : 19-MAY-2003 - S.F. - TechniData AG/Markdorf
*
* Purpose : - Insert record into DISCH_TAB. There is no new DISCH_ID
* returned, because DISCH_ID is stored as given by
* input parameter (due to catchment preprocessing).
*
* - Before INSERT is done
* a) check by CATCH_ID if master record in table CATCH_TAB
* exists. In case not -> cancel insert!
* b) check by STRETCH_ID if referenced record in table
* STRETCH_TAB exists. In case not -> cancel insert!
*
* - Update "MOD_DATE" in master record (CATCH_TAB) by CURRENT_TIMESTAMP
*
*
* Parameter: vp_disch (i/o) data to insert into DISCH_TAB,
* Attention:
* disch_id is not set by sequence,
* but as given by input data !
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into DISCH_TAB.
There is no new DISCH_ID returned, because DISCH_ID is stored as given by input parameter (due to catchment preprocessing).
Before Insert is done:
check by CATCH_ID if master record in table CATCH_TAB exists. In case not -> cancel insert!
check by STRETCH_ID if referenced record in table STRETCH_TAB exists. In case not -> cancel insert!
Update "MOD_DATE" in master record (CATCH_TAB) by CURRENT_TIMESTAMP.
Output:
vp_errinfo - Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 02-AUG-2002
\param db_con Pointer to connection
\param vp_disch data to insert into DISCH_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_disch (DB_con *db_con,
DA_T_disch *vp_disch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_disch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_master_chk = DA_FAIL;
char v_errmsg[256];
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_catch_id_qry;
char h_fmt_date[30];
char h_con_name[31];
struct DA_T_disch_pg_h{ /* type contains host variables for object data */
long disch_id;
long stretch_id;
long catch_id;
char name [256];
char pop [ 41];
char paved_surface[41];
char roof [ 41];
char roof_indust[ 41];
char street [ 41];
char srt [ 41];
char flow_val [256];
char flow_dist [ 12];
char mlss [ 41];
char vol_vk [ 41];
char vol_bb [ 41];
char f_mix [ 41];
char type [ 41];
char vol_sewer [ 41];
char remark [2001];
}h_disch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set date format mask */
strcpy(h_fmt_date, DA_FMT_date);
/* ------------------ *
* PRE-CHECKS
* ------------------ */
v_master_chk = lgda_chk_disch_master(vp_disch->catch_id,
vp_disch->stretch_id,
vp_errinfo);
if (v_master_chk != DA_SUCCESS)
{
/* error during check of master record */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_DISCH_TAB, (void*) vp_disch,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
errln = 50;
h_disch.disch_id = vp_disch->disch_id;
h_disch.stretch_id = vp_disch->stretch_id;
h_disch.catch_id = vp_disch->catch_id;
strcpy(h_disch.name , vp_disch->name);
strcpy(h_disch.pop , vp_disch->pop);
strcpy(h_disch.paved_surface , vp_disch->paved_surface);
strcpy(h_disch.roof , vp_disch->roof);
strcpy(h_disch.roof_indust , vp_disch->roof_indust);
strcpy(h_disch.street , vp_disch->street);
strcpy(h_disch.srt , vp_disch->srt);
strcpy(h_disch.flow_val , vp_disch->flow_val);
strcpy(h_disch.flow_dist , vp_disch->flow_dist);
strcpy(h_disch.mlss , vp_disch->mlss);
strcpy(h_disch.vol_vk , vp_disch->vol_vk);
strcpy(h_disch.vol_bb , vp_disch->vol_bb);
strcpy(h_disch.f_mix , vp_disch->f_mix);
strcpy(h_disch.type , vp_disch->type);
strcpy(h_disch.vol_sewer , vp_disch->vol_sewer);
strcpy(h_disch.remark , vp_disch->remark);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* Insert passed record */
errln = 60;
EXEC SQL INSERT INTO DISCH_TAB ( DISCH_ID,
STRETCH_ID,
CATCH_ID,
NAME,
POP,
PAVED_SURFACE,
ROOF,
ROOF_INDUST,
STREET,
SRT,
FLOW_VAL,
FLOW_DIST,
MLSS,
VOL_VK,
VOL_BB,
F_MIX,
TYPE,
VOL_SEWER,
REMARK )
VALUES (:h_disch.disch_id,
:h_disch.stretch_id,
:h_disch.catch_id,
:h_disch.name,
:h_disch.pop,
:h_disch.paved_surface,
:h_disch.roof,
:h_disch.roof_indust,
:h_disch.street,
:h_disch.srt,
:h_disch.flow_val,
:h_disch.flow_dist,
:h_disch.mlss,
:h_disch.vol_vk,
:h_disch.vol_bb,
:h_disch.f_mix,
:h_disch.type,
:h_disch.vol_sewer,
:h_disch.remark
);
/* Update MOD_DATE in master (CATCH_TAB) */
h_catch_id_qry = vp_disch->catch_id;
errln = 70;
EXEC SQL UPDATE CATCH_TAB
SET MOD_DATE = to_timestamp(to_char(CURRENT_TIMESTAMP, :h_fmt_date), :h_fmt_date)
WHERE CATCH_ID = :h_catch_id_qry;
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_disch (DISCH_TAB)
*
* Issue : 14-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by DISCH_ID) in DISCH_TAB
* by data of passed record.
*
* Parameter: vp_catch_id(i) CATCH_ID of record to update
* vp_disch (i) new disch data, containing DISCH_ID of
* record to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by DISCH_ID) in DISCH_TAB by data of passed record.
Output:
vp_errinfo - error information in case error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 14-OCT-2002
\param db_con Pointer to connection
\param vp_catch_id CATCH_ID of record to update
\param vp_disch new disch data, containing DISCH_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_disch ( DB_con *db_con,
long vp_catch_id,
DA_T_disch vp_disch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_disch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
// not used: DA_T_disch v_disch_buf;
long v_catch_id_new;
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
struct DA_T_disch_pg_h{ /* type contains host variables for object data */
long disch_id;
long stretch_id;
long catch_id;
char name [256];
char pop [ 41];
char paved_surface[41];
char roof [ 41];
char roof_indust[ 41];
char street [ 41];
char srt [ 41];
char flow_val [256];
char flow_dist [ 12];
char mlss [ 41];
char vol_vk [ 41];
char vol_bb [ 41];
char f_mix [ 41];
char type [ 41];
char vol_sewer [ 41];
char remark [2001];
}h_disch;
long h_catch_id_qry;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set old catch_id for getting access right */
v_catch_id_new = vp_disch.catch_id;
vp_disch.catch_id = h_catch_id_qry;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_DISCH_TAB, (void*) &vp_disch,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_disch.disch_id = vp_disch.disch_id;
h_disch.stretch_id = vp_disch.stretch_id;
h_disch.catch_id = v_catch_id_new;
h_catch_id_qry = vp_catch_id;
strcpy (h_disch.name , vp_disch.name);
strcpy (h_disch.pop , vp_disch.pop);
strcpy (h_disch.paved_surface, vp_disch.paved_surface);
strcpy (h_disch.roof , vp_disch.roof);
strcpy (h_disch.roof_indust, vp_disch.roof_indust);
strcpy (h_disch.street , vp_disch.street);
strcpy (h_disch.srt , vp_disch.srt);
strcpy (h_disch.flow_val , vp_disch.flow_val);
strcpy (h_disch.flow_dist , vp_disch.flow_dist);
strcpy (h_disch.mlss , vp_disch.mlss);
strcpy (h_disch.vol_vk , vp_disch.vol_vk);
strcpy (h_disch.vol_bb , vp_disch.vol_bb);
strcpy (h_disch.f_mix , vp_disch.f_mix);
strcpy (h_disch.type , vp_disch.type);
strcpy (h_disch.vol_sewer , vp_disch.vol_sewer);
strcpy (h_disch.remark , vp_disch.remark);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
errln = 20;
EXEC SQL UPDATE DISCH_TAB
SET STRETCH_ID = :h_disch.stretch_id,
CATCH_ID = :h_disch.catch_id,
NAME = :h_disch.name,
POP = :h_disch.pop,
PAVED_SURFACE = :h_disch.paved_surface,
ROOF = :h_disch.roof,
ROOF_INDUST = :h_disch.roof_indust,
STREET = :h_disch.street,
SRT = :h_disch.srt,
FLOW_VAL = :h_disch.flow_val,
FLOW_DIST = :h_disch.flow_dist,
MLSS = :h_disch.mlss,
VOL_BB = :h_disch.vol_bb,
F_MIX = :h_disch.f_mix,
TYPE = :h_disch.type,
VOL_SEWER = :h_disch.vol_sewer,
REMARK = :h_disch.remark
WHERE CATCH_ID = :h_catch_id_qry
AND DISCH_ID = :h_disch.disch_id;
/* update mod_date of master record */
errln = 30;
EXEC SQL UPDATE CATCH_TAB
SET MOD_DATE = CURRENT_TIMESTAMP
WHERE CATCH_ID = :h_disch.catch_id;
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record snot updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_disch (DISCH_TAB)
*
* Issue : 14-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Delete record from DISCH_TAB specified by DISCH_ID
* and CATCH_ID.
*
* Parameter: vp_catch_id (i) CATCH_ID of record to delete
* vp_disch_id (i) DISCH_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from DISCH_TAB specified by DISCH_ID and CATCH_ID.
Output:
vp_errinfo - Error information in case error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 14-OCT-2003
\param db_con Pointer to connection
\param vp_catch_id CATCH_ID of record to delete
\param vp_disch_id DISCH_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_disch ( DB_con *db_con,
long vp_catch_id,
long vp_disch_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_delete_disch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
DA_T_disch v_disch_buf;
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
struct DA_T_disch_pg_h{ /* type contains host variables for object data */
long disch_id;
long stretch_id;
long catch_id;
char name [256];
char pop [ 41];
char paved_surface[41];
char roof [ 41];
char roof_indust[ 41];
char street [ 41];
char srt [ 41];
char flow_val [256];
char flow_dist [ 12];
char mlss [ 41];
char vol_vk [ 41];
char vol_bb [ 41];
char f_mix [ 41];
char type [ 41];
char vol_sewer [ 41];
char remark [2001];
}h_disch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* copy catch_id into temp. buffer */
v_disch_buf.catch_id = vp_catch_id;
v_disch_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_DISCH_TAB, (void*) &v_disch_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
h_disch.disch_id = vp_disch_id;
h_disch.catch_id = vp_catch_id;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* delete specified record */
errln = 10;
EXEC SQL DELETE FROM DISCH_TAB
WHERE CATCH_ID = :h_disch.catch_id
AND DISCH_ID = :h_disch.disch_id;
/* update mod_date of master record */
errln = 20;
EXEC SQL UPDATE CATCH_TAB
SET MOD_DATE = CURRENT_TIMESTAMP
WHERE CATCH_ID = :h_disch.catch_id;
/* record successfully deleted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not deleted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: BACKGRD_JOIN_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_backgrd (BACKGRD_JOIN_TAB)
*
* Issue : 02-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of background object id's
*
* Query conditions:
* a) catch_id > -1; return: 1..n records
* b)
*
* Parameter: vp_catch_id (i) ID of catchment for which background
* object information shall be selected
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of background object id's.
Query conditions:
catch_id > -1; return: 1..n records
Output:
vp_errinfo - Error info in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 02-AUG-2002
\param db_con Pointer to connection
\param vp_catch_id ID of catchment for which background object information shall be selected
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_backgrd (DB_con *db_con,
long vp_catch_id,
DA_T_backgrd **vp_backgrd,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_backgrd";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_backgrd v_backgrd_buf;
/* pointer to list root, list elements */
DA_T_backgrd *v_root_lst_ptr = NULL;
DA_T_backgrd *v_new_elem_ptr = NULL;
DA_T_backgrd *v_last_elem_ptr = NULL;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
char h_query[2000];
char h_where_clause[100];
struct DA_T_backgrd_pg_h{ /* type contains host variables for object data */
long catch_id;
long bin_obj_id;
char bin_obj_user_id[31];
long bin_obj_privs;
} h_backgrd;
struct DA_T_backgrd_pg_i{ /* indicator variables for host variable struct */
short int catch_id;
short int bin_obj_id;
short int bin_obj_user_id;
short int bin_obj_privs;
} h_ind_backgrd;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* determine query condition
* a) catch_id > -1; return: 1..n records
* b)
*/
if (vp_catch_id > -1)
sprintf(h_where_clause,"WHERE J.CATCH_ID = %ld AND B.BIN_OBJ_ID = J.BIN_OBJ_ID", vp_catch_id);
else
strcpy(h_where_clause,"WHERE B.BIN_OBJ_ID = J.BIN_OBJ_ID");
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the catchment details from BACKGRD_JOIN_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT J.CATCH_ID,"
"J.BIN_OBJ_ID,"
"B.USER_ID,"
"B.PRIVS "
"FROM BIN_OBJ_TAB B,"
"BACKGRD_JOIN_TAB J "
"%s "
"ORDER BY J.CATCH_ID, J.BIN_OBJ_ID", h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE backgrd_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN backgrd_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH backgrd_csr INTO :h_backgrd INDICATOR :h_ind_backgrd;
/* check indicator variables (in regard to NULL values) */
if (h_ind_backgrd.catch_id == -1) h_backgrd.catch_id = -1;
if (h_ind_backgrd.bin_obj_id == -1) h_backgrd.bin_obj_id = -1;
if (h_ind_backgrd.bin_obj_privs == -1) h_backgrd.bin_obj_id = 1;
if (h_ind_backgrd.bin_obj_user_id == -1) strcpy(h_backgrd.bin_obj_user_id, "");
/* copy result into temp. buffer */
v_backgrd_buf.catch_id = h_backgrd.catch_id;
v_backgrd_buf.bin_obj_id = h_backgrd.bin_obj_id;
v_backgrd_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_BACKGRD_TAB, (void*) &h_backgrd,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_backgrd*) malloc( sizeof(DA_T_backgrd) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param,"%s - malloc(DA_T_backgrd)", v_module);
gda_free_backgrd(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_backgrd) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_backgrd_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE backgrd_csr;
/* return created result list */
(*vp_backgrd) = v_root_lst_ptr;
/* success fully connected to database */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE backgrd_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_backgrd (BACKGRD_JOIN_TAB)
*
* Issue : 15-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Insert record into BACKGRD_JOIN_TAB.
*
* Parameter: vp_backgrd (i) data to insert into BACKGRD_JOIN_TAB
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into BACKGRD_JOIN_TAB.
Output:
vp_errinfo - error information in case error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 15-OCT-2002
\param db_con Pointer to connection
\param vp_backgrd data to insert into BACKGRD_JOIN_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_backgrd (DB_con *db_con, DA_T_backgrd vp_backgrd,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_backgrd";
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
struct DA_T_backgrd_pg_h{ /* type contains host variables for object data */
long catch_id;
long bin_obj_id;
char bin_obj_user_id[31];
long bin_obj_privs;
} h_backgrd;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* copy passed record into host variable
*/
h_backgrd.catch_id = vp_backgrd.catch_id;
h_backgrd.bin_obj_id = vp_backgrd.bin_obj_id;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* Insert passed record */
errln = 20;
EXEC SQL INSERT INTO BACKGRD_JOIN_TAB
VALUES (:h_backgrd.catch_id,
:h_backgrd.bin_obj_id);
/* record successfully inserted */
return(DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_backgrd (BACKGRD_JOIN_TAB)
*
* Issue : 16-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by vp_backgrd_old) in
* BACKGRD_JOIN_TAB by data of passed record.
*
* Parameter: vp_backgrd_old(i) background data to update
* vp_backgrd (i) new background data
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by vp_backgrd_old) in BACKGRD_JOIN_TAB by data of passed record.
Output:
vp_errinfo - error information in case error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 16-OCT-2002
\param db_con Pointer to connection
\param vp_backgrd_old background data to update
\param vp_backgrd new background data
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_backgrd (DB_con *db_con,
DA_T_backgrd vp_backgrd_old,
DA_T_backgrd vp_backgrd,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_backgrd";
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
struct DA_T_backgrd_pg_h{ /* type contains host variables for object data */
long catch_id;
long bin_obj_id;
char bin_obj_user_id[31];
long bin_obj_privs;
} h_backgrd, h_backgrd_old;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* copy passed record into host variable
*/
h_backgrd_old.catch_id = vp_backgrd_old.catch_id;
h_backgrd_old.bin_obj_id = vp_backgrd_old.bin_obj_id;
/*
* copy passed record into host variable
*/
h_backgrd.catch_id = vp_backgrd.catch_id;
h_backgrd.bin_obj_id = vp_backgrd.bin_obj_id;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
errln = 20;
EXEC SQL UPDATE BACKGRD_JOIN_TAB
SET CATCH_ID = :h_backgrd.catch_id,
BIN_OBJ_ID = :h_backgrd.bin_obj_id
WHERE CATCH_ID = :h_backgrd_old.catch_id
AND BIN_OBJ_ID = :h_backgrd_old.bin_obj_id;
/* record successfully updated */
return(DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_backgrd (BACKGRD_JOIN_TAB)
*
* Issue : 16-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Delete record from BACKGRD_JOIN_TAB.
*
* Parameter: vp_backgrd (i) data of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from BACKGRD_JOIN_TAB.
calls gda_delete_backgrd.
Output:
vp_errinfo - Error information in case error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 16-OCT-2002
\param db_con Pointer to connection
\param vp_backgrd data of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_backgrd(DB_con *db_con,
DA_T_backgrd vp_backgrd,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_delete_backgrd";
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
struct DA_T_backgrd_pg_h{ /* type contains host variables for object data */
long catch_id;
long bin_obj_id;
char bin_obj_user_id[31];
long bin_obj_privs;
} h_backgrd;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* copy passed record into host variable
*/
h_backgrd.catch_id = vp_backgrd.catch_id;
h_backgrd.bin_obj_id = vp_backgrd.bin_obj_id;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* delete specified record */
errln = 10;
EXEC SQL DELETE FROM BACKGRD_JOIN_TAB
WHERE CATCH_ID = :h_backgrd.catch_id
AND BIN_OBJ_ID = :h_backgrd.bin_obj_id;
/* record successfully deleted */
return(DA_SUCCESS);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_backgrd (BACKGRD_JOIN_TAB)
*
* Issue : 02-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_backgrd()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_backgrd_id (i) pointer to "list of" backgrd. obj.
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_backgrd()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 02-AUG-2002
\param vp_backgrd data of record to delete
\return ---
*/
void gda_free_backgrd(DA_T_backgrd *vp_backgrd)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_backgrd";
#endif
/* pointer to list elements */
DA_T_backgrd *v_next_elem_ptr = NULL;
DA_T_backgrd *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_backgrd;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: BIN_OBJ_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_bin_obj (BIN_OBJ_TAB)
*
* Issue : 18-JUL-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of binary objects (BLOB) from BIN_OBJ_TAB
* incl. BLOB values for specified input parameters
* (bin_obj_id and object_id)
*
* Query conditions:
* a) bin_obj_id> 0, object_id=-1 => return: 1 record
* b) bin_obj_id=-1, object_id> 0 => return: 1..n records
* c) bin_obj_id=-1, object_id=-1, vp_object_type="BACKGROUND"
* => return: all background binary objects
* d) bin_obj_id=-1, object_id=-1, vp_object_type="%"
* => return: all binary objects
*
* Parameter: vp_object_id (i) ID of object(s) to select
* vp_object_type (i) Type of object(s) to select
* vp_bin_obj_id (i) Unique ID of object to select
* vp_bin_obj_file (o) Return value (list of bin. objects)
* vp_errinfo (o) Error info in case of error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of binary objects (BLOB) from BIN_OBJ_TAB.
Get list of binary objects (BLOB) from BIN_OBJ_TAB incl. BLOB values for specified input parameters (bin_obj_id and object_id)
Query conditions:
bin_obj_id> 0, object_id=-1 => return: 1 record
bin_obj_id=-1, object_id> 0 => return: 1..n records
bin_obj_id=-1, object_id=-1, vp_object_type="BACKGROUND" => return: all background binary objects
bin_obj_id=-1, object_id=-1, vp_object_type="%" => return: all binary objects
Output:
vp_bin_obj - Return value (list of bin. objects)
vp_errinfo - Error information in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 18-JUL-2002
\param db_con Pointer to connection
\param vp_object_id ID of object(s) to select
\param vp_object_type Type of object(s) to select
\param vp_bin_obj_id Unique ID of object to select
\param vp_get_file_obj DA_YES \n DA_NO
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_bin_obj (DB_con *db_con,
long vp_object_id,
char *vp_object_type,
long vp_bin_obj_id,
char vp_get_file_obj,
DA_T_bin_obj **vp_bin_obj,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_bin_obj";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int fd;
char *v_file_obj_ptr = NULL;
// not used: unsigned int v_file_obj_size = 0;
Oid lobjOid;
PGconn *connection;
PGresult *res;
/* temp. buffer */
DA_T_bin_obj v_bin_obj_buf;
/* pointer to list root */
DA_T_bin_obj *v_root_lst_ptr = NULL;
/* pointer to list element */
DA_T_bin_obj *v_new_elem_ptr = NULL;
DA_T_bin_obj *v_last_elem_ptr = NULL;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_query[2000];
char h_fmt_date[30];
char h_con_name[31];
long h_oid;
char h_where_clause[100];
struct DA_T_bin_obj_pg_h{ /* type contains host variables for object data */
long bin_obj_id;
long object_id;
char name [256];
char user_id [ 31];
int privs;
char obj_type [ 31];
char obj_sub_type[ 31];
char file_type [ 4];
unsigned int file_size;
char remark[2001];
char cre_date[21];
char mod_date[21];
} h_bin_obj;
struct DA_T_bin_obj_pg_i{ /* indicator variables for host variable struct */
short int bin_obj_id;
short int object_id;
short int name;
short int user_id;
short int privs;
short int obj_type;
short int obj_sub_type;
short int file_type;
short int file_size;
short int remark;
short int cre_date;
short int mod_date;
} h_ind_bin_obj;
short int h_ind_oid;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the binary object details and oid representing a
* BLOB from BIN_OBJ_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*
* determine query condition
* a) bin_obj_id> 0, object_id=-1 => return: 1 record
* b) bin_obj_id=-1, object_id> 0 => return: 1..n records
*/
errln = 20;
if (vp_bin_obj_id > 0)
{
/* case a) */
sprintf(h_where_clause,"BIN_OBJ_ID = %ld AND OBJ_TYPE like '%s'", vp_bin_obj_id, vp_object_type);
}
else if (vp_object_id > 0)
{
/* case b) */
sprintf(h_where_clause,"OBJECT_ID = %ld AND OBJ_TYPE like '%s'", vp_object_id, vp_object_type);
}
else
{
/* case c) */
sprintf(h_where_clause,"OBJ_TYPE like '%s'", vp_object_type);
}
sprintf (h_query, "SELECT BIN_OBJ_ID, "
"OBJECT_ID, "
"NAME,"
"USER_ID,"
"PRIVS,"
"OBJ_TYPE,"
"OBJ_SUB_TYPE,"
"FILE_TYPE,"
"FILE_SIZE,"
"REMARK, "
"to_char(CRE_DATE, '%s'), "
"to_char(MOD_DATE, '%s'), "
"FILE_OBJ "
"FROM BIN_OBJ_TAB "
"WHERE %s",
h_fmt_date, h_fmt_date, h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
errln = 20;
EXEC SQL DECLARE bin_obj_csr CURSOR FOR get_state;
errln = 30;
EXEC SQL OPEN bin_obj_csr;
errln = 40;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 50;
EXEC SQL FETCH bin_obj_csr
INTO :h_bin_obj INDICATOR :h_ind_bin_obj,
:h_oid INDICATOR :h_ind_oid;
/* check indicator variables (in regard to NULL values) */
if (h_ind_bin_obj.bin_obj_id == -1) h_bin_obj.bin_obj_id = -1;
if (h_ind_bin_obj.object_id == -1) h_bin_obj.object_id = -1;
if (h_ind_bin_obj.file_size == -1) h_bin_obj.file_size = -1;
if (h_ind_bin_obj.privs == -1) h_bin_obj.privs = 1;
if (h_ind_bin_obj.name == -1) strcpy(h_bin_obj.name, "");
if (h_ind_bin_obj.user_id == -1) strcpy(h_bin_obj.user_id, "");
if (h_ind_bin_obj.obj_type == -1) strcpy(h_bin_obj.obj_type, "");
if (h_ind_bin_obj.obj_sub_type == -1) strcpy(h_bin_obj.obj_sub_type,"");
if (h_ind_bin_obj.file_type == -1) strcpy(h_bin_obj.file_type, "");
if (h_ind_bin_obj.remark == -1) strcpy(h_bin_obj.remark, "");
if (h_ind_bin_obj.cre_date == -1) strcpy(h_bin_obj.cre_date, "");
if (h_ind_bin_obj.mod_date == -1) strcpy(h_bin_obj.mod_date, "");
/* copy result into temp. buffer */
v_bin_obj_buf.bin_obj_id = h_bin_obj.bin_obj_id;
v_bin_obj_buf.object_id = h_bin_obj.object_id;
v_bin_obj_buf.file_size = h_bin_obj.file_size;
v_bin_obj_buf.privs = h_bin_obj.privs;
strcpy(v_bin_obj_buf.name, h_bin_obj.name);
strcpy(v_bin_obj_buf.user_id, h_bin_obj.user_id);
strcpy(v_bin_obj_buf.obj_type, h_bin_obj.obj_type);
strcpy(v_bin_obj_buf.obj_sub_type, h_bin_obj.obj_sub_type);
strcpy(v_bin_obj_buf.file_type, h_bin_obj.file_type);
strcpy(v_bin_obj_buf.remark, h_bin_obj.remark);
strcpy(v_bin_obj_buf.cre_date, h_bin_obj.cre_date);
strcpy(v_bin_obj_buf.mod_date, h_bin_obj.mod_date);
v_bin_obj_buf.file_obj = NULL;
v_bin_obj_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_BIN_OBJ_TAB, (void*) &v_bin_obj_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if ((h_ind_oid != -1) && (vp_get_file_obj == DA_YES))
{
connection = PQsetdbLogin(db_con->host, db_con->port, NULL, NULL, db_con->db_name, db_con->user_id, db_con->user_passwd);
if (PQstatus(connection) == CONNECTION_BAD)
{
PQfinish(connection);
v_status = DA_FAIL;
}
else
{
res = PQexec(connection, "begin");
PQclear(res);
/* load BLOB value from database */
lobjOid = h_oid;
fd = lo_open(connection, lobjOid, INV_READ);
v_file_obj_ptr = (char *) malloc((size_t) v_bin_obj_buf.file_size);
lo_read(connection, fd, v_file_obj_ptr, v_bin_obj_buf.file_size);
lo_close(connection, fd);
res = PQexec(connection, "end");
PQclear(res);
PQfinish(connection);
}
}
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_bin_obj*) malloc( sizeof(DA_T_bin_obj) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf (vp_errinfo->err_param,"%s - malloc(DA_T_bin_obj)", v_module);
/* release already allocated memory */
gda_free_bin_obj(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_bin_obj) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_access_right >= DA_A_VIEWEDIT)
strcpy(v_bin_obj_buf.write, "Y");
else
strcpy(v_bin_obj_buf.write, "N");
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_bin_obj_buf;
/* pass pointer + size to/of allocated memory for loaded BLOB */
v_new_elem_ptr->file_obj = v_file_obj_ptr;
if (vp_get_file_obj == DA_YES)
{
v_new_elem_ptr->file_size = v_bin_obj_buf.file_size;
}
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 60;
EXEC SQL CLOSE bin_obj_csr;
errln = 70;
/* return created result list */
(*vp_bin_obj) = v_root_lst_ptr;
/* success fully connected to database */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE bin_obj_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_get_bin_obj_search (BIN_OBJ_TAB, BIN_OBJ_SEARCH_TAB)
*
* Issue : 24-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Get list of binary objects from BIN_OBJ_TAB, filtered by
* various search parameters, without the BLOB itself.
* If a parameter is NULL ignore it in SELECT-statement
*
* Parameter: vp_name (i) Name of object(s) to select
* vp_object_sub_type (i) Subtype of object(s) to select
* vp_remark (i) Remark of object to select
* vp_user_id (i) User ID of object to select
* vp_file_type (i) File type of object to select
* vp_cre_date (i) Creation date of object to select
* vp_mod_date (i) Modification date of object to select
* vp_bin_obj (o) Return value (list of bin. obj. data)
* vp_errinfo (o) Error info in case of error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of binary objects from BIN_OBJ_TAB.
... filtered by various search parameters, without the BLOB itself. If a parameter is NULL ignore it in SELECT-statement.
Output:
vp_bin_obj - Return value (list of bin. objects)
vp_errinfo - Error information in case error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 24-OCT-2002
\param db_con Pointer to connection
\param vp_name Name of object(s) to select
\param vp_object_sub_type Subtype of object(s) to select
\param vp_remark Remark of object to select
\param vp_user_id User ID of object to select
\param vp_file_type File type of object to select
\param vp_cre_date Creation date of object to select
\param vp_mod_date Modification date of object to select
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_bin_obj_search (DB_con *db_con,
char *vp_name,
char *vp_obj_sub_type,
char *vp_remark,
char *vp_user_id,
char *vp_file_type,
char *vp_cre_date,
char *vp_mod_date,
DA_T_bin_obj **vp_bin_obj,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_bin_obj_search";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
char v_name[256];
char v_obj_sub_type[31];
char v_remark[2002];
char v_user_id[31];
char v_file_type[4];
char v_cre_date[21];
char v_mod_date[21];
char v_date_operator[3] = "";
char v_buffer[6000];
int v_string_pos;
/* used for parsing of remark-field*/
int v_keyword_count = 0;
char v_remark_word[2002];
/* temp. buffer */
DA_T_bin_obj v_bin_obj_buf;
/* pointer to list root */
DA_T_bin_obj *v_root_lst_ptr = NULL;
/* pointer to list element */
DA_T_bin_obj *v_new_elem_ptr = NULL;
DA_T_bin_obj *v_last_elem_ptr = NULL;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
struct DA_T_bin_obj_pg_h{ /* type contains host variables for object data */
long bin_obj_id;
long object_id;
char name [256];
char user_id [ 31];
int privs;
char obj_type [ 31];
char obj_sub_type[ 31];
char file_type [ 4];
unsigned int file_size;
char remark[2001];
char cre_date[21];
char mod_date[21];
} h_bin_obj;
char h_con_name[31];
char h_fmt_date[30];
char h_query[6500];
/* indicator variables */
struct DA_T_bin_obj_pg_i{ /* indicator variables for host variable struct */
short int bin_obj_id;
short int object_id;
short int name;
short int user_id;
short int privs;
short int obj_type;
short int obj_sub_type;
short int file_type;
short int file_size;
short int remark;
short int cre_date;
short int mod_date;
} h_ind_bin_obj;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy (v_name, vp_name);
strcpy (v_obj_sub_type, vp_obj_sub_type);
strcpy (v_remark, vp_remark);
strcpy (v_user_id, vp_user_id);
strcpy (v_file_type, vp_file_type);
/* replace all * with %
and all ' and ´ in name, object subtype, user id and file_type with _ */
while ((v_string_pos = strcspn (v_name, "*´'")) < strlen (v_name))
if (v_name[v_string_pos] == '*')
v_name[v_string_pos] = '%';
else
v_name[v_string_pos] = '_';
while ((v_string_pos = strcspn (v_obj_sub_type, "*´'")) < strlen (v_obj_sub_type))
if (v_obj_sub_type[v_string_pos] == '*')
v_obj_sub_type[v_string_pos] = '%';
else
v_obj_sub_type[v_string_pos] = '_';
while ((v_string_pos = strcspn (v_user_id, "*´'")) < strlen (v_user_id))
if (v_user_id[v_string_pos] == '*')
v_user_id[v_string_pos] = '%';
else
v_user_id[v_string_pos] = '_';
while ((v_string_pos = strcspn (v_file_type, "*´'")) < strlen (v_file_type))
if (v_file_type[v_string_pos] == '*')
v_file_type[v_string_pos] = '%';
else
v_file_type[v_string_pos] = '_';
while ((v_string_pos = strcspn (v_remark, "*")) < strlen (v_remark))
v_remark[v_string_pos] = '%';
/* remove all ', ´ and ` from remark */
while ((v_string_pos = strcspn (v_remark, "'´`")) < strlen (v_remark))
{
v_remark[v_string_pos] = '\0';
sprintf(v_remark, "%s%s", v_remark, v_remark + v_string_pos + 1);
}
/* set format mask for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* build SELECT-statement
*/
/* basic SELECT-statement */
sprintf (h_query, "SELECT B.BIN_OBJ_ID, "
"B.OBJECT_ID, "
"B.NAME,"
"B.USER_ID,"
"B.PRIVS,"
"B.OBJ_TYPE,"
"B.OBJ_SUB_TYPE,"
"B.FILE_TYPE,"
"B.FILE_SIZE,"
"B.REMARK, "
"to_char(B.CRE_DATE, '%s'),"
"to_char(B.MOD_DATE, '%s') "
"FROM BIN_OBJ_TAB B",
h_fmt_date, h_fmt_date);
/* Check all parameters, if they are NULL.
If not, add corresponding WHERE-clause to SELECT-statement */
/* obj_sub_type */
if (strcmp (v_obj_sub_type, "") != 0)
{
/* if obj_sub_type contains wildcards use "LIKE", else use "=" */
if (strcspn (v_obj_sub_type, "%_") < strlen (v_obj_sub_type))
{
sprintf (h_query, "%s AND UPPER(OBJ_SUB_TYPE) LIKE UPPER('%s')",
h_query, v_obj_sub_type);
}
else
sprintf (h_query, "%s AND UPPER(OBJ_SUB_TYPE) = UPPER('%s')",
h_query, v_obj_sub_type);
}
else
{
/* <<< ERROR: OBJ_SUB_TYPE must not be empty >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_NO_OBJ_SUB_TYPE;
sprintf (vp_errinfo->err_param,"%s", v_module);
return DA_FAIL;
}
/* name */
if (strcmp (v_name, "") != 0)
{
/* if name contains wildcards use "LIKE", else use "=" */
if (strcspn (v_name, "%_") < strlen (v_name))
{
sprintf (h_query, "%s AND UPPER(NAME) LIKE UPPER('%s')",
h_query, v_name);
}
else
sprintf (h_query, "%s AND UPPER(NAME) = UPPER('%s')",
h_query, v_name);
}
/* obj_sub_type */
if (strcmp (v_obj_sub_type, "") != 0)
{
/* if obj_sub_type contains wildcards use "LIKE", else use "=" */
if (strcspn (v_obj_sub_type, "%_") < strlen (v_obj_sub_type))
{
sprintf (h_query, "%s AND UPPER(OBJ_SUB_TYPE) LIKE UPPER('%s')",
h_query, v_obj_sub_type);
}
else
sprintf (h_query, "%s AND UPPER(OBJ_SUB_TYPE) = UPPER('%s')",
h_query, v_obj_sub_type);
}
/* user_id */
if (strcmp (v_user_id, "") != 0)
{
/* if user_id contains wildcards use "LIKE", else use "=" */
if (strcspn (v_user_id, "%_") < strlen (v_user_id))
{
sprintf (h_query, "%s AND UPPER(USER_ID) LIKE UPPER('%s')",
h_query, v_user_id);
}
else
sprintf (h_query, "%s AND UPPER(USER_ID) = UPPER('%s')",
h_query, v_user_id);
}
/* file_type */
if (strcmp (v_file_type, "") != 0)
{
/* if file_type contains wildcards use "LIKE", else use "=" */
if (strcspn (v_file_type, "%_") < strlen (v_file_type))
{
sprintf (h_query, "%s AND UPPER(FILE_TYPE) LIKE UPPER('%s')",
h_query, v_file_type);
}
else
sprintf (h_query, "%s AND UPPER(FILE_TYPE) = UPPER('%s')",
h_query, v_file_type);
}
/* cre_date */
if (strcmp (vp_cre_date, "") != 0)
{
/* parse cre_date in search of logical operator */
v_string_pos = -1;
while ((v_string_pos = strcspn (vp_cre_date + v_string_pos + 1, "<>=") + v_string_pos + 1) < strlen (vp_cre_date))
{
if (strlen (v_date_operator) == 2)
{
/* <<< ERROR: too many operators before date >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_DATE_OP;
sprintf (vp_errinfo->err_param,"%s", v_module);
return (DA_FAIL);
}
else
{
v_date_operator[strlen (v_date_operator) + 1] = '\0';
v_date_operator[strlen (v_date_operator)] = vp_cre_date[v_string_pos];
}
}
/* if no operator is specified = is used */
if (strlen (v_date_operator) == 0)
strcpy (v_date_operator, "=");
/* store the date part from vp_cre_date in v_cre_date */
strcpy (v_cre_date, vp_cre_date + strlen (vp_cre_date) - 10);
sprintf (h_query, "%s AND CRE_DATE %s to_date('%s', '%s')",
h_query, v_date_operator, v_cre_date, h_fmt_date);
strcpy (v_date_operator, "");
}
/* mod_date */
if (strcmp (vp_mod_date, "") != 0)
{
/* parse mod_date in search of logical operator */
v_string_pos = -1;
while ((v_string_pos = strcspn (vp_mod_date + v_string_pos + 1, "<>=") + v_string_pos + 1) < strlen (vp_mod_date))
{
if (strlen (v_date_operator) == 2)
{
/* <<< ERROR: too many operators before date >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_DATE_OP;
sprintf (vp_errinfo->err_param,"%s", v_module);
return (DA_FAIL);
}
else
{
v_date_operator[strlen (v_date_operator) + 1] = '\0';
v_date_operator[strlen (v_date_operator)] = vp_mod_date[v_string_pos];
}
}
/* if no operator is specified = is used */
if (strlen (v_date_operator) == 0)
strcpy (v_date_operator, "=");
/* store the date part from vp_mod_date in v_mod_date */
strcpy (v_mod_date, vp_mod_date + strlen (vp_mod_date) - 10);
sprintf (h_query, "%s AND MOD_DATE %s to_date('%s', '%s')",
h_query, v_date_operator, v_mod_date, h_fmt_date);
}
/* separate the keywords in v_remark and add corresponding
Sub-Selections to SELECT-statement, maximal 10 keywords are parsed */
/* A semikolon is placed at the end of the last keyword */
sprintf(v_remark, "%s;", v_remark);
/* parse the string in search of delimiters, until its end is reached
or 10 keywords have been found*/
while (strlen(v_remark) > 0 && v_keyword_count < 10)
{
v_string_pos = strcspn (v_remark, " ,.;:");
/* if delimiter is not a the beginning of the string, get first keyword */
if (v_string_pos != 0)
{
v_keyword_count +=1;
/* place string termination after first keyword in string*/
v_remark[v_string_pos] = '\0';
/* add clause containing first keyword in string to SELECT-statement.
If keyword contains wildcards use "LIKE", else use "=" */
if (strcspn (v_remark, "%") < strlen (v_remark))
{
/* use '*' as escape character to prevent '_' from being used as a
wildcard */
strcpy(v_remark_word, v_remark);
for (v_string_pos=0; v_string_pos= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_bin_obj*) malloc( sizeof(DA_T_bin_obj) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf (vp_errinfo->err_param,"%s - malloc(DA_T_bin_obj)", v_module);
/* release already allocated memory */
gda_free_bin_obj(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_bin_obj) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
v_new_elem_ptr->bin_obj_id = h_bin_obj.bin_obj_id;
v_new_elem_ptr->object_id = h_bin_obj.object_id;
v_new_elem_ptr->file_size = h_bin_obj.file_size;
v_new_elem_ptr->privs = h_bin_obj.privs;
strcpy(v_new_elem_ptr->name, h_bin_obj.name);
strcpy(v_new_elem_ptr->user_id, h_bin_obj.user_id);
strcpy(v_new_elem_ptr->obj_type, h_bin_obj.obj_type);
strcpy(v_new_elem_ptr->obj_sub_type, h_bin_obj.obj_sub_type);
strcpy(v_new_elem_ptr->file_type, h_bin_obj.file_type);
strcpy(v_new_elem_ptr->remark, h_bin_obj.remark);
strcpy(v_new_elem_ptr->cre_date, h_bin_obj.cre_date);
strcpy(v_new_elem_ptr->mod_date, h_bin_obj.mod_date);
/* set WRITE according to current user's access right */
if (v_access_right >= DA_A_VIEWEDIT)
v_new_elem_ptr->write[0] = DA_YES;
else
v_new_elem_ptr->write[0] = DA_NO;
v_new_elem_ptr->write[1] = '\0';
/* function does not return the file object itself */
v_new_elem_ptr->file_obj = NULL;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 60;
EXEC SQL CLOSE bin_obj_search_csr;
/* return created result list */
(*vp_bin_obj) = v_root_lst_ptr;
/* success fully connected to database */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE bin_obj_search_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_bin_obj (BIN_OBJ_TAB)
*
* Issue : 18-JUL-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Insert record into BIN_OBJ_TAB. Return new ID "BIN_OBJ_ID"
* in passed struct, in case for insert could successfully
* be done
*
* Parameter: vp_bin_obj (i/o) data to insert into BIN_OBJ_TAB,
* OUTPUT:
* - bin_obj_id = BIN_OBJ_SEQ.NEXTVAL
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
* vg_db_user_info(i) -> general information about database
* user of current db-session
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into BIN_OBJ_TAB.
Return new ID "BIN_OBJ_ID" in passed struct, in case for insert could successfully be done.
Output:
vp_bin_obj - bin_obj_id
vp_errinfo - Error information in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 18-JUL-2002
\param db_con Pointer to connection
\param vp_bin_obj data to insert into BIN_OBJ_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_bin_obj(DB_con *db_con,
DA_T_bin_obj *vp_bin_obj,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_bin_obj";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
unsigned int v_file_obj_size ;
int fd;
Oid lobjOid;
PGconn *connection;
PGresult *res = NULL;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_bin_obj_id_new;
struct DA_T_bin_obj_pg_h{ /* type contains host variables for object data */
long bin_obj_id;
long object_id;
char name [256];
char user_id [ 31];
int privs;
char obj_type [ 31];
char obj_sub_type[ 31];
char file_type [ 4];
unsigned int file_size;
char remark[2001];
char cre_date[21];
char mod_date[21];
} h_bin_obj;
char h_con_name[31];
long h_file_obj;
/* for insertion of CRE_DATE + MOD_DATE */
char h_fmt_date[30];
char h_fmt_date2[30];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_fmt_date2,DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
connection = PQsetdbLogin(db_con->host, db_con->port, NULL, NULL, db_con->db_name, db_con->user_id, db_con->user_passwd);
if (PQstatus(connection) == CONNECTION_BAD)
{
PQfinish(connection);
return (DA_FAIL);
}
else
{
/* current db-user becomes owner of the new data -> acc. rhgt=VIEW+EDIT */
v_access_right = DA_A_VIEWEDIT;
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* get new BIN_OBJ_ID and set CRE_DATE and MOD_DATE = CURRENT_TIMESTAMP */
errln = 10;
EXEC SQL SELECT NEXTVAL('BIN_OBJ_SEQ'),
to_char(CURRENT_TIMESTAMP, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_bin_obj_id_new,
:h_bin_obj.cre_date,
:h_bin_obj.mod_date;
/*
* copy passed record into host variable
*/
h_bin_obj.bin_obj_id = h_bin_obj_id_new;
h_bin_obj.object_id = vp_bin_obj->object_id;
h_bin_obj.file_size = vp_bin_obj->file_size;
v_file_obj_size = vp_bin_obj->file_size;
h_bin_obj.privs = vp_bin_obj->privs;
strcpy(h_bin_obj.name, vp_bin_obj->name);
strcpy(h_bin_obj.user_id, vg_db_user_info.user_id);
strcpy(h_bin_obj.obj_type, vp_bin_obj->obj_type);
strcpy(h_bin_obj.obj_sub_type, vp_bin_obj->obj_sub_type);
strcpy(h_bin_obj.file_type, vp_bin_obj->file_type);
strcpy(h_bin_obj.remark, vp_bin_obj->remark);
if(vp_bin_obj->file_obj)
{
res = PQexec(connection, "begin");
PQclear(res);
lobjOid = lo_creat(connection, INV_READ|INV_WRITE);
if (lobjOid == 0)
{
return (DA_FAIL);
}
fd = lo_open(connection, lobjOid, INV_WRITE);
lo_write(connection, fd, vp_bin_obj->file_obj, v_file_obj_size);
lo_close(connection, fd);
h_file_obj = lobjOid;
res = PQexec(connection, "end");
PQclear(res);
PQfinish(connection);
}
/* full path for file of blob data is given in vp_bin_obj->name */
else
h_file_obj = 0;
/* Insert passed record and fill the BLOB */
errln = 30;
EXEC SQL INSERT INTO BIN_OBJ_TAB (BIN_OBJ_ID, OBJECT_ID, NAME,
USER_ID, PRIVS,
OBJ_TYPE, OBJ_SUB_TYPE,
FILE_TYPE, FILE_SIZE,
REMARK, CRE_DATE,
MOD_DATE, FILE_OBJ)
VALUES (:h_bin_obj.bin_obj_id,
:h_bin_obj.object_id,
:h_bin_obj.name,
:h_bin_obj.user_id,
:h_bin_obj.privs,
:h_bin_obj.obj_type,
:h_bin_obj.obj_sub_type,
:h_bin_obj.file_type,
:h_bin_obj.file_size,
:h_bin_obj.remark,
to_date(:h_bin_obj.cre_date, :h_fmt_date),
to_date(:h_bin_obj.mod_date, :h_fmt_date2),
:h_file_obj);
/* set return values into passed struct/record */
vp_bin_obj->bin_obj_id = h_bin_obj_id_new;
strcpy(vp_bin_obj->cre_date, h_bin_obj.cre_date);
strcpy(vp_bin_obj->mod_date, h_bin_obj.mod_date);
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
}
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
EXEC SQL WHENEVER SQLERROR CONTINUE;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_bin_obj (BIN_OBJ_TAB)
*
* Issue : 18-JUL-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by BIN_OBJ_ID) in BIN_OBJ_TAB
* by data of passed record. BLOB will be only updated, if
* file_object is specified!
*
* Parameter: vp_bin_obj (i) new bin. obj. data containing BIN_OBJ_ID
* of record to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by BIN_OBJ_ID) in BIN_OBJ_TAB by data of passed record.
BLOB will be only updated, if file_object is specified.
Output:
vp_errinfo - Error information in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 18-JUL-2002
\param db_con Pointer to connection
\param vp_bin_obj new bin. obj. data containing BIN_OBJ_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_bin_obj(DB_con *db_con,
DA_T_bin_obj *vp_bin_obj,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_bin_obj";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
unsigned int v_file_obj_size ;
int fd;
Oid lobjOid;
PGconn *connection;
PGresult *res;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_bin_obj_id;
int dummy;
struct DA_T_bin_obj_pg_h{ /* type contains host variables for object data */
long bin_obj_id;
long object_id;
char name [256];
char user_id [ 31];
int privs;
char obj_type [ 31];
char obj_sub_type[ 31];
char file_type [ 4];
unsigned int file_size;
char remark[2001];
char cre_date[21];
char mod_date[21];
} h_bin_obj;
char h_con_name[31];
long h_file_obj;
char h_fmt_date[30];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_BIN_OBJ_TAB, (void*) vp_bin_obj,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_bin_obj_id = vp_bin_obj->bin_obj_id;
h_bin_obj.bin_obj_id = vp_bin_obj->bin_obj_id;
h_bin_obj.object_id = vp_bin_obj->object_id;
h_bin_obj.file_size = vp_bin_obj->file_size;
v_file_obj_size = vp_bin_obj->file_size;
h_bin_obj.privs = vp_bin_obj->privs;
strcpy(h_bin_obj.name, vp_bin_obj->name);
strcpy(h_bin_obj.user_id, vp_bin_obj->user_id);
strcpy(h_bin_obj.obj_type, vp_bin_obj->obj_type);
strcpy(h_bin_obj.obj_sub_type, vp_bin_obj->obj_sub_type);
strcpy(h_bin_obj.file_type, vp_bin_obj->file_type);
strcpy(h_bin_obj.remark, vp_bin_obj->remark);
/* set MOD_DATE = CURRENT_TIMESTAMP */
errln = 20;
EXEC SQL SELECT to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_bin_obj.mod_date;
connection = PQsetdbLogin(db_con->host, db_con->port, NULL, NULL, db_con->db_name, db_con->user_id, db_con->user_passwd);
if (PQstatus(connection) == CONNECTION_BAD)
{
PQfinish(connection);
/* Update failed */
return(DA_FAIL);
}
/* Update passed record in database including BLOB if data are available */
if (vp_bin_obj->file_obj != NULL)
{
errln = 30;
/* delete old blob from DATABASE */
EXEC SQL SELECT FILE_OBJ INTO :dummy FROM BIN_OBJ_TAB
WHERE BIN_OBJ_ID = :h_bin_obj_id;
lobjOid = dummy;
res = PQexec(connection, "begin");
PQclear(res);
lo_unlink(connection, lobjOid);
lobjOid = lo_creat(connection, INV_READ|INV_WRITE);
fd = lo_open(connection, lobjOid, INV_WRITE);
lo_write(connection, fd, vp_bin_obj->file_obj, v_file_obj_size);
lo_close(connection, fd);
res = PQexec(connection, "end");
PQclear(res);
PQfinish(connection);
h_file_obj = lobjOid;
EXEC SQL UPDATE BIN_OBJ_TAB
set BIN_OBJ_ID = :h_bin_obj.bin_obj_id,
OBJECT_ID = :h_bin_obj.object_id,
NAME = :h_bin_obj.name,
USER_ID = :h_bin_obj.user_id,
PRIVS = :h_bin_obj.privs,
OBJ_TYPE = :h_bin_obj.obj_type,
OBJ_SUB_TYPE = :h_bin_obj.obj_sub_type,
FILE_TYPE = :h_bin_obj.file_type,
FILE_SIZE = :h_bin_obj.file_size,
REMARK = :h_bin_obj.remark,
MOD_DATE = to_date(:h_bin_obj.mod_date, :h_fmt_date),
FILE_OBJ = :h_file_obj
WHERE BIN_OBJ_ID = :h_bin_obj_id;
}
/* Update passed record in database without BLOB data, name and file size */
else
{
errln = 40;
EXEC SQL UPDATE BIN_OBJ_TAB
set BIN_OBJ_ID = :h_bin_obj.bin_obj_id,
OBJECT_ID = :h_bin_obj.object_id,
NAME = :h_bin_obj.name,
USER_ID = :h_bin_obj.user_id,
PRIVS = :h_bin_obj.privs,
OBJ_TYPE = :h_bin_obj.obj_type,
OBJ_SUB_TYPE = :h_bin_obj.obj_sub_type,
REMARK = :h_bin_obj.remark,
MOD_DATE = to_date(:h_bin_obj.mod_date, :h_fmt_date)
WHERE BIN_OBJ_ID = :h_bin_obj_id;
}
errln = 50;
/* set return value into passed struct/record */
strcpy(vp_bin_obj->mod_date, h_bin_obj.mod_date);
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
EXEC SQL WHENEVER SQLERROR CONTINUE;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_bin_obj (BIN_OBJ_TAB)
*
* Issue : 18-JUL-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Delete record (incl. BLOB) specified by "bin_obj_id"
*
* Parameter: vp_bin_obj_id (i) BIN_OBJ_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record (incl. BLOB) specified by "bin_obj_id".
Output:
vp_errinfo - Error information in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 18-JUL-2002
\param db_con Pointer to connection
\param vp_bin_obj_id BIN_OBJ_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_bin_obj(DB_con *db_con,
long vp_bin_obj_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_delete_bin_obj";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
DA_T_bin_obj v_bin_obj_buf;
Oid lobjOid;
PGconn *connection;
PGresult *res;
// not used: char *database = "static_db";
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_con_name[31];
int dummy;
struct DA_T_bin_obj_pg_h{ /* type contains host variables for object data */
long bin_obj_id;
long object_id;
char name [256];
char user_id [ 31];
int privs;
char obj_type [ 31];
char obj_sub_type[ 31];
char file_type [ 4];
unsigned int file_size;
char remark[2001];
char cre_date[21];
char mod_date[21];
} h_bin_obj;
struct DA_T_bin_obj_pg_i{ /* indicator variables for host variable struct */
short int bin_obj_id;
short int object_id;
short int name;
short int user_id;
short int privs;
short int obj_type;
short int obj_sub_type;
short int file_type;
short int file_size;
short int remark;
short int cre_date;
short int mod_date;
} h_ind_bin_obj;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* get access right info for object */
h_bin_obj.bin_obj_id = vp_bin_obj_id;
errln = 10;
EXEC SQL SELECT USER_ID,
PRIVS
INTO :h_bin_obj.user_id INDICATOR :h_ind_bin_obj.user_id,
:h_bin_obj.privs INDICATOR :h_ind_bin_obj.privs
FROM BIN_OBJ_TAB
WHERE BIN_OBJ_ID = :h_bin_obj.bin_obj_id;
/* check indicator variables (in regard to NULL values) */
if (h_ind_bin_obj.bin_obj_id == -1) h_bin_obj.bin_obj_id = -1;
if (h_ind_bin_obj.privs == -1) h_bin_obj.privs = 1;
if (h_ind_bin_obj.user_id == -1) strcpy(h_bin_obj.user_id,"");
/* copy result into temp. buffer */
v_bin_obj_buf.bin_obj_id = h_bin_obj.bin_obj_id;
v_bin_obj_buf.privs = h_bin_obj.privs;
strcpy(v_bin_obj_buf.user_id, h_bin_obj.user_id);
v_bin_obj_buf.file_obj = NULL;
v_bin_obj_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_BIN_OBJ_TAB, (void*) &v_bin_obj_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
connection = PQsetdbLogin(db_con->host, db_con->port, NULL, NULL, db_con->db_name, db_con->user_id, db_con->user_passwd);
if (PQstatus(connection) == CONNECTION_BAD)
{
PQfinish(connection);
return(DA_FAIL);
}
errln = 20;
/* get specified record */
EXEC SQL SELECT FILE_OBJ
INTO :dummy
FROM BIN_OBJ_TAB
where BIN_OBJ_ID = :h_bin_obj.bin_obj_id;
lobjOid = dummy;
res = PQexec(connection, "begin");
PQclear(res);
/* delete blob from db */
lobjOid = lo_unlink(connection, lobjOid);
res = PQexec(connection, "end");
PQclear(res);
PQfinish(connection);
/* delete rest of data from bin_obj_tab*/
EXEC SQL DELETE FROM BIN_OBJ_TAB
WHERE BIN_OBJ_ID = :h_bin_obj.bin_obj_id;
/* record successfully deleted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not deleted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_load_bin_obj (BIN_OBJ_TAB)
*
* Issue : 30-JUL-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Load specified file from file system into memory and insert
* the loaded file (bin. object) together with passed bin.obj.
* detail data into table BIN_OBJ_TAB.
*
* Parameter: vp_bin_obj (i/o) pointer to struct, containing the detail
* data for insert into BIN_OBJ_TAB
*
* OUTPUT:
* vp_bin_obj.bin_obj_id (ret. from insert)
* vp_bin_obj.name (taken from vp_filename)
* vp_bin_obj.file_obj (ptr. to allocated mem.
* containg the inputfile)
* vp_get_file_obj (i) control return of binary input file/obj.
* 'N' => vp_bin_obj->file_obj = NULL
* 'Y' => vp_bin_obj->file_obj <> NULL
* vp_filepath (i) path to file which shall be read in as
* binary object
* vp_filename (i) name of file which shall be read in as
* binary object. Wildcards are not supported!
* vp_errinfo (o) Error information in case error occured
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Load specified file from file system into memory and insert the loaded file.
Output:
vp_errinfo - Error information in case error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 30-JUL-2002
\param db_con Pointer to connection
\param vp_bin_obj pointer to struct, containing the detail data for insert into BIN_OBJ_TAB
\param vp_get_file_obj control return of binary input file/obj. \n
'N' => vp_bin_obj->file_obj = NULL \n 'Y' => vp_bin_obj->file_obj <> NULL
\param vp_filepath path to file which shall be read in as binary object
\param vp_filename name of file which shall be read in as binary object. Wildcards are not supported!
\return DA_SUCCESS \n DA_FAIL
*/
int gda_load_bin_obj (DB_con *db_con,
DA_T_bin_obj *vp_bin_obj,
char vp_get_file_obj,
char *vp_filepath,
char *vp_filename,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_load_bin_obj";
char v_in_buf;
char v_inputfile[480];
FILE *fp;
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* current db-user becomes owner of the new data -> acc. rhgt=VIEW+EDIT */
v_access_right = DA_A_VIEWEDIT;
errln = 10;
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* open file and read into buffer */
if (vp_filepath[strlen(vp_filepath)-1] == '\\')
sprintf(v_inputfile, "%s%s", vp_filepath, vp_filename);
else
sprintf(v_inputfile, "%s/%s", vp_filepath, vp_filename);
/* open input file in "binary" mode (rb) */
errln = 20;
fp = fopen(v_inputfile, "rb");
if (fp == NULL)
{
/* ERROR opening the input file */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param, "%s%s", "gda_load_bin_obj_tab() - fileopen(ERROR): ",vp_filename);
return(DA_FAIL);
}
/*
* Inputfile open in BINARY mode => read file content into memory
*/
vp_bin_obj->file_obj = NULL;
vp_bin_obj->file_size = 0;
errln = 30;
while (!feof(fp))
{
/* read next character from inputfile */
v_in_buf = (char) fgetc(fp);
if (!feof(fp) )
{
/* realloc file buffer */
vp_bin_obj->file_size++;
vp_bin_obj->file_obj = (char *) realloc(vp_bin_obj->file_obj,vp_bin_obj->file_size);
/* copy in buffer into target buffer */
vp_bin_obj->file_obj[vp_bin_obj->file_size-1] = v_in_buf;
}
}/* end: while(!feof(fp)) */
/* close inputfile */
fclose(fp);
/*
* insert record into BIN_OBJ_TAB
*/
errln = 40;
if (!gda_insert_bin_obj(db_con, vp_bin_obj, vp_errinfo))
{
/*
* ERROR
* => release memory allocated for file content
*/
free(vp_bin_obj->file_obj);
return(DA_FAIL);
}
else
{
/*
* SUCCESS
* => file successfully loaded and inserted!
*/
if (vp_get_file_obj == DA_NO)
{
/* release memory allocated for file content */
free(vp_bin_obj->file_obj);
/* reset pointer to file object */
vp_bin_obj->file_obj = NULL;
}
return(DA_SUCCESS);
}
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_bin_obj (BIN_OBJ_TAB)
*
* Issue : 18-JUL-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "gda_get_bin_obj()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_bin_obj (i) pointer to "list of" bin_obj records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "da_get_bin_obj()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 18-JUL-2002
\param vp_bin_obj pointer to "list of" bin_obj records
\return ---
*/
void gda_free_bin_obj(DA_T_bin_obj *vp_bin_obj)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_bin_obj";
#endif
/* pointer to list elements */
DA_T_bin_obj *v_next_elem_ptr = NULL;
DA_T_bin_obj *v_curr_elem_ptr = NULL;
char *v_file_obj_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_bin_obj;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
v_file_obj_ptr = v_curr_elem_ptr->file_obj;
/* free memory allocated for BLOB */
if ( v_file_obj_ptr != NULL)
free( v_file_obj_ptr );
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/*********************************************************************
* Name : gda_load_bin_obj_update (BIN_OBJ_TAB)
*
* Issue : 28-JAN-2003 - S.F. - TechniData AG/Markdorf
*
* Purpose : Load specified file from file system into memory and update
* the loaded file (bin. object) together with passed bin.obj.
* detail data into table BIN_OBJ_TAB. If no file path and no
* file name are given, only the binary object data is updated without
* without upload of file.
*
* Parameter: vp_bin_obj (i/o) pointer to struct, containing the detail
* data for insert into BIN_OBJ_TAB
*
* OUTPUT:
* vp_bin_obj.bin_obj_id (ret. from insert)
* vp_bin_obj.name (taken from vp_filename)
* vp_bin_obj.file_obj (ptr. to allocated mem.
* containg the inputfile)
* vp_get_file_obj (i) control return of binary input file/obj.
* 'N' => vp_bin_obj->file_obj = NULL
* 'Y' => vp_bin_obj->file_obj <> NULL
* vp_filepath (i) path to file which shall be read in as
* binary object
* vp_filename (i) name of file which shall be read in as
* binary object. Wildcards are not supported!
* vp_errinfo (o) Error information in case error occured
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Load specified file from file system into memory and update the loaded file .
calls gda_load_bin_obj_update().
Output:
vp_errinfo - Error information in case error occured
\author S.F. - TechniData AG/Markdorf \n H.K. - Intevation
\date 28-JAN-2003
\param db_con Pointer to connection
\param vp_bin_obj pointer to struct, containing the detail data for insert into BIN_OBJ_TAB
\param vp_get_file_obj control return of binary input file/obj. \n
'N' => vp_bin_obj->file_obj = NULL \n 'Y' => vp_bin_obj->file_obj <> NULL
\param vp_filepath path to file which shall be read in as binary object
\param vp_filename name of file which shall be read in as binary object. Wildcards are not supported!
\return DA_SUCCESS \n DA_FAIL
*/
int gda_load_bin_obj_update (DB_con *db_con,
DA_T_bin_obj *vp_bin_obj,
char vp_get_file_obj,
char *vp_filepath,
char *vp_filename,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_load_bin_obj_update";
char v_in_buf;
char v_inputfile[480];
FILE *fp;
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_BIN_OBJ_TAB, (void*) vp_bin_obj,
&v_access_right, vp_errinfo);
errln = 10;
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* load binary object, if file path and file name are not empty */
if ((strcmp(vp_filepath, "") != 0) && (strcmp(vp_filename, "") != 0))
{
/* open file and read into buffer */
if (vp_filepath[strlen(vp_filepath)-1] == '\\')
sprintf(v_inputfile, "%s%s", vp_filepath, vp_filename);
else
sprintf(v_inputfile, "%s\\%s", vp_filepath, vp_filename);
errln = 20;
/* open input file in "binary" mode (rb) */
fp = fopen(v_inputfile, "rb");
if (fp == NULL)
{
/* ERROR opening the input file */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param, "%s%s", "gda_load_bin_obj_tab() - fileopen(ERROR): ",vp_filename);
return(DA_FAIL);
}
/*
* Inputfile open in BINARY mode => read file content into memory
*/
vp_bin_obj->file_obj = NULL;
vp_bin_obj->file_size = 0;
errln = 30;
while (!feof(fp))
{
/* read next character from inputfile */
v_in_buf = (char) fgetc(fp);
if (!feof(fp) )
{
/* realloc file buffer */
vp_bin_obj->file_size++;
vp_bin_obj->file_obj = (char *) realloc(vp_bin_obj->file_obj,vp_bin_obj->file_size);
/* copy in buffer into target buffer */
vp_bin_obj->file_obj[vp_bin_obj->file_size-1] = v_in_buf;
}
}/* end: while(!feof(fp)) */
errln = 40;
/* close inputfile */
fclose(fp);
}
else
{
/* Set binary object to load to NULL */
vp_bin_obj->file_obj = NULL;
}
errln = 50;
/*
* update record in BIN_OBJ_TAB
*/
if (!gda_update_bin_obj(db_con, vp_bin_obj, vp_errinfo))
{
/*
* ERROR
* => release memory allocated for file content
*/
errln = 60;
free(vp_bin_obj->file_obj);
return(DA_FAIL);
}
else
{
/*
* SUCCESS
* => file successfully loaded and updated!
*/
if (vp_get_file_obj == DA_NO)
{
errln = 70;
/* release memory allocated for file content */
if (vp_bin_obj->file_obj != NULL)
{
free(vp_bin_obj->file_obj);
/* reset pointer to file object */
vp_bin_obj->file_obj = NULL;
}
}
return(DA_SUCCESS);
}
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: PARA_TREE_DEF_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_para_tree (PARA_TREE_DEF_TAB)
*
* Issue : 02-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of parameter tree information
*
* Query conditions:
* a) FIELD_ID=
* BLOCK_ID=
* GROUP_ID= or DA_ALL
* => return: 1 record
*
* b) FIELD_ID= DA_ALL
* BLOCK_ID=
* GROUP_ID= or DA_ALL
* => return: 1..n records (all fields for spec. block_id/group_id)
*
*
* Parameter: vp_block_id (i) ID of parameter block
* vp_group_id (i) ID of parameter group
* vp_field_id (i) ID of parameter field
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of parameter tree information.
Query conditions:
FIELD_ID= \n
BLOCK_ID= \n
GROUP_ID= or DA_ALL \n
=> return: 1 record
FIELD_ID= DA_ALL \n
BLOCK_ID= \n
GROUP_ID= or DA_ALL \n
=> return: 1..n records (all fields for spec. block_id/group_id)
Output:
vp_errinfo - Error information in case error occured
vp_para_tree - the parameter tree information
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 02-AUG-2002
\param db_con Pointer to connection
\param vp_block_id ID of parameter block
\param vp_group_id ID of parameter group
\param vp_field_id ID of parameter field
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_para_tree (DB_con *db_con,
char *vp_block_id,
char *vp_group_id,
char *vp_field_id,
DA_T_para_tree **vp_para_tree,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_para_tree";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_para_tree v_para_tree_buf;
/* pointer to list root, list elements */
DA_T_para_tree *v_root_lst_ptr = NULL;
DA_T_para_tree *v_new_elem_ptr = NULL;
DA_T_para_tree *v_last_elem_ptr = NULL;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_field_id_qry[240];
char h_block_id_qry[240];
char h_group_id_qry[240];
char h_con_name[31];
struct DA_T_para_tree_pg_h{ /* type contains host variables for object data */
char field_id [ 31];
char block_id [ 31];
char group_id [ 31];
char obj_type [ 31];
char var_type [ 31];
int tree_level;
int field_sort;
int block_sort;
int group_sort;
char label [256];
char default_val [256];
char form_mask [256];
char unit [ 31];
char w_range [256];
char e_range [256];
char remark[2001];
} h_para_tree;
struct DA_T_para_tree_pg_i{ /* indicator variables for host variable struct */
short int field_id;
short int block_id;
short int group_id;
short int obj_type;
short int var_type;
short int tree_level;
short int field_sort;
short int block_sort;
short int group_sort;
short int label;
short int default_val;
short int form_mask;
short int unit;
short int w_range;
short int e_range;
short int remark;
} h_ind_para_tree;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module,
"BLK-ID:", vp_block_id,
"GRP-ID:", vp_group_id,
"FLD-ID:", vp_field_id);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* determine query condition
* a) FIELD_ID=
* BLOCK_ID=
* GROUP_ID= or DA_ALL
* => return: 1 record
*
* b) FIELD_ID= DA_ALL
* BLOCK_ID=
* GROUP_ID= or DA_ALL
* => return: 1..n records (all fields for spec. block_id/group_id)
*/
if (vp_group_id[0] == DA_ALL)
strcpy(h_group_id_qry, "%");
else
strcpy(h_group_id_qry, vp_group_id);
if (vp_block_id[0] == DA_ALL)
strcpy(h_block_id_qry, "%");
else
strcpy(h_block_id_qry, vp_block_id);
if (vp_field_id[0] == DA_ALL)
strcpy(h_field_id_qry, "%");
else
strcpy(h_field_id_qry, vp_field_id);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the catchment details from PARA_TREE_DEF_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
EXEC SQL DECLARE para_tree_def_csr CURSOR FOR
SELECT FIELD_ID,
BLOCK_ID,
GROUP_ID,
OBJ_TYPE,
VAR_TYPE,
TREE_LEVEL,
FIELD_SORT,
BLOCK_SORT,
GROUP_SORT,
LABEL,
DEFAULT_VAL,
FORM_MASK,
UNIT,
W_RANGE,
E_RANGE,
REMARK
FROM PARA_TREE_DEF_TAB
WHERE FIELD_ID like :h_field_id_qry
AND BLOCK_ID like :h_block_id_qry
AND GROUP_ID like :h_group_id_qry
ORDER BY BLOCK_SORT, GROUP_SORT, FIELD_SORT;
errln = 20;
EXEC SQL OPEN para_tree_def_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH para_tree_def_csr INTO :h_para_tree INDICATOR :h_ind_para_tree;
/* check indicator variables (in regard to NULL values) */
if (h_ind_para_tree.tree_level == -1) h_para_tree.tree_level = 0;
if (h_ind_para_tree.field_sort == -1) h_para_tree.field_sort = 0;
if (h_ind_para_tree.block_sort == -1) h_para_tree.block_sort = 0;
if (h_ind_para_tree.group_sort == -1) h_para_tree.group_sort = 0;
if (h_ind_para_tree.field_id == -1) strcpy(h_para_tree.field_id, "");
if (h_ind_para_tree.block_id == -1) strcpy(h_para_tree.block_id, "");
if (h_ind_para_tree.group_id == -1) strcpy(h_para_tree.group_id, "");
if (h_ind_para_tree.obj_type == -1) strcpy(h_para_tree.obj_type, "");
if (h_ind_para_tree.var_type == -1) strcpy(h_para_tree.var_type, "");
if (h_ind_para_tree.label == -1) strcpy(h_para_tree.label, "");
if (h_ind_para_tree.default_val== -1) strcpy(h_para_tree.default_val,"");
if (h_ind_para_tree.form_mask == -1) strcpy(h_para_tree.form_mask, "");
if (h_ind_para_tree.unit == -1) strcpy(h_para_tree.unit, "");
if (h_ind_para_tree.w_range == -1) strcpy(h_para_tree.w_range, "");
if (h_ind_para_tree.e_range == -1) strcpy(h_para_tree.e_range, "");
if (h_ind_para_tree.remark == -1) strcpy(h_para_tree.remark, "");
/* copy result into temp. buffer */
v_para_tree_buf.tree_level = h_para_tree.tree_level;
v_para_tree_buf.field_sort = h_para_tree.field_sort;
v_para_tree_buf.block_sort = h_para_tree.block_sort;
v_para_tree_buf.group_sort = h_para_tree.group_sort;
strcpy(v_para_tree_buf.field_id , h_para_tree.field_id);
strcpy(v_para_tree_buf.block_id , h_para_tree.block_id);
strcpy(v_para_tree_buf.group_id , h_para_tree.group_id);
strcpy(v_para_tree_buf.obj_type , h_para_tree.obj_type);
strcpy(v_para_tree_buf.var_type , h_para_tree.var_type);
strcpy(v_para_tree_buf.label , h_para_tree.label);
strcpy(v_para_tree_buf.default_val, h_para_tree.default_val);
strcpy(v_para_tree_buf.form_mask , h_para_tree.form_mask);
strcpy(v_para_tree_buf.unit , h_para_tree.unit);
strcpy(v_para_tree_buf.w_range , h_para_tree.w_range);
strcpy(v_para_tree_buf.e_range , h_para_tree.e_range);
strcpy(v_para_tree_buf.remark , h_para_tree.remark);
v_para_tree_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_PARA_TREE_TAB, (void*) &v_para_tree_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_para_tree*) malloc( sizeof(DA_T_para_tree) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param,"%s - malloc(DA_T_para_tree)", v_module);
gda_free_para_tree(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_para_tree) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_para_tree_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE para_tree_def_csr;
/* return created result list */
(*vp_para_tree) = v_root_lst_ptr;
/* success fully connected to database */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE para_tree_def_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : da_insert_para_tree (PARA_TREE_DEF_TAB)
*
* Issue : 16-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Insert record into PARA_TREE_DEF_TAB.
*
* Parameter: vp_para_tree (i) data to insert into PARA_TREE_DEF_TAB
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into PARA_TREE_DEF_TAB.
Output:
vp_errinfo - Error information in case error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 16-OCT-2002
\param db_con Pointer to connection
\param vp_para_tree data to insert into PARA_TREE_DEF_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_para_tree (DB_con *db_con,
DA_T_para_tree vp_para_tree,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_para_tree";
int v_status = DA_SUCCESS;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
struct DA_T_para_tree_pg_h{ /* type contains host variables for object data */
char field_id [ 31];
char block_id [ 31];
char group_id [ 31];
char obj_type [ 31];
char var_type [ 31];
int tree_level;
int field_sort;
int block_sort;
int group_sort;
char label [256];
char default_val [256];
char form_mask [256];
char unit [ 31];
char w_range [256];
char e_range [256];
char remark[2001];
} h_para_tree;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* copy passed record into host variable */
strcpy(h_para_tree.field_id , vp_para_tree.field_id);
strcpy(h_para_tree.block_id , vp_para_tree.block_id);
strcpy(h_para_tree.group_id , vp_para_tree.group_id);
strcpy(h_para_tree.obj_type , vp_para_tree.obj_type);
strcpy(h_para_tree.var_type , vp_para_tree.var_type);
h_para_tree.tree_level = vp_para_tree.tree_level;
h_para_tree.field_sort = vp_para_tree.field_sort;
h_para_tree.block_sort = vp_para_tree.block_sort;
h_para_tree.group_sort = vp_para_tree.group_sort;
strcpy(h_para_tree.label , vp_para_tree.label);
strcpy(h_para_tree.default_val, vp_para_tree.default_val);
strcpy(h_para_tree.form_mask , vp_para_tree.form_mask);
strcpy(h_para_tree.unit , vp_para_tree.unit);
strcpy(h_para_tree.w_range , vp_para_tree.w_range);
strcpy(h_para_tree.e_range , vp_para_tree.e_range);
strcpy(h_para_tree.remark , vp_para_tree.remark);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* Insert passed record */
errln = 20;
EXEC SQL INSERT INTO PARA_TREE_DEF_TAB (FIELD_ID,
BLOCK_ID,
GROUP_ID,
OBJ_TYPE,
VAR_TYPE,
TREE_LEVEL,
FIELD_SORT,
BLOCK_SORT,
GROUP_SORT,
LABEL,
DEFAULT_VAL,
FORM_MASK,
UNIT,
W_RANGE,
E_RANGE,
REMARK)
VALUES (:h_para_tree.field_id,
:h_para_tree.block_id,
:h_para_tree.group_id,
:h_para_tree.obj_type,
:h_para_tree.var_type,
:h_para_tree.tree_level,
:h_para_tree.field_sort,
:h_para_tree.block_sort,
:h_para_tree.group_sort,
:h_para_tree.label,
:h_para_tree.default_val,
:h_para_tree.form_mask,
:h_para_tree.unit,
:h_para_tree.w_range,
:h_para_tree.e_range,
:h_para_tree.remark);
/* record successfully inserted */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_para_tree (PARA_TREE_DEF_TAB)
*
* Issue : 16-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by BLOCK_ID, GROUP_ID, FIELD_ID)
* in PARA_TREE_DEF_TAB by data of passed record.
*
* Parameter: vp_para_tree (i) new para_tree data
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by BLOCK_ID, GROUP_ID, FIELD_ID) in PARA_TREE_DEF_TAB by data of passed record.
Output:
vp_errinfo - Error information in case error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 16-OCT-2002
\param db_con Pointer to connection
\param vp_para_tree new para_tree data
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_para_tree (DB_con *db_con,
DA_T_para_tree vp_para_tree,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_para_tree";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
struct DA_T_para_tree_pg_h{ /* type contains host variables for object data */
char field_id [ 31];
char block_id [ 31];
char group_id [ 31];
char obj_type [ 31];
char var_type [ 31];
int tree_level;
int field_sort;
int block_sort;
int group_sort;
char label [256];
char default_val [256];
char form_mask [256];
char unit [ 31];
char w_range [256];
char e_range [256];
char remark[2001];
} h_para_tree;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* copy passed record into host variable */
strcpy(h_para_tree.field_id , vp_para_tree.field_id);
strcpy(h_para_tree.block_id , vp_para_tree.block_id);
strcpy(h_para_tree.group_id , vp_para_tree.group_id);
strcpy(h_para_tree.obj_type , vp_para_tree.obj_type);
strcpy(h_para_tree.var_type , vp_para_tree.var_type);
h_para_tree.tree_level = vp_para_tree.tree_level;
h_para_tree.field_sort = vp_para_tree.field_sort;
h_para_tree.block_sort = vp_para_tree.block_sort;
h_para_tree.group_sort = vp_para_tree.group_sort;
strcpy(h_para_tree.label , vp_para_tree.label);
strcpy(h_para_tree.default_val, vp_para_tree.default_val);
strcpy(h_para_tree.form_mask , vp_para_tree.form_mask);
strcpy(h_para_tree.unit , vp_para_tree.unit);
strcpy(h_para_tree.w_range , vp_para_tree.w_range);
strcpy(h_para_tree.e_range , vp_para_tree.e_range);
strcpy(h_para_tree.remark , vp_para_tree.remark);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* Update passed record in database */
errln = 10;
EXEC SQL UPDATE PARA_TREE_DEF_TAB
SET OBJ_TYPE = :h_para_tree.obj_type,
VAR_TYPE = :h_para_tree.var_type,
TREE_LEVEL = :h_para_tree.tree_level,
FIELD_SORT = :h_para_tree.field_sort,
BLOCK_SORT = :h_para_tree.block_sort,
GROUP_SORT = :h_para_tree.group_sort,
LABEL = :h_para_tree.label,
DEFAULT_VAL = :h_para_tree.default_val,
FORM_MASK = :h_para_tree.form_mask,
UNIT = :h_para_tree.unit,
W_RANGE = :h_para_tree.w_range,
E_RANGE = :h_para_tree.e_range,
REMARK = :h_para_tree.remark
WHERE BLOCK_ID = :h_para_tree.block_id
AND GROUP_ID = :h_para_tree.group_id
AND FIELD_ID = :h_para_tree.field_id;
/* record successfully updated */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_para_tree (PARA_TREE_DEF_TAB)
*
* Issue : 16-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Delete record from PARA_TREE_DEF_TAB specified by
* BLOCK_ID, GROUP_ID and FIELD_ID.
*
* Parameter: vp_block_id (i) BLOCK_ID of record to delete
* vp_group_id (i) GROUP_ID of record to delete
* vp_field_id (i) FIELD_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from PARA_TREE_DEF_TAB specified by BLOCK_ID, GROUP_ID and FIELD_ID.
Output:
vp_errinfo - Error information in case error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 16-OCT-2002
\param db_con Pointer to connection
\param vp_block_id BLOCK_ID of record to delete
\param vp_group_id GROUP_ID of record to delete
\param vp_field_id FIELD_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_para_tree (DB_con *db_con,
char *vp_block_id,
char *vp_group_id,
char *vp_field_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_delete_para_tree";
int v_status = DA_SUCCESS;
// not used: int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_block_id_qry[31];
char h_group_id_qry[31];
char h_field_id_qry[31];
char h_con_name[31];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy (h_block_id_qry, vp_block_id);
strcpy (h_group_id_qry, vp_group_id);
strcpy (h_field_id_qry, vp_field_id);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* delete specified record */
errln = 10;
EXEC SQL DELETE FROM PARA_TREE_DEF_TAB
WHERE BLOCK_ID = :h_block_id_qry
AND GROUP_ID = :h_group_id_qry
AND FIELD_ID = :h_field_id_qry;
/* record successfully deleted */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_para_tree (PARA_TREE_DEF_TAB)
*
* Issue : 02-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_para_tree()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_para_tree (i) pointer to "list of" param. tree infos
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_para_tree()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 02-AUG-2002
\param vp_para_tree pointer to "list of" param. tree infos
\return DA_SUCCESS \n DA_FAIL
*/
void gda_free_para_tree(DA_T_para_tree *vp_para_tree)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_para_tree";
#endif
/* pointer to list elements */
DA_T_para_tree *v_next_elem_ptr = NULL;
DA_T_para_tree *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_para_tree;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: SESS_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_sess (SESS_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of sessions from SESS_TAB
*
* Query conditions:
* a) sess_id =-1 return: 1..n records
* b) sess_id <>-1, return: 1 record
*
* Additional filter:
* is_temp_sess = Y -> select only temp. sessions
* is_temp_sess = N -> select only NONE temp. sessions
* is_temp_sess = % -> select both types of sessions
*
* Parameter: vp_sess_id (i) ID of session to select
* vp_is_temp_sess (i) see above
* vp_sess (o) Return value (list of sessions)
* vp_errinfo (o) Error info in case of error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of sessions from SESS_TAB.
Query conditions:
sess_id =-1 return: 1..n records
sess_id <>-1, return: 1 record
Additional filter:
is_temp_sess = Y -> select only temp. sessions
is_temp_sess = N -> select only NONE temp. sessions
is_temp_sess = % -> select both types of sessions
Output:
vp_sess - Return value (list of sessions)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_sess_id ID of session to select
\param vp_is_temp_sess see above
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_sess (DB_con *db_con,
long vp_sess_id,
char vp_is_temp_sess,
DA_T_sess **vp_sess,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_sess";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_sess v_sess_buf;
/* pointer to list root */
DA_T_sess *v_root_lst_ptr = NULL;
/* pointer to list element */
DA_T_sess *v_new_elem_ptr = NULL;
DA_T_sess *v_last_elem_ptr = NULL;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_is_temp_sess[ 2];
char h_fmt_date [ 30];
char h_con_name [ 31];
char h_where_clause[100];
char h_query [2000];
struct DA_T_sess_pg_h{ /* type contains host variables for session data */
long sess_id;
long catch_id;
long subst_id;
long env_id;
long market_id;
long mod_id;
long res_id;
long sess_disch_id; /* added: 04-SEP-02; S.F. */
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
long privs;
char is_temp_sess [ 2];
long temp_sess_src_id;
char temp_sess_db_sid [256];
char remark [2001];
} h_sess;
struct DA_T_sess_pg_i{ /* indicator variables for host variable struct */
short int sess_id;
short int catch_id;
short int subst_id;
short int env_id;
short int market_id;
short int mod_id;
short int res_id;
short int sess_disch_id; /* added: 04-SEP-02; S.F. */
short int name;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int is_temp_sess;
short int temp_sess_src_id;
short int temp_sess_db_sid;
short int remark;
} h_ind_sess;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/*
* determine query condition
* a) sess_id =-1 return: 1..n records
* b) sess_id <>-1, return: 1 record
*/
if (vp_sess_id == -1)
{
/* case a) */
strcpy (h_where_clause, "");
}
else
{
/* case b) */
sprintf(h_where_clause,"SESS_ID = %ld AND ", vp_sess_id);
}
/* set additional filter */
sprintf(h_is_temp_sess, "%c", vp_is_temp_sess);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the session from SESS_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT SESS_ID,"
"CATCH_ID,"
"SUBST_ID,"
"ENV_ID,"
"MARKET_ID,"
"MOD_ID,"
"RES_ID,"
"SESS_DISCH_ID,"
"NAME,"
"USER_ID,"
"to_char(CRE_DATE, '%s'), "
"to_char(MOD_DATE, '%s'), "
"STATUS,"
"PRIVS,"
"IS_TEMP_SESS,"
"TEMP_SESS_SRC_ID,"
"TEMP_SESS_DB_SID,"
"REMARK "
"FROM SESS_TAB "
"WHERE %s IS_TEMP_SESS LIKE '%s' "
"ORDER BY SESS_ID",
h_fmt_date, h_fmt_date, h_where_clause, h_is_temp_sess);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE sess_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN sess_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH sess_csr INTO :h_sess INDICATOR :h_ind_sess;
/* check indicator variables (in regard to NULL values) */
if (h_ind_sess.sess_id == -1) h_sess.sess_id = -1;
if (h_ind_sess.catch_id == -1) h_sess.catch_id = -1;
if (h_ind_sess.subst_id == -1) h_sess.subst_id = -1;
if (h_ind_sess.env_id == -1) h_sess.env_id = -1;
if (h_ind_sess.market_id == -1) h_sess.market_id = -1;
if (h_ind_sess.mod_id == -1) h_sess.mod_id = -1;
if (h_ind_sess.res_id == -1) h_sess.res_id = -1;
if (h_ind_sess.sess_disch_id == -1) h_sess.sess_disch_id = -1;
if (h_ind_sess.privs == -1) h_sess.privs = 1;
if (h_ind_sess.temp_sess_src_id == -1) h_sess.temp_sess_src_id = -1;
if (h_ind_sess.name == -1) strcpy(h_sess.name, "");
if (h_ind_sess.user_id == -1) strcpy(h_sess.user_id, "");
if (h_ind_sess.cre_date == -1) strcpy(h_sess.cre_date, "");
if (h_ind_sess.mod_date == -1) strcpy(h_sess.mod_date, "");
if (h_ind_sess.status == -1) strcpy(h_sess.status, "");
if (h_ind_sess.is_temp_sess == -1) strcpy(h_sess.is_temp_sess, "N");
if (h_ind_sess.temp_sess_db_sid == -1) strcpy(h_sess.temp_sess_db_sid, "");
if (h_ind_sess.remark == -1) strcpy(h_sess.remark, "");
/* copy result into temp. buffer */
v_sess_buf.sess_id = h_sess.sess_id;
v_sess_buf.catch_id = h_sess.catch_id;
v_sess_buf.subst_id = h_sess.subst_id;
v_sess_buf.env_id = h_sess.env_id;
v_sess_buf.market_id = h_sess.market_id;
v_sess_buf.mod_id = h_sess.mod_id;
v_sess_buf.res_id = h_sess.res_id;
v_sess_buf.sess_disch_id = h_sess.sess_disch_id;
v_sess_buf.privs = h_sess.privs;
v_sess_buf.temp_sess_src_id = h_sess.temp_sess_src_id;
strcpy(v_sess_buf.name , h_sess.name);
strcpy(v_sess_buf.user_id , h_sess.user_id);
strcpy(v_sess_buf.cre_date , h_sess.cre_date);
strcpy(v_sess_buf.mod_date , h_sess.mod_date);
strcpy(v_sess_buf.status , h_sess.status);
strcpy(v_sess_buf.is_temp_sess, h_sess.is_temp_sess);
strcpy(v_sess_buf.temp_sess_db_sid, h_sess.temp_sess_db_sid);
strcpy(v_sess_buf.remark , h_sess.remark);
v_sess_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SESS_TAB, (void*) &v_sess_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_sess*) malloc( sizeof(DA_T_sess) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf (vp_errinfo->err_param,"%s - malloc(DA_T_sess)", v_module);
/* release already allocated memory */
gda_free_sess(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_sess) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_sess_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE sess_csr;
/* return created result list */
(*vp_sess) = v_root_lst_ptr;
/* success fully connected to database */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE sess_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_sess (SESS_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Insert record into SESS_TAB. Return new "SESS_ID"
* by passed struct, in case insert could successfully be done
*
* Parameter: vp_sess (i/o) data to insert into SESS_TAB,
* OUTPUT:
* - sess_id = SESS_SEQ.NEXTVAL
* - cre_date = CURRENT_TIMESTAMP
* - mod_date = CURRENT_TIMESTAMP
* - user_id =
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
* vg_db_user_info(i) -> general information about database
* user of current db-session
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into SESS_TAB.
Return new "SESS_ID" by passed struct, in case insert could successfully be done.
Output:
vp_sess - Return value (sess_id = NEXTVAL('SESS_SEQ'), cre_date = CURRENT_TIMESTAMP, mod_date = CURRENT_TIMESTAMP)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_sess data to insert into SESS_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_sess (DB_con *db_con,
DA_T_sess *vp_sess,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_sess";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_id_chk = DA_FAIL;
char v_errmsg[256];
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_sess_id_new;
char h_fmt_date[30];
char h_con_name [31];
struct DA_T_sess_pg_h{ /* type contains host variables for session data */
long sess_id;
long catch_id;
long subst_id;
long env_id;
long market_id;
long mod_id;
long res_id;
long sess_disch_id; /* added: 04-SEP-02; S.F. */
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
long privs;
char is_temp_sess [ 2];
long temp_sess_src_id;
char temp_sess_db_sid [256];
char remark [2001];
} h_sess;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/* ------------------ *
* PRE-CHECK
* ------------------ */
v_id_chk = lgda_chk_market_id(vp_sess->market_id, vp_errinfo);
if (v_id_chk != DA_SUCCESS)
{
/* error during check of market_id */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
v_id_chk = DA_FAIL;
v_id_chk = lgda_chk_sess_disch_id(vp_sess->sess_disch_id, vp_errinfo);
if (v_id_chk != DA_SUCCESS)
{
/* error during check of sess_disch_id */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
/* current db-user becomes owner of the new data -> acc. rhgt=VIEW+EDIT */
v_access_right = DA_A_VIEWEDIT;
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* get new SESSION-ID */
errln = 10;
EXEC SQL SELECT to_char(CURRENT_TIMESTAMP, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_sess.cre_date,
:h_sess.mod_date;
/*
* copy passed record into host variable
*/
h_sess.catch_id = vp_sess->catch_id;
h_sess.subst_id = vp_sess->subst_id;
h_sess.env_id = vp_sess->env_id;
h_sess.market_id = vp_sess->market_id;
h_sess.mod_id = vp_sess->mod_id;
h_sess.res_id = vp_sess->res_id;
h_sess.sess_disch_id = vp_sess->sess_disch_id;
h_sess.privs = vp_sess->privs;
h_sess.temp_sess_src_id = vp_sess->temp_sess_src_id;
strcpy(h_sess.name , vp_sess->name);
strcpy(h_sess.user_id , vg_db_user_info.user_id);
strcpy(h_sess.status , vp_sess->status);
strcpy(h_sess.is_temp_sess, vp_sess->is_temp_sess);
strcpy(h_sess.temp_sess_db_sid, vp_sess->temp_sess_db_sid);
strcpy(h_sess.remark , vp_sess->remark);
/* Insert passed record */
errln = 20;
EXEC SQL INSERT INTO SESS_TAB ( CATCH_ID,
SUBST_ID,
ENV_ID,
MARKET_ID,
MOD_ID,
RES_ID,
SESS_DISCH_ID,
NAME,
USER_ID,
CRE_DATE,
MOD_DATE,
STATUS,
PRIVS,
IS_TEMP_SESS,
TEMP_SESS_SRC_ID,
TEMP_SESS_DB_SID,
REMARK )
VALUES (CASE WHEN :h_sess.catch_id = -1 THEN NULL ELSE :h_sess.catch_id END,
CASE WHEN :h_sess.subst_id = -1 THEN NULL ELSE :h_sess.subst_id END,
CASE WHEN :h_sess.env_id = -1 THEN NULL ELSE :h_sess.env_id END,
CASE WHEN :h_sess.market_id= -1 THEN NULL ELSE :h_sess.market_id END,
CASE WHEN :h_sess.mod_id = -1 THEN NULL ELSE :h_sess.mod_id END,
CASE WHEN :h_sess.res_id = -1 THEN NULL ELSE :h_sess.res_id END,
CASE WHEN :h_sess.sess_disch_id = -1 THEN NULL ELSE :h_sess.sess_disch_id END,
:h_sess.name,
:h_sess.user_id,
TO_TIMESTAMP(:h_sess.cre_date, :h_fmt_date),
TO_TIMESTAMP(:h_sess.mod_date, :h_fmt_date),
:h_sess.status,
:h_sess.privs,
:h_sess.is_temp_sess,
CASE WHEN :h_sess.temp_sess_src_id = -1 THEN NULL ELSE :h_sess.temp_sess_src_id END,
:h_sess.temp_sess_db_sid,
:h_sess.remark);
EXEC SQL SELECT CURRVAL('SESS_SEQ') INTO :h_sess_id_new;
/* set return value (created SESS_ID,...) into passed struct/record */
vp_sess->sess_id = h_sess_id_new;
strcpy(vp_sess->user_id, h_sess.user_id );
strcpy(vp_sess->cre_date, h_sess.cre_date);
strcpy(vp_sess->mod_date, h_sess.mod_date);
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_sess (SESS_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by SESS_ID) in SESS_TAB
* by data of passed record.
*
* Parameter: vp_sess (i/o) new session data, containing SESS_ID of
* record to update.
* OUTPUT: vp_sess.MOD_DATE = CURRENT_TIMESTAMP
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by SESS_ID) in SESS_TAB by data of passed record.
Output:
vp_sess - Return value (vp_sess.MOD_DATE = CURRENT_TIMESTAMP)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_sess new session data, containing SESS_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_sess (DB_con *db_con,
DA_T_sess *vp_sess,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_sess";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_id_chk = DA_FAIL;
char v_errmsg[256];
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_sess_id;
char h_fmt_date[30];
char h_con_name [31];
struct DA_T_sess_pg_h{ /* type contains host variables for session data */
long sess_id;
long catch_id;
long subst_id;
long env_id;
long market_id;
long mod_id;
long res_id;
long sess_disch_id; /* added: 04-SEP-02; S.F. */
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
long privs;
char is_temp_sess [ 2];
long temp_sess_src_id;
char temp_sess_db_sid [256];
char remark [2001];
} h_sess;
short int h_ind_mod_date;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/* ------------------ *
* PRE-CHECK
* ------------------ */
v_id_chk = lgda_chk_market_id(vp_sess->market_id, vp_errinfo);
if (v_id_chk != DA_SUCCESS)
{
/* error during check of market_id */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
v_id_chk = DA_FAIL;
v_id_chk = lgda_chk_sess_disch_id(vp_sess->sess_disch_id, vp_errinfo);
if (v_id_chk != DA_SUCCESS)
{
/* error during check of sess_disch_id */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SESS_TAB, (void*) vp_sess,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_sess_id = vp_sess->sess_id;
h_sess.sess_id = vp_sess->sess_id;
h_sess.catch_id = vp_sess->catch_id;
h_sess.subst_id = vp_sess->subst_id;
h_sess.env_id = vp_sess->env_id;
h_sess.market_id = vp_sess->market_id;
h_sess.mod_id = vp_sess->mod_id;
h_sess.res_id = vp_sess->res_id;
h_sess.sess_disch_id = vp_sess->sess_disch_id;
h_sess.privs = vp_sess->privs;
h_sess.temp_sess_src_id = vp_sess->temp_sess_src_id;
strcpy(h_sess.name , vp_sess->name);
strcpy(h_sess.user_id , vp_sess->user_id);
strcpy(h_sess.cre_date , vp_sess->cre_date);
strcpy(h_sess.mod_date , vp_sess->mod_date);
strcpy(h_sess.status , vp_sess->status);
strcpy(h_sess.is_temp_sess, vp_sess->is_temp_sess);
strcpy(h_sess.temp_sess_db_sid, vp_sess->temp_sess_db_sid);
strcpy(h_sess.remark , vp_sess->remark);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* Update passed record in database */
errln = 10;
EXEC SQL SELECT to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_sess.mod_date INDICATOR :h_ind_mod_date;
if (h_ind_mod_date == -1)
{
strcpy(h_sess.mod_date,"");
}
/* ignore update of CRE_DATE */
errln = 20;
EXEC SQL UPDATE SESS_TAB
SET SESS_ID = :h_sess.sess_id,
CATCH_ID = CASE WHEN :h_sess.catch_id = -1 THEN NULL ELSE :h_sess.catch_id END,
SUBST_ID = CASE WHEN :h_sess.subst_id = -1 THEN NULL ELSE :h_sess.subst_id END,
ENV_ID = CASE WHEN :h_sess.env_id = -1 THEN NULL ELSE :h_sess.env_id END,
MARKET_ID = CASE WHEN :h_sess.market_id = -1 THEN NULL ELSE :h_sess.market_id END,
MOD_ID = CASE WHEN :h_sess.mod_id = -1 THEN NULL ELSE :h_sess.mod_id END,
RES_ID = CASE WHEN :h_sess.res_id = -1 THEN NULL ELSE :h_sess.res_id END,
SESS_DISCH_ID = CASE WHEN :h_sess.sess_disch_id = -1 THEN NULL ELSE :h_sess.sess_disch_id END,
NAME = :h_sess.name,
USER_ID = :h_sess.user_id,
MOD_DATE = to_timestamp(:h_sess.mod_date, :h_fmt_date),
STATUS = :h_sess.status,
PRIVS = :h_sess.privs,
IS_TEMP_SESS = :h_sess.is_temp_sess,
TEMP_SESS_SRC_ID = CASE WHEN :h_sess.temp_sess_src_id = -1 THEN NULL ELSE :h_sess.temp_sess_src_id END,
TEMP_SESS_DB_SID = :h_sess.temp_sess_db_sid,
REMARK = :h_sess.remark
WHERE SESS_ID = :h_sess_id;
/* return new MOD_DATE by passed struct */
strcpy(vp_sess->mod_date, h_sess.mod_date);
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_sess (SESS_TAB)
*
* Issue : 18-JUL-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Delete record from SESS_TAB specified by "sess_id"
*
* Parameter: vp_sess_id (i) SESS_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from SESS_TAB specified by "sess_id".
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 18-JUL-2002
\param db_con Pointer to connection
\param vp_sess_id SESS_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_sess (DB_con *db_con,
long vp_sess_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_delete_sess";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
DA_T_sess v_sess_buf;
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
struct DA_T_sess_pg_h{ /* type contains host variables for session data */
long sess_id;
long catch_id;
long subst_id;
long env_id;
long market_id;
long mod_id;
long res_id;
long sess_disch_id; /* added: 04-SEP-02; S.F. */
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
long privs;
char is_temp_sess [ 2];
long temp_sess_src_id;
char temp_sess_db_sid [256];
char remark [2001];
} h_sess;
struct DA_T_sess_pg_i{ /* indicator variables for host variable struct */
short int sess_id;
short int catch_id;
short int subst_id;
short int env_id;
short int market_id;
short int mod_id;
short int res_id;
short int sess_disch_id; /* added: 04-SEP-02; S.F. */
short int name;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int is_temp_sess;
short int temp_sess_src_id;
short int temp_sess_db_sid;
short int remark;
} h_ind_sess;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* get access right info for object */
h_sess.sess_id = vp_sess_id;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
errln = 10;
EXEC SQL SELECT CATCH_ID,
SUBST_ID,
ENV_ID,
MARKET_ID,
MOD_ID,
RES_ID,
SESS_DISCH_ID,
USER_ID,
PRIVS
INTO :h_sess.catch_id INDICATOR :h_ind_sess.catch_id,
:h_sess.subst_id INDICATOR :h_ind_sess.subst_id,
:h_sess.env_id INDICATOR :h_ind_sess.env_id,
:h_sess.market_id INDICATOR :h_ind_sess.market_id,
:h_sess.mod_id INDICATOR :h_ind_sess.mod_id,
:h_sess.res_id INDICATOR :h_ind_sess.res_id,
:h_sess.sess_disch_id INDICATOR :h_ind_sess.sess_disch_id,
:h_sess.user_id INDICATOR :h_ind_sess.user_id,
:h_sess.privs INDICATOR :h_ind_sess.privs
FROM SESS_TAB
WHERE SESS_ID = :h_sess.sess_id;
/* check indicator variables (in regard to NULL values) */
if (h_ind_sess.catch_id == -1) h_sess.catch_id = -1;
if (h_ind_sess.subst_id == -1) h_sess.subst_id = -1;
if (h_ind_sess.env_id == -1) h_sess.env_id = -1;
if (h_ind_sess.market_id == -1) h_sess.market_id = -1;
if (h_ind_sess.mod_id == -1) h_sess.mod_id = -1;
if (h_ind_sess.res_id == -1) h_sess.res_id = -1;
if (h_ind_sess.sess_disch_id == -1) h_sess.sess_disch_id = -1;
if (h_ind_sess.privs == -1) h_sess.privs = 1;
if (h_ind_sess.user_id == -1) strcpy(h_sess.user_id, "");
/* copy result into temp. buffer */
v_sess_buf.sess_id = h_sess.sess_id;
v_sess_buf.catch_id = h_sess.catch_id;
v_sess_buf.subst_id = h_sess.subst_id;
v_sess_buf.env_id = h_sess.env_id;
v_sess_buf.market_id = h_sess.market_id;
v_sess_buf.mod_id = h_sess.mod_id;
v_sess_buf.res_id = h_sess.res_id;
v_sess_buf.sess_disch_id = h_sess.sess_disch_id;
v_sess_buf.privs = h_sess.privs;
strcpy(v_sess_buf.user_id , h_sess.user_id);
v_sess_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SESS_TAB, (void*) &v_sess_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* delete specified session */
errln = 20;
EXEC SQL DELETE FROM SESS_TAB
WHERE SESS_ID = :h_sess.sess_id;
/* delete session details */
if (h_sess.res_id != -1)
{
errln = 30;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 40;
EXEC SQL DELETE FROM RES_TAB
WHERE RES_ID = :h_sess.res_id;
}
if (h_sess.market_id != -1)
{
errln = 50;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 60;
EXEC SQL DELETE FROM MARKET_TAB
WHERE MARKET_ID = :h_sess.market_id;
}
if (h_sess.subst_id != -1)
{
errln = 70;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 80;
EXEC SQL DELETE FROM SUBST_TAB
WHERE SUBST_ID = :h_sess.subst_id
AND IS_TEMPL = 'N';
}
if (h_sess.env_id != -1)
{
errln = 90;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 100;
EXEC SQL DELETE FROM ENV_TAB
WHERE ENV_ID = :h_sess.env_id
AND IS_TEMPL = 'N';
}
if (h_sess.mod_id != -1)
{
errln = 110;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 120;
EXEC SQL DELETE FROM MOD_TAB
WHERE MOD_ID = :h_sess.mod_id;
}
if (h_sess.sess_disch_id != -1)
{
errln = 130;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 140;
EXEC SQL DELETE FROM SESS_DISCH_TAB
WHERE SESS_DISCH_ID = :h_sess.sess_disch_id;
}
/* record successfully deleted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not deleted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_create_temp_sess (SESS_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Create temp. session, by copying session with passed "sess_id"
* and all session details, like substance, env. params,... .
*
* - Copied session will be marked as temp. session (IS_TEMP_SESS=Y).
* - Copied data are generally no template data anymore (IS_TEMPL=N)
* - Copied data are linked to the same owner(user), because session
* could be owned by an other user than the current database user!
*
* If vp_sess_id_src = -1 then create temporary session from scratch.
*
* - There is no source session required or copied.
* - All reference Ids are set to -1.
* - New temporary session is generally no template session.
* - New temporary session is owned by current database user.
*
* NOTE: All copied details will get new ID's by copy action!
* =====
*
* Parameter: vp_sess_id_src (i) ID of session to copy
* vp_sess_id_temp (o) ID of temporary session
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Create temp. session
by copying session with passed "sess_id" and all session details, like substance, env. params,...
Copied session will be marked as temp. session (IS_TEMP_SESS=Y).
Copied data are generally no template data anymore (IS_TEMPL=N)
Copied data are linked to the same owner(user), because session could be owned by an other user than the current database user!
If vp_sess_id_src = -1 then create temporary session from scratch.
There is no source session required or copied.
All reference Ids are set to -1.
New temporary session is generally no template session.
New temporary session is owned by current database user.
NOTE: All copied details will get new ID's by copy action!
Output:
vp_sess_id_temp ID of temporary session
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_sess_id_src ID of session to copy
\param vp_temp_type "Y" => Session is already marked as temp \n
"N" => Session is not temp yet \n
"W" => Session is an web-based session
\return DA_SUCCESS \n DA_FAIL
*/
int gda_create_temp_sess (DB_con *db_con,
long vp_sess_id_src,
long *vp_sess_id_tmp,
char vp_temp_type,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_create_temp_sess";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
// not used: int v_id_chk = DA_FAIL;
int i=0;
long v_bin_obj_id = -1;
long v_object_id;
char v_object_type[31] = "RESULT";
char get_file_obj = 'Y';
// not used: char v_errmsg[256];
DA_T_sess v_sess_buf;
DA_T_bin_obj* v_bin_obj_buf = 0;
EXEC SQL BEGIN DECLARE SECTION;
char h_fmt_date[30];
/* host variables */
long h_sess_id_src;
long h_sess_id_new;
long h_subst_id_new;
long h_env_id_new;
long h_market_id_new;
long h_mod_id_new;
long h_res_id_new;
long h_sess_disch_id_new;
char h_con_name[31];
char h_temp_user_id[31];
struct DA_T_sess_pg_h{ /* type contains host variables for session data */
long sess_id;
long catch_id;
long subst_id;
long env_id;
long market_id;
long mod_id;
long res_id;
long sess_disch_id; /* added: 04-SEP-02; S.F. */
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
long privs;
char is_temp_sess [ 2];
long temp_sess_src_id;
char temp_sess_db_sid [256];
char remark [2001];
} h_sess;
struct DA_T_sess_pg_i{ /* indicator variables for host variable struct */
short int sess_id;
short int catch_id;
short int subst_id;
short int env_id;
short int market_id;
short int mod_id;
short int res_id;
short int sess_disch_id; /* added: 04-SEP-02; S.F. */
short int name;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int is_temp_sess;
short int temp_sess_src_id;
short int temp_sess_db_sid;
short int remark;
} h_ind_sess;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* General initialisation for insert into SESS_TAB */
h_sess_id_src = vp_sess_id_src;
/* ---------------------------------------------
* Initalise temp session from scratch, if
* source session = -1
* ---------------------------------------------
* => init IDs of session details with -1
* => insert temporary session
*/
if (vp_sess_id_src == -1)
{
/* set reference IDs to -1 */
h_sess.catch_id = -1;
h_sess.subst_id = -1;
h_sess.env_id = -1;
h_sess.market_id = -1;
h_sess.mod_id = -1;
h_sess.res_id = -1;
h_sess.sess_disch_id = -1;
h_sess.privs = 3;
strcpy(h_sess.name , "Unnamed");
strcpy(h_temp_user_id , vg_db_user_info.user_id);
strcpy(h_sess.status , "TEMP");
strcpy(h_sess.remark , "");
/* access right check not required in this case */
v_access_right = DA_A_VIEW;
v_status = DA_SUCCESS;
}
else
{
/* ---------------------------------------------
* Get source SESSION
* ---------------------------------------------
* => get source session to check access rights!
* => get ID's of session details for copy action
*/
errln = 10;
EXEC SQL SELECT SESS_ID,
CATCH_ID,
SUBST_ID,
ENV_ID,
MARKET_ID,
MOD_ID,
RES_ID,
SESS_DISCH_ID,
NAME,
USER_ID,
to_char(CRE_DATE, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date),
STATUS,
PRIVS,
IS_TEMP_SESS,
TEMP_SESS_SRC_ID,
TEMP_SESS_DB_SID,
REMARK
INTO :h_sess INDICATOR :h_ind_sess
FROM SESS_TAB
WHERE SESS_ID = :h_sess_id_src;
/* check indicator variables (in regard to NULL values) */
if (h_ind_sess.sess_id == -1) h_sess.sess_id = -1;
if (h_ind_sess.catch_id == -1) h_sess.catch_id = -1;
if (h_ind_sess.subst_id == -1) h_sess.subst_id = -1;
if (h_ind_sess.env_id == -1) h_sess.env_id = -1;
if (h_ind_sess.market_id == -1) h_sess.market_id = -1;
if (h_ind_sess.mod_id == -1) h_sess.mod_id = -1;
if (h_ind_sess.res_id == -1) h_sess.res_id = -1;
if (h_ind_sess.sess_disch_id == -1) h_sess.sess_disch_id = -1;
if (h_ind_sess.privs == -1) h_sess.privs = 1;
if (h_ind_sess.temp_sess_src_id == -1) h_sess.temp_sess_src_id = -1;
if (h_ind_sess.name == -1) strcpy(h_sess.name, "");
if (h_ind_sess.user_id == -1) strcpy(h_sess.user_id, "");
if (h_ind_sess.cre_date == -1) strcpy(h_sess.cre_date, "");
if (h_ind_sess.mod_date == -1) strcpy(h_sess.mod_date, "");
if (h_ind_sess.status == -1) strcpy(h_sess.status, "");
if (h_ind_sess.is_temp_sess == -1) strcpy(h_sess.is_temp_sess, "N");
if (h_ind_sess.temp_sess_db_sid == -1) strcpy(h_sess.temp_sess_db_sid,"");
if (h_ind_sess.remark == -1) strcpy(h_sess.remark, "");
/* copy result into temp. buffer */
v_sess_buf.sess_id = h_sess.sess_id;
v_sess_buf.catch_id = h_sess.catch_id;
v_sess_buf.subst_id = h_sess.subst_id;
v_sess_buf.env_id = h_sess.env_id;
v_sess_buf.market_id = h_sess.market_id;
v_sess_buf.mod_id = h_sess.mod_id;
v_sess_buf.res_id = h_sess.res_id;
v_sess_buf.sess_disch_id = h_sess.sess_disch_id;
v_sess_buf.privs = h_sess.privs;
v_sess_buf.temp_sess_src_id = h_sess.temp_sess_src_id;
strcpy(v_sess_buf.name , h_sess.name);
strcpy(v_sess_buf.user_id , h_sess.user_id);
strcpy(v_sess_buf.cre_date , h_sess.cre_date);
strcpy(v_sess_buf.mod_date , h_sess.mod_date);
strcpy(v_sess_buf.status , h_sess.status);
strcpy(v_sess_buf.is_temp_sess, h_sess.is_temp_sess);
strcpy(v_sess_buf.temp_sess_db_sid, h_sess.temp_sess_db_sid);
strcpy(v_sess_buf.remark , h_sess.remark);
v_sess_buf.next_element = NULL;
strcpy(h_temp_user_id, vg_db_user_info.user_id);
/*
* check if source session is already marked as temp. session
*/
if (v_sess_buf.is_temp_sess[0] != DA_NO)
{
/* ERROR: session is already marked as temp. session */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_SRC_SESS;
sprintf(vp_errinfo->err_param, "%s - SESS_ID(%ld)", v_module, v_sess_buf.sess_id);
return (DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SESS_TAB, (void*) &v_sess_buf,
&v_access_right, vp_errinfo);
}
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/*
* Start to create temp. session
*/
if (h_sess.subst_id != -1)
{
/* --------------------------------------------------- *
* Copy SUBSTANCE data (SUBST_TAB/SUBST_DET_TAB)
* --------------------------------------------------- */
errln = 20;
EXEC SQL SELECT NEXTVAL('SUBST_SEQ')
INTO :h_subst_id_new;
errln = 30;
EXEC SQL INSERT INTO SUBST_TAB ( SUBST_ID, NAME, USER_ID, PRIVS,
CRE_DATE, MOD_DATE, STATUS, IS_TEMPL,
REMARK )
SELECT :h_subst_id_new, NAME,
:h_temp_user_id, PRIVS,
CRE_DATE, to_timestamp(:h_sess.mod_date,:h_fmt_date), STATUS, 'N',
REMARK
FROM SUBST_TAB
WHERE SUBST_ID = :h_sess.subst_id;
errln = 40;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 50;
EXEC SQL INSERT INTO SUBST_DET_TAB ( SUBST_ID, SUBST_DET_ID,
FIELD_ID, BLOCK_ID, BLOCK_RECNO,
VALUE_SDT, DIST_TYPE, REMARK )
SELECT :h_subst_id_new, NEXTVAL('SUBST_DET_SEQ'),
FIELD_ID, BLOCK_ID, BLOCK_RECNO,
VALUE_SDT, DIST_TYPE, REMARK
FROM SUBST_DET_TAB
WHERE SUBST_ID = :h_sess.subst_id;
errln = 60;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set new SUBST_ID in SESSION data */
h_sess.subst_id = h_subst_id_new;
}
if (h_sess.env_id != -1)
{
/* --------------------------------------------------- *
* Copy ENVIRONMENT PARAM. data (ENV_TAB/ENV_DET_TAB)
* --------------------------------------------------- */
errln = 70;
EXEC SQL SELECT NEXTVAL('ENV_SEQ')
INTO :h_env_id_new;
errln = 80;
EXEC SQL INSERT INTO ENV_TAB ( ENV_ID, NAME, USER_ID, PRIVS,
CRE_DATE, MOD_DATE, STATUS, IS_TEMPL,
REMARK )
SELECT :h_env_id_new, NAME,
:h_temp_user_id, PRIVS,
CRE_DATE, to_timestamp(:h_sess.mod_date,:h_fmt_date), STATUS,'N',
REMARK
FROM ENV_TAB
WHERE ENV_ID = :h_sess.env_id;
errln = 90;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 100;
EXEC SQL INSERT INTO ENV_DET_TAB ( ENV_ID, ENV_DET_ID,
FIELD_ID, BLOCK_ID, BLOCK_RECNO,
VALUE_EDT, DIST_TYPE, REMARK )
SELECT :h_env_id_new, NEXTVAL('ENV_DET_SEQ'),
FIELD_ID, BLOCK_ID, BLOCK_RECNO,
VALUE_EDT, DIST_TYPE, REMARK
FROM ENV_DET_TAB
WHERE ENV_ID = :h_sess.env_id;
errln = 110;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set new ENV_ID in SESSION data */
h_sess.env_id = h_env_id_new;
}
if (h_sess.mod_id != -1)
{
/* --------------------------------------------------- *
* Copy MODEL PARAM. data (MOD_TAB/MOD_DET_TAB)
* --------------------------------------------------- */
errln = 120;
EXEC SQL SELECT NEXTVAL('MOD_SEQ')
INTO :h_mod_id_new;
errln = 130;
EXEC SQL INSERT INTO MOD_TAB ( MOD_ID, NAME, USER_ID, PRIVS,
CRE_DATE, MOD_DATE, STATUS,
REMARK )
SELECT :h_mod_id_new, NAME,
:h_temp_user_id, PRIVS,
CRE_DATE, to_timestamp(:h_sess.mod_date,:h_fmt_date), STATUS,
REMARK
FROM MOD_TAB
WHERE MOD_ID = :h_sess.mod_id;
errln = 140;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 150;
EXEC SQL INSERT INTO MOD_DET_TAB ( MOD_ID, MOD_DET_ID,
FIELD_ID, BLOCK_ID, BLOCK_RECNO,
VALUE_MDT, DIST_TYPE, REMARK )
SELECT :h_mod_id_new, NEXTVAL('MOD_DET_SEQ'),
FIELD_ID, BLOCK_ID, BLOCK_RECNO,
VALUE_MDT, DIST_TYPE, REMARK
FROM MOD_DET_TAB
WHERE MOD_ID = :h_sess.mod_id;
errln = 160;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set new MOD_ID in SESSION data */
h_sess.mod_id = h_mod_id_new;
}
if (h_sess.market_id != -1)
{
/* --------------------------------------------------- *
* Copy MARKET data (MARKET_TAB)
* --------------------------------------------------- */
errln = 170;
EXEC SQL SELECT NEXTVAL('MARKET_SEQ')
INTO :h_market_id_new;
errln = 180;
EXEC SQL INSERT INTO MARKET_TAB ( MARKET_ID, DISCH_ID, CATCH_ID, NAME,
USER_ID, PRIVS, STATUS,
CRE_DATE, MOD_DATE, CONSUMPTION,
SURFACE_POTENTIAL, ROOF_RUNOFF, STREET_RUNOFF,
FLUX_NONDOM, FLUX_RUNOFF, WWTP_REMOVAL, REMARK )
SELECT :h_market_id_new, DISCH_ID, CATCH_ID, NAME,
:h_temp_user_id, PRIVS, STATUS,
CRE_DATE, to_timestamp(:h_sess.mod_date,:h_fmt_date),
CONSUMPTION, SURFACE_POTENTIAL, ROOF_RUNOFF, STREET_RUNOFF,
FLUX_NONDOM, FLUX_RUNOFF, WWTP_REMOVAL, REMARK
FROM MARKET_TAB
WHERE MARKET_ID = :h_sess.market_id
AND CATCH_ID = :h_sess.catch_id;
/* set new MARKET_ID in SESSION data */
h_sess.market_id = h_market_id_new;
}
if (h_sess.res_id != -1)
{
/* --------------------------------------------------- *
* Copy RESULT data (RES_..._TAB)
* --------------------------------------------------- */
errln = 190;
EXEC SQL SELECT NEXTVAL('RES_SEQ')
INTO :h_res_id_new;
errln = 200;
EXEC SQL INSERT INTO RES_TAB ( RES_ID,
RIVER_FACTOR, RIVER_UNIT, STP_FACTOR,
STP_UNIT, PEC_INITIAL, PEC_CATCH,
REMARK )
SELECT :h_res_id_new,
RIVER_FACTOR, RIVER_UNIT, STP_FACTOR,
STP_UNIT, PEC_INITIAL, PEC_CATCH,
REMARK
FROM RES_TAB
WHERE RES_ID = :h_sess.res_id;
errln = 210;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 220;
v_object_id = h_sess.res_id;
if (gda_get_bin_obj(db_con,
v_object_id,
v_object_type,
v_bin_obj_id,
get_file_obj,
&v_bin_obj_buf,
vp_errinfo))
{
if (v_bin_obj_buf != 0)
{
DA_T_bin_obj* v_bin_obj_cur = v_bin_obj_buf;
/* set new RES_ID for binary result detail data */
errln = 230;
while (v_bin_obj_cur != 0)
{
v_bin_obj_cur->object_id = h_res_id_new;
if (!gda_insert_bin_obj(db_con, v_bin_obj_cur, vp_errinfo))
{
/* --------------------------------------------------------- *
* Error during INSERT of binary results
* --------------------------------------------------------- */
/* set error info */
sprintf (vp_errinfo->err_param,"%s - %s", vp_errinfo->err_param, v_module);
/* record not inserted */
return(DA_FAIL);
}
v_bin_obj_cur = v_bin_obj_cur->next_element;
i++;
}
}
}
else
{
/* --------------------------------------------------------- *
* Error during GET of binary results
* --------------------------------------------------------- */
/* set error info */
sprintf (vp_errinfo->err_param,"%s - %s", vp_errinfo->err_param, v_module);
/* record not inserted */
return(DA_FAIL);
}
/* set new RES_ID in SESSION data */
h_sess.res_id = h_res_id_new;
}
if (h_sess.sess_disch_id != -1)
{
/* --------------------------------------------------- *
* Copy SESS_DISCH data (SESS_DISCH_TAB)
* --------------------------------------------------- */
errln = 250;
EXEC SQL SELECT NEXTVAL('SESS_DISCH_SEQ')
INTO :h_sess_disch_id_new;
errln = 260;
EXEC SQL INSERT INTO SESS_DISCH_TAB ( SESS_DISCH_ID, DISCH_ID, STRETCH_ID,
CATCH_ID, NAME,
USER_ID, PRIVS, STATUS,
CRE_DATE, MOD_DATE, POP,
PAVED_SURFACE, ROOF, ROOF_INDUST,
STREET,
FLOW_VAL, FLOW_DIST,
F_MIX, REMARK )
SELECT :h_sess_disch_id_new, DISCH_ID, STRETCH_ID,
CATCH_ID, NAME,
:h_temp_user_id, PRIVS, STATUS,
CRE_DATE, to_timestamp(:h_sess.mod_date,:h_fmt_date),
POP, PAVED_SURFACE,
ROOF, ROOF_INDUST, STREET,
FLOW_VAL, FLOW_DIST,
F_MIX, REMARK
FROM SESS_DISCH_TAB
WHERE SESS_DISCH_ID = :h_sess.sess_disch_id
AND CATCH_ID = :h_sess.catch_id;
/* set new SESS_DISCH_ID in SESSION data */
h_sess.sess_disch_id = h_sess_disch_id_new;
}
/* ------------------------------------------------------- *
* Insert new session record for temp. sess. into SESS_TAB
* ------------------------------------------------------- */
/* get new SESSION-ID */
errln = 270;
if (vp_sess_id_src == -1)
{
EXEC SQL SELECT NEXTVAL('SESS_SEQ'),
to_char(CURRENT_TIMESTAMP, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_sess_id_new,
:h_sess.cre_date,
:h_sess.mod_date;
}
else
{
EXEC SQL SELECT NEXTVAL('SESS_SEQ'),
to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_sess_id_new,
:h_sess.mod_date;
}
/* Take parameter as temp type */
h_sess.is_temp_sess[0]=vp_temp_type;
h_sess.is_temp_sess[1]='\0';
errln = 280;
EXEC SQL INSERT INTO SESS_TAB (SESS_ID,
CATCH_ID,
SUBST_ID,
ENV_ID,
MARKET_ID,
MOD_ID,
RES_ID,
SESS_DISCH_ID,
NAME,
USER_ID,
CRE_DATE,
MOD_DATE,
STATUS,
PRIVS,
IS_TEMP_SESS,
TEMP_SESS_SRC_ID,
REMARK)
VALUES (:h_sess_id_new,
CASE WHEN :h_sess.catch_id = -1 THEN NULL ELSE :h_sess.catch_id END,
CASE WHEN :h_sess.subst_id = -1 THEN NULL ELSE :h_sess.subst_id END,
CASE WHEN :h_sess.env_id = -1 THEN NULL ELSE :h_sess.env_id END,
CASE WHEN :h_sess.market_id = -1 THEN NULL ELSE :h_sess.market_id END,
CASE WHEN :h_sess.mod_id = -1 THEN NULL ELSE :h_sess.mod_id END,
CASE WHEN :h_sess.res_id = -1 THEN NULL ELSE :h_sess.res_id END,
CASE WHEN :h_sess.sess_disch_id = -1 THEN NULL ELSE :h_sess.sess_disch_id END,
:h_sess.name,
:h_temp_user_id,
to_timestamp(:h_sess.cre_date, :h_fmt_date),
to_timestamp(:h_sess.mod_date, :h_fmt_date),
:h_sess.status,
:h_sess.privs,
:h_sess.is_temp_sess,
:h_sess_id_src,
:h_sess.remark);
EXEC SQL SELECT OID INTO :h_sess.temp_sess_db_sid FROM SESS_TAB WHERE SESS_ID = :h_sess_id_new;
EXEC SQL UPDATE SESS_TAB SET TEMP_SESS_DB_SID = :h_sess.temp_sess_db_sid
WHERE SESS_ID = :h_sess_id_new ;
/* set return value (SESS_ID,... of created temp. session) */
h_sess.sess_id = h_sess_id_new;
*vp_sess_id_tmp = h_sess.sess_id;
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEW)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_make_temp_sess_permanent() (SESS_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Save temp. session created by "gda_create_temp_sess()" as
* permanent/none temporary session and delete source session
* (incl. details) of specified temp. session;
* Delete nothing, if no source session is existing.
*
* Parameter: vp_sess_id_temp (i) ID of session to copy
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Save temp. session created by "da_create_temp_sess()"
... as permanent/none temporary session and delete source session (incl. details) of specified temp. session; Delete nothing, if no source session is existing.
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_sess_id_tmp ID of session to copy
\return DA_SUCCESS \n DA_FAIL
*/
int gda_make_temp_sess_permanent (DB_con *db_con,
long vp_sess_id_tmp,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_make_temp_sess_permanent";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
// not used: int v_id_chk = DA_FAIL;
// not used: char v_errmsg[256];
DA_T_sess v_sess_buf;
EXEC SQL BEGIN DECLARE SECTION;
char h_fmt_date[30];
/* host variables */
long h_sess_id_qry;
char h_con_name[31];
struct DA_T_sess_pg_h{ /* type contains host variables for session data */
long sess_id;
long catch_id;
long subst_id;
long env_id;
long market_id;
long mod_id;
long res_id;
long sess_disch_id; /* added: 04-SEP-02; S.F. */
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
long privs;
char is_temp_sess [ 2];
long temp_sess_src_id;
char temp_sess_db_sid [256];
char remark [2001];
} h_sess;
struct DA_T_sess_pg_i{ /* indicator variables for host variable struct */
short int sess_id;
short int catch_id;
short int subst_id;
short int env_id;
short int market_id;
short int mod_id;
short int res_id;
short int sess_disch_id; /* added: 04-SEP-02; S.F. */
short int name;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int is_temp_sess;
short int temp_sess_src_id;
short int temp_sess_db_sid;
short int remark;
} h_ind_sess;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* Get SESSION copy source
* ---------------------------------------------
* => get ID's of detail data to copy and use selected SESSION data
* as source for the new temp. session.
* => get session data to check access rights!
*/
h_sess_id_qry = vp_sess_id_tmp;
errln = 10;
EXEC SQL SELECT SESS_ID,
CATCH_ID,
SUBST_ID,
ENV_ID,
MARKET_ID,
MOD_ID,
RES_ID,
SESS_DISCH_ID,
NAME,
USER_ID,
to_char(CRE_DATE, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date),
STATUS,
PRIVS,
IS_TEMP_SESS,
TEMP_SESS_SRC_ID,
TEMP_SESS_DB_SID,
REMARK
INTO :h_sess INDICATOR :h_ind_sess
FROM SESS_TAB
WHERE SESS_ID = :h_sess_id_qry;
/* check indicator variables (in regard to NULL values) */
if (h_ind_sess.sess_id == -1) h_sess.sess_id = -1;
if (h_ind_sess.catch_id == -1) h_sess.catch_id = -1;
if (h_ind_sess.subst_id == -1) h_sess.subst_id = -1;
if (h_ind_sess.env_id == -1) h_sess.env_id = -1;
if (h_ind_sess.market_id == -1) h_sess.market_id = -1;
if (h_ind_sess.mod_id == -1) h_sess.mod_id = -1;
if (h_ind_sess.res_id == -1) h_sess.res_id = -1;
if (h_ind_sess.sess_disch_id == -1) h_sess.sess_disch_id = -1;
if (h_ind_sess.privs == -1) h_sess.privs = 1;
if (h_ind_sess.temp_sess_src_id == -1) h_sess.temp_sess_src_id = -1;
if (h_ind_sess.name == -1) strcpy(h_sess.name, "");
if (h_ind_sess.user_id == -1) strcpy(h_sess.user_id, "");
if (h_ind_sess.cre_date == -1) strcpy(h_sess.cre_date, "");
if (h_ind_sess.mod_date == -1) strcpy(h_sess.mod_date, "");
if (h_ind_sess.status == -1) strcpy(h_sess.status, "");
if (h_ind_sess.is_temp_sess == -1) strcpy(h_sess.is_temp_sess, "N");
if (h_ind_sess.temp_sess_db_sid == -1) strcpy(h_sess.temp_sess_db_sid,"");
if (h_ind_sess.remark == -1) strcpy(h_sess.remark, "");
/* copy result into temp. buffer */
v_sess_buf.sess_id = h_sess.sess_id;
v_sess_buf.catch_id = h_sess.catch_id;
v_sess_buf.subst_id = h_sess.subst_id;
v_sess_buf.env_id = h_sess.env_id;
v_sess_buf.market_id = h_sess.market_id;
v_sess_buf.mod_id = h_sess.mod_id;
v_sess_buf.res_id = h_sess.res_id;
v_sess_buf.sess_disch_id = h_sess.sess_disch_id;
v_sess_buf.privs = h_sess.privs;
v_sess_buf.temp_sess_src_id = h_sess.temp_sess_src_id;
strcpy(v_sess_buf.name , h_sess.name);
strcpy(v_sess_buf.user_id , h_sess.user_id);
strcpy(v_sess_buf.cre_date , h_sess.cre_date);
strcpy(v_sess_buf.mod_date , h_sess.mod_date);
strcpy(v_sess_buf.status , h_sess.status);
strcpy(v_sess_buf.is_temp_sess, h_sess.is_temp_sess);
strcpy(v_sess_buf.temp_sess_db_sid, h_sess.temp_sess_db_sid);
strcpy(v_sess_buf.remark , h_sess.remark);
v_sess_buf.next_element = NULL;
/*
* check if session is a valid temp. session
*/
if (v_sess_buf.is_temp_sess[0] == DA_NO)
{
/* ERROR: session is no temp. session */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INVALID_SRC_SESS;
sprintf(vp_errinfo->err_param, "%s - SESS_ID(%ld)", v_module, v_sess_buf.sess_id);
return (DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SESS_TAB, (void*) &v_sess_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/*
* delete source session of specified temp. session
*/
if (v_sess_buf.temp_sess_src_id != -1)
{
v_status = gda_delete_sess(db_con, v_sess_buf.temp_sess_src_id, vp_errinfo);
}
if (v_status == DA_SUCCESS)
{
/*
* remove temp. flags from temp. session
*/
errln = 20;
EXEC SQL UPDATE SESS_TAB
SET MOD_DATE = to_timestamp(:h_sess.mod_date, :h_fmt_date),
IS_TEMP_SESS = 'N',
TEMP_SESS_SRC_ID = -1,
TEMP_SESS_DB_SID = NULL
WHERE SESS_ID = :h_sess_id_qry;
}
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEW)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_cleanup_temp_sess (SESS_TAB)
*
* Issue : 16-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Delete all client temporary sessions from database, which
* are linked to database sessions that do not exist anymore;
* delete also web temporary sessions older than 2 days.
*
* Parameter: vp_errinfo (o) Error info in case error occured
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete all client temporary sessions from database,
... which are linked to database sessions that do not exist anymore; delete also web temporary sessions older than 2 days.
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 16-AUG-2002
\param db_con Pointer to connection
\return DA_SUCCESS \n DA_FAIL
*/
int gda_cleanup_temp_sess(DB_con *db_con, DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_cleanup_temp_sess";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
/* not used:
struct DA_T_sess_pg_h{ // type contains host variables for session data
long sess_id;
long catch_id;
long subst_id;
long env_id;
long market_id;
long mod_id;
long res_id;
long sess_disch_id; // added: 04-SEP-02; S.F.
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
long privs;
char is_temp_sess [ 2];
long temp_sess_src_id;
char temp_sess_db_sid [256];
char remark [2001];
} h_sess;
*/
/* not used:
struct DA_T_sess_pg_i{ // indicator variables for host variable struct
short int sess_id;
short int catch_id;
short int subst_id;
short int env_id;
short int market_id;
short int mod_id;
short int res_id;
short int sess_disch_id; // added: 04-SEP-02; S.F.
short int name;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int is_temp_sess;
short int temp_sess_src_id;
short int temp_sess_db_sid;
short int remark;
} h_ind_sess;
*/
char h_user_id[31];
long h_sess_id;
char h_temp_sess_db_sid[256];
char h_is_temp_sess;
short int h_ind_sess_id;
short int h_ind_temp_sess_db_sid;
short int h_ind_is_temp_sess;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_user_id, vg_db_user_info.user_id);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
errln = 10;
EXEC SQL DECLARE temp_sess_csr CURSOR FOR
SELECT SESS_ID,
TEMP_SESS_DB_SID,
IS_TEMP_SESS
FROM SESS_TAB
WHERE ((IS_TEMP_SESS = 'Y' AND MOD_DATE < (CURRENT_TIMESTAMP-7)) OR
(IS_TEMP_SESS = 'W' AND MOD_DATE < (CURRENT_TIMESTAMP-3)) )
AND USER_ID = :h_user_id;
errln = 20;
EXEC SQL OPEN temp_sess_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_of_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH temp_sess_csr INTO :h_sess_id INDICATOR :h_ind_sess_id,
:h_temp_sess_db_sid INDICATOR :h_ind_temp_sess_db_sid,
:h_is_temp_sess INDICATOR :h_ind_is_temp_sess;
/* delete web temporary session without alive check */
errln = 50;
if (h_is_temp_sess == DA_WEB)
{
v_status = gda_delete_sess( db_con, h_sess_id, vp_errinfo);
}
else
{
/* check if db-session of temp. GREAT-ER session is alive */
errln = 60;
if (h_temp_sess_db_sid)
{
/*
* Temp. GREAT-ER session is linked to a none existing db-session
* => delete temp. GREAT-ER session.
*/
v_status = gda_delete_sess( db_con, h_sess_id , vp_errinfo);
}
}
} /* end: while(v_status == DA_SUCCESS) */
end_of_loop:
return (v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_sess (SESS_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_sess()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_sess (i) pointer to "list of" session records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_sess()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param vp_sess pointer to "list of" session records
\return ---
*/
void gda_free_sess(DA_T_sess *vp_sess)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_sess";
#endif
/* pointer to list elements */
DA_T_sess *v_next_elem_ptr = NULL;
DA_T_sess *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_sess;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: SESS_DISCH_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_sess_disch (SESS_DISCH_TAB)
*
* Issue : 04-SEP-2002 - S.F. - TechniData AG/Markdorf
*
* Purpose : Get list of session data from SESS_DISCH_TAB ordered by
* SESS_DISCH_ID
*
* Query conditions:
* a) catch_id <> -1 or = -1
* disch_id = -1 or <> -1
* sess_disch_id = -1 or = -1
* => return: 1..n records!
*
* b) catch_id <> -1
* disch_id <> -1
* sess_disch_id <> -1
* => return: 1 record!
*
* Parameter: vp_catch_id (i) ID of catchment to which session discharge
* data belong
* vp_disch_id (i) ID of disch to which session discharge
* data belong
* vp_sess_disch_id (i) ID of session discharge data record
* vp_sess_disch (o) Return value (list of session discharge data)
* vp_errinfo (o) Error info in case of error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of session data from SESS_DISCH_TAB ordered by SESS_DISCH_ID.
Query conditions:
catch_id <> -1 or = -1 \n disch_id = -1 or <> -1 \n sess_disch_id = -1 or = -1 \n => return: 1..n records!
catch_id <> -1 \n disch_id <> -1 \n sess_disch_id <> -1 \n => return: 1 record!
Output:
vp_sess_disch - Return value (list of session discharge data)
vp_errinfo - Error info in case of error occured
\author S.F. - TechniData AG/Markdorf \n H.K. - Intevation
\date 04-SEP-2002
\param db_con Pointer to connection
\param vp_catch_id ID of catchment to which session discharge data belong
\param vp_disch_id ID of disch to which session discharge data belong
\param vp_sess_disch_id ID of session discharge data record
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_sess_disch (DB_con *db_con,
long vp_catch_id,
long vp_disch_id,
long vp_sess_disch_id,
DA_T_sess_disch **vp_sess_disch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_sess_disch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_sess_disch v_sess_disch_buf;
/* pointer to list root */
DA_T_sess_disch *v_root_lst_ptr = NULL;
/* pointer to list element */
DA_T_sess_disch *v_new_elem_ptr = NULL;
DA_T_sess_disch *v_last_elem_ptr = NULL;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_fmt_date [ 30];
char h_con_name [ 31];
char h_where_clause [100];
char h_query [2000];
struct DA_T_sess_disch_pg_h{ /* type contains host variables for object data */
long sess_disch_id;
long disch_id;
long stretch_id;
long catch_id;
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char pop [ 41];
char paved_surface[41];
char roof [ 41];
char roof_indust[ 41];
char street [ 41];
char flow_val [256];
char flow_dist [ 12];
char f_mix [ 41];
char remark[2001];
} h_sess_disch;
struct DA_T_sess_disch_pg_i{ /* indicator variables for host variable struct */
short int sess_disch_id;
short int disch_id;
short int stretch_id;
short int catch_id;
short int name;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int pop;
short int paved_surface;
short int roof;
short int roof_indust;
short int street;
short int flow_val;
short int flow_dist;
short int f_mix;
short int remark;
} h_ind_sess_disch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/*
* determine query condition
* a) catch_id <> -1 or = -1
* disch_id = -1 or <> -1
* sess_disch_id = -1 or = -1 => return: 1..n records!
* b) catch_id <> -1
* disch_id <> -1
* sess_disch_id <> -1 => return: 1 record!
*/
if (vp_catch_id != -1 && vp_disch_id != -1 && vp_sess_disch_id != -1)
sprintf(h_where_clause,"WHERE CATCH_ID = %ld AND DISCH_ID = %ld AND SESS_DISCH_ID = %ld ",
vp_catch_id, vp_disch_id, vp_sess_disch_id);
else if (vp_catch_id != -1 && vp_disch_id != -1 && vp_sess_disch_id == -1)
sprintf(h_where_clause,"WHERE CATCH_ID = %ld AND DISCH_ID = %ld ", vp_catch_id, vp_disch_id);
else if (vp_catch_id != -1 && vp_disch_id == -1 && vp_sess_disch_id != -1)
sprintf(h_where_clause,"WHERE CATCH_ID = %ld AND SESS_DISCH_ID = %ld ", vp_catch_id, vp_sess_disch_id);
else if (vp_catch_id == -1 && vp_disch_id != -1 && vp_sess_disch_id != -1)
sprintf(h_where_clause,"WHERE DISCH_ID = %ld AND SESS_DISCH_ID = %ld ", vp_disch_id, vp_sess_disch_id);
else if (vp_catch_id != -1 && vp_disch_id == -1 && vp_sess_disch_id == -1)
sprintf(h_where_clause,"WHERE CATCH_ID = %ld ", vp_catch_id);
else if (vp_catch_id == -1 && vp_disch_id == -1 && vp_sess_disch_id != -1)
sprintf(h_where_clause,"WHERE SESS_DISCH_ID = %ld ", vp_sess_disch_id);
else if (vp_catch_id == -1 && vp_disch_id != -1 && vp_sess_disch_id == -1)
sprintf(h_where_clause,"WHERE DISCH_ID = %ld ", vp_disch_id);
else
strcpy (h_where_clause, "");
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the session from SESS_DISCH_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT SESS_DISCH_ID,"
"DISCH_ID,"
"STRETCH_ID,"
"CATCH_ID,"
"NAME,"
"USER_ID,"
"to_char(CRE_DATE, '%s'),"
"to_char(MOD_DATE, '%s'),"
"STATUS,"
"PRIVS,"
"POP,"
"PAVED_SURFACE,"
"ROOF,"
"ROOF_INDUST,"
"STREET,"
"FLOW_VAL,"
"FLOW_DIST,"
"F_MIX,"
"REMARK "
"FROM SESS_DISCH_TAB "
"%s "
"ORDER BY SESS_DISCH_ID",
h_fmt_date, h_fmt_date, h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE sess_disch_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN sess_disch_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH sess_disch_csr INTO :h_sess_disch INDICATOR :h_ind_sess_disch;
/* check indicator variables (in regard to NULL values) */
if (h_ind_sess_disch.sess_disch_id == -1) h_sess_disch.sess_disch_id = -1;
if (h_ind_sess_disch.disch_id == -1) h_sess_disch.disch_id = -1;
if (h_ind_sess_disch.stretch_id == -1) h_sess_disch.stretch_id = -1;
if (h_ind_sess_disch.catch_id == -1) h_sess_disch.catch_id = -1;
if (h_ind_sess_disch.privs == -1) h_sess_disch.privs = 1;
if (h_ind_sess_disch.name == -1) strcpy(h_sess_disch.name, "");
if (h_ind_sess_disch.user_id == -1) strcpy(h_sess_disch.user_id, "");
if (h_ind_sess_disch.cre_date == -1) strcpy(h_sess_disch.cre_date, "");
if (h_ind_sess_disch.mod_date == -1) strcpy(h_sess_disch.mod_date, "");
if (h_ind_sess_disch.status == -1) strcpy(h_sess_disch.status, "");
if (h_ind_sess_disch.pop == -1) strcpy(h_sess_disch.pop, "");
if (h_ind_sess_disch.paved_surface == -1) strcpy(h_sess_disch.paved_surface, "");
if (h_ind_sess_disch.roof == -1) strcpy(h_sess_disch.roof, "");
if (h_ind_sess_disch.roof_indust == -1) strcpy(h_sess_disch.roof_indust, "");
if (h_ind_sess_disch.street == -1) strcpy(h_sess_disch.street, "");
if (h_ind_sess_disch.flow_val == -1) strcpy(h_sess_disch.flow_val, "");
if (h_ind_sess_disch.flow_dist == -1) strcpy(h_sess_disch.flow_dist, "");
if (h_ind_sess_disch.f_mix == -1) strcpy(h_sess_disch.f_mix, "");
if (h_ind_sess_disch.remark == -1) strcpy(h_sess_disch.remark, "");
/* copy result into temp. buffer */
v_sess_disch_buf.sess_disch_id = h_sess_disch.sess_disch_id;
v_sess_disch_buf.disch_id = h_sess_disch.disch_id;
v_sess_disch_buf.stretch_id = h_sess_disch.stretch_id;
v_sess_disch_buf.catch_id = h_sess_disch.catch_id;
v_sess_disch_buf.privs = h_sess_disch.privs;
strcpy(v_sess_disch_buf.name , h_sess_disch.name);
strcpy(v_sess_disch_buf.user_id , h_sess_disch.user_id);
strcpy(v_sess_disch_buf.cre_date , h_sess_disch.cre_date);
strcpy(v_sess_disch_buf.mod_date , h_sess_disch.mod_date);
strcpy(v_sess_disch_buf.status , h_sess_disch.status);
strcpy(v_sess_disch_buf.pop , h_sess_disch.pop);
strcpy(v_sess_disch_buf.paved_surface , h_sess_disch.paved_surface);
strcpy(v_sess_disch_buf.roof , h_sess_disch.roof);
strcpy(v_sess_disch_buf.roof_indust , h_sess_disch.roof_indust);
strcpy(v_sess_disch_buf.street , h_sess_disch.street);
strcpy(v_sess_disch_buf.flow_val , h_sess_disch.flow_val);
strcpy(v_sess_disch_buf.flow_dist , h_sess_disch.flow_dist);
strcpy(v_sess_disch_buf.f_mix , h_sess_disch.f_mix);
strcpy(v_sess_disch_buf.remark , h_sess_disch.remark);
v_sess_disch_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SESS_DISCH_TAB, (void*) &v_sess_disch_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_sess_disch*) malloc( sizeof(DA_T_sess_disch) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf (vp_errinfo->err_param,"%s - malloc(DA_T_sess_disch)", v_module);
/* release already allocated memory */
gda_free_sess_disch(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_sess_disch) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_sess_disch_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE sess_disch_csr;
/* return created result list */
(*vp_sess_disch) = v_root_lst_ptr;
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE sess_disch_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_sess_disch (SESS_DISCH_TAB)
*
* Issue : 05-SEP-2002 - S.F. - TechniData AG/Markdorf
*
* Purpose : Insert record into SES_DISCH_TAB. Return new "SESS_DISCH_ID"
* by passed struct, in case insert could successfully be done.
*
* The new (inserted) session discharge record will be
* automatically linked to the specified session, because a
* session discharge record must always be linked to a session!
*
* Parameter: vp_sess_disch (i/o) data to insert into SESS_DISCH_TAB,
* OUTPUT: (->SESS_DISCH_ID)
* a) When record was first sess disch record
* for specified session:
* -> SESS_DISCH_ID =
* cre_date = CURRENT_TIMESTAMP
* mod_date = CURRENT_TIMESTAMP
* user_id =
*
* a) When record was additional sess disch
* record for specified session:
* -> SESS_DISCH_ID = SESS_TAB.SESS_DISCH_ID
* cre_date = CURRENT_TIMESTAMP
* mod_date = CURRENT_TIMESTAMP
* user_id =
*
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
* vg_db_user_info(i) -> general information about database
* user of current db-session
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into SES_DISCH_TAB.
Return new "SESS_DISCH_ID" by passed struct, in case insert could successfully be done. The new (inserted) session discharge record will be automatically linked to the specified session, because a session discharge record must always be linked to a session!
Output: (->SESS_DISCH_ID)
When record was first sess disch record for specified session: \n SESS_DISCH_ID = \n cre_date = CURRENT_TIMESTAMP \n mod_date = CURRENT_TIMESTAMP
When record was additional sess disch record for specified session: \n SESS_DISCH_ID = SESS_TAB.SESS_DISCH_ID \n cre_date = CURRENT_TIMESTAMP \n mod_date = CURRENT_TIMESTAMP \n user_id =
vp_errinfo - Error info in case of error occured
\author S.F. - TechniData AG/Markdorf \n H.K. - Intevation
\date 05-SEP-2002
\param db_con Pointer to connection
\param vp_sess_id data to insert into SESS_DISCH_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_sess_disch (DB_con *db_con,
long vp_sess_id,
DA_T_sess_disch *vp_sess_disch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_sess_disch";
int v_status = DA_SUCCESS;
int v_access_right = DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_sess_id_qry;
long h_sess_disch_id_new;
char h_fmt_date[30];
short int h_ind_sess_disch_id_new;
char h_con_name[31];
struct DA_T_sess_disch_pg_h{ /* type contains host variables for object data */
long sess_disch_id;
long disch_id;
long stretch_id;
long catch_id;
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char pop [ 41];
char paved_surface[41];
char roof [ 41];
char roof_indust[ 41];
char street [ 41];
char flow_val [256];
char flow_dist [ 12];
char f_mix [ 41];
char remark[2001];
} h_sess_disch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/* current db-user becomes owner of the new data -> acc. rhgt=VIEW+EDIT */
v_access_right = DA_A_VIEWEDIT;
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* get new SESS_DISCH_ID for record to insert
*/
/* a) check for already existing "session discharge record" in SESS_DISCH_TAB
* that are linked to specified session */
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO get_new_id_from_sequence;
h_sess_id_qry = vp_sess_id;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
errln = 20;
EXEC SQL SELECT S.SESS_DISCH_ID,
to_char(CURRENT_TIMESTAMP, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_sess_disch_id_new INDICATOR :h_ind_sess_disch_id_new,
:h_sess_disch.cre_date,
:h_sess_disch.mod_date
FROM SESS_TAB S,
SESS_DISCH_TAB M
WHERE S.SESS_ID = :h_sess_id_qry
AND M.SESS_DISCH_ID = S.SESS_DISCH_ID
LIMIT 1;
if (NULL)
{
get_new_id_from_sequence:
/* b) first sess_disch record will be inserted for spec. session
* => get new sess_disch id */
errln = 30;
EXEC SQL SELECT NEXTVAL('SESS_DISCH_SEQ'),
to_char(CURRENT_TIMESTAMP, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_sess_disch_id_new,
:h_sess_disch.cre_date,
:h_sess_disch.mod_date;
/* link record to current session */
errln = 40;
EXEC SQL UPDATE SESS_TAB
SET SESS_DISCH_ID = :h_sess_disch_id_new
WHERE SESS_ID = :h_sess_id_qry;
}
/*
* copy passed record into host variable
*/
h_sess_disch.sess_disch_id = h_sess_disch_id_new;
h_sess_disch.disch_id = vp_sess_disch->disch_id;
h_sess_disch.stretch_id = vp_sess_disch->stretch_id;
h_sess_disch.catch_id = vp_sess_disch->catch_id;
h_sess_disch.privs = vp_sess_disch->privs;
strcpy(h_sess_disch.name , vp_sess_disch->name);
strcpy(h_sess_disch.user_id , vg_db_user_info.user_id);
strcpy(h_sess_disch.status , vp_sess_disch->status);
strcpy(h_sess_disch.pop , vp_sess_disch->pop);
strcpy(h_sess_disch.paved_surface , vp_sess_disch->paved_surface);
strcpy(h_sess_disch.roof , vp_sess_disch->roof);
strcpy(h_sess_disch.roof_indust , vp_sess_disch->roof_indust);
strcpy(h_sess_disch.street , vp_sess_disch->street);
strcpy(h_sess_disch.flow_val , vp_sess_disch->flow_val);
strcpy(h_sess_disch.flow_dist , vp_sess_disch->flow_dist);
strcpy(h_sess_disch.f_mix , vp_sess_disch->f_mix);
strcpy(h_sess_disch.remark , vp_sess_disch->remark);
/* Insert passed record */
errln = 50;
EXEC SQL INSERT INTO SESS_DISCH_TAB ( SESS_DISCH_ID,
DISCH_ID,
STRETCH_ID,
CATCH_ID,
NAME,
USER_ID,
CRE_DATE,
MOD_DATE,
STATUS,
PRIVS,
POP,
PAVED_SURFACE,
ROOF,
ROOF_INDUST,
STREET,
FLOW_VAL,
FLOW_DIST,
F_MIX,
REMARK )
VALUES ( :h_sess_disch.sess_disch_id,
:h_sess_disch.disch_id,
:h_sess_disch.stretch_id,
:h_sess_disch.catch_id,
:h_sess_disch.name,
:h_sess_disch.user_id,
to_timestamp(:h_sess_disch.cre_date, :h_fmt_date),
to_timestamp(:h_sess_disch.mod_date, :h_fmt_date),
:h_sess_disch.status,
:h_sess_disch.privs,
:h_sess_disch.pop,
:h_sess_disch.paved_surface,
:h_sess_disch.roof,
:h_sess_disch.roof_indust,
:h_sess_disch.street,
:h_sess_disch.flow_val,
:h_sess_disch.flow_dist,
:h_sess_disch.f_mix,
:h_sess_disch.remark);
/* set return value (created SESS_DISCH_ID,...) into passed struct/record */
vp_sess_disch->sess_disch_id = h_sess_disch_id_new;
strcpy(vp_sess_disch->user_id, h_sess_disch.user_id);
strcpy(vp_sess_disch->cre_date, h_sess_disch.cre_date);
strcpy(vp_sess_disch->mod_date, h_sess_disch.mod_date);
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_sess_disch (SESS_DISCH_TAB)
*
* Issue : 05-SEP-2002 - S.F. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by SESS_DISCH_ID) in SESS_DISCH_TAB
* by data of passed record.
*
* Parameter: vp_sess_disch (i) new session discharge data, containing
* SESS_DISCH_ID of record to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by SESS_DISCH_ID) in SESS_DISCH_TAB by data of passed record.
calls gda_update_sess_disch.
Output:
vp_errinfo - Error info in case of error occured
\author S.F. - TechniData AG/Markdorf \n H.K. - Intevation
\date 05-SEP-2002
\param db_con Pointer to connection
\param vp_sess_disch new session discharge data, containing SESS_DISCH_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_sess_disch (DB_con *db_con,
DA_T_sess_disch *vp_sess_disch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_sess_disch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_catch_id_qry;
long h_disch_id_qry;
long h_sess_disch_id_qry;
char h_fmt_date[30];
char h_con_name[31];
struct DA_T_sess_disch_pg_h{ /* type contains host variables for object data */
long sess_disch_id;
long disch_id;
long stretch_id;
long catch_id;
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char pop [ 41];
char paved_surface[41];
char roof [ 41];
char roof_indust[ 41];
char street [ 41];
char flow_val [256];
char flow_dist [ 12];
char f_mix [ 41];
char remark[2001];
} h_sess_disch;
short int h_ind_mod_date;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SESS_DISCH_TAB, (void*) vp_sess_disch,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_sess_disch.sess_disch_id = vp_sess_disch->sess_disch_id;
h_sess_disch.disch_id = vp_sess_disch->disch_id;
h_sess_disch.stretch_id = vp_sess_disch->stretch_id;
h_sess_disch.catch_id = vp_sess_disch->catch_id;
h_sess_disch.privs = vp_sess_disch->privs;
strcpy(h_sess_disch.name , vp_sess_disch->name);
strcpy(h_sess_disch.user_id , vp_sess_disch->user_id);
strcpy(h_sess_disch.cre_date , vp_sess_disch->cre_date);
strcpy(h_sess_disch.mod_date , vp_sess_disch->mod_date);
strcpy(h_sess_disch.status , vp_sess_disch->status);
strcpy(h_sess_disch.pop , vp_sess_disch->pop);
strcpy(h_sess_disch.paved_surface, vp_sess_disch->paved_surface);
strcpy(h_sess_disch.roof , vp_sess_disch->roof);
strcpy(h_sess_disch.roof_indust , vp_sess_disch->roof_indust);
strcpy(h_sess_disch.street , vp_sess_disch->street);
strcpy(h_sess_disch.flow_val , vp_sess_disch->flow_val);
strcpy(h_sess_disch.flow_dist , vp_sess_disch->flow_dist);
strcpy(h_sess_disch.f_mix , vp_sess_disch->f_mix);
strcpy(h_sess_disch.remark , vp_sess_disch->remark);
/* Update passed record in database */
h_catch_id_qry = vp_sess_disch->catch_id;
h_disch_id_qry = vp_sess_disch->disch_id;
h_sess_disch_id_qry = vp_sess_disch->sess_disch_id;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
errln = 10;
EXEC SQL SELECT to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_sess_disch.mod_date INDICATOR :h_ind_mod_date;
if (h_ind_mod_date == -1)
{
strcpy(h_sess_disch.mod_date,"");
}
/* ignore CRE_DATE for update */
errln = 20;
EXEC SQL UPDATE SESS_DISCH_TAB
SET SESS_DISCH_ID = :h_sess_disch.sess_disch_id,
DISCH_ID = :h_sess_disch.disch_id,
STRETCH_ID = :h_sess_disch.stretch_id,
CATCH_ID = :h_sess_disch.catch_id,
NAME = :h_sess_disch.name,
USER_ID = :h_sess_disch.user_id,
MOD_DATE = to_timestamp(:h_sess_disch.mod_date, :h_fmt_date),
STATUS = :h_sess_disch.status,
PRIVS = :h_sess_disch.privs,
POP = :h_sess_disch.pop,
PAVED_SURFACE = :h_sess_disch.paved_surface,
ROOF = :h_sess_disch.roof,
ROOF_INDUST = :h_sess_disch.roof_indust,
STREET = :h_sess_disch.street,
FLOW_VAL = :h_sess_disch.flow_val,
FLOW_DIST = :h_sess_disch.flow_dist,
F_MIX = :h_sess_disch.f_mix,
REMARK = :h_sess_disch.remark
WHERE CATCH_ID = :h_catch_id_qry
AND DISCH_ID = :h_disch_id_qry
AND SESS_DISCH_ID = :h_sess_disch_id_qry;
/* return new MOD_DATE */
strcpy(vp_sess_disch->mod_date, h_sess_disch.mod_date);
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_sess_disch (SESS_DISCH_TAB)
*
* Issue : 04-SEP-2002 - S.F. - TechniData AG/Markdorf
*
* Purpose : Delete record from SESS_DISCH_TAB specified by "sess_disch_id"
*
* Delete condition:
* ------------------
* CATCH_ID > 0, DISCH_ID > 0, SESS_DISCH_ID > 0
*
* Parameter: vp_sess_disch_id (i) SESS_DISCH_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from SESS_DISCH_TAB specified by "sess_disch_id".
Delete condition:
CATCH_ID > 0 DISCH_ID > 0 SESS_DISCH_ID > 0
Output:
vp_errinfo - Error info in case of error occured
\author S.F. - TechniData AG/Markdorf \n H.K. - Intevation
\date 04-SEP-2002
\param db_con Pointer to connection
\param vp_catch_id CATCH_ID of record to delete
\param vp_disch_id DISCH_ID of record to delete
\param vp_sess_disch_id SESS_DISCH_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_sess_disch (DB_con *db_con,
long vp_catch_id,
long vp_disch_id,
long vp_sess_disch_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_delete_sess_disch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
DA_T_sess_disch v_sess_disch_buf;
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
/* host variables */
struct DA_T_sess_disch_pg_h{ /* type contains host variables for object data */
long sess_disch_id;
long disch_id;
long stretch_id;
long catch_id;
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char pop [ 41];
char paved_surface[41];
char roof [ 41];
char roof_runoff[ 41];
char street [ 41];
char flow_val [256];
char flow_dist [ 12];
char f_mix [ 41];
char remark[2001];
} h_sess_disch;
long h_count;
struct DA_T_sess_disch_pg_i{ /* indicator variables for host variable struct */
short int sess_disch_id;
short int disch_id;
short int stretch_id;
short int catch_id;
short int name;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int pop;
short int paved_surface;
short int roof;
short int roof_runoff;
short int street;
short int flow_val;
short int flow_dist;
short int f_mix;
short int remark;
} h_ind_sess_disch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* get access right for data */
h_sess_disch.catch_id = vp_catch_id;
h_sess_disch.disch_id = vp_disch_id;
h_sess_disch.sess_disch_id = vp_sess_disch_id;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
errln = 10;
EXEC SQL SELECT USER_ID,
PRIVS
INTO :h_sess_disch.user_id INDICATOR :h_ind_sess_disch.user_id,
:h_sess_disch.privs INDICATOR :h_ind_sess_disch.privs
FROM SESS_DISCH_TAB
WHERE SESS_DISCH_ID = :h_sess_disch.sess_disch_id
AND CATCH_ID = :h_sess_disch.catch_id
AND DISCH_ID = :h_sess_disch.disch_id;
/* check indicator variables (in regard to NULL values) */
if (h_ind_sess_disch.privs == -1) h_sess_disch.privs = 1;
if (h_ind_sess_disch.user_id == -1) strcpy(h_sess_disch.user_id, "");
/* copy result into temp. buffer */
v_sess_disch_buf.sess_disch_id = h_sess_disch.sess_disch_id;
v_sess_disch_buf.disch_id = h_sess_disch.disch_id;
v_sess_disch_buf.catch_id = h_sess_disch.catch_id;
v_sess_disch_buf.privs = h_sess_disch.privs;
strcpy(v_sess_disch_buf.user_id , h_sess_disch.user_id);
v_sess_disch_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SESS_DISCH_TAB, (void*) &v_sess_disch_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* delete specified record */
errln = 10;
EXEC SQL DELETE FROM SESS_DISCH_TAB
WHERE SESS_DISCH_ID = :h_sess_disch.sess_disch_id
AND CATCH_ID = :h_sess_disch.catch_id
AND DISCH_ID = :h_sess_disch.disch_id;
/* check if record was the last SESS_DISCH record for linked
master record in SESS_TAB. In case it was, then RESET reference
to SESS_DISCH_ID in SESS_TAB */
errln = 20;
EXEC SQL SELECT COUNT(SESS_DISCH_ID)
INTO :h_count
FROM SESS_DISCH_TAB
WHERE SESS_DISCH_ID = :h_sess_disch.sess_disch_id;
if (h_count == 0)
{
/* last SESS_DISCH record was deleted -> reset ref. at master rec. */
errln = 30;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 40;
EXEC SQL UPDATE SESS_TAB
SET SESS_DISCH_ID = NULL
WHERE SESS_DISCH_ID = :h_sess_disch.sess_disch_id;
}
/* record successfully deleted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not deleted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_sess_disch (SESS_DISCH_TAB)
*
* Issue : 04-SEP-2002 - S.F. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_sess_disch()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_sess_disch (i) pointer to "list of" session discharge
* records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_sess_disch()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author S.F. - TechniData AG/Markdorf \n H.K. - Intevation
\date 04-SEP-2002
\param vp_sess_disch pointer to "list of" session discharge records
\return ---
*/
void gda_free_sess_disch (DA_T_sess_disch *vp_sess_disch)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "da_free_sess_disch";
#endif
/* pointer to list elements */
DA_T_sess_disch *v_next_elem_ptr = NULL;
DA_T_sess_disch *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_sess_disch;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: SUBST_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_subst (SUBST_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of substance data from SUBST_TAB order by SUBST_ID
*
* Query conditions:
* a) subst_id =-1, is_templ='Y' return: 1..n records (templates)
* subst_id =-1, is_templ='N' return: 1..n records (non-templ.)
* (is_tepml=DA_ALL -> ignore is_templ for selection!)
*
* b) subst_id<>-1, is_templ='Y' return: 1 record (template)
* subst_id<>-1, is_templ='N' return: 1 record (non-templ.)
* (is_tepml=DA_ALL -> ignore is_templ for selection!)
*
* Parameter: vp_subst_id (i) ID of substance to select
* vp_is_templ (i) 'Y' => select templates only
* 'N' => select non-templates only
* vp_subst (o) Return value (list of substances)
* vp_errinfo (o) Error info in case of error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of substance data from SUBST_TAB order by SUBST_ID.
Query conditions:
subst_id =-1, is_templ='Y' return: 1..n records (templates) \n
subst_id =-1, is_templ='N' return: 1..n records (non-templ.)\n
(is_tepml=DA_ALL -> ignore is_templ for selection!)
subst_id<>-1, is_templ='Y' return: 1 record (template) \n
subst_id<>-1, is_templ='N' return: 1 record (non-templ.)\n
(is_tepml=DA_ALL -> ignore is_templ for selection!)
Output:
vp_subst - Return value (list of substances)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_subst_id ID of substance to select
\param vp_is_templ 'Y' => select templates only \n 'N' => select non-templates only
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_subst (DB_con *db_con,
long vp_subst_id,
char vp_is_templ,
DA_T_subst **vp_subst,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_subst";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_subst v_subst_buf;
/* pointer to list root */
DA_T_subst *v_root_lst_ptr = NULL;
/* pointer to list element */
DA_T_subst *v_new_elem_ptr = NULL;
DA_T_subst *v_last_elem_ptr = NULL;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_is_templ_qry[ 2];
char h_fmt_date [ 30];
char h_con_name [ 31];
char h_where_clause[100];
char h_query [2000];
struct DA_T_subst_pg_h{ /* type contains host variables for object data */
long subst_id;
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char is_templ [ 2];
char remark [2001];
} h_subst;
struct DA_T_subst_pg_i{ /* indicator variables for host variable struct */
short int subst_id;
short int name;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int is_templ;
short int remark;
} h_ind_subst;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/*
* determine query condition
* a) subst_id =-1, is_templ='Y' return: 1..n records (templates)
* subst_id =-1, is_templ='N' return: 1..n records (non-templ.)
* (is_tepml=DA_ALL -> ignore is_templ for selection!)
*
* b) subst_id<>-1, is_templ='Y' return: 1 record (template)
* subst_id<>-1, is_templ='N' return: 1 record (non-templ.)
* (is_tepml=DA_ALL -> ignore is_templ for selection!)
*/
if (vp_subst_id == -1)
{
/* case a) */
strcpy (h_where_clause, "");
}
else
{
/* case b) */
sprintf(h_where_clause,"SUBST_ID = %ld AND ", vp_subst_id);
}
sprintf(h_is_templ_qry, "%c", vp_is_templ);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the session from SUBST_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT SUBST_ID,"
"NAME,"
"USER_ID,"
"to_char(CRE_DATE, '%s'),"
"to_char(MOD_DATE, '%s'),"
"STATUS,"
"PRIVS,"
"IS_TEMPL,"
"REMARK "
"FROM SUBST_TAB "
"WHERE %s IS_TEMPL LIKE '%s' "
"ORDER BY SUBST_ID",
h_fmt_date, h_fmt_date, h_where_clause, h_is_templ_qry);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE subst_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN subst_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH subst_csr INTO :h_subst INDICATOR :h_ind_subst;
/* check indicator variables (in regard to NULL values) */
if (h_ind_subst.subst_id == -1) h_subst.subst_id = -1;
if (h_ind_subst.privs == -1) h_subst.privs = 1;
if (h_ind_subst.name == -1) strcpy(h_subst.name, "");
if (h_ind_subst.user_id == -1) strcpy(h_subst.user_id, "");
if (h_ind_subst.cre_date == -1) strcpy(h_subst.cre_date, "");
if (h_ind_subst.mod_date == -1) strcpy(h_subst.mod_date, "");
if (h_ind_subst.status == -1) strcpy(h_subst.status, "");
if (h_ind_subst.is_templ == -1) strcpy(h_subst.is_templ, "");
if (h_ind_subst.remark == -1) strcpy(h_subst.remark, "");
/* copy result into temp. buffer */
v_subst_buf.subst_id = h_subst.subst_id;
v_subst_buf.privs = h_subst.privs;
strcpy (v_subst_buf.name , h_subst.name);
strcpy (v_subst_buf.user_id , h_subst.user_id);
strcpy (v_subst_buf.cre_date , h_subst.cre_date);
strcpy (v_subst_buf.mod_date , h_subst.mod_date);
strcpy (v_subst_buf.status , h_subst.status);
strcpy (v_subst_buf.is_templ , h_subst.is_templ);
strcpy (v_subst_buf.remark , h_subst.remark);
v_subst_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SUBST_TAB, (void*) &v_subst_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_subst*) malloc( sizeof(DA_T_subst) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf (vp_errinfo->err_param,"%s - malloc(DA_T_subst)", v_module);
/* release already allocated memory */
gda_free_subst(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_subst) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_subst_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE subst_csr;
/* return created result list */
(*vp_subst) = v_root_lst_ptr;
/* success fully connected to database */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE subst_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_get_subst_search (SUBST_TAB, SUBST_DET_TAB)
*
* Issue : 04-NOV-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Get list of subst data from SUBST_TAB and SUBST_DET_TAB,
* filtered by NAME, REMARK in SUBST_TAB and the content of
* the VALUE-field in SUBST_DET_TAB where FIELD_ID = passed
* FIELD_ID.
* If a parameter is NULL ignore it in SELECT-statement.
*
* Parameter: vp_name (i) Name of substance(s) to select
* vp_remark (i) Remark of substance(s) to select
* vp_field_id (i) Specifies the third search criterium
* vp_detail_value (i) Search text for the third search
* criterium
* vp_subst_result (o) Return value (list of substances)
* vp_errinfo (o) Error info in case of error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of subst data from SUBST_TAB and SUBST_DET_TAB,
filtered by NAME, REMARK in SUBST_TAB and the content of the VALUE-field in SUBST_DET_TAB where FIELD_ID = passed FIELD_ID. If a parameter is NULL ignore it in SELECT-statement.
Output:
vp_subst_result - Return value (list of substances)
vp_errinfo - Error info in case of error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 04-NOV-2002
\param db_con Pointer to connection
\param vp_name Name of substance(s) to select
\param vp_remark Remark of substance(s) to select
\param vp_field_id Specifies the third search criterium
\param vp_detail_value Search text for the third search criterium
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_subst_search (DB_con *db_con,
char *vp_name,
char *vp_remark,
char *vp_field_id,
char *vp_detail_value,
DA_T_subst_result **vp_subst_result,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_subst_search";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
char v_name[256];
char v_remark[2001];
char v_field_id[31];
char v_detail_value[256];
// not used: char v_buffer[2001];
int v_string_pos;
/* temp. buffer */
DA_T_subst v_subst_buf;
/* pointer to list root */
DA_T_subst_result *v_root_lst_ptr = NULL;
/* pointer to list element */
DA_T_subst_result *v_new_elem_ptr = NULL;
DA_T_subst_result *v_last_elem_ptr = NULL;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
struct DA_T_subst_result_pg_h{ /* type contains host variables for object data */
long subst_id;
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char is_templ [ 2];
char remark [2001];
char detail_value [256];
} h_subst_result;
char h_fmt_date [ 30];
char h_query [4000];
char h_con_name [ 31];
struct DA_T_subst_result_pg_i{ /* type contains host variables for object data */
short int subst_id;
short int name;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int is_templ;
short int remark;
short int detail_value;
} h_ind_subst_result;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy (v_name, vp_name);
strcpy (v_remark, vp_remark);
strcpy (v_field_id, vp_field_id);
strcpy (v_detail_value, vp_detail_value);
/* replace all * with % and all ' and ´ with _ */
while ((v_string_pos = strcspn (v_name, "*´'")) < strlen (v_name))
if (v_name[v_string_pos] == '*')
v_name[v_string_pos] = '%';
else
v_name[v_string_pos] = '_';
while ((v_string_pos = strcspn (v_remark, "*´'")) < strlen (v_remark))
if (v_remark[v_string_pos] == '*')
v_remark[v_string_pos] = '%';
else
v_remark[v_string_pos] = '_';
while ((v_string_pos = strcspn (v_detail_value, "*´'")) < strlen (v_detail_value))
if (v_detail_value[v_string_pos] == '*')
v_detail_value[v_string_pos] = '%';
else
v_detail_value[v_string_pos] = '_';
/* set format mask for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* build SELECT-statement
*/
/* basic SELECT-statement */
sprintf (h_query, "SELECT S.SUBST_ID, "
"S.NAME, "
"S.USER_ID, "
"to_char(S.CRE_DATE, '%s'), "
"to_char(S.MOD_DATE, '%s'), "
"S.STATUS, "
"S.PRIVS, "
"S.IS_TEMPL, "
"S.REMARK",
h_fmt_date, h_fmt_date);
if (strcmp (v_field_id, "") == 0 || strcmp (v_detail_value, "") == 0)
{
sprintf (h_query, "%s, '' "
"FROM SUBST_TAB S"
" WHERE S.IS_TEMPL = 'Y'",
h_query);
}
/* if field_id *and* detail_value are not NULL, add corresponding FROM- and
WHERE-clause to SELECT-statement */
else
{
sprintf (h_query, "%s, D.VALUE "
"FROM SUBST_TAB S, "
"SUBST_DET_TAB D"
" WHERE S.IS_TEMPL = 'Y'"
" AND S.SUBST_ID = D.SUBST_ID"
" AND D.FIELD_ID = '%s'",
h_query, v_field_id);
/* if detail_value contains wildcards use "LIKE", else use "=" */
if (strcspn (v_detail_value, "%_") < strlen (v_detail_value))
{
sprintf (h_query, "%s AND D.VALUE LIKE %s",h_query, v_detail_value);
}
else
sprintf (h_query, "%s AND D.VALUE = %s", h_query, v_detail_value);
}
/* Check name and remark, if they are NULL.
If not, add corresponding WHERE-clause to SELECT-statement */
/* name */
if (strcmp (v_name, "") != 0)
{
/* if name contains wildcards use "LIKE", else use "=" */
if (strcspn (v_name, "%_") < strlen (v_name))
sprintf (h_query, "%s AND S.NAME LIKE %s", h_query, v_name);
else
sprintf (h_query, "%s AND S.NAME = %s",h_query, v_name);
}
/* remark */
if (strcmp (v_remark, "") != 0)
{
/* if remark contains wildcards use "LIKE", else use "=" */
if (strcspn (v_remark, "%_") < strlen (v_remark))
sprintf (h_query, "%s AND S.REMARK LIKE %s", h_query, v_remark);
else
sprintf (h_query, "%s AND S.REMARK = %s", h_query, v_remark);
}
/* add sort key to SELECT-statement */
sprintf(h_query, "%s ORDER BY S.SUBST_ID", h_query);
/*
* SELECT-statement complete
*/
errln = 10;
EXEC SQL PREPARE search FROM :h_query;
errln = 20;
EXEC SQL DECLARE subst_search_csr CURSOR FOR search;
errln = 30;
EXEC SQL OPEN subst_search_csr;
errln = 40;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 50;
EXEC SQL FETCH subst_search_csr
INTO :h_subst_result INDICATOR :h_ind_subst_result;
/* check indicator variables (in regard to NULL values) */
if (h_ind_subst_result.subst_id == -1) h_subst_result.subst_id = -1;
if (h_ind_subst_result.privs == -1) h_subst_result.privs = 1;
if (h_ind_subst_result.name == -1) strcpy(h_subst_result.name, "");
if (h_ind_subst_result.user_id == -1) strcpy(h_subst_result.user_id, "");
if (h_ind_subst_result.cre_date == -1) strcpy(h_subst_result.cre_date, "");
if (h_ind_subst_result.mod_date == -1) strcpy(h_subst_result.mod_date, "");
if (h_ind_subst_result.status == -1) strcpy(h_subst_result.status, "");
if (h_ind_subst_result.is_templ == -1) strcpy(h_subst_result.is_templ, "");
if (h_ind_subst_result.remark == -1) strcpy(h_subst_result.remark, "");
/* copy result into temp. buffer */
v_subst_buf.subst_id = h_subst_result.subst_id;
v_subst_buf.privs = h_subst_result.privs;
strcpy (v_subst_buf.name , h_subst_result.name);
strcpy (v_subst_buf.user_id , h_subst_result.user_id);
strcpy (v_subst_buf.cre_date , h_subst_result.cre_date);
strcpy (v_subst_buf.mod_date , h_subst_result.mod_date);
strcpy (v_subst_buf.status , h_subst_result.status);
strcpy (v_subst_buf.is_templ , h_subst_result.is_templ);
strcpy (v_subst_buf.remark , h_subst_result.remark);
v_subst_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SUBST_TAB, (void*) &v_subst_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_subst_result*) malloc( sizeof(DA_T_subst_result) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf (vp_errinfo->err_param,"%s - malloc(DA_T_subst_result)", v_module);
/* release already allocated memory */
gda_free_subst_result(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_subst_result) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
v_new_elem_ptr->subst_id = h_subst_result.subst_id;
strcpy(v_new_elem_ptr->name, h_subst_result.name);
strcpy(v_new_elem_ptr->user_id, h_subst_result.user_id);
strcpy(v_new_elem_ptr->cre_date, h_subst_result.cre_date);
strcpy(v_new_elem_ptr->mod_date, h_subst_result.mod_date);
strcpy(v_new_elem_ptr->status, h_subst_result.status);
v_new_elem_ptr->privs = h_subst_result.privs;
strcpy(v_new_elem_ptr->is_templ, h_subst_result.is_templ);
strcpy(v_new_elem_ptr->remark, h_subst_result.remark);
strcpy(v_new_elem_ptr->detail_value, h_subst_result.detail_value);
/* set WRITE according to current user's access right */
if (v_access_right >= DA_A_VIEWEDIT)
v_new_elem_ptr->write[0] = DA_YES;
else
v_new_elem_ptr->write[0] = DA_NO;
v_new_elem_ptr->write[1] = '\0';
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 60;
EXEC SQL CLOSE subst_search_csr;
/* return created result list */
(*vp_subst_result) = v_root_lst_ptr;
/* success fully connected to database */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE subst_search_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_subst (SUBST_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Insert record into SUBST_TAB. Return new "SUBST_ID" by
* passed struct, in case insert could successfully be done
*
* Parameter: vp_subst (i/o) data to insert into SUBST_TAB,
* OUTPUT:
* - subst_id = SUBST_SEQ.NEXTVAL
* - cre_date = CURRENT_TIMESTAMP
* - mod_date = CURRENT_TIMESTAMP
* - user_id =
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
* vg_db_user_info(i) -> general information about database
* user of current db-session
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into SUBST_TAB.
Return new "SUBST_ID" by passed struct, in case insert could successfully be done.
Output:
vp_subst - subst_id, cre_date, mod_date, user_id
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_subst data to insert into SUBST_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_subst (DB_con *db_con,
DA_T_subst *vp_subst,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_subst";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_subst_id_new;
char h_fmt_date[30];
char h_con_name[31];
struct DA_T_subst_pg_h{ /* type contains host variables for object data */
long subst_id;
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char is_templ [ 2];
char remark [2001];
} h_subst;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/* current db-user becomes owner of the new data -> acc. rhgt=VIEW+EDIT */
v_access_right = DA_A_VIEWEDIT;
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* get new SUSBT_ID */
errln = 10;
EXEC SQL SELECT NEXTVAL('SUBST_SEQ'),
to_char(CURRENT_TIMESTAMP, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_subst_id_new,
:h_subst.cre_date,
:h_subst.mod_date;
/*
* copy passed record into host variable
*/
h_subst.subst_id = h_subst_id_new;
h_subst.privs = vp_subst->privs;
strcpy (h_subst.name , vp_subst->name);
strcpy (h_subst.user_id , vg_db_user_info.user_id);
strcpy (h_subst.status , vp_subst->status);
strcpy (h_subst.is_templ , vp_subst->is_templ);
strcpy (h_subst.remark , vp_subst->remark);
/* Insert passed record */
errln = 20;
EXEC SQL INSERT INTO SUBST_TAB ( SUBST_ID,
NAME,
USER_ID,
CRE_DATE,
MOD_DATE,
STATUS,
PRIVS,
IS_TEMPL,
REMARK )
VALUES ( :h_subst.subst_id,
:h_subst.name,
:h_subst.user_id,
to_timestamp(:h_subst.cre_date, :h_fmt_date),
to_timestamp(:h_subst.mod_date, :h_fmt_date),
:h_subst.status,
:h_subst.privs,
:h_subst.is_templ,
:h_subst.remark );
/* set return value (created SUBST_ID,...) into passed struct/record */
vp_subst->subst_id = h_subst_id_new;
strcpy(vp_subst->user_id, h_subst.user_id);
strcpy(vp_subst->cre_date, h_subst.cre_date);
strcpy(vp_subst->mod_date, h_subst.mod_date);
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_subst (SUBST_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by SUBST_ID) in SUBST_TAB
* by data of passed record.
*
* Parameter: vp_subst (i) new substance data, containing SUBST_ID of
* record to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by SUBST_ID) in SUBST_TAB by data of passed record.
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_subst new substance data, containing SUBST_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_subst (DB_con *db_con,
DA_T_subst *vp_subst,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_subst";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_subst_id;
char h_fmt_date[30];
char h_con_name[31];
struct DA_T_subst_pg_h{ /* type contains host variables for object data */
long subst_id;
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char is_templ [ 2];
char remark [2001];
} h_subst;
short int h_ind_mod_date;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SUBST_TAB, (void*) vp_subst,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_subst_id = vp_subst->subst_id;
h_subst.subst_id = vp_subst->subst_id;
h_subst.privs = vp_subst->privs;
strcpy (h_subst.name , vp_subst->name);
strcpy (h_subst.user_id , vp_subst->user_id);
strcpy (h_subst.cre_date , vp_subst->cre_date);
strcpy (h_subst.mod_date , vp_subst->mod_date);
strcpy (h_subst.status , vp_subst->status);
strcpy (h_subst.is_templ , vp_subst->is_templ);
strcpy (h_subst.remark , vp_subst->remark);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* Update passed record in database */
errln = 10;
EXEC SQL SELECT to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_subst.mod_date INDICATOR :h_ind_mod_date;
if (h_ind_mod_date == -1)
{
strcpy(h_subst.mod_date,"");
}
/* ignore CRE_DATE for update */
errln = 20;
EXEC SQL UPDATE SUBST_TAB
SET SUBST_ID = :h_subst.subst_id,
NAME = :h_subst.name,
USER_ID = :h_subst.user_id,
MOD_DATE = to_timestamp(:h_subst.mod_date, :h_fmt_date),
STATUS = :h_subst.status,
PRIVS = :h_subst.privs,
IS_TEMPL = :h_subst.is_templ,
REMARK = :h_subst.remark
WHERE SUBST_ID = :h_subst_id;
/* return new MOD_DATE by passed struct */
strcpy(vp_subst->mod_date, h_subst.mod_date);
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record snot updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_subst (SUBST_TAB)
*
* Issue : 18-JUL-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Delete record from SUBST_TAB specified by "subst_id"
*
* Parameter: vp_subst_id (i) SUBST_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from SUBST_TAB specified by "subst_id".
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 18-JUL-2002
\param db_con Pointer to connection
\param vp_subst_id SUBST_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_subst (DB_con *db_con,
long vp_subst_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_delete_subst";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
DA_T_subst v_subst_buf;
EXEC SQL BEGIN DECLARE SECTION;
int h_count;
char h_con_name[31];
struct DA_T_subst_pg_h{ /* type contains host variables for object data */
long subst_id;
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char is_templ [ 2];
char remark [2001];
} h_subst;
struct DA_T_subst_pg_i{ /* indicator variables for host variable struct */
short int subst_id;
short int name;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int is_templ;
short int remark;
} h_ind_subst;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
errln = 10;
h_subst.subst_id = vp_subst_id;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
EXEC SQL SELECT COUNT (SESS_ID)
INTO :h_count
FROM SESS_TAB
WHERE SUBST_ID = :h_subst.subst_id;
if (h_count > 0)
{
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_SUBST_REF_DATA;
sprintf (vp_errinfo->err_param,"%s", v_module);
/* record not deleted */
return(DA_FAIL);
}
/* get access right for substance */
errln = 20;
EXEC SQL SELECT USER_ID,
PRIVS
INTO :h_subst.user_id INDICATOR :h_ind_subst.user_id,
:h_subst.privs INDICATOR :h_ind_subst.privs
FROM SUBST_TAB
WHERE SUBST_ID = :h_subst.subst_id;
/* check indicator variables (in regard to NULL values) */
if (h_ind_subst.privs == -1) h_subst.privs = 1;
if (h_ind_subst.user_id == -1) strcpy(h_subst.user_id, "");
/* copy result into temp. buffer */
v_subst_buf.subst_id = h_subst.subst_id;
v_subst_buf.privs = h_subst.privs;
strcpy (v_subst_buf.user_id , h_subst.user_id);
v_subst_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SUBST_TAB, (void*) &v_subst_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* delete specified record */
errln = 30;
EXEC SQL DELETE FROM SUBST_TAB
WHERE SUBST_ID = :h_subst.subst_id;
/* record successfully deleted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not deleted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_subst (SUBST_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "gda_get_subst()".
* Pointer must be explicitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_subst (i) pointer to "list of" substance records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "da_get_subst()".
Pointer must be explicitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param vp_subst pointer to "list of" substance records
\return ---
*/
void gda_free_subst (DA_T_subst *vp_subst)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_subst";
#endif
/* pointer to list elements */
DA_T_subst *v_next_elem_ptr = NULL;
DA_T_subst *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_subst;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/*********************************************************************
* Name : gda_free_subst_result (SUBST_TAB)
*
* Issue : 04-NOV-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "gda_get_subst_search()".
* Pointer must be explicitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_subst_result (i) pointer to "list of" substance records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "da_get_subst_search()".
Pointer must be explicitely set to NULL in the calling program after calling this function.
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 04-NOV-2002
\param vp_subst_result pointer to "list of" substance records
\return ---
*/
void gda_free_subst_result (DA_T_subst_result *vp_subst_result)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_subst_result";
#endif
/* pointer to list elements */
DA_T_subst_result *v_next_elem_ptr = NULL;
DA_T_subst_result *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_subst_result;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: SUBST_DET_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_subst_det (SUBST_DET_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of substance detail data from SUBST_DET_TAB ordered
* by SUBST_DET_ID
*
* Query conditions:
* a) subst_id <>-1, subst_det_id =-1; return: 1..n records
* b) subst_id <>-1, subst_det_id<>-1; return: 1 records
*
* Parameter: vp_subst_id (i) ID of substance for which details shall
* be selected
* vp_subst_det_id (i) ID of substance detail data to select
* vp_subst_det (o) Return value (list of substance details)
* vp_errinfo (o) Error info in case of error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of substance detail data from SUBST_DET_TAB ordered by SUBST_DET_ID.
Query conditions:
subst_id <>-1, subst_det_id =-1; return: 1..n records
subst_id <>-1, subst_det_id<>-1; return: 1 records
Output:
vp_subst_det - Return value (list of substance details)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_subst_id ID of substance for which details shall be selected
\param vp_subst_det_id ID of substance detail data to select
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_subst_det (DB_con *db_con,
long vp_subst_id,
long vp_subst_det_id,
DA_T_subst_det **vp_subst_det,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_subst_det";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_subst_det v_subst_det_buf;
/* pointer to list root */
DA_T_subst_det *v_root_lst_ptr = NULL;
/* pointer to list element */
DA_T_subst_det *v_new_elem_ptr = NULL;
DA_T_subst_det *v_last_elem_ptr = NULL;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_con_name [ 31];
char h_where_clause [100];
char h_query [2000];
struct DA_T_subst_det_pg_h{ /* type contains host variables for object data */
long subst_det_id;
long subst_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value [256];
char dist_type [ 12];
char remark [2001];
} h_subst_det;
struct DA_T_subst_det_pg_i{ /* indicator variables for host variable struct */
short int subst_det_id;
short int subst_id;
short int field_id;
short int block_id;
short int block_recno;
short int value;
short int dist_type;
short int remark;
} h_ind_subst_det;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* determine query condition
* a) subst_id <>-1, subst_det_id =-1; return: 1..n records
* b) subst_id <>-1, subst_det_id<>-1; return: 1 records
*/
if (vp_subst_det_id == -1)
{
/* case a) */
sprintf(h_where_clause,"SUBST_ID = %ld ", vp_subst_id);
}
else
{
/* case b) */
sprintf(h_where_clause,"SUBST_ID = %ld AND SUBST_DET_ID = %ld ", vp_subst_id, vp_subst_det_id);
}
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the session from SUBST_DET_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT SUBST_DET_ID,"
"SUBST_ID,"
"FIELD_ID,"
"BLOCK_ID,"
"BLOCK_RECNO,"
"VALUE_SDT,"
"DIST_TYPE,"
"REMARK "
"FROM SUBST_DET_TAB "
"WHERE %s "
"ORDER BY SUBST_DET_ID", h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE subst_det_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN subst_det_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH subst_det_csr INTO :h_subst_det INDICATOR :h_ind_subst_det;
/* check indicator variables (in regard to NULL values) */
if (h_ind_subst_det.subst_det_id == -1) h_subst_det.subst_det_id = -1;
if (h_ind_subst_det.subst_id == -1) h_subst_det.subst_id = -1;
if (h_ind_subst_det.block_recno == -1) h_subst_det.block_recno = 0;
if (h_ind_subst_det.field_id == -1) strcpy(h_subst_det.field_id, "");
if (h_ind_subst_det.block_id == -1) strcpy(h_subst_det.block_id, "");
if (h_ind_subst_det.value == -1) strcpy(h_subst_det.value, "");
if (h_ind_subst_det.dist_type == -1) strcpy(h_subst_det.dist_type, "");
if (h_ind_subst_det.remark == -1) strcpy(h_subst_det.remark, "");
/* copy result into temp. buffer */
v_subst_det_buf.subst_det_id = h_subst_det.subst_det_id;
v_subst_det_buf.subst_id = h_subst_det.subst_id;
v_subst_det_buf.block_recno = h_subst_det.block_recno;
strcpy(v_subst_det_buf.field_id , h_subst_det.field_id);
strcpy(v_subst_det_buf.block_id , h_subst_det.block_id);
strcpy(v_subst_det_buf.value , h_subst_det.value);
strcpy(v_subst_det_buf.dist_type , h_subst_det.dist_type);
strcpy(v_subst_det_buf.remark , h_subst_det.remark);
v_subst_det_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SUBST_DET_TAB, (void*) &v_subst_det_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_subst_det*) malloc( sizeof(DA_T_subst_det) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf (vp_errinfo->err_param,"%s - malloc(DA_T_subst_det)", v_module);
/* release already allocated memory */
gda_free_subst_det(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_subst_det) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_subst_det_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE subst_det_csr;
/* return created result list */
(*vp_subst_det) = v_root_lst_ptr;
/* success fully connected to database */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE subst_det_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_subst_det (SUBST_DET_TAB)
*
* Issue : 07-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : - Insert record into SUBST_DET_TAB. Return new "SUBST_DET_ID"
* by passed struct, in case insert could successfully be done.
*
* - Before INSERT is done
* a) check by FIELD_ID, BLOCK_ID if master record in table
* PARA_TREE_DEF_TAB exists. In case not -> cancel insert!
* b) check by SUBST_ID if master record in table SUBST_TAB
* exists. In case not -> cancel insert!
*
* - Update "MOD_DATE" in master record (SUBST_TAB) by CURRENT_TIMESTAMP
*
*
* Parameter: vp_subst_det (i/o) data to insert into SUBST_DET_TAB,
* OUTPUT:
* new subst_det_id = SUBST_DET_SEQ.NEXTVAL
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into SUBST_DET_TAB.
Return new "SUBST_DET_ID" by passed struct, in case insert could successfully be done.
Before INSERT is done
check by FIELD_ID, BLOCK_ID if master record in table PARA_TREE_DEF_TAB exists. In case not -> cancel insert!
check by SUBST_ID if master record in table SUBST_TAB exists. In case not -> cancel insert!
Update "MOD_DATE" in master record (SUBST_TAB) by CURRENT_TIMESTAMP
Output:
vp_subst_det -> subst_det_id
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 07-AUG-2002
\param db_con Pointer to connection
\param vp_subst_det data to insert into SUBST_DET_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_subst_det (DB_con *db_con,
DA_T_subst_det *vp_subst_det,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_subst_det";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_master_chk = DA_FAIL;
char v_errmsg[256];
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_subst_det_id_new;
long h_subst_id_qry;
char h_fmt_date[30];
char h_con_name [ 31];
struct DA_T_subst_det_pg_h{ /* type contains host variables for object data */
long subst_det_id;
long subst_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value_sdt [256];
char dist_type [ 12];
char remark [2001];
} h_subst_det;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set date format mask */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* ------------------ *
* PRE-CHECKS
* ------------------ */
v_master_chk = lgda_chk_subst_det_master(vp_subst_det->subst_id,
vp_subst_det->field_id,
vp_subst_det->block_id,
vp_errinfo);
if (v_master_chk != DA_SUCCESS)
{
/* error during check of master record */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SUBST_DET_TAB, (void*) vp_subst_det,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* get new SUBST_DET_ID */
errln = 50;
EXEC SQL SELECT NEXTVAL('SUBST_DET_SEQ')
INTO :h_subst_det_id_new;
/*
* copy passed record into host variable
*/
h_subst_det.subst_det_id = h_subst_det_id_new;
h_subst_det.subst_id = vp_subst_det->subst_id;
h_subst_det.block_recno = vp_subst_det->block_recno;
strcpy(h_subst_det.field_id , vp_subst_det->field_id);
strcpy(h_subst_det.block_id , vp_subst_det->block_id);
strcpy(h_subst_det.value_sdt , vp_subst_det->value);
strcpy(h_subst_det.dist_type , vp_subst_det->dist_type);
strcpy(h_subst_det.remark , vp_subst_det->remark);
/* Insert passed record */
errln = 60;
EXEC SQL INSERT INTO SUBST_DET_TAB ( SUBST_DET_ID,
SUBST_ID,
FIELD_ID,
BLOCK_ID,
BLOCK_RECNO,
VALUE_SDT,
DIST_TYPE,
REMARK )
VALUES (:h_subst_det.subst_det_id,
:h_subst_det.subst_id,
:h_subst_det.field_id,
:h_subst_det.block_id,
:h_subst_det.block_recno,
:h_subst_det.value_sdt,
:h_subst_det.dist_type,
:h_subst_det.remark);
/* Update MOD_DATE in master (SUBST_TAB) */
h_subst_id_qry = vp_subst_det->subst_id;
errln = 70;
EXEC SQL UPDATE SUBST_TAB
SET MOD_DATE = to_timestamp(to_char(CURRENT_TIMESTAMP, :h_fmt_date), :h_fmt_date)
WHERE SUBST_ID = :h_subst_id_qry;
/* set return value (created SUBST_DET_ID) into passed struct/record */
vp_subst_det->subst_det_id = h_subst_det_id_new;
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_subst_det (SUBST_DET_TAB)
*
* Issue : 07-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by SUBST_DET_ID) in SUBST_DET_TAB
* by data of passed record.
*
* - Before UPDATE is done
* a) check by FIELD_ID, BLOCK_ID if master record in table
* PARA_TREE_DEF_TAB exists. In case not -> cancel update!
* b) check by SUBST_ID if master record in table SUBST_TAB
* exists. In case not -> cancel update!
*
* - Update "MOD_DATE" in master record (SUBST_TAB) by CURRENT_TIMESTAMP
*
*
* Parameter: vp_subst_det (i) new substancen data, containing SUBST_DET_ID
* of record to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by SUBST_DET_ID) in SUBST_DET_TAB by data of passed record.
Before UPDATE is done
check by FIELD_ID, BLOCK_ID if master record in table PARA_TREE_DEF_TAB exists. In case not -> cancel update!
check by SUBST_ID if master record in table SUBST_TAB exists. In case not -> cancel update!
Update "MOD_DATE" in master record (SUBST_TAB) by CURRENT_TIMESTAMP
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 07-AUG-2002
\param db_con Pointer to connection
\param vp_subst_det new substancen data, containing SUBST_DET_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_subst_det (DB_con *db_con,
DA_T_subst_det *vp_subst_det,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_subst_det";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_master_chk = DA_FAIL;
char v_errmsg[256];
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_subst_det_id;
long h_subst_id_qry;
char h_fmt_date[30];
char h_con_name [ 31];
struct DA_T_subst_det_pg_h{ /* type contains host variables for object data */
long subst_det_id;
long subst_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value_sdt [256];
char dist_type [ 12];
char remark [2001];
} h_subst_det;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set date format mask */
strcpy(h_fmt_date, DA_FMT_date);
/* ------------------ *
* PRE-CHECKS
* ------------------ */
v_master_chk = lgda_chk_subst_det_master(vp_subst_det->subst_id,
vp_subst_det->field_id,
vp_subst_det->block_id,
vp_errinfo);
if (v_master_chk != DA_SUCCESS)
{
/* error during check of master record */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_SUBST_DET_TAB, (void*) vp_subst_det,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_subst_det_id = vp_subst_det->subst_det_id;
h_subst_det.subst_det_id = vp_subst_det->subst_det_id;
h_subst_det.subst_id = vp_subst_det->subst_id;
h_subst_det.block_recno = vp_subst_det->block_recno;
strcpy(h_subst_det.field_id , vp_subst_det->field_id);
strcpy(h_subst_det.block_id , vp_subst_det->block_id);
strcpy(h_subst_det.value_sdt , vp_subst_det->value);
strcpy(h_subst_det.dist_type , vp_subst_det->dist_type);
strcpy(h_subst_det.remark , vp_subst_det->remark);
strcpy(h_con_name , db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* Update passed record in database */
errln = 10;
EXEC SQL UPDATE SUBST_DET_TAB
SET SUBST_DET_ID = :h_subst_det.subst_det_id,
SUBST_ID = :h_subst_det.subst_id,
FIELD_ID = :h_subst_det.field_id,
BLOCK_ID = :h_subst_det.block_id,
BLOCK_RECNO = :h_subst_det.block_recno,
VALUE_SDT = :h_subst_det.value_sdt,
DIST_TYPE = :h_subst_det.dist_type,
REMARK = :h_subst_det.remark
WHERE SUBST_DET_ID = :h_subst_det_id;
/* Update MOD_DATE in master (SUBST_TAB) */
h_subst_id_qry = vp_subst_det->subst_id;
/* set format mask for MOD_DATE */
strcpy(h_fmt_date, DA_FMT_date);
errln = 20;
EXEC SQL UPDATE SUBST_TAB
SET MOD_DATE = to_timestamp(to_char(CURRENT_TIMESTAMP, :h_fmt_date),:h_fmt_date)
WHERE SUBST_ID = :h_subst_id_qry;
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_subst_det (SUBST_DET_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_subst_det()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_subst_det (i) pointer to "list of" substance det. records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_subst_det()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param vp_subst_det pointer to "list of" substance det. records
\return ---
*/
void gda_free_subst_det (DA_T_subst_det *vp_subst_det)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_subst_det";
#endif
/* pointer to list elements */
DA_T_subst_det *v_next_elem_ptr = NULL;
DA_T_subst_det *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_subst_det;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: ENV_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_env (ENV_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of environment data from ENV_TAB order by ENV_ID
*
* Query conditions:
* a) env_id =-1, is_templ='Y' return: 1..n records (templates)
* env_id =-1, is_templ='N' return: 1..n records (non-templ.)
* (is_tepml=DA_ALL -> ignore is_templ for selection!)
*
* b) env_id<>-1, is_templ='Y' return: 1 record (template)
* env_id<>-1, is_templ='N' return: 1 record (non-templ.)
* (is_tepml=DA_ALL -> ignore is_templ for selection!)
*
* Parameter: vp_env_id (i) ID of environment data to select
* vp_is_templ (i) 'Y' => select templates only
* 'N' => select non-templates only
* vp_env (o) Return value (list of environment data)
* vp_errinfo (o) Error info in case of error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of environment data from ENV_TAB order by ENV_ID.
Query conditions:
env_id =-1, is_templ='Y' return: 1..n records (templates) \n
env_id =-1, is_templ='N' return: 1..n records (non-templ.)\n
(is_tepml=DA_ALL -> ignore is_templ for selection!)
env_id<>-1, is_templ='Y' return: 1 record (template) \n
env_id<>-1, is_templ='N' return: 1 record (non-templ.)\n
(is_tepml=DA_ALL -> ignore is_templ for selection!)
Output:
vp_env - Return value (list of environment data)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_env_id ID of environment data to select
\param vp_is_templ 'Y' => select templates only \n 'N' => select non-templates only
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_env (DB_con *db_con,
long vp_env_id,
char vp_is_templ,
DA_T_env **vp_env,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_env";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_env v_env_buf;
/* pointer to list root */
DA_T_env *v_root_lst_ptr = NULL;
/* pointer to list element */
DA_T_env *v_new_elem_ptr = NULL;
DA_T_env *v_last_elem_ptr = NULL;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_is_templ_qry[ 2];
char h_fmt_date [ 30];
char h_where_clause [100];
char h_query [2000];
char h_con_name [ 31];
struct DA_T_env_pg_h{ /* type contains host variables for object data */
long env_id;
char name [ 31];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char is_templ [ 2];
char remark [2001];
} h_env;
struct DA_T_env_pg_i{ /* indicator variables for host variable struct */
short int env_id;
short int name;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int is_templ;
short int remark;
} h_ind_env;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* determine query condition
* a) env_id =-1, is_templ='Y' return: 1..n records (templates)
* env_id =-1, is_templ='N' return: 1..n records (non-templ.)
* (is_tepml=DA_ALL -> ignore is_templ for selection!)
*
* b) env_id<>-1, is_templ='Y' return: 1 record (template)
* env_id<>-1, is_templ='N' return: 1 record (non-templ.)
* (is_tepml=DA_ALL -> ignore is_templ for selection!)
*/
if (vp_env_id == -1)
{
/* case a) */
strcpy (h_where_clause, "");
}
else
{
/* case b) */
sprintf(h_where_clause,"ENV_ID = %ld AND ", vp_env_id);
}
sprintf(h_is_templ_qry, "%c", vp_is_templ);
/*
* DECLARE CURSOR
* to select the session from ENV_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT ENV_ID,"
"NAME,"
"USER_ID,"
"to_char(CRE_DATE, '%s'),"
"to_char(MOD_DATE, '%s'),"
"STATUS,"
"PRIVS,"
"IS_TEMPL,"
"REMARK "
"FROM ENV_TAB "
"WHERE %s IS_TEMPL like '%s'"
"ORDER BY ENV_ID",
h_fmt_date, h_fmt_date, h_where_clause, h_is_templ_qry);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE env_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN env_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH env_csr INTO :h_env INDICATOR :h_ind_env;
/* check indicator variables (in regard to NULL values) */
if (h_ind_env.env_id == -1) h_env.env_id = -1;
if (h_ind_env.privs == -1) h_env.privs = 1;
if (h_ind_env.name == -1) strcpy(h_env.name, "");
if (h_ind_env.user_id == -1) strcpy(h_env.user_id, "");
if (h_ind_env.cre_date == -1) strcpy(h_env.cre_date, "");
if (h_ind_env.mod_date == -1) strcpy(h_env.mod_date, "");
if (h_ind_env.status == -1) strcpy(h_env.status, "");
if (h_ind_env.is_templ == -1) strcpy(h_env.is_templ, "");
if (h_ind_env.remark == -1) strcpy(h_env.remark, "");
/* copy result into temp. buffer */
v_env_buf.env_id = h_env.env_id;
v_env_buf.privs = h_env.privs;
strcpy (v_env_buf.name , h_env.name);
strcpy (v_env_buf.user_id , h_env.user_id);
strcpy (v_env_buf.cre_date , h_env.cre_date);
strcpy (v_env_buf.mod_date , h_env.mod_date);
strcpy (v_env_buf.status , h_env.status);
strcpy (v_env_buf.is_templ , h_env.is_templ);
strcpy (v_env_buf.remark , h_env.remark);
v_env_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_ENV_TAB, (void*) &v_env_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_env*) malloc( sizeof(DA_T_env) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf (vp_errinfo->err_param,"%s - malloc(DA_T_env)", v_module);
/* release already allocated memory */
gda_free_env(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_env) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_env_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE env_csr;
/* return created result list */
(*vp_env) = v_root_lst_ptr;
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE env_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_env (ENV_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Insert record into ENV_TAB. Return new "ENV_ID" by passed
* struct, in case insert could successfully be done
*
* Parameter: vp_env (i/o) data to insert into ENV_TAB,
* OUTPUT:
* new env_id = ENV_SEQ.NEXTVAL
* cre_date = CURRENT_TIMESTAMP
* mod_date = CURRENT_TIMESTAMP
* user_id =
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
* vg_db_user_info (i) -> general information about database
* user of current db-session
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into ENV_TAB.
Return new "ENV_ID" by passed struct, in case insert could successfully be done.
Output:
vp_env - new env_id, cre_date, mod_date, user_id (curr. db-user)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_env data to insert into ENV_TAB
\param vp_is_templ 'Y' => select templates only \n 'N' => select non-templates only
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_env (DB_con *db_con,
DA_T_env *vp_env,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_env";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_env_id_new;
char h_fmt_date[30];
char h_con_name[31];
struct DA_T_env_pg_h{ /* type contains host variables for object data */
long env_id;
char name [ 31];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char is_templ [ 2];
char remark [2001];
} h_env;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/* current db-user becomes owner of the new data -> acc. rhgt=VIEW+EDIT */
v_access_right = DA_A_VIEWEDIT;
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* get new ENV_ID */
errln = 10;
EXEC SQL SELECT NEXTVAL('ENV_SEQ'),
to_char(CURRENT_TIMESTAMP, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_env_id_new,
:h_env.cre_date,
:h_env.mod_date;
/*
* copy passed record into host variable
*/
h_env.env_id = h_env_id_new;
h_env.privs = vp_env->privs;
strcpy (h_env.name , vp_env->name);
strcpy (h_env.user_id , vg_db_user_info.user_id);
strcpy (h_env.status , vp_env->status);
strcpy (h_env.is_templ , vp_env->is_templ);
strcpy (h_env.remark , vp_env->remark);
/* Insert passed record */
errln = 20;
EXEC SQL INSERT INTO ENV_TAB ( ENV_ID,
NAME,
USER_ID,
CRE_DATE,
MOD_DATE,
STATUS,
PRIVS,
IS_TEMPL,
REMARK )
VALUES ( :h_env.env_id,
:h_env.name,
:h_env.user_id,
to_timestamp(:h_env.cre_date, :h_fmt_date),
to_timestamp(:h_env.mod_date, :h_fmt_date),
:h_env.status,
:h_env.privs,
:h_env.is_templ,
:h_env.remark);
/* set return value (created ENV_ID) into passed struct/record */
vp_env->env_id = h_env_id_new;
strcpy(vp_env->user_id, h_env.user_id);
strcpy(vp_env->cre_date, h_env.cre_date);
strcpy(vp_env->mod_date, h_env.mod_date);
/* record not inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record successfully inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_env (ENV_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by ENV_ID) in ENV_TAB
* by data of passed record.
*
* Parameter: vp_env (i) new environment data, containing ENV_ID
* of record to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by ENV_ID) in ENV_TAB by data of passed record.
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_env new environment data, containing ENV_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_env (DB_con *db_con, DA_T_env *vp_env,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_env";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_env_id;
char h_fmt_date[30];
char h_con_name[31];
struct DA_T_env_pg_h{ /* type contains host variables for object data */
long env_id;
char name [ 31];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char is_templ [ 2];
char remark [2001];
} h_env;
short int h_ind_mod_date;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/* get access right for data */
v_status = lgda_get_access_right(DA_A_ENV_TAB, (void*) vp_env,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_env_id = vp_env->env_id;
h_env.env_id = vp_env->env_id;
h_env.privs = vp_env->privs;
strcpy (h_env.name , vp_env->name);
strcpy (h_env.user_id , vp_env->user_id);
strcpy (h_env.cre_date , vp_env->cre_date);
strcpy (h_env.mod_date , vp_env->mod_date);
strcpy (h_env.status , vp_env->status);
strcpy (h_env.is_templ , vp_env->is_templ);
strcpy (h_env.remark , vp_env->remark);
/* Update passed record in database */
errln = 10;
EXEC SQL SELECT to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_env.mod_date INDICATOR :h_ind_mod_date;
if (h_ind_mod_date == -1)
{
strcpy(h_env.mod_date,"");
}
/* ignore CRE_DATE for update */
errln = 20;
EXEC SQL UPDATE ENV_TAB
SET ENV_ID = :h_env.env_id,
NAME = :h_env.name,
USER_ID = :h_env.user_id,
MOD_DATE = to_timestamp(:h_env.mod_date, :h_fmt_date),
STATUS = :h_env.status,
PRIVS = :h_env.privs,
IS_TEMPL = :h_env.is_templ,
REMARK = :h_env.remark
WHERE ENV_ID = :h_env_id;
/* return new MOD_DATE */
strcpy(vp_env->mod_date, h_env.mod_date);
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_env (ENV_TAB)
*
* Issue : 18-JUL-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Delete record from ENV_TAB specified by "env_id"
*
* Parameter: vp_env_id (i) ENV_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from ENV_TAB specified by "env_id".
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 18-JUL-2002
\param db_con Pointer to connection
\param vp_env_id ENV_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_env (DB_con *db_con,
long vp_env_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_delete_env";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
DA_T_env v_env_buf;
EXEC SQL BEGIN DECLARE SECTION;
int h_count;
char h_con_name [ 31];
struct DA_T_env_pg_h{ /* type contains host variables for object data */
long env_id;
char name [ 31];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char is_templ [ 2];
char remark [2001];
} h_env;
struct DA_T_env_pg_i{ /* indicator variables for host variable struct */
short int env_id;
short int name;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int is_templ;
short int remark;
} h_ind_env;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
errln = 10;
h_env.env_id = vp_env_id;
EXEC SQL SELECT COUNT (SESS_ID)
INTO :h_count
FROM SESS_TAB
WHERE ENV_ID = :h_env.env_id;
if (h_count > 0)
{
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_ENV_REF_DATA;
sprintf (vp_errinfo->err_param,"%s", v_module);
/* record not deleted */
return(DA_FAIL);
}
/* get access right for data */
errln = 20;
EXEC SQL SELECT USER_ID,
PRIVS
INTO :h_env.user_id INDICATOR :h_ind_env.user_id,
:h_env.privs INDICATOR :h_ind_env.privs
FROM ENV_TAB
WHERE ENV_ID = :h_env.env_id;
/* check indicator variables (in regard to NULL values) */
if (h_ind_env.privs == -1) h_env.privs = 1;
if (h_ind_env.user_id == -1) strcpy(h_env.user_id, "");
/* copy result into temp. buffer */
v_env_buf.env_id = h_env.env_id;
v_env_buf.privs = h_env.privs;
strcpy (v_env_buf.user_id , h_env.user_id);
v_env_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_ENV_TAB, (void*) &v_env_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* delete specified record */
errln = 30;
EXEC SQL DELETE FROM ENV_TAB
WHERE ENV_ID = :h_env.env_id;
/* record successfully deleted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not deleted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_env (ENV_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_env()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_env (i) pointer to "list of" environment records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_env()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param vp_env pointer to "list of" environment records
\return ---
*/
void gda_free_env (DA_T_env *vp_env)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_env";
#endif
/* pointer to list elements */
DA_T_env *v_next_elem_ptr = NULL;
DA_T_env *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_env;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: ENV_DET_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_env_det (ENV_DET_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of environment detail data from ENV_DET_TAB ordered
* by ENV_DET_ID
*
* Query conditions:
* a) env_id <>-1, env_det_id =-1; return: 1..n records
* b) env_id <>-1, env_det_id<>-1; return: 1 records
*
* Parameter: vp_subst_id (i) ID of environment for which details shall
* be selected
* vp_env_det_id (i) ID of env. detail data to select
* vp_env_det (o) Return value (list of environm. details)
* vp_errinfo (o) Error info in case of error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of environment detail data from ENV_DET_TAB order by ENV_DET_ID.
Query conditions:
env_id <>-1, env_det_id =-1; return: 1..n records
env_id <>-1, env_det_id<>-1; return: 1 records
Output:
vp_env_det - Return value (list of environment data)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_subst_id ID of environment for which details shall be selected
\param vp_env_id ID of environment data to select
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_env_det (DB_con *db_con,
long vp_env_id,
long vp_env_det_id,
DA_T_env_det **vp_env_det,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_env_det";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_env_det v_env_det_buf;
/* pointer to list root */
DA_T_env_det *v_root_lst_ptr = NULL;
/* pointer to list element */
DA_T_env_det *v_new_elem_ptr = NULL;
DA_T_env_det *v_last_elem_ptr = NULL;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_where_clause [100];
char h_query [2000];
char h_con_name [ 31];
struct DA_T_env_det_pg_h{ /* type contains host variables for object data */
long env_det_id;
long env_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value [256];
char dist_type [ 12];
char remark [2001];
} h_env_det;
struct DA_T_env_det_pg_i{ /* indicator variables for host variable struct */
short int env_det_id;
short int env_id;
short int field_id;
short int block_id;
short int block_recno;
short int value;
short int dist_type;
short int remark;
} h_ind_env_det;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* determine query condition
* a) env_id <>-1, env_det_id =-1; return: 1..n records
* b) env_id <>-1, env_det_id<>-1; return: 1 records
*/
if (vp_env_det_id == -1)
{
/* case a) */
sprintf(h_where_clause,"ENV_ID = %ld ", vp_env_id);
}
else
{
/* case b) */
sprintf(h_where_clause,"ENV_ID = %ld AND ENV_DET_ID = %ld ", vp_env_id, vp_env_det_id);
}
/*
* DECLARE CURSOR
* to select the session from ENV_DET_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT ENV_DET_ID,"
"ENV_ID,"
"FIELD_ID,"
"BLOCK_ID,"
"BLOCK_RECNO,"
"VALUE_EDT,"
"DIST_TYPE,"
"REMARK "
" FROM ENV_DET_TAB "
"WHERE %s "
"ORDER BY ENV_DET_ID", h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE env_det_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN env_det_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH env_det_csr INTO :h_env_det INDICATOR :h_ind_env_det;
/* check indicator variables (in regard to NULL values) */
if (h_ind_env_det.env_det_id == -1) h_env_det.env_det_id = -1;
if (h_ind_env_det.env_id == -1) h_env_det.env_id = -1;
if (h_ind_env_det.block_recno == -1) h_env_det.block_recno = 0;
if (h_ind_env_det.field_id == -1) strcpy(h_env_det.field_id, "");
if (h_ind_env_det.block_id == -1) strcpy(h_env_det.block_id, "");
if (h_ind_env_det.value == -1) strcpy(h_env_det.value, "");
if (h_ind_env_det.dist_type == -1) strcpy(h_env_det.dist_type, "");
if (h_ind_env_det.remark == -1) strcpy(h_env_det.remark, "");
/* copy result into temp. buffer */
v_env_det_buf.env_det_id = h_env_det.env_det_id;
v_env_det_buf.env_id = h_env_det.env_id;
v_env_det_buf.block_recno = h_env_det.block_recno;
strcpy(v_env_det_buf.field_id , h_env_det.field_id);
strcpy(v_env_det_buf.block_id , h_env_det.block_id);
strcpy(v_env_det_buf.value , h_env_det.value);
strcpy(v_env_det_buf.dist_type , h_env_det.dist_type);
strcpy(v_env_det_buf.remark , h_env_det.remark);
v_env_det_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_ENV_DET_TAB, (void*) &v_env_det_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_env_det*) malloc( sizeof(DA_T_env_det) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf (vp_errinfo->err_param,"%s - malloc(DA_T_env_det)", v_module);
/* release already allocated memory */
gda_free_env_det(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_env_det) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_env_det_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE env_det_csr;
/* return created result list */
(*vp_env_det) = v_root_lst_ptr;
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE env_det_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_env_det (ENV_DET_TAB)
*
* Issue : 07-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : - Insert record into ENV_DET_TAB. Return new "ENV_DET_ID"
* by passed struct, in case insert could successfully be
* done.
*
* - Before INSERT is done
* a) check by FIELD_ID, BLOCK_ID if master record in table
* PARA_TREE_DEF_TAB exists. In case not -> cancel insert!
* b) check by ENV_ID if master record in table ENV_TAB
* exists. In case not -> cancel insert!
*
* - Update "MOD_DATE" in master record (ENV_TAB) by CURRENT_TIMESTAMP
*
*
* Parameter: vp_env_det (i/o) data to insert into ENV_DET_TAB,
* OUTPUT:
* new env_det_id = ENV_DET_SEQ.NEXTVAL
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into ENV_DET_TAB.
Return new "ENV_DET_ID" by passed struct, in case insert could successfully be done.
Before INSERT is done
check by FIELD_ID, BLOCK_ID if master record in table PARA_TREE_DEF_TAB exists. In case not -> cancel insert!
check by ENV_ID if master record in table ENV_TAB exists. In case not -> cancel insert!
Update "MOD_DATE" in master record (ENV_TAB) by CURRENT_TIMESTAMP.
Output:
vp_env_det - new env_det_id
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 07-AUG-2002
\param db_con Pointer to connection
\param vp_env data to insert into ENV_DET_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_env_det (DB_con *db_con,
DA_T_env_det *vp_env_det,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_env_det";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_master_chk = DA_FAIL;
char v_errmsg[256];
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_env_det_id_new;
long h_env_id_qry;
char h_fmt_date[30];
char h_con_name [ 31];
struct DA_T_env_det_pg_h{ /* type contains host variables for object data */
long env_det_id;
long env_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value [256];
char dist_type [ 12];
char remark [2001];
} h_env_det;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* set format mask */
strcpy(h_fmt_date, DA_FMT_date);
/* ------------------ *
* PRE-CHECKS
* ------------------ */
v_master_chk = lgda_chk_env_det_master (vp_env_det->env_id,
vp_env_det->field_id,
vp_env_det->block_id,
vp_errinfo);
if (v_master_chk != DA_SUCCESS)
{
/* error during check of master record */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_ENV_DET_TAB, (void*) vp_env_det,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* get new ENV_DET_ID */
errln = 50;
EXEC SQL SELECT NEXTVAL('ENV_DET_SEQ')
INTO :h_env_det_id_new;
/*
* copy passed record into host variable
*/
h_env_det.env_det_id = h_env_det_id_new;
h_env_det.env_id = vp_env_det->env_id;
h_env_det.block_recno = vp_env_det->block_recno;
strcpy(h_env_det.field_id , vp_env_det->field_id);
strcpy(h_env_det.block_id , vp_env_det->block_id);
strcpy(h_env_det.value , vp_env_det->value);
strcpy(h_env_det.dist_type , vp_env_det->dist_type);
strcpy(h_env_det.remark , vp_env_det->remark);
/* Insert passed record */
errln = 60;
EXEC SQL INSERT INTO ENV_DET_TAB ( ENV_DET_ID,
ENV_ID,
FIELD_ID,
BLOCK_ID,
BLOCK_RECNO,
VALUE_EDT,
DIST_TYPE,
REMARK )
VALUES (:h_env_det.env_det_id,
:h_env_det.env_id,
:h_env_det.field_id,
:h_env_det.block_id,
:h_env_det.block_recno,
:h_env_det.value,
:h_env_det.dist_type,
:h_env_det.remark);
/* Update MOD_DATE in master (env_TAB) */
h_env_id_qry = vp_env_det->env_id;
errln = 70;
EXEC SQL UPDATE ENV_TAB
SET MOD_DATE = to_timestamp(to_char(CURRENT_TIMESTAMP, :h_fmt_date), :h_fmt_date)
WHERE ENV_ID = :h_env_id_qry;
/* set return value (created ENV_DET_ID) into passed struct/record */
vp_env_det->env_det_id = h_env_det_id_new;
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record successfully inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_env_det (ENV_DET_TAB)
*
* Issue : 07-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by ENV_DET_ID) in ENV_DET_TAB
* by data of passed record.
*
* - Before UPDATE is done
* a) check by FIELD_ID, BLOCK_ID if master record in table
* PARA_TREE_DEF_TAB exists. In case not -> cancel update!
* b) check by ENV_ID if master record in table ENV_TAB
* exists. In case not -> cancel update!
*
* - Update "MOD_DATE" in master record (ENV_TAB) by CURRENT_TIMESTAMP
*
*
* Parameter: vp_env_det (i) new envirnm. detail data, containing ENV_DET_ID
* of record to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by ENV_ID) in ENV_DET_TAB by data of passed record.
Before UPDATE is done
check by FIELD_ID, BLOCK_ID if master record in table PARA_TREE_DEF_TAB exists. In case not -> cancel update!
check by ENV_ID if master record in table ENV_TAB exists. In case not -> cancel update!
Update "MOD_DATE" in master record (ENV_TAB) by CURRENT_TIMESTAMP.
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 07-AUG-2002
\param db_con Pointer to connection
\param vp_env new environment detail data, containing ENV_DET_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_env_det (DB_con *db_con,
DA_T_env_det *vp_env_det,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_env_det";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_master_chk = DA_FAIL;
char v_errmsg[256];
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_env_det_id;
long h_env_id_qry;
char h_fmt_date[30];
char h_con_name [ 31];
struct DA_T_env_det_pg_h{ /* type contains host variables for object data */
long env_det_id;
long env_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value [256];
char dist_type [ 12];
char remark [2001];
} h_env_det;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set date format mask */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* ------------------ *
* PRE-CHECKS
* ------------------ */
v_master_chk = lgda_chk_env_det_master(vp_env_det->env_id,
vp_env_det->field_id,
vp_env_det->block_id,
vp_errinfo);
if (v_master_chk != DA_SUCCESS)
{
/* error during check of master record */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_ENV_DET_TAB, (void*) vp_env_det,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_env_det_id = vp_env_det->env_det_id;
h_env_det.env_det_id = vp_env_det->env_det_id;
h_env_det.env_id = vp_env_det->env_id;
h_env_det.block_recno = vp_env_det->block_recno;
strcpy(h_env_det.field_id , vp_env_det->field_id);
strcpy(h_env_det.block_id , vp_env_det->block_id);
strcpy(h_env_det.value , vp_env_det->value);
strcpy(h_env_det.dist_type , vp_env_det->dist_type);
strcpy(h_env_det.remark , vp_env_det->remark);
/* Update passed record in database */
errln = 10;
EXEC SQL UPDATE ENV_DET_TAB
SET ENV_DET_ID = :h_env_det.env_det_id,
ENV_ID = :h_env_det.env_id,
FIELD_ID = :h_env_det.field_id,
BLOCK_ID = :h_env_det.block_id,
BLOCK_RECNO = :h_env_det.block_recno,
VALUE_EDT = :h_env_det.value,
DIST_TYPE = :h_env_det.dist_type,
REMARK = :h_env_det.remark
WHERE ENV_DET_ID = :h_env_det_id;
/* Update MOD_DATE in master (ENV_TAB) */
h_env_id_qry = vp_env_det->env_id;
errln = 20;
EXEC SQL UPDATE ENV_TAB
SET MOD_DATE = to_timestamp(to_char(CURRENT_TIMESTAMP,:h_fmt_date), :h_fmt_date)
WHERE ENV_ID = :h_env_id_qry;
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record successfully inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_env_det (ENV_DET_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_env_det()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_env_det (i) pointer to "list of" substance det. records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_env_det()".
Pointer must be explizitely set to NULL in the calling Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param vp_env pointer to "list of" substance det. records
\return ---
*/
void gda_free_env_det (DA_T_env_det *vp_env_det)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_env_det";
#endif
/* pointer to list elements */
DA_T_env_det *v_next_elem_ptr = NULL;
DA_T_env_det *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_env_det;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: MARKET_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_market (MARKET_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of market data from MARKET_TAB ordered by MARKET_ID
*
* Query conditions:
* a) catch_id <> -1
* disch_id = -1
* market_id = -1
* => return: 1..n records!
*
* b) catch_id <> -1
* disch_id <> -1
* market_id<> -1
* => return: 1 record!
*
* Parameter: vp_catch_id (i) ID of catchment to which market data
* belong
* vp_disch_id (i) ID of disch to which market data belong
* vp_market_id (i) ID of market data record
* vp_market (o) Return value (list of market data)
* vp_errinfo (o) Error info in case of error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of market data from MARKET_TAB ordered by MARKET_ID.
Query conditions:
catch_id <> -1
disch_id = -1
market_id = -1
=> return: 1..n records!
catch_id <> -1
disch_id <> -1
market_id<> -1
=> return: 1 record!
Output:
vp_market - Return value (list of market data)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_catch_id ID of catchment to which market data belong
\param vp_disch_id ID of disch to which market data belong
\param vp_market_id ID of market data record
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_market (DB_con *db_con,
long vp_catch_id,
long vp_disch_id,
long vp_market_id,
DA_T_market **vp_market,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_market";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_market v_market_buf;
/* pointer to list root */
DA_T_market *v_root_lst_ptr = NULL;
/* pointer to list element */
DA_T_market *v_new_elem_ptr = NULL;
DA_T_market *v_last_elem_ptr = NULL;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_fmt_date [ 30];
char h_con_name [ 31];
char h_where_clause [100];
char h_query [2000];
struct DA_T_market_pg_h{ /* type contains host variables for object data */
long market_id;
long disch_id;
long catch_id;
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char consumption[ 41];
char surface_potential[41];
char roof_runoff[ 41];
char street_runoff[41];
char flux_nondom[ 41];
char flux_runoff[ 41];
char wwtp_removal[41];
char remark[2001];
} h_market;
struct DA_T_market_pg_i{ /* indicator variables for host variable struct */
short int market_id;
short int disch_id;
short int catch_id;
short int name;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int consumption;
short int surface_potential;
short int roof_runoff;
short int street_runoff;
short int flux_nondom;
short int flux_runoff;
short int wwtp_removal;
short int remark;
} h_ind_market;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/*
* determine query condition
* a) catch_id <> -1
* disch_id = -1
* market_id = -1 => return: 1..n records!
* b) catch_id <> -1
* disch_id <> -1
* market_id<> -1 => return: 1 record!
*/
if (vp_catch_id == -1 && vp_disch_id == -1 && vp_market_id == -1)
strcpy(h_where_clause, "");
else if (vp_catch_id != -1 && vp_disch_id != -1 && vp_market_id != -1)
sprintf(h_where_clause,"WHERE CATCH_ID = %ld AND DISCH_ID = %ld AND MARKET_ID = %ld ",
vp_catch_id, vp_disch_id, vp_market_id);
else if (vp_catch_id != -1 && vp_disch_id == -1 && vp_market_id == -1)
sprintf(h_where_clause,"WHERE CATCH_ID = %ld ", vp_catch_id);
else if (vp_catch_id == -1 && vp_disch_id != -1 && vp_market_id == -1)
sprintf(h_where_clause,"WHERE DISCH_ID = %ld ", vp_disch_id);
else if (vp_catch_id == -1 && vp_disch_id == -1 && vp_market_id != -1)
sprintf(h_where_clause,"WHERE MARKET_ID = %ld ", vp_market_id);
else if (vp_catch_id != -1 && vp_disch_id != -1 && vp_market_id == -1)
sprintf(h_where_clause,"WHERE CATCH_ID = %ld AND DISCH_ID = %ld ", vp_catch_id, vp_disch_id);
else if (vp_catch_id != -1 && vp_disch_id == -1 && vp_market_id != -1)
sprintf(h_where_clause,"WHERE CATCH_ID = %ld AND MARKET_ID = %ld ", vp_catch_id, vp_market_id);
else if (vp_catch_id == -1 && vp_disch_id != -1 && vp_market_id != -1)
sprintf(h_where_clause,"WHERE DISCH_ID = %ld AND MARKET_ID = %ld ", vp_disch_id, vp_market_id);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the session from MARKET_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT MARKET_ID,"
"DISCH_ID,"
"CATCH_ID,"
"NAME,"
"USER_ID,"
"to_char(CRE_DATE, '%s'),"
"to_char(MOD_DATE, '%s'),"
"STATUS,"
"PRIVS,"
"CONSUMPTION,"
"SURFACE_POTENTIAL,"
"ROOF_RUNOFF,"
"STREET_RUNOFF,"
"FLUX_NONDOM,"
"FLUX_RUNOFF,"
"WWTP_REMOVAL,"
"REMARK "
"FROM MARKET_TAB "
"%s "
"ORDER BY MARKET_ID",
h_fmt_date, h_fmt_date, h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE market_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN market_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH market_csr INTO :h_market INDICATOR :h_ind_market;
/* check indicator variables (in regard to NULL values) */
if (h_ind_market.market_id == -1) h_market.market_id = -1;
if (h_ind_market.disch_id == -1) h_market.disch_id = -1;
if (h_ind_market.catch_id == -1) h_market.catch_id = -1;
if (h_ind_market.privs == -1) h_market.privs = 1;
if (h_ind_market.name == -1) strcpy(h_market.name, "");
if (h_ind_market.user_id == -1) strcpy(h_market.user_id, "");
if (h_ind_market.cre_date == -1) strcpy(h_market.cre_date, "");
if (h_ind_market.mod_date == -1) strcpy(h_market.mod_date, "");
if (h_ind_market.status == -1) strcpy(h_market.status, "");
if (h_ind_market.consumption== -1) strcpy(h_market.consumption, "");
if (h_ind_market.surface_potential==-1) strcpy(h_market.surface_potential, "");
if (h_ind_market.roof_runoff== -1) strcpy(h_market.roof_runoff, "");
if (h_ind_market.street_runoff==-1) strcpy(h_market.street_runoff,"");
if (h_ind_market.flux_nondom== -1) strcpy(h_market.flux_nondom, "");
if (h_ind_market.flux_runoff== -1) strcpy(h_market.flux_runoff, "");
if (h_ind_market.wwtp_removal==-1) strcpy(h_market.wwtp_removal,"");
if (h_ind_market.remark == -1) strcpy(h_market.remark, "");
/* copy result into temp. buffer */
v_market_buf.market_id = h_market.market_id;
v_market_buf.disch_id = h_market.disch_id;
v_market_buf.catch_id = h_market.catch_id;
v_market_buf.privs = h_market.privs;
strcpy(v_market_buf.name , h_market.name);
strcpy(v_market_buf.user_id , h_market.user_id);
strcpy(v_market_buf.cre_date , h_market.cre_date);
strcpy(v_market_buf.mod_date , h_market.mod_date);
strcpy(v_market_buf.status , h_market.status);
strcpy(v_market_buf.consumption, h_market.consumption);
strcpy(v_market_buf.surface_potential, h_market.surface_potential);
strcpy(v_market_buf.roof_runoff, h_market.roof_runoff);
strcpy(v_market_buf.street_runoff, h_market.street_runoff);
strcpy(v_market_buf.flux_nondom, h_market.flux_nondom);
strcpy(v_market_buf.flux_runoff, h_market.flux_runoff);
strcpy(v_market_buf.wwtp_removal,h_market.wwtp_removal);
strcpy(v_market_buf.remark , h_market.remark);
v_market_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_MARKET_TAB, (void*) &v_market_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_market*) malloc( sizeof(DA_T_market) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf (vp_errinfo->err_param,"%s - malloc(DA_T_market)", v_module);
/* release already allocated memory */
gda_free_market(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_market) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_market_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE market_csr;
/* return created result list */
(*vp_market) = v_root_lst_ptr;
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE market_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_market (MARKET_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Insert record into MARKET_TAB. Return new "MARKET_ID" by
* passed struct, in case insert could successfully be done.
*
* The new (inserted) market record will be automatically linked
* to the specified session, because a market record must always
* be linked to a session!
*
* Parameter: vp_market (i/o) data to insert into MARKET_TAB,
* OUTPUT: (->MARKET_ID)
* a) When record was first market record for
* specified session:
* -> MARKET_ID =
* cre_date = CURRENT_TIMESTAMP
* mod_date = CURRENT_TIMESTAMP
* user_id =
*
* a) When record was additional market record
* for specified session:
* -> MARKET_ID = SESS_TAB.MARKET_ID
* cre_date = CURRENT_TIMESTAMP
* mod_date = CURRENT_TIMESTAMP
* user_id =
*
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
* vg_db_user_info(i) -> general information about database
* user of current db-session
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into MARKET_TAB.
Return new "MARKET_ID" by passed struct, in case insert could successfully be done.
The new (inserted) market record will be automatically linked to the specified session, because a market record must always be linked to a session!
Output:
vp_market - MARKET_ID, cre_date, mod_date, user_id
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_sess_id ID of Session for MARKET_ID
\param vp_market data to insert into MARKET_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_market (DB_con *db_con,
long vp_sess_id,
DA_T_market *vp_market,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_market";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_sess_id_qry;
long h_market_id_new;
char h_fmt_date[30];
short int h_ind_market_id_new;
char h_con_name [ 31];
struct DA_T_market_pg_h{ /* type contains host variables for object data */
long market_id;
long disch_id;
long catch_id;
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char consumption[ 41];
char surface_potential[41];
char roof_runoff[ 41];
char street_runoff[41];
char flux_nondom[ 41];
char flux_runoff[ 41];
char wwtp_removal[41];
char remark[2001];
} h_market;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/* current db-user becomes owner of the new data -> acc. rhgt=VIEW+EDIT */
v_access_right = DA_A_VIEWEDIT;
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* get new MARKET_ID for record to insert
*/
/* a) check for already market record in MARKET_TAB that are
* linked to specified session */
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO get_new_id_from_sequence;
h_sess_id_qry = vp_sess_id;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
errln = 20;
EXEC SQL SELECT S.MARKET_ID,
to_char(CURRENT_TIMESTAMP, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_market_id_new INDICATOR :h_ind_market_id_new,
:h_market.cre_date,
:h_market.mod_date
FROM SESS_TAB S,
MARKET_TAB M
WHERE S.SESS_ID = :h_sess_id_qry
AND M.MARKET_ID = S.MARKET_ID
LIMIT 1;
if (NULL)
{
get_new_id_from_sequence:
/* b) first market record will be inserted for spec. session
* => get new market id */
errln = 30;
EXEC SQL SELECT NEXTVAL('MARKET_SEQ'),
to_char(CURRENT_TIMESTAMP, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_market_id_new,
:h_market.cre_date,
:h_market.mod_date;
/* link record to current session */
errln = 40;
EXEC SQL UPDATE SESS_TAB
SET MARKET_ID = :h_market_id_new
WHERE SESS_ID = :h_sess_id_qry;
}
/*
* copy passed record into host variable
*/
h_market.market_id = h_market_id_new;
h_market.disch_id = vp_market->disch_id;
h_market.catch_id = vp_market->catch_id;
h_market.privs = vp_market->privs;
strcpy(h_market.name , vp_market->name);
strcpy(h_market.user_id , vg_db_user_info.user_id);
strcpy(h_market.status , vp_market->status);
strcpy(h_market.consumption, vp_market->consumption);
strcpy(h_market.surface_potential, vp_market->surface_potential);
strcpy(h_market.roof_runoff, vp_market->roof_runoff);
strcpy(h_market.street_runoff, vp_market->street_runoff);
strcpy(h_market.flux_nondom, vp_market->flux_nondom);
strcpy(h_market.flux_runoff, vp_market->flux_runoff);
strcpy(h_market.wwtp_removal,vp_market->wwtp_removal);
strcpy(h_market.remark , vp_market->remark);
/* Insert passed record */
errln = 50;
EXEC SQL INSERT INTO MARKET_TAB ( MARKET_ID,
DISCH_ID,
CATCH_ID,
NAME,
USER_ID,
CRE_DATE,
MOD_DATE,
STATUS,
PRIVS,
CONSUMPTION,
SURFACE_POTENTIAL,
ROOF_RUNOFF,
STREET_RUNOFF,
FLUX_NONDOM,
FLUX_RUNOFF,
WWTP_REMOVAL,
REMARK )
VALUES ( :h_market.market_id,
:h_market.disch_id,
:h_market.catch_id,
:h_market.name,
:h_market.user_id,
to_timestamp(:h_market.cre_date, :h_fmt_date),
to_timestamp(:h_market.mod_date, :h_fmt_date),
:h_market.status,
:h_market.privs,
:h_market.consumption,
:h_market.surface_potential,
:h_market.roof_runoff,
:h_market.street_runoff,
:h_market.flux_nondom,
:h_market.flux_runoff,
:h_market.wwtp_removal,
:h_market.remark);
/* set return value (created MARKET_ID,...) into passed struct/record */
vp_market->market_id = h_market_id_new;
strcpy(vp_market->user_id, h_market.user_id);
strcpy(vp_market->cre_date, h_market.cre_date);
strcpy(vp_market->mod_date, h_market.mod_date);
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_market (MARKET_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by MARKET_ID) in MARKET_TAB
* by data of passed record.
*
* Parameter: vp_market (i) new market data, containing MARKET_ID
* of record to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by MARKET_ID) in MARKET_TAB by data of passed record.
calls gda_update_market().
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_market new market data, containing MARKET_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_market (DB_con *db_con,
DA_T_market *vp_market,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_market";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_catch_id_qry;
long h_disch_id_qry;
long h_market_id_qry;
char h_fmt_date[30];
char h_con_name[31];
struct DA_T_market_pg_h{ /* type contains host variables for object data */
long market_id;
long disch_id;
long catch_id;
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char consumption[ 41];
char surface_potential[41];
char roof_runoff[ 41];
char street_runoff[41];
char flux_nondom[ 41];
char flux_runoff[ 41];
char wwtp_removal[41];
char remark[2001];
} h_market;
short int h_ind_mod_date;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_MARKET_TAB, (void*) vp_market,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_market.market_id = vp_market->market_id;
h_market.disch_id = vp_market->disch_id;
h_market.catch_id = vp_market->catch_id;
h_market.privs = vp_market->privs;
strcpy(h_market.name , vp_market->name);
strcpy(h_market.user_id , vp_market->user_id);
strcpy(h_market.cre_date , vp_market->cre_date);
strcpy(h_market.mod_date , vp_market->mod_date);
strcpy(h_market.status , vp_market->status);
strcpy(h_market.consumption, vp_market->consumption);
strcpy(h_market.surface_potential, vp_market->surface_potential);
strcpy(h_market.roof_runoff, vp_market->roof_runoff);
strcpy(h_market.street_runoff, vp_market->street_runoff);
strcpy(h_market.flux_nondom, vp_market->flux_nondom);
strcpy(h_market.flux_runoff, vp_market->flux_runoff);
strcpy(h_market.wwtp_removal,vp_market->wwtp_removal);
strcpy(h_market.remark , vp_market->remark);
/* Update passed record in database */
h_catch_id_qry = vp_market->catch_id;
h_disch_id_qry = vp_market->disch_id;
h_market_id_qry = vp_market->market_id;
errln = 10;
EXEC SQL SELECT to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_market.mod_date INDICATOR :h_ind_mod_date;
if (h_ind_mod_date == -1)
{
strcpy(h_market.mod_date,"");
}
/* ignore CRE_DATE for update */
errln = 20;
EXEC SQL UPDATE MARKET_TAB
SET MARKET_ID = :h_market.market_id,
DISCH_ID = :h_market.disch_id,
CATCH_ID = :h_market.catch_id,
NAME = :h_market.name,
USER_ID = :h_market.user_id,
MOD_DATE = to_timestamp(:h_market.mod_date, :h_fmt_date),
STATUS = :h_market.status,
PRIVS = :h_market.privs,
CONSUMPTION = :h_market.consumption,
SURFACE_POTENTIAL = :h_market.surface_potential,
ROOF_RUNOFF = :h_market.roof_runoff,
STREET_RUNOFF = :h_market.street_runoff,
FLUX_NONDOM = :h_market.flux_nondom,
FLUX_RUNOFF = :h_market.flux_runoff,
WWTP_REMOVAL= :h_market.wwtp_removal,
REMARK = :h_market.remark
WHERE CATCH_ID = :h_catch_id_qry
AND DISCH_ID = :h_disch_id_qry
AND MARKET_ID = :h_market_id_qry;
/* return new MOD_DATE */
strcpy(vp_market->mod_date, h_market.mod_date);
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_market (MARKET_TAB)
*
* Issue : 18-JUL-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Delete record from MARKET_TAB specified by "market_id"
*
* Delete condition:
* ------------------
* CATCH_ID > 0, DISCH_ID > 0, MARKET_ID > 0
*
* Parameter: vp_market_id (i) MARKET_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from MARKET_TAB specified by "market_id".
Delete condition:
CATCH_ID > 0, DISCH_ID > 0, MARKET_ID > 0
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 18-JUL-2002
\param db_con Pointer to connection
\param vp_market vp_market_id MARKET_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_market (DB_con *db_con,
long vp_catch_id,
long vp_disch_id,
long vp_market_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_delete_market";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
DA_T_market v_market_buf;
EXEC SQL BEGIN DECLARE SECTION;
long h_count;
char h_con_name[31];
struct DA_T_market_pg_h{ /* type contains host variables for object data */
long market_id;
long disch_id;
long catch_id;
char name [256];
char user_id [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char consumption[ 41];
char surface_potential[41];
char roof_runoff[ 41];
char street_runoff[41];
char flux_nondom[ 41];
char flux_runoff[ 41];
char wwtp_removal[41];
char remark[2001];
} h_market;
struct DA_T_market_pg_i{ /* indicator variables for host variable struct */
short int market_id;
short int disch_id;
short int catch_id;
short int name;
short int user_id;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int consumption;
short int surface_potential;
short int roof_runoff;
short int street_runoff;
short int flux_nondom;
short int flux_runoff;
short int wwtp_removal;
short int remark;
} h_ind_market;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* get access right for data */
h_market.catch_id = vp_catch_id;
h_market.disch_id = vp_disch_id;
h_market.market_id = vp_market_id;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
errln = 10;
EXEC SQL SELECT USER_ID,
PRIVS
INTO :h_market.user_id INDICATOR :h_ind_market.user_id,
:h_market.privs INDICATOR :h_ind_market.privs
FROM MARKET_TAB
WHERE MARKET_ID = :h_market.market_id
AND CATCH_ID = :h_market.catch_id
AND DISCH_ID = :h_market.disch_id;
/* check indicator variables (in regard to NULL values) */
if (h_ind_market.privs == -1) h_market.privs = 1;
if (h_ind_market.user_id == -1) strcpy(h_market.user_id, "");
/* copy result into temp. buffer */
v_market_buf.market_id = h_market.market_id;
v_market_buf.privs = h_market.privs;
strcpy(v_market_buf.user_id , h_market.user_id);
v_market_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_MARKET_TAB, (void*) &v_market_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* delete specified record */
errln = 10;
EXEC SQL DELETE FROM MARKET_TAB
WHERE MARKET_ID = :h_market.market_id
AND CATCH_ID = :h_market.catch_id
AND DISCH_ID = :h_market.disch_id;
/* check if record was the last MARKET record for linked
master record in SESS_TAB. In case it was, then RESET
reference to MARKET record in SESS_TAB */
errln = 20;
EXEC SQL SELECT COUNT(MARKET_ID)
INTO :h_count
FROM MARKET_TAB
WHERE MARKET_ID = :h_market.market_id;
if (h_count == 0)
{
/* last MARKET record was deleted -> reset ref. at master rec. */
errln = 30;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 40;
EXEC SQL UPDATE SESS_TAB
SET MARKET_ID = NULL
WHERE MARKET_ID = :h_market.market_id;
}
/* record successfully deleted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not deleted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_market (MARKET_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_market()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_market (i) pointer to "list of" market records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_market()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param vp_market pointer to "list of" market records
\return ---
*/
void gda_free_market ( DA_T_market *vp_market)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_market";
#endif
/* pointer to list elements */
DA_T_market *v_next_elem_ptr = NULL;
DA_T_market *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_market;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: MOD_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_mod (MOD_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of model modes data from MOD_TAB ordered by MOD_ID
*
* Query conditions:
* a) mod_id =-1; return: 1..n records
* b) mod_id<>-1; return: 1 record
*
* Parameter: vp_mod_id (i) ID of model mode to select
* vp_mod (o) Return value (list of model modes)
* vp_errinfo (o) Error info in case of error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of model modes data from MOD_TAB ordered by MOD_ID.
Query conditions:
mod_id =-1; return: 1..n records
mod_id<>-1; return: 1 record
Output:
vp_mod - Return value (list of model modes)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_mod_id ID of model mode to select
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_mod (DB_con *db_con,
long vp_mod_id,
DA_T_mod **vp_mod,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_mod";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_mod v_mod_buf;
/* pointer to list root */
DA_T_mod *v_root_lst_ptr = NULL;
/* pointer to list element */
DA_T_mod *v_new_elem_ptr = NULL;
DA_T_mod *v_last_elem_ptr = NULL;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_fmt_date [ 30];
char h_con_name [ 31];
char h_where_clause [100];
char h_query [2000];
struct DA_T_mod_pg_h{ /* type contains host variables for object data */
long mod_id;
char user_id [ 31];
char name [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char remark [2001];
} h_mod;
struct DA_T_mod_pg_i{ /* indicator variables for host variable struct */
short int mod_id;
short int user_id;
short int name;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int remark;
} h_ind_mod;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/*
* determine query condition
* a) mod_id =-1; return: 1..n records
* b) mod_id<>-1; return: 1 record
*/
if (vp_mod_id == -1)
{
/* case a) */
strcpy (h_where_clause, "");
}
else
{
/* case b) */
sprintf(h_where_clause, "WHERE MOD_ID = %ld ", vp_mod_id);
}
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the session from MOD_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT MOD_ID,"
"USER_ID,"
"NAME,"
"to_char(CRE_DATE, '%s'),"
"to_char(MOD_DATE, '%s'),"
"STATUS,"
"PRIVS,"
"REMARK "
"FROM MOD_TAB "
"%s "
"ORDER BY MOD_ID",
h_fmt_date, h_fmt_date, h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE mod_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN mod_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH mod_csr INTO :h_mod INDICATOR :h_ind_mod;
/* check indicator variables (in regard to NULL values) */
if (h_ind_mod.mod_id == -1) h_mod.mod_id = -1;
if (h_ind_mod.privs == -1) h_mod.privs = 1;
if (h_ind_mod.name == -1) strcpy(h_mod.name, "");
if (h_ind_mod.user_id == -1) strcpy(h_mod.user_id, "");
if (h_ind_mod.cre_date == -1) strcpy(h_mod.cre_date, "");
if (h_ind_mod.mod_date == -1) strcpy(h_mod.mod_date, "");
if (h_ind_mod.status == -1) strcpy(h_mod.status, "");
if (h_ind_mod.remark == -1) strcpy(h_mod.remark, "");
/* copy result into temp. buffer */
v_mod_buf.mod_id = h_mod.mod_id;
v_mod_buf.privs = h_mod.privs;
strcpy (v_mod_buf.name , h_mod.name);
strcpy (v_mod_buf.user_id , h_mod.user_id);
strcpy (v_mod_buf.cre_date , h_mod.cre_date);
strcpy (v_mod_buf.mod_date , h_mod.mod_date);
strcpy (v_mod_buf.status , h_mod.status);
strcpy (v_mod_buf.remark , h_mod.remark);
v_mod_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_MOD_TAB, (void*) &v_mod_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_mod*) malloc( sizeof(DA_T_mod) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf (vp_errinfo->err_param,"%s - malloc(DA_T_mod)", v_module);
/* release already allocated memory */
gda_free_mod(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_mod) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_mod_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE mod_csr;
/* return created result list */
(*vp_mod) = v_root_lst_ptr;
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE mod_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_mod (MOD_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Insert record into MOD_TAB. Return new "MOD_ID" by passed
* struct, in case insert could successfully be done
*
* Parameter: vp_mod (i/o) data to insert into MOD_TAB,
* OUTPUT:
* - mod_id = MOD_SEQ.NEXTVAL
* - cre_date = CURRENT_TIMESTAMP
* - mod_date = CURRENT_TIMESTAMP
* - user_id =
*
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
* vg_db_user_info(i) -> general information about database
* user of current db-session
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into MOD_TAB.
Return new "MOD_ID" by passed struct, in case insert could successfully be done.
Output:
vp_mod - mod_id, cre_date, mod_date, user_id (curr. db-user)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_mod data to insert into MOD_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_mod (DB_con *db_con,
DA_T_mod *vp_mod,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_mod";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_mod_id_new;
char h_fmt_date[30];
char h_con_name[31];
struct DA_T_mod_pg_h{ /* type contains host variables for object data */
long mod_id;
char user_id [ 31];
char name [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char remark [2001];
} h_mod;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* current user will become owner of the new record -> acc. rhgt.: VIEW+EDIT*/
v_access_right = DA_A_VIEWEDIT;
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* get new mod_ID */
errln = 10;
EXEC SQL SELECT NEXTVAL('MOD_SEQ'),
to_char(CURRENT_TIMESTAMP, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_mod_id_new,
:h_mod.cre_date,
:h_mod.mod_date;
/*
* copy passed record into host variable
*/
h_mod.mod_id = h_mod_id_new;
h_mod.privs = vp_mod->privs;
strcpy (h_mod.name , vp_mod->name);
strcpy (h_mod.user_id , vg_db_user_info.user_id);
strcpy (h_mod.status , vp_mod->status);
strcpy (h_mod.remark , vp_mod->remark);
/* Insert passed record */
errln = 20;
EXEC SQL INSERT INTO MOD_TAB ( MOD_ID,
USER_ID,
NAME,
CRE_DATE,
MOD_DATE,
STATUS,
PRIVS,
REMARK )
VALUES ( :h_mod.mod_id,
:h_mod.user_id,
:h_mod.name,
to_timestamp(:h_mod.cre_date, :h_fmt_date),
to_timestamp(:h_mod.mod_date, :h_fmt_date),
:h_mod.status,
:h_mod.privs,
:h_mod.remark );
/* set return value (created mod_ID) into passed struct/record */
vp_mod->mod_id = h_mod_id_new;
strcpy(vp_mod->user_id, h_mod.user_id);
strcpy(vp_mod->cre_date, h_mod.cre_date);
strcpy(vp_mod->mod_date, h_mod.mod_date);
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_mod (MOD_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by MOD_ID) in MOD_TAB by data of
* passed record.
*
* Parameter: vp_mod (i) new model mode data, containing MOD_ID
* of record to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by MOD_ID) in MOD_TAB by data of passed record.
calls gda_update_mod().
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_mod new model mode data, containing MOD_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_mod (DB_con *db_con,
DA_T_mod *vp_mod,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_mod";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_mod_id;
char h_fmt_date[30];
char h_con_name[31];
struct DA_T_mod_pg_h{ /* type contains host variables for object data */
long mod_id;
char user_id [ 31];
char name [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char remark [2001];
} h_mod;
short int h_ind_mod_date;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_MOD_TAB, (void*) vp_mod,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_mod_id = vp_mod->mod_id;
h_mod.mod_id = vp_mod->mod_id;
h_mod.privs = vp_mod->privs;
strcpy (h_mod.name , vp_mod->name);
strcpy (h_mod.user_id , vp_mod->user_id);
strcpy (h_mod.cre_date , vp_mod->cre_date);
strcpy (h_mod.mod_date , vp_mod->mod_date);
strcpy (h_mod.status , vp_mod->status);
strcpy (h_mod.remark , vp_mod->remark);
/* Update passed record in database */
errln = 10;
EXEC SQL SELECT to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_mod.mod_date INDICATOR :h_ind_mod_date;
if (h_ind_mod_date == -1)
{
strcpy(h_mod.mod_date,"");
}
/* Ignore CRE_DATE for update */
errln = 20;
EXEC SQL UPDATE MOD_TAB
SET MOD_ID = :h_mod.mod_id,
NAME = :h_mod.name,
USER_ID = :h_mod.user_id,
MOD_DATE = to_timestamp(:h_mod.mod_date, :h_fmt_date),
STATUS = :h_mod.status,
PRIVS = :h_mod.privs,
REMARK = :h_mod.remark
WHERE MOD_ID = :h_mod_id;
/* return new MOD_DATE */
strcpy(vp_mod->mod_date, h_mod.mod_date);
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_mod (MOD_TAB)
*
* Issue : 18-JUL-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Delete record from MOD_TAB specified by "MOD_ID"
*
* Parameter: vp_mod_id (i) MOD_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from MOD_TAB specified by "MOD_ID".
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 18-JUL-2002
\param db_con Pointer to connection
\param vp_mod_id MOD_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_mod (DB_con *db_con,
long vp_mod_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_delete_mod";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
DA_T_mod v_mod_buf;
EXEC SQL BEGIN DECLARE SECTION;
int h_count;
char h_con_name[31];
struct DA_T_mod_pg_h{ /* type contains host variables for object data */
long mod_id;
char user_id [ 31];
char name [ 31];
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
int privs;
char remark [2001];
} h_mod;
struct DA_T_mod_pg_i{ /* indicator variables for host variable struct */
short int mod_id;
short int user_id;
short int name;
short int cre_date;
short int mod_date;
short int status;
short int privs;
short int remark;
} h_ind_mod;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
errln = 10;
h_mod.mod_id = vp_mod_id;
EXEC SQL SELECT COUNT (SESS_ID)
INTO :h_count
FROM SESS_TAB
WHERE MOD_ID = :h_mod.mod_id;
if (h_count > 0)
{
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MOD_REF_DATA;
sprintf (vp_errinfo->err_param,"%s", v_module);
/* record not deleted */
return(DA_FAIL);
}
/* get access right for data */
errln = 10;
EXEC SQL SELECT USER_ID,
PRIVS
INTO :h_mod.user_id INDICATOR :h_ind_mod.user_id,
:h_mod.privs INDICATOR :h_ind_mod.privs
FROM MOD_TAB
WHERE mod_ID = :h_mod.mod_id;
/* check indicator variables (in regard to NULL values) */
if (h_ind_mod.privs == -1) h_mod.privs = 1;
if (h_ind_mod.user_id == -1) strcpy(h_mod.user_id, "");
/* copy result into temp. buffer */
v_mod_buf.mod_id = h_mod.mod_id;
v_mod_buf.privs = h_mod.privs;
strcpy (v_mod_buf.user_id , h_mod.user_id);
v_mod_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_MOD_TAB, (void*) &v_mod_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* delete specified record */
errln = 10;
EXEC SQL DELETE FROM MOD_TAB
WHERE MOD_ID = :h_mod.mod_id;
/* record successfully deleted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not deleted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_mod (MOD_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_mod()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_mod (i) pointer to "list of" model mode records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_mod()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param vp_mod pointer to "list of" model mode records
\return ---
*/
void gda_free_mod (DA_T_mod *vp_mod)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_mod";
#endif
/* pointer to list elements */
DA_T_mod *v_next_elem_ptr = NULL;
DA_T_mod *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_mod;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: MOD_DET_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_mod_det (MOD_DET_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of environment detail data from MOD_DET_TAB ordered
* by MOD_DET_ID
*
* Query conditions:
* a) mod_id <>-1, mod_det_id =-1; return: 1..n records
* b) mod_id <>-1, mod_det_id<>-1; return: 1 records
*
* Parameter: vp_mod_id (i) ID of model mode for which details shall
* be selected
* vp_mod_det_id (i) ID of model mode detail data to select
* vp_mod_det (o) Return value (list of model mode details)
* vp_errinfo (o) Error info in case of error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of environment detail data from MOD_DET_TAB ordered by MOD_DET_ID.
Query conditions:
mod_id <>-1, mod_det_id =-1; return: 1..n records
mod_id <>-1, mod_det_id<>-1; return: 1 records
Output:
vp_mod_det - Return value (list of model modes details)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_mod_id ID of model mode for which details shall be selected
\param vp_mod_det_id ID of model mode detail data to select
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_mod_det (DB_con *db_con,
long vp_mod_id,
long vp_mod_det_id,
DA_T_mod_det **vp_mod_det,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_mod_det";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_mod_det v_mod_det_buf;
/* pointer to list root */
DA_T_mod_det *v_root_lst_ptr = NULL;
/* pointer to list element */
DA_T_mod_det *v_new_elem_ptr = NULL;
DA_T_mod_det *v_last_elem_ptr = NULL;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_con_name [ 31];
char h_where_clause [100];
char h_query [2000];
struct DA_T_mod_det_pg_h{ /* type contains host variables for object data */
long mod_det_id;
long mod_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value [256];
char dist_type[ 12];
char remark [2001];
} h_mod_det;
struct DA_T_mod_det_pg_i{ /* indicator variables for host variable struct */
short int mod_det_id;
short int mod_id;
short int field_id;
short int block_id;
short int block_recno;
short int value;
short int dist_type;
short int remark;
} h_ind_mod_det;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* determine query condition
* a) mod_id <>-1, mod_det_id =-1; return: 1..n records
* b) mod_id <>-1, mod_det_id<>-1; return: 1 records
*/
if (vp_mod_det_id == -1)
{
/* case a) */
sprintf(h_where_clause, "WHERE MOD_ID = %ld ", vp_mod_id);
}
else
{
/* case b) */
sprintf(h_where_clause, "WHERE MOD_ID = %ld AND MOD_DET_ID = %ld ", vp_mod_id, vp_mod_det_id);
}
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the session from MOD_DET_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT MOD_DET_ID,"
"MOD_ID,"
"FIELD_ID,"
"BLOCK_ID,"
"BLOCK_RECNO,"
"VALUE_MDT,"
"DIST_TYPE,"
"REMARK "
"FROM MOD_DET_TAB "
"%s "
"ORDER BY MOD_DET_ID", h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE mod_det_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN mod_det_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH mod_det_csr INTO :h_mod_det INDICATOR :h_ind_mod_det;
/* check indicator variables (in regard to NULL values) */
if (h_ind_mod_det.mod_det_id == -1) h_mod_det.mod_det_id = -1;
if (h_ind_mod_det.mod_id == -1) h_mod_det.mod_id = -1;
if (h_ind_mod_det.block_recno == -1) h_mod_det.block_recno = 0;
if (h_ind_mod_det.field_id == -1) strcpy(h_mod_det.field_id, "");
if (h_ind_mod_det.block_id == -1) strcpy(h_mod_det.block_id, "");
if (h_ind_mod_det.value == -1) strcpy(h_mod_det.value, "");
if (h_ind_mod_det.dist_type == -1) strcpy(h_mod_det.dist_type, "");
if (h_ind_mod_det.remark == -1) strcpy(h_mod_det.remark, "");
/* copy result into temp. buffer */
v_mod_det_buf.mod_det_id = h_mod_det.mod_det_id;
v_mod_det_buf.mod_id = h_mod_det.mod_id;
v_mod_det_buf.block_recno = h_mod_det.block_recno;
strcpy(v_mod_det_buf.field_id , h_mod_det.field_id);
strcpy(v_mod_det_buf.block_id , h_mod_det.block_id);
strcpy(v_mod_det_buf.value , h_mod_det.value);
strcpy(v_mod_det_buf.dist_type , h_mod_det.dist_type);
strcpy(v_mod_det_buf.remark , h_mod_det.remark);
v_mod_det_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_MOD_DET_TAB, (void*) &v_mod_det_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_mod_det*) malloc( sizeof(DA_T_mod_det) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf (vp_errinfo->err_param,"%s - malloc(DA_T_mod_det)", v_module);
/* release already allocated memory */
gda_free_mod_det(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_mod_det) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_mod_det_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE mod_det_csr;
/* return created result list */
(*vp_mod_det) = v_root_lst_ptr;
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE mod_det_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_mod_det (MOD_DET_TAB)
*
* Issue : 07-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : - Insert record into MOD_DET_TAB. Return new "MOD_DET_ID"
* by passed struct, in case insert could successfully be
* done.
*
* - Before INSERT is done
* a) check by FIELD_ID, BLOCK_ID if master record in table
* PARA_TREE_DEF_TAB exists. In case not -> cancel insert!
* b) check by MOD_ID if master record in table MOD_TAB
* exists. In case not -> cancel insert!
*
* - Update "MOD_DATE" in master record (MOD_TAB) by CURRENT_TIMESTAMP
*
*
* Parameter: vp_mod_det (i/o) data to insert into MOD_DET_TAB,
* OUTPUT:
* new env_det_id = MOD_DET_SEQ.NEXTVAL
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into MOD_DET_TAB.
Return new "MOD_DET_ID" by passed struct, in case insert could successfully be done.
Before INSERT is done
check by FIELD_ID, BLOCK_ID if master record in table PARA_TREE_DEF_TAB exists. In case not -> cancel insert!
check by MOD_ID if master record in table MOD_TAB exists. In case not -> cancel insert!
Update "MOD_DATE" in master record (MOD_TAB) by CURRENT_TIMESTAMP.
Output:
vp_mod_det - new env_det_id
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 07-AUG-2002
\param db_con Pointer to connection
\param vp_mod_det data to insert into MOD_DET_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_mod_det (DB_con *db_con,
DA_T_mod_det *vp_mod_det,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_mod_det";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_master_chk = DA_FAIL;
char v_errmsg[256];
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_mod_det_id_new;
long h_mod_id_qry;
char h_fmt_date[30];
char h_con_name [ 31];
struct DA_T_mod_det_pg_h{ /* type contains host variables for object data */
long mod_det_id;
long mod_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value [256];
char dist_type[ 12];
char remark [2001];
} h_mod_det;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set date format mask */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* ------------------ *
* PRE-CHECKS
* ------------------ */
v_master_chk = lgda_chk_mod_det_master (vp_mod_det->mod_id,
vp_mod_det->field_id,
vp_mod_det->block_id,
vp_errinfo);
if (v_master_chk != DA_SUCCESS)
{
/* error during check of master record */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_MOD_DET_TAB, (void*) vp_mod_det,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* get new MOD_DET_ID */
errln = 50;
EXEC SQL SELECT NEXTVAL('mod_DET_SEQ')
INTO :h_mod_det_id_new;
/*
* copy passed record into host variable
*/
h_mod_det.mod_det_id = h_mod_det_id_new;
h_mod_det.mod_id = vp_mod_det->mod_id;
h_mod_det.block_recno = vp_mod_det->block_recno;
strcpy(h_mod_det.field_id , vp_mod_det->field_id);
strcpy(h_mod_det.block_id , vp_mod_det->block_id);
strcpy(h_mod_det.value , vp_mod_det->value);
strcpy(h_mod_det.dist_type , vp_mod_det->dist_type);
strcpy(h_mod_det.remark , vp_mod_det->remark);
/* Insert passed record */
errln = 60;
EXEC SQL INSERT INTO MOD_DET_TAB ( MOD_DET_ID,
MOD_ID,
FIELD_ID,
BLOCK_ID,
BLOCK_RECNO,
VALUE_MDT,
DIST_TYPE,
REMARK )
VALUES (:h_mod_det.mod_det_id,
:h_mod_det.mod_id,
:h_mod_det.field_id,
:h_mod_det.block_id,
:h_mod_det.block_recno,
:h_mod_det.value,
:h_mod_det.dist_type,
:h_mod_det.remark);
/* Update MOD_DATE in master (mod_TAB) */
h_mod_id_qry = vp_mod_det->mod_id;
errln = 70;
EXEC SQL UPDATE mod_TAB
SET MOD_DATE = to_timestamp(to_char(CURRENT_TIMESTAMP, :h_fmt_date), :h_fmt_date)
WHERE mod_ID = :h_mod_id_qry;
/* set return value (created mod_DET_ID) into passed struct/record */
vp_mod_det->mod_det_id = h_mod_det_id_new;
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record successfully inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_mod_det (MOD_DET_TAB)
*
* Issue : 07-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by MOD_DET_ID) in MOD_DET_TAB
* by data of passed record.
*
* - Before UPDATE is done
* a) check by FIELD_ID, BLOCK_ID if master record in table
* PARA_TREE_DEF_TAB exists. In case not -> cancel update!
* b) check by MOD_ID if master record in table MOD_TAB
* exists. In case not -> cancel update!
*
* - Update "MOD_DATE" in master record (MOD_TAB) by CURRENT_TIMESTAMP
*
*
* Parameter: vp_mod_det (i) new model mode detail data, containing
* MOD_DET_ID of record to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by MOD_ID) in MOD_TAB by data of passed record.
Before UPDATE is done
check by FIELD_ID, BLOCK_ID if master record in table PARA_TREE_DEF_TAB exists. In case not -> cancel update!
check by MOD_ID if master record in table MOD_TAB exists. In case not -> cancel update!
Update "MOD_DATE" in master record (MOD_TAB) by CURRENT_TIMESTAMP
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 07-AUG-2002
\param db_con Pointer to connection
\param vp_mod_det new model mode detail data, containing MOD_ID_DET of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_mod_det (DB_con *db_con,
DA_T_mod_det *vp_mod_det,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_mod_det";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_master_chk = DA_FAIL;
char v_errmsg[256];
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_mod_det_id;
long h_mod_id_qry;
char h_fmt_date[30];
char h_con_name [ 31];
struct DA_T_mod_det_pg_h{ /* type contains host variables for object data */
long mod_det_id;
long mod_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value [256];
char dist_type[ 12];
char remark [2001];
} h_mod_det;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set date format mask */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* ------------------ *
* PRE-CHECKS
* ------------------ */
v_master_chk = lgda_chk_mod_det_master(vp_mod_det->mod_id,
vp_mod_det->field_id,
vp_mod_det->block_id,
vp_errinfo);
if (v_master_chk != DA_SUCCESS)
{
/* error during check of master record */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_MOD_DET_TAB, (void*) vp_mod_det,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_mod_det_id = vp_mod_det->mod_det_id;
h_mod_det.mod_det_id = vp_mod_det->mod_det_id;
h_mod_det.mod_id = vp_mod_det->mod_id;
h_mod_det.block_recno = vp_mod_det->block_recno;
strcpy(h_mod_det.field_id , vp_mod_det->field_id);
strcpy(h_mod_det.block_id , vp_mod_det->block_id);
strcpy(h_mod_det.value , vp_mod_det->value);
strcpy(h_mod_det.dist_type , vp_mod_det->dist_type);
strcpy(h_mod_det.remark , vp_mod_det->remark);
/* Update passed record in database */
errln = 10;
EXEC SQL UPDATE MOD_DET_TAB
SET MOD_DET_ID = :h_mod_det.mod_det_id,
MOD_ID = :h_mod_det.mod_id,
FIELD_ID = :h_mod_det.field_id,
BLOCK_ID = :h_mod_det.block_id,
BLOCK_RECNO = :h_mod_det.block_recno,
VALUE_MDT = :h_mod_det.value,
DIST_TYPE = :h_mod_det.dist_type,
REMARK = :h_mod_det.remark
WHERE MOD_DET_ID = :h_mod_det_id;
/* Update MOD_DATE in master (mod_TAB) */
h_mod_id_qry = vp_mod_det->mod_id;
errln = 20;
EXEC SQL UPDATE MOD_TAB
SET MOD_DATE = to_timestamp(to_char(CURRENT_TIMESTAMP, :h_fmt_date), :h_fmt_date)
WHERE MOD_ID = :h_mod_id_qry;
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record successfully inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_mod_det (MOD_DET_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_mod_det()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_mod_det (i) pointer to "list of" model mode detail rec.
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_mod_det()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param vp_mod_det pointer to "list of" model mode detail records
\return ---
*/
void gda_free_mod_det (DA_T_mod_det *vp_mod_det)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_mod_det";
#endif
/* pointer to list elements */
DA_T_mod_det *v_next_elem_ptr = NULL;
DA_T_mod_det *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_mod_det;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: RES_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_res (RES_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of results from RES_TAB.
*
* Query conditions:
* a) res_id = -1, => return: 1..n records
* b) res_id <>-1 => return: 1 record
*
* Parameter: vp_res_id (i) ID of result(s) to select
* vp_res (o) Return value (list of results)
* vp_errinfo (o) Error info in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of results from RES_TAB.
Query conditions:
res_id = -1, => return: 1..n records
res_id <>-1 => return: 1 record
Output:
vp_res - Return value (list of results)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param db_con Pointer to connection
\param vp_res_id ID of result(s) to select
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_res (DB_con *db_con,
long vp_res_id,
DA_T_res **vp_res,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_res";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_res v_res_buf;
/* pointer to list root, list elements */
DA_T_res *v_root_lst_ptr = NULL;
DA_T_res *v_new_elem_ptr = NULL;
DA_T_res *v_last_elem_ptr = NULL;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_fmt_date [ 30];
char h_con_name [ 31];
char h_where_clause [100];
char h_query [2000];
struct DA_T_res_pg_h{ /* type contains host variables for object data */
long res_id;
char river_factor[ 41];
char river_unit [256];
char stp_factor [ 41];
char stp_unit [256];
char pec_initial[2001];
char pec_catch [2001];
char remark [2001];
} h_res;
struct DA_T_res_pg_i{ /* indicator variables for host variable struct */
short int res_id;
short int river_factor;
short int river_unit;
short int stp_factor;
short int stp_unit;
short int pec_initial;
short int pec_catch;
short int remark;
} h_ind_res;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for return values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* determine query condition
* a) res_id = -1, => return: 1..n records
* b) res_id <>-1 => return: 1 record
*/
if (vp_res_id == -1)
{
/* case a) */
strcpy (h_where_clause, "");
}
else
{
/* case b) */
sprintf(h_where_clause, "WHERE RES_ID = %ld ", vp_res_id);
}
/*
* DECLARE CURSOR
* to select the resment details from RES_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT RES_ID,"
"RIVER_FACTOR,"
"RIVER_UNIT,"
"STP_FACTOR,"
"STP_UNIT,"
"PEC_INITIAL,"
"PEC_CATCH,"
"REMARK "
"FROM RES_TAB "
"%s "
"ORDER BY RES_ID", h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE res_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN res_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH res_csr INTO :h_res INDICATOR :h_ind_res;
/* check indicator variables (in regard to NULL values) */
if (h_ind_res.res_id == -1) h_res.res_id = -1;
if (h_ind_res.river_factor == -1) strcpy(h_res.river_factor, "");
if (h_ind_res.river_unit == -1) strcpy(h_res.river_unit, "");
if (h_ind_res.stp_factor == -1) strcpy(h_res.stp_factor, "");
if (h_ind_res.stp_unit == -1) strcpy(h_res.stp_unit, "");
if (h_ind_res.pec_initial == -1) strcpy(h_res.pec_initial, "");
if (h_ind_res.pec_catch == -1) strcpy(h_res.pec_catch, "");
if (h_ind_res.remark == -1) strcpy(h_res.remark, "");
/* copy result into temp. buffer */
v_res_buf.res_id = h_res.res_id;
strcpy(v_res_buf.river_factor , h_res.river_factor);
strcpy(v_res_buf.river_unit , h_res.river_unit);
strcpy(v_res_buf.stp_factor , h_res.stp_factor);
strcpy(v_res_buf.stp_unit , h_res.stp_unit);
strcpy(v_res_buf.pec_initial , h_res.pec_initial);
strcpy(v_res_buf.pec_catch , h_res.pec_catch);
strcpy(v_res_buf.remark , h_res.remark);
v_res_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_RES_TAB, (void*) &v_res_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_res*) malloc( sizeof(DA_T_res) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param,"%s - malloc(DA_T_res)", v_module);
gda_free_res(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_res) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_res_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE res_csr;
/* return created result list */
(*vp_res) = v_root_lst_ptr;
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE res_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_res (RES_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Insert record into RES_TAB. Return new "RES_ID" by passed
* struct, in case insert could successfully be done
*
* Parameter: vp_sess_id (i) session to which result belongs
* vp_res (i/o) data to insert into RES_TAB,
* OUTPUT:
* new res_id = RES_SEQ.NEXTVAL
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into RES_TAB.
Return new "RES_ID" by passed struct, in case insert could successfully be done.
Output:
vp_res - new res_id
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_sess_id session to which result belongs
\param vp_res data to insert into RES_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_res (DB_con *db_con,
long vp_sess_id,
DA_T_res *vp_res,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_res";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_cnt;
long h_sess_id_qry;
long h_res_id_new;
char h_con_name [ 31];
struct DA_T_res_pg_h{ /* type contains host variables for object data */
long res_id;
char river_factor[ 41];
char river_unit [256];
char stp_factor [ 41];
char stp_unit [256];
char pec_initial[2001];
char pec_catch [2001];
char remark [2001];
} h_res;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* current user will become owner of the new record -> acc. rhgt.: VIEW+EDIT*/
v_access_right = DA_A_VIEWEDIT;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* check if other result is already linked to spec. session
*/
h_sess_id_qry = vp_sess_id;
errln = 10;
EXEC SQL SELECT count(*)
INTO :h_cnt
FROM SESS_TAB
WHERE SESS_ID = :h_sess_id_qry
AND RES_ID IS NOT NULL;
if (h_cnt >0)
{
/* ERROR: session is already linked to other result */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_DUPL_RES_FOR_SESS;
sprintf (vp_errinfo->err_param,"%s - sess_id: %ld", v_module, vp_sess_id);
return (DA_FAIL);
}
/* get new RES_ID */
errln = 20;
EXEC SQL SELECT NEXTVAL('RES_SEQ')
INTO :h_res_id_new;
/*
* copy passed record into host variable
*/
h_res.res_id = h_res_id_new;
strcpy(h_res.river_factor , vp_res->river_factor);
strcpy(h_res.river_unit , vp_res->river_unit);
strcpy(h_res.stp_factor , vp_res->stp_factor);
strcpy(h_res.stp_unit , vp_res->stp_unit);
strcpy(h_res.pec_initial , vp_res->pec_initial);
strcpy(h_res.pec_catch , vp_res->pec_catch);
strcpy(h_res.remark , vp_res->remark);
/* Insert passed record */
errln = 20;
EXEC SQL INSERT INTO RES_TAB ( RES_ID,
RIVER_FACTOR,
RIVER_UNIT,
STP_FACTOR,
STP_UNIT,
PEC_INITIAL,
PEC_CATCH,
REMARK )
VALUES ( :h_res.res_id,
:h_res.river_factor,
:h_res.river_unit,
:h_res.stp_factor,
:h_res.stp_unit,
:h_res.pec_initial,
:h_res.pec_catch,
:h_res.remark);
/* set return value (created RES_ID) into passed struct/record */
vp_res->res_id = h_res_id_new;
/* link new result to specified session */
errln = 30;
EXEC SQL UPDATE SESS_TAB
SET RES_ID = :h_res.res_id
WHERE SESS_ID = :h_sess_id_qry;
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_res (RES_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by RES_ID) in RES_TAB by data of
* passed record.
*
* Parameter: vp_res (i) new result containing RES_ID of record
* to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by RES_ID) in RES_TAB by data of passed record.
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_res new result containing RES_ID of record
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_res (DB_con *db_con,
DA_T_res *vp_res,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_res";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_res_id;
char h_con_name [ 31];
struct DA_T_res_pg_h{ /* type contains host variables for object data */
long res_id;
char river_factor[ 41];
char river_unit [256];
char stp_factor [ 41];
char stp_unit [256];
char pec_initial[2001];
char pec_catch [2001];
char remark [2001];
} h_res;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_RES_TAB, (void*) vp_res,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_res_id = vp_res->res_id;
h_res.res_id = vp_res->res_id;
strcpy(h_res.river_factor , vp_res->river_factor);
strcpy(h_res.river_unit , vp_res->river_unit);
strcpy(h_res.stp_factor , vp_res->stp_factor);
strcpy(h_res.stp_unit , vp_res->stp_unit);
strcpy(h_res.pec_initial , vp_res->pec_initial);
strcpy(h_res.pec_catch , vp_res->pec_catch);
strcpy(h_res.remark , vp_res->remark);
/* Update passed record in database */
errln = 10;
EXEC SQL UPDATE RES_TAB
SET RES_ID = :h_res.res_id,
RIVER_FACTOR = :h_res.river_factor,
RIVER_UNIT = :h_res.river_unit,
STP_FACTOR = :h_res.stp_factor,
STP_UNIT = :h_res.stp_unit,
PEC_INITIAL = :h_res.pec_initial,
PEC_CATCH = :h_res.pec_catch,
REMARK = :h_res.remark
WHERE RES_ID = :h_res_id;
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_res (RES_TAB)
*
* Issue : 18-JUL-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Delete record from RES_TAB specified by "RES_ID".
* Reference in SESS_TAB is also removed.
*
* Parameter: vp_res_id (i) RES_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from RES_TAB specified by "RES_ID".
Reference in SESS_TAB is also removed..
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 18-JUL-2002
\param db_con Pointer to connection
\param vp_res_id RES_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_res (DB_con *db_con,
long vp_res_id,
DA_T_errinfo *vp_errinfo )
{
DA_T_MODULE_NAME v_module = "gda_delete_res";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
DA_T_res v_res_buf;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_res_id;
char h_con_name[31];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* get access right for data */
h_res_id = vp_res_id;
/* copy res_id into temp. buffer */
v_res_buf.res_id = h_res_id;
v_res_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_RES_TAB, (void*) &v_res_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* remove ref. to result (RES_ID) from master (SESS_TAB)
* to avoid ref. constraint violation */
errln = 10;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 20;
EXEC SQL UPDATE SESS_TAB
SET RES_ID = NULL
WHERE RES_ID = :h_res_id;
/* delete specified result record */
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO error;
errln = 40;
EXEC SQL DELETE FROM RES_TAB
WHERE RES_ID = :h_res_id;
/* record successfully deleted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not deleted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_res (RES_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_res()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_res (i) pointer to "list of" result records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_res()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param vp_res pointer to "list of" result records
\return ---
*/
void gda_free_res(DA_T_res *vp_res)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_res";
#endif
/* pointer to list elements */
DA_T_res *v_next_elem_ptr = NULL;
DA_T_res *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_res;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: RES_STRETCH_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_res_stretch (RES_STRETCH_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of stretch results from RES_STRETCH_TAB.
*
* Query conditions:
* a) res_stretch_id =-1; res_id <> -1; => return: 1..n records
* b) res_stretch_id >-1; res_id <> -1; => return: 1 record
*
* Parameter: vp_res_stretch_id(i) ID of stretch result(s) to select
* vp_res_id (i) ID of result to which stretch res. belongs
* vp_res_stretch (o) Return value (list of results)
* vp_errinfo (o) Error info in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of stretch results from RES_STRETCH_TAB.
Query conditions:
res_stretch_id =-1; res_id <> -1; => return: 1..n records
res_stretch_id >-1; res_id <> -1; => return: 1 record
Output:
vp_res_stretch - Return value (list of results)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param db_con Pointer to connection
\param vp_res_stretch_id ID of stretch result(s) to select
\param vp_res_id ID of result to which stretch res. belongs
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_res_stretch (DB_con *db_con,
long vp_res_id,
long vp_res_stretch_id,
DA_T_res_stretch **vp_res_stretch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_res_stretch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_res_stretch v_res_stretch_buf;
/* pointer to list root, list elements */
DA_T_res_stretch *v_root_lst_ptr = NULL;
DA_T_res_stretch *v_new_elem_ptr = NULL;
DA_T_res_stretch *v_last_elem_ptr = NULL;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
char h_where_clause [100];
char h_query [2000];
struct DA_T_res_stretch_pg_h{ /* type contains host variables for object data */
long res_stretch_id;
long res_id;
long stretch_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value [256];
char dist_type [ 12];
char remark [2001];
} h_res_stretch;
struct DA_T_res_stretch_pg_i{ /* indicator variables for host variable struct */
short int res_stretch_id;
short int res_id;
short int stretch_id;
short int field_id;
short int block_id;
short int block_recno;
short int value;
short int dist_type;
short int remark;
} h_ind_res_stretch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* determine query condition
* a) res_stretch_id =-1; res_id <> -1; => return: 1..n records
* b) res_stretch_id >-1; res_id <> -1; => return: 1 record
*/
if (vp_res_stretch_id == -1)
{
/* case a) */
sprintf(h_where_clause, "WHERE RES_ID = %ld ", vp_res_id);
}
else
{
/* case b) */
sprintf(h_where_clause, "WHERE RES_ID = %ld AND RES_STRETCH_ID = %ld ", vp_res_id, vp_res_stretch_id);
}
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the resment details from RES_STRETCH_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT RES_STRETCH_ID,"
"RES_ID,"
"STRETCH_ID,"
"FIELD_ID,"
"BLOCK_ID,"
"BLOCK_RECNO,"
"VALUE_RST,"
"DIST_TYPE,"
"REMARK "
"FROM RES_STRETCH_TAB "
"%s "
"ORDER BY RES_STRETCH_ID", h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE res_stretch_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN res_stretch_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH res_stretch_csr INTO :h_res_stretch INDICATOR :h_ind_res_stretch;
/* check indicator variables (in regard to NULL values) */
if (h_ind_res_stretch.res_stretch_id == -1) h_res_stretch.res_stretch_id = -1;
if (h_ind_res_stretch.res_id == -1) h_res_stretch.res_id = -1;
if (h_ind_res_stretch.stretch_id == -1) h_res_stretch.stretch_id = -1;
if (h_ind_res_stretch.block_recno == -1) h_res_stretch.block_recno = 0;
if (h_ind_res_stretch.field_id == -1) strcpy(h_res_stretch.field_id, "");
if (h_ind_res_stretch.block_id == -1) strcpy(h_res_stretch.block_id, "");
if (h_ind_res_stretch.value == -1) strcpy(h_res_stretch.value, "");
if (h_ind_res_stretch.dist_type == -1) strcpy(h_res_stretch.dist_type, "");
if (h_ind_res_stretch.remark == -1) strcpy(h_res_stretch.remark, "");
/* copy result into temp. buffer */
v_res_stretch_buf.res_stretch_id = h_res_stretch.res_stretch_id;
v_res_stretch_buf.res_id = h_res_stretch.res_id;
v_res_stretch_buf.stretch_id = h_res_stretch.stretch_id;
v_res_stretch_buf.block_recno = h_res_stretch.block_recno;
strcpy(v_res_stretch_buf.field_id , h_res_stretch.field_id);
strcpy(v_res_stretch_buf.block_id , h_res_stretch.block_id);
strcpy(v_res_stretch_buf.value , h_res_stretch.value);
strcpy(v_res_stretch_buf.dist_type , h_res_stretch.dist_type);
strcpy(v_res_stretch_buf.remark , h_res_stretch.remark);
v_res_stretch_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_RES_STRETCH_TAB, (void*) &v_res_stretch_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_res_stretch*) malloc( sizeof(DA_T_res_stretch) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param,"%s - malloc(DA_T_res_stretch)", v_module);
gda_free_res_stretch(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_res_stretch) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_res_stretch_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE res_stretch_csr;
/* return created result list */
(*vp_res_stretch) = v_root_lst_ptr;
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE res_stretch_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_res_stretch (RES_STRETCH_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Insert record into RES_STRETCH_TAB. Return new "RES_STRETCH_ID"
* by passed struct, in case insert could successfully be done
*
* Parameter: vp_res_stretch (i/o) data to insert into RES_STRETCH_TAB,
* OUTPUT:
* new res_stretch_id = RES_STRETCH_SEQ.NEXTVAL
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into RES_STRETCH_TAB.
Return new "RES_STRETCH_ID" by passed struct, in case insert could successfully be done.
Output:
vp_res_stretch - new res_stretch_id
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_res_stretch data to insert into RES_STRETCH_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_res_stretch (DB_con *db_con,
DA_T_res_stretch *vp_res_stretch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_res_stretch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_master_chk = DA_FAIL;
char v_errmsg[256];
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_res_stretch_id_new;
char h_con_name[31];
struct DA_T_res_stretch_pg_h{ /* type contains host variables for object data */
long res_stretch_id;
long res_id;
long stretch_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value [256];
char dist_type [ 12];
char remark [2001];
} h_res_stretch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* ------------------ *
* PRE-CHECKS
* ------------------ */
v_master_chk = lgda_chk_res_stretch_master(vp_res_stretch->field_id,
vp_res_stretch->block_id,
vp_errinfo);
if (v_master_chk != DA_SUCCESS)
{
/* error during check of master record */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_RES_STRETCH_TAB, (void*) vp_res_stretch,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* get new RES_ID */
errln = 10;
EXEC SQL SELECT NEXTVAL('RES_STRETCH_SEQ')
INTO :h_res_stretch_id_new;
/*
* copy passed record into host variable
*/
h_res_stretch.res_stretch_id = h_res_stretch_id_new;
h_res_stretch.res_id = vp_res_stretch->res_id;
h_res_stretch.stretch_id = vp_res_stretch->stretch_id;
h_res_stretch.block_recno = vp_res_stretch->block_recno;
strcpy(h_res_stretch.field_id , vp_res_stretch->field_id);
strcpy(h_res_stretch.block_id , vp_res_stretch->block_id);
strcpy(h_res_stretch.value , vp_res_stretch->value);
strcpy(h_res_stretch.dist_type , vp_res_stretch->dist_type);
strcpy(h_res_stretch.remark , vp_res_stretch->remark);
/* Insert passed record */
errln = 20;
EXEC SQL INSERT INTO RES_STRETCH_TAB ( RES_STRETCH_ID,
RES_ID,
STRETCH_ID,
FIELD_ID,
BLOCK_ID,
BLOCK_RECNO,
VALUE_RST,
DIST_TYPE,
REMARK )
VALUES ( :h_res_stretch.res_stretch_id,
:h_res_stretch.res_id,
:h_res_stretch.stretch_id,
:h_res_stretch.field_id,
:h_res_stretch.block_id,
:h_res_stretch.block_recno,
:h_res_stretch.value,
:h_res_stretch.dist_type,
:h_res_stretch.remark);
/* set return value (created RES_STRETCH_ID) into passed struct/record */
vp_res_stretch->res_stretch_id = h_res_stretch_id_new;
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_bulk_res_stretch RES_STRETCH_TAB)
*
* Issue : 21-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Insert list of records into RES_STRETCH_TAB. Return new
* "RES_STRETCH_ID"s by passed list of structs, in case insert
* could successfully be done
*
* Parameter: vp_res_stretch (i/o) data to insert into RES_STRETCH_TAB,
* OUTPUT:
* new res_stretch_id = RES_STRETCH_SEQ.NEXTVAL
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert list of records into RES_STRETCH_TAB.
Return new "RES_STRETCH_ID"s by passed list of structs, in case insert could successfully be done.
Output:
vp_res_stretch - new res_stretch_id
vp_errinfo - Error info in case of error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 21-OCT-2002
\param db_con Pointer to connection
\param vp_res_stretch data to insert into RES_STRETCH_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_bulk_res_stretch (DB_con *db_con,
DA_T_res_stretch *vp_res_stretch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_bulk_res_stretch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_master_chk;
// not used: char v_errmsg[256];
/* counts number of data sets which could not be successfully inserted */
int v_errctr = 0;
/* buffer for FIELD_IDs with corresponding record in PARA_TREE_DEF_TAB */
char v_buffer[1000]="";
char v_temp_buffer[1000]="";
/* stores address of list root */
DA_T_res_stretch *v_root_lst_ptr = vp_res_stretch;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_res_stretch_id_new;
char h_con_name[31];
struct DA_T_res_stretch_pg_h{ /* type contains host variables for object data */
long res_stretch_id;
long res_id;
long stretch_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value [256];
char dist_type [ 12];
char remark [2001];
} h_res_stretch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/*g debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_RES_STRETCH_TAB, (void*) vp_res_stretch,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
while (vp_res_stretch != NULL)
{
/* ------------------ *
* PRE-CHECK
* ------------------ */
v_master_chk = DA_FAIL;
/*check if field_id has already been validated, if not validate it */
sprintf(v_temp_buffer, "%s$", vp_res_stretch->field_id);
if (strstr (v_buffer, v_temp_buffer) == 0)
{
v_master_chk = lgda_chk_res_stretch_master(vp_res_stretch->field_id,
vp_res_stretch->block_id,
vp_errinfo);
if (v_master_chk == DA_SUCCESS)
{
/* cut off end of buffer to free enough space for append operation*/
v_buffer[998-strlen(vp_res_stretch->field_id)] = '\0';
/* append validated field_id to beginning of buffer */
strcpy(v_temp_buffer, v_buffer);
sprintf(v_buffer, "%s$%s", vp_res_stretch->field_id, v_temp_buffer);
}
}
else
{
v_master_chk = DA_SUCCESS;
}
if (v_master_chk != DA_SUCCESS)
{
/* error during check of master record */
v_errctr += 1;
}
else
{
/* get new RES_ID */
errln = 10;
EXEC SQL SELECT NEXTVAL('RES_STRETCH_SEQ')
INTO :h_res_stretch_id_new;
/*
* copy passed record into host variable
*/
h_res_stretch.res_stretch_id = h_res_stretch_id_new;
h_res_stretch.res_id = vp_res_stretch->res_id;
h_res_stretch.stretch_id = vp_res_stretch->stretch_id;
h_res_stretch.block_recno = vp_res_stretch->block_recno;
strcpy(h_res_stretch.field_id , vp_res_stretch->field_id);
strcpy(h_res_stretch.block_id , vp_res_stretch->block_id);
strcpy(h_res_stretch.value , vp_res_stretch->value);
strcpy(h_res_stretch.dist_type , vp_res_stretch->dist_type);
strcpy(h_res_stretch.remark , vp_res_stretch->remark);
/* Insert passed record */
errln = 20;
EXEC SQL INSERT INTO RES_STRETCH_TAB ( RES_STRETCH_ID,
RES_ID,
STRETCH_ID,
FIELD_ID,
BLOCK_ID,
BLOCK_RECNO,
VALUE_RST,
DIST_TYPE,
REMARK )
VALUES ( :h_res_stretch.res_stretch_id,
:h_res_stretch.res_id,
:h_res_stretch.stretch_id,
:h_res_stretch.field_id,
:h_res_stretch.block_id,
:h_res_stretch.block_recno,
:h_res_stretch.value,
:h_res_stretch.dist_type,
:h_res_stretch.remark);
/* set return value (created RES_STRETCH_ID) into passed struct/record */
vp_res_stretch->res_stretch_id = h_res_stretch_id_new;
}
vp_res_stretch = vp_res_stretch->next_element;
} /* end: while (vp_res_stretch != NULL) */
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* records not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
/* records inserted */
/* reset vp_res_stretch to first list element */
vp_res_stretch = v_root_lst_ptr;
if (v_errctr > 0)
{
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_RES_STRETCH_INS;
sprintf (vp_errinfo->err_param,"%s - Number of errors: %d", v_module, v_errctr);
v_status = DA_FAIL;
}
else v_status = DA_SUCCESS;
return (v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_res_stretch (RES_STRETCH_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by RES_STRETCH_ID) in RES_STRETCH_TAB
* by data of passed record.
*
* Parameter: vp_res_stretch (i) new result containing RES_STRETCH_ID of
* record to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by RES_STRETCH_ID) in RES_STRETCH_TAB by data of passed record.
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_res_stretch new result containing RES_STRETCH_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_res_stretch (DB_con *db_con,
DA_T_res_stretch *vp_res_stretch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_res_stretch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_master_chk = DA_FAIL;
char v_errmsg[256];
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_res_stretch_id;
char h_con_name[31];
struct DA_T_res_stretch_pg_h{ /* type contains host variables for object data */
long res_stretch_id;
long res_id;
long stretch_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value [256];
char dist_type [ 12];
char remark [2001];
} h_res_stretch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* ------------------ *
* PRE-CHECKS
* ------------------ */
v_master_chk = lgda_chk_res_stretch_master(vp_res_stretch->field_id,
vp_res_stretch->block_id,
vp_errinfo);
if (v_master_chk != DA_SUCCESS)
{
/* error during check of master record */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_RES_STRETCH_TAB, (void*) vp_res_stretch,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_res_stretch_id = vp_res_stretch->res_stretch_id;
h_res_stretch.res_stretch_id = vp_res_stretch->res_stretch_id;
h_res_stretch.res_id = vp_res_stretch->res_id;
h_res_stretch.stretch_id = vp_res_stretch->stretch_id;
h_res_stretch.block_recno = vp_res_stretch->block_recno;
strcpy(h_res_stretch.field_id , vp_res_stretch->field_id);
strcpy(h_res_stretch.block_id , vp_res_stretch->block_id);
strcpy(h_res_stretch.value , vp_res_stretch->value);
strcpy(h_res_stretch.dist_type , vp_res_stretch->dist_type);
strcpy(h_res_stretch.remark , vp_res_stretch->remark);
/* Update passed record in database */
errln = 10;
EXEC SQL UPDATE RES_STRETCH_TAB
SET RES_STRETCH_ID = :h_res_stretch.res_stretch_id,
RES_ID = :h_res_stretch.res_id,
STRETCH_ID = :h_res_stretch.stretch_id,
FIELD_ID = :h_res_stretch.field_id,
BLOCK_ID = :h_res_stretch.block_id,
BLOCK_RECNO = :h_res_stretch.block_recno,
VALUE_RST = :h_res_stretch.value,
DIST_TYPE = :h_res_stretch.dist_type,
REMARK = :h_res_stretch.remark
WHERE RES_STRETCH_ID = :h_res_stretch_id;
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_res_stretch (RES_STRETCH_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_res_stretch()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_res_stretch (i) pointer to "list of" result records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_res_stretch()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param vp_res_stretch pointer to "list of" result records
\return ---
*/
void gda_free_res_stretch(DA_T_res_stretch *vp_res_stretch)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_res_stretch";
#endif
/* pointer to list elements */
DA_T_res_stretch *v_next_elem_ptr = NULL;
DA_T_res_stretch *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_res_stretch;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: RES_DISCH_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_res_disch (RES_DISCH_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of disch results from RES_DISCH_TAB.
*
* Query conditions:
* a) res_disch_id =-1; res_id <> -1; => return: 1..n records
* b) res_disch_id >-1; res_id <> -1; => return: 1 record
*
* Parameter: vp_res_disch_id (i) ID of disch result(s) to select
* vp_res_id (i) ID of result to which disch res. belongs
* vp_res_disch (o) Return value (list of results)
* vp_errinfo (o) Error info in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of disch results from RES_DISCH_TAB.
Query conditions:
res_disch_id =-1; res_id <> -1; => return: 1..n records
res_disch_id >-1; res_id <> -1; => return: 1 record
Output:
vp_res_disch - Return value (list of results)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param db_con Pointer to connection
\param vp_res_disch_id ID of disch result(s) to select
\param vp_res_id ID of result to which disch res. belongs
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_res_disch (DB_con *db_con,
long vp_res_id,
long vp_res_disch_id,
DA_T_res_disch **vp_res_disch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_res_disch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_res_disch v_res_disch_buf;
/* pointer to list root, list elements */
DA_T_res_disch *v_root_lst_ptr = NULL;
DA_T_res_disch *v_new_elem_ptr = NULL;
DA_T_res_disch *v_last_elem_ptr = NULL;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
char h_where_clause [100];
char h_query [2000];
struct DA_T_res_disch_pg_h{ /* type contains host variables for object data */
long res_disch_id;
long res_id;
long disch_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value [256];
char dist_type [ 12];
char remark [2001];
} h_res_disch;
struct DA_T_res_disch_pg_i{ /* indicator variables for host variable struct */
short int res_disch_id;
short int res_id;
short int disch_id;
short int field_id;
short int block_id;
short int block_recno;
short int value;
short int dist_type;
short int remark;
} h_ind_res_disch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* determine query condition
* a) res_disch_id =-1; res_id <> -1; => return: 1..n records
* b) res_disch_id >-1; res_id <> -1; => return: 1 record
*/
if (vp_res_disch_id == -1)
{
/* case a) */
sprintf(h_where_clause, "WHERE RES_ID = %ld ", vp_res_id);
}
else
{
/* case b) */
sprintf(h_where_clause, "WHERE RES_ID = %ld AND RES_DISCH_ID = %ld ", vp_res_id, vp_res_disch_id);
}
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select the resment details from RES_DISCH_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT RES_DISCH_ID,"
"RES_ID,"
"DISCH_ID,"
"FIELD_ID,"
"BLOCK_ID,"
"BLOCK_RECNO,"
"VALUE_RDT,"
"DIST_TYPE,"
"REMARK "
"FROM RES_DISCH_TAB "
"%s "
"ORDER BY RES_DISCH_ID", h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE res_disch_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN res_disch_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH res_disch_csr INTO :h_res_disch INDICATOR :h_ind_res_disch;
/* check indicator variables (in regard to NULL values) */
if (h_ind_res_disch.res_disch_id == -1) h_res_disch.res_disch_id = -1;
if (h_ind_res_disch.res_id == -1) h_res_disch.res_id = -1;
if (h_ind_res_disch.disch_id == -1) h_res_disch.disch_id = -1;
if (h_ind_res_disch.block_recno == -1) h_res_disch.block_recno = 0;
if (h_ind_res_disch.field_id == -1) strcpy(h_res_disch.field_id, "");
if (h_ind_res_disch.block_id == -1) strcpy(h_res_disch.block_id, "");
if (h_ind_res_disch.value == -1) strcpy(h_res_disch.value, "");
if (h_ind_res_disch.dist_type == -1) strcpy(h_res_disch.dist_type,"");
if (h_ind_res_disch.remark == -1) strcpy(h_res_disch.remark, "");
/* copy result into temp. buffer */
v_res_disch_buf.res_disch_id = h_res_disch.res_disch_id;
v_res_disch_buf.res_id = h_res_disch.res_id;
v_res_disch_buf.disch_id = h_res_disch.disch_id;
v_res_disch_buf.block_recno = h_res_disch.block_recno;
strcpy(v_res_disch_buf.field_id , h_res_disch.field_id);
strcpy(v_res_disch_buf.block_id , h_res_disch.block_id);
strcpy(v_res_disch_buf.value , h_res_disch.value);
strcpy(v_res_disch_buf.dist_type , h_res_disch.dist_type);
strcpy(v_res_disch_buf.remark , h_res_disch.remark);
v_res_disch_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_RES_DISCH_TAB, (void*) &v_res_disch_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_res_disch*) malloc( sizeof(DA_T_res_disch) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param,"%s - malloc(DA_T_res_disch)", v_module);
gda_free_res_disch(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_res_disch) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_res_disch_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE res_disch_csr;
/* return created result list */
(*vp_res_disch) = v_root_lst_ptr;
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE res_disch_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_res_disch (RES_DISCH_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Insert record into RES_DISCH_TAB. Return new "RES_DISCH_ID"
* by passed struct, in case insert could successfully be done
*
* Parameter: vp_res_disch (i/o) data to insert into RES_DISCH_TAB,
* OUTPUT:
* new "res_disch_id" = RES_DISCH_SEQ.NEXTVAL
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into RES_DISCH_TAB.
Return new "RES_DISCH_ID" by passed struct, in case insert could successfully be done.
Output:
vp_res_disch - new res_disch_id
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_res_disch data to insert into RES_DISCH_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_res_disch (DB_con *db_con,
DA_T_res_disch *vp_res_disch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_res_disch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_master_chk = DA_FAIL;
char v_errmsg[256];
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_res_disch_id_new;
char h_con_name[31];
struct DA_T_res_disch_pg_h{ /* type contains host variables for object data */
long res_disch_id;
long res_id;
long disch_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value [256];
char dist_type [ 12];
char remark [2001];
} h_res_disch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* ------------------ *
* PRE-CHECKS
* ------------------ */
v_master_chk = lgda_chk_res_disch_master(vp_res_disch->field_id,
vp_res_disch->block_id,
vp_errinfo);
if (v_master_chk != DA_SUCCESS)
{
/* error during check of master record */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_RES_DISCH_TAB, (void*) vp_res_disch,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/* get new RES_DISCH_ID */
errln = 10;
EXEC SQL SELECT NEXTVAL('RES_DISCH_SEQ')
INTO :h_res_disch_id_new;
/*
* copy passed record into host variable
*/
h_res_disch.res_disch_id = h_res_disch_id_new;
h_res_disch.res_id = vp_res_disch->res_id;
h_res_disch.disch_id = vp_res_disch->disch_id;
h_res_disch.block_recno = vp_res_disch->block_recno;
strcpy(h_res_disch.field_id , vp_res_disch->field_id);
strcpy(h_res_disch.block_id , vp_res_disch->block_id);
strcpy(h_res_disch.value , vp_res_disch->value);
strcpy(h_res_disch.dist_type , vp_res_disch->dist_type);
strcpy(h_res_disch.remark , vp_res_disch->remark);
/* Insert passed record */
errln = 20;
EXEC SQL INSERT INTO RES_DISCH_TAB ( RES_DISCH_ID,
RES_ID,
DISCH_ID,
FIELD_ID,
BLOCK_ID,
BLOCK_RECNO,
VALUE_RDT,
DIST_TYPE,
REMARK )
VALUES ( :h_res_disch.res_disch_id,
:h_res_disch.res_id,
:h_res_disch.disch_id,
:h_res_disch.field_id,
:h_res_disch.block_id,
:h_res_disch.block_recno,
:h_res_disch.value,
:h_res_disch.dist_type,
:h_res_disch.remark);
/* set return value (created RES_DISCH_ID) into passed struct/record */
vp_res_disch->res_disch_id = h_res_disch_id_new;
/* record successfully inserted */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not inserted */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_res_disch (RES_DISCH_TAB)
*
* Issue : 06-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by RES_DISCH_ID) in RES_DISCH_TAB
* by data of passed record.
*
* Parameter: vp_res_disch (i) new result containing RES_DISCH_ID of
* record to update
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by RES_DISCH_ID) in RES_DISCH_TAB by data of passed record.
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 06-AUG-2002
\param db_con Pointer to connection
\param vp_res_disch new result containing RES_DISCH_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_res_disch (DB_con *db_con,
DA_T_res_disch *vp_res_disch,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_res_disch";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
int v_master_chk = DA_FAIL;
char v_errmsg[256];
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_res_disch_id;
char h_con_name[31];
struct DA_T_res_disch_pg_h{ /* type contains host variables for object data */
long res_disch_id;
long res_id;
long disch_id;
char field_id [ 31];
char block_id [ 31];
int block_recno;
char value [256];
char dist_type [ 12];
char remark [2001];
} h_res_disch;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* ------------------ *
* PRE-CHECKS
* ------------------ */
v_master_chk = lgda_chk_res_disch_master(vp_res_disch->field_id,
vp_res_disch->block_id,
vp_errinfo);
if (v_master_chk != DA_SUCCESS)
{
/* error during check of master record */
if (vp_errinfo->err_type == DA_ERRTYP_INT)
{
sprintf(v_errmsg,"%s - %s", v_module, vp_errinfo->err_param);
strcpy (vp_errinfo->err_param, v_errmsg);
}
return(DA_FAIL);
}
/* get access right for data */
v_status = lgda_get_access_right(DA_A_RES_DISCH_TAB, (void*) vp_res_disch,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEWEDIT) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
/*
* copy passed record into host variable
*/
h_res_disch_id = vp_res_disch->res_disch_id;
h_res_disch.res_disch_id = vp_res_disch->res_disch_id;
h_res_disch.res_id = vp_res_disch->res_id;
h_res_disch.disch_id = vp_res_disch->disch_id;
h_res_disch.block_recno = vp_res_disch->block_recno;
strcpy(h_res_disch.field_id , vp_res_disch->field_id);
strcpy(h_res_disch.block_id , vp_res_disch->block_id);
strcpy(h_res_disch.value , vp_res_disch->value);
strcpy(h_res_disch.dist_type , vp_res_disch->dist_type);
strcpy(h_res_disch.remark , vp_res_disch->remark);
/* Update passed record in database */
errln = 10;
EXEC SQL UPDATE RES_DISCH_TAB
SET RES_DISCH_ID = :h_res_disch.res_disch_id,
RES_ID = :h_res_disch.res_id,
DISCH_ID = :h_res_disch.disch_id,
FIELD_ID = :h_res_disch.field_id,
BLOCK_ID = :h_res_disch.block_id,
BLOCK_RECNO = :h_res_disch.block_recno,
VALUE_RDT = :h_res_disch.value,
DIST_TYPE = :h_res_disch.dist_type,
REMARK = :h_res_disch.remark
WHERE RES_DISCH_ID = :h_res_disch_id;
/* record successfully updated */
return(v_status);
}
else
{
/* --------------------------------------------------------- *
* PRIV-CHK: Insufficient privs. to access data in req. mode
* --------------------------------------------------------- */
/* set error info */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_INSUFF_PRIVS;
sprintf (vp_errinfo->err_param,"%s - access mode: EDIT", v_module);
/* record not updated */
return(DA_FAIL);
} /* end: if ((v_access_right>=DA_A_VIEWEDIT)&&(v_status==DA_SUCCESS)) */
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_res_disch (RES_DISCH_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_res_disch()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_res_disch (i) pointer to "list of" result records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_res_disch()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param vp_res_disch pointer to "list of" result records
\return ---
*/
void gda_free_res_disch(DA_T_res_disch *vp_res_disch)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_res_disch";
#endif
/* pointer to list elements */
DA_T_res_disch *v_next_elem_ptr = NULL;
DA_T_res_disch *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_res_disch;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: USER_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_user (USER_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of user data from USER_TAB.
*
* Query conditions:
* a) user_id = "" => return: 1..n records
* b) user_id <> "" => return: 1 record
*
* Parameter: vp_user_id (i) ID of user to select
* vp_user (o) Return value (list of users)
* vp_errinfo (o) Error info in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of user data from USER_TAB.
Query conditions:
user_id = "" => return: 1..n records
user_id <> "" => return: 1 record
Output:
vp_user - Return value (list of users)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param db_con Pointer to connection
\param vp_user_id ID of user to select
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_user (DB_con *db_con,
char *vp_user_id,
DA_T_user **vp_user,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "da_get_user";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_user v_user_buf;
/* pointer to list root, list elements */
DA_T_user *v_root_lst_ptr = NULL;
DA_T_user *v_new_elem_ptr = NULL;
DA_T_user *v_last_elem_ptr = NULL;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_user_id_qry[240];
char h_fmt_date [ 30];
char h_con_name [ 31];
struct DA_T_user_pg_h{ /* type contains host variables for object data */
char user_id [ 31];
long group_id;
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
char remark [2001];
} h_user;
struct DA_T_user_pg_i{ /* indicator variables for host variable struct */
short int user_id;
short int group_id;
short int cre_date;
short int mod_date;
short int status;
short int remark;
} h_ind_user;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, "User-ID:", vp_user_id, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* determine query condition
* a) user_id = ""; => return: 1..n records
* b) user_id <>""; => return: 1 record
*/
if (strcmp(vp_user_id,"")==0)
{
/* case a) */
strcpy (h_user_id_qry, "%");
}
else
{
/* case b) */
sprintf(h_user_id_qry, "%s", vp_user_id);
}
/*
* DECLARE CURSOR
* to select the user data from USER_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
EXEC SQL DECLARE user_csr CURSOR FOR
SELECT USER_ID,
GROUP_ID,
to_char(CRE_DATE, :h_fmt_date),
to_char(MOD_DATE, :h_fmt_date),
STATUS,
REMARK
FROM USER_TAB
WHERE USER_ID like :h_user_id_qry
ORDER BY USER_ID;
errln = 20;
EXEC SQL OPEN user_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH user_csr INTO :h_user INDICATOR :h_ind_user;
/* check indicator variables (in regard to NULL values) */
if (h_ind_user.group_id == -1) h_user.group_id = -1;
if (h_ind_user.user_id == -1) strcpy(h_user.user_id, "");
if (h_ind_user.cre_date == -1) strcpy(h_user.cre_date,"");
if (h_ind_user.mod_date == -1) strcpy(h_user.mod_date,"");
if (h_ind_user.status == -1) strcpy(h_user.status, "");
if (h_ind_user.remark == -1) strcpy(h_user.remark, "");
/* copy result into temp. buffer */
v_user_buf.group_id = h_user.group_id;
strcpy(v_user_buf.user_id , h_user.user_id);
strcpy(v_user_buf.cre_date , h_user.cre_date);
strcpy(v_user_buf.mod_date , h_user.mod_date);
strcpy(v_user_buf.status , h_user.status);
strcpy(v_user_buf.remark , h_user.remark);
v_user_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_USER_TAB, (void*) &v_user_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: User is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_user*) malloc( sizeof(DA_T_user) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param,"%s - malloc(DA_T_user)", v_module);
gda_free_user(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_user) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_user_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE user_csr;
/* return created result list */
(*vp_user) = v_root_lst_ptr;
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE user_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_user (USER_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_user()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_user (i) pointer to "list of" user data records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_user()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param vp_user pointer to "list of" user data records
\return ---
*/
void gda_free_user(DA_T_user *vp_user)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_user";
#endif
/* pointer to list elements */
DA_T_user *v_next_elem_ptr = NULL;
DA_T_user *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_user;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/*********************************************************************
* Name : gda_insert_user (USER_TAB)
*
* Issue : 27-SEP-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Insert record into USER_TAB.
*
* Parameter: vp_user (i/o) data to insert into USER_TAB
* OUTPUT:
* - cre_date = CURRENT_TIMESTAMP
* - mod_date = CURRENT_TIMESTAMP
* vp_password (i) new user's password
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into USER_TAB.
calls gda_insert_user().
Output:
vp_user - cre_date, mod_date
vp_errinfo - Error info in case of error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 27-SEP-2002
\param db_con Pointer to connection
\param vp_password new user's password
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_user(DB_con *db_con,
DA_T_user *vp_user,
char *vp_password,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_user";
int v_status = DA_SUCCESS;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name [ 31];
struct DA_T_user_pg_h{ /* type contains host variables for object data */
char user_id [ 31];
long group_id;
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
char remark [2001];
} h_user;
char h_fmt_date[30];
char h_create_statement[200];
/* char h_grant_statement[200];
char h_cre_syn_statement[100];
char h_role_name[256];
char h_synonym[256];
long h_phrase_grp_id; */
int h_count;
/* indicator variables */
short h_ind_user_id;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, "User-ID:", vp_user->user_id, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
errln = 10;
EXEC SQL SELECT :h_user.user_id INTO :h_user.user_id INDICATOR :h_ind_user_id;
if (h_ind_user_id == -1) strcpy (h_user.user_id, "");
/* ---------------------------------------------------------------------
* PRE-CHECK -> does user which is to be inserted exist as database user
*
* Table ALL_USERS is PG_USER in PostgreSQL (fieldname -> usename)
* --------------------------------------------------------------------- */
strcpy(h_user.user_id, vp_user->user_id);
errln = 20;
EXEC SQL SELECT COUNT(USENAME) INTO :h_count
FROM PG_USER
WHERE USENAME = :h_user.user_id;
if (h_count == 0)
{
/* -------------------------------------------------------------------
* create new user
*
* IDENTIFIED BY in Oracle is WITH PASSWORD in PostgreSQL
* ------------------------------------------------------------------- */
sprintf (h_create_statement, "CREATE USER %s WITH PASSWORD '%s'",
h_user.user_id, vp_password);
errln = 30;
EXEC SQL EXECUTE IMMEDIATE :h_create_statement;
}
/*
* THE FOLLOWING PART IS NOT USED ANYMORE BECAUSE
* IN POSTGRESQL THERE IS NO
* - CREATE ROLE ...
* - CREATE SYNONYM...
* - ALL_OBJECTS TABLE
*
* FURTHER ON THE PHRASE_TAB SHOULDN'T BE USED BY
* ADMINISTRATIONAL WORK.
*
* ONE POSSIBILITY WAS TO CREATE AN API-FUNCTION
* WITH USERNAME AS PARAMETER WHERE A SPECIAL SET
* OF RIGHTS WILL BE SET.
*
* THIS FUNCTION WOULD BE CALLED INSTEAD.
*/
/* grant rights to new user */
/* h_phrase_grp_id = DA_PHRASE_GRP_ID_ROLE;
errln = 40;
EXEC SQL SELECT VALUE_PT
INTO :h_role_name
FROM PHRASE_TAB
WHERE PHRASE_GRP_ID = :h_phrase_grp_id;
sprintf (h_grant_statement, "GRANT %s TO %s",
h_role_name, h_user.user_id);
errln = 50;
EXEC SQL EXECUTE IMMEDIATE :h_grant_statement;
errln = 60;
EXEC SQL WHENEVER NOT FOUND GOTO error;
*/
/*
* create private synonyms for all greater tables and sequences for new user,
* if they don't already exist
*/
/* h_phrase_grp_id = DA_PHRASE_GRP_ID_SYN;
errln = 70;
EXEC SQL DECLARE syn_cursor CURSOR FOR
SELECT VALUE_PT
FROM PHRASE_TAB
WHERE PHRASE_GRP_ID = :h_phrase_grp_id;
errln = 80;
EXEC SQL OPEN syn_cursor;
errln = 90;
EXEC SQL WHENEVER NOT FOUND GOTO endloop;
while (1)
{
errln = 100;
EXEC SQL FETCH syn_cursor INTO :h_synonym;
errln = 110;
EXEC SQL SELECT COUNT (OBJECT_NAME)
INTO :h_count
FROM ALL_OBJECTS
WHERE OBJECT_NAME = :h_synonym
AND OWNER = :h_user.user_id;
if (h_count == 0)
{
sprintf (h_cre_syn_statement,
"CREATE SYNONYM %s.%s FOR %s",
h_user.user_id, h_synonym, h_synonym);
errln = 120;
EXEC SQL EXECUTE IMMEDIATE :h_cre_syn_statement;
}
}
endloop:
errln = 130;
EXEC SQL CLOSE syn_cursor;
*/
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
/* set cre_date and mod_date = CURRENT_TIMESTAMP */
errln = 140;
EXEC SQL SELECT to_char(CURRENT_TIMESTAMP, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_user.cre_date,
:h_user.mod_date;
/*
* copy passed record into host variable
*/
h_user.group_id = vp_user->group_id;
strcpy(h_user.status, vp_user->status);
strcpy(h_user.remark, vp_user->remark);
/* Insert passed record */
errln = 150;
EXEC SQL INSERT INTO USER_TAB (USER_ID,
GROUP_ID,
CRE_DATE,
MOD_DATE,
STATUS,
REMARK)
VALUES (:h_user.user_id,
:h_user.group_id,
to_timestamp(:h_user.cre_date, :h_fmt_date),
to_timestamp(:h_user.mod_date, :h_fmt_date),
:h_user.status,
:h_user.remark);
/* return CRE_DATE, MOD_DATE by passed struct */
strcpy(vp_user->cre_date, h_user.cre_date);
strcpy(vp_user->mod_date, h_user.mod_date);
/* record successfully inserted */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
/* EXEC SQL CLOSE syn_cursor;*/
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_user (USER_TAB)
*
* Issue : 30-SEP-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by USER_ID) in USER_TAB
* by data of passed record.
*
* Parameter: vp_user (i/o) new user data, containing USER_ID of
* record to update.
* OUTPUT: vp_user.MOD_DATE = CURRENT_TIMESTAMP
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by USER_ID) in USER_TAB by data of passed record.
Output:
vp_user - mod_date
vp_errinfo - Error info in case of error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 30-SEP-2002
\param db_con Pointer to connection
\param vp_user new user data, containing USER_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_user (DB_con *db_con,
DA_T_user *vp_user,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_user";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_user_id_qry[31];
char h_fmt_date[30];
char h_con_name [ 31];
struct DA_T_user_pg_h{ /* type contains host variables for object data */
char user_id [ 31];
long group_id;
char cre_date [ 21];
char mod_date [ 21];
char status [ 31];
char remark [2001];
} h_user;
short int h_ind_mod_date;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, "User-ID:", vp_user->user_id, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* copy passed record into host variable
*/
strcpy(h_user_id_qry , vp_user->user_id);
strcpy(h_user.user_id , vp_user->user_id);
h_user.group_id = vp_user->group_id;
strcpy(h_user.cre_date , vp_user->cre_date);
strcpy(h_user.mod_date , vp_user->mod_date);
strcpy(h_user.status , vp_user->status);
strcpy(h_user.remark , vp_user->remark);
/* Update passed record in database */
errln = 10;
EXEC SQL SELECT to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_user.mod_date INDICATOR :h_ind_mod_date;
if (h_ind_mod_date == -1) strcpy(h_user.mod_date,"");
/* ignore update of CRE_DATE */
errln = 20;
EXEC SQL UPDATE USER_TAB
SET GROUP_ID = :h_user.group_id,
MOD_DATE = to_timestamp(:h_user.mod_date, :h_fmt_date),
STATUS = :h_user.status,
REMARK = :h_user.remark
WHERE USER_ID = :h_user_id_qry;
/* return new MOD_DATE by passed struct */
strcpy(vp_user->mod_date, h_user.mod_date);
/* record successfully updated */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_user (USER_TAB)
*
* Issue : 30-SEP-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Delete record from USER_TAB specified by "user_id"
*
* Parameter: vp_user_id (i) USER_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from USER_TAB specified by "user_id".
Output:
vp_errinfo - Error info in case of error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 30-SEP-2002
\param db_con Pointer to connection
\param vp_user_id USER_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_user (DB_con *db_con,
char *vp_user_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_delete_user";
int v_status = DA_SUCCESS;
/* used for pre-check */
char v_errortext[256];
int v_data_referenced = 0;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
char h_user_id[31];
/* long h_phrase_grp_id;*/
/* char h_role_name[256]; */
/* char h_revoke_statement[300]; */
/* char h_del_syn_statement[100];*/
/* char h_synonym[31];*/
/* used for pre-check */
int h_count;
long h_sess_id;
/* host var. for DB connection */
char h_con_name[ 31];
/* indicator variables */
/*short int h_ind_user_id;*/
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, "User-ID:", vp_user_id, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* init local variables */
strcpy (v_errortext, "(");
strcpy (h_user_id , vp_user_id);
strcpy (h_con_name , db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* -----------------------------------------------------------------------------*
* PRE-CHECK -> do sessions of other users reference data of user to be deleted?
* ---------------------------------------------------------------------------- */
errln = 10;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 20;
EXEC SQL SELECT COUNT(USER_ID)
INTO :h_count
FROM SESS_TAB
WHERE USER_ID <> :h_user_id
AND CATCH_ID IN (SELECT CATCH_ID
FROM CATCH_TAB
WHERE USER_ID = :h_user_id);
if (h_count > 0)
{
v_data_referenced = 1;
if (strcmp(v_errortext,"(") == 0)
sprintf(v_errortext, "%s%s", v_errortext, "CATCH_TAB");
else
sprintf(v_errortext, "%s, %s", v_errortext, "CATCH_TAB");
}
errln = 30;
EXEC SQL SELECT COUNT(USER_ID)
INTO :h_count
FROM SESS_TAB
WHERE USER_ID <> :h_user_id
AND ENV_ID IN (SELECT ENV_ID
FROM ENV_TAB
WHERE USER_ID = :h_user_id);
if (h_count > 0)
{
v_data_referenced = 1;
if (strcmp(v_errortext,"(") == 0)
sprintf(v_errortext, "%s%s", v_errortext, "ENV_TAB");
else
sprintf(v_errortext, "%s, %s", v_errortext, "ENV_TAB");
}
errln = 40;
EXEC SQL SELECT COUNT(USER_ID)
INTO :h_count
FROM SESS_TAB
WHERE USER_ID <> :h_user_id
AND MARKET_ID IN (SELECT MARKET_ID
FROM MARKET_TAB
WHERE USER_ID = :h_user_id);
if (h_count > 0)
{
v_data_referenced = 1;
if (strcmp(v_errortext,"(") == 0)
sprintf(v_errortext, "%s%s", v_errortext, "MARKET_TAB");
else
sprintf(v_errortext, "%s, %s", v_errortext, "MARKET_TAB");
}
errln = 50;
EXEC SQL SELECT COUNT(USER_ID)
INTO :h_count
FROM SESS_TAB
WHERE USER_ID <> :h_user_id
AND MOD_ID IN (SELECT MOD_ID
FROM MOD_TAB
WHERE USER_ID = :h_user_id);
if (h_count > 0)
{
v_data_referenced = 1;
if (strcmp(v_errortext,"(") == 0)
sprintf(v_errortext, "%s%s", v_errortext, "MOD_TAB");
else
sprintf(v_errortext, "%s, %s", v_errortext, "MOD_TAB");
}
errln = 60;
EXEC SQL SELECT COUNT(USER_ID)
INTO :h_count
FROM SESS_TAB
WHERE USER_ID <> :h_user_id
AND SUBST_ID IN (SELECT SUBST_ID
FROM SUBST_TAB
WHERE USER_ID = :h_user_id);
if (h_count > 0)
{
v_data_referenced = 1;
if (strcmp(v_errortext,"(") == 0)
sprintf(v_errortext, "%s%s", v_errortext, "SUBST_TAB");
else
sprintf(v_errortext, "%s, %s", v_errortext, "SUBST_TAB");
}
errln = 70;
EXEC SQL SELECT COUNT(USER_ID)
INTO :h_count
FROM SESS_TAB
WHERE USER_ID <> :h_user_id
AND SESS_DISCH_ID IN (SELECT SESS_DISCH_ID
FROM SESS_DISCH_TAB
WHERE USER_ID = :h_user_id);
if (h_count > 0)
{
v_data_referenced = 1;
if (strcmp(v_errortext,"(") == 0)
sprintf(v_errortext, "%s%s", v_errortext, "SESS_DISCH_TAB");
else
sprintf(v_errortext, "%s, %s", v_errortext, "SESS_DISCH_TAB");
}
sprintf(v_errortext,"%s%s", v_errortext, ")");
/* end of pre-check */
errln = 80;
EXEC SQL WHENEVER NOT FOUND GOTO error;
if (!v_data_referenced)
{
/* delete sessions and data referenced by the sessions of user to be deleted */
errln = 90;
EXEC SQL DECLARE DELCURSOR CURSOR FOR
SELECT SESS_ID
FROM SESS_TAB
WHERE USER_ID = :h_user_id;
errln = 100;
EXEC SQL OPEN DELCURSOR;
errln = 110;
EXEC SQL WHENEVER NOT FOUND GOTO endloop;
do
{
errln = 120;
EXEC SQL FETCH DELCURSOR
INTO :h_sess_id;
gda_delete_sess (db_con, h_sess_id, NULL);
} while (1);
endloop:
errln = 130;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* delete all remaining data belonging to the user */
errln = 140;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
errln = 150;
EXEC SQL DELETE FROM CATCH_TAB
WHERE USER_ID = :h_user_id;
errln = 160;
EXEC SQL DELETE FROM SUBST_TAB
WHERE USER_ID = :h_user_id;
errln = 170;
EXEC SQL DELETE FROM ENV_TAB
WHERE USER_ID = :h_user_id;
errln = 180;
EXEC SQL DELETE FROM MARKET_TAB
WHERE USER_ID = :h_user_id;
errln = 190;
EXEC SQL DELETE FROM MOD_TAB
WHERE USER_ID = :h_user_id;
errln = 200;
EXEC SQL DELETE FROM SESS_DISCH_TAB
WHERE USER_ID = :h_user_id;
errln = 210;
EXEC SQL DELETE FROM BIN_OBJ_TAB
WHERE USER_ID = :h_user_id;
/* delete specified user */
errln = 220;
EXEC SQL WHENEVER NOT FOUND GOTO error;
errln = 230;
EXEC SQL DELETE FROM USER_TAB
WHERE USER_ID = :h_user_id;
/*
* THE FOLLOWING PART IS NOT USED ANYMORE BECAUSE
* IN POSTGRESQL THERE IS NO
* - CREATE ROLE ...
* - CREATE SYNONYM...
* - ALL_OBJECTS TABLE
*
* FURTHER ON THE PHRASE_TAB SHOULDN'T BE USED BY
* ADMINISTRATIONAL WORK.
*
* ONE POSSIBILITY WAS TO CREATE AN API-FUNCTION
* WITH USERNAME AS PARAMETER WHERE A SPECIAL SET
* OF RIGHTS WILL BE SET.
*
* THIS FUNCTION WOULD BE CALLED INSTEAD THE SQL
* ROLE STATEMENT.
*/
/* revoke greater standard role from user */
/* h_phrase_grp_id = DA_PHRASE_GRP_ID_ROLE;
errln = 240;
EXEC SQL SELECT VALUE_PT
INTO :h_role_name
FROM PHRASE_TAB
WHERE PHRASE_GRP_ID = :h_phrase_grp_id;
sprintf (h_revoke_statement, "REVOKE %s FROM %s",
h_role_name, h_user_id);
errln = 250;
EXEC SQL EXECUTE IMMEDIATE :h_revoke_statement;
*/
/* delete user's private synonyms */
/* h_phrase_grp_id = DA_PHRASE_GRP_ID_SYN;
errln = 260;
EXEC SQL DECLARE syn_del_cursor CURSOR FOR
SELECT VALUE_PT
FROM PHRASE_TAB
WHERE PHRASE_GRP_ID = :h_phrase_grp_id;
errln = 270;
EXEC SQL OPEN syn_del_cursor;
errln = 280;
EXEC SQL WHENEVER NOT FOUND GOTO endloop2;
while (1)
{
errln = 290;
EXEC SQL FETCH syn_del_cursor INTO :h_synonym;
errln = 300;
EXEC SQL SELECT COUNT (OBJECT_NAME)
INTO :h_count
FROM ALL_OBJECTS
WHERE OBJECT_NAME = :h_synonym
AND OWNER = :h_user_id;
if (h_count == 1)
{
sprintf (h_del_syn_statement,
"DROP SYNONYM %s.%s",
h_user_id, h_synonym);
errln = 310;
EXEC SQL EXECUTE IMMEDIATE :h_del_syn_statement;
}
}
endloop2:
*/
/* record successfully deleted */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
else
{
/* set error type = internal */
vp_errinfo->err_type = DA_ERRTYP_INT;
/* set internal error number */
vp_errinfo->err_no = DA_ERR_USER_REF_DATA;
/* set error parameter by error-line and module in which error occured */
sprintf (vp_errinfo->err_param,"%s - %s", v_module, v_errortext);
return(DA_FAIL);
}
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: GROUP_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_group (GROUP_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of group data from GROUP_TAB.
*
* Query conditions:
* a) group_id = -1; => return: 1..n records
* b) group_id <>-1; => return: 1 record
*
* Parameter: vp_group_id (i) ID of group to select
* vp_group (o) Return value (list of group data)
* vp_errinfo (o) Error info in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of group data from GROUP_TAB.
Query conditions:
group_id = -1; => return: 1..n records
group_id <>-1; => return: 1 record
Output:
vp_group - Return value (list of group data)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param db_con Pointer to connection
\param vp_group_id ID of group to select
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_group (DB_con *db_con,
long vp_group_id,
DA_T_group **vp_group,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_group";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_group v_group_buf;
/* pointer to list root, list elements */
DA_T_group *v_root_lst_ptr = NULL;
DA_T_group *v_new_elem_ptr = NULL;
DA_T_group *v_last_elem_ptr = NULL;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_fmt_date [ 30];
char h_con_name [ 31];
char h_where_clause [100];
char h_query [2000];
struct DA_T_group_pg_h{ /* type contains host variables for object data */
long group_id;
char name [256];
char admin [ 2];
char cre_date[ 21];
char mod_date[ 21];
char status [ 31];
char remark [2001];
} h_group;
struct DA_T_group_pg_i{ /* indicator variables for host variable struct */
short int group_id;
short int name;
short int admin;
short int cre_date;
short int mod_date;
short int status;
short int remark;
} h_ind_group;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* determine query condition
* a) group_id = -1; => return: 1..n records
* b) group_id <>-1; => return: 1 record
*/
if ( vp_group_id == -1 )
{
/* case a) */
strcpy (h_where_clause, "");
}
else
{
/* case b) */
sprintf(h_where_clause, "WHERE GROUP_ID = %ld", vp_group_id);
}
/*
* DECLARE CURSOR
* to select group data from GROUP_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
sprintf (h_query, "SELECT GROUP_ID,"
"NAME,"
"ADMIN,"
"to_char(CRE_DATE, '%s'),"
"to_char(MOD_DATE, '%s'),"
"STATUS,"
"REMARK "
" FROM GROUP_TAB "
"%s "
"ORDER BY GROUP_ID",
h_fmt_date, h_fmt_date, h_where_clause);
EXEC SQL PREPARE get_state FROM :h_query;
EXEC SQL DECLARE group_csr CURSOR FOR get_state;
errln = 20;
EXEC SQL OPEN group_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH group_csr INTO :h_group INDICATOR :h_ind_group;
/* check indicator variables (in regard to NULL values) */
if (h_ind_group.group_id == -1) h_group.group_id = -1;
if (h_ind_group.name == -1) strcpy(h_group.name, "");
if (h_ind_group.admin == -1) strcpy(h_group.admin, "");
if (h_ind_group.cre_date == -1) strcpy(h_group.cre_date,"");
if (h_ind_group.mod_date == -1) strcpy(h_group.mod_date,"");
if (h_ind_group.status == -1) strcpy(h_group.status, "");
if (h_ind_group.remark == -1) strcpy(h_group.remark, "");
/* copy result into temp. buffer */
v_group_buf.group_id = h_group.group_id;
strcpy(v_group_buf.name , h_group.name);
strcpy(v_group_buf.admin , h_group.admin);
strcpy(v_group_buf.cre_date , h_group.cre_date);
strcpy(v_group_buf.mod_date , h_group.mod_date);
strcpy(v_group_buf.status , h_group.status);
strcpy(v_group_buf.remark , h_group.remark);
v_group_buf.next_element = NULL;
/* get access right for data */
v_status = lgda_get_access_right(DA_A_GROUP_TAB, (void*) &v_group_buf,
&v_access_right, vp_errinfo);
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: group is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_group*) malloc( sizeof(DA_T_group) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param,"%s - malloc(DA_T_group)", v_module);
gda_free_group(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_group) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_group_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE group_csr;
/* return created result list */
(*vp_group) = v_root_lst_ptr;
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE group_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_group (GROUP_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "db_get_group()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_group (i) pointer to "list of" group data records
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "db_get_group()".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param vp_group pointer to "list of" group data records
\return ---
*/
void gda_free_group(DA_T_group *vp_group)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_group";
#endif
/* pointer to list elements */
DA_T_group *v_next_elem_ptr = NULL;
DA_T_group *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_group;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/*********************************************************************
* Name : gda_insert_group (GROUP_TAB)
*
* Issue : 30-SEP-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Insert record into GROUP_TAB.
*
* Parameter: vp_group (i/o) data to insert into GROUP_TAB
* OUTPUT:
* - cre_date = CURRENT_TIMESTAMP
* - mod_date = CURRENT_TIMESTAMP
* - group_id: from GROUP_SEQ
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into GROUP_TAB.
Output:
vp_group - cre_date, mod_date, group_id
vp_errinfo - Error info in case of error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 30-SEP-2002
\param db_con Pointer to connection
\param vp_group data to insert into GROUP_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_group(DB_con *db_con,
DA_T_group *vp_group,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_group";
int v_status = DA_SUCCESS;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
long h_group_id_new;
char h_fmt_date[30];
char h_con_name[31];
struct DA_T_group_pg_h{ /* type contains host variables for object data */
long group_id;
char name [256];
char admin [ 2];
char cre_date[ 21];
char mod_date[ 21];
char status [ 31];
char remark [2001];
} h_group;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
*get new GROUP-ID and set cre_date and sess_date = CURRENT_TIMESTAMP
*/
errln = 10;
EXEC SQL SELECT NEXTVAL('GROUP_SEQ'),
to_char(CURRENT_TIMESTAMP, :h_fmt_date),
to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_group_id_new,
:h_group.cre_date,
:h_group.mod_date;
/*
* copy passed record into host variable, except for cre_date and
* mod_date
*/
h_group.group_id = h_group_id_new;
strcpy(h_group.name , vp_group->name);
strcpy(h_group.admin , vp_group->admin);
strcpy(h_group.status , vp_group->status);
strcpy(h_group.remark , vp_group->remark);
/* Insert passed record */
errln = 20;
EXEC SQL INSERT INTO GROUP_TAB (GROUP_ID,
NAME,
ADMIN,
CRE_DATE,
MOD_DATE,
STATUS,
REMARK)
VALUES (:h_group.group_id,
:h_group.name,
:h_group.admin,
to_timestamp(:h_group.cre_date, :h_fmt_date),
to_timestamp(:h_group.mod_date, :h_fmt_date),
:h_group.status,
:h_group.remark);
/* set return value (created GROUP_ID,...) into passed struct/record */
vp_group->group_id = h_group_id_new;
strcpy(vp_group->cre_date, h_group.cre_date);
strcpy(vp_group->mod_date, h_group.mod_date);
/* record successfully inserted */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_group (GROUP_TAB)
*
* Issue : 30-SEP-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by GROUP_ID) in GROUP_TAB
* by data of passed record.
*
* Parameter: vp_group (i/o) new group data, containing GROUP_ID of
* record to update.
* OUTPUT: vp_group.MOD_DATE = CURRENT_TIMESTAMP
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by GROUP_ID) in GROUP_TAB by data of passed record.
Output:
vp_group - mod_date
vp_errinfo - Error info in case of error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 30-SEP-2002
\param db_con Pointer to connection
\param vp_group new group data, containing GROUP_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_group (DB_con *db_con,
DA_T_group *vp_group,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_group";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_group_id;
char h_fmt_date[30];
char h_con_name[31];
struct DA_T_group_pg_h{ /* type contains host variables for object data */
long group_id;
char name [256];
char admin [ 2];
char cre_date[ 21];
char mod_date[ 21];
char status [ 31];
char remark [2001];
} h_group;
short int h_ind_mod_date;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/* set format masks for date values */
strcpy(h_fmt_date, DA_FMT_date);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* copy passed record into host variable
*/
h_group_id = vp_group->group_id;
h_group.group_id = vp_group->group_id;
strcpy(h_group.name , vp_group->name);
strcpy(h_group.admin , vp_group->admin);
strcpy(h_group.cre_date , vp_group->cre_date);
strcpy(h_group.mod_date , vp_group->mod_date);
strcpy(h_group.status , vp_group->status);
strcpy(h_group.remark , vp_group->remark);
/* Update passed record in database */
errln = 10;
EXEC SQL SELECT to_char(CURRENT_TIMESTAMP, :h_fmt_date)
INTO :h_group.mod_date INDICATOR :h_ind_mod_date;
if (h_ind_mod_date == -1) strcpy(h_group.mod_date,"");
/* ignore update of CRE_DATE */
errln = 20;
EXEC SQL UPDATE GROUP_TAB
SET GROUP_ID = :h_group.group_id,
NAME = :h_group.name,
ADMIN = :h_group.admin,
MOD_DATE = to_timestamp(:h_group.mod_date, :h_fmt_date),
STATUS = :h_group.status,
REMARK = :h_group.remark
WHERE GROUP_ID = :h_group_id;
/* return new MOD_DATE by passed struct */
strcpy(vp_group->mod_date, h_group.mod_date);
/* record successfully updated */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_group (GROUP_TAB)
*
* Issue : 01-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Delete record from GROUP_TAB specified by "group_id"
*
* Parameter: vp_group_id (i) GROUP_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from GROUP_TAB specified by "group_id".
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param db_con Pointer to connection
\param vp_group_id GROUP_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_group (DB_con *db_con,
long vp_group_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_delete_group";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_group_id;
long h_count;
char h_con_name[31];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* -----------------------------------------------------*
* PRE-CHECK -> do users exist that belong to the group?
* ---------------------------------------------------- */
h_group_id = vp_group_id;
errln = 10;
EXEC SQL SELECT COUNT(GROUP_ID) INTO :h_count
FROM USER_TAB
WHERE GROUP_ID = :h_group_id
LIMIT 1;
if (h_count > 0)
{
/*
* => group is still in use, delete not allowed!
*/
/* set error type = internal */
vp_errinfo->err_type = DA_ERRTYP_INT;
/* set internal error number */
vp_errinfo->err_no = DA_ERR_GROUP_REF_DATA;
/* set error parameter by error-line and module in which error occured */
sprintf (vp_errinfo->err_param,"%s - GROUP_ID: %ld", v_module, vp_group_id);
return(DA_FAIL);
}
/* end of pre-check */
/* delete specified message */
errln = 20;
EXEC SQL DELETE FROM GROUP_TAB
WHERE GROUP_ID = :h_group_id;
/* record successfully deleted */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: MESSAGE_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_message (MESSAGE_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get list of messages from MESSAGE_TAB.
*
* Query conditions:
* - message_id <>-1; => return: 1 record
*
* Parameter: vp_message_id (i) ID of message to select
* vp_language (i) language of message to select
* vp_message (o) Return value (one message)
* vp_errinfo (o) Error info in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of messages from MESSAGE_TAB.
Query conditions:
message_id <>-1; => return: 1 record
Output:
vp_message - Return value (one message)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param db_con Pointer to connection
\param vp_message_id ID of message to select
\param vp_language language of message to select
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_message (DB_con *db_con,
long vp_message_id,
char *vp_language,
DA_T_message *vp_message,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_message";
int v_status = DA_SUCCESS;
// not used: int v_access_right= DA_A_NONE;
/* temp. buffer */
// not used: DA_T_message v_message_buf;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_message_id_qry[240];
char h_language_qry[240];
char h_con_name[31];
struct DA_T_message_pg_h{ /* type contains host variables for object data */
long message_id;
char language [ 2];
char type [ 4];
char message [256];
} h_message;
struct DA_T_message_pg_i{ /* indicator variables for host variable struct */
short int message_id;
short int language;
short int type;
short int message;
} h_ind_message;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* determine query condition
* a) message_id <>-1; => return: 1..n records
*/
sprintf(h_message_id_qry, "%ld", vp_message_id);
strcpy (h_language_qry, vp_language);
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* SELECT message data from MESSAGE_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO message_not_found;
errln = 20;
EXEC SQL SELECT MESSAGE_ID,
LANGUAGE,
TYPE,
MESSAGE
INTO :h_message INDICATOR :h_ind_message
FROM MESSAGE_TAB
WHERE MESSAGE_ID = :h_message_id_qry
AND LANGUAGE = :h_language_qry;
/* check indicator variables (in regard to NULL values) */
if (h_ind_message.message_id == -1) h_message.message_id = -1;
if (h_ind_message.language == -1) strcpy(h_message.language, "");
if (h_ind_message.type == -1) strcpy(h_message.type, "");
if (h_ind_message.message == -1) strcpy(h_message.message, "");
/* copy result into retrun parameter */
vp_message->message_id = h_message.message_id;
strcpy(vp_message->language , h_message.language);
strcpy(vp_message->type , h_message.type);
strcpy(vp_message->message , h_message.message);
if (NULL)
{
message_not_found:
/*
* ERROR: message not defined for message_id/language
*/
vp_message->message_id = vp_message_id;
strcpy(vp_message->language , vp_language);
strcpy(vp_message->type , ">");
strcpy(vp_message->message , "");
}
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_insert_message (MESSAGE_TAB)
*
* Issue : 01-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Insert record into MESSAGE_TAB.
*
* Parameter: vp_message (i) data to insert into MESSAGE_TAB
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into MESSAGE_TAB.
Output:
vp_errinfo - Error info in case of error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-OCT-2002
\param db_con Pointer to connection
\param vp_message data to insert into MESSAGE_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_message(DB_con *db_con,
DA_T_message vp_message,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_message";
int v_status = DA_SUCCESS;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
struct DA_T_message_pg_h{ /* type contains host variables for object data */
long message_id;
char language [ 2];
char type [ 4];
char message [256];
} h_message;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* copy passed record into host variable
*/
h_message.message_id = vp_message.message_id;
strcpy(h_message.language,vp_message.language);
strcpy(h_message.type, vp_message.type);
strcpy(h_message.message, vp_message.message);
/* Insert passed record */
errln = 10;
EXEC SQL INSERT INTO MESSAGE_TAB (MESSAGE_ID,
LANGUAGE,
TYPE,
MESSAGE)
VALUES (:h_message.message_id,
:h_message.language,
:h_message.type,
:h_message.message);
/* record successfully inserted */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_message (MESSAGE_TAB)
*
* Issue : 01-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by MESSAGE_ID) in MESSAGE_TAB
* by data of passed record.
*
* Parameter: vp_message (i) new message data
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by MESSAGE_ID) in MESSAGE_TAB by data of passed record.
Output:
vp_errinfo - Error info in case of error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-OCT-2002
\param db_con Pointer to connection
\param vp_message new message data
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_message(DB_con *db_con,
DA_T_message vp_message,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_message";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
struct DA_T_message_pg_h{ /* type contains host variables for object data */
long message_id;
char language [ 2];
char type [ 4];
char message [256];
} h_message;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* copy passed record into host variable
*/
h_message.message_id = vp_message.message_id;
strcpy(h_message.language, vp_message.language);
strcpy(h_message.type , vp_message.type);
strcpy(h_message.message , vp_message.message);
/* Update passed record in database */
errln = 10;
EXEC SQL UPDATE MESSAGE_TAB
SET LANGUAGE = :h_message.language,
TYPE = :h_message.type,
MESSAGE = :h_message.message
WHERE MESSAGE_ID = :h_message.message_id;
/* record successfully updated */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_message (MESSAGE_TAB)
*
* Issue : 01-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Delete record from MESSAGE_TAB specified by "message_id"
*
* Parameter: vp_group_id (i) MESSAGE_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from MESSAGE_TAB specified by "message_id".
Output:
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param db_con Pointer to connection
\param vp_message_id MESSAGE_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_message(DB_con *db_con,
long vp_message_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_delete_message";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_message_id;
char h_con_name[31];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
h_message_id = vp_message_id;
/* delete specified message */
errln = 10;
EXEC SQL DELETE FROM MESSAGE_TAB
WHERE message_ID = :h_message_id;
/* record successfully deleted */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_get_all_messages (MESSAGE_TAB)
*
* Issue : 21-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Get list of all message data from MESSAGE_TAB.
*
* Parameter: vp_message (o) Return value (list of message data)
* vp_errinfo (o) Error info in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get list of all message data from MESSAGE_TAB.
calls gda_get_all_messages().
Output:
vp_message - Return value (list of message data)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param db_con Pointer to connection
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_all_messages (DB_con *db_con,
DA_T_message_list **vp_message,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_all_messages";
int v_status = DA_SUCCESS;
/* temp. buffer */
DA_T_message_list v_message_buf;
/* pointer to list root, list elements */
DA_T_message_list *v_root_lst_ptr = NULL;
DA_T_message_list *v_new_elem_ptr = NULL;
DA_T_message_list *v_last_elem_ptr = NULL;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name[31];
struct DA_T_message_pg_h{ /* type contains host variables for object data */
long message_id;
char language [ 2];
char type [ 4];
char message [256];
} h_message;
struct DA_T_message_pg_i{ /* indicator variables for host variable struct */
short int message_id;
short int language;
short int type;
short int message;
} h_ind_message;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CURSOR
* to select message data from message_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
EXEC SQL DECLARE message_csr CURSOR FOR
SELECT MESSAGE_ID,
LANGUAGE,
TYPE,
MESSAGE
FROM MESSAGE_TAB
ORDER BY MESSAGE_ID;
errln = 20;
EXEC SQL OPEN message_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH message_csr INTO :h_message INDICATOR :h_ind_message;
/* check indicator variables (in regard to NULL values) */
if (h_ind_message.message_id == -1) h_message.message_id = -1;
if (h_ind_message.language == -1) strcpy(h_message.language, "");
if (h_ind_message.type == -1) strcpy(h_message.type, "");
if (h_ind_message.message == -1) strcpy(h_message.message, "");
/* copy result into temp. buffer */
v_message_buf.message_id = h_message.message_id;
strcpy(v_message_buf.language , h_message.language);
strcpy(v_message_buf.type , h_message.type);
strcpy(v_message_buf.message , h_message.message);
v_message_buf.next_element = NULL;
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_message_list*) malloc( sizeof(DA_T_message_list) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param,"%s - malloc(DA_T_message_list)", v_module);
gda_free_all_messages(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_message) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_message_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE message_csr;
/* return created result list */
(*vp_message) = v_root_lst_ptr;
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE message_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_all_messages (MESSAGE_TAB)
*
* Issue : 21-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "gda_get_all_messages()".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_message_list (i) pointer to "list of" message data records
*
* Return : nothing
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "da_get_all_messages()"..
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param vp_message pointer to "list of" message data records
\return ---
*/
void gda_free_all_messages (DA_T_message_list *vp_message)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_all_messages";
#endif
/* pointer to list elements */
DA_T_message_list *v_next_elem_ptr = NULL;
DA_T_message_list *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_message;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- *
* FUNCTIONS to access table: PHRASE_TAB
* ----------------------------------------------------------------- *
* ----------------------------------------------------------------- */
/*********************************************************************
* Name : gda_get_phrase (PHRASE_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get single phrase from PHRASE_TAB
*
* Query conditions:
* - phrase_id >0, language <> ""; => return: 1 record
*
* Parameter: vp_phrase_id (i) ID of phrase to select
* vp_language (i) language of phrase to select
* vp_phrase (o) Return value (single phrases)
* vp_errinfo (o) Error info in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get single phrase from PHRASE_TAB.
Query conditions:
phrase_id >0, language <> ""; => return: 1 record
Output:
vp_phrase - Return value (single phrases)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param db_con Pointer to connection
\param vp_phrase_id ID of phrase to select
\param vp_language language of phrase to select
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_phrase (DB_con *db_con,
long vp_phrase_id,
char *vp_language,
DA_T_phrase *vp_phrase,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_phrase";
int v_status = DA_SUCCESS;
// not used: int v_access_right= DA_A_NONE;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_phrase_id_qry[240];
char h_language_qry [240];
char h_con_name [ 31];
struct DA_T_phrase_pg_h{ /* type contains host variables for object data */
long phrase_id;
long phrase_grp_id;
char language [ 2];
int sort;
char value [256];
char remark [2001];
} h_phrase;
struct DA_T_phrase_pg_i{ /* indicator variables for host variable struct */
short int phrase_id;
short int phrase_grp_id;
short int language;
short int sort;
short int value;
short int remark;
} h_ind_phrase;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* determine query condition
*/
sprintf(h_phrase_id_qry, "%ld", vp_phrase_id);
strcpy (h_language_qry, vp_language);
strcpy (h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* SELECT phrase from phrase_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
EXEC SQL WHENEVER NOT FOUND GOTO phrase_not_found;
errln = 20;
EXEC SQL SELECT PHRASE_ID,
PHRASE_GRP_ID,
LANGUAGE,
SORT,
VALUE_PT,
REMARK
INTO :h_phrase INDICATOR :h_ind_phrase
FROM PHRASE_TAB
WHERE PHRASE_ID = :h_phrase_id_qry
AND LANGUAGE = :h_language_qry
LIMIT 1;
/* check indicator variables (in regard to NULL values) */
if (h_ind_phrase.phrase_id == -1) h_phrase.phrase_id = -1;
if (h_ind_phrase.phrase_grp_id == -1) h_phrase.phrase_grp_id = -1;
if (h_ind_phrase.sort == -1) h_phrase.sort = 0;
if (h_ind_phrase.language == -1) strcpy(h_phrase.language, "");
if (h_ind_phrase.value == -1) strcpy(h_phrase.value, "");
if (h_ind_phrase.remark == -1) strcpy(h_phrase.remark, "");
/* copy result into temp. buffer */
vp_phrase->phrase_id = h_phrase.phrase_id;
vp_phrase->phrase_grp_id = h_phrase.phrase_grp_id;
vp_phrase->sort = h_phrase.sort;
strcpy(vp_phrase->language , h_phrase.language);
strcpy(vp_phrase->value , h_phrase.value);
strcpy(vp_phrase->remark , h_phrase.remark);
vp_phrase->next_element = NULL;
if (NULL)
{
phrase_not_found:
/*
* ERROR: phrase not found
*/
vp_phrase->phrase_id = vp_phrase_id;
vp_phrase->phrase_grp_id = -1;
vp_phrase->sort = 0;
strcpy(vp_phrase->language , vp_language);
strcpy(vp_phrase->value , "");
strcpy(vp_phrase->remark , "");
vp_phrase->next_element = NULL;
}
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_get_phrase_grp (PHRASE_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Get group phrases (list of values) from PHRASE_TAB
*
* Query conditions:
* a) phrase_grp_id >0; => return: 1..n records
*
* Parameter: vp_phrase_grp_id (i) ID of phrase grp. from which
* phrases has to be selected
* vp_phrase_grp (o) Return value (list of phrases)
* vp_errinfo (o) Error info in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get group phrases (list of values) from PHRASE_TAB.
Query conditions:
phrase_grp_id >0; => return: 1..n records
Output:
vp_phrase_grp - Return value (list phrases)
vp_errinfo - Error info in case of error occured
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param db_con Pointer to connection
\param vp_phrase_grp_id ID of phrase grp. from which phrases has to be selected
\param vp_language language of phrase
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_phrase_grp (DB_con *db_con,
long vp_phrase_grp_id,
char *vp_language,
DA_T_phrase **vp_phrase_grp,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_phrase_grp";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_phrase v_phrase_buf;
/* pointer to list root, list elements */
DA_T_phrase *v_root_lst_ptr = NULL;
DA_T_phrase *v_new_elem_ptr = NULL;
DA_T_phrase *v_last_elem_ptr = NULL;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_phrase_grp_id_qry[240];
char h_language_qry[240];
char h_con_name [ 31];
struct DA_T_phrase_pg_h{ /* type contains host variables for object data */
long phrase_id;
long phrase_grp_id;
char language [ 2];
int sort;
char value [256];
char remark [2001];
} h_phrase;
struct DA_T_phrase_pg_i{ /* indicator variables for host variable struct */
short int phrase_id;
short int phrase_grp_id;
short int language;
short int sort;
short int value;
short int remark;
} h_ind_phrase;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* determine query condition
*/
sprintf(h_phrase_grp_id_qry, "%ld", vp_phrase_grp_id);
strcpy (h_language_qry, vp_language);
strcpy (h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CUROSR
* to select phrases for phrase grp. from phrase_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
EXEC SQL DECLARE phrase_grp_csr CURSOR FOR
SELECT PHRASE_ID,
PHRASE_GRP_ID,
LANGUAGE,
SORT,
VALUE_PT,
REMARK
FROM PHRASE_TAB
WHERE PHRASE_GRP_ID = :h_phrase_grp_id_qry
AND LANGUAGE = :h_language_qry
ORDER BY SORT, phrase_ID;
errln = 20;
EXEC SQL OPEN phrase_grp_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH phrase_grp_csr INTO :h_phrase INDICATOR :h_ind_phrase;
/* check indicator variables (in regard to NULL values) */
if (h_ind_phrase.phrase_id == -1) h_phrase.phrase_id = -1;
if (h_ind_phrase.phrase_grp_id == -1) h_phrase.phrase_grp_id = -1;
if (h_ind_phrase.sort == -1) h_phrase.sort = 0;
if (h_ind_phrase.language == -1) strcpy(h_phrase.language, "");
if (h_ind_phrase.value == -1) strcpy(h_phrase.value, "");
if (h_ind_phrase.remark == -1) strcpy(h_phrase.remark, "");
/* copy result into temp. buffer */
v_phrase_buf.phrase_id = h_phrase.phrase_id;
v_phrase_buf.phrase_grp_id = h_phrase.phrase_grp_id;
v_phrase_buf.sort = h_phrase.sort;
strcpy(v_phrase_buf.language , h_phrase.language);
strcpy(v_phrase_buf.value , h_phrase.value);
strcpy(v_phrase_buf.remark , h_phrase.remark);
v_phrase_buf.next_element = NULL;
/* get access right for data */
v_access_right = DA_A_VIEW;
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: phrase is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_phrase*) malloc( sizeof(DA_T_phrase) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param,"%s - malloc(DA_T_phrase)", v_module);
gda_free_phrase_grp(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_phrase_grp) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_phrase_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE phrase_grp_csr;
/* return created result list */
(*vp_phrase_grp) = v_root_lst_ptr;
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE phrase_grp_csr;
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_get_all_phrases (PHRASE_TAB)
*
* Issue : 03-DEC-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Get all phrases (of a specified language) from PHRASE_TAB
*
* Parameter: vp_language (i) specifies the the language of the
* phrases
* vp_language = "%" ==> get all phrases
* vp_phrase_grp (o) Return value (list of phrases)
* vp_errinfo (o) Error info in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Get all phrases (of a specified language) from PHRASE_TAB.
Output:
vp_phrase_grp - Return value (list phrases)
vp_errinfo - Error info in case of error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 03-DEC-2002
\param db_con Pointer to connection
\param vp_language specifies the the language of the phrases
\return DA_SUCCESS \n DA_FAIL
*/
int gda_get_all_phrases (DB_con *db_con,
char *vp_language,
DA_T_phrase **vp_phrase_grp,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_get_all_phrases";
int v_status = DA_SUCCESS;
int v_access_right= DA_A_NONE;
/* temp. buffer */
DA_T_phrase v_phrase_buf;
/* pointer to list root, list elements */
DA_T_phrase *v_root_lst_ptr = NULL;
DA_T_phrase *v_new_elem_ptr = NULL;
DA_T_phrase *v_last_elem_ptr = NULL;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_language_qry[240];
char h_con_name [ 31];
struct DA_T_phrase_pg_h{ /* type contains host variables for object data */
long phrase_id;
long phrase_grp_id;
char language [ 2];
int sort;
char value [256];
char remark [2001];
} h_phrase;
struct DA_T_phrase_pg_i{ /* indicator variables for host variable struct */
short int phrase_id;
short int phrase_grp_id;
short int language;
short int sort;
short int value;
short int remark;
} h_ind_phrase;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* determine query condition
*/
strcpy (h_language_qry, vp_language);
strcpy (h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
* DECLARE CUROSR
* to select phrases from phrase_TAB
*
* => sequence of columns must match sequence of fields
* of struct in declare section!!!
*/
errln = 10;
EXEC SQL DECLARE phrase_csr CURSOR FOR
SELECT PHRASE_ID,
PHRASE_GRP_ID,
LANGUAGE,
SORT,
VALUE_PT,
REMARK
FROM PHRASE_TAB
WHERE LANGUAGE LIKE :h_language_qry
ORDER BY PHRASE_GRP_ID, SORT;
errln = 20;
EXEC SQL OPEN phrase_csr;
errln = 30;
EXEC SQL WHENEVER NOT FOUND GOTO end_loop;
while (v_status == DA_SUCCESS)
{
/* fetch record */
errln = 40;
EXEC SQL FETCH phrase_csr INTO :h_phrase INDICATOR :h_ind_phrase;
/* check indicator variables (in regard to NULL values) */
if (h_ind_phrase.phrase_id == -1) h_phrase.phrase_id = -1;
if (h_ind_phrase.phrase_grp_id == -1) h_phrase.phrase_grp_id = -1;
if (h_ind_phrase.sort == -1) h_phrase.sort = 0;
if (h_ind_phrase.language == -1) strcpy(h_phrase.language, "");
if (h_ind_phrase.value == -1) strcpy(h_phrase.value, "");
if (h_ind_phrase.remark == -1) strcpy(h_phrase.remark, "");
/* copy result into temp. buffer */
v_phrase_buf.phrase_id = h_phrase.phrase_id;
v_phrase_buf.phrase_grp_id = h_phrase.phrase_grp_id;
v_phrase_buf.sort = h_phrase.sort;
strcpy(v_phrase_buf.language , h_phrase.language);
strcpy(v_phrase_buf.value , h_phrase.value);
strcpy(v_phrase_buf.remark , h_phrase.remark);
v_phrase_buf.next_element = NULL;
/* get access right for data */
v_access_right = DA_A_VIEW;
if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS))
{
/* --------------------------------------------------------- *
* PRIV-CHK: phrase is allowed access data in req. mode
* --------------------------------------------------------- */
if (v_status == DA_SUCCESS)
{
/* -------------------------------------- *
* allocate memory for new result element
* -------------------------------------- */
v_new_elem_ptr = (DA_T_phrase*) malloc( sizeof(DA_T_phrase) );
if (v_new_elem_ptr == NULL)
{
/* <<< ERROR allocating memory >>> */
vp_errinfo->err_type = DA_ERRTYP_INT;
vp_errinfo->err_no = DA_ERR_MEMORY_ALLOC;
sprintf(vp_errinfo->err_param,"%s - malloc(DA_T_phrase)", v_module);
gda_free_phrase_grp(v_root_lst_ptr);
/* set result list pointer to NULL */
(*vp_phrase_grp) = NULL;
v_status = DA_FAIL;
}
else
{
if (v_root_lst_ptr == NULL)
v_root_lst_ptr = v_new_elem_ptr;
else
v_last_elem_ptr->next_element = v_new_elem_ptr;
/* copy result record into allocated list element */
*v_new_elem_ptr = v_phrase_buf;
/* reset pointer to next list element */
v_new_elem_ptr->next_element = NULL;
/* set pointer to last list element */
v_last_elem_ptr = v_new_elem_ptr;
}
} /* end: if (DA_SUCCESS) */
} /* end: if ((v_access_right >= DA_A_VIEW) && (v_status == DA_SUCCESS)) */
} /* end: while(v_status == DA_SUCCESS) */
end_loop:
errln = 50;
EXEC SQL CLOSE phrase_csr;
/* return created result list */
(*vp_phrase_grp) = v_root_lst_ptr;
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
/* try to close open cursor */
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL CLOSE phrase_csr;
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_free_phrase_grp (PHRASE_TAB)
*
* Issue : 01-AUG-2002 - T.V. - TechniData AG/Markdorf
*
* Purpose : Free memory allocated by function "gda_get_phrase_grp()"
* or "gda_get_all_phrases".
* Pointer must be explizitely set to NULL in the calling
* program after calling this function.
*
* Parameter: vp_group (i) pointer to "list of" phrases
*
* Return : none
* Globals : none
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Free memory allocated by function "da_get_phrase_grp()" or "gda_get_all_phrases".
Pointer must be explizitely set to NULL in the calling program after calling this function.
\author T.V. - TechniData AG/Markdorf \n H.K. - Intevation
\date 01-AUG-2002
\param vp_group pointer to "list of" phrases
\return ---
*/
void gda_free_phrase_grp (DA_T_phrase *vp_phrase_grp)
{
#if DEBUG_MODE_ON == 1
DA_T_MODULE_NAME v_module = "gda_free_phrase_grp";
#endif
/* pointer to list elements */
DA_T_phrase *v_next_elem_ptr = NULL;
DA_T_phrase *v_curr_elem_ptr = NULL;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
v_curr_elem_ptr = vp_phrase_grp;
while (v_curr_elem_ptr != NULL)
{
/* set pointer to next list element */
v_next_elem_ptr = v_curr_elem_ptr->next_element;
/* free memory of current list element */
free( v_curr_elem_ptr );
/* set pointer to next list element to deleter */
v_curr_elem_ptr = v_next_elem_ptr;
} /* end: while(v_curr_elem_ptr != NULL) */
}
/*********************************************************************
* Name : gda_insert_phrase (PHRASE_TAB)
*
* Issue : 02-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Insert record into PHRASE_TAB.
*
* Parameter: vp_phrase (i/o) data to insert into PHRASE_TAB
* OUTPUT:
* - phrase_id: from PHRASE_SEQ
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Insert record into PHRASE_TAB.
Output:
vp_phrase - phrase_id
vp_errinfo - Error info in case of error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 02-OCT-2002
\param db_con Pointer to connection
\param vp_phrase data to insert into PHRASE_TAB
\return DA_SUCCESS \n DA_FAIL
*/
int gda_insert_phrase (DB_con *db_con,
DA_T_phrase *vp_phrase,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_insert_phrase";
int v_status = DA_SUCCESS;
/* host variables */
EXEC SQL BEGIN DECLARE SECTION;
char h_con_name [ 31];
struct DA_T_phrase_pg_h{ /* type contains host variables for object data */
long phrase_id;
long phrase_grp_id;
char language [ 2];
int sort;
char value [256];
char remark [2001];
} h_phrase;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
strcpy (h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/*
*get new GROUP-ID and set cre_date and sess_date = CURRENT_TIMESTAMP
*/
errln = 10;
EXEC SQL SELECT NEXTVAL('PHRASE_SEQ')
INTO :h_phrase.phrase_id;
/*
* copy passed record into host variable except for phrase_id
*/
h_phrase.phrase_grp_id = vp_phrase->phrase_grp_id;
strcpy(h_phrase.language, vp_phrase->language);
h_phrase.sort = vp_phrase->sort;
strcpy(h_phrase.value , vp_phrase->value);
strcpy(h_phrase.remark , vp_phrase->remark);
/* Insert passed record */
errln = 20;
EXEC SQL INSERT INTO PHRASE_TAB (PHRASE_ID,
PHRASE_GRP_ID,
LANGUAGE,
SORT,
VALUE_PT,
REMARK)
VALUES (:h_phrase.phrase_id,
:h_phrase.phrase_grp_id,
:h_phrase.language,
:h_phrase.sort,
:h_phrase.value,
:h_phrase.remark);
/* set return value (created PHRASE_ID) into passed struct/record */
vp_phrase->phrase_id = h_phrase.phrase_id;
/* record successfully inserted */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_update_phrase (PHRASE_TAB)
*
* Issue : 02-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Update record (specified by PHRASE_ID) in PHRASE_TAB
* by data of passed record.
*
* Parameter: vp_user (i) new phrase, containing PHRASE_ID of
* record to update.
* vp_errinfo (o) error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Update record (specified by PHRASE_ID) in PHRASE_TAB by data of passed record.
Output:
vp_errinfo - Error info in case of error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 02-OCT-2002
\param db_con Pointer to connection
\param vp_phrase new phrase, containing PHRASE_ID of record to update
\return DA_SUCCESS \n DA_FAIL
*/
int gda_update_phrase (DB_con *db_con,
DA_T_phrase vp_phrase,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_update_phrase";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_phrase_id;
char h_con_name [ 31];
struct DA_T_phrase_pg_h{ /* type contains host variables for object data */
long phrase_id;
long phrase_grp_id;
char language [ 2];
int sort;
char value [256];
char remark [2001];
} h_phrase;
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
/*
* copy passed record into host variable
*/
h_phrase_id = vp_phrase.phrase_id;
h_phrase.phrase_id = vp_phrase.phrase_id;
h_phrase.phrase_grp_id = vp_phrase.phrase_grp_id;
strcpy(h_phrase.language, vp_phrase.language);
h_phrase.sort = vp_phrase.sort;
strcpy(h_phrase.value , vp_phrase.value);
strcpy(h_phrase.remark , vp_phrase.remark);
strcpy (h_con_name , db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* Update passed record in database */
errln = 10;
EXEC SQL UPDATE PHRASE_TAB
SET PHRASE_ID = :h_phrase.phrase_id,
PHRASE_GRP_ID = :h_phrase.phrase_grp_id,
LANGUAGE = :h_phrase.language,
VALUE_PT = :h_phrase.value,
REMARK = :h_phrase.remark
WHERE PHRASE_ID = :h_phrase_id;
/* record successfully updated */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}
/*********************************************************************
* Name : gda_delete_phrase (PHRASE_TAB)
*
* Issue : 02-OCT-2002 - T.L. - TechniData AG/Markdorf
*
* Purpose : Delete record from PHRASE_TAB specified by "phrase_id"
*
* Parameter: vp_phrase_id (i) GROUP_ID of record to delete
* vp_errinfo (o) Error information in case error occured
*
* Return : success => DA_SUCCESS
* fail => DA_FAIL
*
* Globals : errln
*
* Changes :
* [DD-MON-YYYY] - [ Name ] - [ Action ]
*********************************************************************/
/*! \brief Delete record from PHRASE_TAB specified by "phrase_id".
Output:
vp_errinfo - Error info in case of error occured
\author T.L. - TechniData AG/Markdorf \n H.K. - Intevation
\date 02-OCT-2002
\param db_con Pointer to connection
\param vp_phrase_id GROUP_ID of record to delete
\return DA_SUCCESS \n DA_FAIL
*/
int gda_delete_phrase (DB_con *db_con,
long vp_phrase_id,
DA_T_errinfo *vp_errinfo)
{
DA_T_MODULE_NAME v_module = "gda_delete_phrase";
int v_status = DA_SUCCESS;
EXEC SQL BEGIN DECLARE SECTION;
/* host variables */
long h_phrase_id;
char h_con_name[31];
EXEC SQL END DECLARE SECTION;
/* ------------------ *
* Start of function
* ------------------ */
#if DEBUG_MODE_ON == 1
/* debug output */
lgda_write_debug_info(1, v_module, NULL, NULL, NULL, NULL, NULL, NULL);
#endif
errln = 0;
EXEC SQL WHENEVER SQLERROR GOTO error;
EXEC SQL WHENEVER NOT FOUND GOTO error;
h_phrase_id = vp_phrase_id;
strcpy(h_con_name, db_con->con_name);
EXEC SQL SET CONNECTION TO :h_con_name;
/* delete specified phrase */
errln = 10;
EXEC SQL DELETE FROM PHRASE_TAB
WHERE phrase_ID = :h_phrase_id;
/* record successfully deleted */
return(v_status);
error:
/* set error information into return parameter */
lgda_set_db_errinfo( v_module, vp_errinfo);
gda_db_rollback(db_con, vp_errinfo);
return(DA_FAIL);
}