-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresult.c
641 lines (541 loc) · 21.4 KB
/
result.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
#include "driver.h"
#include "convert.h"
conv_resp retrieve_and_convert(stmt_t *phstmt,
SQLSMALLINT col, /* col is 0-based. */
SQLSMALLINT c_data_type,
SQLPOINTER target_ptr,
SQLLEN target_len,
SQLLEN *strlen_or_indicator)
{
void *value;
int size, cdb2_type;
if( (cdb2_type = cdb2_column_type(phstmt->sqlh, col)) == -1 )
return CONV_UNKNOWN_CDB2_TYPE;
if((value = cdb2_column_value(phstmt->sqlh, col)) == NULL) {
*strlen_or_indicator = SQL_NULL_DATA;
return CONV_NULL;
}
size = cdb2_column_size(phstmt->sqlh, col);
if(cdb2_type < NUM_CDB2_CONVS) /* Just in case. */
return (*CDB2_CONVS[cdb2_type])(value, size, c_data_type, target_ptr, target_len, strlen_or_indicator);
return CONV_UNKNOWN_CDB2_TYPE;
}
SQLRETURN comdb2_SQLGetData(SQLHSTMT hstmt,
SQLUSMALLINT col,
SQLSMALLINT c_data_type,
SQLPOINTER target_ptr,
SQLLEN target_len,
SQLLEN *strlen_or_indicator)
{
stmt_t *phstmt = (stmt_t *)hstmt;
errid_t eid = ERROR_NA;
int conv_ret;
/* because @strlen_or_indicator could be NULL, a non-NULL value is passed in to conversion functions. */
SQLLEN len_required;
__debug("enters method.");
if(!hstmt)
return SQL_INVALID_HANDLE;
if(target_ptr == NULL)
eid = ERROR_INVALID_NULL_PTR;
else if(!(phstmt->status & (STMT_PREMATURE | STMT_FINISHED)))
eid = ERROR_FUNCTION_SEQ_ERR;
else if(col > phstmt->col_count)
eid = ERROR_INVALID_DESC_IDX;
else if(col == 0) /* column 0 => bookmark */
eid = ERROR_NOT_IMPL;
else {
if (phstmt->status & STMT_SQLCOLUMNS) {
/* We must convert DATA_TYPE (5) and ORDINAL_POSITION (17) in the driver. */
if (col == 5) {
if (cdb2_column_type(phstmt->sqlh, 18) != CDB2_CSTRING)
return set_stmt_error(phstmt,
ERROR_WTH, "Unexpected data type", ODBC_ERROR_CODE);
char *sqltype = cdb2_column_value(phstmt->sqlh, 18);
if (sqltype == NULL)
return set_stmt_error(phstmt,
ERROR_WTH, "Error reading data", ODBC_ERROR_CODE);
LL datatype;
if (strcasecmp(sqltype, "int") == 0)
datatype = SQL_INTEGER;
else if (strcasecmp(sqltype, "smallint") == 0)
datatype = SQL_SMALLINT;
else if (strcasecmp(sqltype, "largeint") == 0)
datatype = SQL_BIGINT;
else if (strcasecmp(sqltype, "smallfloat") == 0)
datatype = SQL_FLOAT;
else if (strcasecmp(sqltype, "float") == 0)
datatype = SQL_DOUBLE;
else if (strcasecmp(sqltype, "double") == 0)
datatype = SQL_DOUBLE;
else if (strcasecmp(sqltype, "real") == 0)
datatype = SQL_REAL;
else if (strncasecmp(sqltype, "char", 4) == 0)
datatype = SQL_VARCHAR;
else if (strncasecmp(sqltype, "varchar", 8) == 0)
datatype = SQL_WVARCHAR;
else if (strcasecmp(sqltype, "blob") == 0)
datatype = SQL_VARBINARY;
else if (strncasecmp(sqltype, "blob", 4) == 0)
datatype = SQL_BINARY;
else if (strncasecmp(sqltype, "datetime", 8) == 0)
datatype = SQL_TYPE_TIMESTAMP;
else if (strncasecmp(sqltype, "decimal", 7) == 0)
datatype = SQL_VARCHAR;
else if (strcasecmp(sqltype, "interval month") == 0)
datatype = SQL_INTERVAL_YEAR_TO_MONTH;
else if (strcasecmp(sqltype, "interval sec") == 0)
datatype = SQL_INTERVAL_DAY_TO_SECOND;
else if (strcasecmp(sqltype, "interval usec") == 0)
datatype = SQL_INTERVAL_DAY_TO_SECOND;
else
datatype = SQL_VARBINARY;
conv_ret = convert_cdb2int(&datatype, sizeof(datatype), c_data_type,
target_ptr, target_len, &len_required);
} else if (col == 17) {
conv_ret = convert_cdb2int(&phstmt->ord_pos,
sizeof(phstmt->ord_pos), c_data_type,
target_ptr, target_len, &len_required);
} else {
conv_ret = retrieve_and_convert(phstmt, col - 1, c_data_type, target_ptr,
target_len, &len_required);
}
} else {
conv_ret = retrieve_and_convert(phstmt, col - 1, c_data_type, target_ptr,
target_len, &len_required);
}
switch(conv_ret) {
case CONV_YEAH:
if(strlen_or_indicator)
*strlen_or_indicator = len_required;
break;
case CONV_TRUNCATED:
eid = ERROR_STR_TRUNCATED;
if(strlen_or_indicator)
*strlen_or_indicator = len_required;
break;
case CONV_TRUNCATED_WHOLE:
eid = ERROR_INVALID_STRING_FOR_CASTING;
if(strlen_or_indicator)
*strlen_or_indicator = len_required;
break;
case CONV_NULL:
/* @strlen_or_indicator must not be NULL if the column data is NULL. */
if(strlen_or_indicator)
*strlen_or_indicator = SQL_NULL_DATA;
else
eid = ERROR_IND_REQUIRED;
break;
case CONV_UNKNOWN_CDB2_TYPE:
eid = ERROR_INVALID_DATA_TYPE;
break;
case CONV_UNKNOWN_C_TYPE:
eid = ERROR_PROG_OUT_OF_RANGE;
break;
case CONV_IMPOSSIBLE:
eid = ERROR_CANNOT_CONVERT;
break;
default:
eid = ERROR_WTH;
break;
}
}
__debug("eid = %d.", eid);
__debug("leaves method.");
return eid == ERROR_NA ? SQL_SUCCESS : STMT_ODBC_ERR(eid);
}
SQLRETURN SQL_API SQLGetData(SQLHSTMT hstmt,
SQLUSMALLINT col,
SQLSMALLINT c_data_type,
SQLPOINTER target_ptr,
SQLLEN target_len,
SQLLEN *strlen_or_ind)
{
return comdb2_SQLGetData(hstmt, col, c_data_type, target_ptr, target_len, strlen_or_ind);
}
SQLRETURN SQL_API SQLFetch(SQLHSTMT hstmt)
{
stmt_t *phstmt = (stmt_t *)hstmt;
int rc, i;
data_buffer_t *data;
__debug("enters method.");
if(!hstmt)
return SQL_INVALID_HANDLE;
if(!(phstmt->status & STMT_FINISHED))
return STMT_ODBC_ERR_MSG(ERROR_FUNCTION_SEQ_ERR,
"Data not ready yet.");
if((rc = cdb2_next_record(phstmt->sqlh)) == CDB2_OK) {
if (phstmt->status & STMT_SQLCOLUMNS)
++phstmt->ord_pos;
if(phstmt->num_data_buffers > 0 && (data = phstmt->buffers) != NULL) {
/* SQLBindCol is called before. */
for(i = 1; data < phstmt->buffers + phstmt->num_data_buffers; ++data, ++i) {
if(!data->used) /* Skip unused data buffer. */
continue;
if(SQL_FAILED(comdb2_SQLGetData(hstmt, (SQLUSMALLINT)i, data->c_type, data->buffer, data->buffer_length, data->required)))
__warn("Failed to return data in bound column %d", i);
}
}
__debug("leaves method.");
return SQL_SUCCESS;
}
SET_EXTRACTED(phstmt);
return rc == CDB2_OK_DONE ? SQL_NO_DATA : set_stmt_error(phstmt, ERROR_WTH, cdb2_errstr(phstmt->sqlh), rc);
}
/* Returns corresponding SQL types of cdb2api types. */
SQLSMALLINT cdb2_to_sql(int cdb2_type)
{
switch(cdb2_type) {
case CDB2_INTEGER:
return SQL_BIGINT;
case CDB2_REAL:
return SQL_DOUBLE;
case CDB2_CSTRING:
return SQL_VARCHAR;
case CDB2_BLOB:
return SQL_VARBINARY;
case CDB2_DATETIME:
case CDB2_DATETIMEUS:
return SQL_TIMESTAMP;
case CDB2_INTERVALYM:
return SQL_INTERVAL_YEAR_TO_MONTH;
case CDB2_INTERVALDS:
case CDB2_INTERVALDSUS:
return SQL_INTERVAL_DAY_TO_SECOND;
default:
break;
}
return SQL_UNKNOWN_TYPE;
}
/* Returns column size of a cdb2api type. Regarding the definition of 'column size', see
http://msdn.microsoft.com/en-us/library/ms712499(v=vs.85).aspx */
static unsigned int column_size(cdb2_hndl_tp *sqlh, int col)
{
switch(cdb2_column_type(sqlh, col)) {
case CDB2_INTEGER:
/* Max string length for a 64bit number (sign skipped) */
return MAX_INT64_DIGITS;
case CDB2_REAL:
/* Max string length for a double-precision floating number (sign skipped) */
return MAX_DBL_DIGITS;
case CDB2_DATETIME:
/* yyyy-mm-dd hh:MM:ss.fff (TIMEZONE)
gives 26 + CDB2_MAX_TZNAME */
return MAX_DATETIME_DISPLAY_SIZE;
case CDB2_INTERVALYM:
/* +/-year(10 digits at most)-MM
gives 14. */
return MAX_YM_DISPLAY_SIZE;
case CDB2_INTERVALDS:
/* +/-day(10 digits at most) hh:MM:ss.fff
gives 24. */
return MAX_DS_DISPLAY_SIZE;
default:
/* XXX - ODBC requires us to return the length of the longest string
or blob here. Can't be done in comdb2 unless reading all rows. */
return 0;
}
}
static unsigned int display_size(cdb2_hndl_tp *sqlh, int col)
{
switch(cdb2_column_type(sqlh, col)) {
case CDB2_INTEGER:
/* Max string length for a 64bit number (sign skipped) */
return MAX_INT64_DISPLAY_SIZE;
case CDB2_REAL:
/* Max string length for a double-precision floating number (sign skipped) */
return MAX_DBL_DISPLAY_SIZE;
case CDB2_DATETIME:
/* yyyy-mm-dd hh:MM:ss.fff (TIMEZONE)
gives 26 + CDB2_MAX_TZNAME */
return MAX_DATETIME_DISPLAY_SIZE;
case CDB2_INTERVALYM:
/* +/-year(10 digits at most)-MM
gives 14. */
return MAX_YM_DISPLAY_SIZE;
case CDB2_INTERVALDS:
/* +/-day(10 digits at most) hh:MM:ss.fff
gives 24. */
return MAX_DS_DISPLAY_SIZE;
default:
/* XXX - ODBC requires us to return the length of the longest string
or blob here. Can't be done in comdb2 unless reading all rows. */
return 0;
}
}
/*
ODBC API.
SQLDescribeCol returns the result descriptor . column name,type, column size, decimal digits, and nullability . for one column in the result set.
FIXME At this moment, the information is unavailable in IRD.
*/
SQLRETURN __SQLDescribeCol(
SQLHSTMT hstmt,
SQLUSMALLINT col,
SQLCHAR *col_name,
SQLSMALLINT col_name_max,
SQLSMALLINT *col_name_len,
SQLSMALLINT *sql_data_type,
SQLULEN *col_size,
SQLSMALLINT *decimal_digits,
SQLSMALLINT *nullable)
{
stmt_t *phstmt = (stmt_t *)hstmt;
SQLRETURN ret;
cdb2_hndl_tp *sqlh;
const char * _column_name;
int cdb2_type;
__debug("enters method.");
if(!hstmt)
return SQL_INVALID_HANDLE;
/* Validate statement status. */
if(phstmt->status & (STMT_ALLOCATED | STMT_EXECUTING))
return STMT_ODBC_ERR(ERROR_FUNCTION_SEQ_ERR);
/* If the statement is ready, we pre-execute the bound SQL. */
if((phstmt->status & STMT_READY) && SQL_FAILED(ret = comdb2_SQLExecute(hstmt)))
return ret;
__debug("describing column %d.", col);
--col;
sqlh = phstmt->sqlh;
/* Column name */
_column_name = cdb2_column_name(sqlh, col);
if(col_name_len)
*col_name_len = (SQLSMALLINT)strlen(_column_name);
if(col_name)
my_strncpy_out_fn((char *)col_name, _column_name, col_name_max);
/* SQL data type */
cdb2_type = cdb2_column_type(sqlh, col);
if(sql_data_type)
*sql_data_type = (SQLSMALLINT)cdb2_to_sql(cdb2_type);
__debug("cdb2_type is %d. sql type is %d.", cdb2_type, *sql_data_type);
/* Column size - number of digits. So column size of 123.45 is 5 */
if(col_size)
*col_size = column_size(sqlh, col);
/* Decimal digits - scale */
if(decimal_digits) {
if(cdb2_type == CDB2_REAL)
/* Precision of double */
*decimal_digits = MAX_DBL_DIGITS;
else if(cdb2_type == CDB2_INTERVALDS || cdb2_type == CDB2_DATETIME)
*decimal_digits = 3;
else
*decimal_digits = 0;
}
/* Nullable FIXME */
if(nullable)
*nullable = SQL_NULLABLE;
__debug("leaves method.");
return SQL_SUCCESS;
}
SQLRETURN SQL_API SQLDescribeCol(SQLHSTMT hstmt,
SQLUSMALLINT col,
SQLCHAR *col_name,
SQLSMALLINT col_name_max,
SQLSMALLINT *col_name_len,
SQLSMALLINT *sql_data_type,
SQLULEN *col_size,
SQLSMALLINT *decimal_digits,
SQLSMALLINT *nullable)
{
return __SQLDescribeCol(hstmt, col, col_name, col_name_max, col_name_len, sql_data_type, col_size, decimal_digits, nullable);
}
/*
ODBC API.
SQLColAttribute returns descriptor information for a column in a result set.
Descriptor information is returned as a character string, a descriptor-dependent value, or an integer value.
FIXME Currently, only SQL_DESC_LABEL is supported (I implement this function for testing the driver using unixODBC shell).
Applications should use SQLDescribeCol instead.
*/
SQLRETURN __SQLColAttribute(
SQLHSTMT hstmt,
SQLUSMALLINT col,
SQLUSMALLINT field,
SQLPOINTER text_attr,
SQLSMALLINT attr_max,
SQLSMALLINT *attr_len,
SQLLEN *num_attr)
{
stmt_t *phstmt = (stmt_t *)hstmt;
SQLRETURN ret;
int minimum_length_required = -1;
__debug("enters method. field = %d", field);
if(SQL_NULL_HSTMT == hstmt)
return SQL_INVALID_HANDLE;
/* Validate statement status. */
if(phstmt->status & (STMT_ALLOCATED | STMT_EXECUTING))
return STMT_ODBC_ERR(ERROR_FUNCTION_SEQ_ERR);
/* If the statement is ready, we pre-execute the bound SQL. */
if((phstmt->status & STMT_READY) && SQL_FAILED(ret = comdb2_SQLExecute(hstmt)))
return ret;
if(col > phstmt->col_count)
return STMT_ODBC_ERR(ERROR_INVALID_DESC_IDX);
/* @col starts at 1. Zero is allowed only when SQL_ATTR_USE_BOOKMARKS is not SQL_UB_OFF.
Driver Manager will make sure @col != 0 when SQL_ATTR_USE_BOOKMARKS == SQL_UB_OFF (according to Microsoft, but who knows. LOL).
Since I don't have a plan to support bookmark (meaning SQL_ATTR_USE_BOOKMARKS will always set to OFF), so I can assume col will never be 0. */
--col; // use 0-based index
/* Maps ODBC 2.x reserved values to ODBC 3.x reserved values. */
switch(field) {
case SQL_COLUMN_SCALE:
field = SQL_DESC_SCALE;
break;
case SQL_COLUMN_PRECISION:
field = SQL_DESC_PRECISION;
break;
case SQL_COLUMN_NULLABLE:
field = SQL_DESC_NULLABLE;
break;
case SQL_COLUMN_LENGTH:
field = SQL_DESC_OCTET_LENGTH;
break;
case SQL_COLUMN_NAME:
field = SQL_DESC_NAME;
break;
}
/* http://msdn.microsoft.com/en-us/library/ms713558(v=vs.85).aspx */
switch(field) {
case SQL_DESC_AUTO_UNIQUE_VALUE:
break;
case SQL_DESC_BASE_COLUMN_NAME:
break;
case SQL_DESC_BASE_TABLE_NAME:
break;
case SQL_DESC_CASE_SENSITIVE:
break;
case SQL_DESC_CATALOG_NAME:
break;
case SQL_DESC_CONCISE_TYPE:
SET_SQLLEN(num_attr, cdb2_to_sql(cdb2_column_type(phstmt->sqlh, col)), minimum_length_required);
break;
case SQL_DESC_COUNT:
break;
case SQL_DESC_DISPLAY_SIZE:
SET_SQLLEN(num_attr, display_size(phstmt->sqlh, col), minimum_length_required);
break;
case SQL_DESC_FIXED_PREC_SCALE:
break;
case SQL_DESC_NAME:
case SQL_DESC_LABEL:
SET_CSTRING(text_attr, cdb2_column_name(phstmt->sqlh, col), attr_max, minimum_length_required);
break;
case SQL_DESC_LENGTH:
break;
case SQL_DESC_LITERAL_PREFIX:
break;
case SQL_DESC_LITERAL_SUFFIX:
break;
case SQL_DESC_LOCAL_TYPE_NAME:
break;
case SQL_DESC_NULLABLE:
break;
case SQL_DESC_NUM_PREC_RADIX:
break;
case SQL_DESC_OCTET_LENGTH:
break;
case SQL_DESC_PRECISION:
break;
case SQL_DESC_SCALE:
break;
case SQL_DESC_SCHEMA_NAME:
break;
case SQL_DESC_SEARCHABLE:
break;
case SQL_DESC_TABLE_NAME:
break;
case SQL_DESC_TYPE:
break;
case SQL_DESC_TYPE_NAME:
break;
case SQL_DESC_UNNAMED:
break;
case SQL_DESC_UNSIGNED:
break;
case SQL_DESC_UPDATABLE:
break;
default:
return STMT_ODBC_ERR(ERROR_INVALID_DESC_FIELD_ID);
}
if (attr_len != NULL)
*attr_len = (SQLSMALLINT)minimum_length_required;
__debug("enters method.");
return SQL_SUCCESS;
}
SQLRETURN SQL_API SQLColAttribute(SQLHSTMT hstmt,
SQLUSMALLINT col,
SQLUSMALLINT field,
SQLPOINTER text_attr,
SQLSMALLINT attr_max,
SQLSMALLINT *attr_len,
SQLLEN *num_attr)
{
return __SQLColAttribute(hstmt, col, field, text_attr, attr_max, attr_len, num_attr);
}
/*
ODBC API.
SQLNumResultCols returns the number of columns in a result set.
*/
SQLRETURN SQL_API SQLNumResultCols(SQLHSTMT hstmt, SQLSMALLINT *count)
{
stmt_t *phstmt = (stmt_t *) hstmt;
SQLRETURN ret = SQL_SUCCESS;
__debug("enters method.");
if(!hstmt)
ret = SQL_INVALID_HANDLE;
else if (phstmt->status & (STMT_ALLOCATED | STMT_EXECUTING))
ret = STMT_ODBC_ERR_MSG(ERROR_FUNCTION_SEQ_ERR,
"No query is attached or the statement is still executing.");
else if(!(phstmt->status & STMT_READY) || SQL_SUCCEEDED((ret = comdb2_SQLExecute(hstmt))))
*count = (SQLSMALLINT)((phstmt->status & STMT_SQLCOLUMNS) ?
phstmt->col_count - 1 : phstmt->col_count);
__debug("result columns %d.", *count);
__debug("leaves method.");
return ret;
}
/**
* SQLRowCount
* If it's a SELECT (UPDATE) statement, the number of selected (affected) rows is returned.
* The behavior for a select statement is driver-specific.
*
* TODO Add SQLBulkOperations & SQLSetPos supports.
*/
SQLRETURN SQL_API SQLRowCount(SQLHSTMT hstmt, SQLLEN *count)
{
stmt_t *phstmt = (stmt_t *)hstmt;
int rc;
SQLRETURN ret;
__debug("enters method.");
if(!hstmt)
return SQL_INVALID_HANDLE;
/* Validate statement status. */
if(phstmt->status & (STMT_ALLOCATED | STMT_EXECUTING))
return STMT_ODBC_ERR(ERROR_FUNCTION_SEQ_ERR);
/* If the statement is ready, we pre-execute the bound SQL. */
if((phstmt->status & STMT_READY) && SQL_FAILED(ret = comdb2_SQLExecute(hstmt)))
return ret;
if( !phstmt->effects && (phstmt->effects = my_calloc(effects_tp, 1)) == NULL)
return STMT_ODBC_ERR(ERROR_MEM_ALLOC_FAIL);
if(phstmt->sql_type >= STMT_HAS_NO_EFFECT) {
__warn("SQLRowCount is not available, return 0");
*count = 0;
} else {
if((rc = cdb2_get_effects(phstmt->sqlh, phstmt->effects)) != 0) {
__debug("No effects received.");
*count = 0;
return set_stmt_error(phstmt, ERROR_WTH, "Effects were not sent by comdb2 server.", rc);
}
if(phstmt->sql_type != STMT_SELECT) {
*count = phstmt->effects->num_affected;
} else {
/* SQLRowCount returns the count of AFFECTED rows. For a select statement, the behavior is driver-defined.
Most of drivers return the number of tuples for a SELECT statement. So we follow the convention.
For more details, see http://msdn.microsoft.com/en-us/library/ms711835(v=vs.85).aspx */
*count = -1;
}
}
__debug("leaves method.");
return SQL_SUCCESS;
}
SQLRETURN SQL_API SQLMoreResults(SQLHSTMT hstmt)
{
return hstmt ? SQL_NO_DATA : SQL_INVALID_HANDLE;
}
#ifdef __UNICODE__
#include "resultw.c"
#endif