Initial creation.
This commit is contained in:
709
utils/dbbench.c
Normal file
709
utils/dbbench.c
Normal file
@@ -0,0 +1,709 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: dbbench.c,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 1.1 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2006/02/28 23:28:21 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* This file is part of LibDataBase */
|
||||
/* */
|
||||
/* LibDataBase is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU Lesser General Public Licence as published by */
|
||||
/* the Free Software Foundation; either version 2.1 of the License, or */
|
||||
/* (at your option) any later version. */
|
||||
/* */
|
||||
/* LibDataBase is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU Lesser General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU Lesser General Public License */
|
||||
/* along with LibDataBase; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "../lib/database.h"
|
||||
|
||||
|
||||
/* Définition des propriétés de la tables sur laquelle les tests sont réalisés */
|
||||
|
||||
/* CREATE TABLE TOTO (
|
||||
CD_TOTO CHAR (3) NOT NULL PRIMARY KEY,
|
||||
LIB_TOTO VARCHAR2 (50),
|
||||
NUM_TOTO NUMBER (5) NOT NULL,
|
||||
DAT_TOTO DATE);
|
||||
*/
|
||||
#define CD_TOTO_LEN 3
|
||||
#define LIB_TOTO_LEN 50
|
||||
|
||||
/* Mesure des temps d'exécution */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double sec;
|
||||
struct timeval start;
|
||||
struct timeval stop;
|
||||
} cpt;
|
||||
|
||||
#define t_start(x) {gettimeofday (&(x.start), NULL);}
|
||||
#define t_stop(x) {gettimeofday (&(x.stop), NULL); x.sec=(double)(x.stop.tv_sec)-(double)(x.start.tv_sec)+((double)(x.stop.tv_usec)-(double)(x.start.tv_usec))/1000000;}
|
||||
|
||||
#define NB_MAX_RECORD 2
|
||||
#define USAGE "Usage : %s insert|update|delete|select [start=<idx>] [exec=<nb_exec>]\n"
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Fonction principale du bench */
|
||||
/*--------------------------------------------------------------*/
|
||||
int main ( int argc , char ** argv )
|
||||
{
|
||||
cpt t_exec;
|
||||
DBT_Status rc;
|
||||
DBT_Result Result;
|
||||
DBT_Result ins_Result;
|
||||
unsigned int i;
|
||||
unsigned int Start_Idx = 0;
|
||||
unsigned int Nb_Exec = NB_MAX_RECORD;
|
||||
const char * Request;
|
||||
const char * ins_Request;
|
||||
DBT_Indicator Tab_Indic [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_ins_Indic [NB_MAX_RECORD];
|
||||
char Tab_CD_TOTO [NB_MAX_RECORD][CD_TOTO_LEN + 1];
|
||||
char Tab_LIB_TOTO [NB_MAX_RECORD][LIB_TOTO_LEN + 1];
|
||||
char Date_Value [11];
|
||||
int Tab_NUM_TOTO [NB_MAX_RECORD];
|
||||
int Tab_CT_PERSONNE_PHYSIQUE[NB_MAX_RECORD];
|
||||
int Tab_ins_CT_PERSONNE_PHYSIQUE[NB_MAX_RECORD];
|
||||
char Tab_NUM_PP[NB_MAX_RECORD][8];
|
||||
char Tab_ins_NUM_PP[NB_MAX_RECORD][8];
|
||||
DBT_Date * Tab_DAT_DER_MAJ_BDM;
|
||||
DBT_Date * Tab_DAT_CRE_PP_BDM;
|
||||
int Tab_CT_CG_RDP[NB_MAX_RECORD];
|
||||
int Tab_NUM_IDENT_CG_RDP[NB_MAX_RECORD];
|
||||
DBT_Date * Tab_DAT_CRE_CG_BDM_RDP;
|
||||
char Tab_CD_BQUE_RDP[NB_MAX_RECORD][6];
|
||||
char Tab_CD_GUI_CLI_RDP[NB_MAX_RECORD][6];
|
||||
char Tab_CD_ACT_ECO[NB_MAX_RECORD][3];
|
||||
char Tab_CD_PAYS_NAIS[NB_MAX_RECORD][3];
|
||||
int Tab_CD_SOGETYPE[NB_MAX_RECORD];
|
||||
char Tab_CD_SIT_FAM[NB_MAX_RECORD][3];
|
||||
char Tab_CD_CMN_INSEE_NAIS[NB_MAX_RECORD][3];
|
||||
char Tab_CD_PAYS_RM[NB_MAX_RECORD][3];
|
||||
char Tab_CD_PAYS_RF[NB_MAX_RECORD][3];
|
||||
char Tab_CD_DEPT_NAIS[NB_MAX_RECORD][3];
|
||||
char Tab_CD_ST_PROF[NB_MAX_RECORD][3];
|
||||
char Tab_NOM_PAT[NB_MAX_RECORD][33];
|
||||
char Tab_NOM_MAR[NB_MAX_RECORD][33];
|
||||
char Tab_PNOM_OFF[NB_MAX_RECORD][33];
|
||||
char Tab_PNOM_SUPP[NB_MAX_RECORD][33];
|
||||
char Tab_RAISON_SOC[NB_MAX_RECORD][41];
|
||||
int Tab_CT_FOYER_MKT[NB_MAX_RECORD];
|
||||
char Tab_CD_CAT_PROF[NB_MAX_RECORD][3];
|
||||
int Tab_CT_ADRESSE[NB_MAX_RECORD];
|
||||
char Tab_CD_SEXE[NB_MAX_RECORD][3];
|
||||
int Tab_CD_ST_INT_CHQ[NB_MAX_RECORD];
|
||||
char Tab_CD_ST_DECEDE[NB_MAX_RECORD][3];
|
||||
int Tab_CD_ST_COM_PP[NB_MAX_RECORD];
|
||||
int Tab_CD_ETA_PP[NB_MAX_RECORD];
|
||||
int Tab_CD_ST_TECH[NB_MAX_RECORD];
|
||||
char Tab_CD_IND_PP_ANO[NB_MAX_RECORD][2];
|
||||
int Tab_CD_CAP_JUR[NB_MAX_RECORD];
|
||||
int Tab_CD_UNIC_PP[NB_MAX_RECORD];
|
||||
char Tab_ADR_EMAIL[NB_MAX_RECORD][81];
|
||||
DBT_Date * Tab_DAT_DER_MAJ_BLPP;
|
||||
DBT_Date * Tab_DAT_DEB_REL_PP;
|
||||
DBT_Date * Tab_DAT_NAIS;
|
||||
DBT_Date * Tab_DAT_PUR_BLPP;
|
||||
DBT_Date * Tab_DAT_FIN_ACT_COM;
|
||||
int Tab_AGE[NB_MAX_RECORD];
|
||||
char Tab_NUM_FAX[NB_MAX_RECORD][16];
|
||||
char Tab_NUM_TEL_DOM[NB_MAX_RECORD][16];
|
||||
char Tab_NUM_PORT[NB_MAX_RECORD][16];
|
||||
int Tab_STP_MKT[NB_MAX_RECORD];
|
||||
int Tab_STP_TEL[NB_MAX_RECORD];
|
||||
int Tab_TP_FICP[NB_MAX_RECORD];
|
||||
int Tab_TP_BFM[NB_MAX_RECORD];
|
||||
int Tab_TP_HDG[NB_MAX_RECORD];
|
||||
int Tab_TP_CLI_SNS[NB_MAX_RECORD];
|
||||
int Tab_TP_NOR_DAT_NAIS[NB_MAX_RECORD];
|
||||
int Tab_TP_TEL_DOM[NB_MAX_RECORD];
|
||||
int Tab_TP_RLV_BRA[NB_MAX_RECORD];
|
||||
int Tab_CD_PRIO_FOY[NB_MAX_RECORD];
|
||||
char Tab_CD_SEG_MAR[NB_MAX_RECORD][6];
|
||||
|
||||
DBT_HostVar CT_PERSONNE_PHYSIQUE;
|
||||
DBT_HostVar NUM_PP;
|
||||
DBT_HostVar DAT_DER_MAJ_BDM;
|
||||
DBT_HostVar DAT_CRE_PP_BDM;
|
||||
DBT_HostVar CT_CG_RDP;
|
||||
DBT_HostVar NUM_IDENT_CG_RDP;
|
||||
DBT_HostVar DAT_CRE_CG_BDM_RDP;
|
||||
DBT_HostVar CD_BQUE_RDP;
|
||||
DBT_HostVar CD_GUI_CLI_RDP;
|
||||
DBT_HostVar CD_ACT_ECO;
|
||||
DBT_HostVar CD_PAYS_NAIS;
|
||||
DBT_HostVar CD_SOGETYPE;
|
||||
DBT_HostVar CD_SIT_FAM;
|
||||
DBT_HostVar CD_CMN_INSEE_NAIS;
|
||||
DBT_HostVar CD_PAYS_RM;
|
||||
DBT_HostVar CD_PAYS_RF;
|
||||
DBT_HostVar CD_DEPT_NAIS;
|
||||
DBT_HostVar CD_ST_PROF;
|
||||
DBT_HostVar NOM_PAT;
|
||||
DBT_HostVar NOM_MAR;
|
||||
DBT_HostVar PNOM_OFF;
|
||||
DBT_HostVar PNOM_SUPP;
|
||||
DBT_HostVar RAISON_SOC;
|
||||
DBT_HostVar CT_FOYER_MKT;
|
||||
DBT_HostVar CD_CAT_PROF;
|
||||
DBT_HostVar CT_ADRESSE;
|
||||
DBT_HostVar CD_SEXE;
|
||||
DBT_HostVar CD_ST_INT_CHQ;
|
||||
DBT_HostVar CD_ST_DECEDE;
|
||||
DBT_HostVar CD_ST_COM_PP;
|
||||
DBT_HostVar CD_ETA_PP;
|
||||
DBT_HostVar CD_ST_TECH;
|
||||
DBT_HostVar CD_IND_PP_ANO;
|
||||
DBT_HostVar CD_CAP_JUR;
|
||||
DBT_HostVar CD_UNIC_PP;
|
||||
DBT_HostVar ADR_EMAIL;
|
||||
DBT_HostVar DAT_DER_MAJ_BLPP;
|
||||
DBT_HostVar DAT_DEB_REL_PP;
|
||||
DBT_HostVar DAT_NAIS;
|
||||
DBT_HostVar DAT_PUR_BLPP;
|
||||
DBT_HostVar DAT_FIN_ACT_COM;
|
||||
DBT_HostVar AGE;
|
||||
DBT_HostVar NUM_FAX;
|
||||
DBT_HostVar NUM_TEL_DOM;
|
||||
DBT_HostVar NUM_PORT;
|
||||
DBT_HostVar STP_MKT;
|
||||
DBT_HostVar STP_TEL;
|
||||
DBT_HostVar TP_FICP;
|
||||
DBT_HostVar TP_BFM;
|
||||
DBT_HostVar TP_HDG;
|
||||
DBT_HostVar TP_CLI_SNS;
|
||||
DBT_HostVar TP_NOR_DAT_NAIS;
|
||||
DBT_HostVar TP_TEL_DOM;
|
||||
DBT_HostVar TP_RLV_BRA;
|
||||
DBT_HostVar CD_PRIO_FOY;
|
||||
DBT_HostVar CD_SEG_MAR;
|
||||
DBT_HostVar SEL_NUM_TOTO;
|
||||
DBT_Cursor Cursor;
|
||||
int t1, t2;
|
||||
|
||||
DBT_Indicator Tab_Indic_CT_PERSONNE_PHYSIQUE [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_NUM_PP [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_DAT_DER_MAJ_BDM [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_DAT_CRE_PP_BDM [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CT_CG_RDP [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_NUM_IDENT_CG_RDP [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_DAT_CRE_CG_BDM_RDP [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_BQUE_RDP [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_GUI_CLI_RDP [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_ACT_ECO [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_PAYS_NAIS [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_SOGETYPE [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_SIT_FAM [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_CMN_INSEE_NAIS [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_PAYS_RM [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_PAYS_RF [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_DEPT_NAIS [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_ST_PROF [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_NOM_PAT [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_NOM_MAR [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_PNOM_OFF [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_PNOM_SUPP [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_RAISON_SOC [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CT_FOYER_MKT [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_CAT_PROF [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CT_ADRESSE [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_SEXE [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_ST_INT_CHQ [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_ST_DECEDE [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_ST_COM_PP [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_ETA_PP [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_ST_TECH [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_IND_PP_ANO [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_CAP_JUR [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_UNIC_PP [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_ADR_EMAIL [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_DAT_DER_MAJ_BLPP [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_DAT_DEB_REL_PP [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_DAT_NAIS [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_DAT_PUR_BLPP [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_DAT_FIN_ACT_COM [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_AGE [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_NUM_FAX [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_NUM_TEL_DOM [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_NUM_PORT [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_STP_MKT [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_STP_TEL [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_TP_FICP [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_TP_BFM [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_TP_HDG [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_TP_CLI_SNS [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_TP_NOR_DAT_NAIS [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_TP_TEL_DOM [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_TP_RLV_BRA [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_PRIO_FOY [NB_MAX_RECORD];
|
||||
DBT_Indicator Tab_Indic_CD_SEG_MAR [NB_MAX_RECORD];
|
||||
|
||||
/* Ouverture de la librairie */
|
||||
|
||||
if (DB_Library_Open (DBD_ERRMSG | DBD_DEBUG) != DBS_OK)
|
||||
{
|
||||
fprintf (stderr, "=> Ouverture de la lbrairie LIBDATABASE impossible\n");
|
||||
goto Error0;
|
||||
}
|
||||
|
||||
/* Connexion à la base de données */
|
||||
|
||||
/* if (DB_DataBase_Connect (ORACLE, "PBDME1", "entr", "entr") != DBS_OK) */
|
||||
if (DB_DataBase_Connect (ORACLE, "ENT1", "beatrice", "beatrice") != DBS_OK)
|
||||
{
|
||||
fprintf (stderr, "=> Connexion à la base impossible\n");
|
||||
DB_Library_Close ();
|
||||
goto Error1;
|
||||
}
|
||||
|
||||
/* D\351finition des tableaux de valeurs */
|
||||
|
||||
DB_DateArray_Alloc (&Tab_DAT_DER_MAJ_BDM, NB_MAX_RECORD);
|
||||
DB_DateArray_Alloc (&Tab_DAT_CRE_PP_BDM, NB_MAX_RECORD);
|
||||
DB_DateArray_Alloc (&Tab_DAT_CRE_CG_BDM_RDP, NB_MAX_RECORD);
|
||||
DB_DateArray_Alloc (&Tab_DAT_DER_MAJ_BLPP, NB_MAX_RECORD);
|
||||
DB_DateArray_Alloc (&Tab_DAT_DEB_REL_PP, NB_MAX_RECORD);
|
||||
DB_DateArray_Alloc (&Tab_DAT_NAIS, NB_MAX_RECORD);
|
||||
DB_DateArray_Alloc (&Tab_DAT_PUR_BLPP, NB_MAX_RECORD);
|
||||
DB_DateArray_Alloc (&Tab_DAT_FIN_ACT_COM, NB_MAX_RECORD);
|
||||
|
||||
/* Définition des variables hôtes */
|
||||
|
||||
DB_HostVar_Setup (&CT_PERSONNE_PHYSIQUE,INTEGER,35,Tab_CT_PERSONNE_PHYSIQUE, Tab_Indic_CT_PERSONNE_PHYSIQUE);
|
||||
DB_HostVar_Setup (&NUM_PP, STRING,7,Tab_NUM_PP, Tab_Indic_NUM_PP);
|
||||
DB_HostVar_Setup (&DAT_DER_MAJ_BDM,DATE,NULL,Tab_DAT_DER_MAJ_BDM, Tab_Indic_DAT_DER_MAJ_BDM);
|
||||
DB_HostVar_Setup (&DAT_CRE_PP_BDM,DATE,NULL,Tab_DAT_CRE_PP_BDM, Tab_Indic_DAT_CRE_PP_BDM);
|
||||
DB_HostVar_Setup (&CT_CG_RDP,INTEGER,35,Tab_CT_CG_RDP, Tab_Indic_CT_CG_RDP);
|
||||
DB_HostVar_Setup (&NUM_IDENT_CG_RDP,INTEGER,11,Tab_NUM_IDENT_CG_RDP, Tab_Indic_NUM_IDENT_CG_RDP);
|
||||
DB_HostVar_Setup (&DAT_CRE_CG_BDM_RDP,DATE,NULL,Tab_DAT_CRE_CG_BDM_RDP, Tab_Indic_DAT_CRE_CG_BDM_RDP);
|
||||
DB_HostVar_Setup (&CD_BQUE_RDP, STRING,5,Tab_CD_BQUE_RDP, Tab_Indic_CD_BQUE_RDP);
|
||||
DB_HostVar_Setup (&CD_GUI_CLI_RDP, STRING,5,Tab_CD_GUI_CLI_RDP, Tab_Indic_CD_GUI_CLI_RDP);
|
||||
DB_HostVar_Setup (&CD_ACT_ECO, STRING,2,Tab_CD_ACT_ECO, Tab_Indic_CD_ACT_ECO);
|
||||
DB_HostVar_Setup (&CD_PAYS_NAIS, STRING,2,Tab_CD_PAYS_NAIS, Tab_Indic_CD_PAYS_NAIS);
|
||||
DB_HostVar_Setup (&CD_SOGETYPE,INTEGER,2,Tab_CD_SOGETYPE, Tab_Indic_CD_SOGETYPE);
|
||||
DB_HostVar_Setup (&CD_SIT_FAM, STRING,2,Tab_CD_SIT_FAM, Tab_Indic_CD_SIT_FAM);
|
||||
DB_HostVar_Setup (&CD_CMN_INSEE_NAIS, STRING,5,Tab_CD_CMN_INSEE_NAIS, Tab_Indic_CD_CMN_INSEE_NAIS);
|
||||
DB_HostVar_Setup (&CD_PAYS_RM, STRING,2,Tab_CD_PAYS_RM, Tab_Indic_CD_PAYS_RM);
|
||||
DB_HostVar_Setup (&CD_PAYS_RF, STRING,2,Tab_CD_PAYS_RF, Tab_Indic_CD_PAYS_RF);
|
||||
DB_HostVar_Setup (&CD_DEPT_NAIS, STRING,2,Tab_CD_DEPT_NAIS, Tab_Indic_CD_DEPT_NAIS);
|
||||
DB_HostVar_Setup (&CD_ST_PROF, STRING,2,Tab_CD_ST_PROF, Tab_Indic_CD_ST_PROF);
|
||||
DB_HostVar_Setup (&NOM_PAT, STRING,32,Tab_NOM_PAT, Tab_Indic_NOM_PAT);
|
||||
DB_HostVar_Setup (&NOM_MAR, STRING,32,Tab_NOM_MAR, Tab_Indic_NOM_MAR);
|
||||
DB_HostVar_Setup (&PNOM_OFF, STRING,32,Tab_PNOM_OFF, Tab_Indic_PNOM_OFF);
|
||||
DB_HostVar_Setup (&PNOM_SUPP, STRING,32,Tab_PNOM_SUPP, Tab_Indic_PNOM_SUPP);
|
||||
DB_HostVar_Setup (&RAISON_SOC, STRING,40,Tab_RAISON_SOC, Tab_Indic_RAISON_SOC);
|
||||
DB_HostVar_Setup (&CT_FOYER_MKT,INTEGER,35,Tab_CT_FOYER_MKT, Tab_Indic_CT_FOYER_MKT);
|
||||
DB_HostVar_Setup (&CD_CAT_PROF, STRING,2,Tab_CD_CAT_PROF, Tab_Indic_CD_CAT_PROF);
|
||||
DB_HostVar_Setup (&CT_ADRESSE,INTEGER,35,Tab_CT_ADRESSE, Tab_Indic_CT_ADRESSE);
|
||||
DB_HostVar_Setup (&CD_SEXE, STRING,2,Tab_CD_SEXE, Tab_Indic_CD_SEXE);
|
||||
DB_HostVar_Setup (&CD_ST_INT_CHQ,INTEGER,1,Tab_CD_ST_INT_CHQ, Tab_Indic_CD_ST_INT_CHQ);
|
||||
DB_HostVar_Setup (&CD_ST_DECEDE, STRING,2,Tab_CD_ST_DECEDE, Tab_Indic_CD_ST_DECEDE);
|
||||
DB_HostVar_Setup (&CD_ST_COM_PP,INTEGER,1,Tab_CD_ST_COM_PP, Tab_Indic_CD_ST_COM_PP);
|
||||
DB_HostVar_Setup (&CD_ETA_PP,INTEGER,1,Tab_CD_ETA_PP, Tab_Indic_CD_ETA_PP);
|
||||
DB_HostVar_Setup (&CD_ST_TECH,INTEGER,1,Tab_CD_ST_TECH, Tab_Indic_CD_ST_TECH);
|
||||
DB_HostVar_Setup (&CD_IND_PP_ANO, STRING,1,Tab_CD_IND_PP_ANO, Tab_Indic_CD_IND_PP_ANO);
|
||||
DB_HostVar_Setup (&CD_CAP_JUR,INTEGER,1,Tab_CD_CAP_JUR, Tab_Indic_CD_CAP_JUR);
|
||||
DB_HostVar_Setup (&CD_UNIC_PP,INTEGER,12,Tab_CD_UNIC_PP, Tab_Indic_CD_UNIC_PP);
|
||||
DB_HostVar_Setup (&ADR_EMAIL, STRING,60,Tab_ADR_EMAIL, Tab_Indic_ADR_EMAIL);
|
||||
DB_HostVar_Setup (&DAT_DER_MAJ_BLPP,DATE,NULL,Tab_DAT_DER_MAJ_BLPP, Tab_Indic_DAT_DER_MAJ_BLPP);
|
||||
DB_HostVar_Setup (&DAT_DEB_REL_PP,DATE,NULL,Tab_DAT_DEB_REL_PP, Tab_Indic_DAT_DEB_REL_PP);
|
||||
DB_HostVar_Setup (&DAT_NAIS,DATE,NULL,Tab_DAT_NAIS, Tab_Indic_DAT_NAIS);
|
||||
DB_HostVar_Setup (&DAT_PUR_BLPP,DATE,NULL,Tab_DAT_PUR_BLPP, Tab_Indic_DAT_PUR_BLPP);
|
||||
DB_HostVar_Setup (&DAT_FIN_ACT_COM,DATE,NULL,Tab_DAT_FIN_ACT_COM, Tab_Indic_DAT_FIN_ACT_COM);
|
||||
DB_HostVar_Setup (&AGE,INTEGER,3,Tab_AGE, Tab_Indic_AGE);
|
||||
DB_HostVar_Setup (&NUM_FAX, STRING,15,Tab_NUM_FAX, Tab_Indic_NUM_FAX);
|
||||
DB_HostVar_Setup (&NUM_TEL_DOM, STRING,15,Tab_NUM_TEL_DOM, Tab_Indic_NUM_TEL_DOM);
|
||||
DB_HostVar_Setup (&NUM_PORT, STRING,15,Tab_NUM_PORT, Tab_Indic_NUM_PORT);
|
||||
DB_HostVar_Setup (&STP_MKT,INTEGER,1,Tab_STP_MKT, Tab_Indic_STP_MKT);
|
||||
DB_HostVar_Setup (&STP_TEL,INTEGER,1,Tab_STP_TEL, Tab_Indic_STP_TEL);
|
||||
DB_HostVar_Setup (&TP_FICP,INTEGER,1,Tab_TP_FICP, Tab_Indic_TP_FICP);
|
||||
DB_HostVar_Setup (&TP_BFM,INTEGER,1,Tab_TP_BFM, Tab_Indic_TP_BFM);
|
||||
DB_HostVar_Setup (&TP_HDG,INTEGER,1,Tab_TP_HDG, Tab_Indic_TP_HDG);
|
||||
DB_HostVar_Setup (&TP_CLI_SNS,INTEGER,1,Tab_TP_CLI_SNS, Tab_Indic_TP_CLI_SNS);
|
||||
DB_HostVar_Setup (&TP_NOR_DAT_NAIS,INTEGER,1,Tab_TP_NOR_DAT_NAIS, Tab_Indic_TP_NOR_DAT_NAIS);
|
||||
DB_HostVar_Setup (&TP_TEL_DOM,INTEGER,1,Tab_TP_TEL_DOM, Tab_Indic_TP_TEL_DOM);
|
||||
DB_HostVar_Setup (&TP_RLV_BRA,INTEGER,1,Tab_TP_RLV_BRA, Tab_Indic_TP_RLV_BRA);
|
||||
DB_HostVar_Setup (&CD_PRIO_FOY,INTEGER,2,Tab_CD_PRIO_FOY, Tab_Indic_CD_PRIO_FOY);
|
||||
DB_HostVar_Setup (&CD_SEG_MAR, STRING,5,Tab_CD_SEG_MAR, Tab_Indic_CD_SEG_MAR);
|
||||
|
||||
/* Exécution de la requête */
|
||||
|
||||
/* DB_HostVar_Setup(&SEL_NUM_TOTO, INTEGER, NULL, &Start_Idx, &Start_Idx); */
|
||||
|
||||
Request = "SELECT \
|
||||
CT_PERSONNE_PHYSIQUE, \
|
||||
NUM_PP, \
|
||||
DAT_DER_MAJ_BDM, \
|
||||
DAT_CRE_PP_BDM, \
|
||||
CT_CG_RDP, \
|
||||
NUM_IDENT_CG_RDP, \
|
||||
DAT_CRE_CG_BDM_RDP, \
|
||||
CD_BQUE_RDP, \
|
||||
CD_GUI_CLI_RDP, \
|
||||
CD_ACT_ECO, \
|
||||
CD_PAYS_NAIS, \
|
||||
CD_SOGETYPE, \
|
||||
CD_SIT_FAM, \
|
||||
CD_CMN_INSEE_NAIS, \
|
||||
CD_PAYS_RM, \
|
||||
CD_PAYS_RF, \
|
||||
CD_DEPT_NAIS, \
|
||||
CD_ST_PROF, \
|
||||
NOM_PAT, \
|
||||
NOM_MAR, \
|
||||
PNOM_OFF, \
|
||||
PNOM_SUPP, \
|
||||
RAISON_SOC, \
|
||||
CT_FOYER_MKT, \
|
||||
CD_CAT_PROF, \
|
||||
CT_ADRESSE, \
|
||||
CD_SEXE, \
|
||||
CD_ST_INT_CHQ, \
|
||||
CD_ST_DECEDE, \
|
||||
CD_ST_COM_PP, \
|
||||
CD_ETA_PP, \
|
||||
CD_ST_TECH, \
|
||||
CD_IND_PP_ANO, \
|
||||
CD_CAP_JUR, \
|
||||
CD_UNIC_PP, \
|
||||
ADR_EMAIL, \
|
||||
DAT_DER_MAJ_BLPP, \
|
||||
CD_SEG_MAR \
|
||||
FROM TB_PERSONNE_PHYSIQUE";
|
||||
|
||||
/* Ouverture d'un curseur */
|
||||
|
||||
rc = DB_Cursor_Open (&Cursor, &Result, Request,NULL);
|
||||
if (rc != DBS_OK)
|
||||
{
|
||||
fprintf (stderr, "=> Sélection impossible\n");
|
||||
goto Error2;
|
||||
}
|
||||
|
||||
/* Fetch du curseur */
|
||||
|
||||
rc = DB_Cursor_Fetch (Cursor, &Result, Nb_Exec,
|
||||
&CT_PERSONNE_PHYSIQUE,
|
||||
&NUM_PP,
|
||||
&DAT_DER_MAJ_BDM,
|
||||
&DAT_CRE_PP_BDM,
|
||||
&CT_CG_RDP,
|
||||
&NUM_IDENT_CG_RDP,
|
||||
&DAT_CRE_CG_BDM_RDP,
|
||||
&CD_BQUE_RDP,
|
||||
&CD_GUI_CLI_RDP,
|
||||
&CD_ACT_ECO,
|
||||
&CD_PAYS_NAIS,
|
||||
&CD_SOGETYPE,
|
||||
&CD_SIT_FAM,
|
||||
&CD_CMN_INSEE_NAIS,
|
||||
&CD_PAYS_RM,
|
||||
&CD_PAYS_RF,
|
||||
&CD_DEPT_NAIS,
|
||||
&CD_ST_PROF,
|
||||
&NOM_PAT,
|
||||
&NOM_MAR,
|
||||
&PNOM_OFF,
|
||||
&PNOM_SUPP,
|
||||
&RAISON_SOC,
|
||||
&CT_FOYER_MKT,
|
||||
&CD_CAT_PROF,
|
||||
&CT_ADRESSE,
|
||||
&CD_SEXE,
|
||||
&CD_ST_INT_CHQ,
|
||||
&CD_ST_DECEDE,
|
||||
&CD_ST_COM_PP,
|
||||
&CD_ETA_PP,
|
||||
&CD_ST_TECH,
|
||||
&CD_IND_PP_ANO,
|
||||
&CD_CAP_JUR,
|
||||
&CD_UNIC_PP,
|
||||
&ADR_EMAIL,
|
||||
&DAT_DER_MAJ_BLPP,
|
||||
&CD_SEG_MAR,
|
||||
NULL);
|
||||
if (rc == DBS_OK)
|
||||
{
|
||||
fprintf (stderr, "=> %d enregistrement(s) sélectionné(s) :\n", Result.Row_Num);
|
||||
}
|
||||
else if (rc == DBS_ERRNODATA)
|
||||
{
|
||||
fprintf (stderr, "=> Il y a moins de %d enregistrement(s) à sélectionner.\n", Nb_Exec);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "=> Sélection impossible\n");
|
||||
DB_Cursor_Close (Cursor);
|
||||
goto Error2;
|
||||
}
|
||||
|
||||
for (i = 0; i < Result.Row_Num; i++)
|
||||
{
|
||||
if (DB_DateToString_Convert (Tab_DAT_DER_MAJ_BDM, i, Date_Value, NULL) != DBS_OK) goto Error2;
|
||||
fprintf (stderr, "Debug HME Tab_Indic_CD_ETA_PP = ##%d##\n", Tab_Indic_CD_ETA_PP[i]);
|
||||
fprintf (stderr, "Debug HME CD_ETA_PP = ##%d##\n", Tab_CD_ETA_PP[i]);
|
||||
fprintf (stderr, "Debug HME Tab_Indic_CD_ST_TECH = ##%d##\n", Tab_Indic_CD_ST_TECH[i]);
|
||||
fprintf (stderr, "Debug HME CD_ST_TECH = ##%d##\n", Tab_CD_ST_TECH[i]);
|
||||
}
|
||||
|
||||
/* Fermeture du curseur */
|
||||
|
||||
DB_Cursor_Close (Cursor);
|
||||
|
||||
if (DB_DataBase_Disconnect () != DBS_OK)
|
||||
{
|
||||
fprintf (stderr, "=> D\351connexion de la base impossible\n");
|
||||
goto Error1;
|
||||
}
|
||||
|
||||
|
||||
/* INsertion dans la table TEST_ENS */
|
||||
|
||||
t_start (t_exec);
|
||||
|
||||
/* Connexion \340 la base de donn\351es */
|
||||
|
||||
if (DB_DataBase_Connect (ORACLE, "ENT1", "beatrice", "beatrice") != DBS_OK)
|
||||
{
|
||||
fprintf (stderr, "=> Connexion \340 la base impossible\n");
|
||||
DB_Library_Close ();
|
||||
goto Error1;
|
||||
}
|
||||
|
||||
ins_Request = "INSERT INTO TEST_ENS \
|
||||
( \
|
||||
CT_PERSONNE_PHYSIQUE, \
|
||||
NUM_PP, \
|
||||
DAT_DER_MAJ_BDM \
|
||||
/* DAT_CRE_PP_BDM, \
|
||||
CT_CG_RDP, \
|
||||
NUM_IDENT_CG_RDP, \
|
||||
DAT_CRE_CG_BDM_RDP, \
|
||||
CD_BQUE_RDP, \
|
||||
CD_GUI_CLI_RDP, \
|
||||
CD_ACT_ECO, \
|
||||
CD_PAYS_NAIS, \
|
||||
CD_SOGETYPE, \
|
||||
CD_SIT_FAM, \
|
||||
CD_CMN_INSEE_NAIS, \
|
||||
CD_PAYS_RM, \
|
||||
CD_PAYS_RF, \
|
||||
CD_DEPT_NAIS, \
|
||||
CD_ST_PROF, \
|
||||
NOM_PAT, \
|
||||
NOM_MAR, \
|
||||
PNOM_OFF, \
|
||||
PNOM_SUPP, \
|
||||
RAISON_SOC, \
|
||||
CT_FOYER_MKT, \
|
||||
CD_CAT_PROF, \
|
||||
CT_ADRESSE, \
|
||||
CD_SEXE, \
|
||||
CD_ST_INT_CHQ, \
|
||||
CD_ST_DECEDE, \
|
||||
CD_ST_COM_PP, \
|
||||
CD_ETA_PP, \
|
||||
CD_ST_TECH, \
|
||||
CD_IND_PP_ANO, \
|
||||
CD_CAP_JUR, \
|
||||
CD_UNIC_PP, \
|
||||
ADR_EMAIL, \
|
||||
DAT_DER_MAJ_BLPP, \
|
||||
CD_SEG_MAR */
|
||||
) \
|
||||
VALUES \
|
||||
( \
|
||||
:1, \
|
||||
:2, \
|
||||
:3 \
|
||||
/* :4, \
|
||||
:5, \
|
||||
:6, \
|
||||
:7, \
|
||||
:8, \
|
||||
:9, \
|
||||
:10, \
|
||||
:11, \
|
||||
:12, \
|
||||
:13, \
|
||||
:14, \
|
||||
:15, \
|
||||
:16, \
|
||||
:17, \
|
||||
:18, \
|
||||
:19, \
|
||||
:20, \
|
||||
:21, \
|
||||
:22, \
|
||||
:23, \
|
||||
:24, \
|
||||
:25, \
|
||||
:26, \
|
||||
:27, \
|
||||
:28, \
|
||||
:29, \
|
||||
:30, \
|
||||
:31, \
|
||||
:32, \
|
||||
:33, \
|
||||
:34, \
|
||||
:35, \
|
||||
:36, \
|
||||
:37, \
|
||||
:38 */
|
||||
)";
|
||||
fprintf (stderr, "Result.Row_Num = ##%d##\n",Result.Row_Num);
|
||||
fprintf (stderr, "Start_Idx = ##%d##\n",Start_Idx);
|
||||
fprintf (stderr, "ins_Request = ##%s##\n",ins_Request);
|
||||
rc = DB_Insert_Exec (&ins_Result, ins_Request, Nb_Exec, Start_Idx,
|
||||
&CT_PERSONNE_PHYSIQUE,
|
||||
&NUM_PP,
|
||||
&DAT_DER_MAJ_BDM,
|
||||
/* &DAT_CRE_PP_BDM,
|
||||
&CT_CG_RDP,
|
||||
&NUM_IDENT_CG_RDP,
|
||||
&DAT_CRE_CG_BDM_RDP,
|
||||
&CD_BQUE_RDP,
|
||||
&CD_GUI_CLI_RDP,
|
||||
&CD_ACT_ECO,
|
||||
&CD_PAYS_NAIS,
|
||||
&CD_SOGETYPE,
|
||||
&CD_SIT_FAM,
|
||||
&CD_CMN_INSEE_NAIS,
|
||||
&CD_PAYS_RM,
|
||||
&CD_PAYS_RF,
|
||||
&CD_DEPT_NAIS,
|
||||
&CD_ST_PROF,
|
||||
&NOM_PAT,
|
||||
&NOM_MAR,
|
||||
&PNOM_OFF,
|
||||
&PNOM_SUPP,
|
||||
&RAISON_SOC,
|
||||
&CT_FOYER_MKT,
|
||||
&CD_CAT_PROF,
|
||||
&CT_ADRESSE,
|
||||
&CD_SEXE,
|
||||
&CD_ST_INT_CHQ,
|
||||
&CD_ST_DECEDE,
|
||||
&CD_ST_COM_PP,
|
||||
&CD_ETA_PP,
|
||||
&CD_ST_TECH,
|
||||
&CD_IND_PP_ANO,
|
||||
&CD_CAP_JUR,
|
||||
&CD_UNIC_PP,
|
||||
&ADR_EMAIL,
|
||||
&DAT_DER_MAJ_BLPP,
|
||||
&CD_SEG_MAR, */
|
||||
NULL);
|
||||
|
||||
if (rc == DBS_OK)
|
||||
{
|
||||
fprintf (stderr, "Insert OK\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "Insert a échoué\n");
|
||||
}
|
||||
|
||||
/*
|
||||
if (DB_Transaction_Start (&t1) != DBS_OK) goto Error2;
|
||||
rc = DB_Insert_Exec (&Result, Request, 10, 0, &CD_TOTO, &LIB_TOTO, &NUM_TOTO, &DAT_TOTO, NULL);
|
||||
|
||||
if (DB_Transaction_Start (&t2) != DBS_OK) goto Error2;
|
||||
rc = DB_Insert_Exec (&Result, Request, 10, 10, &CD_TOTO, &LIB_TOTO, &NUM_TOTO, &DAT_TOTO, NULL);
|
||||
|
||||
if (DB_Transaction_Change (t1) != DBS_OK) goto Error2;
|
||||
rc = DB_Insert_Exec (&Result, Request, 10, 20, &CD_TOTO, &LIB_TOTO, &NUM_TOTO, &DAT_TOTO, NULL);
|
||||
|
||||
if (DB_Transaction_Change (t2) != DBS_OK) goto Error2;
|
||||
rc = DB_Insert_Exec (&Result, Request, 10, 30, &CD_TOTO, &LIB_TOTO, &NUM_TOTO, &DAT_TOTO, NULL);
|
||||
if (DB_Rollback_Exec () != DBS_OK) goto Error2;
|
||||
if (DB_Transaction_End () != DBS_OK) goto Error2;
|
||||
|
||||
if (DB_Transaction_Change (t1) != DBS_OK) goto Error2;
|
||||
if (DB_Commit_Exec () != DBS_OK) goto Error2;
|
||||
if (DB_Transaction_End () != DBS_OK) goto Error2;
|
||||
*/
|
||||
t_stop (t_exec);
|
||||
|
||||
|
||||
/* Affichage du temps d'exécution */
|
||||
|
||||
if (Result.Row_Num)
|
||||
{
|
||||
fprintf (stdout, "%d enregistrement(s) traité(s) en %.4f sec (%.2f enreg/sec)\n",
|
||||
Result.Row_Num, t_exec.sec, Result.Row_Num / t_exec.sec );
|
||||
}
|
||||
|
||||
if (DB_Commit_Exec () != DBS_OK) goto Error2;
|
||||
|
||||
/* Libération des ressources */
|
||||
|
||||
DB_DateArray_Free (Tab_DAT_DER_MAJ_BDM);
|
||||
DB_DateArray_Free (Tab_DAT_CRE_PP_BDM);
|
||||
DB_DateArray_Free (Tab_DAT_CRE_CG_BDM_RDP);
|
||||
DB_DateArray_Free (Tab_DAT_DER_MAJ_BLPP);
|
||||
DB_DateArray_Free (Tab_DAT_DEB_REL_PP);
|
||||
DB_DateArray_Free (Tab_DAT_NAIS);
|
||||
DB_DateArray_Free (Tab_DAT_PUR_BLPP);
|
||||
DB_DateArray_Free (Tab_DAT_FIN_ACT_COM);
|
||||
|
||||
/* Déconnexion de la base */
|
||||
|
||||
if (DB_DataBase_Disconnect () != DBS_OK)
|
||||
{
|
||||
fprintf (stderr, "=> Déconnexion de la base impossible\n");
|
||||
goto Error1;
|
||||
}
|
||||
|
||||
/* Fermeture de la librairie */
|
||||
|
||||
if (DB_Library_Close () != DBS_OK)
|
||||
{
|
||||
fprintf (stderr, "=> Fermeture de la librairie LIBDATABASE impossible\n");
|
||||
goto Error0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
/* Traitement des erreurs */
|
||||
|
||||
Error2:
|
||||
DB_DateArray_Free (Tab_DAT_DER_MAJ_BDM);
|
||||
DB_DateArray_Free (Tab_DAT_CRE_PP_BDM);
|
||||
DB_DateArray_Free (Tab_DAT_CRE_CG_BDM_RDP);
|
||||
DB_DateArray_Free (Tab_DAT_DER_MAJ_BLPP);
|
||||
DB_DateArray_Free (Tab_DAT_DEB_REL_PP);
|
||||
DB_DateArray_Free (Tab_DAT_NAIS);
|
||||
DB_DateArray_Free (Tab_DAT_PUR_BLPP);
|
||||
DB_DateArray_Free (Tab_DAT_FIN_ACT_COM);
|
||||
DB_DataBase_Disconnect ();
|
||||
|
||||
Error1:
|
||||
DB_Library_Close ();
|
||||
|
||||
Error0:
|
||||
return -1;
|
||||
}
|
||||
241
utils/dbtest.c
Normal file
241
utils/dbtest.c
Normal file
@@ -0,0 +1,241 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: dbtest.c,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 1.1 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2006/02/28 23:28:21 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* This file is part of LibDataBase */
|
||||
/* */
|
||||
/* LibDataBase is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU Lesser General Public Licence as published by */
|
||||
/* the Free Software Foundation; either version 2.1 of the License, or */
|
||||
/* (at your option) any later version. */
|
||||
/* */
|
||||
/* LibDataBase is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU Lesser General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU Lesser General Public License */
|
||||
/* along with LibDataBase; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "../lib/database.h"
|
||||
|
||||
DBT_Connection conn;
|
||||
DBT_Statement st;
|
||||
DBT_Result res;
|
||||
|
||||
|
||||
DBT_HostVar hv1;
|
||||
DBT_HostVar hv2;
|
||||
DBT_HostVar hv3;
|
||||
DBT_HostVar hv4;
|
||||
DBT_HostVar hv5;
|
||||
DBT_HostVar hv6;
|
||||
DBT_HostVar hv7;
|
||||
DBT_HostVar hv8;
|
||||
DBT_HostVar hv9;
|
||||
|
||||
char buf1[100][20];
|
||||
char buf2[100][20];
|
||||
char buf3[100][20];
|
||||
char buf4[100][20];
|
||||
char buf5[100][20];
|
||||
char buf6[100][20];
|
||||
char buf7[100][20];
|
||||
char buf8[100][20];
|
||||
char buf9[100][20];
|
||||
|
||||
int int1[100];
|
||||
int int2[100];
|
||||
int int3[100];
|
||||
int int4[100];
|
||||
int int5[100];
|
||||
int int6[100];
|
||||
int int7[100];
|
||||
int int8[100];
|
||||
int int9[100];
|
||||
|
||||
|
||||
DBT_Indicator indic1[100];
|
||||
DBT_Indicator indic2[100];
|
||||
DBT_Indicator indic3[100];
|
||||
DBT_Indicator indic4[100];
|
||||
DBT_Indicator indic5[100];
|
||||
DBT_Indicator indic6[100];
|
||||
DBT_Indicator indic7[100];
|
||||
DBT_Indicator indic8[100];
|
||||
DBT_Indicator indic9[100];
|
||||
int i;
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
DBT_Status rc;
|
||||
char *err;
|
||||
|
||||
rc = DB_Library_Open(DBD_DEBUG | DBD_ERRMSG);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("open: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = DB_Connect(&conn, "florian", "florian", "hera");
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("connect: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = DB_Statement_Init(&conn, &st);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("st_init: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = DB_Statement_Prepare(&st, argv[1]);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("st_prep: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
rc = DB_HostVar_Setup(&hv1, DBD_STRING, 20, buf1, indic1);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("hv1_set: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
rc = DB_HostVar_Setup(&hv2, DBD_STRING, 20, buf2, indic2);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("hv2_set: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
rc = DB_HostVar_Setup(&hv3, DBD_STRING, 20, buf3, indic3);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("hv3_set: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
rc = DB_HostVar_Setup(&hv4, DBD_STRING, 20, buf4, indic4);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("hv4_set: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = DB_HostVar_Setup(&hv5, DBD_INTEGER, 0, int1, indic5);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("hv5_set: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
rc = DB_HostVar_Setup(&hv6, DBD_INTEGER, 0, int2, indic6);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("hv6_set: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
rc = DB_HostVar_Setup(&hv7, DBD_STRING, 20, buf7, indic7);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("hv7_set: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
rc = DB_HostVar_Setup(&hv8, DBD_STRING, 20, buf8, indic8);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("hv8_set: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
rc = DB_HostVar_Setup(&hv9, DBD_STRING, 20, buf9, indic9);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("hv9_set: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
rc = DB_Statement_DefineVars(&st, 10, &hv1, &hv2, NULL);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("st_def: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = DB_Statement_BindVars(&st, 100, &hv5, &hv6, NULL);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("st_bind: %s\n", err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (i = 0; i < 100; i++) {
|
||||
indic5[i] = 0; strcpy(buf5[i], "4"); int1[i] = 1;
|
||||
indic6[i] = 0; strcpy(buf6[i], "6"); int2[i] = i;
|
||||
}
|
||||
|
||||
|
||||
rc = DB_Statement_Execute(&st, atoi(argv[2]), atoi(argv[3]), &res);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("st_ex: %s\n", err);
|
||||
}
|
||||
|
||||
printf("Rc: %d; Res: %d processed, error iteration %d\n",
|
||||
rc, res.rowsProcessed, res.errorIteration);
|
||||
|
||||
if (st.isSelect) {
|
||||
while (rc == DBS_OK) {
|
||||
for (i = 0; i < res.rowsProcessed; i++) {
|
||||
printf("%2d: %s(%d) | %s(%d) | %s(%d)\n",
|
||||
i,
|
||||
buf1[i], indic1[i],
|
||||
buf2[i], indic2[i],
|
||||
buf3[i], indic3[i],
|
||||
buf4[i], indic4[i],
|
||||
buf5[i], indic5[i],
|
||||
buf6[i], indic6[i],
|
||||
buf7[i], indic7[i],
|
||||
buf8[i], indic8[i],
|
||||
buf9[i], indic9[i]
|
||||
);
|
||||
}
|
||||
|
||||
rc = DB_Statement_Fetch(&st, &res);
|
||||
if (DB_ERROR(rc)) {
|
||||
DB_Library_Error_Get(&err);
|
||||
printf("st_fetch: %s\n", err);
|
||||
}
|
||||
|
||||
printf("Rc: %d; Res: %d processed, error iteration %d\n",
|
||||
rc, res.rowsProcessed, res.errorIteration);
|
||||
};
|
||||
}
|
||||
|
||||
printf("End, rc = %d\n", rc);
|
||||
|
||||
DB_Disconnect(&conn);
|
||||
|
||||
return 0;
|
||||
}
|
||||
91
utils/perfResults.txt
Normal file
91
utils/perfResults.txt
Normal file
@@ -0,0 +1,91 @@
|
||||
---- Base:
|
||||
florian/florian@hera
|
||||
|
||||
---- Table:
|
||||
CREATE TABLE dummy (c1 NUMBER(35) NOT NULL PRIMARY KEY,
|
||||
c2 VARCHAR2(16),
|
||||
c3 NUMBER(10));
|
||||
|
||||
---- Query:
|
||||
"INSERT INTO dummy (c1, c2, c3) VALUES (:1, :2, :3)"
|
||||
|
||||
:1 range from 1 to N
|
||||
:2 range from 'B1' to 'BN'
|
||||
:3 range from 1 to N
|
||||
|
||||
---- Time Results (seconds):
|
||||
|
||||
N | Empty table | after 1 shot | after 2 shots | rows/sec
|
||||
--------------------------------------------------------------------------------------------
|
||||
10 | (ms) 2.19; 1.79; 3.69; 1.76 | | 4500 ~ 5600
|
||||
100 | (ms) 6.8; 10.5; 8.0; | | 9500 ~ 14700
|
||||
1 000 | (ms) 68.3; 80.7; 79.1; | | 12800 ~ 14600
|
||||
10 000 | 1.5; 1.2; 1.1 | 1.4; 1.4; 1.3 | 1.1; 1.1; 1.3 | 6600 ~ 9000
|
||||
50 000 | 7.1; 6.8; 7.1 | 6.4; 8.0; 7.3 | 9.3; 8.0; 6.9 | 5300 ~ 7800
|
||||
65 536 | 12.8; 12.6 | 11.5; 11.6; | 11.3; | 5120 ~ 5800
|
||||
--------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
---- Query:
|
||||
"SELECT c1, c2, c3 FROM dummy"
|
||||
|
||||
Select 100 000 rows in 2.7 sec. --> 35000 rows/sec
|
||||
Select 100 000 rows in 2.3 sec. --> 43000 rows/sec
|
||||
|
||||
---- Query:
|
||||
"SELECT c1, c2, c3 FROM dummy WHERE c1 > 0 and c3 < 1234567"
|
||||
|
||||
Select 100 000 rows in 9.5 sec. --> 10500 rows/sec
|
||||
Select 100 000 rows in 9.6 sec. --> 10400 rows/sec
|
||||
|
||||
|
||||
######################################################################################
|
||||
|
||||
|
||||
---- Base:
|
||||
entr/entr@pbdme1
|
||||
|
||||
|
||||
---- Table:
|
||||
TB_PERSONNE_PHYSIQUE & test_ens
|
||||
|
||||
[ CREATE TABLE test_ens (CT_PERSONNE_PHYSIQUE NOT NULL NUMBER(35),
|
||||
NUM_PP NOT NULL CHAR(7), DAT_DER_MAJ_BDM DATE, .......) ]
|
||||
|
||||
---- Query:
|
||||
"SELECT CT_PERSONNE_PHYSIQUE, NUM_PP, DAT_DER_MAJ_BDM FROM tb_personne_physique"
|
||||
|
||||
Select 11000 rows in 2.7 sec. --> 4000 rows/sec
|
||||
Select 11000 rows in 2.5 sec. --> 4400 rows/sec
|
||||
Select 11000 rows in 2.4 sec. --> 4500 rows/sec
|
||||
|
||||
Select 50000 rows in 11.6 sec. --> 4300 rows/sec
|
||||
Select 50000 rows in 11.4 sec. --> 4400 rows/sec
|
||||
|
||||
|
||||
---- Query:
|
||||
"INSERT INTO test_ens (CT_PERSONNE_PHYSIQUE, NUM_PP, DAT_DER_MAJ_BDM) VALUES (:1, :2, :3)"
|
||||
Input values taken from table "tb_personne_physique" as shown above.
|
||||
|
||||
|
||||
---- Time Results (seconds):
|
||||
|
||||
N | Empty table | after 1 shot | after 2 shots | rows/sec
|
||||
--------------------------------------------------------------------------------------------
|
||||
10 000 | 1.1; 1.3; 1.2 | 1.3; | 1.2; | 7000 ~ 9000
|
||||
50 000 | 5.9; 5.9; 6.2 | 6.4; | 6.0; | 7800 ~ 8400
|
||||
--------------------------------------------------------------------------------------------
|
||||
|
||||
Insert N rows of 38 columns:
|
||||
|
||||
N | | rows/sec
|
||||
--------------------------------------------------------------------------------------------
|
||||
100 | 0.10; 0.11; 0.10; | 877 ~ 980
|
||||
500 | 0.47; 0.41; 0.42; | 1060 ~ 1219
|
||||
1 000 | 0.87; 0.81; 0.83; | 1100 ~ 1200
|
||||
2 000 | 7.93; 8.29; 8.23; | 1200 ~ 1260
|
||||
10 000 | 8.01; 7.98; 8.26; | 1200 ~ 1250
|
||||
15 000 | 15.8; 16.3; 16.4; | 914 ~ 949
|
||||
--------------------------------------------------------------------------------------------
|
||||
|
||||
Select 20000 rows in 38.6 sec. --> 518 rows/sec
|
||||
336
utils/testEntr.c
Normal file
336
utils/testEntr.c
Normal file
@@ -0,0 +1,336 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: testEntr.c,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 1.1 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2006/02/28 23:28:21 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* This file is part of LibDataBase */
|
||||
/* */
|
||||
/* LibDataBase is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU Lesser General Public Licence as published by */
|
||||
/* the Free Software Foundation; either version 2.1 of the License, or */
|
||||
/* (at your option) any later version. */
|
||||
/* */
|
||||
/* LibDataBase is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU Lesser General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU Lesser General Public License */
|
||||
/* along with LibDataBase; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include <tool.h>
|
||||
#include "../lib/database.h"
|
||||
#include "testEntr.h"
|
||||
#include "testEntrColumns.h"
|
||||
|
||||
|
||||
/* Globals */
|
||||
extern DBT_HostVar hv[];
|
||||
extern DBT_Indicator *indic[];
|
||||
|
||||
int totalRowsProcessed = 0;
|
||||
int arraySize = 1;
|
||||
int columnsCount = 3;
|
||||
int showResult = 0;
|
||||
int from = 0;
|
||||
int count = 0;
|
||||
int debugLevel = 0;
|
||||
char *req = NULL;
|
||||
const char *login = "";
|
||||
const char *pwd = "";
|
||||
const char *server = "";
|
||||
|
||||
DBT_Connection conn;
|
||||
DBT_Statement st;
|
||||
DBT_Result res;
|
||||
|
||||
|
||||
/**
|
||||
* Main.
|
||||
*/
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
DBT_Status rc;
|
||||
TOOLT_Counter *counter = NULL;
|
||||
|
||||
|
||||
/* Parse arguments */
|
||||
parseArgs(argc, argv);
|
||||
|
||||
req = createSelectRequest(columnsCount);
|
||||
|
||||
|
||||
counter = TOOL_Counter_Alloc(1);
|
||||
rc = DB_Library_Open(DBD_DEBUG | DBD_ERRMSG);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not open library (%s)\n", DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Connect to Database */
|
||||
rc = DB_Connect(&conn, login, pwd, server);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not connect (%s)\n", DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
say("\n==== SELECT ===================================================\n");
|
||||
|
||||
/* Init data that are going to be selected then inserted */
|
||||
say("Setup data and HostVars\n");
|
||||
setupData(arraySize);
|
||||
if (setupHostVars() == FALSE)
|
||||
return 1;
|
||||
|
||||
/* Init statement */
|
||||
rc = DB_Statement_Init(&conn, &st);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not init statement (err %d: %s)\n", rc, DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
say("Preparing statement for query: '%s'\n", req);
|
||||
rc = DB_Statement_Prepare(&st, req);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not prepare statement (err %d: %s)\n", rc, DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Associate nth hostvar to nth column (note: first column index is 1) */
|
||||
say("Define output vars\n");
|
||||
for (i=0; i < columnsCount; ++i) {
|
||||
rc = DB_Statement_DefineVar(&st, arraySize, i+1, &hv[i]);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not define vars (%s)\n", DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
say("Executing Statement (from row %d, count=%d)...\n", from, count);
|
||||
TOOL_Counter_Start(counter, 0);
|
||||
|
||||
/* Note: 'count' is not relevant here: the number of rows fetched will be equal
|
||||
to the size of the array of defined values (set by DB_Statement_DefineVars).
|
||||
IMPORTANT: However, if some hostvars are bound to placeholders (:1, :2, etc.) in a
|
||||
SELECT statement with DB_Statement_BindVars(), 'count' must be equal to 1 !
|
||||
No array allowed. */
|
||||
rc = DB_Statement_Execute(&st, from, count, &res);
|
||||
TOOL_Counter_Stop(counter, 0);
|
||||
|
||||
|
||||
/* Display results of SELECT request */
|
||||
if (rc == DBS_OK || rc == DBS_END_OF_DATA) {
|
||||
say("Result = %s; %d rows processed in %ld ms\n", ERROR_TO_STRING(rc), res.rowsProcessed, TOOL_Counter_Get(counter, 0));
|
||||
if (showResult)
|
||||
displayValues(res.rowsProcessed);
|
||||
}
|
||||
else {
|
||||
say("Error: %s", DB_Error_Message_Get());
|
||||
say("%d rows processed (error at iteration %d)\n", res.rowsProcessed, res.errorIteration);
|
||||
}
|
||||
|
||||
/* If you want to execute another SELECT request, you should cancel the current
|
||||
cursor (to destroy pre-fetch rows) with: */
|
||||
if (DB_Statement_Fetch_Terminate(&st) != DBS_OK)
|
||||
say("Error: Could not cancel pre-fetch cursor\n");
|
||||
|
||||
|
||||
|
||||
say("\n\n==== INSERT ===================================================\n");
|
||||
|
||||
free(req);
|
||||
req = createInsertRequest(columnsCount);
|
||||
|
||||
/* Note that although we use the same statement as for SELECT, we could use a new one. */
|
||||
say("Preparing statement for query: '%s'\n", req);
|
||||
rc = DB_Statement_Prepare(&st, req);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not prepare statement (err %d: %s)\n", rc, DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Associate nth hostvar to nth placeholder (note: first placeholder index is 1) */
|
||||
say("Bind Vars\n");
|
||||
for (i=0; i < columnsCount; ++i) {
|
||||
rc = DB_Statement_BindVar(&st, arraySize, i+1, &hv[i]);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not bind vars (%s)\n", DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Start transaction */
|
||||
say("Start Transaction\n");
|
||||
DB_Transaction_Start(&conn);
|
||||
|
||||
say("Executing Statement (array size: %d; starting from row %d, %d by %d)...\n", arraySize, from, count, count);
|
||||
TOOL_Counter_Start(counter, 0);
|
||||
|
||||
while (from < arraySize) {
|
||||
if (from + count > arraySize)
|
||||
count = arraySize - from;
|
||||
|
||||
rc = DB_Statement_Execute(&st, from, count, &res);
|
||||
totalRowsProcessed += res.rowsProcessed;
|
||||
|
||||
if (DB_ERROR(rc))
|
||||
break;
|
||||
|
||||
from += count;
|
||||
}
|
||||
|
||||
TOOL_Counter_Stop(counter, 0);
|
||||
|
||||
if (DB_ERROR(rc)) {
|
||||
say("Error: %s", DB_Error_Message_Get());
|
||||
say("%d rows processed (error at iteration %d)\n", totalRowsProcessed, res.errorIteration);
|
||||
}
|
||||
else {
|
||||
say("OK, %d rows processed in %ld ms\n", totalRowsProcessed, TOOL_Counter_Get(counter, 0));
|
||||
}
|
||||
|
||||
/* End transaction */
|
||||
say("Committing Transaction\n\n");
|
||||
DB_Transaction_Commit(&conn);
|
||||
|
||||
DB_Statement_Close(&st);
|
||||
|
||||
/* End of work */
|
||||
if (req)
|
||||
free(req);
|
||||
TOOL_Counter_Free(counter);
|
||||
|
||||
DB_Disconnect(&conn);
|
||||
DB_Library_Close();
|
||||
say("End.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Affichage sur la sortie standard.
|
||||
*/
|
||||
void say(const char *format, ...) {
|
||||
char buffer[1024];
|
||||
va_list v;
|
||||
|
||||
va_start(v, format);
|
||||
vsnprintf(buffer, sizeof(buffer), format, v);
|
||||
fprintf (stdout, "%s", buffer);
|
||||
|
||||
va_end(v);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Arguments.
|
||||
*/
|
||||
void parseArgs(int argc, char **argv) {
|
||||
int i = 0;
|
||||
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if (! strcasecmp(argv[i], "--debuglevel")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
debugLevel = atoi(argv[i]);
|
||||
DB_Debug_Level_Set(debugLevel);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--from")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
from = atoi(argv[i]);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--count")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
count = atoi(argv[i]);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--db")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
splitDBSpec(argv[i], &login, &pwd, &server);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--col")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
columnsCount = atoi(argv[i]);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--show")) {
|
||||
showResult = 1;
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--size")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
arraySize = atoi(argv[i]);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--help") || ! strcasecmp(argv[i], "-h") || ! strcasecmp(argv[i], "-?")) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage.
|
||||
*/
|
||||
void usage(char **argv) {
|
||||
char *b = basename(argv[0]);
|
||||
printf(USAGE, b, b, b);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Splits a database specification in the format "login/password@server" into its
|
||||
* basic components 'login', 'password' and 'server'.
|
||||
* Note that the initial 'spec' string may be altered.
|
||||
*/
|
||||
void splitDBSpec(char *spec, const char **login_, const char **pwd_, const char **server_) {
|
||||
char *p = NULL;
|
||||
|
||||
*login_ = spec;
|
||||
p = strchr(spec, '/');
|
||||
if (p == NULL)
|
||||
return;
|
||||
|
||||
*p = 0;
|
||||
*pwd_ = ++p;
|
||||
|
||||
p = strchr(p, '@');
|
||||
if (p == NULL)
|
||||
return;
|
||||
*p = 0;
|
||||
*server_ = ++p;
|
||||
}
|
||||
65
utils/testEntr.h
Normal file
65
utils/testEntr.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: testEntr.h,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 1.1 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2006/02/28 23:28:21 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* This file is part of LibDataBase */
|
||||
/* */
|
||||
/* LibDataBase is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU Lesser General Public Licence as published by */
|
||||
/* the Free Software Foundation; either version 2.1 of the License, or */
|
||||
/* (at your option) any later version. */
|
||||
/* */
|
||||
/* LibDataBase is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU Lesser General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU Lesser General Public License */
|
||||
/* along with LibDataBase; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef TESTENTR_H
|
||||
#define TESTENTR_H
|
||||
|
||||
|
||||
#define USAGE "Usage: %s [--from <n>] [--count <c>] [--db <db>] [--show] [--size <s>] [--col <c>]\n\n\
|
||||
Selects columns from table TB_PERSONNE_PHYSIQUE then inserts them into table TEST_ENS.\n\
|
||||
Options:\n\
|
||||
--from:\tStarting row in the array from which retrieved data will be put (default: 0).\n\
|
||||
--count:\tRows count to retrieve and insert (default: 0).\n\
|
||||
--db:\t\tDatabase specification in the format: login/password@server.\n\
|
||||
--show:\tIf specified, the results of the SELECT are shown.\n\
|
||||
--col:\tColumns count to fetch and insert for each row (default: 3).\n\
|
||||
--size:\tTotal size of the array that will contain selected values (default: 1).\n\
|
||||
\n\
|
||||
Examples:\n\
|
||||
_ '%s --db entr/entr@pbdme1 --size 10000 --count 1000 --col 38' selects 10000 rows of 38\n\
|
||||
columns from table TB_PERSONNE_PHYSIQUE and inserts them 1000 by 1000 into table TEST_ENS.\n\
|
||||
_ '%s --db entr/entr@pbdme1 --size 50 --count 50 --col 4 --show' selects 50 rows of 4\n\
|
||||
columns from TB_PERSONNE_PHYSIQUE, displays values then inserts them 50 by 50 into TEST_ENS.\n"
|
||||
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
extern int strcasecmp(const char *, const char *);
|
||||
extern char *strdup(const char *);
|
||||
|
||||
void parseArgs(int argc, char **argv);
|
||||
void usage(char **argv);
|
||||
void say (const char *format, ...);
|
||||
void splitDBSpec(char *spec, const char **login, const char **pwd, const char **server);
|
||||
|
||||
|
||||
#endif
|
||||
189
utils/testEntrColumns.c
Normal file
189
utils/testEntrColumns.c
Normal file
@@ -0,0 +1,189 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: testEntrColumns.c,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 1.1 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2006/02/28 23:28:21 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* This file is part of LibDataBase */
|
||||
/* */
|
||||
/* LibDataBase is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU Lesser General Public Licence as published by */
|
||||
/* the Free Software Foundation; either version 2.1 of the License, or */
|
||||
/* (at your option) any later version. */
|
||||
/* */
|
||||
/* LibDataBase is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU Lesser General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU Lesser General Public License */
|
||||
/* along with LibDataBase; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "../lib/database.h"
|
||||
#include "testEntr.h"
|
||||
#include "testEntrColumns.h"
|
||||
|
||||
|
||||
/* Globals */
|
||||
extern int columnsCount; /* cf. testEntr.c */
|
||||
DBT_HostVar hv[MAX_COLUMNS]; /* One hostvar for each column */
|
||||
DBT_Indicator *indic[MAX_COLUMNS]; /* One array of indicator for each column */
|
||||
|
||||
const char *columnsNames[] = {
|
||||
"CT_PERSONNE_PHYSIQUE", "NUM_PP", "DAT_DER_MAJ_BDM", "DAT_CRE_PP_BDM", "CT_CG_RDP",
|
||||
"NUM_IDENT_CG_RDP", "DAT_CRE_CG_BDM_RDP", "CD_BQUE_RDP", "CD_GUI_CLI_RDP",
|
||||
"CD_ACT_ECO", "CD_PAYS_NAIS", "CD_SOGETYPE", "CD_SIT_FAM", "CD_CMN_INSEE_NAIS",
|
||||
"CD_PAYS_RM", "CD_PAYS_RF", "CD_DEPT_NAIS", "CD_ST_PROF", "NOM_PAT", "NOM_MAR",
|
||||
"PNOM_OFF", "PNOM_SUPP", "RAISON_SOC", "CT_FOYER_MKT", "CD_CAT_PROF", "CT_ADRESSE",
|
||||
"CD_SEXE", "CD_ST_INT_CHQ", "CD_ST_DECEDE", "CD_ST_COM_PP", "CD_ETA_PP", "CD_ST_TECH",
|
||||
"CD_IND_PP_ANO", "CD_CAP_JUR", "CD_UNIC_PP", "ADR_EMAIL", "DAT_DER_MAJ_BLPP", "CD_SEG_MAR"
|
||||
};
|
||||
|
||||
int columnsSizes[] = {
|
||||
INTEGER_SIZE, 8, DATE_SIZE, DATE_SIZE, INTEGER_SIZE, INTEGER_SIZE, DATE_SIZE, 6, 6, 3, 3,
|
||||
INTEGER_SIZE, 3, 3, 3, 3, 3, 3, 33, 33, 33, 33, 41, INTEGER_SIZE, 3, INTEGER_SIZE, 3,
|
||||
INTEGER_SIZE, 3, INTEGER_SIZE, INTEGER_SIZE, INTEGER_SIZE, 2, INTEGER_SIZE, INTEGER_SIZE,
|
||||
81, DATE_SIZE, 6
|
||||
};
|
||||
|
||||
int columnsTypes[] = {
|
||||
DBD_INTEGER, DBD_STRING, DBD_STRING, DBD_STRING, DBD_INTEGER, DBD_INTEGER, DBD_STRING,
|
||||
DBD_STRING, DBD_STRING, DBD_STRING, DBD_STRING, DBD_INTEGER, DBD_STRING, DBD_STRING,
|
||||
DBD_STRING, DBD_STRING, DBD_STRING, DBD_STRING, DBD_STRING, DBD_STRING,
|
||||
DBD_STRING, DBD_STRING, DBD_STRING, DBD_INTEGER, DBD_STRING, DBD_INTEGER, DBD_STRING,
|
||||
DBD_INTEGER, DBD_STRING, DBD_INTEGER, DBD_INTEGER, DBD_INTEGER, DBD_STRING, DBD_INTEGER,
|
||||
DBD_INTEGER, DBD_STRING, DBD_STRING, DBD_STRING
|
||||
};
|
||||
|
||||
void *columnsValues[MAX_COLUMNS];
|
||||
|
||||
|
||||
/**
|
||||
* Initializes host variables.
|
||||
* Associates an 'hostvar' with a type, size, array of values and array of indicators
|
||||
* for each column.
|
||||
*/
|
||||
int setupHostVars(void) {
|
||||
int i = 0;
|
||||
DBT_Status rc;
|
||||
|
||||
for (i = 0; i < columnsCount; ++i) {
|
||||
rc = DB_HostVar_Setup(&hv[i], columnsTypes[i], columnsSizes[i], columnsValues[i], indic[i]);
|
||||
if (rc != DBS_OK) {
|
||||
say("Error: %s\n", DB_Error_Message_Get());
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setup arrays.
|
||||
* n (IN): Rows count to allocate for each array.
|
||||
*/
|
||||
void setupData(int n) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < columnsCount; ++i) {
|
||||
/* Allocate array of indicators for each column */
|
||||
indic[i] = malloc(n * sizeof(int));
|
||||
|
||||
/* Allocate arrays of values for each column */
|
||||
columnsValues[i] = malloc((unsigned) n * columnsSizes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dynamically creates the SELECT request according to the number of columns involved.
|
||||
*/
|
||||
char *createSelectRequest(int columns) {
|
||||
int i;
|
||||
char *s = (char *) malloc(2000);
|
||||
|
||||
strcpy(s, "SELECT ");
|
||||
for (i = 0; i < columns; ++i) {
|
||||
strcat(s, columnsNames[i]);
|
||||
if (i < columns -1)
|
||||
strcat(s, ", ");
|
||||
}
|
||||
strcat(s, " FROM tb_personne_physique");
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dynamically creates the INSERT request according to the number of columns involved.
|
||||
*/
|
||||
char *createInsertRequest(int columns) {
|
||||
int i;
|
||||
char val[8];
|
||||
char *s = (char *) malloc(2000);
|
||||
|
||||
strcpy(s, "INSERT INTO test_ens (");
|
||||
for (i = 0; i < columns; ++i) {
|
||||
strcat(s, columnsNames[i]);
|
||||
if (i < columns -1)
|
||||
strcat(s, ", ");
|
||||
}
|
||||
strcat(s, ") VALUES (");
|
||||
|
||||
for (i = 0; i < columns; ++i) {
|
||||
sprintf(val, ":%d", i+1);
|
||||
strcat(s, val);
|
||||
if (i < columns -1)
|
||||
strcat(s, ", ");
|
||||
}
|
||||
strcat(s, ")");
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dynamically displays values of each column according to their type.
|
||||
*/
|
||||
void displayValues(int rowsCount) {
|
||||
int row;
|
||||
int col;
|
||||
|
||||
say("Columns %d to %d:\n", 1, columnsCount);
|
||||
for (row = 0; row < rowsCount; row++) {
|
||||
say("#%d\t", row);
|
||||
for (col = 0; col < columnsCount; col++) {
|
||||
if (indic[col][row] == -1) {
|
||||
printf("<NULL> ");
|
||||
}
|
||||
else {
|
||||
if (columnsTypes[col] == DBD_INTEGER) {
|
||||
int v = ((int *)(columnsValues[col])) [row];
|
||||
printf("%d ", v);
|
||||
/* indicator at -2 or > 0 means data have been truncated */
|
||||
if (indic[col][row] != 0)
|
||||
printf("<trunc> ");
|
||||
}
|
||||
else if (columnsTypes[col] == DBD_STRING) {
|
||||
char *v = & ((char *)(columnsValues[col])) [row * columnsSizes[col]];
|
||||
printf("%s ", v);
|
||||
if (indic[col][row] != 0)
|
||||
printf("<trunc> ");
|
||||
}
|
||||
else {
|
||||
printf("<UNKNOWN TYPE> ");
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
48
utils/testEntrColumns.h
Normal file
48
utils/testEntrColumns.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: testEntrColumns.h,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 1.1 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2006/02/28 23:28:21 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* This file is part of LibDataBase */
|
||||
/* */
|
||||
/* LibDataBase is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU Lesser General Public Licence as published by */
|
||||
/* the Free Software Foundation; either version 2.1 of the License, or */
|
||||
/* (at your option) any later version. */
|
||||
/* */
|
||||
/* LibDataBase is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU Lesser General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU Lesser General Public License */
|
||||
/* along with LibDataBase; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef TESTENTRCOLUMNS_H
|
||||
#define TESTENTRCOLUMNS_H
|
||||
|
||||
|
||||
#define MAX_COLUMNS 38
|
||||
#define STRING_SIZE 20
|
||||
#define DATE_SIZE 20
|
||||
#define INTEGER_SIZE sizeof(int)
|
||||
|
||||
int setupHostVars(void);
|
||||
void setupData(int n);
|
||||
char *createSelectRequest(int columns);
|
||||
char *createInsertRequest(int columns);
|
||||
void displayValues(int rowsCount);
|
||||
|
||||
|
||||
#endif
|
||||
368
utils/testInsert.c
Normal file
368
utils/testInsert.c
Normal file
@@ -0,0 +1,368 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: testInsert.c,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 1.1 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2006/02/28 23:28:21 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* This file is part of LibDataBase */
|
||||
/* */
|
||||
/* LibDataBase is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU Lesser General Public Licence as published by */
|
||||
/* the Free Software Foundation; either version 2.1 of the License, or */
|
||||
/* (at your option) any later version. */
|
||||
/* */
|
||||
/* LibDataBase is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU Lesser General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU Lesser General Public License */
|
||||
/* along with LibDataBase; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include <tool.h>
|
||||
#include "../lib/database.h"
|
||||
|
||||
|
||||
/* Globals */
|
||||
#define DEFAULT_REQUEST "INSERT INTO dummy (c1, c2, c3) VALUES (:1, :2, :3)"
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
const char *USAGE = "Usage: %s [--req <SQL Request>] [--from <n>] [--count <c>] [--db <db>] [--size <s>] [--baseIndex <i>]\n\n\
|
||||
Executes an INSERT SQL request in a table which must have the following format:\n\
|
||||
\"CREATE TABLE dummy (c1 NUMBER(35) primary key, c2 VARCHAR2(16), c3 NUMBER(10))\".\n\
|
||||
Data to insert are taken from an array which elements are generated by the program (see\n\
|
||||
option --baseIndex).\n\
|
||||
\n\
|
||||
Options:\n\
|
||||
--req:\tExecutes specified request. If not specified, a default request is used:\n\
|
||||
\t\"INSERT INTO dummy (c1, c2, c3) VALUES (:1, :2, :3)\".\n\
|
||||
--from:\tStarting row in the array of input data (default: 0).\n\
|
||||
--count:\tRows count to use in the input array (1 to 65536) (Default: 0).\n\
|
||||
--size:\tTotal number of rows of the input array generated by the program (default: 1).\n\
|
||||
--db:\t\tDatabase specification in the format: login/password@oracleSID.\n\
|
||||
--baseIndex:\tStart index to use to create input data. Ex: if baseIndex = 10, first row\n\
|
||||
to insert will have columns values: 10, 'A10', 110; second row will have\n\
|
||||
11, 'A11', 111; etc. (default: 1).\n\
|
||||
\n\
|
||||
Examples:\n\
|
||||
_ '%s --db \"login/pwd@srv\" --size 100 --count 20' will insert 5 times 20 rows in table dummy.\n\
|
||||
_ '%s --db \"login/pwd@srv\" --size 10 --count 4' will insert 2 times 4 rows then the 2\n\
|
||||
remaining rows.\n";
|
||||
|
||||
|
||||
extern int strcasecmp(const char *, const char *);
|
||||
extern char *strdup(const char *);
|
||||
void parseArgs(int argc, char **argv);
|
||||
void usage(char **argv);
|
||||
void say (const char *format, ...);
|
||||
int setupHostVars(void);
|
||||
void setupData(int n);
|
||||
void splitDBSpec(char *spec, const char **login, const char **pwd, const char **server);
|
||||
|
||||
|
||||
int arraySize = 1;
|
||||
int baseIndex = 0;
|
||||
int from = 0;
|
||||
int count = 0;
|
||||
int debugLevel = 0;
|
||||
char *req = NULL;
|
||||
const char *login = "";
|
||||
const char *pwd = "";
|
||||
const char *server = "";
|
||||
DBT_Connection conn;
|
||||
DBT_Statement st;
|
||||
DBT_Result res;
|
||||
|
||||
DBT_HostVar hv1;
|
||||
DBT_HostVar hv2;
|
||||
DBT_HostVar hv3;
|
||||
|
||||
int *dynInt1 = NULL;
|
||||
char *dynBuf = NULL;
|
||||
int *dynInt3 = NULL;
|
||||
|
||||
DBT_Indicator *dynIndic1 = NULL;
|
||||
DBT_Indicator *dynIndic2 = NULL;
|
||||
DBT_Indicator *dynIndic3 = NULL;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Main.
|
||||
*/
|
||||
int main(int argc, char **argv) {
|
||||
int totalRowsProcessed = 0;
|
||||
DBT_Status rc;
|
||||
TOOLT_Counter *counter = NULL;
|
||||
|
||||
|
||||
/* Parse arguments */
|
||||
parseArgs(argc, argv);
|
||||
|
||||
if (req == NULL) {
|
||||
req = strdup(DEFAULT_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
counter = TOOL_Counter_Alloc(1);
|
||||
rc = DB_Library_Open(DBD_DEBUG | DBD_ERRMSG);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not open library (%s)\n", DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Connect to Database */
|
||||
rc = DB_Connect(&conn, login, pwd, server);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not connect (%s)\n", DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Init data that are going to be inserted */
|
||||
say("Setup data and HostVars\n");
|
||||
setupData(arraySize);
|
||||
if (setupHostVars() == FALSE)
|
||||
return 1;
|
||||
|
||||
|
||||
/* Init statement */
|
||||
rc = DB_Statement_Init(&conn, &st);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not init statement (err %d: %s)\n", rc, DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
say("Preparing statement for query: '%s'\n", req);
|
||||
rc = DB_Statement_Prepare(&st, req);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not prepare statement (err %d: %s)\n", rc, DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
say("Bind Vars\n");
|
||||
rc = DB_Statement_BindVars(&st, arraySize, &hv1, &hv2, &hv3, NULL);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not bind vars (%s)\n", DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Start transaction */
|
||||
say("\nStart Transaction\n");
|
||||
DB_Transaction_Start(&conn);
|
||||
|
||||
say("Executing Statement (array size: %d; starting from row %d, %d by %d)...\n", arraySize, from, count, count);
|
||||
TOOL_Counter_Start(counter, 0);
|
||||
|
||||
while (from < arraySize) {
|
||||
if (from + count > arraySize)
|
||||
count = arraySize - from;
|
||||
|
||||
rc = DB_Statement_Execute(&st, from, count, &res);
|
||||
totalRowsProcessed += res.rowsProcessed;
|
||||
|
||||
if (DB_ERROR(rc))
|
||||
break;
|
||||
|
||||
from += count;
|
||||
}
|
||||
|
||||
/* End transaction */
|
||||
TOOL_Counter_Stop(counter, 0);
|
||||
|
||||
if (DB_ERROR(rc)) {
|
||||
say("Error: %s", DB_Error_Message_Get());
|
||||
say("%d rows processed (error at iteration %d)\n", totalRowsProcessed, res.errorIteration);
|
||||
}
|
||||
else {
|
||||
say("OK, %d rows processed in %ld ms\n", totalRowsProcessed, TOOL_Counter_Get(counter, 0));
|
||||
}
|
||||
|
||||
/*DB_Transaction_Rollback(&conn);*/
|
||||
say("Committing Transaction\n\n");
|
||||
DB_Transaction_Commit(&conn);
|
||||
|
||||
if (req)
|
||||
free(req);
|
||||
TOOL_Counter_Free(counter);
|
||||
|
||||
DB_Disconnect(&conn);
|
||||
DB_Library_Close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Affichage sur la sortie standard.
|
||||
*/
|
||||
void say(const char *format, ...) {
|
||||
char buffer[512];
|
||||
va_list v;
|
||||
|
||||
va_start(v, format);
|
||||
vsnprintf(buffer, sizeof(buffer), format, v);
|
||||
fprintf (stdout, "%s", buffer);
|
||||
|
||||
va_end(v);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Arguments.
|
||||
*/
|
||||
void parseArgs(int argc, char **argv) {
|
||||
int i = 0;
|
||||
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if (! strcasecmp(argv[i], "--debuglevel")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
debugLevel = atoi(argv[i]);
|
||||
DB_Debug_Level_Set(debugLevel);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--from")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
from = atoi(argv[i]);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--count")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
count = atoi(argv[i]);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--size")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
arraySize = atoi(argv[i]);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--baseIndex")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
baseIndex = atoi(argv[i]);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--req")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
req = strdup(argv[i]);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--db")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
splitDBSpec(argv[i], &login, &pwd, &server);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--help") || ! strcasecmp(argv[i], "-h") || ! strcasecmp(argv[i], "-?")) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage.
|
||||
*/
|
||||
void usage(char **argv) {
|
||||
char *b = basename(argv[0]);
|
||||
printf(USAGE, b, b, b);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes host variables.
|
||||
* Associates an 'hostvar' with a type, size, array of values and array of indicators.
|
||||
*/
|
||||
int setupHostVars(void) {
|
||||
|
||||
if (DB_HostVar_Setup(&hv1, DBD_INTEGER, 0, dynInt1, dynIndic1) != DBS_OK ||
|
||||
DB_HostVar_Setup(&hv2, DBD_STRING, 20, dynBuf, dynIndic2) != DBS_OK ||
|
||||
DB_HostVar_Setup(&hv3, DBD_INTEGER, 0, dynInt3, dynIndic3) != DBS_OK) {
|
||||
|
||||
say("Error: %s\n", DB_Error_Message_Get());
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setup arrays of values and indicators.
|
||||
* (IN) n: Rows count to allocate for each array.
|
||||
*/
|
||||
void setupData(int n) {
|
||||
int i;
|
||||
|
||||
dynInt1 = malloc(n * sizeof(int));
|
||||
dynBuf = malloc((unsigned) n * 20);
|
||||
dynInt3 = malloc(n * sizeof(int));
|
||||
|
||||
dynIndic1 = malloc(n * sizeof(int));
|
||||
dynIndic2 = malloc(n * sizeof(int));
|
||||
dynIndic3 = malloc(n * sizeof(int));
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
int x = i + baseIndex;
|
||||
dynIndic1[i] = 0;
|
||||
dynIndic2[i] = 0;
|
||||
dynIndic3[i] = 0;
|
||||
|
||||
dynInt1[i] = x;
|
||||
sprintf(dynBuf+20*i, "A%d", x);
|
||||
dynInt3[i] = 100+x;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Splits a database specification in the format "login/password@server" into its
|
||||
* basic components 'login', 'password' and 'server'.
|
||||
* Note that the initial 'spec' string may be altered.
|
||||
*/
|
||||
void splitDBSpec(char *spec, const char **login_, const char **pwd_, const char **server_) {
|
||||
char *p = NULL;
|
||||
|
||||
*login_ = spec;
|
||||
p = strchr(spec, '/');
|
||||
if (p == NULL)
|
||||
return;
|
||||
|
||||
*p = 0;
|
||||
*pwd_ = ++p;
|
||||
|
||||
p = strchr(p, '@');
|
||||
if (p == NULL)
|
||||
return;
|
||||
*p = 0;
|
||||
*server_ = ++p;
|
||||
}
|
||||
272
utils/testSelect.c
Normal file
272
utils/testSelect.c
Normal file
@@ -0,0 +1,272 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: testSelect.c,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 1.1 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2006/02/28 23:28:21 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* This file is part of LibDataBase */
|
||||
/* */
|
||||
/* LibDataBase is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU Lesser General Public Licence as published by */
|
||||
/* the Free Software Foundation; either version 2.1 of the License, or */
|
||||
/* (at your option) any later version. */
|
||||
/* */
|
||||
/* LibDataBase is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU Lesser General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU Lesser General Public License */
|
||||
/* along with LibDataBase; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <libgen.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <bdm.h>
|
||||
#include <database.h>
|
||||
|
||||
int main(int argc, char **argv);
|
||||
int parseArgs(int argc, char **argv, char **login, char **pwd, char **base, char **sql, int *tp);
|
||||
int sqlAnalyse(const char *sql);
|
||||
int execQuery(DBT_Connection *conn, const char *sql, int tp);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
DBT_Connection conn;
|
||||
DBT_Status rco;
|
||||
char *login = NULL;
|
||||
char *pwd = NULL;
|
||||
char *base = NULL;
|
||||
char *sql = NULL;
|
||||
int tp = 1;
|
||||
int rc = 1;
|
||||
|
||||
if (parseArgs(argc, argv, &login, &pwd, &base, &sql, &tp)) {
|
||||
BDM_Trace(0, "testSelect", "main", "Usage : %s options\n\n\
|
||||
Les options sont :\n\
|
||||
-sql ou --sql-query <requete SQL> : requête à exécuter\n\
|
||||
-ps ou --packet-size <taille paquets> : nombre de lignes par fetch (1 par défaut)\n\
|
||||
-db ou --db-connection <user/pwd@base> : paramètres de connexion à Oracle\n\
|
||||
--debug<n> : niveau de trace", basename(argv[0]));
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* connexion Oracle */
|
||||
DB_Library_Open(0);
|
||||
memset(&conn, 0, sizeof(conn));
|
||||
while (1) {
|
||||
rco = DB_Connect(&conn, login, pwd, base);
|
||||
if (DB_ERROR(rco)) break;
|
||||
while (1) {
|
||||
if (execQuery(&conn, sql, tp)) break;
|
||||
if (1) break;
|
||||
}
|
||||
DB_Disconnect(&conn);
|
||||
rc = 0;
|
||||
if (1) break;
|
||||
}
|
||||
|
||||
DB_Library_Close();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int parseArgs(int argc, char **argv, char **login, char **pwd, char **base, char **sql, int *tp) {
|
||||
int i = 1;
|
||||
|
||||
while (i < argc) {
|
||||
if (!strcmp(argv[i], "-sql") || !strcmp(argv[i], "--sql-query")) {
|
||||
if (++i == argc) {
|
||||
BDM_Trace(0, "testSelect", "parseArgs", "Paramètre attendu après %s", argv[i - 1]);
|
||||
return 1;
|
||||
}
|
||||
if (*sql) BDM_Trace(1, "testSelect", "parseArgs", "Une seule requête SQL attendue : seule la dernière est prise en compte");
|
||||
*sql = argv[i++];
|
||||
} else if (!strcmp(argv[i], "-ps") || !strcmp(argv[i], "--packet-size")) {
|
||||
if (++i == argc) {
|
||||
BDM_Trace(0, "testSelect", "parseArgs", "Paramètre attendu après %s", argv[i - 1]);
|
||||
return 1;
|
||||
}
|
||||
if (atoi(argv[i]) < 1) {
|
||||
BDM_Trace(0, "testSelect", "parseArgs", "Le nombre de lignes par fetch doit être > 0");
|
||||
return 1;
|
||||
}
|
||||
*tp = atoi(argv[i++]);
|
||||
} else if (!strcmp(argv[i], "-db") || !strcmp(argv[i], "--db-connection")) {
|
||||
char *start, *end;
|
||||
if (++i == argc) {
|
||||
BDM_Trace(0, "testSelect", "parseArgs", "Paramètre attendu après %s", argv[i - 1]);
|
||||
return 1;
|
||||
}
|
||||
start = argv[i++];
|
||||
end = start;
|
||||
while (*end && *end != '/') ++end;
|
||||
if (!*end) return 1;
|
||||
*end = '\0';
|
||||
*login = start;
|
||||
start = ++end;
|
||||
while (*end && *end != '@') ++end;
|
||||
*pwd = start;
|
||||
if (*end == '@') {
|
||||
*end = '\0';
|
||||
*base = end + 1;
|
||||
}
|
||||
} else if (!strncmp(argv[i], "--debug", 7)) {
|
||||
int level;
|
||||
level = atoi(argv[i++] + 7);
|
||||
if (level < 0) {
|
||||
BDM_Trace(0, "testSelect", "parseArgs", "Le niveau de trace doit être fixé par --debug<n> : --debug2, --debug5, etc");
|
||||
return 1;
|
||||
}
|
||||
BDM_Trace_SetLevel(level, "testSelect");
|
||||
} else {
|
||||
BDM_Trace(0, "testSelect", "parseArgs", "Option %s non reconnue", argv[i]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!*sql) {
|
||||
BDM_Trace(0, "testSelect", "parseArgs", "Option -sql obligatoire");
|
||||
return 1;
|
||||
}
|
||||
if (!*login) {
|
||||
BDM_Trace(0, "testSelect", "parseArgs", "Option -db obligatoire");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sqlAnalyse(const char *sql) {
|
||||
int colCount = 0;
|
||||
int par = 0;
|
||||
const char *ptr;
|
||||
const char *sep = "() \t\n\r";
|
||||
|
||||
BDM_Trace(3, "testSelect", "sqlAnalyse", "Analyse de \"%s\"", sql);
|
||||
|
||||
/* ptr : début de la 1ère colonne */
|
||||
ptr = sql;
|
||||
while (*ptr && strchr(sep, *ptr) == NULL) ++ptr;
|
||||
|
||||
while (*ptr) {
|
||||
if (*ptr == '(') {
|
||||
++par;
|
||||
++ptr;
|
||||
continue;
|
||||
}
|
||||
if (*ptr == ')') {
|
||||
if (!par) {
|
||||
BDM_Trace(0, "testSelect", "sqlAnalyse", ") rencontré sans ( : %s", ptr);
|
||||
return 0;
|
||||
}
|
||||
--par;
|
||||
++ptr;
|
||||
continue;
|
||||
}
|
||||
if (*ptr == ',' && !par) {
|
||||
++colCount;
|
||||
++ptr;
|
||||
continue;
|
||||
}
|
||||
if (strchr(sep, *ptr)) {
|
||||
char tmp[6];
|
||||
int i;
|
||||
strncpy(tmp, ptr + 1, 5);
|
||||
tmp[5] = '\0';
|
||||
for (i = 0; i < 5; ++i)
|
||||
if (tmp[i] >= 'A' && tmp[i] <= 'Z') tmp[i] += 'a' - 'A';
|
||||
if (!strcmp(tmp, "from ")) {
|
||||
++colCount;
|
||||
break;
|
||||
}
|
||||
++ptr;
|
||||
continue;
|
||||
}
|
||||
++ptr;
|
||||
}
|
||||
|
||||
if (!*ptr) {
|
||||
BDM_Trace(0, "testSelect", "sqlAnalyse", "FROM non trouvé dans la requête");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!colCount) {
|
||||
BDM_Trace(0, "testSelect", "sqlAnalyse", "Aucune colonne n'a été identifiée");
|
||||
return 0;
|
||||
}
|
||||
|
||||
BDM_Trace(2, "testSelect", "sqlAnalyse", "La requête devrait retourner %d colonnes", colCount);
|
||||
|
||||
return colCount;
|
||||
}
|
||||
|
||||
int execQuery(DBT_Connection *conn, const char *sql, int tp) {
|
||||
int colCount = sqlAnalyse(sql);
|
||||
int idx;
|
||||
DBT_HostVar *hv = NULL;
|
||||
char *data = NULL;
|
||||
const int max = 100 + 1;
|
||||
DBT_Indicator *inull = NULL;
|
||||
DBT_Status rc = DBS_OK;
|
||||
DBT_Statement st;
|
||||
DBT_Result res;
|
||||
|
||||
/* nombre de colonnes */
|
||||
if (colCount == 0) return 1;
|
||||
|
||||
while (1) {
|
||||
BDM_Trace(3, "testSelect", "execQuery", "Préparation des variables pour %d colonnes x %d lignes", colCount, tp);
|
||||
/* HostVar */
|
||||
hv = (DBT_HostVar *)malloc(sizeof(DBT_HostVar) * colCount);
|
||||
memset(hv, 0, sizeof(DBT_HostVar) * colCount);
|
||||
/* data */
|
||||
data = (char *)malloc((size_t)tp * max * colCount);
|
||||
/* inull */
|
||||
inull = (DBT_Indicator *)malloc(sizeof(DBT_Indicator) * colCount * tp);
|
||||
for (idx = 0; !DB_ERROR(rc) && idx < colCount; ++idx)
|
||||
rc = DB_HostVar_Setup(&hv[idx], DBD_STRING, max, data + tp * max * idx, &inull[tp * idx]);
|
||||
if (DB_ERROR(rc)) break;
|
||||
rc = DB_Statement_Init(conn, &st);
|
||||
if (DB_ERROR(rc)) break;
|
||||
rc = DB_Statement_Prepare(&st, sql);
|
||||
if (DB_ERROR(rc)) break;
|
||||
for (idx = 0; !DB_ERROR(rc) && idx < colCount; ++idx)
|
||||
rc = DB_Statement_DefineVar(&st, tp, idx + 1, &hv[idx]);
|
||||
if (DB_ERROR(rc)) break;
|
||||
BDM_Trace(3, "testSelect", "execQuery", "Variables initialisées");
|
||||
|
||||
rc = DB_Statement_ExecuteSelect(&st, &res);
|
||||
while (rc == DBS_OK) {
|
||||
int nl;
|
||||
BDM_Trace(3, "testSelect", "execQuery", "Lecture de %d enregistrements", res.rowsProcessed);
|
||||
for (nl = 0; nl < res.rowsProcessed; ++nl) {
|
||||
for (idx = 0; idx < colCount; ++idx)
|
||||
printf("%s%s", idx ? ";" : "", inull[idx * tp + nl] ? "" : data + max * (idx * tp + nl));
|
||||
printf("\n");
|
||||
}
|
||||
if (st.isEOF) break;
|
||||
rc = DB_Statement_Fetch(&st, &res);
|
||||
}
|
||||
DB_Statement_Close(&st);
|
||||
if (1) break;
|
||||
}
|
||||
|
||||
free(inull);
|
||||
free(data);
|
||||
free(hv);
|
||||
|
||||
if (DB_ERROR(rc)) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
236
utils/testUpdate.c
Normal file
236
utils/testUpdate.c
Normal file
@@ -0,0 +1,236 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: testUpdate.c,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 1.1 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2006/02/28 23:28:21 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* This file is part of LibDataBase */
|
||||
/* */
|
||||
/* LibDataBase is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU Lesser General Public Licence as published by */
|
||||
/* the Free Software Foundation; either version 2.1 of the License, or */
|
||||
/* (at your option) any later version. */
|
||||
/* */
|
||||
/* LibDataBase is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU Lesser General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU Lesser General Public License */
|
||||
/* along with LibDataBase; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include <tool.h>
|
||||
#include "../lib/database.h"
|
||||
|
||||
|
||||
/* Globals */
|
||||
const char *USAGE = "Usage: %s --req <delete SQL request> --db <Database spec>\n\
|
||||
Executes an UPDATE, DELETE or any request that takes no variable argument nor produces\n\
|
||||
any output value (other than the number of rows processed).\n\
|
||||
Ex: _ \"CREATE TABLE tableX (col1 NUMBER(5) PRIMARY KEY, col2 VARCHAR2(10))\";\n\
|
||||
_ \"INSERT INTO tableX VALUES (1, 'A')\";\n\
|
||||
_ \"UPDATE tableX SET col1=col1+1, col2='ABC' WHERE col1 < 10\";\n\
|
||||
_ \"DELETE FROM tableX WHERE col2=1\";\n\
|
||||
_ \"DROP TABLE tableX\".\n\
|
||||
\n\
|
||||
Command line arguments:\n\
|
||||
--req The SQL request.\n\
|
||||
--db Database on which to operate. Format: \"login/pwd@server\"\n";
|
||||
|
||||
|
||||
extern int strcasecmp(const char *, const char *);
|
||||
extern char *strdup(const char *);
|
||||
void parseArgs(int argc, char **argv);
|
||||
void usage(char **argv);
|
||||
void say (const char *format, ...);
|
||||
void splitDBSpec(char *spec, const char **login, const char **pwd, const char **server);
|
||||
|
||||
int debugLevel = 0;
|
||||
char *req = NULL;
|
||||
const char *login = "";
|
||||
const char *pwd = "";
|
||||
const char *server = "";
|
||||
DBT_Connection conn;
|
||||
DBT_Statement st;
|
||||
DBT_Result res;
|
||||
|
||||
|
||||
/**
|
||||
* Main.
|
||||
*/
|
||||
int main(int argc, char **argv) {
|
||||
DBT_Status rc;
|
||||
TOOLT_Counter *counter = NULL;
|
||||
|
||||
|
||||
/* Parse arguments */
|
||||
parseArgs(argc, argv);
|
||||
if (req == NULL) {
|
||||
usage(argv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
counter = TOOL_Counter_Alloc(1);
|
||||
|
||||
rc = DB_Library_Open(DBD_DEBUG | DBD_ERRMSG);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not open library (%s)\n", DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Connect to Database */
|
||||
say("Connecting to %s/%s@%s...\n", login, pwd, server);
|
||||
rc = DB_Connect(&conn, login, pwd, server);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not connect (%s)\n", DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Init statement */
|
||||
rc = DB_Statement_Init(&conn, &st);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not init statement (err %d)\n", rc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
say("Preparing statement for query: '%s'\n", req);
|
||||
rc = DB_Statement_Prepare(&st, req);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not prepare statement (err %d)\n", rc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Start transaction */
|
||||
say("Start Transaction\n");
|
||||
DB_Transaction_Start(&conn);
|
||||
|
||||
say("\nExecuting Statement...\n");
|
||||
TOOL_Counter_Start(counter, 0);
|
||||
rc = DB_Statement_Execute(&st, 0, 1, &res);
|
||||
TOOL_Counter_Stop(counter, 0);
|
||||
|
||||
if (DB_ERROR(rc)) {
|
||||
say("Error: %s", DB_Error_Message_Get());
|
||||
say("%d rows processed (error at iteration %d)\n", res.rowsProcessed, res.errorIteration);
|
||||
}
|
||||
else {
|
||||
say("OK, %d rows processed in %ld ms\n", res.rowsProcessed, TOOL_Counter_Get(counter, 0));
|
||||
}
|
||||
|
||||
|
||||
/*DB_Transaction_Rollback(&conn);*/
|
||||
|
||||
say("\nCommitting Transaction\n");
|
||||
DB_Transaction_Commit(&conn);
|
||||
|
||||
if (req)
|
||||
free(req);
|
||||
TOOL_Counter_Free(counter);
|
||||
|
||||
DB_Disconnect(&conn);
|
||||
DB_Library_Close();
|
||||
say("End.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Affichage sur la sortie standard.
|
||||
*/
|
||||
void say(const char *format, ...) {
|
||||
char buffer[512];
|
||||
va_list v;
|
||||
|
||||
va_start(v, format);
|
||||
vsnprintf(buffer, sizeof(buffer), format, v);
|
||||
fprintf (stdout, "%s", buffer);
|
||||
|
||||
va_end(v);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Arguments.
|
||||
*/
|
||||
void parseArgs(int argc, char **argv) {
|
||||
int i = 0;
|
||||
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if (! strcasecmp(argv[i], "--debuglevel")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
debugLevel = atoi(argv[i]);
|
||||
DB_Debug_Level_Set(debugLevel);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--req")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
req = strdup(argv[i]);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--db")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
splitDBSpec(argv[i], &login, &pwd, &server);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--help") || ! strcasecmp(argv[i], "-h") || ! strcasecmp(argv[i], "-?")) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage.
|
||||
*/
|
||||
void usage(char **argv) {
|
||||
printf(USAGE, basename(argv[0]));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Splits a database specification in the format "login/password@server" into its
|
||||
* basic components 'login', 'password' and 'server'.
|
||||
* Note that the initial 'spec' string may be altered.
|
||||
*/
|
||||
void splitDBSpec(char *spec, const char **login_, const char **pwd_, const char **server_) {
|
||||
char *p = NULL;
|
||||
|
||||
*login_ = spec;
|
||||
p = strchr(spec, '/');
|
||||
if (p == NULL)
|
||||
return;
|
||||
|
||||
*p = 0;
|
||||
*pwd_ = ++p;
|
||||
|
||||
p = strchr(p, '@');
|
||||
if (p == NULL)
|
||||
return;
|
||||
*p = 0;
|
||||
*server_ = ++p;
|
||||
}
|
||||
338
utils/testUpdateArray.c
Normal file
338
utils/testUpdateArray.c
Normal file
@@ -0,0 +1,338 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: testUpdateArray.c,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 1.1 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2006/02/28 23:28:21 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* This file is part of LibDataBase */
|
||||
/* */
|
||||
/* LibDataBase is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU Lesser General Public Licence as published by */
|
||||
/* the Free Software Foundation; either version 2.1 of the License, or */
|
||||
/* (at your option) any later version. */
|
||||
/* */
|
||||
/* LibDataBase is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU Lesser General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU Lesser General Public License */
|
||||
/* along with LibDataBase; if not, write to the Free Software */
|
||||
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#include <tool.h>
|
||||
#include "../lib/database.h"
|
||||
|
||||
|
||||
/* Globals */
|
||||
const char *USAGE = "Usage: %s --db <Database spec> [--req <delete SQL request>]\n\
|
||||
Executes an UPDATE request using an array as comparison values. The request is:\n\
|
||||
\"update dummy set c1=:1 where c3=:2\".\n\
|
||||
The table 'dummy' should have the following format:\n\
|
||||
\"CREATE TABLE dummy (c1 NUMBER(35) primary key, c2 VARCHAR2(16), c3 NUMBER(10))\".\n\
|
||||
Try with the following data:\n\
|
||||
1 ABC 100\n\
|
||||
2 ABC 101\n\
|
||||
3 ABC 102\n\
|
||||
4 ABC 103\n\
|
||||
5 ABC 104\n\
|
||||
\n\
|
||||
Command line arguments:\n\
|
||||
--req Another SQL request, if you whish - Be careful that there are only 2 placeholders (:1 and :2).\n\
|
||||
--db Database on which to operate. Format: \"login/pwd@server\"\n";
|
||||
|
||||
|
||||
extern int strcasecmp(const char *, const char *);
|
||||
extern char *strdup(const char *);
|
||||
void parseArgs(int argc, char **argv);
|
||||
void usage(char **argv);
|
||||
void say (const char *format, ...);
|
||||
void splitDBSpec(char *spec, const char **login, const char **pwd, const char **server);
|
||||
int setupHostVars(void);
|
||||
void setupData(int n);
|
||||
|
||||
|
||||
int debugLevel = 0;
|
||||
int arraySize = 3;
|
||||
int baseIndex = 0;
|
||||
char *req = NULL;
|
||||
const char *login = "";
|
||||
const char *pwd = "";
|
||||
const char *server = "";
|
||||
DBT_Connection conn;
|
||||
DBT_Statement st;
|
||||
DBT_Result res;
|
||||
|
||||
DBT_HostVar hv1;
|
||||
DBT_HostVar hv2;
|
||||
DBT_HostVar hv3;
|
||||
|
||||
int *dynInt1 = NULL;
|
||||
int *dynInt2 = NULL;
|
||||
int *dynInt3 = NULL;
|
||||
|
||||
DBT_Indicator *dynIndic1 = NULL;
|
||||
DBT_Indicator *dynIndic2 = NULL;
|
||||
DBT_Indicator *dynIndic3 = NULL;
|
||||
|
||||
|
||||
/**
|
||||
* Main.
|
||||
*/
|
||||
int main(int argc, char **argv) {
|
||||
DBT_Status rc;
|
||||
TOOLT_Counter *counter = NULL;
|
||||
|
||||
|
||||
/* Parse arguments */
|
||||
parseArgs(argc, argv);
|
||||
if (req == NULL) {
|
||||
/*req = strdup("update dummy set c1=:1 where c3=:2");*/
|
||||
req = strdup("update dummy set c1=:1 where :2 = 0 and c3=:3");
|
||||
}
|
||||
|
||||
counter = TOOL_Counter_Alloc(1);
|
||||
|
||||
rc = DB_Library_Open(DBD_DEBUG | DBD_ERRMSG);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not open library (%s)\n", DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Connect to Database */
|
||||
say("Connecting to %s/%s@%s...\n", login, pwd, server);
|
||||
rc = DB_Connect(&conn, login, pwd, server);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not connect (%s)\n", DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Init data that are going to be inserted */
|
||||
say("Setup data and HostVars\n");
|
||||
setupData(arraySize);
|
||||
if (setupHostVars() == FALSE)
|
||||
return 1;
|
||||
|
||||
|
||||
/* Init statement */
|
||||
rc = DB_Statement_Init(&conn, &st);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not init statement (err %d)\n", rc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
say("Preparing statement for query: '%s'\n", req);
|
||||
rc = DB_Statement_Prepare(&st, req);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not prepare statement (err %d)\n", rc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
say("Bind Vars\n");
|
||||
rc = DB_Statement_BindVars(&st, arraySize, &hv1, &hv2, &hv3, NULL);
|
||||
if (DB_ERROR(rc)) {
|
||||
printf("Error: Could not bind vars (%s)\n", DB_Error_Message_Get());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* Start transaction */
|
||||
say("Start Transaction\n");
|
||||
DB_Transaction_Start(&conn);
|
||||
|
||||
say("\nExecuting Statement...\n");
|
||||
TOOL_Counter_Start(counter, 0);
|
||||
rc = DB_Statement_Execute(&st, 0, 3, &res);
|
||||
TOOL_Counter_Stop(counter, 0);
|
||||
|
||||
if (DB_ERROR(rc)) {
|
||||
say("Error: %s", DB_Error_Message_Get());
|
||||
say("%d rows processed (error at iteration %d)\n", res.rowsProcessed, res.errorIteration);
|
||||
}
|
||||
else {
|
||||
say("OK, %d rows processed in %ld ms\n", res.rowsProcessed, TOOL_Counter_Get(counter, 0));
|
||||
}
|
||||
|
||||
|
||||
/*DB_Transaction_Rollback(&conn);*/
|
||||
|
||||
say("\nCommitting Transaction\n");
|
||||
DB_Transaction_Commit(&conn);
|
||||
|
||||
if (req)
|
||||
free(req);
|
||||
TOOL_Counter_Free(counter);
|
||||
|
||||
DB_Disconnect(&conn);
|
||||
DB_Library_Close();
|
||||
say("End.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Affichage sur la sortie standard.
|
||||
*/
|
||||
void say(const char *format, ...) {
|
||||
char buffer[512];
|
||||
va_list v;
|
||||
|
||||
va_start(v, format);
|
||||
vsnprintf(buffer, sizeof(buffer), format, v);
|
||||
fprintf (stdout, "%s", buffer);
|
||||
|
||||
va_end(v);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Arguments.
|
||||
*/
|
||||
void parseArgs(int argc, char **argv) {
|
||||
int i = 0;
|
||||
|
||||
for (i = 1; i < argc; ++i) {
|
||||
if (! strcasecmp(argv[i], "--debuglevel")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
debugLevel = atoi(argv[i]);
|
||||
DB_Debug_Level_Set(debugLevel);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--req")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
req = strdup(argv[i]);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--db")) {
|
||||
if (++i >= argc) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
splitDBSpec(argv[i], &login, &pwd, &server);
|
||||
}
|
||||
else if (! strcasecmp(argv[i], "--help") || ! strcasecmp(argv[i], "-h") || ! strcasecmp(argv[i], "-?")) {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
else {
|
||||
usage(argv);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Usage.
|
||||
*/
|
||||
void usage(char **argv) {
|
||||
printf(USAGE, basename(argv[0]));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Splits a database specification in the format "login/password@server" into its
|
||||
* basic components 'login', 'password' and 'server'.
|
||||
* Note that the initial 'spec' string may be altered.
|
||||
*/
|
||||
void splitDBSpec(char *spec, const char **login_, const char **pwd_, const char **server_) {
|
||||
char *p = NULL;
|
||||
|
||||
*login_ = spec;
|
||||
p = strchr(spec, '/');
|
||||
if (p == NULL)
|
||||
return;
|
||||
|
||||
*p = 0;
|
||||
*pwd_ = ++p;
|
||||
|
||||
p = strchr(p, '@');
|
||||
if (p == NULL)
|
||||
return;
|
||||
*p = 0;
|
||||
*server_ = ++p;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Initializes host variables.
|
||||
* Associates an 'hostvar' with a type, size, array of values and array of indicators.
|
||||
*/
|
||||
int setupHostVars(void) {
|
||||
|
||||
if (DB_HostVar_Setup(&hv1, DBD_INTEGER, 0, dynInt1, dynIndic1) != DBS_OK ||
|
||||
DB_HostVar_Setup(&hv2, DBD_INTEGER, 0, dynInt2, dynIndic2) != DBS_OK ||
|
||||
DB_HostVar_Setup(&hv3, DBD_INTEGER, 0, dynInt3, dynIndic3) != DBS_OK) {
|
||||
|
||||
say("Error: %s\n", DB_Error_Message_Get());
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setup arrays of values and indicators.
|
||||
* (IN) n: Rows count to allocate for each array.
|
||||
*/
|
||||
void setupData(int n) {
|
||||
int i;
|
||||
|
||||
dynInt1 = malloc(n * sizeof(int));
|
||||
dynInt2 = malloc(n * sizeof(int));
|
||||
dynInt3 = malloc(n * sizeof(int));
|
||||
|
||||
dynIndic1 = malloc(n * sizeof(int));
|
||||
dynIndic2 = malloc(n * sizeof(int));
|
||||
dynIndic3 = malloc(n * sizeof(int));
|
||||
|
||||
/* Zeroe indicators */
|
||||
for (i = 0; i < n; i++) {
|
||||
dynIndic1[i] = 0;
|
||||
dynIndic2[i] = 0;
|
||||
dynIndic3[i] = 0;
|
||||
}
|
||||
|
||||
/* These are the places to update : set c1=2001 where c3=101, etc. */
|
||||
/*
|
||||
dynInt1[0] = 2001;
|
||||
dynInt3[0] = 101;
|
||||
|
||||
dynInt1[1] = 2002;
|
||||
dynInt3[1] = 102;
|
||||
|
||||
dynInt1[2] = 2003;
|
||||
dynInt3[2] = 103;
|
||||
*/
|
||||
|
||||
dynInt1[0] = 91;
|
||||
dynInt2[0] = 1;
|
||||
dynInt3[0] = 101;
|
||||
|
||||
dynInt1[1] = 92;
|
||||
dynInt2[1] = 0;
|
||||
dynInt3[1] = 101;
|
||||
|
||||
dynInt1[2] = 93;
|
||||
dynInt2[2] = 0;
|
||||
dynInt3[2] = 103;
|
||||
}
|
||||
Reference in New Issue
Block a user