~ubuntu-branches/ubuntu/hardy/sqlite3/hardy

« back to all changes in this revision

Viewing changes to src/insert.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-07-23 14:35:04 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20070723143504-v52h2illx871jas3
Tags: 3.4.1-0ubuntu1
New upstream release. Closes LP: #127223.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
** This file contains C code routines that are called by the parser
13
13
** to handle INSERT statements in SQLite.
14
14
**
15
 
** $Id: insert.c,v 1.186 2007/05/04 13:15:56 drh Exp $
 
15
** $Id: insert.c,v 1.187 2007/06/26 10:38:55 danielk1977 Exp $
16
16
*/
17
17
#include "sqliteInt.h"
18
18
 
349
349
  int appendFlag = 0;   /* True if the insert is likely to be an append */
350
350
  int iDb;
351
351
 
 
352
  int nHidden = 0;
 
353
 
352
354
#ifndef SQLITE_OMIT_TRIGGER
353
355
  int isView;                 /* True if attempting to insert into a view */
354
356
  int triggers_exist = 0;     /* True if there are FOR EACH ROW triggers */
525
527
  /* Make sure the number of columns in the source data matches the number
526
528
  ** of columns to be inserted into the table.
527
529
  */
528
 
  if( pColumn==0 && nColumn && nColumn!=pTab->nCol ){
 
530
  if( IsVirtual(pTab) ){
 
531
    for(i=0; i<pTab->nCol; i++){
 
532
      nHidden += (IsHiddenColumn(&pTab->aCol[i]) ? 1 : 0);
 
533
    }
 
534
  }
 
535
  if( pColumn==0 && nColumn && nColumn!=(pTab->nCol-nHidden) ){
529
536
    sqlite3ErrorMsg(pParse, 
530
537
       "table %S has %d columns but %d values were supplied",
531
538
       pTabList, 0, pTab->nCol, nColumn);
640
647
      sqlite3VdbeAddOp(v, OP_MustBeInt, 0, 0);
641
648
    }
642
649
 
 
650
    /* Cannot have triggers on a virtual table. If it were possible,
 
651
    ** this block would have to account for hidden column.
 
652
    */
 
653
    assert(!IsVirtual(pTab));
 
654
 
643
655
    /* Create the new column data
644
656
    */
645
657
    for(i=0; i<pTab->nCol; i++){
732
744
    /* Push onto the stack, data for all columns of the new entry, beginning
733
745
    ** with the first column.
734
746
    */
 
747
    nHidden = 0;
735
748
    for(i=0; i<pTab->nCol; i++){
736
749
      if( i==pTab->iPKey ){
737
750
        /* The value of the INTEGER PRIMARY KEY column is always a NULL.
742
755
        continue;
743
756
      }
744
757
      if( pColumn==0 ){
745
 
        j = i;
 
758
        if( IsHiddenColumn(&pTab->aCol[i]) ){
 
759
          assert( IsVirtual(pTab) );
 
760
          j = -1;
 
761
          nHidden++;
 
762
        }else{
 
763
          j = i - nHidden;
 
764
        }
746
765
      }else{
747
766
        for(j=0; j<pColumn->nId; j++){
748
767
          if( pColumn->a[j].idx==i ) break;
749
768
        }
750
769
      }
751
 
      if( nColumn==0 || (pColumn && j>=pColumn->nId) ){
 
770
      if( j<0 || nColumn==0 || (pColumn && j>=pColumn->nId) ){
752
771
        sqlite3ExprCode(pParse, pTab->aCol[i].pDflt);
753
772
      }else if( useTempTable ){
754
773
        sqlite3VdbeAddOp(v, OP_Column, srcTab, j);