File: ora7test.C

package info (click to toggle)
sqlrelay 1%3A0.35-10
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 11,944 kB
  • ctags: 6,102
  • sloc: cpp: 41,419; python: 11,007; ansic: 10,279; java: 9,833; perl: 9,500; php: 9,229; ruby: 9,182; sh: 8,700; makefile: 3,474; tcl: 5
file content (166 lines) | stat: -rw-r--r-- 3,310 bytes parent folder | download
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// Copyright (c) 2000-2001  David Muse
// See the file COPYING for more information

#include "../../config.h"

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>

#define FETCH_AT_ONCE		10
#define MAX_SELECT_LIST_SIZE	256
#define MAX_ITEM_BUFFER_SIZE	2048

extern "C" {

	#ifdef HAVE_OCI_H
		#include <oci.h>
	#else
		#include <oratypes.h>
		#include <ocidfn.h>
		#include <ociapr.h>
	#endif
	#include <ocidem.h>

	#define NULL_TERMINATED_STRING	5

	#define PARSE_DEFER		1
	#define PARSE_V7_LNG		2
}

struct describe {
	sb4	dbsize;
	sb2	dbtype;
	sb1	buf[MAX_ITEM_BUFFER_SIZE];
	sb4	buflen;
	sb4	dsize;
	sb2	precision;
	sb2	scale;
	sb2	nullok;
};
	
Lda_Def		lda;
Cda_Def		cda;
ub4		hda[256/sizeof(ub4)];
sword		ncols;

describe	desc[MAX_SELECT_LIST_SIZE];
ub1		def_buf[MAX_SELECT_LIST_SIZE]
			[FETCH_AT_ONCE][MAX_ITEM_BUFFER_SIZE];
sb2		def_indp[MAX_SELECT_LIST_SIZE][FETCH_AT_ONCE];
ub2		def_col_retlen[MAX_SELECT_LIST_SIZE][FETCH_AT_ONCE];
ub2		def_col_retcode[MAX_SELECT_LIST_SIZE][FETCH_AT_ONCE];

int		row;

int main(int argc, char **argv) {

	if (argc<6) {
		printf("usage: ora7test user password sid query iterations\n");
		exit(0);
	}

	char	*user=argv[1];
	char	*password=argv[2];
	char	*sid=argv[3];
	char	*query=argv[4];
	int	iterations=atoi(argv[5]);

	#if defined(HAVE_PUTENV)
		char	*sidstr=new char[strlen(sid)+12];
		sprintf(sidstr,"ORACLE_SID=%s",sid);
		putenv(sidstr);
		delete[] sidstr;
		sidstr=new char[strlen(sid)+10];
		sprintf(sidstr,"TWO_TASK=%s",sid);
		putenv(sidstr);
		delete[] sidstr;
	#elif defined(HAVE_SETENV)
		setenv("ORACLE_SID",sid,1);
		setenv("TWO_TATK",sid,1);
	#endif

	// init the timer
	time_t	starttime=time(NULL);
	printf("oratest running, please wait...\n");
	clock();

	for (int count=0; count<iterations; count++) {

		// log in
		olog(&lda,(ub1 *)hda,(text *)user,-1,(text *)password,-1,
			(text *)0,-1,OCI_LM_DEF);

		// allocate a cursor
		oopen(&cda,&lda,(text *)0,-1,-1,(text *)0,-1);

		// parse the query
		oparse(&cda,(text *)query,
			(sb4)-1,(sword)PARSE_DEFER,(ub4)PARSE_V7_LNG);

		// describe/define the query
		ncols=0;
		if (cda.ft==FT_SELECT) {

			sword	col=0;

			// run through the columns...
			while (1) {

				desc[col].buflen=MAX_ITEM_BUFFER_SIZE;

				// describe the column
				if (!odescr(&cda,col+1,
					&desc[col].dbsize, &desc[col].dbtype,
					&desc[col].buf[0], &desc[col].buflen,
					&desc[col].dsize, &desc[col].precision,
					&desc[col].scale, &desc[col].nullok)) {
	
					// define the column
					odefin(&cda,col+1,
							*def_buf[col],
							MAX_ITEM_BUFFER_SIZE,
							NULL_TERMINATED_STRING,
							-1,
							def_indp[col],
							(text *)0,
							-1,
							-1,
							def_col_retlen[col],
							def_col_retcode[col]);
				} else {
					ncols=col;
					break;
				}
				col++;
			}
		}

		// execute the query
		oexec(&cda);

		// go fetch all rows and columns
		int	oldrpc=0;
		for (;;) {
			ofen(&cda,FETCH_AT_ONCE);
			if (cda.rpc==oldrpc) {
				break;
			}
			for (int j=0; j<cda.rpc-oldrpc; j++) {
				for (int i=0; i<ncols; i++) {
					printf("\"%s\",",def_buf[i][j]);
				}
				printf("\n");
			}
			oldrpc=cda.rpc;
		}
	
		// log off
		oclose(&cda);
		ologof(&lda);
	}

	printf("total system time used: %d\n",clock());
	printf("total real time: %d\n",time(NULL)-starttime);
}