]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a bug in the sqlite3_column_decltype() API. (CVS 1486)
authordanielk1977 <danielk1977@noemail.net>
Fri, 28 May 2004 13:13:02 +0000 (13:13 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Fri, 28 May 2004 13:13:02 +0000 (13:13 +0000)
FossilOrigin-Name: c8a40218c20cf5d0abad330e8fa59ca4c36e7608

manifest
manifest.uuid
src/select.c
src/vdbeapi.c
src/vdbeaux.c
test/capi3.test

index eb1d8f8901f7468e5ecd750aa5f3563013e94412..15f258b83bbbcf6a956c24c71a475b4841ba658d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Allow\sCREATE\sand\sDROP\sVIEW\son\sattached\sdatabases.\s(CVS\s1485)
-D 2004-05-28T12:33:31
+C Fix\sa\sbug\sin\sthe\ssqlite3_column_decltype()\sAPI.\s(CVS\s1486)
+D 2004-05-28T13:13:02
 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -52,7 +52,7 @@ F src/parse.y 9d3be712abc9005495701efbec741c58408f1343
 F src/pragma.c f2b05b087a5764802296a28d7abdd75728beedee
 F src/printf.c ef750e8e2398ca7e8b58be991075f08c6a7f0e53
 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
-F src/select.c 26f726b398af8708c81178acc9c68d64e78e6f5e
+F src/select.c ee54bf2faa76f5e30832fd589a1f10c485047469
 F src/shell.c ed4d237b3e52a0a42512bfcc53530e46de20c28f
 F src/sqlite.h.in edc6408c7f53c2104f781a76b926036e17018ec9
 F src/sqliteInt.h 1c3fc5d7a2bf33b1ea64284c81dbd07d00d9d1bd
@@ -72,8 +72,8 @@ F src/vacuum.c 8734f89742f246abd91dbd3e087fc153bddbfbad
 F src/vdbe.c 3b208964add3da0c35c41955a95e6aa44ce75850
 F src/vdbe.h e73f890e0f2a6c42b183d7d6937947930fe4fdeb
 F src/vdbeInt.h c2bcd6e5a6e6a3753e4c5a368629c3a625719bfc
-F src/vdbeapi.c b0bb1f98c899ba00c8a5cbca612c2a28a1bb79de
-F src/vdbeaux.c 7a0dd0fb224285e8c5f0b2edf68a10b29fd512a8
+F src/vdbeapi.c 0c5d64c81871cb4fe5407e639604ee95738b6942
+F src/vdbeaux.c b1e176b1c9027b4a4eff7b936a449d926956f283
 F src/vdbemem.c c97c145ff6d9fc5b4236704c04a65849117e6214
 F src/where.c efe5d25fe18cd7381722457898cd863e84097a0c
 F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
@@ -91,7 +91,7 @@ F test/btree4.test 3797b4305694c7af6828675b0f4b1424b8ca30e4
 F test/btree5.test 8e5ff32c02e685d36516c6499add9375fe1377f2
 F test/btree6.test a5ede6bfbbb2ec8b27e62813612c0f28e8f3e027
 F test/capi2.test 8fb64e8ab7f78b8254cd4d04bb96822167f731b2
-F test/capi3.test 3d4d431c3b889893504d59064a018642013fd740
+F test/capi3.test b6fe8a66d2ffe28d4faaaec154a143131e8ff631
 F test/conflict.test 0911bb2f079046914a6e9c3341b36658c4e2103e
 F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
 F test/date.test aed5030482ebc02bd8d386c6c86a29f694ab068d
@@ -204,7 +204,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
 F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
 F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P 2fb3708e10a06660ad1974ef8e9742b706a0a9fc
-R 357b84549b85209a0556b43d32e20b9f
+P ad879a957d93c0b49c289947826b451d3ea37e5b
+R b9f9e8717dc68172e0562ef2fe6cb24a
 U danielk1977
-Z 9f71f73052e9fd5a8f1a3443c4f3df37
+Z 50937c4114738747c8662b16c4256cda
index 8a6bf5a92a763912468f9dc06f665f42466f5ce2..adf7d768a9ea6e679dff207539ce975ff4db538f 100644 (file)
@@ -1 +1 @@
-ad879a957d93c0b49c289947826b451d3ea37e5b
\ No newline at end of file
+c8a40218c20cf5d0abad330e8fa59ca4c36e7608
\ No newline at end of file
index 03fd4c4d7483dbae817ac6ec8472983b857d011b..d0cbf3c0097725999778cf4e0d5e488d0f8c2eb6 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle SELECT statements in SQLite.
 **
-** $Id: select.c,v 1.180 2004/05/27 23:56:16 danielk1977 Exp $
+** $Id: select.c,v 1.181 2004/05/28 13:13:02 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -663,7 +663,7 @@ static void generateColumnTypes(
         default:                  zType = "ANY";     break;
       }
     }
