1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Make sure compound queries inside a subquery only return a single result

column.  Ticket #2347. (CVS 3967)

FossilOrigin-Name: 66954bdd81dabfb60306de8480b5477a4acb1d9e
This commit is contained in:
drh
2007-05-09 22:56:39 +00:00
parent 6fa51035c3
commit e305f43f17
4 changed files with 59 additions and 13 deletions

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.342 2007/05/08 13:58:28 drh Exp $
** $Id: select.c,v 1.343 2007/05/09 22:56:39 drh Exp $
*/
#include "sqliteInt.h"
@@ -434,6 +434,21 @@ static void codeDistinct(
sqlite3VdbeAddOp(v, OP_IdxInsert, iTab, 0);
}
/*
** Generate an error message when a SELECT is used within a subexpression
** (example: "a IN (SELECT * FROM table)") but it has more than 1 result
** column. We do this in a subroutine because the error occurs in multiple
** places.
*/
static int checkForMultiColumnSelectError(Parse *pParse, int eDest, int nExpr){
if( nExpr>1 && (eDest==SRT_Mem || eDest==SRT_Set) ){
sqlite3ErrorMsg(pParse, "only a single result allowed for "
"a SELECT that is part of an expression");
return 1;
}else{
return 0;
}
}
/*
** This routine generates the code for the inside of the inner loop
@@ -497,6 +512,10 @@ static int selectInnerLoop(
}
}
if( checkForMultiColumnSelectError(pParse, eDest, pEList->nExpr) ){
return 0;
}
switch( eDest ){
/* In this mode, write each query result to the key of the temporary
** table iParm.
@@ -2889,9 +2908,7 @@ int sqlite3Select(
** only a single column may be output.
*/
#ifndef SQLITE_OMIT_SUBQUERY
if( (eDest==SRT_Mem || eDest==SRT_Set) && pEList->nExpr>1 ){
sqlite3ErrorMsg(pParse, "only a single result allowed for "
"a SELECT that is part of an expression");
if( checkForMultiColumnSelectError(pParse, eDest, pEList->nExpr) ){
goto select_end;
}
#endif