1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-01 06:27:03 +03:00

Fix a bug in the sqlite3_column_decltype() API. (CVS 1486)

FossilOrigin-Name: c8a40218c20cf5d0abad330e8fa59ca4c36e7608
This commit is contained in:
danielk1977
2004-05-28 13:13:02 +00:00
parent 48dec7e215
commit 76d505baad
6 changed files with 60 additions and 67 deletions

View File

@ -1,5 +1,5 @@
C Allow\sCREATE\sand\sDROP\sVIEW\son\sattached\sdatabases.\s(CVS\s1485) C Fix\sa\sbug\sin\sthe\ssqlite3_column_decltype()\sAPI.\s(CVS\s1486)
D 2004-05-28T12:33:31 D 2004-05-28T13:13:02
F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@ -52,7 +52,7 @@ F src/parse.y 9d3be712abc9005495701efbec741c58408f1343
F src/pragma.c f2b05b087a5764802296a28d7abdd75728beedee F src/pragma.c f2b05b087a5764802296a28d7abdd75728beedee
F src/printf.c ef750e8e2398ca7e8b58be991075f08c6a7f0e53 F src/printf.c ef750e8e2398ca7e8b58be991075f08c6a7f0e53
F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
F src/select.c 26f726b398af8708c81178acc9c68d64e78e6f5e F src/select.c ee54bf2faa76f5e30832fd589a1f10c485047469
F src/shell.c ed4d237b3e52a0a42512bfcc53530e46de20c28f F src/shell.c ed4d237b3e52a0a42512bfcc53530e46de20c28f
F src/sqlite.h.in edc6408c7f53c2104f781a76b926036e17018ec9 F src/sqlite.h.in edc6408c7f53c2104f781a76b926036e17018ec9
F src/sqliteInt.h 1c3fc5d7a2bf33b1ea64284c81dbd07d00d9d1bd F src/sqliteInt.h 1c3fc5d7a2bf33b1ea64284c81dbd07d00d9d1bd
@ -72,8 +72,8 @@ F src/vacuum.c 8734f89742f246abd91dbd3e087fc153bddbfbad
F src/vdbe.c 3b208964add3da0c35c41955a95e6aa44ce75850 F src/vdbe.c 3b208964add3da0c35c41955a95e6aa44ce75850
F src/vdbe.h e73f890e0f2a6c42b183d7d6937947930fe4fdeb F src/vdbe.h e73f890e0f2a6c42b183d7d6937947930fe4fdeb
F src/vdbeInt.h c2bcd6e5a6e6a3753e4c5a368629c3a625719bfc F src/vdbeInt.h c2bcd6e5a6e6a3753e4c5a368629c3a625719bfc
F src/vdbeapi.c b0bb1f98c899ba00c8a5cbca612c2a28a1bb79de F src/vdbeapi.c 0c5d64c81871cb4fe5407e639604ee95738b6942
F src/vdbeaux.c 7a0dd0fb224285e8c5f0b2edf68a10b29fd512a8 F src/vdbeaux.c b1e176b1c9027b4a4eff7b936a449d926956f283
F src/vdbemem.c c97c145ff6d9fc5b4236704c04a65849117e6214 F src/vdbemem.c c97c145ff6d9fc5b4236704c04a65849117e6214
F src/where.c efe5d25fe18cd7381722457898cd863e84097a0c F src/where.c efe5d25fe18cd7381722457898cd863e84097a0c
F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242 F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
@ -91,7 +91,7 @@ F test/btree4.test 3797b4305694c7af6828675b0f4b1424b8ca30e4
F test/btree5.test 8e5ff32c02e685d36516c6499add9375fe1377f2 F test/btree5.test 8e5ff32c02e685d36516c6499add9375fe1377f2
F test/btree6.test a5ede6bfbbb2ec8b27e62813612c0f28e8f3e027 F test/btree6.test a5ede6bfbbb2ec8b27e62813612c0f28e8f3e027
F test/capi2.test 8fb64e8ab7f78b8254cd4d04bb96822167f731b2 F test/capi2.test 8fb64e8ab7f78b8254cd4d04bb96822167f731b2
F test/capi3.test 3d4d431c3b889893504d59064a018642013fd740 F test/capi3.test b6fe8a66d2ffe28d4faaaec154a143131e8ff631
F test/conflict.test 0911bb2f079046914a6e9c3341b36658c4e2103e F test/conflict.test 0911bb2f079046914a6e9c3341b36658c4e2103e
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2 F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
F test/date.test aed5030482ebc02bd8d386c6c86a29f694ab068d F test/date.test aed5030482ebc02bd8d386c6c86a29f694ab068d
@ -204,7 +204,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1 F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
P 2fb3708e10a06660ad1974ef8e9742b706a0a9fc P ad879a957d93c0b49c289947826b451d3ea37e5b
R 357b84549b85209a0556b43d32e20b9f R b9f9e8717dc68172e0562ef2fe6cb24a
U danielk1977 U danielk1977
Z 9f71f73052e9fd5a8f1a3443c4f3df37 Z 50937c4114738747c8662b16c4256cda

