aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2007-05-08 15:15:02 +0000
committerdrh <drh@noemail.net>2007-05-08 15:15:02 +0000
commita0206bc81c7b709e5737eadcfbbcbcf11d49e0c1 (patch)
tree47df734ba61443d5c01eab60636cc682617d2de0 /src
parentf8e632b630c57bc61ba6b8ddfdc6ad0ee56d03c6 (diff)
downloadsqlite-a0206bc81c7b709e5737eadcfbbcbcf11d49e0c1.tar.gz
sqlite-a0206bc81c7b709e5737eadcfbbcbcf11d49e0c1.zip
Introduce the (experimental) sqlite3_result_error_toobig() API that
function implementations can use to signal SQLite that the function result is too big to represent. (CVS 3949) FossilOrigin-Name: 17c4235c492f746867c1d2b8621043b93f8aa10e
Diffstat (limited to 'src')
-rw-r--r--src/date.c8
-rw-r--r--src/func.c12
-rw-r--r--src/limits.h2
-rw-r--r--src/sqlite.h.in3
-rw-r--r--src/vdbeapi.c5
5 files changed, 20 insertions, 10 deletions
diff --git a/src/date.c b/src/date.c
index 0f0522604..f1230d6c5 100644
--- a/src/date.c
+++ b/src/date.c
@@ -16,7 +16,7 @@
** sqlite3RegisterDateTimeFunctions() found at the bottom of the file.
** All other code has file scope.
**
-** $Id: date.c,v 1.64 2007/05/04 13:15:56 drh Exp $
+** $Id: date.c,v 1.65 2007/05/08 15:15:02 drh Exp $
**
** NOTES:
**
@@ -774,7 +774,8 @@ static void strftimeFunc(
sqlite3_value **argv
){
DateTime x;
- int n, i, j;
+ u64 n;
+ int i, j;
char *z;
const char *zFmt = (const char*)sqlite3_value_text(argv[0]);
char zBuf[100];
@@ -814,6 +815,9 @@ static void strftimeFunc(
}
if( n<sizeof(zBuf) ){
z = zBuf;
+ }else if( n>SQLITE_MAX_LENGTH ){
+ sqlite3_result_error_toobig(context);
+ return;
}else{
z = sqliteMalloc( n );
if( z==0 ) return;
diff --git a/src/func.c b/src/func.c
index b6ac068a2..6c3cfdb78 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.148 2007/05/08 14:39:04 danielk1977 Exp $
+** $Id: func.c,v 1.149 2007/05/08 15:15:02 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@@ -301,7 +301,7 @@ static void randomBlob(
n = 1;
}
if( n>SQLITE_MAX_LENGTH ){
- sqlite3_result_error(context, "randomblob() too large", -1);
+ sqlite3_result_error_toobig(context);
return;
}
p = sqliteMalloc(n);
@@ -624,7 +624,7 @@ static void quoteFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
char const *zBlob = sqlite3_value_blob(argv[0]);
if( 2*nBlob+4>SQLITE_MAX_LENGTH ){
- sqlite3_result_error(context, "BLOB too big to quote", -1);
+ sqlite3_result_error_toobig(context);
return;
}
zText = (char *)sqliteMalloc((2*nBlob)+4);
@@ -654,7 +654,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++; }
if( i+n+3>SQLITE_MAX_LENGTH ){
- sqlite3_result_error(context, "string too big to quote", -1);
+ sqlite3_result_error_toobig(context);
return;
}
z = sqliteMalloc( i+n+3 );
@@ -689,7 +689,7 @@ static void hexFunc(
assert( argc==1 );
n = sqlite3_value_bytes(argv[0]);
if( n*2+1>SQLITE_MAX_LENGTH ){
- sqlite3_result_error(context, "BLOB too big to convert to hex", -1);
+ sqlite3_result_error_toobig(context);
return;
}
pBlob = sqlite3_value_blob(argv[0]);
@@ -764,7 +764,7 @@ static void replaceFunc(
zOut[j++] = zStr[i];
}else{
if( (j+nRep+loopLimit-i)>SQLITE_MAX_LENGTH ){
- sqlite3_result_error(context, "replace() is too large", -1);
+ sqlite3_result_error_toobig(context);
sqlite3_free(zOut);
return;
}
diff --git a/src/limits.h b/src/limits.h
index e85ec0dae..6b4c9f6f6 100644
--- a/src/limits.h
+++ b/src/limits.h
@@ -12,7 +12,7 @@
**
** This file defines various limits of what SQLite can process.
**
-** @(#) $Id: limits.h,v 1.3 2007/05/08 14:51:37 drh Exp $
+** @(#) $Id: limits.h,v 1.4 2007/05/08 15:15:02 drh Exp $
*/
/*
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 2a7c4e973..42a39c3a2 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -12,7 +12,7 @@
** This header file defines the interface that the SQLite library
** presents to client programs.
**
-** @(#) $Id: sqlite.h.in,v 1.207 2007/05/08 01:08:49 drh Exp $
+** @(#) $Id: sqlite.h.in,v 1.208 2007/05/08 15:15:02 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@@ -1224,6 +1224,7 @@ void sqlite3_result_text16le(sqlite3_context*, const void*, int,void(*)(void*));
void sqlite3_result_text16be(sqlite3_context*, const void*, int,void(*)(void*));
void sqlite3_result_value(sqlite3_context*, sqlite3_value*);
void sqlite3_result_zeroblob(sqlite3_context*, int n);
+void sqlite3_result_error_toobig(sqlite3_context*);
/*
** These are the allowed values for the eTextRep argument to
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index 4e121059f..7ff9ba297 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -156,6 +156,11 @@ void sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){
sqlite3VdbeMemSetZeroBlob(&pCtx->s, n);
}
+/* Force an SQLITE_TOOBIG error. */
+void sqlite3_result_error_toobig(sqlite3_context *pCtx){
+ sqlite3VdbeMemSetZeroBlob(&pCtx->s, SQLITE_MAX_LENGTH+1);
+}
+
/*
** Execute the statement pStmt, either until a row of data is ready, the