Hi,
sorry for the noise. Again trying to supply attachments.
Bye.
--
Reinhard Nißl
-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]]
Im Auftrag von Nißl Reinhard
Gesendet: Montag, 14. Februar 2011 13:56
An: General Discussion of SQLite Database
Betreff: Re: [sqlite] BUG (3.7.5): identifier quotation characters get part of
column names for certain statements
Hi,
looks like the patch did got stripped. I've attached it again.
And please find attached a further patch which addresses TK_AGG_COLUMNS.
Bye.
--
Reinhard Nißl
-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]]
Im Auftrag von Nißl Reinhard
Gesendet: Samstag, 12. Februar 2011 23:42
An: General Discussion of SQLite Database
Betreff: Re: [sqlite] BUG (3.7.5): identifier quotation characters get part of
column names for certain statements
Hi,
it took me 6 hours to find the source location which behaves inconsistent.
Please find attached a fix for this bug.
Bye.
--
Reinhard Nißl
-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]]
Im Auftrag von Nißl Reinhard
Gesendet: Freitag, 11. Februar 2011 10:42
An: [email protected]; General Discussion of SQLite Database
Betreff: Re: [sqlite] BUG (3.7.5): identifier quotation characters get part of
column names for certain statements
I'd like to create a patch which changes the behavior in that way, but I'm not
that used to the sqlite3 internals. From a quick glance at the source, I think
it has something to do with TK_COLUMN and TK_VARIABLE. It would be nice if you
could give me a pointer where to place the change in the source code.
--- src/select.c
+++ src/select.c
@@ -2710,10 +2710,53 @@
}
}
/***** If we reach this point, flattening is permitted. *****/
+ pList = p->pEList;
+ {
+ SrcList *pTabList = pSrc; /* List of tables to select from */
+ int fullNames, shortNames;
+ fullNames = (db->flags & SQLITE_FullColNames)!=0;
+ shortNames = (db->flags & SQLITE_ShortColNames)!=0;
+ /* generate alias names for columns that are consistent with
generateColumnNames() */
+ for(i=0; i<pList->nExpr; i++){
+ if( pList->a[i].zName==0 ){
+ Expr *p;
+ p = pList->a[i].pExpr;
+
+ if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN) && pTabList &&
(shortNames || fullNames) ){
+ Table *pTab;
+ char *zCol;
+ int j, iCol = p->iColumn;
+ for(j=0; ALWAYS(j<pTabList->nSrc); j++){
+ if( pTabList->a[j].iCursor==p->iTable ) break;
+ }
+ assert( j<pTabList->nSrc );
+ pTab = pTabList->a[j].pTab;
+ if( iCol<0 ) iCol = pTab->iPKey;
+ assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
+ if( iCol<0 ){
+ zCol = "rowid";
+ }else{
+ zCol = pTab->aCol[iCol].zName;
+ }
+ if( fullNames ){
+ pList->a[i].zName = sqlite3MPrintf(db, "%s.%s", pTab->zName, zCol);
+ }else{
+ pList->a[i].zName = sqlite3DbStrDup(db, zCol);
+ }
+ }else{
+ const char *zSpan = pList->a[i].zSpan;
+ if( ALWAYS(zSpan) ){
+ pList->a[i].zName = sqlite3DbStrDup(db, zSpan);
+ }
+ }
+ }
+ }
+ }
+
/* Authorize the subquery */
pParse->zAuthContext = pSubitem->zName;
sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0);
pParse->zAuthContext = zSavedAuthContext;
@@ -2884,19 +2927,10 @@
** \_____________________ outer query ______________________________/
**
** We look at every expression in the outer query and every place we see
** "a" we substitute "x*3" and every place we see "b" we substitute "y+10".
*/
- pList = pParent->pEList;
- for(i=0; i<pList->nExpr; i++){
- if( pList->a[i].zName==0 ){
- const char *zSpan = pList->a[i].zSpan;
- if( ALWAYS(zSpan) ){
- pList->a[i].zName = sqlite3DbStrDup(db, zSpan);
- }
- }
- }
substExprList(db, pParent->pEList, iParent, pSub->pEList);
if( isAgg ){
substExprList(db, pParent->pGroupBy, iParent, pSub->pEList);
pParent->pHaving = substExpr(db, pParent->pHaving, iParent,
pSub->pEList);
}
--- src/select.c
+++ src/select.c
@@ -89284,7 +89284,7 @@
Expr *pColExpr = p; /* The expression that is the result column name */
Table *pTab; /* Table associated with this expression */
while( pColExpr->op==TK_DOT ) pColExpr = pColExpr->pRight;
- if( pColExpr->op==TK_COLUMN && ALWAYS(pColExpr->pTab!=0) ){
+ if( (pColExpr->op==TK_COLUMN || pColExpr->op==TK_AGG_COLUMN) &&
ALWAYS(pColExpr->pTab!=0) ){
/* For columns use the column name name */
int iCol = pColExpr->iColumn;
pTab = pColExpr->pTab;
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users