/ Check-in [f8041f3d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:A SELECT statement inside the body of a TRIGGER uses the SRT_Discard target to discard the query results. Such selects are intended to be used to call user-defined functions for their side-effects. They do not return results. (CVS 594)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:f8041f3d4d3350b4086cd6ba3e9006bdde8546a9
User & Date: drh 2002-05-27 12:24:48
Context
2002-05-28
06:55
Update trigger2.test to match checkin 591. Also fix ticket #51 (by documenting problem) (CVS 595) check-in: 5e74d096 user: danielk1977 tags: trunk
2002-05-27
12:24
A SELECT statement inside the body of a TRIGGER uses the SRT_Discard target to discard the query results. Such selects are intended to be used to call user-defined functions for their side-effects. They do not return results. (CVS 594) check-in: f8041f3d user: drh tags: trunk
03:25
Fix the "alias.*" bug found by Bernie Cosell and reported on the newsgroup. (CVS 593) check-in: f562d542 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/select.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
399
400
401
402
403
404
405









406
407
408
409
410
411
412
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.87 2002/05/27 03:25:52 drh Exp $
*/
#include "sqliteInt.h"

/*
** Allocate a new Select structure and return a pointer to that
** structure.
*/
................................................................................
  ** of the scan loop.
  */
  if( eDest==SRT_Mem ){
    assert( nColumn==1 );
    sqliteVdbeAddOp(v, OP_MemStore, iParm, 1);
    sqliteVdbeAddOp(v, OP_Goto, 0, iBreak);
  }else










  /* If none of the above, send the data to the callback function.
  */
  {
    sqliteVdbeAddOp(v, OP_Callback, nColumn, iBreak);
  }
  return 0;







|







 







>
>
>
>
>
>
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.88 2002/05/27 12:24:48 drh Exp $
*/
#include "sqliteInt.h"

/*
** Allocate a new Select structure and return a pointer to that
** structure.
*/
................................................................................
  ** of the scan loop.
  */
  if( eDest==SRT_Mem ){
    assert( nColumn==1 );
    sqliteVdbeAddOp(v, OP_MemStore, iParm, 1);
    sqliteVdbeAddOp(v, OP_Goto, 0, iBreak);
  }else

  /* Discard the results.  This is used for SELECT statements inside
  ** the body of a TRIGGER.  The purpose of such selects is to call
  ** user-defined functions that have side effects.  We do not care
  ** about the actual results of the select.
  */
  if( eDest==SRT_Discard ){
    sqliteVdbeAddOp(v, OP_Pop, nColumn, 0);
  }else

  /* If none of the above, send the data to the callback function.
  */
  {
    sqliteVdbeAddOp(v, OP_Callback, nColumn, iBreak);
  }
  return 0;

Changes to src/sqliteInt.h.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
536
537
538
539
540
541
542

543
544
545
546
547
548
549
**    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.
**
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.117 2002/05/26 20:54:34 drh Exp $
*/
#include "sqlite.h"
#include "hash.h"
#include "vdbe.h"
#include "parse.h"
#include "btree.h"
#include <stdio.h>
................................................................................
#define SRT_Callback     1  /* Invoke a callback with each row of result */
#define SRT_Mem          2  /* Store result in a memory cell */
#define SRT_Set          3  /* Store result as unique keys in a table */
#define SRT_Union        5  /* Store result as keys in a table */
#define SRT_Except       6  /* Remove result from a UNION table */
#define SRT_Table        7  /* Store result as data with a unique key */
#define SRT_TempTable    8  /* Store result in a trasient table */


/*
** When a SELECT uses aggregate functions (like "count(*)" or "avg(f1)")
** we have to do some additional analysis of expressions.  An instance
** of the following structure holds information about a single subexpression
** somewhere in the SELECT statement.  An array of these structures holds
** all the information we need to generate code for aggregate







|







 







>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
**    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.
**
*************************************************************************
** Internal interface definitions for SQLite.
**
** @(#) $Id: sqliteInt.h,v 1.118 2002/05/27 12:24:49 drh Exp $
*/
#include "sqlite.h"
#include "hash.h"
#include "vdbe.h"
#include "parse.h"
#include "btree.h"
#include <stdio.h>
................................................................................
#define SRT_Callback     1  /* Invoke a callback with each row of result */
#define SRT_Mem          2  /* Store result in a memory cell */
#define SRT_Set          3  /* Store result as unique keys in a table */
#define SRT_Union        5  /* Store result as keys in a table */
#define SRT_Except       6  /* Remove result from a UNION table */
#define SRT_Table        7  /* Store result as data with a unique key */
#define SRT_TempTable    8  /* Store result in a trasient table */
#define SRT_Discard      9  /* Do not save the results anywhere */

/*
** When a SELECT uses aggregate functions (like "count(*)" or "avg(f1)")
** we have to do some additional analysis of expressions.  An instance
** of the following structure holds information about a single subexpression
** somewhere in the SELECT statement.  An array of these structures holds
** all the information we need to generate code for aggregate

Changes to src/trigger.c.

476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496

  while( pTriggerStep ){
    int saveNTab = pParse->nTab;
    orconf = (orconfin == OE_Default)?pTriggerStep->orconf:orconfin;
    pParse->trigStack->orconf = orconf;
    switch( pTriggerStep->op ){
      case TK_SELECT: {
        int tmp_tbl = pParse->nTab++;
	sqliteVdbeAddOp(pParse->pVdbe, OP_OpenTemp, tmp_tbl, 0);
	sqliteVdbeAddOp(pParse->pVdbe, OP_KeyAsData, tmp_tbl, 1);
	sqliteSelect(pParse, pTriggerStep->pSelect, SRT_Union, 
	    tmp_tbl, 0, 0, 0);
	sqliteVdbeAddOp(pParse->pVdbe, OP_Close, tmp_tbl, 0);
	pParse->nTab--;
	break;
      }
      case TK_UPDATE: {
        sqliteVdbeAddOp(pParse->pVdbe, OP_ListPush, 0, 0);
        sqliteUpdate(pParse, &pTriggerStep->target, 
        sqliteExprListDup(pTriggerStep->pExprList), 
        sqliteExprDup(pTriggerStep->pWhere), orconf);







<
<
<
|
<
<
<







476
477
478
479
480
481
482



483



484
485
486
487
488
489
490

  while( pTriggerStep ){
    int saveNTab = pParse->nTab;
    orconf = (orconfin == OE_Default)?pTriggerStep->orconf:orconfin;
    pParse->trigStack->orconf = orconf;
    switch( pTriggerStep->op ){
      case TK_SELECT: {



	sqliteSelect(pParse, pTriggerStep->pSelect, SRT_Discard, 0, 0, 0, 0);



	break;
      }
      case TK_UPDATE: {
        sqliteVdbeAddOp(pParse->pVdbe, OP_ListPush, 0, 0);
        sqliteUpdate(pParse, &pTriggerStep->target, 
        sqliteExprListDup(pTriggerStep->pExprList), 
        sqliteExprDup(pTriggerStep->pWhere), orconf);