]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Avoid ambiguous column name errors when the column name is in the USING clause
authordrh <drh@noemail.net>
Mon, 6 Jun 2005 17:11:46 +0000 (17:11 +0000)
committerdrh <drh@noemail.net>
Mon, 6 Jun 2005 17:11:46 +0000 (17:11 +0000)
of a join.  Ticket #743. (CVS 2495)

FossilOrigin-Name: 6a51bdeeff8312fa54fa2b1200f823428f35d605

manifest
manifest.uuid
src/expr.c
test/join.test

index 6e64112cc435173ef9a70a01a94ff5a73f1afb37..8145ffdb3260152a92aee4e6a1646ba3b44a32eb 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Naming\sthe\sjoin\scolumns\sin\sthe\sresult\sset\sof\sa\snatural\sjoin\sdoes\snot\sresult\nin\san\s"ambiguous\scolumn\sname"\serror.\s\sTicket\s#1217.\s(CVS\s2494)
-D 2005-06-06T16:59:24
+C Avoid\sambiguous\scolumn\sname\serrors\swhen\sthe\scolumn\sname\sis\sin\sthe\sUSING\sclause\nof\sa\sjoin.\s\sTicket\s#743.\s(CVS\s2495)
+D 2005-06-06T17:11:46
 F Makefile.in 8129e7f261d405db783676f9ca31e0841768c652
 F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -37,7 +37,7 @@ F src/callback.c 0910b611e0c158f107ee3ff86f8a371654971e2b
 F src/date.c 2134ef4388256e8247405178df8a61bd60dc180a
 F src/delete.c 75b53db21aa1879d3655bbbc208007db31d58a63
 F src/experimental.c 50c1e3b34f752f4ac10c36f287db095c2b61766d
-F src/expr.c 3a8dae4bfa478fcffad1bacfce645e8b9ecaf0a7
+F src/expr.c e2aec43eda9d5f8cf6a7eb3adee59ec913effed7
 F src/func.c f208d71f741d47b63277530939f552815af8ce35
 F src/hash.c 2b1b13f7400e179631c83a1be0c664608c8f021f
 F src/hash.h 1b0c445e1c89ff2aaad9b4605ba61375af001e84
@@ -144,7 +144,7 @@ F test/insert3.test c67f0240b1c17e71fa2ed8bb6de064928f549f95
 F test/interrupt.test 170f87c2819f0e56c76e0a754949ea103d05009c
 F test/intpkey.test aaee5325eedf48b8f1e01d0d6e3f7c712908179b
 F test/ioerr.test b27540c5873d28c0e77f02ce85b15f904d5b03a6
-F test/join.test 8d17a014c09b55341a3f4de7d3ba357e342b2c7a
+F test/join.test db3802739fb695bdfa2e88805e3d64ec5ffbebd1
 F test/join2.test f2171c265e57ee298a27e57e7051d22962f9f324
 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
 F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
@@ -281,7 +281,7 @@ F www/tclsqlite.tcl 425be741b8ae664f55cb1ef2371aab0a75109cf9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 528299b8316726dbcc5548e9aa0648c8b1bd055b
-P 0d57f851ae4f483985710db149c8f541e45cdb86
-R 9469697d6a1c4cc6fbe1741dbc1f5add
+P 265fb6079c0a4b7a93f063939436db494ff1d56c
+R cca026e07dbc9f19c88e6b197e703c3a
 U drh
-Z 61e967726e8372ccce8b56eb5899004e
+Z b6b1f25cc7643f9245d6474cb22ef036
index b0898c6d11db308b7ac284b8b5955adff7badd24..a87690df74b926e4486eaa67d040e55c244948cd 100644 (file)
@@ -1 +1 @@
-265fb6079c0a4b7a93f063939436db494ff1d56c
\ No newline at end of file
+6a51bdeeff8312fa54fa2b1200f823428f35d605
\ No newline at end of file
index 44664d215fe3bbbdb0909a9d42dcb023e36b1f0d..5cfd280c7a0037ecf1a5005c61f79ea75aff3dc5 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains routines used for analyzing expressions and
 ** for generating VDBE code that evaluates expressions in SQLite.
 **
-** $Id: expr.c,v 1.203 2005/06/06 16:59:24 drh Exp $
+** $Id: expr.c,v 1.204 2005/06/06 17:11:46 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -817,6 +817,7 @@ static int lookupName(
         }
         for(j=0, pCol=pTab->aCol; j<pTab->nCol; j++, pCol++){
           if( sqlite3StrICmp(pCol->zName, zCol)==0 ){
+            IdList *pUsing;
             cnt++;
             pExpr->iTable = pItem->iCursor;
             pMatch = pItem;
@@ -831,6 +832,19 @@ static int lookupName(
               pItem++;
               i++;
             }
+            if( (pUsing = pItem->pUsing)!=0 ){
+              /* If this match occurs on a column that is in the USING clause
+              ** of a join, skip the search of the right table of the join
+              ** to avoid a duplicate match there. */
+              int k;
+              for(k=0; k<pUsing->nId; k++){
+                if( sqlite3StrICmp(pUsing->a[k].zName, zCol)==0 ){
+                  pItem++;
+                  i++;
+                  break;
+                }
+              }
+            }
             break;
           }
         }
index 3a511945a9006bd29477aa724caec39ebb2fdb41..138633aaea2c0ff329fb08e25d7b4ae471a810f8 100644 (file)
@@ -12,7 +12,7 @@
 #
 # This file implements tests for joins, including outer joins.
 #
-# $Id: join.test,v 1.19 2005/06/06 16:59:24 drh Exp $
+# $Id: join.test,v 1.20 2005/06/06 17:11:46 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -81,6 +81,11 @@ do_test join-1.4.4 {
     SELECT * FROM t1 AS x INNER JOIN t2 AS y USING(b,c);
   }
 } {a 1 b 2 c 3 d 4 a 2 b 3 c 4 d 5}
+do_test join-1.4.5 {
+  execsql {
+    SELECT b FROM t1 JOIN t2 USING(b);
+  }
+} {2 3}
 do_test join-1.5 {
   execsql2 {
     SELECT * FROM t1 INNER JOIN t2 USING(b);