/*****************************************************************
*
* filename: chg_acd_office.pc
*
* purpose: changes ofc_short_name in acd_groups
*
* usage info: chg_acd_office -f <full name>
* -o
<new office>
* -i
interactive mode.
*
* where: <full
name> REQUIRED.
* is a string that will find a
* match in ACD_GROUPS FULL_NAME
*
* <new
office> REQUIRED.
* is a 6 character string that will
be the
* new
OFC_SHORT_NAME in ACD_GROUPS.
*
* -i
prompts for confirmation before
* performing the update.
*
******************************************************************
* history
* -------
*
* when what who
* ---- ---- ---
* 06-Mar-1998 v1.0
- started JJM
*
******************************************************************/
#include <stdio.h>
#include <time.h>
#include <string.h>
EXEC
SQL INCLUDE SQLCA;
EXEC
SQL INCLUDE ORACA;
#define VERSION "v1.0"
#define NODATA 1403
int major_counter; /* general purpose int's */
int minor_counter;
int status; /* generic status */
int target_set = 0; /* set if -f arg given */
int new_set
= 0; /* set if -o arg given */
int interactive_set = 0; /* set if -i arg given */
char *msg_text[132]; /* bufer for messages */
char *real_name[132]; /* name of this
process */
time_t
*curtime; /* for time functions */
struct tm
*MyTime; /* time structure */
/* declare host and indicator varibles for SQLCA */
EXEC
SQL BEGIN DECLARE SECTION;
VARCHAR in_full_name[80];
VARCHAR
in_new_name[7];
VARCHAR
out_ofc_short_name[7];
VARCHAR
out_ent_sub_type_code[8];
VARCHAR
out_ent_name[7];
VARCHAR
out_name[7];
VARCHAR out_short_name[7];
char
ind_comm;
EXEC
SQL END DECLARE SECTION;
/***************** end global/preprocessing *********************/
Àpar
int main (argc,argv)
int
argc;
char
**argv;
{
/* annouce ourselves */
sprintf(msg_text,
"Starting %s\n", VERSION );
put_msg(msg_text, argv[0], 0 );
/* check args */
decode_arguments( argc, argv );
/* connect to oracle */
connect_to_oracle("/", " ");
/* find valid relationships */
get_acd_entity();
/* update acd_groups short_ofc_name */
update_acd_groups();
exit(0);
}
/******************* end of main
*********************************/
Àpar
/****************** update_acd_groups *****************************
*
* purpose: updates ACD_GROUPS OFC_SHORT_NAME from -o arg.
* Seeks
confirmation if -i arg given.
*
* arguments: command line arguments
in_full_name and in_new_name
* should
be validated from get_acd_entity();
*
* history:
*
* when what who
* ---- ---- ---
* 06-Mar-1998 started jjm
*
************************************************************************/
update_acd_groups()
{
int enable_update
= 0; /* zero to enable update sql */
char
key;
if(
interactive_set )
{
fprintf(stdout,"\nAbout to modify ACD_GROUP: %s %s
\n",
in_full_name.arr,
out_ofc_short_name.arr);
fprintf(stdout,"
TO: %s %s \n\n",
in_full_name.arr,
in_new_name.arr);
fprintf(stdout,"Is this OK (Y/N/D:N)? ");
key = fgetc(stdin);
key = toupper(key);
enable_update = key - 'Y';
}
if(
enable_update == 0 )
{
EXEC SQL WHENEVER
SQLERROR DO check_sql("update_acd_groups");
EXEC SQL UPDATE
acd_groups
SET
ofc_short_name = :in_new_name
WHERE full_name = :in_full_name;
EXEC SQL COMMIT;
}
/* show new relationships */
fprintf(stdout,"\n\nNew
relationship follows:\n");
get_acd_entity();
return(0);
}/***************** end of
update_acd_groups ***************************/
Àpar
/****************** get_acd_entity ***************************************
*
* purpose: steps up from ACD_GROUPS to ENTITIES walking along
* foriegn keys.
*
* arguments: Global in_full_name should be valid
from decode_arguments.
*
* notes: although
it is possible to transverse the relationships
* in one short query, I wanted to know the specific point
* where query returned no data in order to provide
* more specific debug verbage.
* history:
*
* when what who
* ---- ---- ---
* Mar 1998 started jjm
*
*************************************************************************/
int
get_acd_entity()
{
int has_office = 1; /* cleared if acd group has no
office
*/
int oentity = 1; /* cleared if acd group has no office entity */
int entity =
1; /* cleared if acd group has no entity */
/* init string arrays */
memset(
out_ofc_short_name.arr,
'\0', out_ofc_short_name.len );
memset(
out_ent_sub_type_code.arr, '\0', out_ent_sub_type_code.len );
memset(
out_ent_name.arr,
'\0', out_ent_name.len );
memset(
out_short_name.arr,
'\0', out_short_name.len );
memset(
out_name.arr,
'\0', out_name.len);
EXEC
SQL WHENEVER SQLERROR DO check_sql("get_acd_entity");
/* get the ACD group */
EXEC SQL
select
distinct nvl( rtrim(ofc_short_name), ' ' )
into
:out_ofc_short_name
from
acd_groups
where
full_name = :in_full_name;
if(
sqlca.sqlcode == NODATA )
{
sprintf(msg_text,
"can't find %s in ACD_GROUPS\n",
in_full_name.arr);
put_msg(msg_text,"get_acd_entity",0);
exit(-2);
}
Àpar
/* get the office */
EXEC SQL
select
distinct nvl( rtrim(short_name),'NULL'),
nvl(
rtrim(ent_sub_type_code),'NULL')
into :out_short_name,
:out_ent_sub_type_code
from
offices
where
short_name = :out_ofc_short_name;
if(
sqlca.sqlcode == NODATA )
{
has_office = 0;
sprintf(msg_text,
"%s%s's assigned
office (%s) has no link to OFFICES.\n",
"WARNING: ",
in_full_name.arr,
out_ofc_short_name.arr);
put_msg(msg_text,"get_acd_entity",0);
}
/* get the office entity if
ACD_GROUPS-OFFICES linked */
else
{
EXEC
SQL
select distinct nvl( rtrim(ent_name),'NULL')
into :out_ent_name
from office_entities
where ofc_short_name = :out_short_name
and ent_sub_type_code = :out_ent_sub_type_code;
if(
sqlca.sqlcode == NODATA )
{
oentity = 0;
entity =
0; /* w/o an oentity then no entity */
sprintf(msg_text,
"%s%s's assigned
office (%-6.6s) has no office entity\n",
"WARNING: ",
in_full_name.arr,
out_short_name.arr);
put_msg(msg_text,"get_acd_entity",0);
}
else
{
/* get the entity type */
EXEC SQL
select distinct nvl(
rtrim(sub_type_code),'NULL')
into :out_ent_sub_type_code
from entities
where name = :out_ent_name;
if(
sqlca.sqlcode == NODATA )
{
entity = 0;