aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/odbc/results.c
blob: 13960830464cfd4032f06038f13d33bf571528d5 (plain)
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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
/* Module:          results.c
 *
 * Description:     This module contains functions related to 
 *                  retrieving result information through the ODBC API.
 *
 * Classes:         n/a
 *
 * API functions:   SQLRowCount, SQLNumResultCols, SQLDescribeCol, SQLColAttributes,
 *                  SQLGetData, SQLFetch, SQLExtendedFetch, 
 *                  SQLMoreResults(NI), SQLSetPos(NI), SQLSetScrollOptions(NI),
 *                  SQLSetCursorName(NI), SQLGetCursorName(NI)
 *
 * Comments:        See "notice.txt" for copyright and license information.
 *
 */

#include <string.h>
#include "psqlodbc.h"
#include "environ.h"
#include "connection.h"
#include "statement.h"
#include "bind.h"
#include "qresult.h"
#include "convert.h"
#include "pgtypes.h" 

#include <stdio.h>
#include <windows.h>
#include <sqlext.h>


RETCODE SQL_API SQLRowCount(
        HSTMT      hstmt,
        SDWORD FAR *pcrow)
{
StatementClass *stmt = (StatementClass *) hstmt;
QResultClass *res;
char *msg, *ptr;

	if ( ! stmt)
		return SQL_ERROR;

	if(stmt->statement_type == STMT_TYPE_SELECT) {
		if (stmt->status == STMT_FINISHED) {
			res = SC_get_Result(stmt);

			if(res && pcrow) {
				*pcrow = QR_get_num_tuples(res);
				return SQL_SUCCESS;
			}
		}
	} else {

		res = SC_get_Result(stmt);
		if (res && pcrow) {
			msg = QR_get_command(res);
			mylog("*** msg = '%s'\n", msg);
			trim(msg);	//	get rid of trailing spaces
			ptr = strrchr(msg, ' ');
			if (ptr) {
				*pcrow = atoi(ptr+1);
				mylog("**** SQLRowCount(): THE ROWS: *pcrow = %d\n", *pcrow);
			}
			else {
				*pcrow = -1;

				mylog("**** SQLRowCount(): NO ROWS: *pcrow = %d\n", *pcrow);
			}

		return SQL_SUCCESS;
		}
	}

	return SQL_ERROR;     
}


//      This returns the number of columns associated with the database
//      attached to "hstmt".


RETCODE SQL_API SQLNumResultCols(
        HSTMT     hstmt,
        SWORD FAR *pccol)
{       
StatementClass *stmt = (StatementClass *) hstmt;
QResultClass *result;

	if ( ! stmt)
		return SQL_INVALID_HANDLE;

	SC_clear_error(stmt);    

	/* CC: Now check for the "prepared, but not executed" situation, that enables us to
	deal with "SQLPrepare -- SQLDescribeCol -- ... -- SQLExecute" situations.
	(AutoCAD 13 ASE/ASI just _loves_ that ;-) )
	*/
	mylog("**** SQLNumResultCols: calling SC_pre_execute\n");

	SC_pre_execute(stmt);       

	result = SC_get_Result(stmt);

	mylog("SQLNumResultCols: result = %u, status = %d, numcols = %d\n", result, stmt->status, result != NULL ? QR_NumResultCols(result) : -1);
	if (( ! result) || ((stmt->status != STMT_FINISHED) && (stmt->status != STMT_PREMATURE)) ) {
		/* no query has been executed on this statement */
		stmt->errornumber = STMT_SEQUENCE_ERROR;
		stmt->errormsg = "No query has been executed with that handle";
		return SQL_ERROR;
	}

	*pccol = QR_NumResultCols(result);

	return SQL_SUCCESS;
}

//      -       -       -       -       -       -       -       -       -

