aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/expr.c6
-rw-r--r--src/func.c18
-rw-r--r--src/main.c8
-rw-r--r--src/parse.y8
-rw-r--r--src/printf.c9
-rw-r--r--src/sqlite.h.in10
-rw-r--r--src/sqliteInt.h4
-rw-r--r--src/test1.c59
8 files changed, 87 insertions, 35 deletions
diff --git a/src/expr.c b/src/expr.c
index 47f10fc3b..7ee47a4e7 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -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.355 2008/03/20 14:03:29 drh Exp $
+** $Id: expr.c,v 1.356 2008/03/20 16:30:18 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -696,10 +696,10 @@ no_mem:
void sqlite3ExprListCheckLength(
Parse *pParse,
ExprList *pEList,
- int iLimit,
const char *zObject
){
- if( pEList && pEList->nExpr>iLimit ){
+ int mx = pParse->db->aLimit[SQLITE_LIMIT_COLUMN];
+ if( pEList && pEList->nExpr>mx ){
sqlite3ErrorMsg(pParse, "too many columns in %s", zObject);
}
}
diff --git a/src/func.c b/src/func.c
index ebb553947..1c1bbd7e2 100644
--- a/src/func.c
+++ b/src/func.c
@@ -16,7 +16,7 @@
** sqliteRegisterBuildinFunctions() found at the bottom of the file.
** All other code has file scope.
**
-** $Id: func.c,v 1.190 2008/03/20 14:03:29 drh Exp $
+** $Id: func.c,v 1.191 2008/03/20 16:30:18 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -243,7 +243,7 @@ static void roundFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
** allocation fails, call sqlite3_result_error_nomem() to notify
** the database handle that malloc() has failed.
*/
-static void *contextMalloc(sqlite3_context *context, int nByte){
+static void *contextMalloc(sqlite3_context *context, i64 nByte){
char *z;
if( nByte>sqlite3_context_db_handle(context)->aLimit[SQLITE_LIMIT_LENGTH] ){
sqlite3_result_error_toobig(context);
@@ -270,7 +270,7 @@ static void upperFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
/* Verify that the call to _bytes() does not invalidate the _text() pointer */
assert( z2==(char*)sqlite3_value_text(argv[0]) );
if( z2 ){
- z1 = contextMalloc(context, n+1);
+ z1 = contextMalloc(context, ((i64)n)+1);
if( z1 ){
memcpy(z1, z2, n+1);
for(i=0; z1[i]; i++){
@@ -290,7 +290,7 @@ static void lowerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
/* Verify that the call to _bytes() does not invalidate the _text() pointer */
assert( z2==(char*)sqlite3_value_text(argv[0]) );
if( z2 ){
- z1 = contextMalloc(context, n+1);
+ z1 = contextMalloc(context, ((i64)n)+1);
if( z1 ){
memcpy(z1, z2, n+1);
for(i=0; z1[i]; i++){
@@ -694,7 +694,7 @@ 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 */
- zText = (char *)contextMalloc(context, (2*nBlob)+4);
+ zText = (char *)contextMalloc(context, (2*(i64)nBlob)+4);
if( zText ){
int i;
for(i=0; i<nBlob; i++){
@@ -718,7 +718,7 @@ 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++; }
- z = contextMalloc(context, i+n+3);
+ z = contextMalloc(context, ((i64)i)+((i64)n)+3);
if( z ){
z[0] = '\'';
for(i=0, j=1; zArg[i]; i++){
@@ -751,7 +751,7 @@ static void hexFunc(
pBlob = sqlite3_value_blob(argv[0]);
n = sqlite3_value_bytes(argv[0]);
assert( pBlob==sqlite3_value_blob(argv[0]) ); /* No encoding change */
- z = zHex = contextMalloc(context, n*2 + 1);
+ z = zHex = contextMalloc(context, ((i64)n)*2 + 1);
if( zHex ){
for(i=0; i<n; i++, pBlob++){
unsigned char c = *pBlob;
@@ -818,7 +818,7 @@ static void replaceFunc(
assert( zRep==sqlite3_value_text(argv[2]) );
nOut = nStr + 1;
assert( nOut<SQLITE_MAX_LENGTH );
- zOut = contextMalloc(context, (int)nOut);
+ zOut = contextMalloc(context, (i64)nOut);
if( zOut==0 ){
return;
}
@@ -895,7 +895,7 @@ static void trimFunc(
SQLITE_SKIP_UTF8(z);
}
if( nChar>0 ){
- azChar = contextMalloc(context, nChar*(sizeof(char*)+1));
+ azChar = contextMalloc(context, ((i64)nChar)*(sizeof(char*)+1));
if( azChar==0 ){
return;
}
diff --git a/src/main.c b/src/main.c
index 609cf86fb..c472ba320 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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.426 2008/03/20 14:03:29 drh Exp $
+** $Id: main.c,v 1.427 2008/03/20 16:30:18 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -933,7 +933,7 @@ static int createCollation(
** initializer must be kept in sync with the SQLITE_LIMIT_*
** #defines in sqlite3.h.
*/
-static const aHardLimit[] = {
+static const int aHardLimit[] = {
SQLITE_MAX_LENGTH,
SQLITE_MAX_SQL_LENGTH,
SQLITE_MAX_COLUMN,
@@ -942,7 +942,6 @@ static const aHardLimit[] = {
SQLITE_MAX_VDBE_OP,
SQLITE_MAX_FUNCTION_ARG,
SQLITE_MAX_ATTACHED,
- SQLITE_MAX_PAGE_COUNT,
SQLITE_MAX_LIKE_PATTERN_LENGTH,
SQLITE_MAX_VARIABLE_NUMBER,
};
@@ -977,9 +976,6 @@ static const aHardLimit[] = {
#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
diff --git a/src/parse.y b/src/parse.y
index 776634195..fee497f4a 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -14,7 +14,7 @@
** the parser. Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
-** @(#) $Id: parse.y,v 1.240 2008/01/22 23:37:10 drh Exp $
+** @(#) $Id: parse.y,v 1.241 2008/03/20 16:30:18 drh Exp $
*/
// All token codes are small integers with #defines that begin with "TK_"
@@ -573,7 +573,7 @@ where_opt(A) ::= WHERE expr(X). {A = X;}
////////////////////////// The UPDATE command ////////////////////////////////
//
cmd ::= UPDATE orconf(R) fullname(X) SET setlist(Y) where_opt(Z). {
- sqlite3ExprListCheckLength(pParse,Y,SQLITE_MAX_COLUMN,"set list");
+ sqlite3ExprListCheckLength(pParse,Y,"set list");
sqlite3Update(pParse,X,Y,Z,R);
}
@@ -896,7 +896,7 @@ idxlist(A) ::= idxlist(X) COMMA idxitem(Y) collate(C) sortorder(Z). {
sqlite3ExprSetColl(pParse, p, &C);
}
A = sqlite3ExprListAppend(pParse,X, p, &Y);
- sqlite3ExprListCheckLength(pParse, A, SQLITE_MAX_COLUMN, "index");
+ sqlite3ExprListCheckLength(pParse, A, "index");
if( A ) A->a[A->nExpr-1].sortOrder = Z;
}
idxlist(A) ::= idxitem(Y) collate(C) sortorder(Z). {
@@ -906,7 +906,7 @@ idxlist(A) ::= idxitem(Y) collate(C) sortorder(Z). {
sqlite3ExprSetColl(pParse, p, &C);
}
A = sqlite3ExprListAppend(pParse,0, p, &Y);
- sqlite3ExprListCheckLength(pParse, A, SQLITE_MAX_COLUMN, "index");
+ sqlite3ExprListCheckLength(pParse, A, "index");
if( A ) A->a[A->nExpr-1].sortOrder = Z;
}
idxitem(A) ::= nm(X). {A = X;}
diff --git a/src/printf.c b/src/printf.c
index 2cd02a851..4e7525798 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -735,14 +735,17 @@ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
return;
}
}else{
- p->nAlloc += p->nAlloc + N + 1;
- if( p->nAlloc > p->mxAlloc ){
+ i64 szNew = p->nAlloc;
+ szNew += N + 1;
+ if( szNew > p->mxAlloc ){
p->nAlloc = p->mxAlloc;
- if( p->nChar+N >= p->nAlloc ){
+ if( ((i64)p->nChar)+((i64)N) >= p->nAlloc ){
sqlite3StrAccumReset(p);
p->tooBig = 1;
return;
}
+ }else{
+ p->nAlloc = szNew;
}
zNew = sqlite3_malloc( p->nAlloc );
if( zNew ){
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 21a968e6d..6032cf8e5 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -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.296 2008/03/20 14:03:29 drh Exp $
+** @(#) $Id: sqlite.h.in,v 1.297 2008/03/20 16:30:18 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@@ -2245,9 +2245,6 @@ int sqlite3_limit(sqlite3*, int id, int newVal);
** <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>
@@ -2265,9 +2262,8 @@ int sqlite3_limit(sqlite3*, int id, int newVal);
#define SQLITE_LIMIT_VDBE_OP 5
#define SQLITE_LIMIT_FUNCTION_ARG 6
#define SQLITE_LIMIT_ATTACHED 7
-#define SQLITE_LIMIT_PAGE_COUNT 8
-#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 9
-#define SQLITE_LIMIT_VARIABLE_NUMBER 10
+#define SQLITE_LIMIT_LIKE_PATTERN_LENGTH 8
+#define SQLITE_LIMIT_VARIABLE_NUMBER 9
/*
** CAPI3REF: Compiling An SQL Statement {F13010}
diff --git a/src/sqliteInt.h b/src/sqliteInt.h
index 66a7aebd7..8c7173b2f 100644
--- a/src/sqliteInt.h
+++ b/src/sqliteInt.h
@@ -11,7 +11,7 @@
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.677 2008/03/20 14:03:29 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.678 2008/03/20 16:30:18 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
@@ -2069,7 +2069,7 @@ int sqlite3VtabBegin(sqlite3 *, sqlite3_vtab *);
FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
void sqlite3InvalidFunction(sqlite3_context*,int,sqlite3_value**);
int sqlite3Reprepare(Vdbe*);
-void sqlite3ExprListCheckLength(Parse*, ExprList*, int, const char*);
+void sqlite3ExprListCheckLength(Parse*, ExprList*, const char*);
CollSeq *sqlite3BinaryCompareCollSeq(Parse *, Expr *, Expr *);
diff --git a/src/test1.c b/src/test1.c
index 9319eb0b9..3f718aef6 100644
--- a/src/test1.c
+++ b/src/test1.c
@@ -13,7 +13,7 @@
** is not included in the SQLite library. It is used for automated
** testing of the SQLite library.
**
-** $Id: test1.c,v 1.293 2008/03/19 14:15:35 drh Exp $
+** $Id: test1.c,v 1.294 2008/03/20 16:30:18 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
@@ -4321,6 +4321,62 @@ static int file_control_test(
}
/*
+** tclcmd: sqlite3_limit DB ID VALUE
+**
+** This TCL command runs the sqlite3_limit interface and
+** verifies correct operation of the same.
+*/
+static int test_limit(
+ ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
+ Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
+ int objc, /* Number of arguments */
+ Tcl_Obj *CONST objv[] /* Command arguments */
+){
+ sqlite3 *db;
+ int rc;
+ static const struct {
+ char *zName;
+ int id;
+ } aId[] = {
+ { "SQLITE_LIMIT_LENGTH", SQLITE_LIMIT_LENGTH },
+ { "SQLITE_LIMIT_SQL_LENGTH", SQLITE_LIMIT_SQL_LENGTH },
+ { "SQLITE_LIMIT_COLUMN", SQLITE_LIMIT_COLUMN },
+ { "SQLITE_LIMIT_EXPR_DEPTH", SQLITE_LIMIT_EXPR_DEPTH },
+ { "SQLITE_LIMIT_COMPOUND_SELECT", SQLITE_LIMIT_COMPOUND_SELECT },
+ { "SQLITE_LIMIT_VDBE_OP", SQLITE_LIMIT_VDBE_OP },
+ { "SQLITE_LIMIT_FUNCTION_ARG", SQLITE_LIMIT_FUNCTION_ARG },
+ { "SQLITE_LIMIT_ATTACHED", SQLITE_LIMIT_ATTACHED },
+ { "SQLITE_LIMIT_LIKE_PATTERN_LENGTH", SQLITE_LIMIT_LIKE_PATTERN_LENGTH },
+ { "SQLITE_LIMIT_VARIABLE_NUMBER", SQLITE_LIMIT_VARIABLE_NUMBER },
+ };
+ int i, id;
+ int val;
+ const char *zId;
+
+ if( objc!=4 ){
+ Tcl_AppendResult(interp, "wrong # args: should be \"",
+ Tcl_GetStringFromObj(objv[0], 0), " DB ID VALUE", 0);
+ return TCL_ERROR;
+ }
+ if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
+ zId = Tcl_GetString(objv[2]);
+ for(i=0; i<sizeof(aId)/sizeof(aId[0]); i++){
+ if( strcmp(zId, aId[i].zName)==0 ){
+ id = aId[i].id;
+ break;
+ }
+ }
+ if( i>=sizeof(aId)/sizeof(aId[0]) ){
+ Tcl_AppendResult(interp, "unknown limit type: ", zId, (char*)0);
+ return TCL_ERROR;
+ }
+ if( Tcl_GetIntFromObj(interp, objv[3], &val) ) return TCL_ERROR;
+ rc = sqlite3_limit(db, id, val);
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(rc));
+ return TCL_OK;
+}
+
+/*
** tclcmd: save_prng_state
*/
static int save_prng_state(
@@ -4456,6 +4512,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "sqlite3_load_extension", test_load_extension, 0},
{ "sqlite3_enable_load_extension", test_enable_load, 0},
{ "sqlite3_extended_result_codes", test_extended_result_codes, 0},
+ { "sqlite3_limit", test_limit, 0},
{ "save_prng_state", save_prng_state, 0 },
{ "restore_prng_state", restore_prng_state, 0 },