~ubuntu-branches/ubuntu/gutsy/psqlodbc/gutsy

« back to all changes in this revision

Viewing changes to bind.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2007-03-05 22:28:19 UTC
  • mfrom: (3.1.4 edgy)
  • Revision ID: james.westby@ubuntu.com-20070305222819-95d0rzmt2ah6dwwc
Tags: 1:08.01.0200-2.1
* Non-maintainer upload.
* High-urgency upload for RC bugfix.
* Fix the signature of SQLGetData on 64-bit architectures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
RETCODE         SQL_API
31
31
PGAPI_BindParameter(
32
32
                                        HSTMT hstmt,
33
 
                                        UWORD ipar,
34
 
                                        SWORD fParamType,
35
 
                                        SWORD fCType,
36
 
                                        SWORD fSqlType,
37
 
                                        UDWORD cbColDef,
38
 
                                        SWORD ibScale,
 
33
                                        SQLUSMALLINT ipar,
 
34
                                        SQLSMALLINT fParamType,
 
35
                                        SQLSMALLINT fCType,
 
36
                                        SQLSMALLINT fSqlType,
 
37
                                        SQLUINTEGER cbColDef,
 
38
                                        SQLSMALLINT ibScale,
39
39
                                        PTR rgbValue,
40
 
                                        SDWORD cbValueMax,
41
 
                                        SDWORD FAR * pcbValue)
 
40
                                        SQLINTEGER cbValueMax,
 
41
                                        SQLINTEGER *pcbValue)
42
42
{
43
43
        StatementClass *stmt = (StatementClass *) hstmt;
44
44
        CSTR func = "PGAPI_BindParameter";
45
45
        APDFields       *apdopts;
46
46
        IPDFields       *ipdopts;
 
47
        PutDataInfo     *pdata_info;
47
48
 
48
49
        mylog("%s: entering...\n", func);
49
50
 
54
55
        }
55
56
        SC_clear_error(stmt);
56
57
 
57
 
        apdopts = SC_get_APD(stmt);
 
58
        apdopts = SC_get_APDF(stmt);
58
59
        if (apdopts->allocated < ipar)
59
60
                extend_parameter_bindings(apdopts, ipar);
60
 
        ipdopts = SC_get_IPD(stmt);
 
61
        ipdopts = SC_get_IPDF(stmt);
61
62
        if (ipdopts->allocated < ipar)
62
63
                extend_iparameter_bindings(ipdopts, ipar);
 
64
        pdata_info = SC_get_PDTI(stmt);
 
65
        if (pdata_info->allocated < ipar)
 
66
                extend_putdata_info(pdata_info, ipar, FALSE);
63
67
 
64
68
        /* use zero based column numbers for the below part */
65
69
        ipar--;
67
71
        /* store the given info */
68
72
        apdopts->parameters[ipar].buflen = cbValueMax;
69
73
        apdopts->parameters[ipar].buffer = rgbValue;
70
 
        apdopts->parameters[ipar].used = pcbValue;
71
 
        apdopts->parameters[ipar].paramType = fParamType;
 
74
        apdopts->parameters[ipar].used = (Int4 *) pcbValue;
72
75
        apdopts->parameters[ipar].CType = fCType;
73
76
        ipdopts->parameters[ipar].SQLType = fSqlType;
74
77
        ipdopts->parameters[ipar].paramType = fParamType;
77
80
        ipdopts->parameters[ipar].precision = 0;
78
81
        ipdopts->parameters[ipar].scale = 0;
79
82
        ipdopts->parameters[ipar].PGType = sqltype_to_pgtype(stmt, fSqlType);
80
 
#if (ODBCVER >= 0x0300)
 
83
 
81
84
        switch (fCType)
82
85
        {
83
86
                case SQL_C_NUMERIC:
93
96
        }
94
97
        apdopts->parameters[ipar].precision = ipdopts->parameters[ipar].precision;
95
98
        apdopts->parameters[ipar].scale = ipdopts->parameters[ipar].scale;
96
 
#endif /* ODBCVER */
97
99
 
98
100
        /*
99
101
         * If rebinding a parameter that had data-at-exec stuff in it, then
100
102
         * free that stuff
101
103
         */
102
 
        if (apdopts->parameters[ipar].EXEC_used)
 
104
        if (pdata_info->pdata[ipar].EXEC_used)
