1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Initial implementation of per-connection limits and the sqlite3_limit() API.

The sqllimits1.test script crashes.  SQLITE_LIMIT_PAGE_COUNT and
SQLITE_LIMIT_VDBE_OP are currently ignored. (CVS 4897)

FossilOrigin-Name: 60c77882b2de9f6a45f8bd87c9c6a0cc613f8373
This commit is contained in:
drh
2008-03-20 14:03:29 +00:00
parent f653d78282
commit bb4957f858
21 changed files with 284 additions and 364 deletions

View File

@@ -1,5 +1,5 @@
C Allow\sa\sVACUUM\soperation\sto\schange\sthe\spage-size\sin\sthe\ssame\sway\sas\sit\scan\sbe\sused\sto\schange\sa\sdatabase\sbetween\sauto-vacuum\sand\snormal\smode.\s(CVS\s4896)
D 2008-03-20T11:04:21
C Initial\simplementation\sof\sper-connection\slimits\sand\sthe\ssqlite3_limit()\sAPI.\nThe\ssqllimits1.test\sscript\scrashes.\s\sSQLITE_LIMIT_PAGE_COUNT\sand\nSQLITE_LIMIT_VDBE_OP\sare\scurrently\signored.\s(CVS\s4897)
D 2008-03-20T14:03:29
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in cf434ce8ca902e69126ae0f94fc9f7dc7428a5fa
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -82,30 +82,29 @@ F sqlite3.def a1be7b9a4b8b51ac41c6ff6e8e44a14ef66b338b
F sqlite3.pc.in 32b8a014799c2028c8e0c9cc5659718262fc493f
F src/alter.c b42d782906fc3b92c331efbe06e9389617b47ce7
F src/analyze.c a78ac494668581fe7f54ee63700815bb0ea34261
F src/attach.c e7cf4ae2a2c8ebd554dc6ca06859b587fa7197c2
F src/attach.c bdc75e759ca25a16f4dc7fbdbc6d37ad2561bb24
F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
F src/bitvec.c fac68429a9916a50229c4ab88abb69c00c438f7f
F src/btmutex.c 483ced3c52205b04b97df69161fadbf87f4f1ea2
F src/btree.c 77304a2086a9089fe5e5ee8861248b72d6cca5d6
F src/btree.h 19dcf5ad23c17b98855da548e9a8e3eb4429d5eb
F src/btreeInt.h d7d2f4d9d7f2e72c455326d48b2b478b842a81f6
F src/build.c fa70bc0fb02e4d08202dd6a752ab5f5df5676e50
F src/build.c 31ed5af4e8ac40c30bb0f88d7fec75e72cc16e0e
F src/callback.c 77b302b0d41468dcda78c70e706e5b84577f0fa0
F src/complete.c 4cf68fd75d60257524cbe74f87351b9848399131
F src/date.c 7b80383c47beafd9b49f2c1be65a72747593c4e1
F src/date.c e41ce4513fb0e359dc678d6bddb4ace135fe365d
F src/delete.c 217cd5559e00bb135dc626d4ea4ac713604729e8
F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b
F src/expr.c 242f2f57a32f6909270e4a22ce1c810a150f5a17
F src/expr.c 11e00cafa3c6c7e432b06f06c923d1332349354a
F src/fault.c 039abb45c9dbcbdf575ec2a23ae38db01bc2f7b2
F src/func.c ffce8131bbc2117168beb32afce7fb75bd2c055f
F src/func.c 3ac6e84e601321519d1b452c95cf92a51403fc4d
F src/hash.c 53655c312280211444bfe23af6490a460aec2980
F src/hash.h 031cd9f915aff27e12262cb9eb570ac1b8326b53
F src/insert.c 358c80592c20a61a8d5b4a127215b5e25de652f4
F src/journal.c 807bed7a158979ac8d63953e1774e8d85bff65e2
F src/legacy.c cb1939fdeb91ea88fb44fbd2768a10e14bc44650
F src/limits.h 71ab25f17e35e0a9f3f6f234b8ed49cc56731d35
F src/loadext.c f26b22f7c84153c9d5dbd7c240848823c6e6b6dc
F src/main.c 9dd4646a7dadcde7efa36c2904792f992872b2bc
F src/main.c 03a53976e226dfb5867b3102db5b9ec2e40fc0e7
F src/malloc.c 60e392a4c12c839517f9b0db7b995f825444fb35
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/mem1.c fc716ff521b6dd3e43eaa211967383308800e70a
@@ -133,16 +132,16 @@ F src/pager.c 22241b59c80ca083a96816df434adb8c097afcd4
F src/pager.h b1e2258f03878c14b06a95bfa362e8c5c9638170
F src/parse.y 00f2698c8ae84f315be5e3f10b63c94f531fdd6d
F src/pragma.c f64eed914518c28d1863356163dea1e6f58e28f2
F src/prepare.c 88e32e985921e9fb5d3ca22ccc74e054ebfe49f2
F src/printf.c eb27822ba2eec669161409ca31279a24c26ac910
F src/prepare.c 1b71b5d43ba3d88f2d3c2a6d084f28ac209df956
F src/printf.c 88674589be4b9eac3987ff735e74681864c88c32
F src/random.c 8b6ab5418cf0f4dde551730825d67da1457c2b3c
F src/select.c d0a1e01a2a6c05bd60324e843c7e4581d3605950
F src/select.c 2a0f383a16c780b8ee8108e994c2f6c4f82233a9
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c 22297fffa6f00a6c6d44020fa13b1184a1bb372d
F src/sqlite.h.in c82088b99b3262c017ddadc14d45b2d5877cbeae
F src/sqlite.h.in be6a431e128b831df7d62fc48b7ce2043f55cf90
F src/sqlite3ext.h faacd0e6a81aabee0861c6d7883c9172e74ef5b3
F src/sqliteInt.h 160aadae3b44b53b9176d615bbada6b0ba7d00c4
F src/sqliteLimit.h ee4430f88f69bf63527967bb35ca52af7b0ccb1e
F src/sqliteInt.h ec78c602dc2675f675ca4f9fbc72e60a262c40e9
F src/sqliteLimit.h eecbc288b410ae5565e71aaa4a439aae57bb0707
F src/table.c 2c48c575dd59b3a6c5c306bc55f51a9402cf429a
F src/tclsqlite.c d42912617d4734b8f9195416badf5b27e512ded2
F src/test1.c 935f327fe989694a3aa07ab78ae5c00705651b34
@@ -157,7 +156,7 @@ F src/test9.c 4615ef08750245a2d96aaa7cbe2fb4aff2b57acc
F src/test_async.c 3147c64c34721f088d5ab20f85dabd5d7732c007
F src/test_autoext.c 5e892ab84aece3f0428920bf46923f16ac83962a
F src/test_btree.c c1308ba0b88ab577fa56c9e493a09829dfcded9c
F src/test_config.c 4c1fe5184b1e9db8a4bb130889f3a2e91f07508b
F src/test_config.c a0c779e589df63a9de36d4fe3971bc04975e2675
F src/test_devsym.c cee1aecaa90c895030399ca4ae38f84a08038f8a
F src/test_func.c 9e9b33ff083b65da91c389cece903bc32de06f01
F src/test_hexio.c 1a1cd8324d57585ea86b922f609fa1fbaaf9662d
@@ -169,20 +168,20 @@ F src/test_schema.c 12c9de7661d6294eec2d57afbb52e2af1128084f
F src/test_server.c a6ece6c835e7eae835054124e09e947e422b1ac5
F src/test_tclvar.c b2d1115e4d489179d3f029e765211b2ad527ba59
F src/test_thread.c e297dd41db0b249646e69f97d36ec13e56e8b730
F src/tokenize.c c4b79fd48ddb709b2b8522b7d93a5a3d98168ca4
F src/tokenize.c 13113f94bd1c15dea9e922f08b10f3eee6863474
F src/trigger.c 9bd3b6fa0beff4a02d262c96466f752ec15a7fc3
F src/update.c d2c59643af98f966c2a04d392463089b715ca18f
F src/utf.c 32b00d6e19010025e58f2ecb2f921d5e126771b4
F src/util.c dba9e04121eb17ec4643d6ca231ff859452cf0e2
F src/vacuum.c 3524411bfb58aac0d87eadd3e5b7cd532772af30
F src/vdbe.c 86033e43d89892ea6a817e8bcd4e6273bc1ebdf5
F src/vdbe.c 5ac49cf526843436ed295f5150a508a38b192b89
F src/vdbe.h 58a7d931ffb704e034b2a725981cfa5bd406fad9
F src/vdbeInt.h 76c81d057a39813de0fda3cad1498655d53ec69d
F src/vdbeapi.c 6e6f2bd51a74b74a72e31f6db409f55a98bc8ea2
F src/vdbeapi.c a3bddeee0f011faadb20316926cc97f95efa6415
F src/vdbeaux.c 82f3c8913e68b4928de28c3fa117464356d59df6
F src/vdbeblob.c 63c750acc7b5012479f508c0e9627372a82cb65d
F src/vdbefifo.c a30c237b2a3577e1415fb6e288cbb6b8ed1e5736
F src/vdbemem.c 5de8de022bb93674cd6d48dd919242b517c27c60
F src/vdbemem.c 67662aac917b627356262f9501591206db2a8845
F src/vtab.c 00cd16317b29495c185ff40e4b227917d5a371b2
F src/where.c 78d6689d7154d8d41c1a913e17bce9a320981653
F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
@@ -328,7 +327,7 @@ F test/fts3ao.test 0aa29dd4fc1c8d46b1f7cfe5926f7ac97551bea9
F test/fts3atoken.test 25c2070e1e8755d414bf9c8200427b277a9f99fa
F test/fts3b.test b3a25180a633873d37d86e1ccd00ed690d37237a
F test/fts3near.test 2d4dadcaac5025ab65bb87e66c45f39e92966194
F test/func.test c805453a6fc95b20266682eb10a6325b4e7d8bd3
F test/func.test 03502ed9cbf3acc0cddf5f41efa61fdb05d03139
F test/fuzz.test 62fc19dd36a427777fd671b569df07166548628a
F test/fuzz2.test ea38692ce2da99ad79fe0be5eb1a452c1c4d37bb
F test/fuzz_common.tcl ff4bc2dfc465f6878f8e2d819620914365382731
@@ -625,7 +624,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 8b198617f572d35f04d119ba688e0f5c67f81144
R a308dd47ecbf55342f9cd3c4b73f760c
U danielk1977
Z ca52892929aebf794b5fd5229c74cc6b
P 871df0e7c36a88f175cfc63797745e52a1b1796b
R 4c7da889f1547b07b3861cee6e60887d
U drh
Z 1218328931920895e6af9308ec904100