-    sqlite3VdbeOp3(v, OP_ColumnName, i + pEList->nExpr, 0, zType, 0);
+    sqlite3VdbeSetColName(v, i+pEList->nExpr, zType, P3_STATIC);
   }
 }
 
@@ -740,6 +740,7 @@ static void generateColumnNames(
       sqlite3VdbeSetColName(v, i, zName, 0);
     }
   }
+  generateColumnTypes(pParse, pTabList, pEList);
 }
 
 /*
index 167178af34cb141bd7ed57d3c93215a69723a667..682d9a63eec30bf9f148e31476eac340056b4a23 100644 (file)
@@ -330,67 +330,38 @@ const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
   return sqlite3_value_text16(pColName);
 }
 
-
 /*
-** This routine returns either the column name, or declaration type (see
-** sqlite3_column_decltype16() ) of the 'i'th column of the result set of
-** SQL statement pStmt. The returned string is UTF-16 encoded.
-**
-** The declaration type is returned if 'decltype' is true, otherwise
-** the column name.
+** Return the column declaration type (if applicable) of the 'i'th column
+** of the result set of SQL statement pStmt, encoded as UTF-8.
 */
-static const void *columnName16(sqlite3_stmt *pStmt, int i, int decltype){
+const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
   Vdbe *p = (Vdbe *)pStmt;
+  Mem *pColName;
 
-  if( i>=sqlite3_column_count(pStmt) || i<0 ){
+  if( N>=sqlite3_column_count(pStmt) || N<0 ){
     sqlite3Error(p->db, SQLITE_RANGE, 0);
     return 0;
   }
 
-  if( decltype ){
-    i += p->nResColumn;
-  }
-
-  if( !p->azColName16 ){
-    p->azColName16 = (void **)sqliteMalloc(sizeof(void *)*p->nResColumn*2);
-    if( !p->azColName16 ){
-      sqlite3Error(p->db, SQLITE_NOMEM, 0);
-      return 0;
-    }
-  }
-  if( !p->azColName16[i] ){
-    if( SQLITE3_BIGENDIAN ){
-      p->azColName16[i] = sqlite3utf8to16be(p->azColName[i], -1);
-    }
-    if( !p->azColName16[i] ){
-      sqlite3Error(p->db, SQLITE_NOMEM, 0);
-      return 0;
-    }
-  }
-  return p->azColName16[i];
+  pColName = &(p->aColName[N+sqlite3_column_count(pStmt)]);
+  return sqlite3_value_text(pColName);
 }
 
 /*
 ** Return the column declaration type (if applicable) of the 'i'th column
-** of the result set of SQL statement pStmt, encoded as UTF-8.
+** of the result set of SQL statement pStmt, encoded as UTF-16.
 */
-const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int i){
+const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
   Vdbe *p = (Vdbe *)pStmt;
+  Mem *pColName;
 
-  if( i>=sqlite3_column_count(pStmt) || i<0 ){
+  if( N>=sqlite3_column_count(pStmt) || N<0 ){
     sqlite3Error(p->db, SQLITE_RANGE, 0);
     return 0;
   }
 
-  return p->azColName[i+p->nResColumn];
-}
-
-/*
-** Return the column declaration type (if applicable) of the 'i'th column
-** of the result set of SQL statement pStmt, encoded as UTF-16.
-*/
-const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int i){
-  return columnName16(pStmt, i, 1);
+  pColName = &(p->aColName[N+sqlite3_column_count(pStmt)]);
+  return sqlite3_value_text16(pColName);
 }
 
 /******************************* sqlite3_bind_  ***************************
index 93a30fd308ac6612e91895412bf80998cf4c770a..1ad5d3c8b641195a29e7451f3da783d918cd752c 100644 (file)
@@ -921,18 +921,18 @@ void sqlite3VdbeSetNumCols(Vdbe *p, int nResColumn){
 int sqlite3VdbeSetColName(Vdbe *p, int idx, const char *zName, int N){
   int rc;
   Mem *pColName;
-  assert( idx<p->nResColumn );
+  assert( idx<(2*p->nResColumn) );
 
   /* If the Vdbe.aColName array has not yet been allocated, allocate
   ** it now.
   */
   if( !p->aColName ){
     int i;
-    p->aColName = (Mem *)sqliteMalloc(sizeof(Mem)*p->nResColumn);
+    p->aColName = (Mem *)sqliteMalloc(sizeof(Mem)*p->nResColumn*2);
     if( !p->aColName ){
       return SQLITE_NOMEM;
     }
-    for(i=0; i<p->nResColumn; i++){
+    for(i=0; i<(2*p->nResColumn); i++){
       p->aColName[i].flags = MEM_Null;
     }
   }
index dd40738fbff37ea0ff1b0968a92d18d5425c48b0..c8a116a7b30949a0a2b06497c3ef5efe39f54602 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this script testing the callback-free C/C++ API.
 #
-# $Id: capi3.test,v 1.9 2004/05/27 10:31:12 danielk1977 Exp $
+# $Id: capi3.test,v 1.10 2004/05/28 13:13:04 danielk1977 Exp $
 #
 
 set testdir [file dirname $argv0]
@@ -193,7 +193,9 @@ proc check_header {STMT test names decltypes} {
   # Column names in UTF-16
   do_test $test.2 {
     set cnamelist [list]
-    foreach i $idxlist {lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]}
+    foreach i $idxlist {
+      lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]
+    }
     set cnamelist
   } $names
 