103
105
        {
104
 
                free(apdopts->parameters[ipar].EXEC_used);
105
 
                apdopts->parameters[ipar].EXEC_used = NULL;
 
106
                free(pdata_info->pdata[ipar].EXEC_used);
 
107
                pdata_info->pdata[ipar].EXEC_used = NULL;
106
108
        }
107
109
 
108
 
        if (apdopts->parameters[ipar].EXEC_buffer)
 
110
        if (pdata_info->pdata[ipar].EXEC_buffer)
109
111
        {
110
 
                free(apdopts->parameters[ipar].EXEC_buffer);
111
 
                apdopts->parameters[ipar].EXEC_buffer = NULL;
 
112
                free(pdata_info->pdata[ipar].EXEC_buffer);
 
113
                pdata_info->pdata[ipar].EXEC_buffer = NULL;
112
114
        }
113
115
 
114
116
        if (pcbValue && apdopts->param_offset_ptr)
133
135
/*      Associate a user-supplied buffer with a database column. */
134
136
RETCODE         SQL_API
135
137
PGAPI_BindCol(
136
 
                          HSTMT hstmt,
137
 
                          UWORD icol,
138
 
                          SWORD fCType,
139
 
                          PTR rgbValue,
140
 
                          SDWORD cbValueMax,
141
 
                          SDWORD FAR * pcbValue)
 
138
                        HSTMT hstmt,
 
139
                        SQLUSMALLINT icol, 
 
140
                        SQLSMALLINT fCType,
 
141
                        PTR rgbValue, 
 
142
                        SQLINTEGER cbValueMax,
 
143
                        SQLINTEGER *pcbValue)
142
144
{
143
145
        StatementClass *stmt = (StatementClass *) hstmt;
144
146
        CSTR func = "PGAPI_BindCol";
145
147
        ARDFields       *opts;
 
148
        GetDataInfo     *gdata_info;
 
149
        BindInfoClass   *bookmark;
146
150
 
147
151
        mylog("%s: entering...\n", func);
148
152
 
155
159
                return SQL_INVALID_HANDLE;
156
160
        }
157
161
 
158
 
 
159
 
 
160
 
        opts = SC_get_ARD(stmt);
 
162
        opts = SC_get_ARDF(stmt);
161
163
        if (stmt->status == STMT_EXECUTING)
