/ Check-in [c8a40218]
Login

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

Overview
Comment:Fix a bug in the sqlite3_column_decltype() API. (CVS 1486)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c8a40218c20cf5d0abad330e8fa59ca4c36e7608
User & Date: danielk1977 2004-05-28 13:13:02
Context
2004-05-28
16:00
Factor common code for generating index keys into a procedure. Other speed improvements and bug fixes. (CVS 1487) check-in: 6661bb5f user: drh tags: trunk
13:13
Fix a bug in the sqlite3_column_decltype() API. (CVS 1486) check-in: c8a40218 user: danielk1977 tags: trunk
12:33
Allow CREATE and DROP VIEW on attached databases. (CVS 1485) check-in: ad879a95 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/select.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle SELECT statements in SQLite.
    14     14   **
    15         -** $Id: select.c,v 1.180 2004/05/27 23:56:16 danielk1977 Exp $
           15  +** $Id: select.c,v 1.181 2004/05/28 13:13:02 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Allocate a new Select structure and return a pointer to that
    22     22   ** structure.
................................................................................
   659    659       }else{
   660    660         switch( sqlite3ExprType(p) ){
   661    661           case SQLITE_AFF_TEXT:     zType = "TEXT";    break;
   662    662           case SQLITE_AFF_NUMERIC:  zType = "NUMERIC"; break;
   663    663           default:                  zType = "ANY";     break;
   664    664         }
   665    665       }
   666         -    sqlite3VdbeOp3(v, OP_ColumnName, i + pEList->nExpr, 0, zType, 0);
          666  +    sqlite3VdbeSetColName(v, i+pEList->nExpr, zType, P3_STATIC);
   667    667     }
   668    668   }
   669    669   
   670    670   /*
   671    671   ** Generate code that will tell the VDBE the names of columns
   672    672   ** in the result set.  This information is used to provide the
   673    673   ** azCol[] values in the callback.
................................................................................
   736    736       }else{
   737    737         char zName[30];
   738    738         assert( p->op!=TK_COLUMN || pTabList==0 );
   739    739         sprintf(zName, "column%d", i+1);
   740    740         sqlite3VdbeSetColName(v, i, zName, 0);
   741    741       }
   742    742     }
          743  +  generateColumnTypes(pParse, pTabList, pEList);
   743    744   }
   744    745   
   745    746   /*
   746    747   ** Name of the connection operator, used for error messages.
   747    748   */
   748    749   static const char *selectOpName(int id){
   749    750     char *z;

Changes to src/vdbeapi.c.

   326    326       return 0;
   327    327     }
   328    328   
   329    329     pColName = &(p->aColName[N]);
   330    330     return sqlite3_value_text16(pColName);
   331    331   }
   332    332   
   333         -
   334    333   /*
   335         -** This routine returns either the column name, or declaration type (see
   336         -** sqlite3_column_decltype16() ) of the 'i'th column of the result set of
   337         -** SQL statement pStmt. The returned string is UTF-16 encoded.
   338         -**
   339         -** The declaration type is returned if 'decltype' is true, otherwise
   340         -** the column name.
          334  +** Return the column declaration type (if applicable) of the 'i'th column
          335  +** of the result set of SQL statement pStmt, encoded as UTF-8.
   341    336   */
   342         -static const void *columnName16(sqlite3_stmt *pStmt, int i, int decltype){
          337  +const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
   343    338     Vdbe *p = (Vdbe *)pStmt;
          339  +  Mem *pColName;
   344    340   
   345         -  if( i>=sqlite3_column_count(pStmt) || i<0 ){
          341  +  if( N>=sqlite3_column_count(pStmt) || N<0 ){
   346    342       sqlite3Error(p->db, SQLITE_RANGE, 0);
   347    343       return 0;
   348    344     }
   349    345   
   350         -  if( decltype ){
   351         -    i += p->nResColumn;
   352         -  }
   353         -
   354         -  if( !p->azColName16 ){
   355         -    p->azColName16 = (void **)sqliteMalloc(sizeof(void *)*p->nResColumn*2);
   356         -    if( !p->azColName16 ){
   357         -      sqlite3Error(p->db, SQLITE_NOMEM, 0);
   358         -      return 0;
   359         -    }
   360         -  }
   361         -  if( !p->azColName16[i] ){
   362         -    if( SQLITE3_BIGENDIAN ){
   363         -      p->azColName16[i] = sqlite3utf8to16be(p->azColName[i], -1);
   364         -    }
   365         -    if( !p->azColName16[i] ){
   366         -      sqlite3Error(p->db, SQLITE_NOMEM, 0);
   367         -      return 0;
   368         -    }
   369         -  }
   370         -  return p->azColName16[i];
   371         -}
   372         -
   373         -/*
   374         -** Return the column declaration type (if applicable) of the 'i'th column
   375         -** of the result set of SQL statement pStmt, encoded as UTF-8.
   376         -*/
   377         -const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int i){
   378         -  Vdbe *p = (Vdbe *)pStmt;
   379         -
   380         -  if( i>=sqlite3_column_count(pStmt) || i<0 ){
   381         -    sqlite3Error(p->db, SQLITE_RANGE, 0);
   382         -    return 0;
   383         -  }
   384         -
   385         -  return p->azColName[i+p->nResColumn];
          346  +  pColName = &(p->aColName[N+sqlite3_column_count(pStmt)]);
          347  +  return sqlite3_value_text(pColName);
   386    348   }
   387    349   
   388    350   /*
   389    351   ** Return the column declaration type (if applicable) of the 'i'th column
   390    352   ** of the result set of SQL statement pStmt, encoded as UTF-16.
   391    353   */
   392         -const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int i){
   393         -  return columnName16(pStmt, i, 1);
          354  +const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
          355  +  Vdbe *p = (Vdbe *)pStmt;
          356  +  Mem *pColName;
          357  +
          358  +  if( N>=sqlite3_column_count(pStmt) || N<0 ){
          359  +    sqlite3Error(p->db, SQLITE_RANGE, 0);
          360  +    return 0;
          361  +  }
          362  +
          363  +  pColName = &(p->aColName[N+sqlite3_column_count(pStmt)]);
          364  +  return sqlite3_value_text16(pColName);
   394    365   }
   395    366   
   396    367   /******************************* sqlite3_bind_  ***************************
   397    368   ** 
   398    369   ** Routines used to attach values to wildcards in a compiled SQL statement.
   399    370   */
   400    371   /*

Changes to src/vdbeaux.c.

   917    917   ** This call must be made after a call to sqlite3VdbeSetNumCols().
   918    918   **
   919    919   ** Parameter N may be either P3_DYNAMIC or P3_STATIC.
   920    920   */
   921    921   int sqlite3VdbeSetColName(Vdbe *p, int idx, const char *zName, int N){
   922    922     int rc;
   923    923     Mem *pColName;
   924         -  assert( idx<p->nResColumn );
          924  +  assert( idx<(2*p->nResColumn) );
   925    925   
   926    926     /* If the Vdbe.aColName array has not yet been allocated, allocate
   927    927     ** it now.
   928    928     */
   929    929     if( !p->aColName ){
   930    930       int i;
   931         -    p->aColName = (Mem *)sqliteMalloc(sizeof(Mem)*p->nResColumn);
          931  +    p->aColName = (Mem *)sqliteMalloc(sizeof(Mem)*p->nResColumn*2);
   932    932       if( !p->aColName ){
   933    933         return SQLITE_NOMEM;
   934    934       }
   935         -    for(i=0; i<p->nResColumn; i++){
          935  +    for(i=0; i<(2*p->nResColumn); i++){
   936    936         p->aColName[i].flags = MEM_Null;
   937    937       }
   938    938     }
   939    939   
   940    940     pColName = &(p->aColName[idx]);
   941    941     if( N==0 ){
   942    942       rc = sqlite3VdbeMemSetStr(pColName, zName, -1, TEXT_Utf8, 1);

Changes to test/capi3.test.

     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this script testing the callback-free C/C++ API.
    13     13   #
    14         -# $Id: capi3.test,v 1.9 2004/05/27 10:31:12 danielk1977 Exp $
           14  +# $Id: capi3.test,v 1.10 2004/05/28 13:13:04 danielk1977 Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Return the UTF-16 representation of the supplied UTF-8 string $str.
    21     21   # If $nt is true, append two 0x00 bytes as a nul terminator.
................................................................................
   189    189       foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]} 
   190    190       set cnamelist
   191    191     } $names
   192    192   
   193    193     # Column names in UTF-16
   194    194     do_test $test.2 {
   195    195       set cnamelist [list]
   196         -    foreach i $idxlist {lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]}
          196  +    foreach i $idxlist {
          197  +      lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]
          198  +    }
   197    199       set cnamelist
   198    200     } $names
   199    201   
   200    202     # Column names in UTF-8
   201    203     do_test $test.3 {
   202    204       set cnamelist [list]
   203    205       foreach i $idxlist {lappend cnamelist [sqlite3_column_name $STMT $i]} 
   204    206       set cnamelist
   205    207     } $names
   206    208   
   207    209     # Column names in UTF-16
   208    210     do_test $test.4 {
   209    211       set cnamelist [list]
   210         -    foreach i $idxlist {lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]}
          212  +    foreach i $idxlist {
          213  +      lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]
          214  +    }
   211    215       set cnamelist
   212    216     } $names
          217  +
          218  +  # Column names in UTF-8
          219  +  do_test $test.5 {
          220  +    set cnamelist [list]
          221  +    foreach i $idxlist {lappend cnamelist [sqlite3_column_decltype $STMT $i]} 
          222  +    set cnamelist
          223  +  } $decltypes
          224  +
          225  +  # Column declaration types in UTF-16
          226  +  do_test $test.6 {
          227  +    set cnamelist [list]
          228  +    foreach i $idxlist {
          229  +      lappend cnamelist [utf8 [sqlite3_column_decltype16 $STMT $i]]
          230  +    }
          231  +    set cnamelist
          232  +  } $decltypes
          233  +
   213    234   } 
   214    235   
   215    236   # This proc is used to test the following APIs:
   216    237   #
   217    238   # sqlite3_data_count
   218    239   # sqlite3_column_type
   219    240   # sqlite3_column_int
