]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Allow creation of ephemeral pseudo-tables - pseudo-tables that copy a pointer to...
authordanielk1977 <danielk1977@noemail.net>
Thu, 27 Mar 2008 17:59:01 +0000 (17:59 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Thu, 27 Mar 2008 17:59:01 +0000 (17:59 +0000)
FossilOrigin-Name: 1a58a87023f7780aee813ac64dda1a80021002a7

manifest
manifest.uuid
src/select.c
src/vdbe.c
src/vdbeInt.h
src/vdbeaux.c

index 5dcfcfafac14b3d76a11a9b5cc99cc91a9853cc7..e8865cd2898e534b4f57f1363f730a9ce40ab628 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Added\sthe\sspeed4p.test\sscript\sfor\stesting\sperformance\sof\sviews\sand\striggers.\s(CVS\s4923)
-D 2008-03-27T15:07:05
+C Allow\screation\sof\sephemeral\spseudo-tables\s-\spseudo-tables\sthat\scopy\sa\spointer\sto\sa\srow\swhen\sinserted\sinstead\sof\scopying\sthe\srow\sdata.\s(CVS\s4924)
+D 2008-03-27T17:59:02
 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
 F Makefile.in cf434ce8ca902e69126ae0f94fc9f7dc7428a5fa
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -135,7 +135,7 @@ F src/pragma.c 99cec6d99d0241436494aab15b05da97b0e70683
 F src/prepare.c 185fb47f1fb3e45a345d523eb391d673f5eb367c
 F src/printf.c 05d2b44d7b5b80c8a4a09108ddad9c20e254370d
 F src/random.c 2b2db2de4ab491f5a14d3480466f8f4b5a5db74a
-F src/select.c 5b5197016a0b751fdb78758370ba127175d3f786
+F src/select.c f47faa4af940d0acd0cff92a1a77ebb27331a31a
 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
 F src/shell.c 22297fffa6f00a6c6d44020fa13b1184a1bb372d
 F src/sqlite.h.in b1ac824d9fc163a5d2226ebf5990b09a02a11117
@@ -174,11 +174,11 @@ F src/update.c 2aefd3c9277792e9fa2414dfe14202119fa49fe7
 F src/utf.c 32b00d6e19010025e58f2ecb2f921d5e126771b4
 F src/util.c dba9e04121eb17ec4643d6ca231ff859452cf0e2
 F src/vacuum.c 3524411bfb58aac0d87eadd3e5b7cd532772af30
-F src/vdbe.c 0068703495a197e7b77dbdff604b42896722a1cc
+F src/vdbe.c f8e6d7f96f27c273e252c475a54d485943f0bb24
 F src/vdbe.h f72201a0657d5f3d6cc008d1f8d9cc65768518c9
-F src/vdbeInt.h 2584494757e7d8e7015754d4017b36f758c2adef
+F src/vdbeInt.h 73a3162979585cc15d02e47cec2a1033df768246
 F src/vdbeapi.c f74189e4cae0d93b2744386b9ac57f5ab60c5133
-F src/vdbeaux.c c77a88c97cf5836eb1f68ca6fea967569472712b
+F src/vdbeaux.c 0bdcfad81941f7f6b0b5f2f489d65804d4bdaf02
 F src/vdbeblob.c cc713c142c3d4952b380c98ee035f850830ddbdb
 F src/vdbefifo.c a30c237b2a3577e1415fb6e288cbb6b8ed1e5736
 F src/vdbemem.c d48a71d66a7afd564b6537ab7e7442f7729fa5af
@@ -619,7 +619,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 8c2f69521f13bc24cf005520efbe0589eeadd763
-R 0fca44539a2917afad155100f6434a4c
-U drh
-Z 074101a796f99fca1a50c6aac650887e
+P adf7645f9a1e12389a7511d2adca9013b7f330fa
+R c27119a978dd6220ce607704acf25a98
+U danielk1977
+Z 2fd91019f3a606466497fa3759b61fc9
index c5c3143650b20cf26bd1bedca2cb555450c0102b..2741d0926a5a5af14401263e538061ff7f7b8c99 100644 (file)
@@ -1 +1 @@
-adf7645f9a1e12389a7511d2adca9013b7f330fa
\ No newline at end of file
+1a58a87023f7780aee813ac64dda1a80021002a7
\ No newline at end of file
index 879951b00ff14c8276938453c5bcb2e32b5882a2..649e846b936e22efac294dcf7bd1d5e4700e33a3 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle SELECT statements in SQLite.
 **
-** $Id: select.c,v 1.421 2008/03/26 12:50:15 drh Exp $
+** $Id: select.c,v 1.422 2008/03/27 17:59:02 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 
@@ -795,7 +795,7 @@ static void generateSortTail(
   if( eDest==SRT_Callback || eDest==SRT_Subroutine ){
     pseudoTab = pParse->nTab++;
     sqlite3VdbeAddOp2(v, OP_SetNumColumns, 0, nColumn);
-    sqlite3VdbeAddOp2(v, OP_OpenPseudo, pseudoTab, 0);
+    sqlite3VdbeAddOp2(v, OP_OpenPseudo, pseudoTab, eDest==SRT_Callback);
   }
   addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, brk);
   codeOffset(v, p, cont);
@@ -833,6 +833,7 @@ static void generateSortTail(
       sqlite3VdbeAddOp2(v, OP_Integer, 1, regRowid);
       sqlite3VdbeAddOp3(v, OP_Insert, pseudoTab, regRow, regRowid);
       for(i=0; i<nColumn; i++){
+        assert( regRow!=pDest->iMem+i );
         sqlite3VdbeAddOp3(v, OP_Column, pseudoTab, i, pDest->iMem+i);
       }
       if( eDest==SRT_Callback ){
index 72657ce36fd4e42e5aad55a889478e98ef65cf0a..e41c6eed07500ab948a1bf68c92081d28e7aab02 100644 (file)
@@ -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.718 2008/03/25 17:23:33 drh Exp $
+** $Id: vdbe.c,v 1.719 2008/03/27 17:59:02 danielk1977 Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -2684,7 +2684,7 @@ case OP_OpenEphemeral: {
   break;
 }
 
-/* Opcode: OpenPseudo P1 * * * *
+/* Opcode: OpenPseudo P1 P2 * * *
 **
 ** Open a new cursor that points to a fake table that contains a single
 ** row of data.  Any attempt to write a second row of data causes the
@@ -2695,6 +2695,14 @@ case OP_OpenEphemeral: {
 ** NEW or OLD tables in a trigger.  Also used to hold the a single
 ** row output from the sorter so that the row can be decomposed into
 ** individual columns using the OP_Column opcode.
+**
+** When OP_Insert is executed to insert a row in to the pseudo table,
+** the pseudo-table cursor may or may not make it's own copy of the
+** original row data. If P2 is 0, then the pseudo-table will copy the
+** original row data. Otherwise, a pointer to the original memory cell
+** is stored. In this case, the vdbe program must ensure that the 
+** memory cell containing the row data is not overwritten until the
+** pseudo table is closed (or a new row is inserted into it).
 */
 case OP_OpenPseudo: {
   int i = pOp->p1;
@@ -2704,6 +2712,7 @@ case OP_OpenPseudo: {
   if( pCx==0 ) goto no_mem;
   pCx->nullRow = 1;
   pCx->pseudoTable = 1;
+  pCx->ephemPseudoTable = pOp->p2;
   pCx->pIncrKey = &pCx->bogusIncrKey;
   pCx->isTable = 1;
   pCx->isIndex = 0;
@@ -3276,13 +3285,17 @@ case OP_Insert: {
     assert( pData->flags & (MEM_Blob|MEM_Str) );
   }
   if( pC->pseudoTable ){
-    sqlite3_free(pC->pData);
+    if( !pC->ephemPseudoTable ){
+      sqlite3_free(pC->pData);
+    }
     pC->iKey = iKey;
     pC->nData = pData->n;
     if( pData->flags & MEM_Dyn ){
       pC->pData = pData->z;
-      pData->flags &= ~MEM_Dyn;
-      pData->flags |= MEM_Ephem;
+      if( !pC->ephemPseudoTable ){
+        pData->flags &= ~MEM_Dyn;
+        pData->flags |= MEM_Ephem;
+      }
     }else{
       pC->pData = sqlite3_malloc( pC->nData+2 );
       if( !pC->pData ) goto no_mem;
index d492a26b426032101e8c7bc2d3c277adeb260839..c3a0297798696a20f84996e14e35e2e9b83c863d 100644 (file)
@@ -65,6 +65,7 @@ struct Cursor {
   Bool nullRow;         /* True if pointing to a row with no data */
   Bool nextRowidValid;  /* True if the nextRowid field is valid */
   Bool pseudoTable;     /* This is a NEW or OLD pseudo-tables of a trigger */
+  Bool ephemPseudoTable;
   Bool deferredMoveto;  /* A call to sqlite3BtreeMoveto() is needed */
   Bool isTable;         /* True if a table requiring integer keys */
   Bool isIndex;         /* True if an index containing keys only - no data */
index 6b737d2c8717a38cb43078cf29388861569ab850..369946c4e0fdd3af7cd86f258750bc0e8bf9dc8e 100644 (file)
@@ -1081,7 +1081,9 @@ void sqlite3VdbeFreeCursor(Vdbe *p, Cursor *pCx){
     p->inVtabMethod = 0;
   }
 #endif
-  sqlite3_free(pCx->pData);
+  if( !pCx->ephemPseudoTable ){
+    sqlite3_free(pCx->pData);
+  }
   memset(pCx, 0, sizeof(Cursor));
   /* sqlite3_free(pCx->aType); */
   /* sqlite3_free(pCx); */