Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 99d21d5

Browse files
author
Byron Nikolaidis
committed
Update odbc driver to current version V.0244
1 parent 85f91d0 commit 99d21d5

39 files changed

+5462
-3765
lines changed

src/interfaces/odbc/bind.c

Lines changed: 54 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
2-
/* Module: bind.c
3-
*
4-
* Description: This module contains routines related to binding
5-
* columns and parameters.
6-
*
7-
* Classes: BindInfoClass, ParameterInfoClass
8-
*
9-
* API functions: SQLBindParameter, SQLBindCol, SQLDescribeParam, SQLNumParams,
10-
* SQLParamOptions(NI)
11-
*
12-
* Comments: See "notice.txt" for copyright and license information.
13-
*
14-
*/
1+
2+
/* Module: bind.c
3+
*
4+
* Description: This module contains routines related to binding
5+
* columns and parameters.
6+
*
7+
* Classes: BindInfoClass, ParameterInfoClass
8+
*
9+
* API functions: SQLBindParameter, SQLBindCol, SQLDescribeParam, SQLNumParams,
10+
* SQLParamOptions(NI)
11+
*
12+
* Comments: See "notice.txt" for copyright and license information.
13+
*
14+
*/
1515
#include "bind.h"
1616
#include "environ.h"
1717
#include "statement.h"
1818
#include "qresult.h"
1919
#include "pgtypes.h"
2020
#include <stdlib.h>
2121
#include <malloc.h>
22-
#include <sql.h>
23-
#include <sqlext.h>
22+
#include <sql.h>
23+
#include <sqlext.h>
2424

2525
// Bind parameters on a statement handle
2626

@@ -77,10 +77,11 @@ StatementClass *stmt = (StatementClass *) hstmt;
7777
stmt->parameters[i].CType = 0;
7878
stmt->parameters[i].SQLType = 0;
7979
stmt->parameters[i].precision = 0;
80-
stmt->parameters[i].scale = 0;
81-
stmt->parameters[i].data_at_exec = FALSE;
82-
stmt->parameters[i].EXEC_used = NULL;
83-
stmt->parameters[i].EXEC_buffer = NULL;
80+
stmt->parameters[i].scale = 0;
81+
stmt->parameters[i].data_at_exec = FALSE;
82+
stmt->parameters[i].lobj_oid = 0;
83+
stmt->parameters[i].EXEC_used = NULL;
84+
stmt->parameters[i].EXEC_buffer = NULL;
8485
}
8586
}
8687

@@ -94,26 +95,28 @@ StatementClass *stmt = (StatementClass *) hstmt;
9495
stmt->parameters[ipar].CType = fCType;
9596
stmt->parameters[ipar].SQLType = fSqlType;
9697
stmt->parameters[ipar].precision = cbColDef;
97-
stmt->parameters[ipar].scale = ibScale;
98-
99-
/* If rebinding a parameter that had data-at-exec stuff in it,
100-
then free that stuff
101-
*/
102-
if (stmt->parameters[ipar].EXEC_used) {
103-
free(stmt->parameters[ipar].EXEC_used);
104-
stmt->parameters[ipar].EXEC_used = NULL;
105-
}
106-
107-
if (stmt->parameters[ipar].EXEC_buffer) {
108-
free(stmt->parameters[ipar].EXEC_buffer);
109-
stmt->parameters[ipar].EXEC_buffer = NULL;
110-
}
111-
112-
if (pcbValue && *pcbValue <= SQL_LEN_DATA_AT_EXEC_OFFSET)
113-
stmt->parameters[ipar].data_at_exec = TRUE;
114-
else
115-
stmt->parameters[ipar].data_at_exec = FALSE;
116-
98+
stmt->parameters[ipar].scale = ibScale;
99+
100+
/* If rebinding a parameter that had data-at-exec stuff in it,
101+
then free that stuff
102+
*/
103+
if (stmt->parameters[ipar].EXEC_used) {
104+
free(stmt->parameters[ipar].EXEC_used);
105+
stmt->parameters[ipar].EXEC_used = NULL;
106+
}
107+
108+
if (stmt->parameters[ipar].EXEC_buffer) {
109+
free(stmt->parameters[ipar].EXEC_buffer);
110+
stmt->parameters[ipar].EXEC_buffer = NULL;
111+
}
112+
113+
if (pcbValue && *pcbValue <= SQL_LEN_DATA_AT_EXEC_OFFSET)
114+
stmt->parameters[ipar].data_at_exec = TRUE;
115+
else
116+
stmt->parameters[ipar].data_at_exec = FALSE;
117+
118+
mylog("SQLBindParamater: ipar = %d, *pcbValue = %d, data_at_exec = %d\n",
119+
ipar, pcbValue ? *pcbValue: -777, stmt->parameters[ipar].data_at_exec);
117120

118121
return SQL_SUCCESS;
119122
}
@@ -188,6 +191,8 @@ mylog("**** SQLBindCol: stmt = %u, icol = %d\n", stmt, icol);
188191
stmt->bindings[icol].buffer = rgbValue;
189192
stmt->bindings[icol].used = pcbValue;
190193
stmt->bindings[icol].returntype = fCType;
194+
195+
mylog(" bound buffer[%d] = %u\n", icol, stmt->bindings[icol].buffer);
191196
}
192197

