Skip to content

Commit d4f9052

Browse files
committed
Cleanup print statements
1 parent 8c8abcf commit d4f9052

File tree

1 file changed

+15
-218
lines changed

1 file changed

+15
-218
lines changed

main.c

+15-218
Original file line numberDiff line numberDiff line change
@@ -71,219 +71,26 @@ int main(int argc, char **argv) {
7171

7272
ReportStatus(SQLAllocHandle(SQL_HANDLE_STMT, hDbc, &hStmt));
7373

74-
/************************************************
75-
Non-Paramatized Prepared Query - Works as Expected
76-
*******************************************************/
77-
/*
78-
fprintf(stderr, "Prepare: ");
79-
ReportStatus(SQLPrepare(hStmt, "SELECT 1 as id", strlen("SELECT 1 as id")));
80-
81-
fprintf(stderr, "Execute: ");
82-
ReportStatus(SQLExecute(hStmt));
83-
84-
fprintf(stderr, "Fetch: ");
85-
ReportStatus(SQLFetch(hStmt));
86-
87-
fprintf(stderr, "SQLGetData: ");
88-
ReportStatus(SQLGetData(hStmt, (SQLUSMALLINT)(1), SQL_C_LONG, &value, sizeof(value), &cbFetched));
89-
fprintf(stderr, "Value %i\n", value);
90-
SQLFreeStmt(hStmt, SQL_UNBIND);
91-
SQLFreeStmt(hStmt, SQL_RESET_PARAMS);
92-
SQLFreeStmt(hStmt, SQL_CLOSE);
93-
94-
95-
96-
//fprintf(stderr, "Prepare: ");
97-
//ReportStatus(SQLPrepare(hStmt, "SELECT 1 as id", strlen("SELECT 1 as id")));
98-
99-
fprintf(stderr, "Execute: ");
100-
ReportStatus(SQLExecute(hStmt));
101-
102-
fprintf(stderr, "Fetch: ");
103-
ReportStatus(SQLFetch(hStmt));
104-
105-
fprintf(stderr, "SQLGetData: ");
106-
ReportStatus(SQLGetData(hStmt, (SQLUSMALLINT)(1), SQL_C_LONG, &value, sizeof(value), &cbFetched));
107-
fprintf(stderr, "Value %i\n", value);
108-
109-
SQLFreeStmt(hStmt, SQL_UNBIND);
110-
SQLFreeStmt(hStmt, SQL_RESET_PARAMS);
111-
SQLFreeStmt(hStmt, SQL_CLOSE);
112-
113-
114-
fprintf(stderr, "Execute: ");
115-
ReportStatus(SQLExecute(hStmt));
116-
117-
fprintf(stderr, "Fetch: ");
118-
ReportStatus(SQLFetch(hStmt));
119-
120-
fprintf(stderr, "SQLGetData: ");
121-
ReportStatus(SQLGetData(hStmt, (SQLUSMALLINT)(1), SQL_C_LONG, &value, sizeof(value), &cbFetched));
122-
fprintf(stderr, "Value %i\n", value);
123-
124-
SQLFreeStmt(hStmt, SQL_UNBIND);
125-
SQLFreeStmt(hStmt, SQL_RESET_PARAMS);
126-
SQLFreeStmt(hStmt, SQL_CLOSE);
127-
*/
128-
129-
/********************************************************
130-
Parameterized Integer - SQL_RESET_PARAMS Issue
131-
***********************************************************/
132-
/*
133-
fprintf(stderr, "Parameterized Integer SQL_RESET_PARAMS\n");
134-
fprintf(stderr, "Prepare: ");
135-
//SQL Server
136-
ReportStatus(SQLPrepare(hStmt, "declare @v int; SELECT ? as id", strlen("declare @vint; SELECT ? as id")));
137-
138-
// Postgres
139-
//ReportStatus(SQLPrepare(hStmt, "SELECT ?::int as id", strlen("SELECT ?::int as id")));
140-
141-
142-
fprintf(stderr, "Bind: ");
143-
SQLINTEGER v_reset = 2; SQLLEN l;
144-
ReportStatus(SQLBindParameter(hStmt, (SQLUSMALLINT)1, SQL_PARAM_INPUT, SQL_INTEGER, SQL_DECIMAL, 4, 0, &v_reset, 4, &l ));
145-
146-
fprintf(stderr, "Execute: ");
147-
ReportStatus(SQLExecute(hStmt));
148-
149-
fprintf(stderr, "Fetch: ");
150-
ReportStatus(SQLFetch(hStmt));
151-
152-
fprintf(stderr, "SQLGetData: ");
153-
ReportStatus(SQLGetData(hStmt, (SQLUSMALLINT)(1), SQL_C_LONG, &value, sizeof(value), &cbFetched));
154-
fprintf(stderr, "Value %i\n", value);
155-
156-
// Problem Here
157-
//SQLFreeStmt(hStmt, SQL_RESET_PARAMS);
158-
SQLFreeStmt(hStmt, SQL_UNBIND);
159-
SQLFreeStmt(hStmt, SQL_CLOSE);
160-
161-
//fprintf(stderr, "Bind: ");
162-
//ReportStatus(SQLBindParameter(hStmt, (SQLUSMALLINT)1, SQL_PARAM_INPUT, SQL_INTEGER, SQL_DECIMAL, 4, 0, &v_reset, 4, &l ));
163-
164-
165-
fprintf(stderr, "Execute: ");
166-
ReportStatus(SQLExecute(hStmt));
167-
168-
fprintf(stderr, "Fetch: ");
169-
ReportStatus(SQLFetch(hStmt));
170-
171-
fprintf(stderr, "SQLGetData: ");
172-
ReportStatus(SQLGetData(hStmt, (SQLUSMALLINT)(1), SQL_C_LONG, &value, sizeof(value), &cbFetched));
173-
fprintf(stderr, "Value %i\n", value);
174-
175-
SQLFreeStmt(hStmt, SQL_RESET_PARAMS);
176-
SQLFreeStmt(hStmt, SQL_UNBIND);
177-
SQLFreeStmt(hStmt, SQL_CLOSE);
178-
179-
fprintf(stderr, "Bind: ");
180-
ReportStatus(SQLBindParameter(hStmt, (SQLUSMALLINT)1, SQL_PARAM_INPUT, SQL_INTEGER, SQL_DECIMAL, 4, 0, &v_reset, 4, &l ));
181-
182-
183-
fprintf(stderr, "Execute: ");
184-
ReportStatus(SQLExecute(hStmt));
185-
186-
fprintf(stderr, "Fetch: ");
187-
ReportStatus(SQLFetch(hStmt));
188-
189-
fprintf(stderr, "SQLGetData: ");
190-
ReportStatus(SQLGetData(hStmt, (SQLUSMALLINT)(1), SQL_C_LONG, &value, sizeof(value), &cbFetched));
191-
fprintf(stderr, "Value %i\n", value);
192-
*/
193-
194-
/********************************************************
195-
Parameterized Integer - SQLBindParameteri Pointer Issue
196-
**********************************************************/
197-
/*
198-
fprintf(stderr, "Parameterized Integer SQLBindParameter\n");
199-
fprintf(stderr, "Prepare: ");
200-
//SQL Server
201-
ReportStatus(SQLPrepare(hStmt, "declare @v int; SELECT ? as id", strlen("declare @vint; SELECT ? as id")));
202-
203-
// Postgres
204-
//ReportStatus(SQLPrepare(hStmt, "SELECT ?::int as id", strlen("SELECT ?::int as id")));
205-
206-
207-
fprintf(stderr, "Bind: ");
208-
SQLINTEGER v_bind_1 = 2; SQLLEN l_bind;
209-
ReportStatus(SQLBindParameter(hStmt, (SQLUSMALLINT)1, SQL_PARAM_INPUT, SQL_INTEGER, SQL_DECIMAL, 4, 0, &v_bind_1, 4, &l_bind ));
210-
211-
fprintf(stderr, "Execute: ");
212-
ReportStatus(SQLExecute(hStmt));
213-
214-
215-
fprintf(stderr, "Fetch: ");
216-
ReportStatus(SQLFetch(hStmt));
217-
218-
fprintf(stderr, "SQLGetData: ");
219-
ReportStatus(SQLGetData(hStmt, (SQLUSMALLINT)(1), SQL_C_LONG, &value, sizeof(value), &cbFetched));
220-
fprintf(stderr, "Value %i\n", value);
221-
222-
//SQLFreeStmt(hStmt, SQL_RESET_PARAMS);
223-
SQLFreeStmt(hStmt, SQL_UNBIND);
224-
SQLFreeStmt(hStmt, SQL_CLOSE);
225-
226-
fprintf(stderr, "Bind: ");
227-
SQLINTEGER v_bind_2 = 2;
228-
//v = 3;
229-
// Use new variable
230-
ReportStatus(SQLBindParameter(hStmt, (SQLUSMALLINT)1, SQL_PARAM_INPUT, SQL_INTEGER, SQL_DECIMAL, 4, 0, &v_bind_2, 4, &l_bind));
231-
232-
233-
fprintf(stderr, "Execute: ");
234-
ReportStatus(SQLExecute(hStmt));
235-
236-
fprintf(stderr, "Fetch: ");
237-
ReportStatus(SQLFetch(hStmt));
238-
239-
fprintf(stderr, "SQLGetData: ");
240-
ReportStatus(SQLGetData(hStmt, (SQLUSMALLINT)(1), SQL_C_LONG, &value, sizeof(value), &cbFetched));
241-
fprintf(stderr, "Value %i\n", value);
242-
243-
244-
//SQLFreeStmt(hStmt, SQL_RESET_PARAMS);
245-
SQLFreeStmt(hStmt, SQL_UNBIND);
246-
SQLFreeStmt(hStmt, SQL_CLOSE);
247-
248-
fprintf(stderr, "Bind: ");
249-
//v = 3;
250-
// Use new variable
251-
ReportStatus(SQLBindParameter(hStmt, (SQLUSMALLINT)1, SQL_PARAM_INPUT, SQL_INTEGER, SQL_DECIMAL, 4, 0, &v_bind_2, 4, &l_bind ));
252-
253-
254-
fprintf(stderr, "Execute: ");
255-
ReportStatus(SQLExecute(hStmt));
256-
257-
fprintf(stderr, "Fetch: ");
258-
ReportStatus(SQLFetch(hStmt));
259-
260-
fprintf(stderr, "SQLGetData: ");
261-
ReportStatus(SQLGetData(hStmt, (SQLUSMALLINT)(1), SQL_C_LONG, &value, sizeof(value), &cbFetched));
262-
fprintf(stderr, "Value %i\n", value);
263-
*/
264-
/********************************************************
265-
Parameterized Vector
266-
**********************************************************/
267-
fprintf(stderr, "Parameterized Vector Start\n");
268-
26974
/*********************************************************
27075
1st Query Prepare the Statement
27176
**********************************************************/
27277
fprintf(stderr, "Prepare: ");
78+
79+
// SQL Server
27380
ReportStatus(SQLPrepare(hStmt, "declare @v VECTOR(3); SELECT ? as id", strlen("declare @v VECTOR(3); SELECT ? as id")));
27481

27582
// Postgres
27683
//ReportStatus(SQLPrepare(hStmt, "SELECT ?::text as id", strlen("SELECT ?::text as id")));
27784

27885
fprintf(stderr, "Bind: ");
27986
SQLLEN l = 1;
280-
l = SQL_DATA_AT_EXEC;///sstrlen((char *)vec_str);
87+
l = SQL_DATA_AT_EXEC;
28188
SQLCHAR *vec_str = "[1, 2, 3]\0";
28289
ReportStatus(SQLBindParameter(hStmt, (SQLUSMALLINT)1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 0, 0, vec_str, sizeof((char *)vec_str), &l ));
28390

28491

285-
SQLCHAR varchar_value[100000]; // Buffer to store the VARCHAR data. Make it large enough!
286-
SQLLEN varchar_len_or_ind; // To store the length or indicator (e.g., SQL_NULL_DATA)
92+
SQLCHAR varchar_value[100000];
93+
SQLLEN varchar_len_or_ind;
28794

28895
fprintf(stderr, "BindCol: ");
28996
ReportStatus(SQLBindCol(hStmt, 1, SQL_C_CHAR, &varchar_value, 100000, &varchar_len_or_ind));
@@ -299,7 +106,7 @@ Parameterized Vector
299106
fprintf(stderr, "Fetch: ");
300107
ReportStatus(SQLFetch(hStmt));
301108

302-
fprintf(stderr, "varhcar: %s\n", varchar_value);
109+
fprintf(stderr, "value: %s\n", varchar_value);
303110

304111
SQLFreeStmt(hStmt, SQL_RESET_PARAMS);
305112
SQLFreeStmt(hStmt, SQL_UNBIND);
@@ -310,7 +117,7 @@ Parameterized Vector
310117
**************************************************************/
311118
SQLCHAR vec_str2[10] = "[4, 5, 6]\0";
312119
SQLLEN l2 = 1;
313-
l2 = SQL_DATA_AT_EXEC;///sstrlen((char *)vec_str);
120+
l2 = SQL_DATA_AT_EXEC;
314121

315122
fprintf(stderr, "Bind: ");
316123
ReportStatus(SQLBindParameter(hStmt, (SQLUSMALLINT)1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 0, 0, &vec_str2, sizeof(vec_str2), &l2 ));
@@ -328,7 +135,7 @@ Parameterized Vector
328135
fprintf(stderr, "Fetch: ");
329136
ReportStatus(SQLFetch(hStmt));
330137

331-
fprintf(stderr, "varhcar: %s\n", varchar_value);
138+
fprintf(stderr, "value: %s\n", varchar_value);
332139

333140
int cbAllocated = 10000;
334141
char *pb = malloc(sizeof(char) * cbAllocated);
@@ -346,9 +153,9 @@ Parameterized Vector
346153
SQLCHAR vec_str3[10] = "[7, 8, 9]\0";
347154
memcpy(&vec_str2, &vec_str3, sizeof(vec_str2));
348155

349-
//fprintf(stderr, "Bind: ");
350-
//ReportStatus(SQLBindParameter(hStmt, (SQLUSMALLINT)1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 0, 0, &vec_str3, sizeof(vec_str3), &l2 ));
351-
156+
fprintf(stderr, "BindCol: ");
157+
ReportStatus(SQLBindCol(hStmt, 1, SQL_C_CHAR, &varchar_value, 100000, &varchar_len_or_ind));
158+
352159
fprintf(stderr, "Execute: ");
353160
ReportStatus(SQLExecute(hStmt));
354161

@@ -359,24 +166,16 @@ Parameterized Vector
359166
fprintf(stderr, "Fetch: ");
360167
ReportStatus(SQLFetch(hStmt));
361168

362-
fprintf(stderr, "varhcar: %s\n", varchar_value);
169+
fprintf(stderr, "value: %s\n", varchar_value);
363170

364-
// SQLFreeStmt(hStmt, SQL_UNBIND);
365-
SQLFreeStmt(hStmt, SQL_CLOSE);
171+
//SQLFreeStmt(hStmt, SQL_UNBIND);
172+
SQLFreeStmt(hStmt, SQL_CLOSE);
366173

367174

368175
/****************************************************************
369176
4th Query Same as query 2 with no SQLUnbind or SQL_RESET_PARAMS
370177
*****************************************************************/
371178
SQLCHAR vec_str4[10] = "[1, 5, 9]\0";
372-
//memcpy(&vec_str2, &vec_str3, sizeof(vec_str2));
373-
374-
//fprintf(stderr, "Bind: ");
375-
//ReportStatus(SQLBindParameter(hStmt, (SQLUSMALLINT)1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 0, 0, &vec_str4, sizeof(vec_str4), &l2 ));
376-
377-
//fprintf(stderr, "BindCol: ");
378-
//ReportStatus(SQLBindCol(hStmt, 1, SQL_C_CHAR, &varchar_value, 100000, &varchar_len_or_ind));
379-
380179

381180
fprintf(stderr, "Execute: ");
382181
ReportStatus(SQLExecute(hStmt));
@@ -388,11 +187,9 @@ Parameterized Vector
388187
fprintf(stderr, "Fetch: ");
389188
ReportStatus(SQLFetch(hStmt));
390189

391-
fprintf(stderr, "varhcar: %s\n", varchar_value);
190+
fprintf(stderr, "value: %s\n", varchar_value);
392191
SQLFreeStmt(hStmt, SQL_CLOSE);
393192

394-
395-
396193
SQLDisconnect(hEnv);
397194

398195
}

0 commit comments

Comments
 (0)