/*
** 2008 March 19
**
** 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.
**
*************************************************************************
** Code for testing all sorts of SQLite interfaces. This code
** implements new SQL functions used by the test scripts.
*/
#include "sqlite3.h"
#include "tclsqlite.h"
#include
#include
#include
#include "sqliteInt.h"
#include "vdbeInt.h"
/*
** Allocate nByte bytes of space using sqlite3_malloc(). If the
** allocation fails, call sqlite3_result_error_nomem() to notify
** the database handle that malloc() has failed.
*/
static void *testContextMalloc(sqlite3_context *context, int nByte){
char *z = sqlite3_malloc(nByte);
if( !z && nByte>0 ){
sqlite3_result_error_nomem(context);
}
return z;
}
/*
** This function generates a string of random characters. Used for
** generating test data.
*/
static void randStr(sqlite3_context *context, int argc, sqlite3_value **argv){
static const unsigned char zSrc[] =
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789"
".-!,:*^+=_|?/ ";
int iMin, iMax, n, r, i;
unsigned char zBuf[1000];
/* It used to be possible to call randstr() with any number of arguments,
** but now it is registered with SQLite as requiring exactly 2.
*/
assert(argc==2);
iMin = sqlite3_value_int(argv[0]);
if( iMin=sizeof(zBuf) ) iMin = sizeof(zBuf)-1;
iMax = sqlite3_value_int(argv[1]);
if( iMax=sizeof(zBuf) ) iMax = sizeof(zBuf)-1;
n = iMin;
if( iMax>iMin ){
sqlite3_randomness(sizeof(r), &r);
r &= 0x7fffffff;
n += r%(iMax + 1 - iMin);
}
assert( n