From: drh Date: Thu, 2 Apr 2009 20:27:28 +0000 (+0000) Subject: Make sure count(*) works on the sqlite_master table of an empty database. X-Git-Tag: version-3.6.15~307 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=818e39ad350aa2a7d47e298d6459fd9c5715363f;p=thirdparty%2Fsqlite.git Make sure count(*) works on the sqlite_master table of an empty database. Ticket #3774. (CVS 6443) FossilOrigin-Name: e0c1a780f5a356c48b2a4cc66fab988fe441722f --- diff --git a/manifest b/manifest index e2e88a957a..2a21103fd0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sthe\sVACUUM\sstatement\slocks\sdown\sthe\spage_size\sand\sauto_vacuum\nmodes\safter\sit\sruns.\s\sOtherwise,\spragmas\smight\schange\sthese\ssettings\son\na\spopulated\sdatabase,\sresulting\sin\sproblems.\s(CVS\s6442) -D 2009-04-02T20:16:59 +C Make\ssure\scount(*)\sworks\son\sthe\ssqlite_master\stable\sof\san\sempty\sdatabase.\nTicket\s#3774.\s(CVS\s6443) +D 2009-04-02T20:27:28 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 @@ -200,7 +200,7 @@ F src/update.c 8ededddcde6f7b6da981dd0429a5d34518a475b7 F src/utf.c 9541d28f40441812c0b40f00334372a0542c00ff F src/util.c 469d74f5bf09ed6398702c7da2ef8a34e979a1c1 F src/vacuum.c 07121a727beeee88f27d704a00313ad6a7c9bef0 -F src/vdbe.c 624922027b8b5fe203bd89e204aaed447e8b7ce7 +F src/vdbe.c bddddefc5c7ec1c9cd3e4f9220eb813b43668605 F src/vdbe.h d70a68bee196ab228914a3902c79dbd24342a0f2 F src/vdbeInt.h 53a2f4696871712646c77351904576cca6ad9752 F src/vdbeapi.c 950986b0f765b5b91aab1acb2b405d9450b749d1 @@ -287,7 +287,7 @@ F test/corrupt9.test 794d284109c65c8f10a2b275479045e02d163bae F test/corruptA.test 99e95620b980161cb3e79f06a884a4bb8ae265ff F test/corruptB.test 505331779fe7a96fe38ecbb817f19c63bc27d171 F test/corruptC.test c798aa395a8d052fba88bd1be8e1945309e3f94a -F test/count.test 89df9e4cf33caa060be12607462caaf47df6c435 +F test/count.test 276b32260ecfa1f3c50799818fd1aea99888eea8 F test/crash.test 1b6ac8410689ff78028887f445062dc897c9ac89 F test/crash2.test 5b14d4eb58b880e231361d3b609b216acda86651 F test/crash3.test 776f9363554c029fcce71d9e6600fa0ba6359ce7 @@ -715,7 +715,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e -P 23bf9f266559603e37b2703715eaf8ef5af6bb17 -R e0d218115c45629c5885d4b4b4658168 +P 85e6a4740d6db731c8c35a331031c346e9189c27 +R bd78ffb4482bff31a318e650753900a9 U drh -Z 1702788136b089e50c945192dcad3cc4 +Z 65e49db46664fd71c4cc25be1e95b592 diff --git a/manifest.uuid b/manifest.uuid index 4ea73c6e41..edefd6890f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -85e6a4740d6db731c8c35a331031c346e9189c27 \ No newline at end of file +e0c1a780f5a356c48b2a4cc66fab988fe441722f \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 128e81bdf3..da4747e752 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.828 2009/03/23 17:11:27 danielk1977 Exp $ +** $Id: vdbe.c,v 1.829 2009/04/02 20:27:28 drh Exp $ */ #include "sqliteInt.h" #include "vdbeInt.h" @@ -2365,7 +2365,11 @@ case OP_MakeRecord: { case OP_Count: { /* out2-prerelease */ i64 nEntry; BtCursor *pCrsr = p->apCsr[pOp->p1]->pCursor; - rc = sqlite3BtreeCount(pCrsr, &nEntry); + if( pCrsr ){ + rc = sqlite3BtreeCount(pCrsr, &nEntry); + }else{ + nEntry = 0; + } pOut->flags = MEM_Int; pOut->u.i = nEntry; break; diff --git a/test/count.test b/test/count.test index 890bb2fadd..d0adb53b0f 100644 --- a/test/count.test +++ b/test/count.test @@ -11,13 +11,15 @@ # This file implements regression tests for SQLite library. The # focus of this file is testing "SELECT count(*)" statements. # -# $Id: count.test,v 1.3 2009/02/25 08:56:47 danielk1977 Exp $ +# $Id: count.test,v 1.4 2009/04/02 20:27:28 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # Test plan: # +# count-0.*: Make sure count(*) works on an empty database. (Ticket #3774) +# # count-1.*: Test that the OP_Count instruction appears to work on both # tables and indexes. Test both when they contain 0 entries, # when all entries are on the root page, and when the b-tree @@ -27,6 +29,12 @@ source $testdir/tester.tcl # # +do_test count-0.1 { + db eval { + SELECT count(*) FROM sqlite_master; + } +} {0} + set iTest 0 foreach zIndex [list { /* no-op */ @@ -182,4 +190,3 @@ do_test count-4.3 { finish_test -