Index: src/select.c ================================================================== --- src/select.c +++ src/select.c @@ -10,11 +10,11 @@ ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.142 2003/07/16 02:19:38 drh Exp $ +** $Id: select.c,v 1.143 2003/07/16 11:51:36 drh Exp $ */ #include "sqliteInt.h" /* @@ -2146,12 +2146,18 @@ ** If the comparison is p->nLimit<=0 then "LIMIT 0" shows ** all rows. It is the same as no limit. If the comparision is ** p->nLimit<0 then "LIMIT 0" show no rows at all. ** "LIMIT -1" always shows all rows. There is some ** contraversy about what the correct behavior should be. + ** + ** Note that up until this point, the nLimit and nOffset hold + ** the numeric values of the limit and offset that appeared in + ** the original SQL. After this code, the nLimit and nOffset hold + ** the register number of counters used to track the limit and + ** offset. */ - if( p->nLimit<=0 ){ + if( p->nLimit<0 ){ p->nLimit = -1; }else{ int iMem = pParse->nMem++; sqliteVdbeAddOp(v, OP_Integer, -p->nLimit, 0); sqliteVdbeAddOp(v, OP_MemStore, iMem, 1); Index: test/limit.test ================================================================== --- test/limit.test +++ test/limit.test @@ -10,11 +10,11 @@ #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this file is testing the LIMIT ... OFFSET ... clause # of SELECT statements. # -# $Id: limit.test,v 1.8 2003/07/16 02:19:38 drh Exp $ +# $Id: limit.test,v 1.9 2003/07/16 11:51:36 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Build some test data @@ -192,15 +192,25 @@ SELECT * FROM t6 LIMIT -432 OFFSET 2; } } {3 4} do_test limit-6.5 { execsql { - SELECT * FROM t6 LIMIT 0 + SELECT * FROM t6 LIMIT -1 } } {1 2 3 4} do_test limit-6.6 { execsql { - SELECT * FROM t6 LIMIT 0 OFFSET 1 + SELECT * FROM t6 LIMIT -1 OFFSET 1 } } {2 3 4} +do_test limit-6.7 { + execsql { + SELECT * FROM t6 LIMIT 0 + } +} {} +do_test limit-6.8 { + execsql { + SELECT * FROM t6 LIMIT 0 OFFSET 1 + } +} {} finish_test Index: www/lang.tcl ================================================================== --- www/lang.tcl +++ www/lang.tcl @@ -1,9 +1,9 @@ # # Run this Tcl script to generate the sqlite.html file. # -set rcsid {$Id: lang.tcl,v 1.63 2003/06/15 23:49:39 drh Exp $} +set rcsid {$Id: lang.tcl,v 1.64 2003/07/16 11:51:36 drh Exp $} puts { Query Language Understood By SQLite @@ -1548,11 +1548,11 @@ expression must exactly match one of the result columns. Each sort expression may be optionally followed by ASC or DESC to specify the sort order.

The LIMIT clause places an upper bound on the number of rows -returned in the result. A LIMIT of 0 indicates no upper bound. +returned in the result. A negative LIMIT indicates no upper bound. The optional OFFSET following LIMIT specifies how many rows to skip at the beginning of the result set.

A compound SELECT is formed from two or more simple SELECTs connected by one of the operators UNION, UNION ALL, INTERSECT, or EXCEPT. In