sqllogictest

Check-in [b5897694e8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Made the xQuery method of the odbc interface match the SQLite version more closely, honoring type information and formatting in the same manor.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b5897694e8e9c106a36226c688ccdbc377928495
User & Date: shaneh 2008-12-02 04:57:32.000
Context
2008-12-02
05:32
MSSQL doesn't like calling SQLGetData() twice on the same column for the same row. check-in: 4140649727 user: shaneh tags: trunk
04:57
Made the xQuery method of the odbc interface match the SQLite version more closely, honoring type information and formatting in the same manor. check-in: b5897694e8 user: shaneh tags: trunk
02:28
Added more error checking. Updated to allow specifing DSN and DATABASE name in -odbc option. check-in: 2014c5b9c3 user: shaneh tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/slt_odbc3.c.
234
235
236
237
238
239
240
241

242
243
244

245
246
247
248
249
250
251
      while( *pc2 && (*pc2!=';') ) *pc1++ = *pc2++;
      *pc1 = '\0';
    }
  
    /* for each valid table found, drop it */
    for( i=0; !rc && (i+4<res.nUsed); i+=5 ){
      if(    (0 == strcmp(res.azValue[i], zDbName))
          && (0 == strcmp(res.azValue[i+1], "dbo"))

          && (strlen(res.azValue[i+2])>0)
          && (0 == strcmp(res.azValue[i+3], "TABLE"))
          && (0 == strcmp(res.azValue[i+4], "NULL")) ){

        sprintf(zSql, "DROP TABLE %s", res.azValue[i+2]);
        rc = ODBC3Statement(pODBC3conn, zSql);
      }
    }
  }
  
  return rc;







|
>


|
>







234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
      while( *pc2 && (*pc2!=';') ) *pc1++ = *pc2++;
      *pc1 = '\0';
    }
  
    /* for each valid table found, drop it */
    for( i=0; !rc && (i+4<res.nUsed); i+=5 ){
      if(    (0 == strcmp(res.azValue[i], zDbName))
          && (   (0 == strcmp(res.azValue[i+1], "dbo"))
              || (0 == strcmp(res.azValue[i+1], "(empty)")) ) /* MySQL */
          && (strlen(res.azValue[i+2])>0)
          && (0 == strcmp(res.azValue[i+3], "TABLE"))
          && (   (0 == strcmp(res.azValue[i+4], "NULL")) 
              || (0 == strcmp(res.azValue[i+1], "(empty)")) ) ){ /* MySQL */
        sprintf(zSql, "DROP TABLE %s", res.azValue[i+2]);
        rc = ODBC3Statement(pODBC3conn, zSql);
      }
    }
  }
  
  return rc;
427
428
429
430
431
432
433