//      Return information about the database column the user wants
//      information about.
/* CC: preliminary implementation */
RETCODE SQL_API SQLDescribeCol(
        HSTMT      hstmt,
        UWORD      icol,
        UCHAR  FAR *szColName,
        SWORD      cbColNameMax,
        SWORD  FAR *pcbColName,
        SWORD  FAR *pfSqlType,
        UDWORD FAR *pcbColDef,
        SWORD  FAR *pibScale,
        SWORD  FAR *pfNullable)
{
    /* gets all the information about a specific column */
StatementClass *stmt = (StatementClass *) hstmt;
QResultClass *result;
char *name;
Int4 fieldtype;

    if ( ! stmt)
        return SQL_INVALID_HANDLE;

    SC_clear_error(stmt);

    /* CC: Now check for the "prepared, but not executed" situation, that enables us to
           deal with "SQLPrepare -- SQLDescribeCol -- ... -- SQLExecute" situations.
           (AutoCAD 13 ASE/ASI just _loves_ that ;-) )
    */

	SC_pre_execute(stmt);       

        
    result = SC_get_Result(stmt);
	mylog("**** SQLDescribeCol: result = %u, stmt->status = %d, !finished=%d, !premature=%d\n", result, stmt->status, stmt->status != STMT_FINISHED, stmt->status != STMT_PREMATURE);
    if ( (NULL == result) || ((stmt->status != STMT_FINISHED) && (stmt->status != STMT_PREMATURE))) {
        /* no query has been executed on this statement */
        stmt->errornumber = STMT_SEQUENCE_ERROR;
        stmt->errormsg = "No query has been assigned to this statement.";
        return SQL_ERROR;
    }

    if (cbColNameMax >= 1) {
        name = QR_get_fieldname(result, (Int2) (icol-1));
		mylog("describeCol: col %d fieldname = '%s'\n", icol - 1, name);
        /* our indices start from 0 whereas ODBC defines indices starting from 1 */
        if (NULL != pcbColName)  {
            // we want to get the total number of bytes in the column name
            if (NULL == name) 
                *pcbColName = 0;
            else
                *pcbColName = strlen(name);
        }
        if (NULL != szColName) {
            // get the column name into the buffer if there is one
            if (NULL == name) 
                szColName[0] = '\0';
            else
                strncpy_null(szColName, name, cbColNameMax);
        }
    }

    fieldtype = QR_get_field_type(result, (Int2) (icol-1));
	mylog("describeCol: col %d fieldtype = %d\n", icol - 1, fieldtype);

    if (NULL != pfSqlType) {
        *pfSqlType = pgtype_to_sqltype(fieldtype);
		if (*pfSqlType == PG_UNKNOWN)
			*pfSqlType = SQL_CHAR;
	}

    if (NULL != pcbColDef)
		*pcbColDef = pgtype_precision(fieldtype);

    if (NULL != pibScale) {
        Int2 scale;
        scale = pgtype_scale(fieldtype);
        if(scale == -1) { scale = 0; }
        
        *pibScale = scale;
    }
    if (NULL != pfNullable) {
        *pfNullable = pgtype_nullable(fieldtype);
    }

    return SQL_SUCCESS;
}

//      Returns result column descriptor information for a result set.