162
164
        {
163
165
                SC_set_error(stmt, STMT_SEQUENCE_ERROR, "Can't bind columns while statement is still executing.");
169
171
        /* If the bookmark column is being bound, then just save it */
170
172
        if (icol == 0)
171
173
        {
 
174
                bookmark = opts->bookmark;
172
175
                if (rgbValue == NULL)
173
176
                {
174
 
                        opts->bookmark->buffer = NULL;
175
 
                        opts->bookmark->used = NULL;
 
177
                        if (bookmark)
 
178
                        {
 
179
                                bookmark->buffer = NULL;
 
180
                                bookmark->used = NULL;
 
181
                        }
176
182
                }
177
183
                else
178
184
                {
180
186
                        switch (fCType)
181
187
                        {
182
188
                                case SQL_C_BOOKMARK:
183
 
#if (ODBCVER >= 0x0300)
184
189
                                case SQL_C_VARBOOKMARK:
185
 
#endif /* ODBCVER */
 
190
 
186
191
                                        break;
187
192
                                default:
188
193
                                        SC_set_error(stmt, STMT_PROGRAM_TYPE_OUT_OF_RANGE, "Bind column 0 is not of type SQL_C_BOOKMARK");
189
 
inolog("Bind column 0 is type %d not of type SQL_C_BOOKMARK", fCType);
 
194
                    mylog("Bind column 0 is type %d not of type SQL_C_BOOKMARK\n", fCType);
190
195
                                        SC_log_error(func, "", stmt);
191
196
                                        return SQL_ERROR;
192
197
                        }
193
198
 
194
 
                        opts->bookmark->buffer = rgbValue;
195
 
                        opts->bookmark->used = pcbValue;
196
 
                        opts->bookmark->buflen = cbValueMax;
197
 
                        opts->bookmark->returntype = fCType;
 
199
                        bookmark = ARD_AllocBookmark(opts);
 
200
                        bookmark->buffer = rgbValue;
 
201
                        bookmark->used = (Int4 *) pcbValue;
 
202
                        bookmark->buflen = cbValueMax;
 
203
                        bookmark->returntype = fCType;
198
204
                }
199
205
                return SQL_SUCCESS;
200
206
        }
206
212
         */
207
213
        if (icol > opts->allocated)
208
214
                extend_column_bindings(opts, icol);
 
215
        gdata_info = SC_get_GDTI(stmt);
 
216
        if (icol > gdata_info->allocated)
 
217
                extend_getdata_info(gdata_info, icol, FALSE);
209
218
 
210
219
        /* check to see if the bindings were allocated */
211
220
        if (!opts->bindings)
219
228
        icol--;
220
229
 
221
230
        /* Reset for SQLGetData */
222
 
        opts->bindings[icol].data_left = -1;
 
231
        gdata_info->gdata[icol].data_left = -1;
223
232
 
224
233
        if (rgbValue == NULL)
225
234
        {
228
237
                opts->bindings[icol].buffer = NULL;
229
238
                opts->bindings[icol].used = NULL;
230
239
                opts->bindings[icol].returntype = SQL_C_CHAR;
231
 
                if (opts->bindings[icol].ttlbuf)
232
 
                        free(opts->bindings[icol].ttlbuf);
233
 
                opts->bindings[icol].ttlbuf = NULL;
234
 
                opts->bindings[icol].ttlbuflen = 0;
235
 
                opts->bindings[icol].ttlbufused = 0;
236
240
                opts->bindings[icol].precision = 0;
237
241
                opts->bindings[icol].scale = 0;
 
242
                if (gdata_info->gdata[icol].ttlbuf)
 
243
                        free(gdata_info->gdata[icol].ttlbuf);
 
244
                gdata_info->gdata[icol].ttlbuf = NULL;
 
245
                gdata_info->gdata[icol].ttlbuflen = 0;
 
246
                gdata_info->gdata[icol].ttlbufused = 0;
238
247
        }
239
248
        else
240
249
        {
241
250
                /* ok, bind that column */
242
251
                opts->bindings[icol].buflen = cbValueMax;
243
252
                opts->bindings[icol].buffer = rgbValue;
244
 
                opts->bindings[icol].used = pcbValue;
 
253
                opts->bindings[icol].used = (Int4 *) pcbValue;
245
254
                opts->bindings[icol].returntype = fCType;
246
 
#if (ODBCVER >= 0x0300)
 
255
 
247
256
                if (SQL_C_NUMERIC == fCType)
248
257
                        opts->bindings[icol].precision = 32;
249
258
                else
250
 
#endif /* ODBCVER */
251
259
                        opts->bindings[icol].precision = 0;
252
260
                opts->bindings[icol].scale = 0;
253
261
 
267
275
 *      data type (most likely varchar).
268
276
 */
269
277
RETCODE         SQL_API
270
 
PGAPI_DescribeParam(
271
 
                                        HSTMT hstmt,
272
 
                                        UWORD ipar,
273
 
                                        SWORD FAR * pfSqlType,
274
 
                                        UDWORD FAR * pcbColDef,
275
 
                                        SWORD FAR * pibScale,
276
 
                                        SWORD FAR * pfNullable)
 
278
PGAPI_DescribeParam(HSTMT hstmt,
 
279
                        SQLUSMALLINT ipar,
 
280
                        SQLSMALLINT *pfSqlType,
 
281
                        SQLUINTEGER *pcbColDef,
 
282
                        SQLSMALLINT *pibScale,
 
283
                        SQLSMALLINT *pfNullable)
277
284
{
278
285
        StatementClass *stmt = (StatementClass *) hstmt;
279
286
        CSTR func = "PGAPI_DescribeParam";
289
296
        }
290
297
        SC_clear_error(stmt);
291
298
 
292
 
        apdopts = SC_get_APD(stmt);
 
299
        apdopts = SC_get_APDF(stmt);
293
300
        if ((ipar < 1) || (ipar > apdopts->allocated))
294
301
        {
295
302
                SC_set_error(stmt, STMT_BAD_PARAMETER_NUMBER_ERROR, "Invalid parameter number for PGAPI_DescribeParam.");
296
303
                SC_log_error(func, "", stmt);
297
304
                return SQL_ERROR;
298
305
        }
299
 
        ipdopts = SC_get_IPD(stmt);
 
306
        ipdopts = SC_get_IPDF(stmt);
300
307
 
301
308
        ipar--;
302
309
 
315
322
                *pibScale = ipdopts->parameters[ipar].decimal_digits;
316
323
 
317
324
        if (pfNullable)
318
 
                *pfNullable = pgtype_nullable(stmt, apdopts->parameters[ipar].paramType);
 
325
                *pfNullable = pgtype_nullable(stmt, ipdopts->parameters[ipar].paramType);
319
326
 
320
327
        return SQL_SUCCESS;
321
328
}
323
330
 
324
331
/*      Sets multiple values (arrays) for the set of parameter markers. */
325
332
RETCODE         SQL_API
326
 
PGAPI_ParamOptions(
327
 
                                   HSTMT hstmt,
328
 
                                   UDWORD crow,
329
 
                                   UDWORD FAR * pirow)
 
333
PGAPI_ParamOptions(HSTMT hstmt,
 
334
                   SQLUINTEGER crow,
 
335
                   SQLUINTEGER *pirow)
330
336
{
331
337
        CSTR func = "PGAPI_ParamOptions";
332
338
        StatementClass *stmt = (StatementClass *) hstmt;
334
340
 
335
341
        mylog("%s: entering... %d %x\n", func, crow, pirow);
336
342
 
337
 
        apdopts = SC_get_APD(stmt);
 
343
        apdopts = SC_get_APDF(stmt);
338
344
        apdopts->paramset_size = crow;
339
 
        SC_get_IPD(stmt)->param_processed_ptr = (UInt4 *) pirow;
 
345
        SC_get_IPDF(stmt)->param_processed_ptr = (UInt4 *) pirow;
340
346
        return SQL_SUCCESS;
341
347
}
342
348
 
377
383
        }
