Fossil SCM

Pull the latest trunk version of SQLite from upstream.

drh 2013-01-07 14:45 trunk
Commit 9ae863a5eb004f94031476536ab9d9b99398606e
3 files changed +6 +208 -104 +1 -1
--- src/shell.c
+++ src/shell.c
@@ -1477,10 +1477,16 @@
14771477
p->zDbFilename, sqlite3_errmsg(db));
14781478
exit(1);
14791479
}
14801480
#ifndef SQLITE_OMIT_LOAD_EXTENSION
14811481
sqlite3_enable_load_extension(p->db, 1);
1482
+#endif
1483
+#ifdef SQLITE_ENABLE_REGEXP
1484
+ {
1485
+ extern int sqlite3_add_regexp_func(sqlite3*);
1486
+ sqlite3_add_regexp_func(db);
1487
+ }
14821488
#endif
14831489
}
14841490
}
14851491
14861492
/*
14871493
--- src/shell.c
+++ src/shell.c
@@ -1477,10 +1477,16 @@
1477 p->zDbFilename, sqlite3_errmsg(db));
1478 exit(1);
1479 }
1480 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1481 sqlite3_enable_load_extension(p->db, 1);
 
 
 
 
 
 
1482 #endif
1483 }
1484 }
1485
1486 /*
1487
--- src/shell.c
+++ src/shell.c
@@ -1477,10 +1477,16 @@
1477 p->zDbFilename, sqlite3_errmsg(db));
1478 exit(1);
1479 }
1480 #ifndef SQLITE_OMIT_LOAD_EXTENSION
1481 sqlite3_enable_load_extension(p->db, 1);
1482 #endif
1483 #ifdef SQLITE_ENABLE_REGEXP
1484 {
1485 extern int sqlite3_add_regexp_func(sqlite3*);
1486 sqlite3_add_regexp_func(db);
1487 }
1488 #endif
1489 }
1490 }
1491
1492 /*
1493
+208 -104
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -673,11 +673,11 @@
673673
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674674
** [sqlite_version()] and [sqlite_source_id()].
675675
*/
676676
#define SQLITE_VERSION "3.7.16"
677677
#define SQLITE_VERSION_NUMBER 3007016
678
-#define SQLITE_SOURCE_ID "2012-12-21 16:15:35 ff6857b6ed6a46671006b75157d8cf853a816ef9"
678
+#define SQLITE_SOURCE_ID "2013-01-07 13:26:23 0a1207c895d9f77586a3a2a4965175909be90503"
679679
680680
/*
681681
** CAPI3REF: Run-Time Library Version Numbers
682682
** KEYWORDS: sqlite3_version, sqlite3_sourceid
683683
**
@@ -10553,24 +10553,24 @@
1055310553
** and the value of Index.onError indicate the which conflict resolution
1055410554
** algorithm to employ whenever an attempt is made to insert a non-unique
1055510555
** element.
1055610556
*/
1055710557
struct Index {
10558
- char *zName; /* Name of this index */
10559
- int *aiColumn; /* Which columns are used by this index. 1st is 0 */
10560
- tRowcnt *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
10561
- Table *pTable; /* The SQL table being indexed */
10562
- char *zColAff; /* String defining the affinity of each column */
10563
- Index *pNext; /* The next index associated with the same table */
10564
- Schema *pSchema; /* Schema containing this index */
10565
- u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */
10566
- char **azColl; /* Array of collation sequence names for index */
10567
- int nColumn; /* Number of columns in the table used by this index */
10568
- int tnum; /* Page containing root of this index in database file */
10569
- u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
10570
- u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
10571
- u8 bUnordered; /* Use this index for == or IN queries only */
10558
+ char *zName; /* Name of this index */
10559
+ int *aiColumn; /* Which columns are used by this index. 1st is 0 */
10560
+ tRowcnt *aiRowEst; /* From ANALYZE: Est. rows selected by each column */
10561
+ Table *pTable; /* The SQL table being indexed */
10562
+ char *zColAff; /* String defining the affinity of each column */
10563
+ Index *pNext; /* The next index associated with the same table */
10564
+ Schema *pSchema; /* Schema containing this index */
10565
+ u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
10566
+ char **azColl; /* Array of collation sequence names for index */
10567
+ int tnum; /* DB Page containing root of this index */
10568
+ u16 nColumn; /* Number of columns in table used by this index */
10569
+ u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
10570
+ unsigned autoIndex:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
10571
+ unsigned bUnordered:1; /* Use this index for == or IN queries only */
1057210572
#ifdef SQLITE_ENABLE_STAT3
1057310573
int nSample; /* Number of elements in aSample[] */
1057410574
tRowcnt avgEq; /* Average nEq value for key values not in aSample */
1057510575
IndexSample *aSample; /* Samples of the left-most key */
1057610576
#endif
@@ -10840,22 +10840,31 @@
1084010840
** name. An expr/name combination can be used in several ways, such
1084110841
** as the list of "expr AS ID" fields following a "SELECT" or in the
1084210842
** list of "ID = expr" items in an UPDATE. A list of expressions can
1084310843
** also be used as the argument to a function, in which case the a.zName
1084410844
** field is not used.
10845
+**
10846
+** By default the Expr.zSpan field holds a human-readable description of
10847
+** the expression that is used in the generation of error messages and
10848
+** column labels. In this case, Expr.zSpan is typically the text of a
10849
+** column expression as it exists in a SELECT statement. However, if
10850
+** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name
10851
+** of the result column in the form: DATABASE.TABLE.COLUMN. This later
10852
+** form is used for name resolution with nested FROM clauses.
1084510853
*/
1084610854
struct ExprList {
1084710855
int nExpr; /* Number of expressions on the list */
1084810856
int iECursor; /* VDBE Cursor associated with this ExprList */
1084910857
struct ExprList_item { /* For each expression in the list */
10850
- Expr *pExpr; /* The list of expressions */
10851
- char *zName; /* Token associated with this expression */
10852
- char *zSpan; /* Original text of the expression */
10853
- u8 sortOrder; /* 1 for DESC or 0 for ASC */
10854
- u8 done; /* A flag to indicate when processing is finished */
10855
- u16 iOrderByCol; /* For ORDER BY, column number in result set */
10856
- u16 iAlias; /* Index into Parse.aAlias[] for zName */
10858
+ Expr *pExpr; /* The list of expressions */
10859
+ char *zName; /* Token associated with this expression */
10860
+ char *zSpan; /* Original text of the expression */
10861
+ u8 sortOrder; /* 1 for DESC or 0 for ASC */
10862
+ unsigned done :1; /* A flag to indicate when processing is finished */
10863
+ unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
10864
+ u16 iOrderByCol; /* For ORDER BY, column number in result set */
10865
+ u16 iAlias; /* Index into Parse.aAlias[] for zName */
1085710866
} *a; /* Alloc a power of two greater or equal to nExpr */
1085810867
};
1085910868
1086010869
/*
1086110870
** An instance of this structure is used by the parser to record both
@@ -12141,10 +12150,11 @@
1214112150
SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
1214212151
SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
1214312152
SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*);
1214412153
SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *, Expr *, int, int);
1214512154
SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
12155
+SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
1214612156
SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
1214712157
SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
1214812158
SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
1214912159
SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
1215012160
SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *);
@@ -23289,15 +23299,11 @@
2328923299
{ "pwrite64", (sqlite3_syscall_ptr)0, 0 },
2329023300
#endif
2329123301
#define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\
2329223302
aSyscall[13].pCurrent)
2329323303
23294
-#if SQLITE_ENABLE_LOCKING_STYLE
2329523304
{ "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
23296
-#else
23297
- { "fchmod", (sqlite3_syscall_ptr)0, 0 },
23298
-#endif
2329923305
#define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
2330023306
2330123307
#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
2330223308
{ "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 },
2330323309
#else
@@ -23318,13 +23324,10 @@
2331823324
#define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent)
2331923325
2332023326
{ "fchown", (sqlite3_syscall_ptr)posixFchown, 0 },
2332123327
#define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)
2332223328
23323
- { "umask", (sqlite3_syscall_ptr)umask, 0 },
23324
-#define osUmask ((mode_t(*)(mode_t))aSyscall[21].pCurrent)
23325
-
2332623329
}; /* End of the overrideable system calls */
2332723330
2332823331
/*
2332923332
** This is the xSetSystemCall() method of sqlite3_vfs for all of the
2333023333
** "unix" VFSes. Return SQLITE_OK opon successfully updating the
@@ -23425,31 +23428,29 @@
2342523428
** process that is able to write to the database will also be able to
2342623429
** recover the hot journals.
2342723430
*/
2342823431
static int robust_open(const char *z, int f, mode_t m){
2342923432
int fd;
23430
- mode_t m2;
23431
- mode_t origM = 0;
23432
- if( m==0 ){
23433
- m2 = SQLITE_DEFAULT_FILE_PERMISSIONS;
23434
- }else{
23435
- m2 = m;
23436
- origM = osUmask(0);
23437
- }
23433
+ mode_t m2 = m ? m : SQLITE_DEFAULT_FILE_PERMISSIONS;
2343823434
do{
2343923435
#if defined(O_CLOEXEC)
2344023436
fd = osOpen(z,f|O_CLOEXEC,m2);
2344123437
#else
2344223438
fd = osOpen(z,f,m2);
2344323439
#endif
2344423440
}while( fd<0 && errno==EINTR );
23445
- if( m ){
23446
- osUmask(origM);
23447
- }
23441
+ if( fd>=0 ){
23442
+ if( m!=0 ){
23443
+ struct stat statbuf;
23444
+ if( osFstat(fd, &statbuf)==0 && (statbuf.st_mode&0777)!=m ){
23445
+ osFchmod(fd, m);
23446
+ }
23447
+ }
2344823448
#if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
23449
- if( fd>=0 ) osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
23449
+ osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
2345023450
#endif
23451
+ }
2345123452
return fd;
2345223453
}
2345323454
2345423455
/*
2345523456
** Helper functions to obtain and relinquish the global mutex. The
@@ -29871,11 +29872,11 @@
2987129872
};
2987229873
unsigned int i; /* Loop counter */
2987329874
2987429875
/* Double-check that the aSyscall[] array has been constructed
2987529876
** correctly. See ticket [bb3a86e890c8e96ab] */
29876
- assert( ArraySize(aSyscall)==22 );
29877
+ assert( ArraySize(aSyscall)==21 );
2987729878
2987829879
/* Register all VFSes defined in the aVfs[] array */
2987929880
for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
2988029881
sqlite3_vfs_register(&aVfs[i], i==0);
2988129882
}
@@ -72655,10 +72656,39 @@
7265572656
}
7265672657
}
7265772658
return 0;
7265872659
}
7265972660
72661
+/*
72662
+** Subqueries stores the original database, table and column names for their
72663
+** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN".
72664
+** Check to see if the zSpan given to this routine matches the zDb, zTab,
72665
+** and zCol. If any of zDb, zTab, and zCol are NULL then those fields will
72666
+** match anything.
72667
+*/
72668
+SQLITE_PRIVATE int sqlite3MatchSpanName(
72669
+ const char *zSpan,
72670
+ const char *zCol,
72671
+ const char *zTab,
72672
+ const char *zDb
72673
+){
72674
+ int n;
72675
+ for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
72676
+ if( zDb && sqlite3StrNICmp(zSpan, zDb, n)!=0 ){
72677
+ return 0;
72678
+ }
72679
+ zSpan += n+1;
72680
+ for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
72681
+ if( zTab && sqlite3StrNICmp(zSpan, zTab, n)!=0 ){
72682
+ return 0;
72683
+ }
72684
+ zSpan += n+1;
72685
+ if( zCol && sqlite3StrICmp(zSpan, zCol)!=0 ){
72686
+ return 0;
72687
+ }
72688
+ return 1;
72689
+}
7266072690
7266172691
/*
7266272692
** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up
7266372693
** that name in the set of source tables in pSrcList and make the pExpr
7266472694
** expression node refer back to that source column. The following changes
@@ -72710,44 +72740,63 @@
7271072740
7271172741
/* Initialize the node to no-match */
7271272742
pExpr->iTable = -1;
7271372743
pExpr->pTab = 0;
7271472744
ExprSetIrreducible(pExpr);
72745
+
72746
+ /* Translate the schema name in zDb into a pointer to the corresponding
72747
+ ** schema. If not found, pSchema will remain NULL and nothing will match
72748
+ ** resulting in an appropriate error message toward the end of this routine
72749
+ */
72750
+ if( zDb ){
72751
+ for(i=0; i<db->nDb; i++){
72752
+ assert( db->aDb[i].zName );
72753
+ if( sqlite3StrICmp(db->aDb[i].zName,zDb)==0 ){
72754
+ pSchema = db->aDb[i].pSchema;
72755
+ break;
72756
+ }
72757
+ }
72758
+ }
7271572759
7271672760
/* Start at the inner-most context and move outward until a match is found */
7271772761
while( pNC && cnt==0 ){
7271872762
ExprList *pEList;
7271972763
SrcList *pSrcList = pNC->pSrcList;
7272072764
7272172765
if( pSrcList ){
7272272766
for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
7272372767
Table *pTab;
72724
- int iDb;
7272572768
Column *pCol;
7272672769
7272772770
pTab = pItem->pTab;
7272872771
assert( pTab!=0 && pTab->zName!=0 );
72729
- iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
7273072772
assert( pTab->nCol>0 );
72773
+ if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){
72774
+ ExprList *pEList = pItem->pSelect->pEList;
72775
+ int hit = 0;
72776
+ for(j=0; j<pEList->nExpr; j++){
72777
+ if( sqlite3MatchSpanName(pEList->a[j].zSpan, zCol, zTab, zDb) ){
72778
+ cnt++;
72779
+ cntTab = 2;
72780
+ pMatch = pItem;
72781
+ pExpr->iColumn = j;
72782
+ hit = 1;
72783
+ }
72784
+ }
72785
+ if( hit || zTab==0 ) continue;
72786
+ }
72787
+ if( zDb && pTab->pSchema!=pSchema ){
72788
+ continue;
72789
+ }
7273172790
if( zTab ){
72732
- if( pItem->zAlias ){
72733
- char *zTabName = pItem->zAlias;
72734
- if( sqlite3StrICmp(zTabName, zTab)!=0 ) continue;
72735
- }else{
72736
- char *zTabName = pTab->zName;
72737
- if( NEVER(zTabName==0) || sqlite3StrICmp(zTabName, zTab)!=0 ){
72738
- continue;
72739
- }
72740
- if( zDb!=0 && sqlite3StrICmp(db->aDb[iDb].zName, zDb)!=0 ){
72741
- continue;
72742
- }
72791
+ const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName;
72792
+ assert( zTabName!=0 );
72793
+ if( sqlite3StrICmp(zTabName, zTab)!=0 ){
72794
+ continue;
7274372795
}
7274472796
}
7274572797
if( 0==(cntTab++) ){
72746
- pExpr->iTable = pItem->iCursor;
72747
- pExpr->pTab = pTab;
72748
- pSchema = pTab->pSchema;
7274972798
pMatch = pItem;
7275072799
}
7275172800
for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
7275272801
if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
7275372802
/* If there has been exactly one prior match and this match
@@ -72757,21 +72806,23 @@
7275772806
if( cnt==1 ){
7275872807
if( pItem->jointype & JT_NATURAL ) continue;
7275972808
if( nameInUsingClause(pItem->pUsing, zCol) ) continue;
7276072809
}
7276172810
cnt++;
72762
- pExpr->iTable = pItem->iCursor;
72763
- pExpr->pTab = pTab;
7276472811
pMatch = pItem;
72765
- pSchema = pTab->pSchema;
7276672812
/* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
7276772813
pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
7276872814
break;
7276972815
}
7277072816
}
7277172817
}
72772
- }
72818
+ if( pMatch ){
72819
+ pExpr->iTable = pMatch->iCursor;
72820
+ pExpr->pTab = pMatch->pTab;
72821
+ pSchema = pExpr->pTab->pSchema;
72822
+ }
72823
+ } /* if( pSrcList ) */
7277372824
7277472825
#ifndef SQLITE_OMIT_TRIGGER
7277572826
/* If we have not already resolved the name, then maybe
7277672827
** it is a new.* or old.* trigger argument reference
7277772828
*/
@@ -73066,42 +73117,43 @@
7306673117
int wrong_num_args = 0; /* True if wrong number of arguments */
7306773118
int is_agg = 0; /* True if is an aggregate function */
7306873119
int auth; /* Authorization to use the function */
7306973120
int nId; /* Number of characters in function name */
7307073121
const char *zId; /* The function name. */
73071
- FuncDef *pDef; /* Information about the function */
7307273122
u8 enc = ENC(pParse->db); /* The database encoding */
7307373123
7307473124
testcase( pExpr->op==TK_CONST_FUNC );
7307573125
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
7307673126
zId = pExpr->u.zToken;
7307773127
nId = sqlite3Strlen30(zId);
73078
- pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
73079
- if( pDef==0 ){
73080
- pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
73081
- if( pDef==0 ){
73082
- no_such_func = 1;
73083
- }else{
73084
- wrong_num_args = 1;
73085
- }
73086
- }else{
73087
- is_agg = pDef->xFunc==0;
73088
- }
73089
-#ifndef SQLITE_OMIT_AUTHORIZATION
73090
- if( pDef ){
73091
- auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
73092
- if( auth!=SQLITE_OK ){
73093
- if( auth==SQLITE_DENY ){
73094
- sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
73095
- pDef->zName);
73096
- pNC->nErr++;
73097
- }
73098
- pExpr->op = TK_NULL;
73099
- return WRC_Prune;
73100
- }
73101
- }
73102
-#endif
73128
+ if( pParse->db->init.busy==0 ){
73129
+ FuncDef *pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
73130
+ if( pDef==0 ){
73131
+ pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
73132
+ if( pDef==0 ){
73133
+ no_such_func = 1;
73134
+ }else{
73135
+ wrong_num_args = 1;
73136
+ }
73137
+ }else{
73138
+ is_agg = pDef->xFunc==0;
73139
+ }
73140
+#ifndef SQLITE_OMIT_AUTHORIZATION
73141
+ if( pDef ){
73142
+ auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
73143
+ if( auth!=SQLITE_OK ){
73144
+ if( auth==SQLITE_DENY ){
73145
+ sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
73146
+ pDef->zName);
73147
+ pNC->nErr++;
73148
+ }
73149
+ pExpr->op = TK_NULL;
73150
+ return WRC_Prune;
73151
+ }
73152
+ }
73153
+#endif
73154
+ }
7310373155
if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
7310473156
sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
7310573157
pNC->nErr++;
7310673158
is_agg = 0;
7310773159
}else if( no_such_func ){
@@ -77065,10 +77117,16 @@
7706577117
for(i=0; i<pList->nExpr; i++){
7706677118
sqlite3ExplainPrintf(pOut, "item[%d] = ", i);
7706777119
sqlite3ExplainPush(pOut);
7706877120
sqlite3ExplainExpr(pOut, pList->a[i].pExpr);
7706977121
sqlite3ExplainPop(pOut);
77122
+ if( pList->a[i].zName ){
77123
+ sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName);
77124
+ }
77125
+ if( pList->a[i].bSpanIsTab ){
77126
+ sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan);
77127
+ }
7707077128
if( i<pList->nExpr-1 ){
7707177129
sqlite3ExplainNL(pOut);
7707277130
}
7707377131
}
7707477132
sqlite3ExplainPop(pOut);
@@ -92739,13 +92797,15 @@
9273992797
if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
9274092798
Table *pTab;
9274192799
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
9274292800
pTab = sqlite3FindTable(db, zRight, zDb);
9274392801
if( pTab ){
92744
- int i;
92802
+ int i, k;
9274592803
int nHidden = 0;
9274692804
Column *pCol;
92805
+ Index *pPk;
92806
+ for(pPk=pTab->pIndex; pPk && pPk->autoIndex!=2; pPk=pPk->pNext){}
9274792807
sqlite3VdbeSetNumCols(v, 6);
9274892808
pParse->nMem = 6;
9274992809
sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
9275092810
sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
9275192811
sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
@@ -92766,12 +92826,18 @@
9276692826
if( pCol->zDflt ){
9276792827
sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0);
9276892828
}else{
9276992829
sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
9277092830
}
92771
- sqlite3VdbeAddOp2(v, OP_Integer,
92772
- (pCol->colFlags&COLFLAG_PRIMKEY)!=0, 6);
92831
+ if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
92832
+ k = 0;
92833
+ }else if( pPk==0 ){
92834
+ k = 1;
92835
+ }else{
92836
+ for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){}
92837
+ }
92838
+ sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
9277392839
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
9277492840
}
9277592841
}
9277692842
}else
9277792843
@@ -95756,12 +95822,10 @@
9575695822
9575795823
for(i=0, pCol=aCol; i<nCol; i++, pCol++){
9575895824
/* Get an appropriate name for the column
9575995825
*/
9576095826
p = sqlite3ExprSkipCollate(pEList->a[i].pExpr);
95761
- assert( p->pRight==0 || ExprHasProperty(p->pRight, EP_IntValue)
95762
- || p->pRight->u.zToken==0 || p->pRight->u.zToken[0]!=0 );
9576395827
if( (zName = pEList->a[i].zName)!=0 ){
9576495828
/* If the column contains an "AS <name>" phrase, use <name> as the name */
9576595829
zName = sqlite3DbStrDup(db, zName);
9576695830
}else{
9576795831
Expr *pColExpr = p; /* The expression that is the result column name */
@@ -95795,10 +95859,13 @@
9579595859
*/
9579695860
nName = sqlite3Strlen30(zName);
9579795861
for(j=cnt=0; j<i; j++){
9579895862
if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){
9579995863
char *zNewName;
95864
+ int k;
95865
+ for(k=nName-1; k>1 && sqlite3Isdigit(zName[k]); k--){}
95866
+ if( zName[k]==':' ) nName = k;
9580095867
zName[nName] = 0;
9580195868
zNewName = sqlite3MPrintf(db, "%s:%d", zName, ++cnt);
9580295869
sqlite3DbFree(db, zName);
9580395870
zName = zNewName;
9580495871
j = -1;
@@ -97711,10 +97778,11 @@
9771197778
int i, j, k;
9771297779
SrcList *pTabList;
9771397780
ExprList *pEList;
9771497781
struct SrcList_item *pFrom;
9771597782
sqlite3 *db = pParse->db;
97783
+ Expr *pE, *pRight, *pExpr;
9771697784
9771797785
if( db->mallocFailed ){
9771897786
return WRC_Abort;
9771997787
}
9772097788
if( NEVER(p->pSrc==0) || (p->selFlags & SF_Expanded)!=0 ){
@@ -97796,11 +97864,11 @@
9779697864
**
9779797865
** The first loop just checks to see if there are any "*" operators
9779897866
** that need expanding.
9779997867
*/
9780097868
for(k=0; k<pEList->nExpr; k++){
97801
- Expr *pE = pEList->a[k].pExpr;
97869
+ pE = pEList->a[k].pExpr;
9780297870
if( pE->op==TK_ALL ) break;
9780397871
assert( pE->op!=TK_DOT || pE->pRight!=0 );
9780497872
assert( pE->op!=TK_DOT || (pE->pLeft!=0 && pE->pLeft->op==TK_ID) );
9780597873
if( pE->op==TK_DOT && pE->pRight->op==TK_ALL ) break;
9780697874
}
@@ -97814,14 +97882,22 @@
9781497882
ExprList *pNew = 0;
9781597883
int flags = pParse->db->flags;
9781697884
int longNames = (flags & SQLITE_FullColNames)!=0
9781797885
&& (flags & SQLITE_ShortColNames)==0;
9781897886
97887
+ /* When processing FROM-clause subqueries, it is always the case
97888
+ ** that full_column_names=OFF and short_column_names=ON. The
97889
+ ** sqlite3ResultSetOfSelect() routine makes it so. */
97890
+ assert( (p->selFlags & SF_NestedFrom)==0
97891
+ || ((flags & SQLITE_FullColNames)==0 &&
97892
+ (flags & SQLITE_ShortColNames)!=0) );
97893
+
9781997894
for(k=0; k<pEList->nExpr; k++){
97820
- Expr *pE = a[k].pExpr;
97821
- assert( pE->op!=TK_DOT || pE->pRight!=0 );
97822
- if( pE->op!=TK_ALL && (pE->op!=TK_DOT || pE->pRight->op!=TK_ALL) ){
97895
+ pE = a[k].pExpr;
97896
+ pRight = pE->pRight;
97897
+ assert( pE->op!=TK_DOT || pRight!=0 );
97898
+ if( pE->op!=TK_ALL && (pE->op!=TK_DOT || pRight->op!=TK_ALL) ){
9782397899
/* This particular expression does not need to be expanded.
9782497900
*/
9782597901
pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
9782697902
if( pNew ){
9782797903
pNew->a[pNew->nExpr-1].zName = a[k].zName;
@@ -97832,44 +97908,56 @@
9783297908
a[k].pExpr = 0;
9783397909
}else{
9783497910
/* This expression is a "*" or a "TABLE.*" and needs to be
9783597911
** expanded. */
9783697912
int tableSeen = 0; /* Set to 1 when TABLE matches */
97837
- char *zTName; /* text of name of TABLE */
97913
+ char *zTName = 0; /* text of name of TABLE */
9783897914
if( pE->op==TK_DOT ){
9783997915
assert( pE->pLeft!=0 );
9784097916
assert( !ExprHasProperty(pE->pLeft, EP_IntValue) );
9784197917
zTName = pE->pLeft->u.zToken;
97842
- }else{
97843
- zTName = 0;
9784497918
}
9784597919
for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
9784697920
Table *pTab = pFrom->pTab;
97921
+ Select *pSub = pFrom->pSelect;
9784797922
char *zTabName = pFrom->zAlias;
97923
+ const char *zSchemaName = 0;
97924
+ int iDb;
9784897925
if( zTabName==0 ){
9784997926
zTabName = pTab->zName;
9785097927
}
9785197928
if( db->mallocFailed ) break;
97852
- if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
97853
- continue;
97929
+ if( pSub==0 || (pSub->selFlags & SF_NestedFrom)==0 ){
97930
+ pSub = 0;
97931
+ if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
97932
+ continue;
97933
+ }
97934
+ iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
97935
+ zSchemaName = iDb>=0 ? db->aDb[iDb].zName : "*";
9785497936
}
97855
- tableSeen = 1;
9785697937
for(j=0; j<pTab->nCol; j++){
97857
- Expr *pExpr, *pRight;
9785897938
char *zName = pTab->aCol[j].zName;
9785997939
char *zColname; /* The computed column name */
9786097940
char *zToFree; /* Malloced string that needs to be freed */
9786197941
Token sColname; /* Computed column name as a token */
97942
+
97943
+ assert( zName );
97944
+ if( zTName && pSub
97945
+ && sqlite3MatchSpanName(pSub->pEList->a[j].zSpan, 0, zTName, 0)==0
97946
+ ){
97947
+ continue;
97948
+ }
9786297949
9786397950
/* If a column is marked as 'hidden' (currently only possible
9786497951
** for virtual tables), do not include it in the expanded
9786597952
** result-set list.
9786697953
*/
9786797954
if( IsHiddenColumn(&pTab->aCol[j]) ){
9786897955
assert(IsVirtual(pTab));
9786997956
continue;
9787097957
}
97958
+ tableSeen = 1;
9787197959
9787297960
if( i>0 && zTName==0 ){
9787397961
if( (pFrom->jointype & JT_NATURAL)!=0
9787497962
&& tableAndColumnIndex(pTabList, i, zName, 0, 0)
9787597963
){
@@ -97888,10 +97976,14 @@
9788897976
zToFree = 0;
9788997977
if( longNames || pTabList->nSrc>1 ){
9789097978
Expr *pLeft;
9789197979
pLeft = sqlite3Expr(db, TK_ID, zTabName);
9789297980
pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
97981
+ if( zSchemaName ){
97982
+ pLeft = sqlite3Expr(db, TK_ID, zSchemaName);
97983
+ pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pExpr, 0);
97984
+ }
9789397985
if( longNames ){
9789497986
zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
9789597987
zToFree = zColname;
9789697988
}
9789797989
}else{
@@ -97899,10 +97991,22 @@
9789997991
}
9790097992
pNew = sqlite3ExprListAppend(pParse, pNew, pExpr);
9790197993
sColname.z = zColname;
9790297994
sColname.n = sqlite3Strlen30(zColname);
9790397995
sqlite3ExprListSetName(pParse, pNew, &sColname, 0);
97996
+ if( pNew && (p->selFlags & SF_NestedFrom)!=0 ){
97997
+ struct ExprList_item *pX = &pNew->a[pNew->nExpr-1];
97998
+ if( pSub ){
97999
+ pX->zSpan = sqlite3DbStrDup(db, pSub->pEList->a[j].zSpan);
98000
+ testcase( pX->zSpan==0 );
98001
+ }else{
98002
+ pX->zSpan = sqlite3MPrintf(db, "%s.%s.%s",
98003
+ zSchemaName, zTabName, zColname);
98004
+ testcase( pX->zSpan==0 );
98005
+ }
98006
+ pX->bSpanIsTab = 1;
98007
+ }
9790498008
sqlite3DbFree(db, zToFree);
9790598009
}
9790698010
}
9790798011
if( !tableSeen ){
9790898012
if( zTName ){
9790998013
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -673,11 +673,11 @@
673 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674 ** [sqlite_version()] and [sqlite_source_id()].
675 */
676 #define SQLITE_VERSION "3.7.16"
677 #define SQLITE_VERSION_NUMBER 3007016
678 #define SQLITE_SOURCE_ID "2012-12-21 16:15:35 ff6857b6ed6a46671006b75157d8cf853a816ef9"
679
680 /*
681 ** CAPI3REF: Run-Time Library Version Numbers
682 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
683 **
@@ -10553,24 +10553,24 @@
10553 ** and the value of Index.onError indicate the which conflict resolution
10554 ** algorithm to employ whenever an attempt is made to insert a non-unique
10555 ** element.
10556 */
10557 struct Index {
10558 char *zName; /* Name of this index */
10559 int *aiColumn; /* Which columns are used by this index. 1st is 0 */
10560 tRowcnt *aiRowEst; /* Result of ANALYZE: Est. rows selected by each column */
10561 Table *pTable; /* The SQL table being indexed */
10562 char *zColAff; /* String defining the affinity of each column */
10563 Index *pNext; /* The next index associated with the same table */
10564 Schema *pSchema; /* Schema containing this index */
10565 u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */
10566 char **azColl; /* Array of collation sequence names for index */
10567 int nColumn; /* Number of columns in the table used by this index */
10568 int tnum; /* Page containing root of this index in database file */
10569 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
10570 u8 autoIndex; /* True if is automatically created (ex: by UNIQUE) */
10571 u8 bUnordered; /* Use this index for == or IN queries only */
10572 #ifdef SQLITE_ENABLE_STAT3
10573 int nSample; /* Number of elements in aSample[] */
10574 tRowcnt avgEq; /* Average nEq value for key values not in aSample */
10575 IndexSample *aSample; /* Samples of the left-most key */
10576 #endif
@@ -10840,22 +10840,31 @@
10840 ** name. An expr/name combination can be used in several ways, such
10841 ** as the list of "expr AS ID" fields following a "SELECT" or in the
10842 ** list of "ID = expr" items in an UPDATE. A list of expressions can
10843 ** also be used as the argument to a function, in which case the a.zName
10844 ** field is not used.
 
 
 
 
 
 
 
 
10845 */
10846 struct ExprList {
10847 int nExpr; /* Number of expressions on the list */
10848 int iECursor; /* VDBE Cursor associated with this ExprList */
10849 struct ExprList_item { /* For each expression in the list */
10850 Expr *pExpr; /* The list of expressions */
10851 char *zName; /* Token associated with this expression */
10852 char *zSpan; /* Original text of the expression */
10853 u8 sortOrder; /* 1 for DESC or 0 for ASC */
10854 u8 done; /* A flag to indicate when processing is finished */
10855 u16 iOrderByCol; /* For ORDER BY, column number in result set */
10856 u16 iAlias; /* Index into Parse.aAlias[] for zName */
 
10857 } *a; /* Alloc a power of two greater or equal to nExpr */
10858 };
10859
10860 /*
10861 ** An instance of this structure is used by the parser to record both
@@ -12141,10 +12150,11 @@
12141 SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
12142 SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
12143 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*);
12144 SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *, Expr *, int, int);
12145 SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
 
12146 SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
12147 SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
12148 SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
12149 SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
12150 SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *);
@@ -23289,15 +23299,11 @@
23289 { "pwrite64", (sqlite3_syscall_ptr)0, 0 },
23290 #endif
23291 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\
23292 aSyscall[13].pCurrent)
23293
23294 #if SQLITE_ENABLE_LOCKING_STYLE
23295 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
23296 #else
23297 { "fchmod", (sqlite3_syscall_ptr)0, 0 },
23298 #endif
23299 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
23300
23301 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
23302 { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 },
23303 #else
@@ -23318,13 +23324,10 @@
23318 #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent)
23319
23320 { "fchown", (sqlite3_syscall_ptr)posixFchown, 0 },
23321 #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)
23322
23323 { "umask", (sqlite3_syscall_ptr)umask, 0 },
23324 #define osUmask ((mode_t(*)(mode_t))aSyscall[21].pCurrent)
23325
23326 }; /* End of the overrideable system calls */
23327
23328 /*
23329 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
23330 ** "unix" VFSes. Return SQLITE_OK opon successfully updating the
@@ -23425,31 +23428,29 @@
23425 ** process that is able to write to the database will also be able to
23426 ** recover the hot journals.
23427 */
23428 static int robust_open(const char *z, int f, mode_t m){
23429 int fd;
23430 mode_t m2;
23431 mode_t origM = 0;
23432 if( m==0 ){
23433 m2 = SQLITE_DEFAULT_FILE_PERMISSIONS;
23434 }else{
23435 m2 = m;
23436 origM = osUmask(0);
23437 }
23438 do{
23439 #if defined(O_CLOEXEC)
23440 fd = osOpen(z,f|O_CLOEXEC,m2);
23441 #else
23442 fd = osOpen(z,f,m2);
23443 #endif
23444 }while( fd<0 && errno==EINTR );
23445 if( m ){
23446 osUmask(origM);
23447 }
 
 
 
 
23448 #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
23449 if( fd>=0 ) osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
23450 #endif
 
23451 return fd;
23452 }
23453
23454 /*
23455 ** Helper functions to obtain and relinquish the global mutex. The
@@ -29871,11 +29872,11 @@
29871 };
29872 unsigned int i; /* Loop counter */
29873
29874 /* Double-check that the aSyscall[] array has been constructed
29875 ** correctly. See ticket [bb3a86e890c8e96ab] */
29876 assert( ArraySize(aSyscall)==22 );
29877
29878 /* Register all VFSes defined in the aVfs[] array */
29879 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
29880 sqlite3_vfs_register(&aVfs[i], i==0);
29881 }
@@ -72655,10 +72656,39 @@
72655 }
72656 }
72657 return 0;
72658 }
72659
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72660
72661 /*
72662 ** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up
72663 ** that name in the set of source tables in pSrcList and make the pExpr
72664 ** expression node refer back to that source column. The following changes
@@ -72710,44 +72740,63 @@
72710
72711 /* Initialize the node to no-match */
72712 pExpr->iTable = -1;
72713 pExpr->pTab = 0;
72714 ExprSetIrreducible(pExpr);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72715
72716 /* Start at the inner-most context and move outward until a match is found */
72717 while( pNC && cnt==0 ){
72718 ExprList *pEList;
72719 SrcList *pSrcList = pNC->pSrcList;
72720
72721 if( pSrcList ){
72722 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
72723 Table *pTab;
72724 int iDb;
72725 Column *pCol;
72726
72727 pTab = pItem->pTab;
72728 assert( pTab!=0 && pTab->zName!=0 );
72729 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
72730 assert( pTab->nCol>0 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72731 if( zTab ){
72732 if( pItem->zAlias ){
72733 char *zTabName = pItem->zAlias;
72734 if( sqlite3StrICmp(zTabName, zTab)!=0 ) continue;
72735 }else{
72736 char *zTabName = pTab->zName;
72737 if( NEVER(zTabName==0) || sqlite3StrICmp(zTabName, zTab)!=0 ){
72738 continue;
72739 }
72740 if( zDb!=0 && sqlite3StrICmp(db->aDb[iDb].zName, zDb)!=0 ){
72741 continue;
72742 }
72743 }
72744 }
72745 if( 0==(cntTab++) ){
72746 pExpr->iTable = pItem->iCursor;
72747 pExpr->pTab = pTab;
72748 pSchema = pTab->pSchema;
72749 pMatch = pItem;
72750 }
72751 for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
72752 if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
72753 /* If there has been exactly one prior match and this match
@@ -72757,21 +72806,23 @@
72757 if( cnt==1 ){
72758 if( pItem->jointype & JT_NATURAL ) continue;
72759 if( nameInUsingClause(pItem->pUsing, zCol) ) continue;
72760 }
72761 cnt++;
72762 pExpr->iTable = pItem->iCursor;
72763 pExpr->pTab = pTab;
72764 pMatch = pItem;
72765 pSchema = pTab->pSchema;
72766 /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
72767 pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
72768 break;
72769 }
72770 }
72771 }
72772 }
 
 
 
 
 
72773
72774 #ifndef SQLITE_OMIT_TRIGGER
72775 /* If we have not already resolved the name, then maybe
72776 ** it is a new.* or old.* trigger argument reference
72777 */
@@ -73066,42 +73117,43 @@
73066 int wrong_num_args = 0; /* True if wrong number of arguments */
73067 int is_agg = 0; /* True if is an aggregate function */
73068 int auth; /* Authorization to use the function */
73069 int nId; /* Number of characters in function name */
73070 const char *zId; /* The function name. */
73071 FuncDef *pDef; /* Information about the function */
73072 u8 enc = ENC(pParse->db); /* The database encoding */
73073
73074 testcase( pExpr->op==TK_CONST_FUNC );
73075 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
73076 zId = pExpr->u.zToken;
73077 nId = sqlite3Strlen30(zId);
73078 pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
73079 if( pDef==0 ){
73080 pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
73081 if( pDef==0 ){
73082 no_such_func = 1;
73083 }else{
73084 wrong_num_args = 1;
73085 }
73086 }else{
73087 is_agg = pDef->xFunc==0;
73088 }
73089 #ifndef SQLITE_OMIT_AUTHORIZATION
73090 if( pDef ){
73091 auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
73092 if( auth!=SQLITE_OK ){
73093 if( auth==SQLITE_DENY ){
73094 sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
73095 pDef->zName);
73096 pNC->nErr++;
73097 }
73098 pExpr->op = TK_NULL;
73099 return WRC_Prune;
73100 }
73101 }
73102 #endif
 
 
73103 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
73104 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
73105 pNC->nErr++;
73106 is_agg = 0;
73107 }else if( no_such_func ){
@@ -77065,10 +77117,16 @@
77065 for(i=0; i<pList->nExpr; i++){
77066 sqlite3ExplainPrintf(pOut, "item[%d] = ", i);
77067 sqlite3ExplainPush(pOut);
77068 sqlite3ExplainExpr(pOut, pList->a[i].pExpr);
77069 sqlite3ExplainPop(pOut);
 
 
 
 
 
 
77070 if( i<pList->nExpr-1 ){
77071 sqlite3ExplainNL(pOut);
77072 }
77073 }
77074 sqlite3ExplainPop(pOut);
@@ -92739,13 +92797,15 @@
92739 if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
92740 Table *pTab;
92741 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
92742 pTab = sqlite3FindTable(db, zRight, zDb);
92743 if( pTab ){
92744 int i;
92745 int nHidden = 0;
92746 Column *pCol;
 
 
92747 sqlite3VdbeSetNumCols(v, 6);
92748 pParse->nMem = 6;
92749 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
92750 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
92751 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
@@ -92766,12 +92826,18 @@
92766 if( pCol->zDflt ){
92767 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0);
92768 }else{
92769 sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
92770 }
92771 sqlite3VdbeAddOp2(v, OP_Integer,
92772 (pCol->colFlags&COLFLAG_PRIMKEY)!=0, 6);
 
 
 
 
 
 
92773 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
92774 }
92775 }
92776 }else
92777
@@ -95756,12 +95822,10 @@
95756
95757 for(i=0, pCol=aCol; i<nCol; i++, pCol++){
95758 /* Get an appropriate name for the column
95759 */
95760 p = sqlite3ExprSkipCollate(pEList->a[i].pExpr);
95761 assert( p->pRight==0 || ExprHasProperty(p->pRight, EP_IntValue)
95762 || p->pRight->u.zToken==0 || p->pRight->u.zToken[0]!=0 );
95763 if( (zName = pEList->a[i].zName)!=0 ){
95764 /* If the column contains an "AS <name>" phrase, use <name> as the name */
95765 zName = sqlite3DbStrDup(db, zName);
95766 }else{
95767 Expr *pColExpr = p; /* The expression that is the result column name */
@@ -95795,10 +95859,13 @@
95795 */
95796 nName = sqlite3Strlen30(zName);
95797 for(j=cnt=0; j<i; j++){
95798 if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){
95799 char *zNewName;
 
 
 
95800 zName[nName] = 0;
95801 zNewName = sqlite3MPrintf(db, "%s:%d", zName, ++cnt);
95802 sqlite3DbFree(db, zName);
95803 zName = zNewName;
95804 j = -1;
@@ -97711,10 +97778,11 @@
97711 int i, j, k;
97712 SrcList *pTabList;
97713 ExprList *pEList;
97714 struct SrcList_item *pFrom;
97715 sqlite3 *db = pParse->db;
 
97716
97717 if( db->mallocFailed ){
97718 return WRC_Abort;
97719 }
97720 if( NEVER(p->pSrc==0) || (p->selFlags & SF_Expanded)!=0 ){
@@ -97796,11 +97864,11 @@
97796 **
97797 ** The first loop just checks to see if there are any "*" operators
97798 ** that need expanding.
97799 */
97800 for(k=0; k<pEList->nExpr; k++){
97801 Expr *pE = pEList->a[k].pExpr;
97802 if( pE->op==TK_ALL ) break;
97803 assert( pE->op!=TK_DOT || pE->pRight!=0 );
97804 assert( pE->op!=TK_DOT || (pE->pLeft!=0 && pE->pLeft->op==TK_ID) );
97805 if( pE->op==TK_DOT && pE->pRight->op==TK_ALL ) break;
97806 }
@@ -97814,14 +97882,22 @@
97814 ExprList *pNew = 0;
97815 int flags = pParse->db->flags;
97816 int longNames = (flags & SQLITE_FullColNames)!=0
97817 && (flags & SQLITE_ShortColNames)==0;
97818
 
 
 
 
 
 
 
97819 for(k=0; k<pEList->nExpr; k++){
97820 Expr *pE = a[k].pExpr;
97821 assert( pE->op!=TK_DOT || pE->pRight!=0 );
97822 if( pE->op!=TK_ALL && (pE->op!=TK_DOT || pE->pRight->op!=TK_ALL) ){
 
97823 /* This particular expression does not need to be expanded.
97824 */
97825 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
97826 if( pNew ){
97827 pNew->a[pNew->nExpr-1].zName = a[k].zName;
@@ -97832,44 +97908,56 @@
97832 a[k].pExpr = 0;
97833 }else{
97834 /* This expression is a "*" or a "TABLE.*" and needs to be
97835 ** expanded. */
97836 int tableSeen = 0; /* Set to 1 when TABLE matches */
97837 char *zTName; /* text of name of TABLE */
97838 if( pE->op==TK_DOT ){
97839 assert( pE->pLeft!=0 );
97840 assert( !ExprHasProperty(pE->pLeft, EP_IntValue) );
97841 zTName = pE->pLeft->u.zToken;
97842 }else{
97843 zTName = 0;
97844 }
97845 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
97846 Table *pTab = pFrom->pTab;
 
97847 char *zTabName = pFrom->zAlias;
 
 
97848 if( zTabName==0 ){
97849 zTabName = pTab->zName;
97850 }
97851 if( db->mallocFailed ) break;
97852 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
97853 continue;
 
 
 
 
 
97854 }
97855 tableSeen = 1;
97856 for(j=0; j<pTab->nCol; j++){
97857 Expr *pExpr, *pRight;
97858 char *zName = pTab->aCol[j].zName;
97859 char *zColname; /* The computed column name */
97860 char *zToFree; /* Malloced string that needs to be freed */
97861 Token sColname; /* Computed column name as a token */
 
 
 
 
 
 
 
97862
97863 /* If a column is marked as 'hidden' (currently only possible
97864 ** for virtual tables), do not include it in the expanded
97865 ** result-set list.
97866 */
97867 if( IsHiddenColumn(&pTab->aCol[j]) ){
97868 assert(IsVirtual(pTab));
97869 continue;
97870 }
 
97871
97872 if( i>0 && zTName==0 ){
97873 if( (pFrom->jointype & JT_NATURAL)!=0
97874 && tableAndColumnIndex(pTabList, i, zName, 0, 0)
97875 ){
@@ -97888,10 +97976,14 @@
97888 zToFree = 0;
97889 if( longNames || pTabList->nSrc>1 ){
97890 Expr *pLeft;
97891 pLeft = sqlite3Expr(db, TK_ID, zTabName);
97892 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
 
 
 
 
97893 if( longNames ){
97894 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
97895 zToFree = zColname;
97896 }
97897 }else{
@@ -97899,10 +97991,22 @@
97899 }
97900 pNew = sqlite3ExprListAppend(pParse, pNew, pExpr);
97901 sColname.z = zColname;
97902 sColname.n = sqlite3Strlen30(zColname);
97903 sqlite3ExprListSetName(pParse, pNew, &sColname, 0);
 
 
 
 
 
 
 
 
 
 
 
 
97904 sqlite3DbFree(db, zToFree);
97905 }
97906 }
97907 if( !tableSeen ){
97908 if( zTName ){
97909
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -673,11 +673,11 @@
673 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674 ** [sqlite_version()] and [sqlite_source_id()].
675 */
676 #define SQLITE_VERSION "3.7.16"
677 #define SQLITE_VERSION_NUMBER 3007016
678 #define SQLITE_SOURCE_ID "2013-01-07 13:26:23 0a1207c895d9f77586a3a2a4965175909be90503"
679
680 /*
681 ** CAPI3REF: Run-Time Library Version Numbers
682 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
683 **
@@ -10553,24 +10553,24 @@
10553 ** and the value of Index.onError indicate the which conflict resolution
10554 ** algorithm to employ whenever an attempt is made to insert a non-unique
10555 ** element.
10556 */
10557 struct Index {
10558 char *zName; /* Name of this index */
10559 int *aiColumn; /* Which columns are used by this index. 1st is 0 */
10560 tRowcnt *aiRowEst; /* From ANALYZE: Est. rows selected by each column */
10561 Table *pTable; /* The SQL table being indexed */
10562 char *zColAff; /* String defining the affinity of each column */
10563 Index *pNext; /* The next index associated with the same table */
10564 Schema *pSchema; /* Schema containing this index */
10565 u8 *aSortOrder; /* for each column: True==DESC, False==ASC */
10566 char **azColl; /* Array of collation sequence names for index */
10567 int tnum; /* DB Page containing root of this index */
10568 u16 nColumn; /* Number of columns in table used by this index */
10569 u8 onError; /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */
10570 unsigned autoIndex:2; /* 1==UNIQUE, 2==PRIMARY KEY, 0==CREATE INDEX */
10571 unsigned bUnordered:1; /* Use this index for == or IN queries only */
10572 #ifdef SQLITE_ENABLE_STAT3
10573 int nSample; /* Number of elements in aSample[] */
10574 tRowcnt avgEq; /* Average nEq value for key values not in aSample */
10575 IndexSample *aSample; /* Samples of the left-most key */
10576 #endif
@@ -10840,22 +10840,31 @@
10840 ** name. An expr/name combination can be used in several ways, such
10841 ** as the list of "expr AS ID" fields following a "SELECT" or in the
10842 ** list of "ID = expr" items in an UPDATE. A list of expressions can
10843 ** also be used as the argument to a function, in which case the a.zName
10844 ** field is not used.
10845 **
10846 ** By default the Expr.zSpan field holds a human-readable description of
10847 ** the expression that is used in the generation of error messages and
10848 ** column labels. In this case, Expr.zSpan is typically the text of a
10849 ** column expression as it exists in a SELECT statement. However, if
10850 ** the bSpanIsTab flag is set, then zSpan is overloaded to mean the name
10851 ** of the result column in the form: DATABASE.TABLE.COLUMN. This later
10852 ** form is used for name resolution with nested FROM clauses.
10853 */
10854 struct ExprList {
10855 int nExpr; /* Number of expressions on the list */
10856 int iECursor; /* VDBE Cursor associated with this ExprList */
10857 struct ExprList_item { /* For each expression in the list */
10858 Expr *pExpr; /* The list of expressions */
10859 char *zName; /* Token associated with this expression */
10860 char *zSpan; /* Original text of the expression */
10861 u8 sortOrder; /* 1 for DESC or 0 for ASC */
10862 unsigned done :1; /* A flag to indicate when processing is finished */
10863 unsigned bSpanIsTab :1; /* zSpan holds DB.TABLE.COLUMN */
10864 u16 iOrderByCol; /* For ORDER BY, column number in result set */
10865 u16 iAlias; /* Index into Parse.aAlias[] for zName */
10866 } *a; /* Alloc a power of two greater or equal to nExpr */
10867 };
10868
10869 /*
10870 ** An instance of this structure is used by the parser to record both
@@ -12141,10 +12150,11 @@
12150 SQLITE_PRIVATE int sqlite3GetToken(const unsigned char *, int *);
12151 SQLITE_PRIVATE void sqlite3NestedParse(Parse*, const char*, ...);
12152 SQLITE_PRIVATE void sqlite3ExpirePreparedStatements(sqlite3*);
12153 SQLITE_PRIVATE int sqlite3CodeSubselect(Parse *, Expr *, int, int);
12154 SQLITE_PRIVATE void sqlite3SelectPrep(Parse*, Select*, NameContext*);
12155 SQLITE_PRIVATE int sqlite3MatchSpanName(const char*, const char*, const char*, const char*);
12156 SQLITE_PRIVATE int sqlite3ResolveExprNames(NameContext*, Expr*);
12157 SQLITE_PRIVATE void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
12158 SQLITE_PRIVATE int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
12159 SQLITE_PRIVATE void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
12160 SQLITE_PRIVATE void sqlite3AlterFinishAddColumn(Parse *, Token *);
@@ -23289,15 +23299,11 @@
23299 { "pwrite64", (sqlite3_syscall_ptr)0, 0 },
23300 #endif
23301 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\
23302 aSyscall[13].pCurrent)
23303
 
23304 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
 
 
 
23305 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
23306
23307 #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
23308 { "fallocate", (sqlite3_syscall_ptr)posix_fallocate, 0 },
23309 #else
@@ -23318,13 +23324,10 @@
23324 #define osRmdir ((int(*)(const char*))aSyscall[19].pCurrent)
23325
23326 { "fchown", (sqlite3_syscall_ptr)posixFchown, 0 },
23327 #define osFchown ((int(*)(int,uid_t,gid_t))aSyscall[20].pCurrent)
23328
 
 
 
23329 }; /* End of the overrideable system calls */
23330
23331 /*
23332 ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
23333 ** "unix" VFSes. Return SQLITE_OK opon successfully updating the
@@ -23425,31 +23428,29 @@
23428 ** process that is able to write to the database will also be able to
23429 ** recover the hot journals.
23430 */
23431 static int robust_open(const char *z, int f, mode_t m){
23432 int fd;
23433 mode_t m2 = m ? m : SQLITE_DEFAULT_FILE_PERMISSIONS;
 
 
 
 
 
 
 
23434 do{
23435 #if defined(O_CLOEXEC)
23436 fd = osOpen(z,f|O_CLOEXEC,m2);
23437 #else
23438 fd = osOpen(z,f,m2);
23439 #endif
23440 }while( fd<0 && errno==EINTR );
23441 if( fd>=0 ){
23442 if( m!=0 ){
23443 struct stat statbuf;
23444 if( osFstat(fd, &statbuf)==0 && (statbuf.st_mode&0777)!=m ){
23445 osFchmod(fd, m);
23446 }
23447 }
23448 #if defined(FD_CLOEXEC) && (!defined(O_CLOEXEC) || O_CLOEXEC==0)
23449 osFcntl(fd, F_SETFD, osFcntl(fd, F_GETFD, 0) | FD_CLOEXEC);
23450 #endif
23451 }
23452 return fd;
23453 }
23454
23455 /*
23456 ** Helper functions to obtain and relinquish the global mutex. The
@@ -29871,11 +29872,11 @@
29872 };
29873 unsigned int i; /* Loop counter */
29874
29875 /* Double-check that the aSyscall[] array has been constructed
29876 ** correctly. See ticket [bb3a86e890c8e96ab] */
29877 assert( ArraySize(aSyscall)==21 );
29878
29879 /* Register all VFSes defined in the aVfs[] array */
29880 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
29881 sqlite3_vfs_register(&aVfs[i], i==0);
29882 }
@@ -72655,10 +72656,39 @@
72656 }
72657 }
72658 return 0;
72659 }
72660
72661 /*
72662 ** Subqueries stores the original database, table and column names for their
72663 ** result sets in ExprList.a[].zSpan, in the form "DATABASE.TABLE.COLUMN".
72664 ** Check to see if the zSpan given to this routine matches the zDb, zTab,
72665 ** and zCol. If any of zDb, zTab, and zCol are NULL then those fields will
72666 ** match anything.
72667 */
72668 SQLITE_PRIVATE int sqlite3MatchSpanName(
72669 const char *zSpan,
72670 const char *zCol,
72671 const char *zTab,
72672 const char *zDb
72673 ){
72674 int n;
72675 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
72676 if( zDb && sqlite3StrNICmp(zSpan, zDb, n)!=0 ){
72677 return 0;
72678 }
72679 zSpan += n+1;
72680 for(n=0; ALWAYS(zSpan[n]) && zSpan[n]!='.'; n++){}
72681 if( zTab && sqlite3StrNICmp(zSpan, zTab, n)!=0 ){
72682 return 0;
72683 }
72684 zSpan += n+1;
72685 if( zCol && sqlite3StrICmp(zSpan, zCol)!=0 ){
72686 return 0;
72687 }
72688 return 1;
72689 }
72690
72691 /*
72692 ** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up
72693 ** that name in the set of source tables in pSrcList and make the pExpr
72694 ** expression node refer back to that source column. The following changes
@@ -72710,44 +72740,63 @@
72740
72741 /* Initialize the node to no-match */
72742 pExpr->iTable = -1;
72743 pExpr->pTab = 0;
72744 ExprSetIrreducible(pExpr);
72745
72746 /* Translate the schema name in zDb into a pointer to the corresponding
72747 ** schema. If not found, pSchema will remain NULL and nothing will match
72748 ** resulting in an appropriate error message toward the end of this routine
72749 */
72750 if( zDb ){
72751 for(i=0; i<db->nDb; i++){
72752 assert( db->aDb[i].zName );
72753 if( sqlite3StrICmp(db->aDb[i].zName,zDb)==0 ){
72754 pSchema = db->aDb[i].pSchema;
72755 break;
72756 }
72757 }
72758 }
72759
72760 /* Start at the inner-most context and move outward until a match is found */
72761 while( pNC && cnt==0 ){
72762 ExprList *pEList;
72763 SrcList *pSrcList = pNC->pSrcList;
72764
72765 if( pSrcList ){
72766 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
72767 Table *pTab;
 
72768 Column *pCol;
72769
72770 pTab = pItem->pTab;
72771 assert( pTab!=0 && pTab->zName!=0 );
 
72772 assert( pTab->nCol>0 );
72773 if( pItem->pSelect && (pItem->pSelect->selFlags & SF_NestedFrom)!=0 ){
72774 ExprList *pEList = pItem->pSelect->pEList;
72775 int hit = 0;
72776 for(j=0; j<pEList->nExpr; j++){
72777 if( sqlite3MatchSpanName(pEList->a[j].zSpan, zCol, zTab, zDb) ){
72778 cnt++;
72779 cntTab = 2;
72780 pMatch = pItem;
72781 pExpr->iColumn = j;
72782 hit = 1;
72783 }
72784 }
72785 if( hit || zTab==0 ) continue;
72786 }
72787 if( zDb && pTab->pSchema!=pSchema ){
72788 continue;
72789 }
72790 if( zTab ){
72791 const char *zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName;
72792 assert( zTabName!=0 );
72793 if( sqlite3StrICmp(zTabName, zTab)!=0 ){
72794 continue;
 
 
 
 
 
 
 
72795 }
72796 }
72797 if( 0==(cntTab++) ){
 
 
 
72798 pMatch = pItem;
72799 }
72800 for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
72801 if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
72802 /* If there has been exactly one prior match and this match
@@ -72757,21 +72806,23 @@
72806 if( cnt==1 ){
72807 if( pItem->jointype & JT_NATURAL ) continue;
72808 if( nameInUsingClause(pItem->pUsing, zCol) ) continue;
72809 }
72810 cnt++;
 
 
72811 pMatch = pItem;
 
72812 /* Substitute the rowid (column -1) for the INTEGER PRIMARY KEY */
72813 pExpr->iColumn = j==pTab->iPKey ? -1 : (i16)j;
72814 break;
72815 }
72816 }
72817 }
72818 if( pMatch ){
72819 pExpr->iTable = pMatch->iCursor;
72820 pExpr->pTab = pMatch->pTab;
72821 pSchema = pExpr->pTab->pSchema;
72822 }
72823 } /* if( pSrcList ) */
72824
72825 #ifndef SQLITE_OMIT_TRIGGER
72826 /* If we have not already resolved the name, then maybe
72827 ** it is a new.* or old.* trigger argument reference
72828 */
@@ -73066,42 +73117,43 @@
73117 int wrong_num_args = 0; /* True if wrong number of arguments */
73118 int is_agg = 0; /* True if is an aggregate function */
73119 int auth; /* Authorization to use the function */
73120 int nId; /* Number of characters in function name */
73121 const char *zId; /* The function name. */
 
73122 u8 enc = ENC(pParse->db); /* The database encoding */
73123
73124 testcase( pExpr->op==TK_CONST_FUNC );
73125 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
73126 zId = pExpr->u.zToken;
73127 nId = sqlite3Strlen30(zId);
73128 if( pParse->db->init.busy==0 ){
73129 FuncDef *pDef = sqlite3FindFunction(pParse->db, zId, nId, n, enc, 0);
73130 if( pDef==0 ){
73131 pDef = sqlite3FindFunction(pParse->db, zId, nId, -2, enc, 0);
73132 if( pDef==0 ){
73133 no_such_func = 1;
73134 }else{
73135 wrong_num_args = 1;
73136 }
73137 }else{
73138 is_agg = pDef->xFunc==0;
73139 }
73140 #ifndef SQLITE_OMIT_AUTHORIZATION
73141 if( pDef ){
73142 auth = sqlite3AuthCheck(pParse, SQLITE_FUNCTION, 0, pDef->zName, 0);
73143 if( auth!=SQLITE_OK ){
73144 if( auth==SQLITE_DENY ){
73145 sqlite3ErrorMsg(pParse, "not authorized to use function: %s",
73146 pDef->zName);
73147 pNC->nErr++;
73148 }
73149 pExpr->op = TK_NULL;
73150 return WRC_Prune;
73151 }
73152 }
73153 #endif
73154 }
73155 if( is_agg && (pNC->ncFlags & NC_AllowAgg)==0 ){
73156 sqlite3ErrorMsg(pParse, "misuse of aggregate function %.*s()", nId,zId);
73157 pNC->nErr++;
73158 is_agg = 0;
73159 }else if( no_such_func ){
@@ -77065,10 +77117,16 @@
77117 for(i=0; i<pList->nExpr; i++){
77118 sqlite3ExplainPrintf(pOut, "item[%d] = ", i);
77119 sqlite3ExplainPush(pOut);
77120 sqlite3ExplainExpr(pOut, pList->a[i].pExpr);
77121 sqlite3ExplainPop(pOut);
77122 if( pList->a[i].zName ){
77123 sqlite3ExplainPrintf(pOut, " AS %s", pList->a[i].zName);
77124 }
77125 if( pList->a[i].bSpanIsTab ){
77126 sqlite3ExplainPrintf(pOut, " (%s)", pList->a[i].zSpan);
77127 }
77128 if( i<pList->nExpr-1 ){
77129 sqlite3ExplainNL(pOut);
77130 }
77131 }
77132 sqlite3ExplainPop(pOut);
@@ -92739,13 +92797,15 @@
92797 if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
92798 Table *pTab;
92799 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
92800 pTab = sqlite3FindTable(db, zRight, zDb);
92801 if( pTab ){
92802 int i, k;
92803 int nHidden = 0;
92804 Column *pCol;
92805 Index *pPk;
92806 for(pPk=pTab->pIndex; pPk && pPk->autoIndex!=2; pPk=pPk->pNext){}
92807 sqlite3VdbeSetNumCols(v, 6);
92808 pParse->nMem = 6;
92809 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", SQLITE_STATIC);
92810 sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", SQLITE_STATIC);
92811 sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", SQLITE_STATIC);
@@ -92766,12 +92826,18 @@
92826 if( pCol->zDflt ){
92827 sqlite3VdbeAddOp4(v, OP_String8, 0, 5, 0, (char*)pCol->zDflt, 0);
92828 }else{
92829 sqlite3VdbeAddOp2(v, OP_Null, 0, 5);
92830 }
92831 if( (pCol->colFlags & COLFLAG_PRIMKEY)==0 ){
92832 k = 0;
92833 }else if( pPk==0 ){
92834 k = 1;
92835 }else{
92836 for(k=1; ALWAYS(k<=pTab->nCol) && pPk->aiColumn[k-1]!=i; k++){}
92837 }
92838 sqlite3VdbeAddOp2(v, OP_Integer, k, 6);
92839 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 6);
92840 }
92841 }
92842 }else
92843
@@ -95756,12 +95822,10 @@
95822
95823 for(i=0, pCol=aCol; i<nCol; i++, pCol++){
95824 /* Get an appropriate name for the column
95825 */
95826 p = sqlite3ExprSkipCollate(pEList->a[i].pExpr);
 
 
95827 if( (zName = pEList->a[i].zName)!=0 ){
95828 /* If the column contains an "AS <name>" phrase, use <name> as the name */
95829 zName = sqlite3DbStrDup(db, zName);
95830 }else{
95831 Expr *pColExpr = p; /* The expression that is the result column name */
@@ -95795,10 +95859,13 @@
95859 */
95860 nName = sqlite3Strlen30(zName);
95861 for(j=cnt=0; j<i; j++){
95862 if( sqlite3StrICmp(aCol[j].zName, zName)==0 ){
95863 char *zNewName;
95864 int k;
95865 for(k=nName-1; k>1 && sqlite3Isdigit(zName[k]); k--){}
95866 if( zName[k]==':' ) nName = k;
95867 zName[nName] = 0;
95868 zNewName = sqlite3MPrintf(db, "%s:%d", zName, ++cnt);
95869 sqlite3DbFree(db, zName);
95870 zName = zNewName;
95871 j = -1;
@@ -97711,10 +97778,11 @@
97778 int i, j, k;
97779 SrcList *pTabList;
97780 ExprList *pEList;
97781 struct SrcList_item *pFrom;
97782 sqlite3 *db = pParse->db;
97783 Expr *pE, *pRight, *pExpr;
97784
97785 if( db->mallocFailed ){
97786 return WRC_Abort;
97787 }
97788 if( NEVER(p->pSrc==0) || (p->selFlags & SF_Expanded)!=0 ){
@@ -97796,11 +97864,11 @@
97864 **
97865 ** The first loop just checks to see if there are any "*" operators
97866 ** that need expanding.
97867 */
97868 for(k=0; k<pEList->nExpr; k++){
97869 pE = pEList->a[k].pExpr;
97870 if( pE->op==TK_ALL ) break;
97871 assert( pE->op!=TK_DOT || pE->pRight!=0 );
97872 assert( pE->op!=TK_DOT || (pE->pLeft!=0 && pE->pLeft->op==TK_ID) );
97873 if( pE->op==TK_DOT && pE->pRight->op==TK_ALL ) break;
97874 }
@@ -97814,14 +97882,22 @@
97882 ExprList *pNew = 0;
97883 int flags = pParse->db->flags;
97884 int longNames = (flags & SQLITE_FullColNames)!=0
97885 && (flags & SQLITE_ShortColNames)==0;
97886
97887 /* When processing FROM-clause subqueries, it is always the case
97888 ** that full_column_names=OFF and short_column_names=ON. The
97889 ** sqlite3ResultSetOfSelect() routine makes it so. */
97890 assert( (p->selFlags & SF_NestedFrom)==0
97891 || ((flags & SQLITE_FullColNames)==0 &&
97892 (flags & SQLITE_ShortColNames)!=0) );
97893
97894 for(k=0; k<pEList->nExpr; k++){
97895 pE = a[k].pExpr;
97896 pRight = pE->pRight;
97897 assert( pE->op!=TK_DOT || pRight!=0 );
97898 if( pE->op!=TK_ALL && (pE->op!=TK_DOT || pRight->op!=TK_ALL) ){
97899 /* This particular expression does not need to be expanded.
97900 */
97901 pNew = sqlite3ExprListAppend(pParse, pNew, a[k].pExpr);
97902 if( pNew ){
97903 pNew->a[pNew->nExpr-1].zName = a[k].zName;
@@ -97832,44 +97908,56 @@
97908 a[k].pExpr = 0;
97909 }else{
97910 /* This expression is a "*" or a "TABLE.*" and needs to be
97911 ** expanded. */
97912 int tableSeen = 0; /* Set to 1 when TABLE matches */
97913 char *zTName = 0; /* text of name of TABLE */
97914 if( pE->op==TK_DOT ){
97915 assert( pE->pLeft!=0 );
97916 assert( !ExprHasProperty(pE->pLeft, EP_IntValue) );
97917 zTName = pE->pLeft->u.zToken;
 
 
97918 }
97919 for(i=0, pFrom=pTabList->a; i<pTabList->nSrc; i++, pFrom++){
97920 Table *pTab = pFrom->pTab;
97921 Select *pSub = pFrom->pSelect;
97922 char *zTabName = pFrom->zAlias;
97923 const char *zSchemaName = 0;
97924 int iDb;
97925 if( zTabName==0 ){
97926 zTabName = pTab->zName;
97927 }
97928 if( db->mallocFailed ) break;
97929 if( pSub==0 || (pSub->selFlags & SF_NestedFrom)==0 ){
97930 pSub = 0;
97931 if( zTName && sqlite3StrICmp(zTName, zTabName)!=0 ){
97932 continue;
97933 }
97934 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
97935 zSchemaName = iDb>=0 ? db->aDb[iDb].zName : "*";
97936 }
 
97937 for(j=0; j<pTab->nCol; j++){
 
97938 char *zName = pTab->aCol[j].zName;
97939 char *zColname; /* The computed column name */
97940 char *zToFree; /* Malloced string that needs to be freed */
97941 Token sColname; /* Computed column name as a token */
97942
97943 assert( zName );
97944 if( zTName && pSub
97945 && sqlite3MatchSpanName(pSub->pEList->a[j].zSpan, 0, zTName, 0)==0
97946 ){
97947 continue;
97948 }
97949
97950 /* If a column is marked as 'hidden' (currently only possible
97951 ** for virtual tables), do not include it in the expanded
97952 ** result-set list.
97953 */
97954 if( IsHiddenColumn(&pTab->aCol[j]) ){
97955 assert(IsVirtual(pTab));
97956 continue;
97957 }
97958 tableSeen = 1;
97959
97960 if( i>0 && zTName==0 ){
97961 if( (pFrom->jointype & JT_NATURAL)!=0
97962 && tableAndColumnIndex(pTabList, i, zName, 0, 0)
97963 ){
@@ -97888,10 +97976,14 @@
97976 zToFree = 0;
97977 if( longNames || pTabList->nSrc>1 ){
97978 Expr *pLeft;
97979 pLeft = sqlite3Expr(db, TK_ID, zTabName);
97980 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight, 0);
97981 if( zSchemaName ){
97982 pLeft = sqlite3Expr(db, TK_ID, zSchemaName);
97983 pExpr = sqlite3PExpr(pParse, TK_DOT, pLeft, pExpr, 0);
97984 }
97985 if( longNames ){
97986 zColname = sqlite3MPrintf(db, "%s.%s", zTabName, zName);
97987 zToFree = zColname;
97988 }
97989 }else{
@@ -97899,10 +97991,22 @@
97991 }
97992 pNew = sqlite3ExprListAppend(pParse, pNew, pExpr);
97993 sColname.z = zColname;
97994 sColname.n = sqlite3Strlen30(zColname);
97995 sqlite3ExprListSetName(pParse, pNew, &sColname, 0);
97996 if( pNew && (p->selFlags & SF_NestedFrom)!=0 ){
97997 struct ExprList_item *pX = &pNew->a[pNew->nExpr-1];
97998 if( pSub ){
97999 pX->zSpan = sqlite3DbStrDup(db, pSub->pEList->a[j].zSpan);
98000 testcase( pX->zSpan==0 );
98001 }else{
98002 pX->zSpan = sqlite3MPrintf(db, "%s.%s.%s",
98003 zSchemaName, zTabName, zColname);
98004 testcase( pX->zSpan==0 );
98005 }
98006 pX->bSpanIsTab = 1;
98007 }
98008 sqlite3DbFree(db, zToFree);
98009 }
98010 }
98011 if( !tableSeen ){
98012 if( zTName ){
98013
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.7.16"
111111
#define SQLITE_VERSION_NUMBER 3007016
112
-#define SQLITE_SOURCE_ID "2012-12-21 16:15:35 ff6857b6ed6a46671006b75157d8cf853a816ef9"
112
+#define SQLITE_SOURCE_ID "2013-01-07 13:26:23 0a1207c895d9f77586a3a2a4965175909be90503"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
118118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.16"
111 #define SQLITE_VERSION_NUMBER 3007016
112 #define SQLITE_SOURCE_ID "2012-12-21 16:15:35 ff6857b6ed6a46671006b75157d8cf853a816ef9"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.16"
111 #define SQLITE_VERSION_NUMBER 3007016
112 #define SQLITE_SOURCE_ID "2013-01-07 13:26:23 0a1207c895d9f77586a3a2a4965175909be90503"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button