OLD | NEW |
1 /* | 1 /* |
2 ** 2005 February 15 | 2 ** 2005 February 15 |
3 ** | 3 ** |
4 ** The author disclaims copyright to this source code. In place of | 4 ** The author disclaims copyright to this source code. In place of |
5 ** a legal notice, here is a blessing: | 5 ** a legal notice, here is a blessing: |
6 ** | 6 ** |
7 ** May you do good and not evil. | 7 ** May you do good and not evil. |
8 ** May you find forgiveness for yourself and forgive others. | 8 ** May you find forgiveness for yourself and forgive others. |
9 ** May you share freely, never taking more than you give. | 9 ** May you share freely, never taking more than you give. |
10 ** | 10 ** |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 if( zInput==0 || zOld==0 ) return; | 119 if( zInput==0 || zOld==0 ) return; |
120 for(z=zInput; *z; z=z+n){ | 120 for(z=zInput; *z; z=z+n){ |
121 n = sqlite3GetToken(z, &token); | 121 n = sqlite3GetToken(z, &token); |
122 if( token==TK_REFERENCES ){ | 122 if( token==TK_REFERENCES ){ |
123 char *zParent; | 123 char *zParent; |
124 do { | 124 do { |
125 z += n; | 125 z += n; |
126 n = sqlite3GetToken(z, &token); | 126 n = sqlite3GetToken(z, &token); |
127 }while( token==TK_SPACE ); | 127 }while( token==TK_SPACE ); |
128 | 128 |
| 129 if( token==TK_ILLEGAL ) break; |
129 zParent = sqlite3DbStrNDup(db, (const char *)z, n); | 130 zParent = sqlite3DbStrNDup(db, (const char *)z, n); |
130 if( zParent==0 ) break; | 131 if( zParent==0 ) break; |
131 sqlite3Dequote(zParent); | 132 sqlite3Dequote(zParent); |
132 if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){ | 133 if( 0==sqlite3StrICmp((const char *)zOld, zParent) ){ |
133 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"", | 134 char *zOut = sqlite3MPrintf(db, "%s%.*s\"%w\"", |
134 (zOutput?zOutput:""), (int)(z-zInput), zInput, (const char *)zNew | 135 (zOutput?zOutput:""), (int)(z-zInput), zInput, (const char *)zNew |
135 ); | 136 ); |
136 sqlite3DbFree(db, zOutput); | 137 sqlite3DbFree(db, zOutput); |
137 zOutput = zOut; | 138 zOutput = zOut; |
138 zInput = &z[n]; | 139 zInput = &z[n]; |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 sqlite3ChangeCookie(pParse, iDb); | 484 sqlite3ChangeCookie(pParse, iDb); |
484 | 485 |
485 /* If this is a virtual table, invoke the xRename() function if | 486 /* If this is a virtual table, invoke the xRename() function if |
486 ** one is defined. The xRename() callback will modify the names | 487 ** one is defined. The xRename() callback will modify the names |
487 ** of any resources used by the v-table implementation (including other | 488 ** of any resources used by the v-table implementation (including other |
488 ** SQLite tables) that are identified by the name of the virtual table. | 489 ** SQLite tables) that are identified by the name of the virtual table. |
489 */ | 490 */ |
490 #ifndef SQLITE_OMIT_VIRTUALTABLE | 491 #ifndef SQLITE_OMIT_VIRTUALTABLE |
491 if( pVTab ){ | 492 if( pVTab ){ |
492 int i = ++pParse->nMem; | 493 int i = ++pParse->nMem; |
493 sqlite3VdbeAddOp4(v, OP_String8, 0, i, 0, zName, 0); | 494 sqlite3VdbeLoadString(v, i, zName); |
494 sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB); | 495 sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB); |
495 sqlite3MayAbort(pParse); | 496 sqlite3MayAbort(pParse); |
496 } | 497 } |
497 #endif | 498 #endif |
498 | 499 |
499 /* figure out how many UTF-8 characters are in zName */ | 500 /* figure out how many UTF-8 characters are in zName */ |
500 zTabName = pTab->zName; | 501 zTabName = pTab->zName; |
501 nTabName = sqlite3Utf8CharLen(zTabName, -1); | 502 nTabName = sqlite3Utf8CharLen(zTabName, -1); |
502 | 503 |
503 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) | 504 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 */ | 595 */ |
595 void sqlite3MinimumFileFormat(Parse *pParse, int iDb, int minFormat){ | 596 void sqlite3MinimumFileFormat(Parse *pParse, int iDb, int minFormat){ |
596 Vdbe *v; | 597 Vdbe *v; |
597 v = sqlite3GetVdbe(pParse); | 598 v = sqlite3GetVdbe(pParse); |
598 /* The VDBE should have been allocated before this routine is called. | 599 /* The VDBE should have been allocated before this routine is called. |
599 ** If that allocation failed, we would have quit before reaching this | 600 ** If that allocation failed, we would have quit before reaching this |
600 ** point */ | 601 ** point */ |
601 if( ALWAYS(v) ){ | 602 if( ALWAYS(v) ){ |
602 int r1 = sqlite3GetTempReg(pParse); | 603 int r1 = sqlite3GetTempReg(pParse); |
603 int r2 = sqlite3GetTempReg(pParse); | 604 int r2 = sqlite3GetTempReg(pParse); |
604 int j1; | 605 int addr1; |
605 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT); | 606 sqlite3VdbeAddOp3(v, OP_ReadCookie, iDb, r1, BTREE_FILE_FORMAT); |
606 sqlite3VdbeUsesBtree(v, iDb); | 607 sqlite3VdbeUsesBtree(v, iDb); |
607 sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2); | 608 sqlite3VdbeAddOp2(v, OP_Integer, minFormat, r2); |
608 j1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1); | 609 addr1 = sqlite3VdbeAddOp3(v, OP_Ge, r2, 0, r1); |
609 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); VdbeCoverage(v); | 610 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL); VdbeCoverage(v); |
610 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2); | 611 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, r2); |
611 sqlite3VdbeJumpHere(v, j1); | 612 sqlite3VdbeJumpHere(v, addr1); |
612 sqlite3ReleaseTempReg(pParse, r1); | 613 sqlite3ReleaseTempReg(pParse, r1); |
613 sqlite3ReleaseTempReg(pParse, r2); | 614 sqlite3ReleaseTempReg(pParse, r2); |
614 } | 615 } |
615 } | 616 } |
616 | 617 |
617 /* | 618 /* |
618 ** This function is called after an "ALTER TABLE ... ADD" statement | 619 ** This function is called after an "ALTER TABLE ... ADD" statement |
619 ** has been parsed. Argument pColDef contains the text of the new | 620 ** has been parsed. Argument pColDef contains the text of the new |
620 ** column definition. | 621 ** column definition. |
621 ** | 622 ** |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 sqlite3ErrorMsg(pParse, | 684 sqlite3ErrorMsg(pParse, |
684 "Cannot add a NOT NULL column with default value NULL"); | 685 "Cannot add a NOT NULL column with default value NULL"); |
685 return; | 686 return; |
686 } | 687 } |
687 | 688 |
688 /* Ensure the default expression is something that sqlite3ValueFromExpr() | 689 /* Ensure the default expression is something that sqlite3ValueFromExpr() |
689 ** can handle (i.e. not CURRENT_TIME etc.) | 690 ** can handle (i.e. not CURRENT_TIME etc.) |
690 */ | 691 */ |
691 if( pDflt ){ | 692 if( pDflt ){ |
692 sqlite3_value *pVal = 0; | 693 sqlite3_value *pVal = 0; |
693 if( sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_NONE, &pVal) ){ | 694 int rc; |
| 695 rc = sqlite3ValueFromExpr(db, pDflt, SQLITE_UTF8, SQLITE_AFF_BLOB, &pVal); |
| 696 assert( rc==SQLITE_OK || rc==SQLITE_NOMEM ); |
| 697 if( rc!=SQLITE_OK ){ |
694 db->mallocFailed = 1; | 698 db->mallocFailed = 1; |
695 return; | 699 return; |
696 } | 700 } |
697 if( !pVal ){ | 701 if( !pVal ){ |
698 sqlite3ErrorMsg(pParse, "Cannot add a column with non-constant default"); | 702 sqlite3ErrorMsg(pParse, "Cannot add a column with non-constant default"); |
699 return; | 703 return; |
700 } | 704 } |
701 sqlite3ValueFree(pVal); | 705 sqlite3ValueFree(pVal); |
702 } | 706 } |
703 | 707 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 sqlite3BeginWriteOperation(pParse, 0, iDb); | 823 sqlite3BeginWriteOperation(pParse, 0, iDb); |
820 v = sqlite3GetVdbe(pParse); | 824 v = sqlite3GetVdbe(pParse); |
821 if( !v ) goto exit_begin_add_column; | 825 if( !v ) goto exit_begin_add_column; |
822 sqlite3ChangeCookie(pParse, iDb); | 826 sqlite3ChangeCookie(pParse, iDb); |
823 | 827 |
824 exit_begin_add_column: | 828 exit_begin_add_column: |
825 sqlite3SrcListDelete(db, pSrc); | 829 sqlite3SrcListDelete(db, pSrc); |
826 return; | 830 return; |
827 } | 831 } |
828 #endif /* SQLITE_ALTER_TABLE */ | 832 #endif /* SQLITE_ALTER_TABLE */ |
OLD | NEW |