/ Check-in [9e96511f]
Login

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

Overview
Comment:Changes to test8.c to support UPDATE operations on xUpdate. (CVS 3250)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:9e96511f83476e489fa62a05241393a851cbac5c
User & Date: drh 2006-06-14 23:43:31
Context
2006-06-15
04:28
Add void* argument to sqlite3_create_module to replace sqlite3_module.pAux. (CVS 3251) check-in: 470a3a0b user: danielk1977 tags: trunk
2006-06-14
23:43
Changes to test8.c to support UPDATE operations on xUpdate. (CVS 3250) check-in: 9e96511f user: drh tags: trunk
22:07
Bug fixes in the MATCH and ORDER BY processing of virtual tables. (CVS 3249) check-in: c996185a user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/test8.c.

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
481
482
483
484
485
486
487































































488
489
490
491
492
493
494
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Code for testing the virtual table interfaces.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test8.c,v 1.18 2006/06/14 22:07:11 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>

................................................................................

int echoUpdate(sqlite3_vtab *tab, int nData, sqlite3_value **apData){
  echo_vtab *pVtab = (echo_vtab *)tab;
  sqlite3 *db = pVtab->db;
  int rc = SQLITE_OK;

  assert( nData==pVtab->nCol+2 || nData==1 );
































































  /* If apData[0] is an integer, delete the identified row */
  if( sqlite3_value_type(apData[0])==SQLITE_INTEGER ){
    const char *zFormat = "DELETE FROM %Q WHERE rowid = ?";
    char *zDelete = sqlite3_mprintf(zFormat, pVtab->zTableName);
    if( !zDelete ){
      rc = SQLITE_NOMEM;







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
**    May you share freely, never taking more than you give.
**
*************************************************************************
** Code for testing the virtual table interfaces.  This code
** is not included in the SQLite library.  It is used for automated
** testing of the SQLite library.
**
** $Id: test8.c,v 1.19 2006/06/14 23:43:31 drh Exp $
*/
#include "sqliteInt.h"
#include "tcl.h"
#include "os.h"
#include <stdlib.h>
#include <string.h>

................................................................................

int echoUpdate(sqlite3_vtab *tab, int nData, sqlite3_value **apData){
  echo_vtab *pVtab = (echo_vtab *)tab;
  sqlite3 *db = pVtab->db;
  int rc = SQLITE_OK;

  assert( nData==pVtab->nCol+2 || nData==1 );

  /* If apData[0] is an integer and nData>1 then do an UPDATE */
  if( nData>1 && sqlite3_value_type(apData[0])==SQLITE_INTEGER ){
    char *zUpdate = sqlite3_mprintf("UPDATE %Q", pVtab->zTableName);
    char *zSep = " SET";
    char *zTemp;
    int i, j;
    sqlite3_stmt *pStmt;
    
    if( apData[1] && sqlite3_value_type(apData[1])  &&
           sqlite3_value_int64(apData[0])!=sqlite3_value_int64(apData[1]) ){
       zTemp = sqlite3_mprintf("%s SET rowid=%lld", zUpdate, zSep,
                                sqlite3_value_int64(apData[1]));
       sqlite3_free(zUpdate);
       zUpdate = zTemp;
       zSep = ",";
    }
    for(i=2; i<nData; i++){
      if( apData[i]==0 ) continue;
      zTemp = sqlite3_mprintf("%s%s %Q=?", zUpdate, zSep, pVtab->aCol[i-2]);
      sqlite3_free(zUpdate);
      zUpdate = zTemp;
      zSep = ",";
    }
    zTemp = sqlite3_mprintf("%s WHERE rowid=%lld", zUpdate,
                             sqlite3_value_int64(apData[0]));
    sqlite3_free(zUpdate);
    zUpdate = zTemp;
    rc = sqlite3_prepare(db, zUpdate, -1, &pStmt, 0);
    assert( rc!=SQLITE_OK || pStmt );
    if( rc ) return rc;
    for(i=2, j=1; i<nData; i++){
      if( apData[i]==0 ) continue;
      switch( sqlite3_value_type(apData[i]) ){
        case SQLITE_INTEGER: {
          sqlite3_bind_int64(pStmt, j, sqlite3_value_int64(apData[i]));
          break;
        }
        case SQLITE_FLOAT: {
          sqlite3_bind_double(pStmt, j, sqlite3_value_double(apData[i]));
          break;
        }
        case SQLITE_NULL: {
          sqlite3_bind_null(pStmt, j);
          break;
        }
        case SQLITE_TEXT: {
          sqlite3_bind_text(pStmt, j, sqlite3_value_text(apData[i]),
                            sqlite3_value_bytes(apData[i]), SQLITE_TRANSIENT);
          break;
        }
        case SQLITE_BLOB: {
          sqlite3_bind_blob(pStmt, j, sqlite3_value_blob(apData[i]),
                            sqlite3_value_bytes(apData[i]), SQLITE_TRANSIENT);
          break;
        }
      }
      j++;
    }
    sqlite3_step(pStmt);
    rc = sqlite3_finalize(pStmt);
    return rc;
  }

  /* If apData[0] is an integer, delete the identified row */
  if( sqlite3_value_type(apData[0])==SQLITE_INTEGER ){
    const char *zFormat = "DELETE FROM %Q WHERE rowid = ?";
    char *zDelete = sqlite3_mprintf(zFormat, pVtab->zTableName);
    if( !zDelete ){
      rc = SQLITE_NOMEM;