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
+3 -2
View 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);
}
/*
+16 -45
View 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.
*/
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
** 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;
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];
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-16.
*/
const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int i){
return columnName16(pStmt, i, 1);
const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
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_ ***************************
+3 -3
View 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;
}
}