193198
return SQL_SUCCESS;
@@ -228,7 +233,7 @@ StatementClass *stmt = (StatementClass *) hstmt;
228233
*pibScale = stmt->parameters[ipar].scale;
229234

230235
if(pfNullable)
231-
*pfNullable = pgtype_nullable(stmt->parameters[ipar].paramType);
236+
*pfNullable = pgtype_nullable(stmt, stmt->parameters[ipar].paramType);
232237

233238
return SQL_SUCCESS;
234239
}
@@ -247,37 +252,25 @@ RETCODE SQL_API SQLParamOptions(
247252

248253
// - - - - - - - - -
249254

250-
// Returns the number of parameter markers.
255+
// Returns the number of parameters in an SQL statement
251256

252257
RETCODE SQL_API SQLNumParams(
253258
HSTMT hstmt,
254259
SWORD FAR *pcpar)
255260
{
256261
StatementClass *stmt = (StatementClass *) hstmt;
257-
unsigned int i;
258262

259-
// I guess this is the number of actual parameter markers
260-
// in the statement, not the number of parameters that are bound.
261-
// why does this have to be driver-specific?
262263

263264
if(!stmt)
264265
return SQL_INVALID_HANDLE;
265266

266-
if(!stmt->statement) {
267-
// no statement has been allocated
268-
*pcpar = 0;
269-
stmt->errormsg = "SQLNumParams called with no statement ready.";
270-
stmt->errornumber = STMT_SEQUENCE_ERROR;
271-
return SQL_ERROR;
272-
} else {
273-
*pcpar = 0;
274-
for(i=0; i < strlen(stmt->statement); i++) {
275-
if(stmt->statement[i] == '?')
276-
(*pcpar)++;
277-
}
267+
// If the statement does not have parameters, it should just return 0.
278268

279-
return SQL_SUCCESS;
269+
if (pcpar) {
270+
*pcpar = stmt->parameters_allocated;
280271
}
272+
273+
return SQL_SUCCESS;
281274
}
282275

283276
/********************************************************************
@@ -309,7 +302,7 @@ extend_bindings(StatementClass *stmt, int num_columns)
309302
BindInfoClass *new_bindings;
310303
int i;
311304

312-
mylog("in extend_bindings\n");
305+
mylog("in extend_bindings: stmt=%u, bindings_allocated=%d, num_columns=%d\n", stmt, stmt->bindings_allocated, num_columns);
313306

314307
/* if we have too few, allocate room for more, and copy the old */
315308
/* entries into the new structure */
@@ -325,6 +318,7 @@ int i;
325318
}
326319

327320
stmt->bindings = new_bindings; // null indicates error
321+
stmt->bindings_allocated = num_columns;
328322

329323
} else {
330324
/* if we have too many, make sure the extra ones are emptied out */

src/interfaces/odbc/bind.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
2-
/* File: bind.h
3-
*
4-
* Description: See "bind.c"
5-
*
6-
* Comments: See "notice.txt" for copyright and license information.
7-
*
8-
*/
1+
2+
/* File: bind.h
3+
*
4+
* Description: See "bind.c"
5+
*
6+
* Comments: See "notice.txt" for copyright and license information.
7+
*
8+
*/
99

1010
#ifndef __BIND_H__
1111
#define __BIND_H__
1212

1313
#include "psqlodbc.h"
1414

15-
/*
16-
* BindInfoClass -- stores information about a bound column
17-
*/
15+
/*
16+
* BindInfoClass -- stores information about a bound column
17+
*/
1818
struct BindInfoClass_ {
1919
Int4 buflen; /* size of buffer */
2020
char *buffer; /* pointer to the buffer */
@@ -33,10 +33,11 @@ struct ParameterInfoClass_ {
3333
Int2 CType;
3434
Int2 SQLType;
3535
UInt4 precision;
36-
Int2 scale;
37-
Int4 *EXEC_used;
38-
char *EXEC_buffer;
39-
char data_at_exec;
36+
Int2 scale;
37+
Oid lobj_oid;
38+
Int4 *EXEC_used; /* amount of data OR the oid of the large object */
39+
char *EXEC_buffer; /* the data or the FD of the large object */
40+
char data_at_exec;
4041
};
4142

4243
BindInfoClass *create_empty_bindings(int num_columns);

src/interfaces/odbc/columninfo.c

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
2-
/* Module: columninfo.c
3-
*
4-
* Description: This module contains routines related to
5-
* reading and storing the field information from a query.
6-
*
7-
* Classes: ColumnInfoClass (Functions prefix: "CI_")
8-
*
9-
* API functions: none
10-
*
11-
* Comments: See "notice.txt" for copyright and license information.
12-
*
13-
*/
14-
15-
#include "columninfo.h"
1+
2+
/* Module: columninfo.c
3+
*
4+
* Description: This module contains routines related to
5+
* reading and storing the field information from a query.
6+
*
7+
* Classes: ColumnInfoClass (Functions prefix: "CI_")
8+
*
9+
* API functions: none
10+
*
11+
* Comments: See "notice.txt" for copyright and license information.
12+
*
13+
*/
14+
15+
#include "columninfo.h"
1616
#include "socket.h"
1717
#include <stdlib.h>
1818
#include <malloc.h>
@@ -29,6 +29,7 @@ ColumnInfoClass *rv;
2929
rv->name = NULL;
3030
rv->adtid = NULL;
3131
rv->adtsize = NULL;
32+
rv->display_size = NULL;
3233
}
3334

3435
return rv;
@@ -54,7 +55,7 @@ int new_num_fields;
5455
Oid new_adtid;
5556
Int2 new_adtsize;
5657
char new_field_name[MAX_MESSAGE_LEN+1];
57-
58+
5859

5960
/* at first read in the number of fields that are in the query */
6061
new_num_fields = (Int2) SOCK_get_int(sock, sizeof(Int2));
@@ -93,11 +94,12 @@ int num_fields = self->num_fields;
9394
if( self->name[lf])
9495
free (self->name[lf]);
9596
}
96-
97+
9798
/* Safe to call even if null */
9899
free(self->name);
99100
free(self->adtid);
100101
free(self->adtsize);
102+
free(self->display_size);
101103
}
102104