378
384
 
379
385
 
380
 
        if (!stmt->statement)
 
386
        if (stmt->num_params >= 0)
 
387
                *pcpar = stmt->num_params;
 
388
        else if (!stmt->statement)
381
389
        {
382
390
                /* no statement has been allocated */
383
391
                SC_set_error(stmt, STMT_SEQUENCE_ERROR, "PGAPI_NumParams called with no statement ready.");
396
404
                                        in_quote = (in_quote ? FALSE : TRUE);
397
405
                        }
398
406
                }
399
 
                return SQL_SUCCESS;
 
407
                stmt->num_params = *pcpar;
400
408
        }
 
409
        return SQL_SUCCESS;
401
410
}
402
411
 
403
412
 
404
413
/*
405
414
 *       Bindings Implementation
406
415
 */
407
 
BindInfoClass *
 
416
static BindInfoClass *
408
417
create_empty_bindings(int num_columns)
409
418
{
410
419
        BindInfoClass *new_bindings;
419
428
                new_bindings[i].buflen = 0;
420
429
                new_bindings[i].buffer = NULL;
421
430
                new_bindings[i].used = NULL;
422
 
                new_bindings[i].data_left = -1;
423
 
                new_bindings[i].ttlbuf = NULL;
424
 
                new_bindings[i].ttlbuflen = 0;
425
 
                new_bindings[i].ttlbufused = 0;
426
431
        }
427
432
 
428
433
        return new_bindings;
508
513
        self->parameters[ipar].buflen = 0;
509
514
        self->parameters[ipar].buffer = 0;
510
515
        self->parameters[ipar].used = 0;
511
 
        self->parameters[ipar].paramType = 0;
512
516
        self->parameters[ipar].CType = 0;
513
517
        self->parameters[ipar].data_at_exec = FALSE;
514
 
        if (self->parameters[ipar].EXEC_used)
515
 
        {
516
 
                free(self->parameters[ipar].EXEC_used);
517
 
                self->parameters[ipar].EXEC_used = NULL;
518
 
        }
519
 
 
520
 
        if (self->parameters[ipar].EXEC_buffer)
521
 
        {
522
 
                free(self->parameters[ipar].EXEC_buffer);
523
 
                self->parameters[ipar].EXEC_buffer = NULL;
524
 
        }
525
 
        self->parameters[ipar].lobj_oid = 0;
526
518
        self->parameters[ipar].precision = 0;
527
519
        self->parameters[ipar].scale = 0;
