Skip to content

Commit 296e7ba

Browse files
committed
ODBC source code cleanup patch. Should match rest of PostgreSQL code better.
1 parent 062a79a commit 296e7ba

24 files changed

+990
-1182
lines changed

src/interfaces/odbc/bind.c

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* Module: bind.c
1+
/*-------
2+
* Module: bind.c
23
*
34
* Description: This module contains routines related to binding
45
* columns and parameters.
@@ -9,7 +10,7 @@
910
* SQLParamOptions(NI)
1011
*
1112
* Comments: See "notice.txt" for copyright and license information.
12-
*
13+
*-------
1314
*/
1415

1516
#ifdef HAVE_CONFIG_H
@@ -33,8 +34,8 @@
3334
#include "sqlext.h"
3435
#endif
3536

36-
/* Bind parameters on a statement handle */
3737

38+
/* Bind parameters on a statement handle */
3839
RETCODE SQL_API
3940
SQLBindParameter(
4041
HSTMT hstmt,
@@ -112,8 +113,8 @@ SQLBindParameter(
112113
}
113114
}
114115

115-
ipar--; /* use zero based column numbers for the
116-
* below part */
116+
/* use zero based column numbers for the below part */
117+
ipar--;
117118

118119
/* store the given info */
119120
stmt->parameters[ipar].buflen = cbValueMax;
@@ -158,9 +159,8 @@ SQLBindParameter(
158159
return SQL_SUCCESS;
159160
}
160161

161-
/* - - - - - - - - - */
162162

