]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
In kvtest.c, use stat() instead of fseek()/ftell() to determine the size of
authordrh <drh@noemail.net>
Thu, 29 Dec 2016 17:25:06 +0000 (17:25 +0000)
committerdrh <drh@noemail.net>
Thu, 29 Dec 2016 17:25:06 +0000 (17:25 +0000)
a BLOB to be read directly from disk.  This makes the pile-of-files database
more competative against SQLite.

FossilOrigin-Name: a7dca29f03e037fe71cc600db97f8058e3bd28a4

manifest
manifest.uuid
test/kvtest.c

index 70c7ebc070f9486974da948fc03b2c026fc7d398..ee9eb6e447aa132de44a98732e6ca9c8b30e96de 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sthe\skvtest.c\stest\sprogram\sused\sto\sshow\sthat\sit\sis\smany\stimes\sfaster\sto\nread\sthumbnail\sand\ssimilar\sBLOBs\sout\sof\san\sSQLite\sdatabase\sthan\sit\sis\sto\sread\nthem\sas\sseparate\sfiles\sfrom\sthe\sfilesystem.
-D 2016-12-29T16:58:01.454
+C In\skvtest.c,\suse\sstat()\sinstead\sof\sfseek()/ftell()\sto\sdetermine\sthe\ssize\sof\na\sBLOB\sto\sbe\sread\sdirectly\sfrom\sdisk.\s\sThis\smakes\sthe\spile-of-files\sdatabase\nmore\scompetative\sagainst\sSQLite.
+D 2016-12-29T17:25:06.872
 F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da
@@ -894,7 +894,7 @@ F test/json101.test c0897616f32d95431f37fd291cb78742181980ac
 F test/json102.test bf3fe7a706d30936a76a0f7a0375e1e8e73aff5a
 F test/json103.test c5f6b85e69de05f6b3195f9f9d5ce9cd179099a0
 F test/keyword1.test 37ef6bba5d2ed5b07ecdd6810571de2956599dff
-F test/kvtest.c 05685d636f6c2985cfe00f88ba95e5c19cbd22bc
+F test/kvtest.c 2c66ddefcd03c2caa337f6dd79e6c82368af83df
 F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63
 F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200
 F test/like.test 0603f4fa0dad50987f70032c05800cbfa8985302
@@ -1540,8 +1540,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P a6af06f164b1f65779e2171ec4946119c66f9be8 55d29839c9fafe9e6a694f5790151d1f22396b01
-R 7016508fdc58bb08d2b99836c37fbfc4
-T +closed 55d29839c9fafe9e6a694f5790151d1f22396b01
+P 8074d59cf177cb91ee371e2660f2c59ce540b7e2
+R 753a90b01c338f55ad8c1b7fed642932
 U drh
-Z 23505d55f5d4f936007bea728155ea61
+Z 3b88de21d40c4e92a72ebab5ce816139
index 8059e9f0eea3a787d1430b8eaf4c6bc548f78389..52db41a7732f99bfb869c108c435da0e51c0df40 100644 (file)
@@ -1 +1 @@
-8074d59cf177cb91ee371e2660f2c59ce540b7e2
\ No newline at end of file
+a7dca29f03e037fe71cc600db97f8058e3bd28a4
\ No newline at end of file
index 25accc026287e51d7e596ab4d883bd0d7aec8f09..877605aced4430b66a368efef550a54550fffe42 100644 (file)
@@ -104,6 +104,7 @@ static const char zHelp[] =
   /* Provide Windows equivalent for the needed parts of unistd.h */
 # include <io.h>
 # define R_OK 2
+# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
 # define access _access
 #endif
@@ -154,6 +155,20 @@ static int pathType(const char *zPath){
   return PATH_OTHER;
 }
 
+/*
+** Return the size of a file in bytes.  Or return -1 if the
+** named object is not a regular file or does not exist.
+*/
+static sqlite3_int64 fileSize(const char *zPath){
+  struct stat x;
+  int rc;
+  memset(&x, 0, sizeof(x));
+  rc = stat(zPath, &x);
+  if( rc<0 ) return -1;
+  if( !S_ISREG(x.st_mode) ) return -1;
+  return x.st_size;
+}
+
 /*
 ** A Pseudo-random number generator with a fixed seed.  Use this so
 ** that the same sequence of "random" numbers are generated on each
@@ -315,15 +330,16 @@ static int exportMain(int argc, char **argv){
 ** is undefined in this case.
 */
 static unsigned char *readFile(const char *zName, int *pnByte){
-  FILE *in = fopen(zName, "rb");
-  long nIn;
-  size_t nRead;
-  unsigned char *pBuf;
+  FILE *in;               /* FILE from which to read content of zName */
+  sqlite3_int64 nIn;      /* Size of zName in bytes */
+  size_t nRead;           /* Number of bytes actually read */
+  unsigned char *pBuf;    /* Content read from disk */
+
+  nIn = fileSize(zName);
+  if( nIn<0 ) return 0;
+  in = fopen(zName, "rb");
   if( in==0 ) return 0;
-  fseek(in, 0, SEEK_END);
-  nIn = ftell(in);
-  rewind(in);
-  pBuf = sqlite3_malloc64( nIn+1 );
+  pBuf = sqlite3_malloc64( nIn );
   if( pBuf==0 ) return 0;
   nRead = fread(pBuf, nIn, 1, in);
   fclose(in);
@@ -331,7 +347,6 @@ static unsigned char *readFile(const char *zName, int *pnByte){
     sqlite3_free(pBuf);
     return 0;
   }
-  pBuf[nIn] = 0;
   if( pnByte ) *pnByte = nIn;
   return pBuf;
 }