103105
void
@@ -110,6 +112,7 @@ CI_set_num_fields(ColumnInfoClass *self, int new_num_fields)
110112
self->name = (char **) malloc (sizeof(char *) * self->num_fields);
111113
self->adtid = (Oid *) malloc (sizeof(Oid) * self->num_fields);
112114
self->adtsize = (Int2 *) malloc (sizeof(Int2) * self->num_fields);
115+
self->display_size = (Int2 *) malloc(sizeof(Int2) * self->num_fields);
113116
}
114117

115118
void
@@ -126,34 +129,7 @@ CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name,
126129
self->name[field_num] = strdup(new_name);
127130
self->adtid[field_num] = new_adtid;
128131
self->adtsize[field_num] = new_adtsize;
129-
}
130132

131-
char *
132-
CI_get_fieldname(ColumnInfoClass *self, Int2 which)
133-
{
134-
char *rv = NULL;
135-
136-
if ( ! self->name)
137-
return NULL;
138-
139-
if ((which >= 0) && (which < self->num_fields))
140-
rv = self->name[which];
141-
142-
return rv;
143-
}
144-
145-
146-
Int2
147-
CI_get_fieldsize(ColumnInfoClass *self, Int2 which)
148-
{
149-
Int2 rv = 0;
150-
151-
if ( ! self->adtsize)
152-
return 0;
153-
154-
if ((which >= 0) && (which < self->num_fields))
155-
rv = self->adtsize[which];
156-
157-
return rv;
133+
self->display_size[field_num] = 0;
158134
}
159135

src/interfaces/odbc/columninfo.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
2-
/* File: columninfo.h
3-
*
4-
* Description: See "columninfo.c"
5-
*
6-
* Comments: See "notice.txt" for copyright and license information.
7-
*
8-
*/
1+
2+
/* File: columninfo.h
3+
*
4+
* Description: See "columninfo.c"
5+
*
6+
* Comments: See "notice.txt" for copyright and license information.
7+
*
8+
*/
99

1010
#ifndef __COLUMNINFO_H__
1111
#define __COLUMNINFO_H__
@@ -17,14 +17,18 @@ struct ColumnInfoClass_ {
1717
char **name; /* list of type names */
1818
Oid *adtid; /* list of type ids */
1919
Int2 *adtsize; /* list type sizes */
20+
Int2 *display_size; /* the display size (longest row) */
2021
};
2122

22-
#define CI_get_num_fields(self) (self->num_fields)
23-
#define CI_get_oid(self, col) (self->adtid[col])
24-
23+
#define CI_get_num_fields(self) (self->num_fields)
24+
#define CI_get_oid(self, col) (self->adtid[col])
25+
#define CI_get_fieldname(self, col) (self->name[col])
26+
#define CI_get_fieldsize(self, col) (self->adtsize[col])
27+
#define CI_get_display_size(self, col) (self->display_size[col])
2528

2629
ColumnInfoClass *CI_Constructor();
2730
void CI_Destructor(ColumnInfoClass *self);
31+
void CI_free_memory(ColumnInfoClass *self);
2832
char CI_read_fields(ColumnInfoClass *self, SocketClass *sock);
2933

3034
/* functions for setting up the fields from within the program, */
@@ -33,8 +37,5 @@ void CI_set_num_fields(ColumnInfoClass *self, int new_num_fields);
3337
void CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name,
3438
Oid new_adtid, Int2 new_adtsize);
3539

36-
char *CI_get_fieldname(ColumnInfoClass *self, Int2 which);
37-
Int2 CI_get_fieldsize(ColumnInfoClass *self, Int2 which);
38-
void CI_free_memory(ColumnInfoClass *self);
3940

4041
#endif

0 commit comments

Comments
 (0)