RETCODE SQL_API SQLColAttributes(
        HSTMT      hstmt,
        UWORD      icol,
        UWORD      fDescType,
        PTR        rgbDesc,
        SWORD      cbDescMax,
        SWORD  FAR *pcbDesc,
        SDWORD FAR *pfDesc)
{
StatementClass *stmt = (StatementClass *) hstmt;
char *value;
Int4 field_type;

    if( ! stmt) {
        return SQL_INVALID_HANDLE;
    }

    /* CC: Now check for the "prepared, but not executed" situation, that enables us to
           deal with "SQLPrepare -- SQLDescribeCol -- ... -- SQLExecute" situations.
           (AutoCAD 13 ASE/ASI just _loves_ that ;-) )
    */
    SC_pre_execute(stmt);       

	mylog("**** SQLColAtt: result = %u, status = %d, numcols = %d\n", stmt->result, stmt->status, stmt->result != NULL ? QR_NumResultCols(stmt->result) : -1);

    if ( (NULL == stmt->result) || ((stmt->status != STMT_FINISHED) && (stmt->status != STMT_PREMATURE)) ) {
        stmt->errormsg = "Can't get column attributes: no result found.";
        stmt->errornumber = STMT_SEQUENCE_ERROR;
        return SQL_ERROR;
    }

    if(icol < 1) {
        // we do not support bookmarks
        stmt->errormsg = "Bookmarks are not currently supported.";
        stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
        return SQL_ERROR;
    }

    icol -= 1;
    field_type = QR_get_field_type(stmt->result, icol);
	mylog("colAttr: col %d field_type = %d\n", icol, field_type);
    switch(fDescType) {
    case SQL_COLUMN_AUTO_INCREMENT:
        if (NULL != pfDesc) {
	    *pfDesc = pgtype_auto_increment(field_type);

	    if(*pfDesc == -1) { /* "not applicable" becomes false */
		*pfDesc = FALSE;
	    }
	}
        break;
    case SQL_COLUMN_CASE_SENSITIVE:
        if (NULL != pfDesc)    
          *pfDesc = pgtype_case_sensitive(field_type);
        break;
    case SQL_COLUMN_COUNT:
        if (NULL != pfDesc)    
          *pfDesc = QR_NumResultCols(stmt->result);
        break;
    case SQL_COLUMN_DISPLAY_SIZE:
		if (NULL != pfDesc)
			*pfDesc = pgtype_precision(field_type);

		mylog("colAttr: col %d fieldsize = %d\n", icol, *pfDesc);

        break;
    case SQL_COLUMN_LABEL:
    case SQL_COLUMN_NAME:
        value = QR_get_fieldname(stmt->result, icol);
        strncpy_null((char *)rgbDesc, value, cbDescMax);
        /* CC: Check for Nullpointesr */
        if (NULL != pcbDesc)
          *pcbDesc = strlen(value);
        break;
    case SQL_COLUMN_LENGTH:
        if (NULL != pfDesc)
          *pfDesc = pgtype_precision(field_type);
        return SQL_SUCCESS;
        break;
    case SQL_COLUMN_MONEY:
        if (NULL != pfDesc)    
          *pfDesc = pgtype_money(field_type);
        break;
    case SQL_COLUMN_NULLABLE:
        if (NULL != pfDesc)    
          *pfDesc = pgtype_nullable(field_type);
        break;
    case SQL_COLUMN_OWNER_NAME:
        return SQL_ERROR;
        break;
    case SQL_COLUMN_PRECISION:
        if (NULL != pfDesc)    
          *pfDesc = pgtype_precision(field_type);
        break;
    case SQL_COLUMN_QUALIFIER_NAME:
        strncpy_null((char *)rgbDesc, "", cbDescMax);
        if (NULL != pfDesc)        
          *pcbDesc = 1;
        break;
    case SQL_COLUMN_SCALE:
        if (NULL != pfDesc)    
          *pfDesc = pgtype_scale(field_type);
        break;
    case SQL_COLUMN_SEARCHABLE:
        if (NULL != pfDesc)    
          *pfDesc = pgtype_searchable(field_type);
        break;
    case SQL_COLUMN_TABLE_NAME:
        return SQL_ERROR;
        break;
    case SQL_COLUMN_TYPE:
        if (NULL != pfDesc) {
          *pfDesc = pgtype_to_sqltype(field_type);
		  if (*pfDesc == PG_UNKNOWN)
			  *pfDesc = SQL_CHAR;
		}
        break;
    case SQL_COLUMN_TYPE_NAME:
        value = pgtype_to_name(field_type);
        strncpy_null((char *)rgbDesc, value, cbDescMax);
        if (NULL != pcbDesc)        
          *pcbDesc = strlen(value);
        break;
    case SQL_COLUMN_UNSIGNED:
        if (NULL != pfDesc) {
	    *pfDesc = pgtype_unsigned(field_type);
	    if(*pfDesc == -1) {
		*pfDesc = FALSE;
	    }
	}
        break;
    case SQL_COLUMN_UPDATABLE:
        // everything should be updatable, I guess, unless access permissions
        // prevent it--are we supposed to check for that here?  seems kind
        // of complicated.  hmm...
        if (NULL != pfDesc)        
          *pfDesc = SQL_ATTR_WRITE;
        break;
    }

    return SQL_SUCCESS;
}

