Ugly formatting aside (did you send this HTML formatted rather than as text/plain perchance), this is indeed a "bug" (as in does not return correct results) in the version of the "readfile" SQLite function included in shell.c. This issue does not exist with the extension version in fileio.c.
My own build process #ifdef's out the version of the functions included in shell.c and instead uses the fileio.c as a builtin extension. > -----Original Message----- > From: sqlite-users [mailto:[email protected]] > On Behalf Of [email protected] > Sent: Thursday, 15 December, 2016 07:08 > To: sqlite-users > Subject: [sqlite] shell: fix blob partial missing when readfile > > Hi all, > I found a readfile() BUG with version 3.15.2, it will cause file's partial > content missed. Just as bellow says: > > commit e624d8571dfeb30566da72657c71776e2f6c1a56Author: Gang Deng > <[email protected]>Date: Thu Dec 15 21:58:07 2016 +0800 > shell: fix blob partial missing when readfile Without this > patch, the readfile(X) SQL function translate the file's content to > blob util reachs a '\0' byte, which was obviously a bug. This may cause > partial content missed. Signed-off-by: Gang Deng > <[email protected]> > diff --git a/src/shell.c b/src/shell.cindex d0b743c..a3e04c0 100644--- > a/src/shell.c+++ b/src/shell.c@@ -2285,7 +2285,7 @@ static int > process_input(ShellState *p, FILE *in); ** ** NULL is returned if any > error is encountered. */-static char *readFile(const char *zName){+static > char *readFile(const char *zName, long *pLen){ FILE *in = fopen(zName, > "rb"); long nIn; size_t nRead;@@ -2303,6 +2303,8 @@ static char > *readFile(const char *zName){ return 0; } pBuf[nIn] = 0;+ if > (pLen)+ *pLen = nIn; return pBuf; } @@ -2318,12 +2320,13 @@ static > void readfileFunc( ){ const char *zName; void *pBuf;+ long nLen; > UNUSED_PARAMETER(argc); zName = (const > char*)sqlite3_value_text(argv[0]); if( zName==0 ) return;- pBuf = > readFile(zName);- if( pBuf ) sqlite3_result_blob(context, pBuf, -1, > sqlite3_free);+ pBuf = readFile(zName, &nLen);+ if( pBuf ) > sqlite3_result_blob(context, pBuf, nLen, sqlite3_free); } /*@@ -3416,7 > +3419,7 @@ static int do_meta_command(char *zLine, ShellState *p){ if( > nArg!=2 ){ raw_printf(stderr, "Usage: .check GLOB-PATTERN\n"); > rc = 2;- }else if( (zRes = readFile("testcase-out.txt"))==0 ){+ > }else if( (zRes = readFile("testcase-out.txt", NULL))==0 ){ > raw_printf(stderr, "Error: cannot read 'testcase-out.txt'\n"); rc = > 2; }else if( testcase_glob(azArg[1],zRes)==0 ){ > > Best Regards,gavin > _______________________________________________ > sqlite-users mailing list > [email protected] > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list [email protected] http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