434
435
436
437
438
439
440
  int rc = 0;
  SQLRETURN ret;              /* ODBC API return status */
  ODBC3_Handles *pODBC3conn = pConn;
  ODBC3_resAccum res;         /* query result accumulator */
  char zBuffer[512];          /* Buffer to render numbers */
  SQLSMALLINT columns;        /* number of columns in result-set */
  SQLHSTMT stmt = SQL_NULL_HSTMT;


  /* zero out accumulator structure */
  memset(&res, 0, sizeof(res));

  /* Allocate a statement handle */
  ret = SQLAllocHandle(SQL_HANDLE_STMT, pODBC3conn->dbc, &stmt);
  if( !SQL_SUCCEEDED(ret) && (ret != SQL_SUCCESS_WITH_INFO) ){







>







429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
  int rc = 0;
  SQLRETURN ret;              /* ODBC API return status */
  ODBC3_Handles *pODBC3conn = pConn;
  ODBC3_resAccum res;         /* query result accumulator */
  char zBuffer[512];          /* Buffer to render numbers */
  SQLSMALLINT columns;        /* number of columns in result-set */
  SQLHSTMT stmt = SQL_NULL_HSTMT;
  SQLUSMALLINT i;

  /* zero out accumulator structure */
  memset(&res, 0, sizeof(res));

  /* Allocate a statement handle */
  ret = SQLAllocHandle(SQL_HANDLE_STMT, pODBC3conn->dbc, &stmt);
  if( !SQL_SUCCEEDED(ret) && (ret != SQL_SUCCESS_WITH_INFO) ){
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
  }
  
  if( !rc ){
    /* Loop through the rows in the result-set */
    do {
      ret = SQLFetch(stmt);
      if( SQL_SUCCEEDED(ret) ){
        SQLUSMALLINT i;
        /* Loop through the columns */
        for(i = 1; i <= columns; i++){
          SQLINTEGER indicator;
          /* retrieve column data as a string */
          ret = SQLGetData(stmt, 
                           i, 
                           SQL_C_CHAR,












                           zBuffer, 
                           sizeof(zBuffer), 
                           &indicator);
          if( SQL_SUCCEEDED(ret) ){
            char *z;
            /* Handle null columns */
            if( indicator == SQL_NULL_DATA ){ 
              strcpy(zBuffer, "NULL");
            /* Handle empty columns */
            } else if( *zBuffer == '\0' ) {
              strcpy(zBuffer, "(empty)");
            }
            ODBC3_appendValue(&res, zBuffer);
            /* Convert non-printing and control characters to '@' */
            z = res.azValue[res.nUsed-1];
            while( *z ){
              if( *z<' ' || *z>'~' ){ *z = '@'; }
              z++;
            }
































          }
        } /* end for i */
      }
    } while( SQL_SUCCEEDED(ret) );
  }
  
  if( stmt != SQL_NULL_HSTMT ){
    SQLFreeHandle(SQL_HANDLE_STMT, stmt);
  }

  *pazResult = res.azValue;







<

|

<



>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
<
<
<
<
<
|
<
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



|







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
  }
  
  if( !rc ){
    /* Loop through the rows in the result-set */
    do {
      ret = SQLFetch(stmt);
      if( SQL_SUCCEEDED(ret) ){

        /* Loop through the columns */
        for(i = 1; !rc && (i <= columns); i++){
          SQLINTEGER indicator;

          ret = SQLGetData(stmt, 
                           i, 
                           SQL_C_CHAR,
                           NULL, 
                           0, 
                           &indicator);
          if( SQL_SUCCEEDED(ret) && (indicator == SQL_NULL_DATA) ){
            ODBC3_appendValue(&res, "NULL");
          } else {
            switch( zType[i-1] ){
              case 'T': {
                /* retrieve column data as a string */
                ret = SQLGetData(stmt, 
                                 i, 
                                 SQL_C_CHAR,
                                 zBuffer, 
                                 sizeof(zBuffer), 
                                 NULL);
                if( SQL_SUCCEEDED(ret) ){
                  char *z;





                  if( zBuffer[0]==0 ) strcpy(zBuffer, "(empty)");

                  ODBC3_appendValue(&res, zBuffer);
                  /* Convert non-printing and control characters to '@' */
                  z = res.azValue[res.nUsed-1];
                  while( *z ){
                    if( *z<' ' || *z>'~' ){ *z = '@'; }
                    z++;
                  }
                }
                break;
              }
              case 'I': {
                long int li = 0L;
                SQLGetData(stmt, 
                           i, 
                           SQL_C_SLONG,
                           &li, 
                           sizeof(li), 
                           NULL);
                sprintf(zBuffer, "%ld", li);
                ODBC3_appendValue(&res, zBuffer);
                break;
              }
              case 'R': {
                double r = 0.0f;
                SQLGetData(stmt, 
                           i, 
                           SQL_C_DOUBLE,
                           &r, 
                           sizeof(r), 
                           NULL);
                sprintf(zBuffer, "%.3f", r);
                ODBC3_appendValue(&res, zBuffer);
                break;
              }
              default: {
                fprintf(stderr, "Unknown character in type-string: %c\n", zType[i-1]);
                rc = 1;
              }
            } /* end switch */
          }
        } /* end for i */
      }
    } while( !rc && SQL_SUCCEEDED(ret) );
  }
  
  if( stmt != SQL_NULL_HSTMT ){
    SQLFreeHandle(SQL_HANDLE_STMT, stmt);
  }

  *pazResult = res.azValue;