163-
/* Associate a user-supplied buffer with a database column. */
163+
/* Associate a user-supplied buffer with a database column. */
164164
RETCODE SQL_API
165165
SQLBindCol(
166166
HSTMT hstmt,
@@ -197,7 +197,6 @@ SQLBindCol(
197197
/* If the bookmark column is being bound, then just save it */
198198
if (icol == 0)
199199
{
200-
201200
if (rgbValue == NULL)
202201
{
203202
stmt->bookmark.buffer = NULL;
@@ -220,10 +219,12 @@ SQLBindCol(
220219
return SQL_SUCCESS;
221220
}
222221

223-
/* allocate enough bindings if not already done */
224-
/* Most likely, execution of a statement would have setup the */
225-
/* necessary bindings. But some apps call BindCol before any */
226-
/* statement is executed. */
222+
/*
223+
* Allocate enough bindings if not already done.
224+
* Most likely, execution of a statement would have setup the
225+
* necessary bindings. But some apps call BindCol before any
226+
* statement is executed.
227+
*/
227228
if (icol > stmt->bindings_allocated)
228229
extend_bindings(stmt, icol);
229230

@@ -236,8 +237,8 @@ SQLBindCol(
236237
return SQL_ERROR;
237238
}
238239

239-
icol--; /* use zero based col numbers from here
240-
* out */
240+
/* use zero based col numbers from here out */
241+
icol--;
241242

242243
/* Reset for SQLGetData */
243244
stmt->bindings[icol].data_left = -1;
@@ -264,15 +265,15 @@ SQLBindCol(
264265
return SQL_SUCCESS;
265266
}
266267

267-
/* - - - - - - - - - */
268-
269-
/* Returns the description of a parameter marker. */
270-
/* This function is listed as not being supported by SQLGetFunctions() because it is */
271-
/* used to describe "parameter markers" (not bound parameters), in which case, */
272-
/* the dbms should return info on the markers. Since Postgres doesn't support that, */
273-
/* it is best to say this function is not supported and let the application assume a */
274-
/* data type (most likely varchar). */
275268

269+
/*
270+
* Returns the description of a parameter marker.
271+
* This function is listed as not being supported by SQLGetFunctions() because it is
272+
* used to describe "parameter markers" (not bound parameters), in which case,
273+
* the dbms should return info on the markers. Since Postgres doesn't support that,
274+
* it is best to say this function is not supported and let the application assume a
275+
* data type (most likely varchar).
276+
*/
276277
RETCODE SQL_API
277278
SQLDescribeParam(
278279
HSTMT hstmt,
@@ -323,10 +324,8 @@ SQLDescribeParam(
323324
return SQL_SUCCESS;
324325
}
325326

326-
/* - - - - - - - - - */
327-
328-
/* Sets multiple values (arrays) for the set of parameter markers. */
329327

328+
/* Sets multiple values (arrays) for the set of parameter markers. */
330329
RETCODE SQL_API
331330
SQLParamOptions(
332331
HSTMT hstmt,
@@ -341,15 +340,16 @@ SQLParamOptions(
341340
return SQL_ERROR;
342341
}
343342

344-
/* - - - - - - - - - */
345343

346-
/* This function should really talk to the dbms to determine the number of */
347-
/* "parameter markers" (not bound parameters) in the statement. But, since */
348-
/* Postgres doesn't support that, the driver should just count the number of markers */
349-
/* and return that. The reason the driver just can't say this function is unsupported */
350-
/* like it does for SQLDescribeParam is that some applications don't care and try */
351-
/* to call it anyway. */
352-
/* If the statement does not have parameters, it should just return 0. */
344+
/*
345+
* This function should really talk to the dbms to determine the number of
346+
* "parameter markers" (not bound parameters) in the statement. But, since
347+
* Postgres doesn't support that, the driver should just count the number of markers
348+
* and return that. The reason the driver just can't say this function is unsupported
349+
* like it does for SQLDescribeParam is that some applications don't care and try
350+
* to call it anyway.
351+
* If the statement does not have parameters, it should just return 0.
352+
*/
353353
RETCODE SQL_API
354354
SQLNumParams(
355355
HSTMT hstmt,
@@ -387,10 +387,8 @@ SQLNumParams(
387387
}
388388
else
389389
{
390-
391390
for (i = 0; i < strlen(stmt->statement); i++)
392391
{
393-
394392
if (stmt->statement[i] == '?' && !in_quote)
395393
(*pcpar)++;
396394
else
@@ -399,12 +397,12 @@ SQLNumParams(
399397
in_quote = (in_quote ? FALSE : TRUE);
400398
}
401399
}
402-
403400
return SQL_SUCCESS;
404401
}
405402
}
406403

407-
/********************************************************************
404+
405+
/*
408406
* Bindings Implementation
409407
*/
410408
BindInfoClass *
@@ -428,6 +426,7 @@ create_empty_bindings(int num_columns)
428426
return new_bindings;
429427
}
430428

429+
431430
void
432431
extend_bindings(StatementClass *stmt, int num_columns)
433432
{
@@ -437,11 +436,12 @@ extend_bindings(StatementClass *stmt, int num_columns)
437436

438437
mylog("%s: entering ... stmt=%u, bindings_allocated=%d, num_columns=%d\n", func, stmt, stmt->bindings_allocated, num_columns);
439438

440-
/* if we have too few, allocate room for more, and copy the old */
441-
/* entries into the new structure */
439+
/*
440+
* if we have too few, allocate room for more, and copy the old
441+
* entries into the new structure
442+
*/
442443
if (stmt->bindings_allocated < num_columns)
443444
{
444-
445445
new_bindings = create_empty_bindings(num_columns);
446446
if (!new_bindings)
447447
{
@@ -466,11 +466,12 @@ extend_bindings(StatementClass *stmt, int num_columns)
466466

467467
stmt->bindings = new_bindings;
468468
stmt->bindings_allocated = num_columns;
469-
470469
}
471-
/* There is no reason to zero out extra bindings if there are */
472-
/* more than needed. If an app has allocated extra bindings, */
473-
/* let it worry about it by unbinding those columns. */
470+
/*
471+
* There is no reason to zero out extra bindings if there are
472+
* more than needed. If an app has allocated extra bindings,
473+
* let it worry about it by unbinding those columns.
474+
*/
474475

475476
/* SQLBindCol(1..) ... SQLBindCol(10...) # got 10 bindings */
476477
/* SQLExecDirect(...) # returns 5 cols */

src/interfaces/odbc/columninfo.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* Module: columninfo.c
1+
/*-------
2+
* Module: columninfo.c
23
*
34
* Description: This module contains routines related to
45
* reading and storing the field information from a query.
@@ -8,7 +9,7 @@
89
* API functions: none
910
*
1011
* Comments: See "notice.txt" for copyright and license information.
11-
*
12+
*-------
1213
*/
1314

1415
#include "columninfo.h"
@@ -37,6 +38,7 @@ CI_Constructor()
3738
return rv;
3839
}
3940

41+
4042
void
4143
CI_Destructor(ColumnInfoClass *self)
4244
{
@@ -45,10 +47,12 @@ CI_Destructor(ColumnInfoClass *self)
4547
free(self);
4648
}
4749

48-
/* Read in field descriptions.
49-
If self is not null, then also store the information.
50-
If self is null, then just read, don't store.
51-
*/
50+
51+
/*
52+
* Read in field descriptions.
53+
* If self is not null, then also store the information.
54+
* If self is null, then just read, don't store.
55+
*/
5256
char
5357
CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn)
5458
{
@@ -71,22 +75,19 @@ CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn)
7175
mylog("num_fields = %d\n", new_num_fields);
7276

7377
if (self)
74-
{ /* according to that allocate memory */
78+
/* according to that allocate memory */
7579
CI_set_num_fields(self, new_num_fields);
76-
}
7780

7881
/* now read in the descriptions */
7982
for (lf = 0; lf < new_num_fields; lf++)
8083
{
81-
8284
SOCK_get_string(sock, new_field_name, 2 * MAX_COLUMN_LEN);
8385
new_adtid = (Oid) SOCK_get_int(sock, 4);
8486
new_adtsize = (Int2) SOCK_get_int(sock, 2);
8587

8688
/* If 6.4 protocol, then read the atttypmod field */
8789
if (PG_VERSION_GE(conn, 6.4))
8890
{
89-
9091
mylog("READING ATTTYPMOD\n");
9192
new_atttypmod = (Int4) SOCK_get_int(sock, 4);
9293

@@ -107,7 +108,6 @@ CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn)
107108
}
108109

109110

110-
111111
void
112112
CI_free_memory(ColumnInfoClass *self)
113113
{
@@ -143,6 +143,7 @@ CI_free_memory(ColumnInfoClass *self)
143143
self->atttypmod = NULL;
144144
}
145145

146+
146147
void
147148
CI_set_num_fields(ColumnInfoClass *self, int new_num_fields)
148149
{
@@ -158,11 +159,11 @@ CI_set_num_fields(ColumnInfoClass *self, int new_num_fields)
158159
self->atttypmod = (Int4 *) malloc(sizeof(Int4) * self->num_fields);
159160
}
160161

162+
161163
void
162164
CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name,
163165
Oid new_adtid, Int2 new_adtsize, Int4 new_atttypmod)
164166
{
165-
166167
/* check bounds */
167168
if ((field_num < 0) || (field_num >= self->num_fields))
168169
return;

0 commit comments

Comments
 (0)