-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathwiscextra.c
235 lines (193 loc) · 6.76 KB
/
wiscextra.c
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Universal Permissive License v 1.0 as shown
* at http://oss.oracle.com/licenses/upl
*/
#include <stdio.h>
#include <stdlib.h>
#if defined(WIN32)
#include <windows.h>
#else
#include "sqlunix.h"
#endif
#include <sql.h>
#include <sqlext.h>
#include "utils.h"
#include "timesten.h"
extern int DBMSType;
#define SQL_OP_FAILED(a) ((BOOL)( ((a) != SQL_SUCCESS) && \
((a) != SQL_SUCCESS_WITH_INFO)))
#define SQL_OP_ENDOFSET(a) ((BOOL)( ((a) == SQL_NO_DATA_FOUND) ))
/*********************************************************************
*
* FUNCTION: wiscUpdateStats
*
* DESCRIPTION: This function updates data store statistics on
* named table 'szTableName' using statement
* handle 'hstmt'.
*
* PARAMETERS: SQLHDBC hdbc SQL Connection handle
* SQLHSTMT hstmt SQL Statement handle
* char* szTableName Table name
*
* RETURNS: void (failures cause application exit)
*
*
*********************************************************************/
void
wiscUpdateStats(SQLHDBC hdbc, SQLHSTMT hstmt, char * szTableName )
{
SQLRETURN rc = SQL_SUCCESS;
char buf[100];
if (DBMSType == DBMS_TIMESTEN) {
sprintf(buf, "{ CALL TTOptUpdateStats('%s', 1) }", szTableName);
rc = SQLExecDirect(hstmt, (SQLCHAR *) buf, SQL_NTS);
handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
"Error in TTOptUpdateStats",
__FILE__, __LINE__);
}
rc = SQLStatistics( hstmt,(SQLCHAR *)NULL,0,
(SQLCHAR *)NULL,0,
(SQLCHAR *)szTableName,
SQL_NTS,
SQL_INDEX_ALL,
SQL_ENSURE);
handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
"Error in updating stats",
__FILE__, __LINE__);
/*
* Having forced the statistics update we now close the query
* without fetching any results as we don't really care to
* fetch the data
*/
rc = SQLFreeStmt(hstmt, SQL_CLOSE);
handle_errors(hdbc, hstmt, rc, ABORT_DISCONNECT_EXIT,
"Error in SQL_CLOSE for the statement handle",
__FILE__, __LINE__);
}
/*********************************************************************
*
* FUNCTION: showPlan
*
* DESCRIPTION: This function shows the contents of the PLAN table.
*
* PARAMETERS: SQLHDBC hDbc SQL Connection handle
*
* RETURNS: SQLRETURN (return code from SQL statements)
*
* NOTES: NONE
*
*********************************************************************/
SQLRETURN
showPlan(SQLHDBC hDbc )
{
SQLRETURN rc = SQL_SUCCESS;
BOOL fEndOfSet = 0;
int i = 0;
SQLHSTMT hStmt = SQL_NULL_HSTMT;
SQLINTEGER dwStep = 0;
SQLLEN cbStep = sizeof(int);
SQLINTEGER dwLevel = 0;
SQLLEN cbLevel = sizeof(int);
SQLCHAR szOperation[40];
SQLLEN cbOperation;
SQLCHAR szTblName[40];
SQLLEN cbTblName;
SQLCHAR szIxName[40];
SQLLEN cbIxName;
SQLCHAR szPred[1024];
SQLLEN cbPred;
SQLCHAR szOtherPred[1024];
SQLLEN cbOtherPred;
if ( hDbc == SQL_NULL_HDBC ) {
err_msg0("Invalid Connection Handle\n");
return SQL_ERROR;
}
rc = SQLAllocStmt(hDbc,&hStmt);
handle_errors(hDbc, SQL_NULL_HSTMT, rc, ABORT_DISCONNECT_EXIT,
"Error in allocating statement",
__FILE__, __LINE__);
rc = SQLBindCol(hStmt, 1, SQL_C_SLONG, &dwStep,
sizeof(int), &cbStep);
handle_errors(hDbc, hStmt, rc, ABORT_DISCONNECT_EXIT,
"binding parameter",
__FILE__, __LINE__);
rc = SQLBindCol(hStmt, 2, SQL_C_SLONG, &dwLevel,
sizeof(int), &cbLevel);
handle_errors(hDbc, hStmt, rc, ABORT_DISCONNECT_EXIT,
"binding parameter",
__FILE__, __LINE__);
rc = SQLBindCol(hStmt, 3, SQL_C_CHAR, szOperation, 40, &cbOperation);
handle_errors(hDbc, hStmt, rc, ABORT_DISCONNECT_EXIT,
"binding parameter",
__FILE__, __LINE__);
rc = SQLBindCol(hStmt, 4, SQL_C_CHAR, szTblName, 40, &cbTblName);
handle_errors(hDbc, hStmt, rc, ABORT_DISCONNECT_EXIT,
"binding parameter",
__FILE__, __LINE__);
rc = SQLBindCol(hStmt, 5, SQL_C_CHAR, szIxName, 40, &cbIxName);
handle_errors(hDbc, hStmt, rc, ABORT_DISCONNECT_EXIT,
"binding parameter",
__FILE__, __LINE__);
rc = SQLBindCol(hStmt, 6, SQL_C_CHAR, szPred, 1024, &cbPred);
handle_errors(hDbc, hStmt, rc, ABORT_DISCONNECT_EXIT,
"binding parameter",
__FILE__, __LINE__);
rc = SQLBindCol(hStmt, 7, SQL_C_CHAR, szOtherPred, 1024, &cbOtherPred);
handle_errors(hDbc, hStmt, rc, ABORT_DISCONNECT_EXIT,
"binding parameter",
__FILE__, __LINE__);
rc = SQLExecDirect(hStmt,(SQLCHAR *) "SELECT * FROM SYS.PLAN",SQL_NTS);
handle_errors(hDbc, hStmt, rc, ABORT_DISCONNECT_EXIT,
"Error in executing statement",
__FILE__, __LINE__);
while ( !fEndOfSet ) {
rc = SQLFetch(hStmt);
handle_errors(hDbc, hStmt, rc, ABORT_DISCONNECT_EXIT,
"Error in fetching row",
__FILE__, __LINE__);
if ( SQL_OP_ENDOFSET(rc) ) {
fEndOfSet = 1;
break;
}
else {
if ( SQL_OP_FAILED(rc) ) {
handle_errors(hDbc, hStmt, rc, ABORT_DISCONNECT_EXIT,
"Error in fetching row",
__FILE__, __LINE__);
break;
}
else {
i++;
if ( cbOperation == SQL_NULL_DATA )
szOperation[0] = '\0';
else szOperation[cbOperation] = '\0';
if ( cbTblName == SQL_NULL_DATA )
szTblName[0] = '\0';
else szTblName[cbTblName] = '\0';
if ( cbIxName == SQL_NULL_DATA )
szIxName[0] = '\0';
else szIxName[cbIxName] = '\0';
if ( cbPred == SQL_NULL_DATA )
szPred[0] = '\0';
else szPred[cbPred] = '\0';
if ( cbOtherPred == SQL_NULL_DATA )
szOtherPred[0] = '\0';
else szOtherPred[cbOtherPred] = '\0';
err_msg7("<%d,%d,%s,%s,%s,%s,%s>\n", dwStep, dwLevel,
szOperation,szTblName,szIxName,szPred,szOtherPred);
}
}
} /* end while */
rc = SQLFreeStmt(hStmt,SQL_DROP);
handle_errors(hDbc, hStmt, rc, 1, "freeing statement handle",
__FILE__, __LINE__);
return rc;
}
/* Emacs variable settings */
/* Local Variables: */
/* tab-width:8 */
/* indent-tabs-mode:nil */
/* c-basic-offset:2 */
/* End: */