Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Orasta500.c

303 views

Published on

  • Be the first to comment

  • Be the first to like this

Orasta500.c

  1. 1. orasta500.c/* Result Sets Interface */#ifndef SQL_CRSR# define SQL_CRSR struct sql_cursor { unsigned int curocn; void *ptr1; void *ptr2; unsigned int magic; }; typedef struct sql_cursor sql_cursor; typedef struct sql_cursor SQL_CURSOR;#endif /* SQL_CRSR *//* Thread Safety */typedef void * sql_context;typedef void * SQL_CONTEXT;/* Object support */struct sqltvn{ unsigned char *tvnvsn; unsigned short tvnvsnl; unsigned char *tvnnm; unsigned short tvnnml; unsigned char *tvnsnm; unsigned short tvnsnml;};typedef struct sqltvn sqltvn;struct sqladts{ unsigned int adtvsn; unsigned short adtmode; unsigned short adtnum; sqltvn adttvn[1];};typedef struct sqladts sqladts;static struct sqladts sqladt = { 1,0,0,};/* Binding to PL/SQL Records */struct sqltdss{ unsigned int tdsvsn; unsigned short tdsnum; unsigned char *tdsval[1];};typedef struct sqltdss sqltdss;static struct sqltdss sqltds ={ 1, 0,};/* File name & Package Name */struct sqlcxp{ unsigned short fillen; char filnam[13];};static const struct sqlcxp sqlfpn ={ 12, "orasta500.pc" Página 1
  2. 2. orasta500.c};static unsigned int sqlctx = 318459;static struct sqlexd { unsigned int sqlvsn; unsigned int arrsiz; unsigned int iters; unsigned int offset; unsigned short selerr; unsigned short sqlety; unsigned int occurs; const short *cud; unsigned char *sqlest; const char *stmt; sqladts *sqladtp; sqltdss *sqltdsp; void **sqphsv; unsigned int *sqphsl; int *sqphss; void **sqpind; int *sqpins; unsigned int *sqparm; unsigned int **sqparc; unsigned short *sqpadto; unsigned short *sqptdso; unsigned int sqlcmax; unsigned int sqlcmin; unsigned int sqlcincr; unsigned int sqlctimeout; unsigned int sqlcnowait; int sqfoff; unsigned int sqcmod; unsigned int sqfmod; void *sqhstv[5]; unsigned int sqhstl[5]; int sqhsts[5]; void *sqindv[5]; int sqinds[5]; unsigned int sqharm[5]; unsigned int *sqharc[5]; unsigned short sqadto[5]; unsigned short sqtdso[5];} sqlstm = {12,5};/* SQLLIB Prototypes */extern void sqlcxt (void **, unsigned int *, struct sqlexd *, const struct sqlcxp *);extern void sqlcx2t(void **, unsigned int *, struct sqlexd *, const struct sqlcxp *);extern void sqlbuft(void **, char *);extern void sqlgs2t(void **, char *);extern void sqlorat(void **, unsigned int *, void *);/* Forms Interface */static const int IAPSUCC = 0;static const int IAPFAIL = 1403;static const int IAPFTL = 535;extern void sqliem(char *, int *);typedef struct { unsigned short len; unsigned char arr[1]; } VARCHAR;typedef struct { unsigned short len; unsigned char arr[1]; } varchar;/* cud (compilation unit data) array */static const short sqlcud0[] ={12,4242,178,1,0, Página 2
  3. 3. orasta500.c5,0,0,1,0,0,273,146,0,0,1,1,0,1,0,1,5,0,0,24,0,0,1,0,0,267,157,0,0,1,1,0,1,0,1,32,0,0,43,0,0,1,0,0,271,188,0,0,0,0,0,1,0,58,0,0,2,0,0,286,189,0,0,0,0,0,1,0,73,0,0,3,0,0,283,210,0,0,4,4,0,1,0,1,9,0,0,1,10,0,0,1,10,0,0,1,10,0,0,104,0,0,4,0,0,1307,259,0,0,4,4,0,0,128,1,9,0,0,1,9,0,0,1,9,0,0,1,10,0,0,1,9,0,0,139,0,0,1,0,0,275,314,0,0,1,1,0,1,0,3,32,0,0,158,0,0,1,0,0,276,362,0,0,1,1,0,1,0,3,32,0,0,177,0,0,1,0,0,270,394,0,0,1,0,0,1,0,2,32,0,0,196,0,0,5,0,0,287,466,0,0,0,0,0,1,0,211,0,0,6,83,0,1284,491,0,0,1,0,0,0,128,2,9,0,0,1,9,0,0,234,0,0,7,71,0,1284,548,0,0,1,0,0,0,128,2,9,0,0,1,9,0,0,257,0,0,8,78,0,1284,580,0,0,2,1,0,0,128,2,9,0,0,1,9,0,0,1,9,0,0,284,0,0,9,57,0,1284,614,0,0,2,1,0,0,128,2,9,0,0,1,97,0,0,1,9,0,0,311,0,0,10,98,0,1284,662,0,0,2,1,0,0,128,2,9,0,0,1,3,0,0,1,9,0,0,338,0,0,11,75,0,1284,708,0,0,2,1,0,0,128,2,9,0,0,1,3,0,0,1,9,0,0,};/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/#include <oraca.h>#include <sqlca.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <setjmp.h>#include "constant_definition.h"#include "case_constant_func_def.h"#include "case_constant_sql_stmt_def.h"#include "constant_oracle_versions.h"#include "extern_functions_orastat_principal.h"#include "local_functions_preceded_calls.h"#include "extern_functions_funciones_auxiliares.h"#ifndef NULL#define NULL 0#endif/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/ char *dml_commands[] = {"SELECT", "select", "INSERT", "insert","UPDATE","update", "DELETE", "delete"}; char dyn_size [MAX_VAR_SIZE]; char dyn_title [MAX_VAR_SIZE]; char dyn_column [MAX_VAR_SIZE]; char dyn_proc_func [MAX_VAR_SIZE]; /* EXEC SQL BEGIN DECLARE SECTION; */ Página 3
  4. 4. orasta500.c /* VARCHAR nomb_001 [256]; */struct { unsigned short len; unsigned char arr[256]; } nomb_001; /* VARCHAR nomb_002 [256]; */struct { unsigned short len; unsigned char arr[256]; } nomb_002; char dyn_sts[16384]; /* EXEC SQL VAR dyn_sts IS STRING(16384); */ /* EXEC SQL END DECLARE SECTION; *//* EXEC SQL INCLUDE sqlca; *//* * $Header: sqlca.h,v 1.3 1994/12/12 19:27:27 jbasu Exp $ sqlca.h *//* Copyright (c) 1985,1986, 1998 by Oracle Corporation. *//*NAME SQLCA : SQL Communications Area.FUNCTION Contains no code. Oracle fills in the SQLCA with status info during the execution of a SQL stmt.NOTES ************************************************************** *** *** *** This file is SOSD. Porters must change the data types *** *** appropriately on their platform. See notes/pcport.doc *** *** for more information. *** *** *** ************************************************************** If the symbol SQLCA_STORAGE_CLASS is defined, then the SQLCA will be defined to have this storage class. For example: #define SQLCA_STORAGE_CLASS extern will define the SQLCA as an extern. If the symbol SQLCA_INIT is defined, then the SQLCA will be statically initialized. Although this is not necessary in order to use the SQLCA, it is a good pgming practice not to have unitialized variables. However, some C compilers/OSs dont allow automatic variables to be initd in this manner. Therefore, if you are INCLUDEing the SQLCA in a place where it would be an automatic AND your C compiler/OS doesnt allow this style of initialization, then SQLCA_INIT should be left undefined -- all others can define SQLCA_INIT if they wish. If the symbol SQLCA_NONE is defined, then the SQLCA variable will not be defined at all. The symbol SQLCA_NONE should not be defined in source modules that have embedded SQL. However, source modules that have no embedded SQL, but need to manipulate a sqlca struct passed in as a parameter, can set the SQLCA_NONE symbol to avoid creation of an extraneous sqlca variable.MODIFIED lvbcheng 07/31/98 - long to int jbasu 12/12/94 - Bug 217878: note this is an SOSD file losborne 08/11/92 - No sqlca var if SQLCA_NONE macro set Clare 12/06/84 - Ch SQLCA to not be an extern. Clare 10/21/85 - Add initialization. Bradbury 01/05/86 - Only initialize when SQLCA_INIT set Clare 06/12/86 - Add SQLCA_STORAGE_CLASS option. Página 4
  5. 5. orasta500.c*/#ifndef SQLCA#define SQLCA 1struct sqlca { /* ub1 */ char sqlcaid[8]; /* b4 */ int sqlabc; /* b4 */ int sqlcode; struct { /* ub2 */ unsigned short sqlerrml; /* ub1 */ char sqlerrmc[70]; } sqlerrm; /* ub1 */ char sqlerrp[8]; /* b4 */ int sqlerrd[6]; /* ub1 */ char sqlwarn[8]; /* ub1 */ char sqlext[8]; };#ifndef SQLCA_NONE#ifdef SQLCA_STORAGE_CLASSSQLCA_STORAGE_CLASS struct sqlca sqlca#else struct sqlca sqlca#endif#ifdef SQLCA_INIT = { {S, Q, L, C, A, , , }, sizeof(struct sqlca), 0, { 0, {0}}, {N, O, T, , S, E, T, }, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0} }#endif ;#endif#endif/* end SQLCA *//* EXEC SQL INCLUDE sqlda; *//* * $Header: sqlda.h 31-jul-99.19:34:41 apopat Exp $ sqlda.h *//**************************************************************** The SQLDA descriptor definition **--------------------------------------------------------------** VAX/3B Version ** ** Copyright (c) 1987, 1997, 1998, 1999 by Oracle Corporation****************************************************************//* NOTES ************************************************************** *** *** *** This file is SOSD. Porters must change the data types *** *** appropriately on their platform. See notes/pcport.doc *** *** for more information. *** Página 5
  6. 6. orasta500.c *** *** ***************************************************************//* MODIFIED apopat 07/31/99 - [707588] TAB to blanks for OCCS lvbcheng 10/27/98 - change long to int for sqlda lvbcheng 08/15/97 - Move sqlda protos to sqlcpr.h lvbcheng 06/25/97 - Move sqlda protos to this file jbasu 01/29/95 - correct typo jbasu 01/27/95 - correct comment - ub2->sb2 jbasu 12/12/94 - Bug 217878: note this is an SOSD file Morse 12/01/87 - undef L and S for v6 include files Richey 07/13/87 - change int defs to long Clare 09/13/84 - Port: Ch types to match SQLLIB structs Clare 10/02/86 - Add ifndef SQLDA*/#ifndef SQLDA_#define SQLDA_ 1#ifdef T# undef T#endif#ifdef F# undef F#endif#ifdef S# undef S#endif#ifdef L# undef L#endifstruct SQLDA { /* ub4 */ int N; /* Descriptor size in number of entries */ /* text** */ char **V; /* Ptr to Arr of addresses of main variables */ /* ub4* */ int *L; /* Ptr to Arr of lengths of buffers */ /* sb2* */ short *T; /* Ptr to Arr of types of buffers */ /* sb2** */ short **I; /* Ptr to Arr of addresses of indicator vars */ /* sb4 */ int F; /* Number of variables found by DESCRIBE */ /* text** */ char **S; /* Ptr to Arr of variable name pointers */ /* ub2* */ short *M; /* Ptr to Arr of max lengths of var. names */ /* ub2* */ short *C; /* Ptr to Arr of current lengths of var. names */ /* text** */ char **X; /* Ptr to Arr of ind. var. name pointers */ /* ub2* */ short *Y; /* Ptr to Arr of max lengths of ind. var. names */ /* ub2* */ short *Z; /* Ptr to Arr of cur lengths of ind. var. names */ };typedef struct SQLDA SQLDA;#endif/* ----------------- *//* defines for sqlda *//* ----------------- */#define SQLSQLDAAlloc(arg1, arg2, arg3, arg4) sqlaldt(arg1, arg2, arg3, arg4)#define SQLSQLDAFree(arg1, arg2) sqlclut(arg1, arg2) SQLDA *bind_dp; SQLDA *select_dp; Página 6
  7. 7. orasta500.c jmp_buf jmp_continue; int parse_flag = 0; extern SQLDA *sqlald(); extern void sqlnul();/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/main( int argc , char *argv[]) { int i=0; int nro_loop=0; int opcion_nro=0; int version=0; char opcion_uno [MAX_LEN_ARG]; char opcion_dos [MAX_LEN_ARG]; char opcion_tres [MAX_LEN_ARG]; char opcion_cuatro [MAX_LEN_ARG]; char datos_conexion [MAX_LEN_CONNECT]; char username [MAX_LEN_CONNECT]; char password [MAX_LEN_CONNECT]; char conexion [MAX_LEN_CONNECT]; opcion_uno[0]=ASCII_FIN_LINEA; opcion_dos[0]=ASCII_FIN_LINEA; opcion_tres[0]=ASCII_FIN_LINEA; opcion_cuatro[0]=ASCII_FIN_LINEA; datos_conexion[0]=ASCII_FIN_LINEA; if (argc <3 ) { printf ("Insuficientes argumentos n"); exit (1); } strcpy (datos_conexion,argv[1]); strcpy (nomb_001.arr,"CONEX002"); nomb_001.arr[strlen((char *) nomb_001.arr)] = ASCII_FIN_LINEA; nomb_001.len = (unsigned short )strlen((char *) nomb_001.arr); vaciar_cadena (username,MAX_LEN_CONNECT); vaciar_cadena (password,MAX_LEN_CONNECT); vaciar_cadena (conexion,MAX_LEN_CONNECT); strcpy (username,separar_dato (datos_conexion,USERNAME)); strcpy (password,separar_dato (datos_conexion,PASSWORD)); strcpy (conexion,separar_dato (datos_conexion,CONEXION));/* printf ("User [%s] - Pass [%s] - Cone [%s] - DbAl [%s]n",username,password,conexion,nomb_001.arr); Página 7
  8. 8. orasta500.c*/ if (argc >= 3 ) opcion_nro=atoi(argv[2]); if (argc >= 4 ) strcpy (opcion_uno,pasar_amayus(argv[3])); if (argc >= 5 ) strcpy (opcion_dos,pasar_amayus(argv[4])); if (argc >= 6 ) strcpy (opcion_tres,pasar_amayus(argv[5])); if (argc >= 7 ) strcpy (opcion_cuatro,pasar_amayus(argv[6]));/* ********************************************************* *//* ********************************************************* */ if (oracle_connect_original(datos_conexion) != 0) { /* printf ("No es posible conectarse ...n"); */ exit(1); } else printf ("[ Connected Default Link ...");/* ********************************************************* *//* ********************************************************* */ if (oracle_connect_new(datos_conexion,username,password,conexion,nomb_001.arr) != 0) { /* printf ("No es posible conectarse ...n"); */ exit(1); } else printf (" Connected Non-Default link ].n");/* ********************************************************* */ version = version_oracle(); printf ("[ Oracle Version < %d > ]nn",version); if (alloc_descriptors(MAX_ITEMS,MAX_VNAME_LEN, MAX_INAME_LEN) != 0)exit(1); i = setjmp(jmp_continue);/* printf ("Opcion elegida [%d] n",opcion_nro); */ if ( opcion_nro >= 0 && opcion_nro <= MAX_NRO_OPCION ) {/* --------------------------------------------------------------------- */ cargar_sentencia (version, opcion_nro, opcion_uno, opcion_dos,opcion_tres,opcion_cuatro); /* EXEC SQL WHENEVER SQLERROR DO sql_error(); */ parse_flag = 1; /* EXEC SQL PREPARE S FROM :dyn_sts; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 1; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.stmt = ""; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )5; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)dyn_sts; sqlstm.sqhstl[0] = (unsigned int )16384; sqlstm.sqhsts[0] = ( int )0; sqlstm.sqindv[0] = ( void *)0; sqlstm.sqinds[0] = ( int )0; Página 8
  9. 9. orasta500.c sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode < 0) sql_error();} parse_flag = 0; /* EXEC SQL DECLARE C CURSOR FOR S; */ set_bind_variables(); /* ********** INICIAR LOOP PARA CORRER LA MISMA OPCION ********** */ for ( nro_loop =0; nro_loop < 10000; nro_loop++) { printf ("Procesando Consulta Nro [%d] n",nro_loop); /* EXEC SQL OPEN C USING DESCRIPTOR bind_dp; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 1; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.stmt = ""; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )24; sqlstm.selerr = (unsigned short)1; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqcmod = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)bind_dp; sqlstm.sqhstl[0] = (unsigned int )0; sqlstm.sqhsts[0] = ( int )0; sqlstm.sqindv[0] = ( void *)0; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode < 0) sql_error();} Página 9
  10. 10. orasta500.c process_select_list(); esperar_seg (10); } /* ************************************************************** *//* --------------------------------------------------------------------- */ } liberar_memoria(); func_menu_mostrar (version,opcion_nro); return NO_ERROR; }/*----****----****----****----****----****----****----****----****----****----*****/liberar_memoria () { int i; for (i = 0; i < MAX_ITEMS; i++) { if (bind_dp->V[i] != (char *) 0) free(bind_dp->V[i]); free(bind_dp->I[i]); if (select_dp->V[i] != (char *) 0) free(select_dp->V[i]); free(select_dp->I[i]); } /* EXEC SQL WHENEVER SQLERROR CONTINUE; */ /* EXEC SQL CLOSE C; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 1; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )43; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);} /* EXEC SQL COMMIT WORK RELEASE; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 1; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )58; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); Página 10
  11. 11. orasta500.c} /* EXEC SQL WHENEVER SQLERROR DO sql_error(); */ return SI_ERROR; }/*----****----****----****----****----****----****----****----****----****----*****/oracle_connect_original ( char *datos_conexion ) { /* EXEC SQL BEGIN DECLARE SECTION; */ /* VARCHAR connectstring[256]; */struct { unsigned short len; unsigned char arr[256]; } connectstring; /* EXEC SQL END DECLARE SECTION; */ strcpy ((char *) connectstring.arr,datos_conexion); connectstring.arr[strlen((char *) connectstring.arr)] = ASCII_FIN_LINEA; connectstring.len = (unsigned short )strlen((char *) connectstring.arr); /* EXEC SQL WHENEVER SQLERROR GOTO connect_error; */ /* printf ("nConnecting .....n"); */ /* EXEC SQL CONNECT :connectstring; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 4; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.iters = (unsigned int )10; sqlstm.offset = (unsigned int )73; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)&connectstring; sqlstm.sqhstl[0] = (unsigned int )258; sqlstm.sqhsts[0] = ( int )258; sqlstm.sqindv[0] = ( void *)0; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlstm.sqlcmax = (unsigned int )100; sqlstm.sqlcmin = (unsigned int )2; sqlstm.sqlcincr = (unsigned int )1; sqlstm.sqlctimeout = (unsigned int )0; sqlstm.sqlcnowait = (unsigned int )0; Página 11
  12. 12. orasta500.c sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode < 0) goto connect_error;} /* printf("nConnected to ORACLE n"); */ return 0; connect_error: fprintf(stderr,"Cannot Connect Default Link.n"); return -1; }/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/oracle_connect_new ( char *datos_conexion, char *user_name, char *pass_word,char *net_conexion, char *aliasdb) { /* EXEC SQL BEGIN DECLARE SECTION; */ /* VARCHAR username[256]; */struct { unsigned short len; unsigned char arr[256]; } username; /* VARCHAR password[256]; */struct { unsigned short len; unsigned char arr[256]; } password; /* VARCHAR connectstring[256]; */struct { unsigned short len; unsigned char arr[256]; } connectstring; /* VARCHAR db_net_connect[256]; */struct { unsigned short len; unsigned char arr[256]; } db_net_connect; /* VARCHAR db_alias_name[256]; */struct { unsigned short len; unsigned char arr[256]; } db_alias_name; /* EXEC SQL END DECLARE SECTION; */ strcpy ((char *) connectstring.arr,datos_conexion); connectstring.arr[strlen((char *) connectstring.arr)] = ASCII_FIN_LINEA; connectstring.len = (unsigned short )strlen((char *) connectstring.arr); strcpy ((char *) username.arr,user_name); username.arr[strlen((char *) username.arr)] = ASCII_FIN_LINEA; username.len = (unsigned short )strlen((char *) username.arr); strcpy ((char *) password.arr,pass_word); password.arr[strlen((char *) password.arr)] = ASCII_FIN_LINEA; password.len = (unsigned short )strlen((char *) password.arr); strcpy ((char *) db_net_connect.arr,net_conexion); db_net_connect.arr[strlen((char *) db_net_connect.arr)] =ASCII_FIN_LINEA; db_net_connect.len = (unsigned short )strlen((char *)db_net_connect.arr); strcpy ((char *) db_alias_name.arr,aliasdb); Página 12
  13. 13. orasta500.c db_alias_name.arr[strlen((char *) db_alias_name.arr)] = ASCII_FIN_LINEA; db_alias_name.len = (unsigned short )strlen((char *) db_alias_name.arr); /* EXEC SQL WHENEVER SQLERROR GOTO connect_error; *//* printf ("nConnecting .....n"); *//* printf ("User [%s] - Pass [%s] - Cone [%s] - Nomb [%s]n",username.arr,password.arr,db_net_connect.arr,db_alias_name.arr);*/ /* EXEC SQL CONNECT :username IDENTIFIED BY :password AT :db_alias_nameUSING :db_net_connect; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 5; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.iters = (unsigned int )10; sqlstm.offset = (unsigned int )104; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)&username; sqlstm.sqhstl[0] = (unsigned int )258; sqlstm.sqhsts[0] = ( int )258; sqlstm.sqindv[0] = ( void *)0; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqhstv[1] = ( void *)&password; sqlstm.sqhstl[1] = (unsigned int )258; sqlstm.sqhsts[1] = ( int )258; sqlstm.sqindv[1] = ( void *)0; sqlstm.sqinds[1] = ( int )0; sqlstm.sqharm[1] = (unsigned int )0; sqlstm.sqadto[1] = (unsigned short )0; sqlstm.sqtdso[1] = (unsigned short )0; sqlstm.sqhstv[2] = ( void *)&db_net_connect; sqlstm.sqhstl[2] = (unsigned int )258; sqlstm.sqhsts[2] = ( int )258; sqlstm.sqindv[2] = ( void *)0; sqlstm.sqinds[2] = ( int )0; sqlstm.sqharm[2] = (unsigned int )0; sqlstm.sqadto[2] = (unsigned short )0; sqlstm.sqtdso[2] = (unsigned short )0; sqlstm.sqhstv[4] = ( void *)&db_alias_name; sqlstm.sqhstl[4] = (unsigned int )258; sqlstm.sqhsts[4] = ( int )258; sqlstm.sqindv[4] = ( void *)0; sqlstm.sqinds[4] = ( int )0; sqlstm.sqharm[4] = (unsigned int )0; sqlstm.sqadto[4] = (unsigned short )0; sqlstm.sqtdso[4] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlstm.sqlcmax = (unsigned int )100; Página 13
  14. 14. orasta500.c sqlstm.sqlcmin = (unsigned int )2; sqlstm.sqlcincr = (unsigned int )1; sqlstm.sqlctimeout = (unsigned int )0; sqlstm.sqlcnowait = (unsigned int )0; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode < 0) goto connect_error;}/* printf("nConnected to ORACLE n"); */ return 0; connect_error: fprintf(stderr,"Cannot Connect Non-Default Link n"); return -1; }/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/alloc_descriptors(size, max_vname_len, max_iname_len) int size; int max_vname_len; int max_iname_len; { int i; if ((bind_dp = sqlald(size, max_vname_len, max_iname_len)) == (SQLDA *)0) { fprintf(stderr,"Insuficient memory..."); return -1; } if ((select_dp = sqlald (size, max_vname_len, max_iname_len)) == (SQLDA*) 0) { fprintf(stderr,"Insuficient memory..."); return -1; } select_dp->N = MAX_ITEMS; for (i = 0; i < MAX_ITEMS; i++) { bind_dp->I[i] = (short *) malloc(sizeof (short)); select_dp->I[i] = (short *) malloc(sizeof(short)); bind_dp->V[i] = (char *) malloc(1); select_dp->V[i] = (char *) malloc(1); } return 0; }/*----****----****----****----****----****----****----****----****----****----*****/set_bind_variables() Página 14
  15. 15. orasta500.c { int i, n; char bind_var [MAX_BIND_VARIABLE]; /* EXEC SQL WHENEVER SQLERROR DO sql_error(); */ bind_dp->N = MAX_ITEMS; /* EXEC SQL DESCRIBE BIND VARIABLES FOR S INTO bind_dp; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 5; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )139; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)bind_dp; sqlstm.sqhstl[0] = (unsigned int )0; sqlstm.sqhsts[0] = ( int )0; sqlstm.sqindv[0] = ( void *)0; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode < 0) sql_error();} if (bind_dp->F < 0) { printf ("nToo many variables to bind...n", -bind_dp->F,MAX_ITEMS); return SI_ERROR; } bind_dp->N = bind_dp->F; for (i = 0; i < bind_dp->F; i++) { printf ("nEnter value for bind variable %.*s:",(int)bind_dp->C[i], bind_dp->S[i]); fgets (bind_var, (int )sizeof(bind_var), stdin); n = (int )strlen(bind_var) - 1; bind_dp->L[i] = n; bind_dp->V[i] = (char *) realloc(bind_dp->V[i], (bind_dp->L[i] +1)); strncpy(bind_dp->V[i], bind_var, n); if ((strncmp(bind_dp->V[i], "NULL", 4) == 0) ||(strncmp(bind_dp->V[i], "null", 4) == 0)) Página 15
  16. 16. orasta500.c *bind_dp->I[i] = -1; else *bind_dp->I[i] = 0; bind_dp->T[i] = 1; } return NO_ERROR; }/*----****----****----****----****----****----****----****----****----****----*****/process_select_list() { int null_ok; int nro_columna=0; int column_size=0; int si_proceso=0; int nro_bytes=0; int nro_funcion=0; char datos_auxi[MAX_LEN_DATOS_AUXI]; vaciar_cadena (datos_auxi,MAX_LEN_DATOS_AUXI); if ((strncmp(dyn_sts, "SELECT", 6) != 0) && (strncmp(dyn_sts, "select",6) != 0)) { select_dp->F = 0; return NO_ERROR; } select_dp->N = MAX_ITEMS; /* EXEC SQL DESCRIBE SELECT LIST FOR S INTO select_dp; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 5; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )158; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)select_dp; sqlstm.sqhstl[0] = (unsigned int )0; sqlstm.sqhsts[0] = ( int )0; sqlstm.sqindv[0] = ( void *)0; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode < 0) sql_error();} Página 16
  17. 17. orasta500.c if (select_dp->F < 0) { printf ("nToo many select-list items (%d), maximum is %dn",-(select_dp->F), MAX_ITEMS); return SI_ERROR; } select_dp->N = select_dp->F; printf ("[ < %s > ] n",dyn_title); for (nro_columna = 0; nro_columna < select_dp->F; nro_columna++) { sqlnul ( &(select_dp->T[nro_columna]),&(select_dp->T[nro_columna]), &null_ok); column_size=col_size(dyn_size,nro_columna); select_dp->L[nro_columna]= column_size; select_dp->C[nro_columna]= column_size; select_dp->T[nro_columna]=1; } for (nro_columna = 0; nro_columna < select_dp->F; nro_columna++) { select_dp->V[nro_columna] = (char *)realloc(select_dp->V[nro_columna], select_dp->L[nro_columna]); printf ("["); column_size=col_size(dyn_size,nro_columna); procesar_encabe (column_size,nro_columna,dyn_column); printf ("] "); } printf ("n"); /* EXEC SQL WHENEVER NOT FOUND GOTO end_select_loop; */ for ( ; ; ) { /* Asegurandome que la estructura de Retorno estetotalmente vacia */ vaciar_estructura ( select_dp ); /* Tomando una fila (ROW) de la base de datos */ /* EXEC SQL FETCH C USING DESCRIPTOR select_dp; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 5; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )177; sqlstm.selerr = (unsigned short)1; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqfoff = ( int )0; sqlstm.sqfmod = (unsigned int )2; sqlstm.sqhstv[0] = ( void *)select_dp; sqlstm.sqhstl[0] = (unsigned int )0; sqlstm.sqhsts[0] = ( int )0; sqlstm.sqindv[0] = ( void *)0; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; Página 17
  18. 18. orasta500.c sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode == 1403) goto end_select_loop; if (sqlca.sqlcode < 0) sql_error();} /* Procesando las "i" columnas de datos de la filaretornada */ for (nro_columna = 0; nro_columna < select_dp->F;nro_columna++) { printf (" "); /*----------------------------------------------------------------------------- */ column_size=col_size(dyn_size,nro_columna); /*----------------------------------------------------------------------------- */ si_proceso = procesar_columna_funcion(dyn_proc_func, nro_columna, &nro_funcion); if ( si_proceso == SI_PROCESAR) { vaciar_cadena(datos_auxi,strlen(datos_auxi)); strcpy (datos_auxi,funcion_columna(nro_bytes, (char *)select_dp->V[nro_columna], nro_funcion)); procesar_cadena(column_size,datos_auxi); } else { /*----------------------------------------------------------------------------- */ procesar_cadena (column_size,(char*)select_dp->V[nro_columna]); /*----------------------------------------------------------------------------- */ } printf (" "); } printf ("n"); } end_select_loop: return NO_ERROR; }/*----****----****----****----****----****----****----****----****----****----*****/cargar_sentencia (int version, int sentencia, char *opcion_uno, char *opcion_dos, char *opcion_tres , char*opcion_cuatro) { strcpy (dyn_column,func_dyn_column_set (version,sentencia)); strcpy (dyn_title,func_dyn_title_set (version,sentencia)); strcpy (dyn_sts,func_dyn_statement_set(version,sentencia,opcion_uno,opcion_dos,opcion_tres,opcion_cuatro)); strcpy (dyn_size,func_dyn_size_set (version,sentencia)); strcpy (dyn_proc_func, func_dyn_proc_func_set (version,sentencia)); /*----------------------------------------------------------------------------- */ Página 18
  19. 19. orasta500.c /* COMPROBACION DE LAS VARIABLES RETORNADAS EN LOS CASE */ /* SEGUN LA OPCION ELEGIDA Y LA VERSION DE ORACLE */ /*----------------------------------------------------------------------------- *//* printf ("Proc Func [%s] n",dyn_proc_func); printf ("Column Set [%s] n",dyn_column); printf ("Column Size[%s] n",dyn_size);*//* printf ("Statement n [n%s] n",dyn_sts);*/ if (strlen (dyn_sts) >= MAX_STMT) printf ("Max Statement large [%d] | Actual Statement large [%d]n",MAX_STMT,strlen(dyn_sts)); return NO_ERROR; }/*----****----****----****----****----****----****----****----****----****----*****/sql_error() { /* int i; */ printf ("nn%.70sn",sqlca.sqlerrm.sqlerrmc); if (parse_flag) printf("n Error de Oracle... n",sqlca.sqlerrd[4]); /* EXEC SQL WHENEVER SQLERROR CONTINUE; */ /* EXEC SQL ROLLBACK WORK; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 5; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )196; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);} liberar_memoria(); exit(1); }/*----****----****----****----****----****----****----****----****----****----*****//* ----****---- FUNCIONES A DEFINIR PARA PROCESAR LAS COLUMNAS RETORNADAS----**** *//*----****----****----****----****----****----****----****----****----****----*****/ Página 19
  20. 20. orasta500.cint version_oracle () { char Version[10]; int conta=0; int pos=0; int caracter=0; int nro_puntos=0; /* EXEC SQL BEGIN DECLARE SECTION; */ /* VARCHAR version [256]; */struct { unsigned short len; unsigned char arr[256]; } version; /* EXEC SQL END DECLARE SECTION; */ vaciar_cadena (version.arr,MAX_VERSION_LEN); for ( ; ; ) { /* EXEC SQL WHENEVER NOT FOUND DO break; */ /* EXEC SQL AT :nomb_001 SELECT ltrim(lpad(banner,70)) INTO :version FROM V$VERSION WHERE banner like %Oracle%; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 5; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.stmt = "select ltrim(lpad(banner,70)) into :b1 from V$VERSION where banner like %Oracle%"; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )211; sqlstm.selerr = (unsigned short)1; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)&version; sqlstm.sqhstl[0] = (unsigned int )258; sqlstm.sqhsts[0] = ( int )0; sqlstm.sqindv[0] = ( void *)0; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqhstv[1] = ( void *)&nomb_001; sqlstm.sqhstl[1] = (unsigned int )258; sqlstm.sqhsts[1] = ( int )0; sqlstm.sqindv[1] = ( void *)0; sqlstm.sqinds[1] = ( int )0; sqlstm.sqharm[1] = (unsigned int )0; sqlstm.sqadto[1] = (unsigned short )0; sqlstm.sqtdso[1] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; Página 20
  21. 21. orasta500.c sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode == 1403) break;} break; /* SOLO ME INTERESA UN REGISTRO */ } for ( pos =0; pos < version.len; pos ++) { caracter = version.arr[pos]; Version[conta]=ASCII_FIN_LINEA; if ( nro_puntos < 3 ) { switch (caracter) { case 48: case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: Version[conta]=caracter; conta++; Version[conta]=ASCII_FIN_LINEA; break; case 46: /* Version[conta]=caracter; conta++; */ nro_puntos++; Version[conta]=ASCII_FIN_LINEA; break; default: conta=0; } } } return (atoi (Version)); }/*----****----****----****----****----****----****----****----****----****----*****//* ----****---- FUNCIONES A DEFINIR PARA PROCESAR LAS COLUMNAS RETORNADAS----**** *//*----****----****----****----****----****----****----****----****----****----*****/int db_block_size () { int block_size=0; /* EXEC SQL BEGIN DECLARE SECTION; */ /* VARCHAR data_block_size [20]; */struct { unsigned short len; unsigned char arr[20]; } data_block_size; /* EXEC SQL END DECLARE SECTION; */ vaciar_cadena (data_block_size.arr,20); for ( ; ; ) { /* EXEC SQL WHENEVER NOT FOUND DO break; */ Página 21
  22. 22. orasta500.c /* EXEC SQL AT :nomb_001 SELECT value INTO :data_block_size FROM V$PARAMETER WHERE NAME IN (db_block_size); */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 5; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.stmt = "select value into :b1 from V$PARAMETER where NAME in (db_block_size)"; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )234; sqlstm.selerr = (unsigned short)1; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)&data_block_size; sqlstm.sqhstl[0] = (unsigned int )22; sqlstm.sqhsts[0] = ( int )0; sqlstm.sqindv[0] = ( void *)0; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqhstv[1] = ( void *)&nomb_001; sqlstm.sqhstl[1] = (unsigned int )258; sqlstm.sqhsts[1] = ( int )0; sqlstm.sqindv[1] = ( void *)0; sqlstm.sqinds[1] = ( int )0; sqlstm.sqharm[1] = (unsigned int )0; sqlstm.sqadto[1] = (unsigned short )0; sqlstm.sqtdso[1] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode == 1403) break;} break; /* SOLO ME INTERESA UN REGISTRO */ } block_size = atoi (data_block_size.arr); return (block_size); }/*----****----****----****----****----****----****----****----****----****----*****//* ----****---- FUNCIONES A DEFINIR PARA PROCESAR LAS COLUMNAS RETORNADAS----**** *//*----****----****----****----****----****----****----****----****----****----*****/int db_tablspace_ini_ext_size (void *punt_tbl_name) { Página 22
  23. 23. orasta500.c int ini_ext_size=0; /* EXEC SQL BEGIN DECLARE SECTION; */ /* VARCHAR data_ini_ext_size [20]; */struct { unsigned short len; unsigned char arr[20]; } data_ini_ext_size; /* VARCHAR tablespace_name[100]; */struct { unsigned short len; unsigned char arr[100]; } tablespace_name; /* EXEC SQL END DECLARE SECTION; */ vaciar_cadena (data_ini_ext_size.arr,20); vaciar_cadena (tablespace_name.arr,100); strcpy (tablespace_name.arr, (char *) punt_tbl_name); tablespace_name.len=(int )strlen ((char *) punt_tbl_name); for ( ; ; ) { /* EXEC SQL WHENEVER NOT FOUND DO break; */ /* EXEC SQL AT :nomb_001 SELECT INITIAL_EXTENT INTO :data_ini_ext_size FROM dba_tablespaces WHERE tablespace_name=:tablespace_name; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 5; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.stmt = "select INITIAL_EXTENT into :b1 from dba_tablespaces where tablespace_name=:b2"; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )257; sqlstm.selerr = (unsigned short)1; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)&data_ini_ext_size; sqlstm.sqhstl[0] = (unsigned int )22; sqlstm.sqhsts[0] = ( int )0; sqlstm.sqindv[0] = ( void *)0; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqhstv[1] = ( void *)&tablespace_name; sqlstm.sqhstl[1] = (unsigned int )102; sqlstm.sqhsts[1] = ( int )0; sqlstm.sqindv[1] = ( void *)0; sqlstm.sqinds[1] = ( int )0; sqlstm.sqharm[1] = (unsigned int )0; sqlstm.sqadto[1] = (unsigned short )0; sqlstm.sqtdso[1] = (unsigned short )0; sqlstm.sqhstv[2] = ( void *)&nomb_001; sqlstm.sqhstl[2] = (unsigned int )258; sqlstm.sqhsts[2] = ( int )0; sqlstm.sqindv[2] = ( void *)0; sqlstm.sqinds[2] = ( int )0; sqlstm.sqharm[2] = (unsigned int )0; sqlstm.sqadto[2] = (unsigned short )0; sqlstm.sqtdso[2] = (unsigned short )0; Página 23
  24. 24. orasta500.c sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode == 1403) break;} break; /* SOLO ME INTERESA UN REGISTRO */ } ini_ext_size = atoi (data_ini_ext_size.arr); return (ini_ext_size); }/*----****----****----****----****----****----****----****----****----****----*****//* ----****---- FUNCIONES A DEFINIR PARA PROCESAR LAS COLUMNAS RETORNADAS----**** *//*----****----****----****----****----****----****----****----****----****----*****/char *db_session_sid_locked (void *punt_kaddr) { static char dato_1[MAX_LEN_VARCHAR]; int pos; /* EXEC SQL BEGIN DECLARE SECTION; */ /* VARCHAR sid_ses[128]; */struct { unsigned short len; unsigned char arr[128]; } sid_ses; char kaddr[10]; short var_indic; /* EXEC SQL END DECLARE SECTION; */ vaciar_cadena (kaddr,10); vaciar_cadena (sid_ses.arr,128); vaciar_cadena (dato_1, MAX_LEN_VARCHAR); strcpy (kaddr,pasar_amayus( (char *) punt_kaddr) ); kaddr[(int)strlen((char *)punt_kaddr)]=ASCII_FIN_LINEA; for ( ; ; ) { /* EXEC SQL WHENEVER NOT FOUND DO break; */ /* EXEC SQL AT :nomb_001 SELECT sid INTO :sid_ses INDICATOR :var_indic FROM V$SESSION WHERE LOCKWAIT = :kaddr; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 5; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.stmt = "select sid into :b1:b2 from V$SESSION where LOCKWAIT=:b3"; sqlstm.iters = (unsigned int )1; Página 24
  25. 25. orasta500.c sqlstm.offset = (unsigned int )284; sqlstm.selerr = (unsigned short)1; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)&sid_ses; sqlstm.sqhstl[0] = (unsigned int )130; sqlstm.sqhsts[0] = ( int )0; sqlstm.sqindv[0] = ( void *)&var_indic; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqhstv[1] = ( void *)kaddr; sqlstm.sqhstl[1] = (unsigned int )10; sqlstm.sqhsts[1] = ( int )0; sqlstm.sqindv[1] = ( void *)0; sqlstm.sqinds[1] = ( int )0; sqlstm.sqharm[1] = (unsigned int )0; sqlstm.sqadto[1] = (unsigned short )0; sqlstm.sqtdso[1] = (unsigned short )0; sqlstm.sqhstv[2] = ( void *)&nomb_001; sqlstm.sqhstl[2] = (unsigned int )258; sqlstm.sqhsts[2] = ( int )0; sqlstm.sqindv[2] = ( void *)0; sqlstm.sqinds[2] = ( int )0; sqlstm.sqharm[2] = (unsigned int )0; sqlstm.sqadto[2] = (unsigned short )0; sqlstm.sqtdso[2] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode == 1403) break;} break; /* SOLO ME INTERESA UN REGISTRO */ }/* printf ("Dato [%s] n",sid_ses.arr);*/ if ( ( var_indic != 0 ) ) { for (pos=0; pos < 3 ; pos++) sid_ses.arr[pos]=ASCII_PUNTO; sid_ses.arr[pos]=ASCII_FIN_LINEA; } else if ( strlen (sid_ses.arr) == 0 ) { for (pos=0; pos < 3 ; pos++) sid_ses.arr[pos]=ASCII_PUNTO; sid_ses.arr[pos]=ASCII_FIN_LINEA; } strcpy (dato_1,sid_ses.arr); return (dato_1); }/*----****----****----****----****----****----****----****----****----****----**** Página 25
  26. 26. orasta500.c*//* ----****---- FUNCIONES A DEFINIR PARA PROCESAR LAS COLUMNAS RETORNADAS----**** *//*----****----****----****----****----****----****----****----****----****----*****/char *db_object_owner_name (long objeto_id) { int block_size=0; int pos=0; static char dato_1[MAX_LEN_VARCHAR]; /* EXEC SQL BEGIN DECLARE SECTION; */ /* VARCHAR objeto_owner_name [128]; */struct { unsigned short len; unsigned char arr[128]; } objeto_owner_name; long numero; short var_indic; /* EXEC SQL END DECLARE SECTION; */ numero = objeto_id; vaciar_cadena (objeto_owner_name.arr,128); vaciar_cadena (dato_1,MAX_LEN_VARCHAR); for ( ; ; ) { /* EXEC SQL WHENEVER NOT FOUND DO break; */ /* EXEC SQL AT :nomb_001 SELECTltrim(owner)||.||ltrim(object_name) INTO :objeto_owner_name INDICATOR :var_indic FROM ALL_OBJECTS WHERE OBJECT_ID= :numero; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 5; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.stmt = "select ((ltrim(owner)||.)||ltrim(object_name)) into :b1:b2 from ALL_OBJECTS where OBJECT_ID=:b3"; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )311; sqlstm.selerr = (unsigned short)1; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)&objeto_owner_name; sqlstm.sqhstl[0] = (unsigned int )130; sqlstm.sqhsts[0] = ( int )0; sqlstm.sqindv[0] = ( void *)&var_indic; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqhstv[1] = ( void *)&numero; sqlstm.sqhstl[1] = (unsigned int )sizeof(long); sqlstm.sqhsts[1] = ( int )0; sqlstm.sqindv[1] = ( void *)0; sqlstm.sqinds[1] = ( int )0; sqlstm.sqharm[1] = (unsigned int )0; sqlstm.sqadto[1] = (unsigned short )0; sqlstm.sqtdso[1] = (unsigned short )0; Página 26
  27. 27. orasta500.c sqlstm.sqhstv[2] = ( void *)&nomb_001; sqlstm.sqhstl[2] = (unsigned int )258; sqlstm.sqhsts[2] = ( int )0; sqlstm.sqindv[2] = ( void *)0; sqlstm.sqinds[2] = ( int )0; sqlstm.sqharm[2] = (unsigned int )0; sqlstm.sqadto[2] = (unsigned short )0; sqlstm.sqtdso[2] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode == 1403) break;} break; /* SOLO ME INTERESA UN REGISTRO */ } if ( ( var_indic != 0 ) ) { for (pos=0; pos < 10 ; pos++) objeto_owner_name.arr[pos]=ASCII_PUNTO; objeto_owner_name.arr[pos]=ASCII_FIN_LINEA; } else if ( ( strlen (objeto_owner_name.arr) == 0 ) ) { for (pos=0; pos < 10 ; pos++) objeto_owner_name.arr[pos]=ASCII_PUNTO; objeto_owner_name.arr[pos]=ASCII_FIN_LINEA; } strcpy (dato_1, objeto_owner_name.arr); return (dato_1); }/*----****----****----****----****----****----****----****----****----****----*****//* ----****---- FUNCIONES A DEFINIR PARA PROCESAR LAS COLUMNAS RETORNADAS----**** *//*----****----****----****----****----****----****----****----****----****----*****/char *db_object_type (long objeto_id) { int block_size=0; static char dato_1[MAX_LEN_VARCHAR]; int pos=0; /* EXEC SQL BEGIN DECLARE SECTION; */ /* VARCHAR tipo_objeto [128]; */struct { unsigned short len; unsigned char arr[128]; } tipo_objeto; long numero; short var_indic; /* EXEC SQL END DECLARE SECTION; */ numero = objeto_id; vaciar_cadena (tipo_objeto.arr,128); Página 27
  28. 28. orasta500.c vaciar_cadena (dato_1,MAX_LEN_VARCHAR); for ( ; ; ) { /* EXEC SQL WHENEVER NOT FOUND DO break; */ /* EXEC SQL AT :nomb_001 SELECT ltrim(object_type) INTO :tipo_objeto INDICATOR :var_indic FROM ALL_OBJECTS WHERE OBJECT_ID=:numero; */{ struct sqlexd sqlstm; sqlorat((void **)0, &sqlctx, &oraca); sqlstm.sqlvsn = 12; sqlstm.arrsiz = 5; sqlstm.sqladtp = &sqladt; sqlstm.sqltdsp = &sqltds; sqlstm.stmt = "select ltrim(object_type) into :b1:b2 from ALL_OBJECTS where OBJECT_ID=:b3"; sqlstm.iters = (unsigned int )1; sqlstm.offset = (unsigned int )338; sqlstm.selerr = (unsigned short)1; sqlstm.cud = sqlcud0; sqlstm.sqlest = (unsigned char *)&sqlca; sqlstm.sqlety = (unsigned short)256; sqlstm.occurs = (unsigned int )0; sqlstm.sqhstv[0] = ( void *)&tipo_objeto; sqlstm.sqhstl[0] = (unsigned int )130; sqlstm.sqhsts[0] = ( int )0; sqlstm.sqindv[0] = ( void *)&var_indic; sqlstm.sqinds[0] = ( int )0; sqlstm.sqharm[0] = (unsigned int )0; sqlstm.sqadto[0] = (unsigned short )0; sqlstm.sqtdso[0] = (unsigned short )0; sqlstm.sqhstv[1] = ( void *)&numero; sqlstm.sqhstl[1] = (unsigned int )sizeof(long); sqlstm.sqhsts[1] = ( int )0; sqlstm.sqindv[1] = ( void *)0; sqlstm.sqinds[1] = ( int )0; sqlstm.sqharm[1] = (unsigned int )0; sqlstm.sqadto[1] = (unsigned short )0; sqlstm.sqtdso[1] = (unsigned short )0; sqlstm.sqhstv[2] = ( void *)&nomb_001; sqlstm.sqhstl[2] = (unsigned int )258; sqlstm.sqhsts[2] = ( int )0; sqlstm.sqindv[2] = ( void *)0; sqlstm.sqinds[2] = ( int )0; sqlstm.sqharm[2] = (unsigned int )0; sqlstm.sqadto[2] = (unsigned short )0; sqlstm.sqtdso[2] = (unsigned short )0; sqlstm.sqphsv = sqlstm.sqhstv; sqlstm.sqphsl = sqlstm.sqhstl; sqlstm.sqphss = sqlstm.sqhsts; sqlstm.sqpind = sqlstm.sqindv; sqlstm.sqpins = sqlstm.sqinds; sqlstm.sqparm = sqlstm.sqharm; sqlstm.sqparc = sqlstm.sqharc; sqlstm.sqpadto = sqlstm.sqadto; sqlstm.sqptdso = sqlstm.sqtdso; sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn); if (sqlca.sqlcode == 1403) break;} break; /* SOLO ME INTERESA UN REGISTRO */ } if ( var_indic != 0 ) Página 28
  29. 29. orasta500.c { for (pos=0; pos < 10 ; pos++) tipo_objeto.arr[pos]=ASCII_PUNTO; } else if ( ( strlen (tipo_objeto.arr) == 0 ) ) { for (pos=0; pos < 10 ; pos++) tipo_objeto.arr[pos]=ASCII_PUNTO; } strcpy (dato_1,tipo_objeto.arr); return (dato_1); }/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/ Página 29

×