528
520
}
552
544
void
553
545
APD_free_params(APDFields *apdopts, char option)
554
546
{
555
 
        int                     i;
556
 
 
557
547
        mylog("APD_free_params:  ENTER, self=%d\n", apdopts);
558
548
 
559
549
        if (!apdopts->parameters)
560
550
                return;
561
551
 
562
 
        for (i = 0; i < apdopts->allocated; i++)
563
 
        {
564
 
                if (apdopts->parameters[i].data_at_exec)
565
 
                {
566
 
                        if (apdopts->parameters[i].EXEC_used)
567
 
                        {
568
 
                                free(apdopts->parameters[i].EXEC_used);
569
 
                                apdopts->parameters[i].EXEC_used = NULL;
570
 
                        }
571
 
                        if (apdopts->parameters[i].EXEC_buffer)
572
 
                        {
573
 
                                free(apdopts->parameters[i].EXEC_buffer);
574
 
                                apdopts->parameters[i].EXEC_buffer = NULL;
575
 
                        }
576
 
                }
577
 
        }
578
 
 
579
552
        if (option == STMT_FREE_PARAMS_ALL)
580
553
        {
581
 
                if (apdopts->parameters)
582
 
                        free(apdopts->parameters);
 
554
                free(apdopts->parameters);
583
555
                apdopts->parameters = NULL;
584
556
                apdopts->allocated = 0;
585
557
        }
587
559
        mylog("APD_free_params:  EXIT\n");
588
560
}
589
561
 
 
562
void
 
563
PDATA_free_params(PutDataInfo *pdata, char option)
 
564
{
 
565
        int                     i;
 
566
 
 
567
        mylog("PDATA_free_params:  ENTER, self=%d\n", pdata);
 
568
 
 
569
        if (!pdata->pdata)
 
570
                return;
 
571
 
 
572
        for (i = 0; i < pdata->allocated; i++)
 
573
        {
 
574
                if (pdata->pdata[i].EXEC_used)
 
575
                {
 
576
                        free(pdata->pdata[i].EXEC_used);
 
577
                        pdata->pdata[i].EXEC_used = NULL;
 
578
                }
 
579
                if (pdata->pdata[i].EXEC_buffer)
 
580
                {
 
581
                        free(pdata->pdata[i].EXEC_buffer);
 
582
                        pdata->pdata[i].EXEC_buffer = NULL;
 
583
                }
 
584
        }
 
585
 
 
586
        if (option == STMT_FREE_PARAMS_ALL)
 
587
        {
 
588
                free(pdata->pdata);
 
589
                pdata->pdata = NULL;
 
590
                pdata->allocated = 0;
 
591
        }
 
592
 
 
593
        mylog("PDATA_free_params:  EXIT\n");
 
594
}
 
595
 
590
596
/*
591
597
 *      Free parameters and free the memory.
592
598
 */
595
601
{
596
602
        mylog("IPD_free_params:  ENTER, self=%d\n", ipdopts);
597
603
 
598
 
        if (ipdopts->parameters &&
599
 
                option == STMT_FREE_PARAMS_ALL)
 
604
        if (!ipdopts->parameters)
 
605
                return;
 
606
        if (option == STMT_FREE_PARAMS_ALL)
600
607
        {
601
 
                if (ipdopts->parameters)
602
 
                        free(ipdopts->parameters);
 
608
                free(ipdopts->parameters);
603
609
                ipdopts->parameters = NULL;
604
610
                ipdopts->allocated = 0;
605
611
        }
665
671
reset_a_column_binding(ARDFields *self, int icol)
666
672
{
667
673
        CSTR func = "reset_a_column_binding";
 
674
        BindInfoClass   *bookmark;
668
675
 
669
676
        mylog("%s: entering ... self=%u, bindings_allocated=%d, icol=%d\n", func, self, self->allocated, icol);
670
677
 
674
681
        /* use zero based col numbers from here out */
675
682
        if (0 == icol)
676
683
        {
677
 
                self->bookmark->buffer = NULL;
678
 
                self->bookmark->used = NULL;
 
684
                if (bookmark = self->bookmark, bookmark != NULL)
 
685
                {
 
686
                        bookmark->buffer = NULL;
 
687
                        bookmark->used = NULL;
 
688
                }
679
689
        }
680
690
        else
681
691
        {
685
695
                self->bindings[icol].buflen = 0;
686
696
                self->bindings[icol].buffer = NULL;
687
697
                self->bindings[icol].used = NULL;
688
 
                self->bindings[icol].data_left = -1;
689
698
                self->bindings[icol].returntype = SQL_C_CHAR;
690
 
                if (self->bindings[icol].ttlbuf)
691
 
                        free(self->bindings[icol].ttlbuf);
692
 
                self->bindings[icol].ttlbuf = NULL;
693
 
                self->bindings[icol].ttlbuflen = 0;
694
 
                self->bindings[icol].ttlbufused = 0;
695
699
        }
696
700
}
697
701
 
699
703
{
700
704
        Int2    lf;
701
705
 
 
706
    mylog("ARD_unbind_cols freeall=%d allocated=%d bindings=%x\n", freeall, self->allocated, self->bindings);
702
707
        for (lf = 1; lf <= self->allocated; lf++)
703
708
                reset_a_column_binding(self, lf);
704
709
        if (freeall)
708
713
                self->bindings = NULL;
709
714
                self->allocated = 0;
710
715
        }
711
 
 
716
}
 