@@ -207,9 +209,28 @@ proc check_header {STMT test names decltypes} {
   # Column names in UTF-16
   do_test $test.4 {
     set cnamelist [list]
-    foreach i $idxlist {lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]}
+    foreach i $idxlist {
+      lappend cnamelist [utf8 [sqlite3_column_name16 $STMT $i]]
+    }
     set cnamelist
   } $names
+
+  # Column names in UTF-8
+  do_test $test.5 {
+    set cnamelist [list]
+    foreach i $idxlist {lappend cnamelist [sqlite3_column_decltype $STMT $i]} 
+    set cnamelist
+  } $decltypes
+
+  # Column declaration types in UTF-16
+  do_test $test.6 {
+    set cnamelist [list]
+    foreach i $idxlist {
+      lappend cnamelist [utf8 [sqlite3_column_decltype16 $STMT $i]]
+    }
+    set cnamelist
+  } $decltypes
+
 } 
 
 # This proc is used to test the following APIs:
@@ -321,27 +342,27 @@ do_test capi3-5.0 {
   sqlite3_column_count $STMT
 } 3
 
-check_header $STMT capi3-5.1 {a b c} {VARIANT BLOB VARCHAR(16)}
+check_header $STMT capi3-5.1 {a b c} {VARINT BLOB VARCHAR(16)}
 
 do_test capi3-5.2 {
   sqlite3_step $STMT
 } SQLITE_ROW
 
-check_header $STMT capi3-5.3 {a b c} {VARIANT BLOB VARCHAR(16)}
+check_header $STMT capi3-5.3 {a b c} {VARINT BLOB VARCHAR(16)}
 check_data $STMT capi3-5.4 {INTEGER INTEGER TEXT} {1 2 3} {1.0 2.0 3.0} {1 2 3}
 
 do_test capi3-5.5 {
   sqlite3_step $STMT
 } SQLITE_ROW
 
-check_header $STMT capi3-5.6 {a b c} {VARIANT BLOB VARCHAR(16)}
+check_header $STMT capi3-5.6 {a b c} {VARINT BLOB VARCHAR(16)}
 check_data $STMT capi3-5.7 {TEXT TEXT NULL} {0 0 0} {0.0 0.0 0.0} {one two {}}
 
 do_test capi3-5.8 {
   sqlite3_step $STMT
 } SQLITE_ROW
 
-check_header $STMT capi3-5.9 {a b c} {VARIANT BLOB VARCHAR(16)}
+check_header $STMT capi3-5.9 {a b c} {VARINT BLOB VARCHAR(16)}
 check_data $STMT capi3-5.10 {FLOAT FLOAT TEXT} {1 1 1} {1.2 1.3 1.4} {1.2 1.3 1.4}
 
 do_test capi3-5.11 {