-C The\sFOR\sEACH\sSTATEMENT\sclause\sin\sa\strigger\sis\snow\sa\ssyntax\serror.\s\sIt\sused\nto\sbe\ssilently\signored.\s\sSTATEMENT\sis\sno\slonger\sa\skeyword.\s(CVS\s3821)
-D 2007-04-06T11:26:00
-F Makefile.in a9bd493360a2b17e5214b69d8c32dd6cdaceaf55
+C Binary\sfile\sI/O\sinfrastructure\sadded\sand\sused\sto\sincrease\stest\scoverage\nfor\sdetection\sof\scorrupt\sdatabase\sfiles.\s(CVS\s3822)
+D 2007-04-06T15:02:13
+F Makefile.in 8cab54f7c9f5af8f22fd97ddf1ecfd1e1860de62
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
F VERSION ebbd5a08dc4d7f984b7e0f2dd3d5d78001119117
F ext/fts2/fts2_tokenizer1.c 6067f2f710bc7e91c0688b7b11be1027777553e0
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
F ltmain.sh 56abb507100ed2d4261f6dd1653dec3cf4066387
-F main.mk 2c20b3501860b36115c477a95a7f9355c755cf3b
+F main.mk dd14eeac33ac5e6c062f43e79876948f1d64908b
F mkdll.sh ed62756baf44babf562a7843588790c02fee2106
F mkopcodec.awk bd46ad001c98dfbab07b1713cb8e692fa0e5415d
F mkopcodeh.awk cde995d269aa06c94adbf6455bea0acedb913fa5
F src/analyze.c 4bbf5ddf9680587c6d4917e02e378b6037be3651
F src/attach.c a16ada4a4654a0d126b8223ec9494ebb81bc5c3c
F src/auth.c 902f4722661c796b97f007d9606bd7529c02597f
-F src/btree.c 27299eba3ad5aa1fed184c707576d12d0e608e8d
+F src/btree.c 5a0f425843ff81f3308fd083e606344b48c332f8
F src/btree.h 9b2cc0d113c0bc2d37d244b9a394d56948c9acbf
F src/build.c 7c2efa468f0c404ef5aa648d43c383318390937f
F src/callback.c 31d22b4919c7645cbcbb1591ce2453e8c677c558
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F src/pager.c 642f804b20a71933fb83b13a1ce93cb4dd1390f7
F src/pager.h e79a24cf200b8771366217f5bca414f5b7823f42
-F src/parse.y 6112045e2d3b8be20049645ab494b607d271d129
+F src/parse.y b6cfbadb6d5b21b5087d30698ee5af0ebb098767
F src/pragma.c 3b992b5b2640d6ae25cef05aa6a42cd1d6c43234
F src/prepare.c 37207b2b2ccb41d379b01dd62231686bcc48ef1f
F src/printf.c 0c6f40648770831341ac45ab32423a80b4c87f05
F src/sqlite3ext.h 7d0d363ea7327e817ef0dfe1b7eee1f171b72890
F src/sqliteInt.h 347160d30eb61210417f1086aeb57d7d3e2a8191
F src/table.c 6d0da66dde26ee75614ed8f584a1996467088d06
-F src/tclsqlite.c 58fd67ba2c5a6ca816ad110029b6cb2a44a3c707
+F src/tclsqlite.c ec69eb9ad56d03fbf7570ca1ca5ea947d1ec4b6f
F src/test1.c 6021cbcede9bfab986ade678efa7226180f3edff
F src/test2.c 24458b17ab2f3c90cbc1c8446bd7ffe69be62f88
F src/test3.c 65f92247cf8592854e9bf5115b3fb711f8b33280
F src/test9.c cb1a7b5a4a918bb0552fd0101fd3f88d85904cd2
F src/test_async.c 9d326ceda4306bcab252b8f7e8e480ed45d7ccb6
F src/test_autoext.c 855157d97aa28cf84233847548bfacda21807436
+F src/test_hexio.c 9644c0360c3e1090f4a5765b9eb0492bb273bbb5
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
F src/test_md5.c 6c42bc0a3c0b54be34623ff77a0eec32b2fa96e3
F src/test_schema.c ced72140a3a25c148975428e170ec1850d3c3a7d
F test/conflict.test 8a59399f61a14296a9bfed02e0570590a8a79cba
F test/corrupt.test 18c7a995b1af76a8c8600b996257f2c7b7bff083
F test/corrupt2.test 572f8df0303d0ce63ddad5c5c9101a83a345ae46
+F test/corrupt3.test 9b3a005c9692206f2800a948f0c9c79728ffee7f
F test/crash.test 167eb4652eccbedb199b6f21850346c3f5d779fb
F test/crash2.test ccc7d5f202aeadc3c13003829e6bb6561129f419
F test/crashtest1.c 09c1c7d728ccf4feb9e481671e29dda5669bbcc2
F test/exclusive2.test 8d580e5bb8d49fde59fe1142543b7da081f28d06
F test/exclusive3.test 0e49c35b7e7cb8e7280b4ce3f0359d30b207d2ff
F test/expr.test ab21e2fc3613595131efd7d8bbca4b95ed5cc608
+F test/filefmt.test 16107ce2c98843070ba5ec8f0c2ac31029bdabd6
F test/fkey1.test dcb4f28eb22d5141f15161d6bdca9a4f58c95729
F test/format4.test bf3bed3b13c63abfb3cfec232597a319a31d0bcc
F test/fts1a.test 46090311f85da51bb33bd5ce84f7948359c6d8d7
F test/safety.test 4a06934e45d03b8b50ebcd8d174eb0367d2fd851
F test/schema.test 8a2ae440fb15f5798a68059e8746402f3137be46
F test/schema2.test d815923e57e90b8c60ddf5e0d8fd65075e94f57f
-F test/select1.test fa4e941da0a38961635d903530bd292dc149a8e8
+F test/select1.test 1287b040f912b979ccc8d4b50ea585eeeacf1835
F test/select2.test f3c2678c3a9f3cf08ec4988a3845bda64be6d9e3
F test/select3.test 2d473f45c57c0526833e045fca0537badec0dd04
F test/select4.test 305ba0a6e97efc5544def5e5cb49b54e1bf87fd9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P a776d93ccae3bfa6e992cdd1387571dd21561f98
-R fa0c92e65fb1c611f3e19261755e89a8
+P 8e2559b4da6329d7c21925d0850f7f91a3731975
+R bf361c806ccd54df8932ace1ba12eaf6
U drh
-Z db8a808c353b3a8ae294eee8fe0830c1
+Z e15d206887ea8f19e691b97bb3aee05c
--- /dev/null
+/*
+** 2007 April 6
+**
+** 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 TCL commands for reading and writing the binary
+** database files and displaying the content of those files as
+** hexadecimal. We could, in theory, use the built-in "binary"
+** command of TCL to do a lot of this, but there are some issues
+** with historical versions of the "binary" command. So it seems
+** easier and safer to build our own mechanism.
+**
+** $Id: test_hexio.c,v 1.1 2007/04/06 15:02:14 drh Exp $
+*/
+#include "tcl.h"
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+/*
+hexio_read filename offset amt
+hexio_write filename offset hexdata
+hexio_get_int hexdata
+hexio_get_varint hexdata
+hexio_render_int8 integer
+hexio_render_int16 integer
+hexio_render_int38 integer
+hexio_render_varint integer
+*/
+
+/*
+** Convert binary to hex. The input zBuf[] contains N bytes of
+** binary data. zBuf[] is 2*n+1 bytes long. Overwrite zBuf[]
+** with a hexadecimal representation of its original binary input.
+*/
+static void binToHex(unsigned char *zBuf, int N){
+ const unsigned char zHex[] = "0123456789ABCDEF";
+ int i, j;
+ unsigned char c;
+ i = N*2;
+ zBuf[i--] = 0;
+ for(j=N-1; j>=0; j--){
+ c = zBuf[j];
+ zBuf[i--] = zHex[c&0xf];
+ zBuf[i--] = zHex[c>>4];
+ }
+ assert( i==-1 );
+}
+
+/*
+** Convert hex to binary. The input zIn[] contains N bytes of
+** hexadecimal. Convert this into binary and write aOut[] with
+** the binary data. Spaces in the original input are ignored.
+** Return the number of bytes of binary rendered.
+*/
+static int hexToBin(const unsigned char *zIn, int N, unsigned char *aOut){
+ const unsigned char aMap[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 0, 0, 0, 0, 0, 0,
+ 0,11,12,13,14,15,16, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0,11,12,13,14,15,16, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ };
+ int i, j;
+ int hi=1;
+ unsigned char c;
+
+ for(i=j=0; i<N; i++){
+ c = aMap[zIn[i]];
+ if( c==0 ) continue;
+ if( hi ){
+ aOut[j] = (c-1)<<4;
+ hi = 0;
+ }else{
+ aOut[j++] |= c-1;
+ hi = 1;
+ }
+ }
+ return j;
+}
+
+
+/*
+** Usage: hexio_read FILENAME OFFSET AMT
+**
+** Read AMT bytes from file FILENAME beginning at OFFSET from the
+** beginning of the file. Convert that information to hexadecimal
+** and return the resulting HEX string.
+*/
+static int hexio_read(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ int offset;
+ int amt, got;
+ const char *zFile;
+ unsigned char *zBuf;
+ FILE *in;
+
+ if( objc!=4 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "FILENAME OFFSET AMT");
+ return TCL_ERROR;
+ }
+ if( Tcl_GetIntFromObj(interp, objv[2], &offset) ) return TCL_ERROR;
+ if( Tcl_GetIntFromObj(interp, objv[3], &amt) ) return TCL_ERROR;
+ zFile = Tcl_GetString(objv[1]);
+ zBuf = malloc( amt*2+1 );
+ if( zBuf==0 ){
+ return TCL_ERROR;
+ }
+ in = fopen(zFile, "r");
+ if( in==0 ){
+ Tcl_AppendResult(interp, "cannot open input file ", zFile, 0);
+ return TCL_ERROR;
+ }
+ fseek(in, offset, SEEK_SET);
+ got = fread(zBuf, 1, amt, in);
+ fclose(in);
+ if( got<0 ){
+ got = 0;
+ }
+ binToHex(zBuf, got);
+ Tcl_AppendResult(interp, zBuf, 0);
+ free(zBuf);
+ return TCL_OK;
+}
+
+
+/*
+** Usage: hexio_write FILENAME OFFSET DATA
+**
+** Write DATA into file FILENAME beginning at OFFSET from the
+** beginning of the file. DATA is expressed in hexadecimal.
+*/
+static int hexio_write(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ int offset;
+ int nIn, nOut, written;
+ const char *zFile;
+ const unsigned char *zIn;
+ unsigned char *aOut;
+ FILE *out;
+
+ if( objc!=4 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "FILENAME OFFSET HEXDATA");
+ return TCL_ERROR;
+ }
+ if( Tcl_GetIntFromObj(interp, objv[2], &offset) ) return TCL_ERROR;
+ zFile = Tcl_GetString(objv[1]);
+ zIn = (const unsigned char *)Tcl_GetStringFromObj(objv[3], &nIn);
+ aOut = malloc( nIn/2 );
+ if( aOut==0 ){
+ return TCL_ERROR;
+ }
+ nOut = hexToBin(zIn, nIn, aOut);
+ out = fopen(zFile, "r+");
+ if( out==0 ){
+ Tcl_AppendResult(interp, "cannot open output file ", zFile, 0);
+ return TCL_ERROR;
+ }
+ fseek(out, offset, SEEK_SET);
+ written = fwrite(aOut, 1, nOut, out);
+ free(aOut);
+ fclose(out);
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(written));
+ return TCL_OK;
+}
+
+/*
+** USAGE: hexio_get_int HEXDATA
+**
+** Interpret the HEXDATA argument as a big-endian integer. Return
+** the value of that integer. HEXDATA can contain between 2 and 8
+** hexadecimal digits.
+*/
+static int hexio_get_int(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ int val;
+ int nIn, nOut;
+ const unsigned char *zIn;
+ unsigned char *aOut;
+ unsigned char aNum[4];
+
+ if( objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "HEXDATA");
+ return TCL_ERROR;
+ }
+ zIn = (const unsigned char *)Tcl_GetStringFromObj(objv[1], &nIn);
+ aOut = malloc( nIn/2 );
+ if( aOut==0 ){
+ return TCL_ERROR;
+ }
+ nOut = hexToBin(zIn, nIn, aOut);
+ if( nOut>=4 ){
+ memcpy(aNum, aOut, 4);
+ }else{
+ memset(aNum, 0, sizeof(aNum));
+ memcpy(&aNum[4-nOut], aOut, 4-nOut);
+ }
+ free(aOut);
+ val = (aNum[0]<<24) | (aNum[1]<<16) | (aNum[2]<<8) | aNum[3];
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(val));
+ return TCL_OK;
+}
+
+
+/*
+** USAGE: hexio_render_int16 INTEGER
+**
+** Render INTEGER has a 16-bit big-endian integer in hexadecimal.
+*/
+static int hexio_render_int16(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ int val;
+ unsigned char aNum[10];
+
+ if( objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "INTEGER");
+ return TCL_ERROR;
+ }
+ if( Tcl_GetIntFromObj(interp, objv[1], &val) ) return TCL_ERROR;
+ aNum[0] = val>>8;
+ aNum[1] = val;
+ binToHex(aNum, 2);
+ Tcl_SetObjResult(interp, Tcl_NewStringObj((char*)aNum, 4));
+ return TCL_OK;
+}
+
+
+/*
+** USAGE: hexio_render_int32 INTEGER
+**
+** Render INTEGER has a 32-bit big-endian integer in hexadecimal.
+*/
+static int hexio_render_int32(
+ void * clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ int val;
+ unsigned char aNum[10];
+
+ if( objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "INTEGER");
+ return TCL_ERROR;
+ }
+ if( Tcl_GetIntFromObj(interp, objv[1], &val) ) return TCL_ERROR;
+ aNum[0] = val>>24;
+ aNum[1] = val>>16;
+ aNum[2] = val>>8;
+ aNum[3] = val;
+ binToHex(aNum, 4);
+ Tcl_SetObjResult(interp, Tcl_NewStringObj((char*)aNum, 8));
+ return TCL_OK;
+}
+
+
+
+/*
+** Register commands with the TCL interpreter.
+*/
+int Sqlitetest_hexio_Init(Tcl_Interp *interp){
+ static struct {
+ char *zName;
+ Tcl_ObjCmdProc *xProc;
+ } aObjCmd[] = {
+ { "hexio_read", hexio_read },
+ { "hexio_write", hexio_write },
+ { "hexio_get_int", hexio_get_int },
+ { "hexio_render_int16", hexio_render_int16 },
+ { "hexio_render_int32", hexio_render_int32 },
+ };
+ int i;
+ for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
+ Tcl_CreateObjCommand(interp, aObjCmd[i].zName, aObjCmd[i].xProc, 0, 0);
+ }
+ return TCL_OK;
+}