717
void    GDATA_unbind_cols(GetDataInfo *self, BOOL freeall)
 
718
{
 
719
        Int2    lf;
 
720
 
 
721
    mylog("GDATA_unbind_cols freeall=%d allocated=%d gdata=%x\n", freeall, self->allocated, self->gdata);
 
722
        if (self->fdata.ttlbuf)
 
723
        {
 
724
                free(self->fdata.ttlbuf);
 
725
                self->fdata.ttlbuf = NULL;
 
726
        }
 
727
        self->fdata.ttlbuflen = self->fdata.ttlbufused = 0;
 
728
        self->fdata.data_left = -1;
 
729
        for (lf = 1; lf <= self->allocated; lf++)
 
730
                reset_a_getdata_info(self, lf);
 
731
        if (freeall)
 
732
        {
 
733
                if (self->gdata)
 
734
                        free(self->gdata);
 
735
                self->gdata = NULL;
 
736
                self->allocated = 0;
 
737
        }
 
738
}
 
739
 
 
740
void GetDataInfoInitialize(GetDataInfo *gdata_info)
 
741
{
 
742
        gdata_info->fdata.data_left = -1;
 
743
        gdata_info->fdata.ttlbuf = NULL;
 
744
        gdata_info->fdata.ttlbuflen = gdata_info->fdata.ttlbufused = 0;
 
745
        gdata_info->allocated = 0;
 
746
        gdata_info->gdata = NULL;
 
747
}
 
748
static GetDataClass *
 
749
create_empty_gdata(int num_columns)
 
750
{
 
751
        GetDataClass    *new_gdata;
 
752
        int                     i;
 
753
 
 
754
        new_gdata = (GetDataClass *) malloc(num_columns * sizeof(GetDataClass));
 
755
        if (!new_gdata)
 
756
                return NULL;
 
757
 
 
758
        for (i = 0; i < num_columns; i++)
 
759
        {
 
760
                new_gdata[i].data_left = -1;
 
761
                new_gdata[i].ttlbuf = NULL;
 
762
                new_gdata[i].ttlbuflen = 0;
 
763
                new_gdata[i].ttlbufused = 0;
 
764
        }
 
765
 
 
766
        return new_gdata;
 
767
}
 
768
void
 
769
extend_getdata_info(GetDataInfo *self, int num_columns, BOOL shrink)
 
770
{
 
771
        CSTR func = "extend_getdata_info";
 
772
        GetDataClass    *new_gdata;
 
773
        int                     i;
 
774
 
 
775
        mylog("%s: entering ... self=%u, gdata_allocated=%d, num_columns=%d\n", func, self, self->allocated, num_columns);
 
776
 
 
777
        /*
 
778
         * if we have too few, allocate room for more, and copy the old
 
779
         * entries into the new structure
 
780
         */
 
781
        if (self->allocated < num_columns)
 
782
        {
 
783
                new_gdata = create_empty_gdata(num_columns);
 
784
                if (!new_gdata)
 
785
                {
 
786
                        mylog("%s: unable to create %d new gdata from %d old gdata\n", func, num_columns, self->allocated);
 
787
 
 
788
                        if (self->gdata)
 
789
                        {
 
790
                                free(self->gdata);
 
791
                                self->gdata = NULL;
 
792
                        }
 
793
                        self->allocated = 0;
 
794
                        return;
 
795
                }
 
796
                if (self->gdata)
 
797
                {
 
798
                        for (i = 0; i < self->allocated; i++)
 
799
                                new_gdata[i] = self->gdata[i];
 
800
                        free(self->gdata);
 
801
                }
 
802
                self->gdata = new_gdata;
 
803
                self->allocated = num_columns;
 
804
        }
 
805
        else if (shrink && self->allocated > num_columns)
 
806
        {
 
807
                for (i = self->allocated; i > num_columns; i--)
 
808
                        reset_a_getdata_info(self, i);
 
809
                self->allocated = num_columns;
 
810
                if (0 == num_columns)
 
811
                {
 
812
                        free(self->gdata);
 
813
                        self->gdata = NULL;
 
814
                }
 
815
        } 
 
816
 
 
817
        /*
 
818
         * There is no reason to zero out extra gdata if there are more
 
819
         * than needed.  If an app has allocated extra gdata, let it worry
 
820
         * about it by unbinding those columns.
 
821
         */
 
822
 
 
823
        mylog("exit extend_gdata_info\n");
 
824
}
 