//      Returns result data for a single column in the current row.

RETCODE SQL_API SQLGetData(
        HSTMT      hstmt,
        UWORD      icol,
        SWORD      fCType,
        PTR        rgbValue,
        SDWORD     cbValueMax,
        SDWORD FAR *pcbValue)
{
QResultClass *res;
StatementClass *stmt = (StatementClass *) hstmt;
int num_cols, num_rows;
Int4 field_type;
void *value;
int result;

    if( ! stmt) {
        return SQL_INVALID_HANDLE;
    }
	res = stmt->result;

    if (STMT_EXECUTING == stmt->status) {
        stmt->errormsg = "Can't get data while statement is still executing.";
        stmt->errornumber = STMT_SEQUENCE_ERROR;
        return 0;
    }

    if (stmt->status != STMT_FINISHED) {
        stmt->errornumber = STMT_STATUS_ERROR;
        stmt->errormsg = "GetData can only be called after the successful execution on a SQL statement";
        return 0;
    }

    if (icol == 0) {
        stmt->errormsg = "Bookmarks are not currently supported.";
        stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
        return SQL_ERROR;
    }

    // use zero-based column numbers
    icol--;

    // make sure the column number is valid
    num_cols = QR_NumResultCols(res);
    if (icol >= num_cols) {
        stmt->errormsg = "Invalid column number.";
        stmt->errornumber = STMT_INVALID_COLUMN_NUMBER_ERROR;
        return SQL_ERROR;
    }

	if ( stmt->manual_result) {
		// make sure we're positioned on a valid row
		num_rows = QR_get_num_tuples(res);
		if((stmt->currTuple < 0) ||
		   (stmt->currTuple >= num_rows)) {
			stmt->errormsg = "Not positioned on a valid row for GetData.";
			stmt->errornumber = STMT_INVALID_CURSOR_STATE_ERROR;
			return SQL_ERROR;
		}
		value = QR_get_value_manual(res, stmt->currTuple, icol);
	}
	else { /* its a SOCKET result (backend data) */
		if (stmt->currTuple == -1 || ! res || QR_end_tuples(res)) {
			stmt->errormsg = "Not positioned on a valid row for GetData.";
			stmt->errornumber = STMT_INVALID_CURSOR_STATE_ERROR;
			return SQL_ERROR;
		}

		value = QR_get_value_backend(res, icol);

	}

	field_type = QR_get_field_type(res, icol);

	mylog("**** SQLGetData: icol = %d, fCType = %d, field_type = %d, value = '%s'\n", icol, fCType, field_type, value);

    result = copy_and_convert_field(field_type, value, 
                                    fCType, rgbValue, cbValueMax, pcbValue);


    if(result == COPY_UNSUPPORTED_TYPE) {
        stmt->errormsg = "Received an unsupported type from Postgres.";
        stmt->errornumber = STMT_RESTRICTED_DATA_TYPE_ERROR;
        return SQL_ERROR;
    } else if(result == COPY_UNSUPPORTED_CONVERSION) {
        stmt->errormsg = "Couldn't handle the necessary data type conversion.";
        stmt->errornumber = STMT_RESTRICTED_DATA_TYPE_ERROR;
        return SQL_ERROR;
    } else if(result == COPY_RESULT_TRUNCATED) {
        stmt->errornumber = STMT_TRUNCATED;
        stmt->errormsg = "The buffer was too small for the result.";
        return SQL_SUCCESS_WITH_INFO;
    } else if(result != COPY_OK) {
        stmt->errormsg = "Unrecognized return value from copy_and_convert_field.";
        stmt->errornumber = STMT_INTERNAL_ERROR;
        return SQL_ERROR;
    }

    return SQL_SUCCESS;
}

