File: ora7test.C

package info (click to toggle)
sqlrelay 1%3A0.37.1-3.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 13,084 kB
  • ctags: 6,691
  • sloc: cpp: 48,136; python: 10,118; ansic: 9,673; java: 9,195; php: 8,839; perl: 8,827; sh: 8,554; ruby: 8,516; tcl: 5,039; makefile: 3,665
file content (170 lines) | stat: -rw-r--r-- 3,344 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
167
168
169
170
// Copyright (c) 2000-2001  David Muse
// See the file COPYING for more information

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

#include <rudiments/environment.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>

#ifdef RUDIMENTS_NAMESPACE
using namespace rudiments;
#endif

#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<7) {
		printf("usage: ora7test user password sid query iterations queriesperiteration\n");
		exit(0);
	}

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

	environment	env;
	env.setValue("ORACLE_SID",sid);
	env.setValue("TWO_TASK",sid);

	// 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);

		for (int qcount=0; qcount<queriesperiteration; qcount++) {

			// 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...
				for (;;) {

					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;
			}

			oclose(&cda);
		}
	
		// log off
		ologof(&lda);
	}

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