825
void    reset_a_getdata_info(GetDataInfo *gdata_info, int icol)
 
826
{
 
827
        if (icol < 1 || icol > gdata_info->allocated)
 
828
                return;
 
829
        icol--;
 
830
        if (gdata_info->gdata[icol].ttlbuf)
 
831
        {
 
832
                free(gdata_info->gdata[icol].ttlbuf);
 
833
                gdata_info->gdata[icol].ttlbuf = NULL;
 
834
        }
 
835
        gdata_info->gdata[icol].ttlbuflen =
 
836
        gdata_info->gdata[icol].ttlbufused = 0;
 
837
        gdata_info->gdata[icol].data_left = -1;
 
838
}
 
839
 
 
840
void PutDataInfoInitialize(PutDataInfo *pdata_info)
 
841
{
 
842
        pdata_info->allocated = 0;
 
843
        pdata_info->pdata = NULL;
 
844
}
 
845
void
 
846
extend_putdata_info(PutDataInfo *self, int num_params, BOOL shrink)
 
847
{
 
848
        CSTR func = "extend_putdata_info";
 
849
        PutDataClass    *new_pdata;
 
850
 
 
851
        mylog("%s: entering ... self=%u, parameters_allocated=%d, num_params=%d\n", func, self, self->allocated, num_params);
 
852
 
 
853
        /*
 
854
         * if we have too few, allocate room for more, and copy the old
 
855
         * entries into the new structure
 
856
         */
 
857
        if (self->allocated < num_params)
 
858
        {
 
859
                new_pdata = (PutDataClass *) realloc(self->pdata, sizeof(PutDataClass) * num_params);
 
860
                if (!new_pdata)
 
861
                {
 
862
                        mylog("%s: unable to create %d new pdata from %d old pdata\n", func, num_params, self->allocated);
 
863
 
 
864
                        self->pdata = NULL;
 
865
                        self->allocated = 0;
 
866
                        return;
 
867
                }
 
868
                memset(&new_pdata[self->allocated], 0,
 
869
                        sizeof(PutDataClass) * (num_params - self->allocated));
 
870
 
 
871
                self->pdata = new_pdata;
 
872
                self->allocated = num_params;
 
873
        }
 
874
        else if (shrink && self->allocated > num_params)
 
875
        {
 
876
                int     i;
 
877
 
 
878
                for (i = self->allocated; i > num_params; i--)
 
879
                        reset_a_putdata_info(self, i);
 
880
                self->allocated = num_params;
 
881
                if (0 == num_params)
 
882
                {
 
883
                        free(self->pdata);
 
884
                        self->pdata = NULL;
 
885
                }
 
886
        }
 
887
 
 
888
        mylog("exit extend_putdata_info\n");
 
889
}
 
890
void    reset_a_putdata_info(PutDataInfo *pdata_info, int ipar)
 
891
{
 
892
        if (ipar < 1 || ipar > pdata_info->allocated)
 
893
                return;
 
894
        ipar--;
 
895
        if (pdata_info->pdata[ipar].EXEC_used)
 
896
        {
 
897
                free(pdata_info->pdata[ipar].EXEC_used);
 
898
                pdata_info->pdata[ipar].EXEC_used = NULL;
 
899
        }
 
900
        if (pdata_info->pdata[ipar].EXEC_buffer)
 
901
        {
 
902
                free(pdata_info->pdata[ipar].EXEC_buffer);
 
903
                pdata_info->pdata[ipar].EXEC_buffer = NULL;
 
904
        }
 
905
        pdata_info->pdata[ipar].lobj_oid = 0;
 
906
}