//      Returns data for bound columns in the current row ("hstmt->iCursor"),
//      advances the cursor.

RETCODE SQL_API SQLFetch(
        HSTMT   hstmt)
{
StatementClass *stmt = (StatementClass *) hstmt;   
QResultClass *res;
int retval;
Int2 num_cols, lf;
Oid type;
char *value;
ColumnInfoClass *ci;


 if ( ! stmt)
     return SQL_INVALID_HANDLE;

 SC_clear_error(stmt);

 if ( ! (res = stmt->result)) {
     stmt->errormsg = "Null statement result in SQLFetch.";
     stmt->errornumber = STMT_SEQUENCE_ERROR;
     return SQL_ERROR;
 }

 ci = QR_get_fields(res);		/* the column info */

 if (stmt->status == STMT_EXECUTING) {
     stmt->errormsg = "Can't fetch while statement is still executing.";
     stmt->errornumber = STMT_SEQUENCE_ERROR;
     return SQL_ERROR;
 }


 if (stmt->status != STMT_FINISHED) {
     stmt->errornumber = STMT_STATUS_ERROR;
     stmt->errormsg = "Fetch can only be called after the successful execution on a SQL statement";
     return SQL_ERROR;
 }

 if (stmt->bindings == NULL) {
     // just to avoid a crash if the user insists on calling this
     // function even if SQL_ExecDirect has reported an Error
     stmt->errormsg = "Bindings were not allocated properly.";
     stmt->errornumber = STMT_SEQUENCE_ERROR;
     return SQL_ERROR;
 }

 
 if ( stmt->manual_result) {
	 if (QR_get_num_tuples(res) -1 == stmt->currTuple ||
		 (stmt->maxRows > 0 && stmt->currTuple == stmt->maxRows - 1))
		 /* if we are at the end of a tuple list, we return a "no data found" */
		 return SQL_NO_DATA_FOUND;
 
	 mylog("**** SQLFetch: manual_result\n");
	 (stmt->currTuple)++;
 }
 else {

	 // read from the cache or the physical next tuple
	 retval = QR_next_tuple(res);
	 if (retval < 0) {
		mylog("**** SQLFetch: end_tuples\n");
		return SQL_NO_DATA_FOUND;
	 }
	 else if (retval > 0)
		 (stmt->currTuple)++;		// all is well

	 else {
		mylog("SQLFetch: error\n");
		stmt->errornumber = STMT_EXEC_ERROR;
		stmt->errormsg = "Error fetching next row";
		 return SQL_ERROR;
	 }

 }

 num_cols = QR_NumResultCols(res);

 for (lf=0; lf < num_cols; lf++) {

	 mylog("fetch: cols=%d, lf=%d, buffer[] = %u\n", 
			 num_cols, lf, stmt->bindings[lf].buffer);

     if (stmt->bindings[lf].buffer != NULL) {
            // this column has a binding

            // type = QR_get_field_type(res, lf);
			type = CI_get_oid(ci, lf);		/* speed things up */

			if (stmt->manual_result)
				value = QR_get_value_manual(res, stmt->currTuple, lf);
			else
				value = QR_get_value_backend(res, lf);

            retval = copy_and_convert_field_bindinfo(type, value, &(stmt->bindings[lf]));

            // check whether the complete result was copied
            if(retval == COPY_UNSUPPORTED_TYPE) {
                stmt->errormsg = "Received an unsupported type from Postgres.";
                stmt->errornumber = STMT_RESTRICTED_DATA_TYPE_ERROR;
                return SQL_ERROR;

            } else if(retval == COPY_UNSUPPORTED_CONVERSION) {
                stmt->errormsg = "Couldn't handle the necessary data type conversion.";
                stmt->errornumber = STMT_RESTRICTED_DATA_TYPE_ERROR;
                return SQL_ERROR;

            } else if(retval == COPY_RESULT_TRUNCATED) {
                /* The result has been truncated during the copy */
                /* this will generate a SQL_SUCCESS_WITH_INFO result */
                stmt->errornumber = STMT_TRUNCATED;
                stmt->errormsg = "A buffer was too small for the return value to fit in";
				return SQL_SUCCESS_WITH_INFO;

            } else if(retval != COPY_OK) {
                stmt->errormsg = "Unrecognized return value from copy_and_convert_field.";
                stmt->errornumber = STMT_INTERNAL_ERROR;
                return SQL_ERROR;

            }
     }
 }

 return SQL_SUCCESS;
}

