Funciones auxiliares.c

416 views
356 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
416
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Funciones auxiliares.c

  1. 1. funciones_auxiliares.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[24];};static const struct sqlcxp sqlfpn ={ 23, "funciones_auxiliares.pc" Página 1
  2. 2. funciones_auxiliares.c};static unsigned int sqlctx = 628383107;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[1]; unsigned int sqhstl[1]; int sqhsts[1]; void *sqindv[1]; int sqinds[1]; unsigned int sqharm[1]; unsigned int *sqharc[1]; unsigned short sqadto[1]; unsigned short sqtdso[1];} sqlstm = {12,1};/* 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. funciones_auxiliares.c};#include <stdio.h>#include <stdlib.h>#include <string.h>#include "constant_definition.h"#include "case_constant_func_def.h"#include "case_constant_sql_stmt_def.h"#include "constant_oracle_versions.h"#include <oraca.h>#include <sqlca.h>#include "extern_functions_funciones_auxiliares.h"/* 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. Página 3
  4. 4. funciones_auxiliares.c 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.*/#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 ************************************************************** *** *** Página 4
  5. 5. funciones_auxiliares.c *** This file is SOSD. Porters must change the data types *** *** appropriately on their platform. See notes/pcport.doc *** *** for more information. *** *** *** ***************************************************************//* 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) Página 5
  6. 6. funciones_auxiliares.c/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/int stmtsqlncmp (char *punt_cad1, char *punt_cad2, int largo) { int pos=0; int caracter1=0; int caracter2=0; int sizecad1=(int )strlen (punt_cad1); int sizecad2=(int )strlen (punt_cad2);/* printf ("A comparar [%s] = [%s] n",punt_cad1, punt_cad2);*/ for (pos=0; pos < largo; pos ++) { if (( pos > sizecad1 ) || ( pos > sizecad2) ) return 1; else { caracter1= tolower (punt_cad1[pos]); caracter2= tolower (punt_cad2[pos]);/* printf ("Carater [%c] == [%c] n",caracter1,caracter2);*/ if ( caracter1 != caracter2 ) return 1; } }/* printf ("Encontrado [%s] n",punt_cad1); */ return 0; }/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/void vaciar_cadena (void *punt_cadena, int largo) { int pos; for (pos = 0; pos < largo; pos ++) ((char *) punt_cadena ) [pos] = ASCII_FIN_LINEA; }/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/col_size (char *puntero, int posicion) { Página 6
  7. 7. funciones_auxiliares.c char ascii_nro[3]; static int numero; int i; for ( i = posicion*2; i < posicion*2+2; i++) ascii_nro[i-posicion*2]=puntero[i]; ascii_nro[2]=ASCII_FIN_LINEA; numero=atoi(ascii_nro); return numero; }/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/int filtrar_char (int caracter) { if ( (caracter >= 32 && caracter <= 127 ) ) return caracter; else { switch (caracter) { case 164: break; case 165: break; case 168: break; case 173: break; default: caracter=32;break; } } return caracter; }/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/char *separar_dato (void *punt_cad, int opcion ) { static char cadena[MAX_LEN_CONNECT]; int posicion=0; int pos_arroba=0; int pos_slash=0; int largocad=0; int caracter=0; int contador=0; largocad=(int )strlen ((char *) punt_cad); vaciar_cadena (cadena,MAX_LEN_CONNECT); for ( posicion=0; posicion < largocad; posicion++) { caracter = ((char *) punt_cad )[posicion]; if ( caracter == ASCII_SLASH ) pos_slash = posicion; else if (caracter == ASCII_ARROBA) pos_arroba = posicion; Página 7
  8. 8. funciones_auxiliares.c } switch (opcion ) { case USERNAME: for (posicion=0; posicion < pos_slash; posicion++) { caracter = ((char *) punt_cad )[posicion]; cadena[contador]=caracter; contador++; } break; case PASSWORD: for (posicion=pos_slash+1; posicion < pos_arroba;posicion++) { caracter = ((char *) punt_cad )[posicion]; cadena[contador]=caracter; contador++; } break; case CONEXION: for (posicion=pos_arroba+1; posicion < largocad;posicion++) { caracter = ((char *) punt_cad )[posicion]; cadena[contador]=caracter; contador++; } break; } cadena[contador]=ASCII_FIN_LINEA; return (cadena); }/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/procesar_columna_funcion ( void *punt_cadena, int nro_columna, int *nro_funcion) { char procesar[10]; char col_char[10]; char func_char[10]; int pos_col = 0; int flag_procesar = 0; int caracter = 0; int delimitador = 0; int contador = 0; int nro_col = 0; int nro_func = 0; for ( pos_col = 1; pos_col < 3; pos_col ++) { procesar [pos_col-1] = ( (char *) punt_cadena)[pos_col]; procesar [pos_col] = ASCII_FIN_LINEA; } if (strncmp (procesar,"SI",2) == 0 ) flag_procesar = SI_PROCESAR; if (strncmp (procesar,"NO",2) == 0 ) { Página 8
  9. 9. funciones_auxiliares.c flag_procesar = NO_PROCESAR; return (NO_PROCESAR); } vaciar_cadena (col_char,10); vaciar_cadena (func_char,10); for ( pos_col = 3; pos_col < (int ) (strlen ( (char *) punt_cadena ));pos_col ++ ) { caracter = ( (char *) punt_cadena )[pos_col];/* printf (" ______> CHAR={%c} POS_COL=[%d]CONTADOR=[%d] LIMITADOR=[%d]n",caracter,pos_col,contador,delimitador); */ if ( caracter == ASCII_SEPARADOR ) if ( delimitador == 0 ) delimitador++; else delimitador--; if ( ( delimitador == 1 ) && ( caracter != ASCII_SEPARADOR ) ) { if ( contador < 2 ) { col_char[contador] = caracter; col_char[contador+1] = ASCII_FIN_LINEA; } else if (contador >=2 ) { func_char [contador-2] = caracter; func_char [contador-2+1]= ASCII_FIN_LINEA; }/* printf (" ______________>>>>>> COL_CHAR [%s]FUNC_CHAR [%s] NRO_COLUMNA [%d] n",col_char,func_char,nro_columna); */ contador++; if ( contador == 4 ) { nro_col = atoi (col_char); nro_func = atoi (func_char); contador=0; vaciar_cadena (col_char,10); vaciar_cadena (func_char,10); if ( nro_col == nro_columna ) { *nro_funcion = nro_func; return (SI_PROCESAR); } } } } return (NO_PROCESAR); }/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/char *convert_ss_to_hh_mm_ss (char *punt_cadena ) { static char dato_1[MAX_LEN_VARCHAR]; char auxiliar[12]; int hora,minuto,segundo; float numero= (float )atoi (punt_cadena); Página 9
  10. 10. funciones_auxiliares.c vaciar_cadena (dato_1,MAX_LEN_VARCHAR); vaciar_cadena (auxiliar,12); hora = (int )(numero/60/60); minuto = (int ) ((numero/60/60 - (int )(numero/60/60))*60); segundo = (int ) ((numero/60 - (int )(numero/60))*60); if (hora < 10) sprintf (auxiliar,"00%d:",hora); else if ((hora > 9) && (hora < 100)) sprintf (auxiliar,"0%d:",hora); else sprintf (auxiliar,"%d:",hora); strcat (dato_1,auxiliar); if (minuto < 10) sprintf (auxiliar,"0%d:",minuto); else sprintf (auxiliar,"%2d:",minuto); strcat (dato_1,auxiliar); if (segundo < 10) sprintf (auxiliar,"0%dn0",segundo); else sprintf (auxiliar,"%2dn0",segundo); strcat (dato_1,auxiliar); return (dato_1); }/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/void vaciar_estructura ( void *punt_sqlda ) { int pos_k, pos_j; int limite_k = ((SQLDA *) punt_sqlda ) ->F; int limite_j; for ( pos_k = 0; pos_k < limite_k ; pos_k++ ) { limite_j = ((SQLDA *) punt_sqlda ) ->L[ pos_k ]; for ( pos_j = 0; pos_j < limite_j ; pos_j++) (char ) (((SQLDA *) punt_sqlda)->V[pos_k])[pos_j] = ASCII_FIN_LINEA; } }/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/procesar_encabe (int tamano, int posicion, char *puntero_char) { int pos_col=0; int pos_cad=0; int columna=-1; int caracter=0; Página 10
  11. 11. funciones_auxiliares.c int salto=0; for ( pos_col = 0; pos_col < (int )strlen(puntero_char); pos_col ++) { if ( puntero_char[pos_col] == ASCII_SEPARADOR ) columna++; if ( columna == posicion ) break; } for ( pos_cad = pos_col+1; pos_cad < tamano+pos_col+1; pos_cad++ ) { if ( puntero_char[pos_cad]==ASCII_SEPARADOR) salto++; if (salto==0) { caracter = filtrar_char ( puntero_char[pos_cad] ); printf ("%c",caracter); } else printf (" "); } return NO_ERROR; }/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/procesar_cadena (int nrocolum, char *puntero_char) { int pos, caracter; for ( pos=0; pos < nrocolum; pos++ ) { caracter=filtrar_char(puntero_char[pos]); printf ("%c",caracter); } fflush(stdout); return NO_ERROR; }/*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/char *pasar_amayus (char *cadena ) { int pos=0; /* printf ("Iniciando conversion n"); */ for (pos =0; pos < (int ) strlen (cadena); pos ++) cadena[pos]=toupper(cadena[pos]); return cadena; }/*----****----****----****----****----****----****----****----****----****----*****//* Página 11
  12. 12. funciones_auxiliares.c----****----****----****----****----****----****----****----****----****----*****//*----****----****----****----****----****----****----****----****----****----*****/char *funcion_columna (int nro_bytes, void *punt_cadena, int nro_funcion) { static char dato_1 [1024]; long valor_salida; long valor_entrada; vaciar_cadena (dato_1,1024); switch (nro_funcion) { case FUNC_DB_BLOCK_SIZE: /* Calculo DB_BLOCK_SIZE, multiplico por la COLUMNA ydevuelvo el RESULTADO */ /*------------------------------------------------------------------------ */ itoa ((atoi ( (char *) punt_cadena ) * db_block_size() )/ 1000,dato_1,10); break; case FUNC_COMMAND_SQL: /* Decodifico el nro de la Columna y lo relaciono con elnombre del COMANDO */ /*------------------------------------------------------------------------ */ strcpy ( dato_1, decode_command_oracle ( atoi ( (char *)punt_cadena) ) ); break; case FUNC_LOCK_MODE: /* Decodifico el nro de la Columna y lo relaciono con eltipo de LOCKEO */ /*------------------------------------------------------------------------ */ strcpy ( dato_1, decode_lock_mode ( atoi ( (char *)punt_cadena) ) ); break; case FUNC_LOCK_NAME_MODE: /* Decodifico el nro de la Columna y lo relaciono con elnombre de LOCKEO */ /*------------------------------------------------------------------------ */ strcpy ( dato_1, decode_name_lock ( (char *)punt_cadena) ); break; case FUNC_DB_BLOCK_SIZE0: /* Calculo DB_BLOCK_SIZE, multiplico por la COLUMNA ydevuelvo el RESULTADO */ /*------------------------------------------------------------------------ */ itoa ((atoi ( (char *) punt_cadena ) * db_block_size() )/ 1024,dato_1,10); break; case FUNC_DB_OBJECT_TYPE: /* Busco el OBJECT_TYPE dentro de la tabla ALL_OBJECTS*/ /*------------------------------------------------------------------------ */ strcpy (dato_1,db_object_type ( atoi ( (char *)punt_cadena ) ) ); break; case FUNC_DB_OBJECT_OWNER_NAME: /* Busco el OBJECT_OWNER_NAME dentro de la tablaALL_OBJECTS */ /* Página 12
  13. 13. funciones_auxiliares.c------------------------------------------------------------------------ */ strcpy (dato_1,db_object_owner_name ( atoi ( (char *)punt_cadena ) ) ); /* printf ("[%s] n",dato_1); */ break; case FUNC_DB_SESSION_SID: /* Busco el OBJECT_OWNER_NAME dentro de la tablaALL_OBJECTS */ /*------------------------------------------------------------------------ *//* printf ("Cons[%s]n",((char *) punt_cadena));*/ strcpy (dato_1,db_session_sid_locked ((char *)punt_cadena )); /* printf ("[%s] n",dato_1);*/ break; case FUNC_CONVERT_HH_MM_SS: /* Busco el OBJECT_OWNER_NAME dentro de la tablaALL_OBJECTS */ /*------------------------------------------------------------------------ */ strcpy (dato_1,convert_ss_to_hh_mm_ss ((char *)punt_cadena )); break; case FUNC_DB_COMP_TBLSPC_INI_EXT: /* Busco el INIT_EXTENT de un TABLESPACE, y lo comparoen el valor */ /*--------------------------------------------------------------- */ valor_entrada = atoi ((char *) punt_cadena); valor_salida = db_tablspace_ini_ext_size ((char *)punt_cadena); if (valor_entrada == 0) strcpy (dato_1,"FREEn"); else if (valor_entrada != valor_salida ) strcpy (dato_1,"CHANGEDn"); else strcpy (dato_1,"INITIALn"); break; default: break; } return (dato_1); } Página 13

×