aboutsummaryrefslogtreecommitdiff
path: root/src/window.c
diff options
context:
space:
mode:
authordan <dan@noemail.net>2018-07-06 14:15:49 +0000
committerdan <dan@noemail.net>2018-07-06 14:15:49 +0000
commit5d764ac9e6ea4bbeef59f05a6a146ca6ab51a26f (patch)
tree1a597571336fd951322ca78925fa44ceb05aa174 /src/window.c
parent287fa17b782d41badea92af1986b85e801eb623f (diff)
downloadsqlite-5d764ac9e6ea4bbeef59f05a6a146ca6ab51a26f.tar.gz
sqlite-5d764ac9e6ea4bbeef59f05a6a146ca6ab51a26f.zip
Ensure an error is returned if the user specifies an unsupported frame type.
FossilOrigin-Name: 0f3f8fcde1a535bcf93e23a68d2411c21785d8c0cac1f9481a06e7225755cdbc
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/window.c b/src/window.c
index d20b90b58..f8e71a673 100644
--- a/src/window.c
+++ b/src/window.c
@@ -837,10 +837,26 @@ Window *sqlite3WindowAlloc(
){
Window *pWin = 0;
- if( eType==TK_RANGE && (pStart || pEnd) ){
- sqlite3ErrorMsg(pParse, "RANGE %s is only supported with UNBOUNDED",
- (pStart ? "PRECEDING" : "FOLLOWING")
- );
+ /* If a frame is declared "RANGE" (not "ROWS"), then it may not use
+ ** either "<expr> PRECEDING" or "<expr> FOLLOWING". Additionally, the
+ ** starting boundary type may not occur earlier in the following list than
+ ** the ending boundary type:
+ **
+ ** UNBOUNDED PRECEDING
+ ** <expr> PRECEDING
+ ** CURRENT ROW
+ ** <expr> FOLLOWING
+ ** UNBOUNDED FOLLOWING
+ **
+ ** The parser ensures that "UNBOUNDED PRECEDING" cannot be used as an ending
+ ** boundary, and than "UNBOUNDED FOLLOWING" cannot be used as a starting
+ ** frame boundary.
+ */
+ if( eType==TK_RANGE && (pStart || pEnd)
+ || (eStart==TK_CURRENT && eEnd==TK_PRECEDING)
+ || (eStart==TK_FOLLOWING && (eEnd==TK_PRECEDING || eEnd==TK_CURRENT))
+ ){
+ sqlite3ErrorMsg(pParse, "unsupported window-frame type");
}else{
pWin = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
}