//      This fetchs a block of data (rowset).

RETCODE SQL_API SQLExtendedFetch(
        HSTMT      hstmt,
        UWORD      fFetchType,
        SDWORD     irow,
        UDWORD FAR *pcrow,
        UWORD  FAR *rgfRowStatus)
{
StatementClass *stmt = (StatementClass *) hstmt;

       if ( ! stmt)
          return SQL_INVALID_HANDLE;

	   /*	Currently, only for manual results can this be done 
			because not all the tuples are read in ahead of time.
	   */
	   if ( ! stmt->manual_result)
		   return SQL_ERROR;

       // CC: we currently only support fetches in one row bits
       if (NULL != pcrow)
         *pcrow = 1;
       if (NULL != rgfRowStatus)  
         *rgfRowStatus = SQL_ROW_SUCCESS;

       switch (fFetchType)  {
       case SQL_FETCH_NEXT:
          return SQLFetch(hstmt);
       case SQL_FETCH_PRIOR:
          if (stmt->currTuple <= 0)
              return SQL_ERROR;
          stmt->currTuple--;
          return SQLFetch(hstmt);
       case SQL_FETCH_FIRST:
          stmt->currTuple = -1;
          return SQLFetch(hstmt);
       case SQL_FETCH_LAST:
          stmt->currTuple = QR_get_num_tuples(stmt->result)-1;
          return SQLFetch(hstmt);
       case SQL_FETCH_ABSOLUTE:
          if (irow == 0) {
              stmt->currTuple = stmt->currTuple > 0 ? stmt->currTuple-2 : -1;
          } else if (irow > 0) {
              stmt->currTuple = irow-2;
              return SQLFetch(hstmt);
          } else {
              // CC: ??? not sure about the specification in that case
              return SQL_ERROR;
          }    
        default:
          return SQL_ERROR;   
        }           
        return SQL_SUCCESS;
}

//      This determines whether there are more results sets available for
//      the "hstmt".

/* CC: return SQL_NO_DATA_FOUND since we do not support multiple result sets */
RETCODE SQL_API SQLMoreResults(
        HSTMT   hstmt)
{
          return SQL_NO_DATA_FOUND;
}

//      This positions the cursor within a block of data.

RETCODE SQL_API SQLSetPos(
        HSTMT   hstmt,
        UWORD   irow,
        UWORD   fOption,
        UWORD   fLock)
{
        return SQL_ERROR;
}

//      Sets options that control the behavior of cursors.

RETCODE SQL_API SQLSetScrollOptions(
        HSTMT      hstmt,
        UWORD      fConcurrency,
        SDWORD  crowKeyset,
        UWORD      crowRowset)
{
        return SQL_ERROR;
}


//      Set the cursor name on a statement handle

RETCODE SQL_API SQLSetCursorName(
        HSTMT     hstmt,
        UCHAR FAR *szCursor,
        SWORD     cbCursor)
{
        return SQL_SUCCESS;
}

//      Return the cursor name for a statement handle

RETCODE SQL_API SQLGetCursorName(
        HSTMT     hstmt,
        UCHAR FAR *szCursor,
        SWORD     cbCursorMax,
        SWORD FAR *pcbCursor)
{
        return SQL_ERROR;
}