................................................................................
   317    338     }
   318    339     set sql "SELECT * FROM t1"
   319    340     set STMT [sqlite3_prepare $DB $sql -1 TAIL]
   320    341   
   321    342     sqlite3_column_count $STMT
   322    343   } 3
   323    344   
   324         -check_header $STMT capi3-5.1 {a b c} {VARIANT BLOB VARCHAR(16)}
          345  +check_header $STMT capi3-5.1 {a b c} {VARINT BLOB VARCHAR(16)}
   325    346   
   326    347   do_test capi3-5.2 {
   327    348     sqlite3_step $STMT
   328    349   } SQLITE_ROW
   329    350   
   330         -check_header $STMT capi3-5.3 {a b c} {VARIANT BLOB VARCHAR(16)}
          351  +check_header $STMT capi3-5.3 {a b c} {VARINT BLOB VARCHAR(16)}
   331    352   check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3}
   332    353   
   333    354   do_test capi3-5.5 {
   334    355     sqlite3_step $STMT
   335    356   } SQLITE_ROW
   336    357   
   337         -check_header $STMT capi3-5.6 {a b c} {VARIANT BLOB VARCHAR(16)}
          358  +check_header $STMT capi3-5.6 {a b c} {VARINT BLOB VARCHAR(16)}
   338    359   check_data $STMT capi3-5.7 {TEXT TEXT NULL} {0 0 0} {0.0 0.0 0.0} {one two {}}
   339    360   
   340    361   do_test capi3-5.8 {
   341    362     sqlite3_step $STMT
   342    363   } SQLITE_ROW
   343    364   
   344         -check_header $STMT capi3-5.9 {a b c} {VARIANT BLOB VARCHAR(16)}
          365  +check_header $STMT capi3-5.9 {a b c} {VARINT BLOB VARCHAR(16)}
   345    366   check_data $STMT capi3-5.10 {FLOAT FLOAT TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4}
   346    367   
   347    368   do_test capi3-5.11 {
   348    369     sqlite3_step $STMT
   349    370   } SQLITE_DONE
   350    371   
   351    372   do_test capi3-5.12 {