View File

@ -1 +1 @@
ad879a957d93c0b49c289947826b451d3ea37e5b c8a40218c20cf5d0abad330e8fa59ca4c36e7608

View File

@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser ** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite. ** 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" #include "sqliteInt.h"
@ -663,7 +663,7 @@ static void generateColumnTypes(
default: zType = "ANY"; break; 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); sqlite3VdbeSetColName(v, i, zName, 0);
} }
} }
generateColumnTypes(pParse, pTabList, pEList);
} }
/* /*

View File

@ -330,67 +330,38 @@ const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
return sqlite3_value_text16(pColName); 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.
*/
static const void *columnName16(sqlite3_stmt *pStmt, int i, int decltype){
Vdbe *p = (Vdbe *)pStmt;
if( i>=sqlite3_column_count(pStmt) || i<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];
}
/* /*
** Return the column declaration type (if applicable) of the 'i'th column ** 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-8.
*/ */
const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int i){ const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
Vdbe *p = (Vdbe *)pStmt; 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); sqlite3Error(p->db, SQLITE_RANGE, 0);
return 0; return 0;
} }
return p->azColName[i+p->nResColumn]; 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 ** Return the column declaration type (if applicable) of the 'i'th column
** of the result set of SQL statement pStmt, encoded as UTF-16. ** of the result set of SQL statement pStmt, encoded as UTF-16.
*/ */
const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int i){ const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
return columnName16(pStmt, i, 1); Vdbe *p = (Vdbe *)pStmt;
Mem *pColName;
if( N>=sqlite3_column_count(pStmt) || N<0 ){
sqlite3Error(p->db, SQLITE_RANGE, 0);
return 0;
}
pColName = &(p->aColName[N+sqlite3_column_count(pStmt)]);
return sqlite3_value_text16(pColName);
} }
/******************************* sqlite3_bind_ *************************** /******************************* sqlite3_bind_ ***************************

View File

@ -921,18 +921,18 @@ void sqlite3VdbeSetNumCols(Vdbe *p, int nResColumn){
int sqlite3VdbeSetColName(Vdbe *p, int idx, const char *zName, int N){ int sqlite3VdbeSetColName(Vdbe *p, int idx, const char *zName, int N){
int rc; int rc;
Mem *pColName; Mem *pColName;
assert( idx<p->nResColumn ); assert( idx<(2*p->nResColumn) );
/* If the Vdbe.aColName array has not yet been allocated, allocate /* If the Vdbe.aColName array has not yet been allocated, allocate
** it now. ** it now.
*/ */
if( !p->aColName ){ if( !p->aColName ){
int i; int i;
p->aColName = (Mem *)sqliteMalloc(sizeof(Mem)*p->nResColumn); p->aColName = (Mem *)sqliteMalloc(sizeof(Mem)*p->nResColumn*2);
if( !p->aColName ){ if( !p->aColName ){
return SQLITE_NOMEM; return SQLITE_NOMEM;
} }
for(i=0; i<p->nResColumn; i++){ for(i=0; i<(2*p->nResColumn); i++){
p->aColName[i].flags = MEM_Null; p->aColName[i].flags = MEM_Null;
} }
} }

View File

@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The # This file implements regression tests for SQLite library. The
# focus of this script testing the callback-free C/C++ API. # 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] set testdir [file dirname $argv0]
@ -193,7 +193,9 @@ proc check_header {STMT test names decltypes} {
# Column names in UTF-16 # Column names in UTF-16
do_test $test.2 { do_test $test.2 {
set cnamelist [list] 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 set cnamelist
} $names } $names
@ -207,9 +209,28 @@ proc check_header {STMT test names decltypes} {
# Column names in UTF-16 # Column names in UTF-16
do_test $test.4 { do_test $test.4 {
set cnamelist [list] 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 set cnamelist
} $names } $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: # This proc is used to test the following APIs:
@ -321,27 +342,27 @@ do_test capi3-5.0 {
sqlite3_column_count $STMT sqlite3_column_count $STMT
} 3 } 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 { do_test capi3-5.2 {
sqlite3_step $STMT sqlite3_step $STMT
} SQLITE_ROW } 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} 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 { do_test capi3-5.5 {
sqlite3_step $STMT sqlite3_step $STMT
} SQLITE_ROW } 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 {}} 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 { do_test capi3-5.8 {
sqlite3_step $STMT sqlite3_step $STMT
} SQLITE_ROW } 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} 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 { do_test capi3-5.11 {