242 lines
6.3 KiB
C
242 lines
6.3 KiB
C
|
/*---------------------------------------------------------------------------------*/
|
||
|
/* $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;
|
||
|
}
|