View File

@@ -1 +1 @@
871df0e7c36a88f175cfc63797745e52a1b1796b
60c77882b2de9f6a45f8bd87c9c6a0cc613f8373

View File

@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
**
** $Id: attach.c,v 1.73 2008/03/19 21:45:51 drh Exp $
** $Id: attach.c,v 1.74 2008/03/20 14:03:29 drh Exp $
*/
#include "sqliteInt.h"
@@ -87,10 +87,10 @@ static void attachFunc(
** * Transaction currently open
** * Specified database name already being used.
*/
if( db->nDb>=SQLITE_MAX_ATTACHED+2 ){
if( db->nDb>=db->aLimit[SQLITE_LIMIT_ATTACHED]+2 ){
sqlite3_snprintf(
sizeof(zErr), zErr, "too many attached databases - max %d",
SQLITE_MAX_ATTACHED
db->aLimit[SQLITE_LIMIT_ATTACHED]
);
goto attach_error;
}

View File

@@ -22,7 +22,7 @@
** COMMIT
** ROLLBACK
**
** $Id: build.c,v 1.474 2008/03/06 09:58:50 mlcreech Exp $
** $Id: build.c,v 1.475 2008/03/20 14:03:29 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -933,11 +933,14 @@ void sqlite3AddColumn(Parse *pParse, Token *pName){
int i;
char *z;
Column *pCol;
sqlite3 *db = pParse->db;
if( (p = pParse->pNewTable)==0 ) return;
if( p->nCol+1>SQLITE_MAX_COLUMN ){
#if SQLITE_MAX_COLUMN
if( p->nCol+1>db->aLimit[SQLITE_LIMIT_COLUMN] ){
sqlite3ErrorMsg(pParse, "too many columns on %s", p->zName);
return;
}
#endif
z = sqlite3NameFromToken(pParse->db, pName);
if( z==0 ) return;
for(i=0; i<p->nCol; i++){

View File

@@ -16,7 +16,7 @@
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: date.c,v 1.78 2008/03/19 21:45:51 drh Exp $
** $Id: date.c,v 1.79 2008/03/20 14:03:29 drh Exp $
**
** SQLite processes all times and dates as Julian Day numbers. The
** dates and times are stored as the number of days since noon
@@ -840,7 +840,7 @@ static void strftimeFunc(
}
if( n<sizeof(zBuf) ){
z = zBuf;
}else if( n>SQLITE_MAX_LENGTH ){
}else if( n>sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH] ){
sqlite3_result_error_toobig(context);
return;
}else{

View File

@@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.354 2008/03/12 10:39:00 danielk1977 Exp $
** $Id: expr.c,v 1.355 2008/03/20 14:03:29 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -400,9 +400,9 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
** use it as the variable number */
int i;
pExpr->iTable = i = atoi((char*)&pToken->z[1]);
if( i<1 || i>SQLITE_MAX_VARIABLE_NUMBER ){
if( i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
SQLITE_MAX_VARIABLE_NUMBER);
db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
}
if( i>pParse->nVar ){
pParse->nVar = i;
@@ -440,7 +440,7 @@ void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr){
}
}
}
if( !pParse->nErr && pParse->nVar>SQLITE_MAX_VARIABLE_NUMBER ){
if( !pParse->nErr && pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
sqlite3ErrorMsg(pParse, "too many SQL variables");
}
}
@@ -705,7 +705,6 @@ void sqlite3ExprListCheckLength(
}
#if defined(SQLITE_TEST) || SQLITE_MAX_EXPR_DEPTH>0
/* The following three functions, heightOfExpr(), heightOfExprList()
** and heightOfSelect(), are used to determine the maximum height
** of any expression tree referenced by the structure passed as the
@@ -768,7 +767,6 @@ int sqlite3SelectExprHeight(Select *p){
heightOfSelect(p, &nHeight);
return nHeight;
}
#endif
/*
** Delete an entire expression list.
@@ -1484,21 +1482,24 @@ int sqlite3ExprResolveNames(
Expr *pExpr /* The expression to be analyzed. */
){
int savedHasAgg;
if( pExpr==0 ) return 0;
#if defined(SQLITE_TEST) || SQLITE_MAX_EXPR_DEPTH>0
if( (pExpr->nHeight+pNC->pParse->nHeight)>SQLITE_MAX_EXPR_DEPTH ){
#if SQLITE_MAX_EXPR_DEPTH>0
{
int mxDepth = pNC->pParse->db->aLimit[SQLITE_LIMIT_EXPR_DEPTH];
if( (pExpr->nHeight+pNC->pParse->nHeight)>mxDepth ){
sqlite3ErrorMsg(pNC->pParse,
"Expression tree is too large (maximum depth %d)",
SQLITE_MAX_EXPR_DEPTH
"Expression tree is too large (maximum depth %d)", mxDepth
);
return 1;
}
pNC->pParse->nHeight += pExpr->nHeight;
}
#endif
savedHasAgg = pNC->hasAgg;
pNC->hasAgg = 0;
walkExprTree(pExpr, nameResolverStep, pNC);
#if defined(SQLITE_TEST) || SQLITE_MAX_EXPR_DEPTH>0
#if SQLITE_MAX_EXPR_DEPTH>0
pNC->pParse->nHeight -= pExpr->nHeight;
#endif
if( pNC->nErr>0 ){

View File

@@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
** $Id: func.c,v 1.189 2008/03/19 21:45:51 drh Exp $
** $Id: func.c,v 1.190 2008/03/20 14:03:29 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -188,7 +188,7 @@ static void substrFunc(
if( argc==3 ){
p2 = sqlite3_value_int(argv[2]);
}else{
p2 = SQLITE_MAX_LENGTH;
p2 = sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH];
}
if( p1<0 ){
p1 += len;
@@ -244,10 +244,16 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
** the database handle that malloc() has failed.
*/
static void *contextMalloc(sqlite3_context *context, int nByte){
char *z = sqlite3_malloc(nByte);
char *z;
if( nByte>sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH] ){
sqlite3_result_error_toobig(context);
z = 0;
}else{
z = sqlite3_malloc(nByte);
if( !z && nByte>0 ){
sqlite3_result_error_nomem(context);
}
}
return z;
}
@@ -345,10 +351,6 @@ static void randomBlob(
if( n<1 ){
n = 1;
}
if( n>SQLITE_MAX_LENGTH ){
sqlite3_result_error_toobig(context);
return;
}
p = contextMalloc(context, n);
if( p ){
sqlite3_randomness(n, p);
@@ -591,6 +593,7 @@ static void likeFunc(
){
const unsigned char *zA, *zB;
int escape = 0;
sqlite3 *db = sqlite3_context_db_handle(context);
zB = sqlite3_value_text(argv[0]);
zA = sqlite3_value_text(argv[1]);
@@ -598,7 +601,8 @@ static void likeFunc(
/* Limit the length of the LIKE or GLOB pattern to avoid problems
** of deep recursion and N*N behavior in patternCompare().
*/
if( sqlite3_value_bytes(argv[0])>SQLITE_MAX_LIKE_PATTERN_LENGTH ){
if( sqlite3_value_bytes(argv[0]) >
db->aLimit[SQLITE_LIMIT_LIKE_PATTERN_LENGTH] ){
sqlite3_result_error(context, "LIKE or GLOB pattern too complex", -1);
return;
}
@@ -690,11 +694,6 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
char const *zBlob = sqlite3_value_blob(argv[0]);
int nBlob = sqlite3_value_bytes(argv[0]);
assert( zBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */
if( 2*nBlob+4>SQLITE_MAX_LENGTH ){
sqlite3_result_error_toobig(context);
return;
}
zText = (char *)contextMalloc(context, (2*nBlob)+4);
if( zText ){
int i;
@@ -719,10 +718,6 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
if( zArg==0 ) return;
for(i=0, n=0; zArg[i]; i++){ if( zArg[i]=='\'' ) n++; }
if( i+n+3>SQLITE_MAX_LENGTH ){
sqlite3_result_error_toobig(context);
return;
}
z = contextMalloc(context, i+n+3);
if( z ){
z[0] = '\'';
@@ -755,10 +750,6 @@ static void hexFunc(
assert( argc==1 );
pBlob = sqlite3_value_blob(argv[0]);
n = sqlite3_value_bytes(argv[0]);
if( n*2+1>SQLITE_MAX_LENGTH ){
sqlite3_result_error_toobig(context);
return;
}
assert( pBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */
z = zHex = contextMalloc(context, n*2 + 1);
if( zHex ){
@@ -837,8 +828,9 @@ static void replaceFunc(
zOut[j++] = zStr[i];
}else{
u8 *zOld;
sqlite3 *db = sqlite3_context_db_handle(context);
nOut += nRep - nPattern;
if( nOut>=SQLITE_MAX_LENGTH ){
if( nOut>=db->aLimit[SQLITE_LIMIT_LENGTH] ){
sqlite3_result_error_toobig(context);
sqlite3_free(zOut);
return;
@@ -1179,7 +1171,9 @@ static void groupConcatStep(
pAccum = (StrAccum*)sqlite3_aggregate_context(context, sizeof(*pAccum));
if( pAccum ){
sqlite3 *db = sqlite3_context_db_handle(context);
pAccum->useMalloc = 1;
pAccum->mxAlloc = db->aLimit[SQLITE_LIMIT_LENGTH];
if( pAccum->nChar ){
if( argc==2 ){
zSep = (char*)sqlite3_value_text(argv[1]);

View File

@@ -1,158 +0,0 @@
/*
** 2007 May 7
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
*************************************************************************
**
** This file defines various limits of what SQLite can process.
**
** @(#) $Id: limits.h,v 1.9 2007/06/09 09:53:51 drh Exp $
*/
/*
** The maximum length of a TEXT or BLOB in bytes. This also
** limits the size of a row in a table or index.
**
** The hard limit is the ability of a 32-bit signed integer
** to count the size: 2^31-1 or 2147483647.
*/
#ifndef SQLITE_MAX_LENGTH
# define SQLITE_MAX_LENGTH 1000000000
#endif
/*
** This is the maximum number of
**
** * Columns in a table
** * Columns in an index
** * Columns in a view
** * Terms in the SET clause of an UPDATE statement
** * Terms in the result set of a SELECT statement
** * Terms in the GROUP BY or ORDER BY clauses of a SELECT statement.
** * Terms in the VALUES clause of an INSERT statement
**
** The hard upper limit here is 32676. Most database people will
** tell you that in a well-normalized database, you usually should
** not have more than a dozen or so columns in any table. And if
** that is the case, there is no point in having more than a few
** dozen values in any of the other situations described above.
*/
#ifndef SQLITE_MAX_COLUMN
# define SQLITE_MAX_COLUMN 2000
#endif
/*
** The maximum length of a single SQL statement in bytes.
** The hard limit here is the same as SQLITE_MAX_LENGTH.
*/
#ifndef SQLITE_MAX_SQL_LENGTH
# define SQLITE_MAX_SQL_LENGTH 1000000
#endif
/*
** The maximum depth of an expression tree. This is limited to
** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might
** want to place more severe limits on the complexity of an
** expression. A value of 0 (the default) means do not enforce
** any limitation on expression tree depth.
*/
#ifndef SQLITE_MAX_EXPR_DEPTH
# define SQLITE_MAX_EXPR_DEPTH 1000
#endif
/*
** The maximum number of terms in a compound SELECT statement.
** The code generator for compound SELECT statements does one
** level of recursion for each term. A stack overflow can result
** if the number of terms is too large. In practice, most SQL
** never has more than 3 or 4 terms. Use a value of 0 to disable
** any limit on the number of terms in a compount SELECT.
*/
#ifndef SQLITE_MAX_COMPOUND_SELECT
# define SQLITE_MAX_COMPOUND_SELECT 500
#endif
/*
** The maximum number of opcodes in a VDBE program.
** Not currently enforced.
*/
#ifndef SQLITE_MAX_VDBE_OP
# define SQLITE_MAX_VDBE_OP 25000
#endif
/*
** The maximum number of arguments to an SQL function.
*/
#ifndef SQLITE_MAX_FUNCTION_ARG
# define SQLITE_MAX_FUNCTION_ARG 100
#endif
/*
** The maximum number of in-memory pages to use for the main database
** table and for temporary tables. The SQLITE_DEFAULT_CACHE_SIZE
*/
#ifndef SQLITE_DEFAULT_CACHE_SIZE
# define SQLITE_DEFAULT_CACHE_SIZE 2000
#endif
#ifndef SQLITE_DEFAULT_TEMP_CACHE_SIZE
# define SQLITE_DEFAULT_TEMP_CACHE_SIZE 500
#endif
/*
** The maximum number of attached databases. This must be at least 2
** in order to support the main database file (0) and the file used to
** hold temporary tables (1). And it must be less than 32 because
** we use a bitmask of databases with a u32 in places (for example
** the Parse.cookieMask field).
*/
#ifndef SQLITE_MAX_ATTACHED
# define SQLITE_MAX_ATTACHED 10
#endif
/*
** The maximum value of a ?nnn wildcard that the parser will accept.
*/
#ifndef SQLITE_MAX_VARIABLE_NUMBER
# define SQLITE_MAX_VARIABLE_NUMBER 999
#endif
/*
** The default size of a database page.
*/
#ifndef SQLITE_DEFAULT_PAGE_SIZE
# define SQLITE_DEFAULT_PAGE_SIZE 1024
#endif
/* Maximum page size. The upper bound on this value is 32768. This a limit
** imposed by the necessity of storing the value in a 2-byte unsigned integer
** and the fact that the page size must be a power of 2.
*/
#ifndef SQLITE_MAX_PAGE_SIZE
# define SQLITE_MAX_PAGE_SIZE 32768
#endif
/*
** Maximum number of pages in one database file.
**
** This is really just the default value for the max_page_count pragma.
** This value can be lowered (or raised) at run-time using that the
** max_page_count macro.
*/
#ifndef SQLITE_MAX_PAGE_COUNT
# define SQLITE_MAX_PAGE_COUNT 1073741823
#endif
/*
** Maximum length (in bytes) of the pattern in a LIKE or GLOB
** operator.
*/
#ifndef SQLITE_MAX_LIKE_PATTERN_LENGTH
# define SQLITE_MAX_LIKE_PATTERN_LENGTH 50000
#endif

View File

@@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.425 2008/03/20 11:04:21 danielk1977 Exp $
** $Id: main.c,v 1.426 2008/03/20 14:03:29 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -928,6 +928,93 @@ static int createCollation(
}
/*
** This array defines hard upper bounds on limit values. The
** initializer must be kept in sync with the SQLITE_LIMIT_*
** #defines in sqlite3.h.
*/
static const aHardLimit[] = {
SQLITE_MAX_LENGTH,
SQLITE_MAX_SQL_LENGTH,
SQLITE_MAX_COLUMN,
SQLITE_MAX_EXPR_DEPTH,
SQLITE_MAX_COMPOUND_SELECT,
SQLITE_MAX_VDBE_OP,
SQLITE_MAX_FUNCTION_ARG,
SQLITE_MAX_ATTACHED,
SQLITE_MAX_PAGE_COUNT,
SQLITE_MAX_LIKE_PATTERN_LENGTH,
SQLITE_MAX_VARIABLE_NUMBER,
};
/*
** Make sure the hard limits are set to reasonable values
*/
#if SQLITE_MAX_LENGTH<100
# error SQLITE_MAX_LENGTH must be at least 100
#endif
#if SQLITE_MAX_SQL_LENGTH<100
# error SQLITE_MAX_SQL_LENGTH must be at least 100
#endif
#if SQLITE_MAX_SQL_LENGTH>SQLITE_MAX_LENGTH
# error SQLITE_MAX_SQL_LENGTH must not be greater than SQLITE_MAX_LENGTH
#endif
#if SQLITE_MAX_COLUMN<1
# error SQLITE_MAX_COLUMN must be at least 1
#endif
#if SQLITE_MAX_EXPR_DEPTH<1
# error SQLITE_MAX_EXPR_DEPTH must be at least 1
#endif
#if SQLITE_MAX_COMPOUND_SELECT<2
# error SQLITE_MAX_COMPOUND_SELECT must be at least 2
#endif
#if SQLITE_MAX_VDBE_OP<40
# error SQLITE_MAX_VDBE_OP must be at least 40
#endif
#if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>255
# error SQLITE_MAX_FUNCTION_ARG must be between 0 and 255
#endif
#if SQLITE_MAX_ATTACH<0 || SQLITE_MAX_ATTACH>30
# error SQLITE_MAX_ATTACH must be between 0 and 30
#endif
#if SQLITE_MAX_PAGE_COUNT<1
# error SQLITE_MAX_PAGE_COUNT must be at least 1
#endif
#if SQLITE_MAX_LIKE_PATTERN_LENGTH<1
# error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1
#endif
#if SQLITE_MAX_VARIABLE_NUMBER<1
# error SQLITE_MAX_VARIABLE_NUMBER must be at least 1
#endif
/*
** Change the value of a limit. Report the old value.
** If an invalid limit index is supplied, report -1.
** Make no changes but still report the old value if the
** new limit is negative.
**
** A new lower limit does not shrink existing constructs.
** It merely prevents new constructs that exceed the limit
** from forming.
*/
int sqlite3_limit(sqlite3 *db, int limitId, int newLimit){
int oldLimit;
if( limitId<0 || limitId>SQLITE_N_LIMIT ){
return -1;
}
oldLimit = db->aLimit[limitId];
if( newLimit>=0 ){
if( newLimit==0 ){
newLimit = aHardLimit[limitId];
}else if( aHardLimit[limitId]>0 && newLimit>aHardLimit[limitId] ){
newLimit = aHardLimit[limitId];
}
db->aLimit[limitId] = newLimit;
}
return oldLimit;
}
/*
** This routine does the work of opening a database on behalf of
** sqlite3_open() and sqlite3_open16(). The database filename "zFilename"
@@ -969,6 +1056,8 @@ static int openDatabase(
db->nDb = 2;
db->magic = SQLITE_MAGIC_BUSY;
db->aDb = db->aDbStatic;
assert( sizeof(db->aLimit)==sizeof(aHardLimit) );
memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit));
db->autoCommit = 1;
db->nextAutovac = -1;
db->nextPagesize = 0;

View File

@@ -13,7 +13,7 @@
** interface, and routines that contribute to loading the database schema
** from disk.
**
** $Id: prepare.c,v 1.79 2008/03/19 13:03:34 drh Exp $
** $Id: prepare.c,v 1.80 2008/03/20 14:03:29 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -538,7 +538,8 @@ static int sqlite3Prepare(
sParse.db = db;
if( nBytes>=0 && zSql[nBytes]!=0 ){
char *zSqlCopy;
if( SQLITE_MAX_SQL_LENGTH>0 && nBytes>SQLITE_MAX_SQL_LENGTH ){
int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
if( nBytes>mxLen ){
sqlite3Error(db, SQLITE_TOOBIG, "statement too long");
(void)sqlite3SafetyOff(db);
return SQLITE_TOOBIG;

View File

@@ -736,8 +736,8 @@ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
}
}else{
p->nAlloc += p->nAlloc + N + 1;
if( p->nAlloc > SQLITE_MAX_LENGTH ){
p->nAlloc = SQLITE_MAX_LENGTH;
if( p->nAlloc > p->mxAlloc ){
p->nAlloc = p->mxAlloc;
if( p->nChar+N >= p->nAlloc ){
sqlite3StrAccumReset(p);
p->tooBig = 1;
@@ -793,10 +793,11 @@ void sqlite3StrAccumReset(StrAccum *p){
/*
** Initialize a string accumulator
*/
static void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n){
static void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){
p->zText = p->zBase = zBase;
p->nChar = 0;
p->nAlloc = n;
p->mxAlloc = mx;
p->useMalloc = 1;
p->tooBig = 0;
p->mallocFailed = 0;
@@ -810,7 +811,8 @@ char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){
char *z;
char zBase[SQLITE_PRINT_BUF_SIZE];
StrAccum acc;
sqlite3StrAccumInit(&acc, zBase, sizeof(zBase));
sqlite3StrAccumInit(&acc, zBase, sizeof(zBase),
db ? db->aLimit[SQLITE_LIMIT_LENGTH] : SQLITE_MAX_LENGTH);
vxprintf(&acc, 1, zFormat, ap);
z = sqlite3StrAccumFinish(&acc);
if( acc.mallocFailed && db ){
@@ -840,7 +842,7 @@ char *sqlite3_vmprintf(const char *zFormat, va_list ap){
char *z;
char zBase[SQLITE_PRINT_BUF_SIZE];
StrAccum acc;
sqlite3StrAccumInit(&acc, zBase, sizeof(zBase));
sqlite3StrAccumInit(&acc, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
vxprintf(&acc, 0, zFormat, ap);
z = sqlite3StrAccumFinish(&acc);
return z;
@@ -873,7 +875,7 @@ char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
if( n<=0 ){
return zBuf;
}
sqlite3StrAccumInit(&acc, zBuf, n);
sqlite3StrAccumInit(&acc, zBuf, n, 0);
acc.useMalloc = 0;
va_start(ap,zFormat);
vxprintf(&acc, 0, zFormat, ap);
@@ -892,7 +894,7 @@ void sqlite3DebugPrintf(const char *zFormat, ...){
va_list ap;
StrAccum acc;
char zBuf[500];
sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf));
sqlite3StrAccumInit(&acc, zBuf, sizeof(zBuf), 0);
acc.useMalloc = 0;
va_start(ap,zFormat);
vxprintf(&acc, 0, zFormat, ap);

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.415 2008/03/04 17:45:01 mlcreech Exp $
** $Id: select.c,v 1.416 2008/03/20 14:03:29 drh Exp $
*/
#include "sqliteInt.h"
@@ -1459,10 +1459,12 @@ static int prepSelectStmt(Parse *pParse, Select *p){
sqlite3ExprListDelete(pEList);
p->pEList = pNew;
}
if( p->pEList && p->pEList->nExpr>SQLITE_MAX_COLUMN ){
#if SQLITE_MAX_COLUMN
if( p->pEList && p->pEList->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
sqlite3ErrorMsg(pParse, "too many columns in result set");
rc = SQLITE_ERROR;
}
#endif
if( db->mallocFailed ){
rc = SQLITE_NOMEM;
}
@@ -1589,11 +1591,13 @@ static int processOrderGroupBy(
ExprList *pEList;
if( pOrderBy==0 || pParse->db->mallocFailed ) return 0;
if( pOrderBy->nExpr>SQLITE_MAX_COLUMN ){
#if SQLITE_MAX_COLUMN
if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
const char *zType = isOrder ? "ORDER" : "GROUP";
sqlite3ErrorMsg(pParse, "too many terms in %s BY clause", zType);
return 1;
}
#endif
pEList = pSelect->pEList;
if( pEList==0 ){
return 0;
@@ -1656,11 +1660,13 @@ static int processCompoundOrderBy(
pOrderBy = pSelect->pOrderBy;
if( pOrderBy==0 ) return 0;
if( pOrderBy->nExpr>SQLITE_MAX_COLUMN ){
db = pParse->db;
#if SQLITE_MAX_COLUMN
if( pOrderBy->nExpr>db->aLimit[SQLITE_LIMIT_COLUMN] ){
sqlite3ErrorMsg(pParse, "too many terms in ORDER BY clause");
return 1;
}
db = pParse->db;
#endif
for(i=0; i<pOrderBy->nExpr; i++){
pOrderBy->a[i].done = 0;
}
@@ -3048,12 +3054,14 @@ int sqlite3Select(
if( p->pRightmost==0 ){
Select *pLoop, *pRight = 0;
int cnt = 0;
int mxSelect;
for(pLoop=p; pLoop; pLoop=pLoop->pPrior, cnt++){
pLoop->pRightmost = p;
pLoop->pNext = pRight;
pRight = pLoop;
}
if( SQLITE_MAX_COMPOUND_SELECT>0 && cnt>SQLITE_MAX_COMPOUND_SELECT ){
mxSelect = db->aLimit[SQLITE_LIMIT_COMPOUND_SELECT];
if( mxSelect && cnt>mxSelect ){
sqlite3ErrorMsg(pParse, "too many terms in compound SELECT");
return 1;
}
@@ -3116,7 +3124,6 @@ int sqlite3Select(
}else{
needRestoreContext = 0;
}
#if defined(SQLITE_TEST) || SQLITE_MAX_EXPR_DEPTH>0
/* Increment Parse.nHeight by the height of the largest expression
** tree refered to by this, the parent select. The child select
** may contain expression trees of at most
@@ -3125,15 +3132,12 @@ int sqlite3Select(
** an exact limit.
*/
pParse->nHeight += sqlite3SelectExprHeight(p);
#endif
sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
sqlite3Select(pParse, pItem->pSelect, &dest, p, i, &isAgg, 0);
if( db->mallocFailed ){
goto select_end;
}
#if defined(SQLITE_TEST) || SQLITE_MAX_EXPR_DEPTH>0
pParse->nHeight -= sqlite3SelectExprHeight(p);
#endif
if( needRestoreContext ){
pParse->zAuthContext = zSavedAuthContext;
}

View File

@@ -30,7 +30,7 @@
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
** @(#) $Id: sqlite.h.in,v 1.295 2008/03/20 00:32:20 drh Exp $
** @(#) $Id: sqlite.h.in,v 1.296 2008/03/20 14:03:29 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@@ -2173,6 +2173,16 @@ typedef struct sqlite3_stmt sqlite3_stmt;
** constant SQLITE_MAX_XYZ. Attempts to increase a limit above its
** hard upper bound are silently truncated.
**
** Run time limits are intended for use in applications that manage
** both their own internal database and also databases that are controlled
** by untrusted external sources. An example application might be a
** webbrowser that has its own databases for storing history and
** separate databases controlled by javascript applications downloaded
** of the internet. The internal databases can be given the
** large, default limits. Databases managed by external sources can
** be given much smaller limits designed to prevent a denial of service
** attach.
**
** This interface is currently considered experimental and is subject
** to change or removal without prior notice.
**
@@ -2180,13 +2190,13 @@ typedef struct sqlite3_stmt sqlite3_stmt;
**
** {F12763} A successful call to [sqlite3_limit(D,C,V)] where V is
** positive changes the
** limit on the size of construct C in [database connetion] D
** limit on the size of construct C in [database connection] D
** to the lessor of V and the hard upper bound on the size
** of C that is set at compile-time.
**
** {F12763} A successful call to [sqlite3_limit(D,C,V)] where V is zero
** changes the limit on the size of construct C in
** [database connetion] D to be the hard upper bound on the size
** [database connection] D to be the hard upper bound on the size
** of C that is set at compile-time.
**
** {F12766} A successful call to [sqlite3_limit(D,C,V)] where V is negative
@@ -2194,7 +2204,7 @@ typedef struct sqlite3_stmt sqlite3_stmt;
**
** {F12769} A successful call to [sqlite3_limit(D,C,V)] returns the
** value of the limit on the size of construct C in
** in [database connetion] D as it was prior to the call.
** in [database connection] D as it was prior to the call.
*/
int sqlite3_limit(sqlite3*, int id, int newVal);
@@ -2204,6 +2214,48 @@ int sqlite3_limit(sqlite3*, int id, int newVal);
**
** These constants define various aspects of a [database connection]
** that can be limited in size by calls to [sqlite3_limit()].
** The meanings of the various limits are as follows:
**
** <dl>
** <dt>SQLITE_LIMIT_LENGTH</dt>
** <dd>The maximum size of any
** string or blob or table row.<dd>
**
** <dt>SQLITE_LIMIT_SQL_LENGTH</dt>
** <dd>The maximum length of an SQL statement.</dd>
**
** <dt>SQLITE_LIMIT_COLUMN</dt>
** <dd>The maximum number of columns in a table definition or in the
** result set of a SELECT or the maximum number of columns in an index
** or in an ORDER BY or GROUP BY clause.</dd>
**
** <dt>SQLITE_LIMIT_EXPR_DEPTH</dt>
** <dd>The maximum depth of the parse tree on any expression.</dd>
**
** <dt>SQLITE_LIMIT_COMPOUND_SELECT</dt>
** <dd>The maximum number of terms in a compound SELECT statement.</dd>
**
** <dt>SQLITE_LIMIT_VDBE_OP</dt>
** <dd>The maximum number of instructions in a virtual machine program
** used to implement an SQL statement.</dd>
**
** <dt>SQLITE_LIMIT_FUNCTION_ARG</dt>
** <dd>The maximum number of arguments on a function.</dd>
**
** <dt>SQLITE_LIMIT_ATTACHED</dt>
** <dd>The maximum number of attached databases.</dd>
**
** <dt>SQLITE_LIMIT_PAGE_COUNT</dt>
** <dd>The maximum number of pages in a database.</dd>
**
** <dt>SQLITE_LIMIT_LIKE_PATTERN_LENGTH</dt>
** <dd>The maximum length of the pattern argument to the LIKE or
** GLOB operators.</dd>
**
** <dt>SQLITE_LIMIT_VARIABLE_NUMBER</dt>
** <dd>The maximum number of variables in an SQL statement that can
** be bound.</dd>
** </dl>
*/
#define SQLITE_LIMIT_LENGTH 0
#define SQLITE_LIMIT_SQL_LENGTH 1

View File

@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.676 2008/03/20 11:04:21 danielk1977 Exp $
** @(#) $Id: sqliteInt.h,v 1.677 2008/03/20 14:03:29 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@@ -21,6 +21,7 @@
** (otherwise we get an empty default).
*/
#include "config.h"
#include "sqliteLimit.h"
/* Needed for various definitions... */
#define _GNU_SOURCE
@@ -91,51 +92,6 @@
#endif
#include "sqliteLimit.h"
/*
** For testing purposes, the various size limit constants are really
** variables that we can modify in the testfixture.
*/
#ifdef SQLITE_TEST
#undef SQLITE_MAX_LENGTH
#undef SQLITE_MAX_COLUMN
#undef SQLITE_MAX_SQL_LENGTH
#undef SQLITE_MAX_EXPR_DEPTH
#undef SQLITE_MAX_COMPOUND_SELECT
#undef SQLITE_MAX_VDBE_OP
#undef SQLITE_MAX_FUNCTION_ARG
#undef SQLITE_MAX_VARIABLE_NUMBER
#undef SQLITE_MAX_PAGE_SIZE
#undef SQLITE_MAX_PAGE_COUNT
#undef SQLITE_MAX_LIKE_PATTERN_LENGTH
#define SQLITE_MAX_LENGTH sqlite3MAX_LENGTH
#define SQLITE_MAX_COLUMN sqlite3MAX_COLUMN
#define SQLITE_MAX_SQL_LENGTH sqlite3MAX_SQL_LENGTH
#define SQLITE_MAX_EXPR_DEPTH sqlite3MAX_EXPR_DEPTH
#define SQLITE_MAX_COMPOUND_SELECT sqlite3MAX_COMPOUND_SELECT
#define SQLITE_MAX_VDBE_OP sqlite3MAX_VDBE_OP
#define SQLITE_MAX_FUNCTION_ARG sqlite3MAX_FUNCTION_ARG
#define SQLITE_MAX_VARIABLE_NUMBER sqlite3MAX_VARIABLE_NUMBER
#define SQLITE_MAX_PAGE_SIZE sqlite3MAX_PAGE_SIZE
#define SQLITE_MAX_PAGE_COUNT sqlite3MAX_PAGE_COUNT
#define SQLITE_MAX_LIKE_PATTERN_LENGTH sqlite3MAX_LIKE_PATTERN_LENGTH
extern int sqlite3MAX_LENGTH;
extern int sqlite3MAX_COLUMN;
extern int sqlite3MAX_SQL_LENGTH;
extern int sqlite3MAX_EXPR_DEPTH;
extern int sqlite3MAX_COMPOUND_SELECT;
extern int sqlite3MAX_VDBE_OP;
extern int sqlite3MAX_FUNCTION_ARG;
extern int sqlite3MAX_VARIABLE_NUMBER;
extern int sqlite3MAX_PAGE_SIZE;
extern int sqlite3MAX_PAGE_COUNT;
extern int sqlite3MAX_LIKE_PATTERN_LENGTH;
#endif
/*
** The SQLITE_THREADSAFE macro must be defined as either 0 or 1.
** Older versions of SQLite used an optional THREADSAFE macro.
@@ -1721,6 +1677,7 @@ struct StrAccum {
char *zText; /* The string collected so far */
int nChar; /* Length of the string so far */
int nAlloc; /* Amount of space allocated in zText */
int mxAlloc; /* Maximum allowed string length */
u8 mallocFailed; /* Becomes true if any memory allocation fails */
u8 useMalloc; /* True if zText is enlargable using realloc */
u8 tooBig; /* Becomes true if string size exceeds limits */

View File

@@ -12,7 +12,7 @@
**
** This file defines various limits of what SQLite can process.
**
** @(#) $Id: sqliteLimit.h,v 1.6 2007/12/17 16:20:07 drh Exp $
** @(#) $Id: sqliteLimit.h,v 1.7 2008/03/20 14:03:29 drh Exp $
*/
/*
@@ -49,18 +49,24 @@
/*
** The maximum length of a single SQL statement in bytes.
** A value of zero means there is no limit.
**
** It used to be the case that setting this value to zero would
** turn the limit off. That is no longer true. It is not possible
** to turn this limit off.
*/
#ifndef SQLITE_MAX_SQL_LENGTH
# define SQLITE_MAX_SQL_LENGTH 0
# define SQLITE_MAX_SQL_LENGTH 1000000000
#endif
/*
** The maximum depth of an expression tree. This is limited to
** some extent by SQLITE_MAX_SQL_LENGTH. But sometime you might
** want to place more severe limits on the complexity of an
** expression. A value of 0 (the default) means do not enforce
** any limitation on expression tree depth.
** expression.
**
** A value of 0 used to mean that the limit was not enforced.
** But that is no longer true. The limit is now strictly enforced
** at all times.
*/
#ifndef SQLITE_MAX_EXPR_DEPTH
# define SQLITE_MAX_EXPR_DEPTH 1000

View File

@@ -16,23 +16,11 @@
** The focus of this file is providing the TCL testing layer
** access to compile-time constants.
**
** $Id: test_config.c,v 1.21 2008/03/19 14:15:35 drh Exp $
** $Id: test_config.c,v 1.22 2008/03/20 14:03:29 drh Exp $
*/
#include "sqliteLimit.h"
int sqlite3MAX_LENGTH = SQLITE_MAX_LENGTH;
int sqlite3MAX_COLUMN = SQLITE_MAX_COLUMN;
int sqlite3MAX_SQL_LENGTH = SQLITE_MAX_SQL_LENGTH;
int sqlite3MAX_EXPR_DEPTH = SQLITE_MAX_EXPR_DEPTH;
int sqlite3MAX_COMPOUND_SELECT = SQLITE_MAX_COMPOUND_SELECT;
int sqlite3MAX_VDBE_OP = SQLITE_MAX_VDBE_OP;
int sqlite3MAX_FUNCTION_ARG = SQLITE_MAX_FUNCTION_ARG;
int sqlite3MAX_VARIABLE_NUMBER = SQLITE_MAX_VARIABLE_NUMBER;
int sqlite3MAX_PAGE_SIZE = SQLITE_MAX_PAGE_SIZE;
int sqlite3MAX_PAGE_COUNT = SQLITE_MAX_PAGE_COUNT;
int sqlite3MAX_LIKE_PATTERN_LENGTH = SQLITE_MAX_LIKE_PATTERN_LENGTH;
#include "sqliteInt.h"
#include "tcl.h"
#include <stdlib.h>
@@ -425,8 +413,10 @@ Tcl_SetVar2(interp, "sqlite_options", "long_double",
Tcl_SetVar2(interp, "sqlite_options", "vtab", "1", TCL_GLOBAL_ONLY);
#endif
#define LINKVAR(x) \
Tcl_LinkVar(interp, "SQLITE_" #x, (char *)&(sqlite3 ## x), TCL_LINK_INT)
#define LINKVAR(x) { \
static const int cv_ ## x = SQLITE_ ## x; \
Tcl_LinkVar(interp, "SQLITE_" #x, (char *)&(cv_ ## x), \
TCL_LINK_INT | TCL_LINK_READ_ONLY); }
LINKVAR( MAX_LENGTH );
LINKVAR( MAX_COLUMN );
@@ -439,38 +429,17 @@ Tcl_SetVar2(interp, "sqlite_options", "long_double",
LINKVAR( MAX_PAGE_SIZE );
LINKVAR( MAX_PAGE_COUNT );
LINKVAR( MAX_LIKE_PATTERN_LENGTH );
LINKVAR( DEFAULT_TEMP_CACHE_SIZE );
LINKVAR( DEFAULT_CACHE_SIZE );
LINKVAR( DEFAULT_PAGE_SIZE );
LINKVAR( DEFAULT_FILE_FORMAT );
LINKVAR( MAX_ATTACHED );
{
static int sqlite_default_temp_cache_size = SQLITE_DEFAULT_TEMP_CACHE_SIZE;
Tcl_LinkVar(interp, "SQLITE_DEFAULT_TEMP_CACHE_SIZE",
(char*)&sqlite_default_temp_cache_size,
static const int cv_TEMP_STORE = TEMP_STORE;
Tcl_LinkVar(interp, "TEMP_STORE", (char *)&(cv_TEMP_STORE),
TCL_LINK_INT | TCL_LINK_READ_ONLY);
}
{
static int sqlite_default_cache_size = SQLITE_DEFAULT_CACHE_SIZE;
Tcl_LinkVar(interp, "SQLITE_DEFAULT_CACHE_SIZE",
(char*)&sqlite_default_cache_size, TCL_LINK_INT|TCL_LINK_READ_ONLY);
}
{
static int sqlite_default_page_size = SQLITE_DEFAULT_PAGE_SIZE;
Tcl_LinkVar(interp, "SQLITE_DEFAULT_PAGE_SIZE",
(char*)&sqlite_default_page_size, TCL_LINK_INT|TCL_LINK_READ_ONLY);
}
{
static int temp_store = TEMP_STORE;
Tcl_LinkVar(interp, "TEMP_STORE",
(char*)&temp_store, TCL_LINK_INT|TCL_LINK_READ_ONLY);
}
{
static int sqlite_default_file_format = SQLITE_DEFAULT_FILE_FORMAT;
Tcl_LinkVar(interp, "SQLITE_DEFAULT_FILE_FORMAT",
(char*)&sqlite_default_file_format, TCL_LINK_INT|TCL_LINK_READ_ONLY);
}
{
static int sqlite_max_attached = SQLITE_MAX_ATTACHED;
Tcl_LinkVar(interp, "SQLITE_MAX_ATTACHED",
(char*)&sqlite_max_attached, TCL_LINK_INT|TCL_LINK_READ_ONLY);
}
}

View File

@@ -15,7 +15,7 @@
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
**
** $Id: tokenize.c,v 1.138 2008/01/22 23:37:10 drh Exp $
** $Id: tokenize.c,v 1.139 2008/03/20 14:03:29 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -388,6 +388,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
int tokenType;
int lastTokenParsed = -1;
sqlite3 *db = pParse->db;
int mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
if( db->activeVdbeCnt==0 ){
db->u1.isInterrupted = 0;
@@ -413,7 +414,7 @@ int sqlite3RunParser(Parse *pParse, const char *zSql, char **pzErrMsg){
assert( pParse->sLastToken.dyn==0 );
pParse->sLastToken.n = getToken((unsigned char*)&zSql[i],&tokenType);
i += pParse->sLastToken.n;
if( SQLITE_MAX_SQL_LENGTH>0 && i>SQLITE_MAX_SQL_LENGTH ){
if( i>mxSqlLen ){
pParse->rc = SQLITE_TOOBIG;
break;
}

View File

@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.713 2008/03/19 21:45:51 drh Exp $
** $Id: vdbe.c,v 1.714 2008/03/20 14:03:29 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -832,14 +832,14 @@ case OP_String8: { /* same as TK_STRING, out2-prerelease */
pOp->p4type = P4_DYNAMIC;
pOp->p4.z = pOut->z;
pOp->p1 = pOut->n;
if( pOp->p1>SQLITE_MAX_LENGTH ){
if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
goto too_big;
}
UPDATE_MAX_BLOBSIZE(pOut);
break;
}
#endif
if( pOp->p1>SQLITE_MAX_LENGTH ){
if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
goto too_big;
}
/* Fall through to the next case, OP_String */
@@ -1020,7 +1020,7 @@ case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */
ExpandBlob(pIn2);
Stringify(pIn2, encoding);
nByte = pIn1->n + pIn2->n;
if( nByte>SQLITE_MAX_LENGTH ){
if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
goto too_big;
}
MemSetTypeFlag(pOut, MEM_Str);
@@ -1884,7 +1884,7 @@ case OP_Column: {
assert( pDest->flags&MEM_Null );
goto op_column_out;
}
if( payloadSize>SQLITE_MAX_LENGTH ){
if( payloadSize>db->aLimit[SQLITE_LIMIT_LENGTH] ){
goto too_big;
}
@@ -2137,7 +2137,7 @@ case OP_MakeRecord: {
nHdr++;
}
nByte = nHdr+nData-nZero;
if( nByte>SQLITE_MAX_LENGTH ){
if( nByte>db->aLimit[SQLITE_LIMIT_LENGTH] ){
goto too_big;
}
@@ -3394,13 +3394,13 @@ case OP_RowData: {
i64 n64;
assert( !pC->isTable );
sqlite3BtreeKeySize(pCrsr, &n64);
if( n64>SQLITE_MAX_LENGTH ){
if( n64>db->aLimit[SQLITE_LIMIT_LENGTH] ){
goto too_big;
}
n = n64;
}else{
sqlite3BtreeDataSize(pCrsr, &n);
if( n>SQLITE_MAX_LENGTH ){
if( n>db->aLimit[SQLITE_LIMIT_LENGTH] ){
goto too_big;
}
}

View File

@@ -238,7 +238,9 @@ void sqlite3_result_error_code(sqlite3_context *pCtx, int errCode){
/* Force an SQLITE_TOOBIG error. */
void sqlite3_result_error_toobig(sqlite3_context *pCtx){
assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
sqlite3VdbeMemSetZeroBlob(&pCtx->s, SQLITE_MAX_LENGTH+1);
pCtx->isError = SQLITE_TOOBIG;
sqlite3VdbeMemSetStr(&pCtx->s, "string or blob too big", -1,
SQLITE_UTF8, SQLITE_STATIC);
}
/* An SQLITE_NOMEM error. */

View File

@@ -509,7 +509,7 @@ int sqlite3VdbeMemTooBig(Mem *p){
if( p->flags & MEM_Zero ){
n += p->u.i;
}
return n>SQLITE_MAX_LENGTH;
return n>p->db->aLimit[SQLITE_LIMIT_LENGTH];
}
return 0;
}

View File

@@ -11,7 +11,7 @@
# This file implements regression tests for SQLite library. The
# focus of this file is testing built-in functions.
#
# $Id: func.test,v 1.73 2008/03/19 16:35:24 drh Exp $
# $Id: func.test,v 1.74 2008/03/20 14:03:29 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@@ -337,7 +337,6 @@ if {$encoding=="UTF-16le"} {
do_test func-9.12-utf16le {
execsql {SELECT hex(replace('abcdefg','','12'))}
} {{}}
breakpoint
do_test func-9.13-utf16le {
execsql {SELECT hex(replace('aabcdefg','a','aaa'))}
} {610061006100610061006100620063006400650066006700}
@@ -348,7 +347,6 @@ if {$encoding=="UTF-16le"} {
do_test func-9.12-utf8 {
execsql {SELECT hex(replace('abcdefg','','12'))}
} {{}}
breakpoint
do_test func-9.13-utf8 {
execsql {SELECT hex(replace('aabcdefg','a','aaa'))}
} {616161616161626364656667}