From 7f5f199266a012fdb29a13736a6cc1f95b65ef7d Mon Sep 17 00:00:00 2001
From: gmantele <gmantele@ari.uni-heidelberg.de>
Date: Thu, 25 Sep 2014 15:37:55 +0200
Subject: [PATCH] [ADQL] Fix major bug for 'SELECT table.* ...' (it was
 translated by a 'SELECT * ...')

---
 src/adql/query/ADQLQuery.java        |  9 +++++++--
 src/adql/query/SelectAllColumns.java | 13 +++++++++----
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/adql/query/ADQLQuery.java b/src/adql/query/ADQLQuery.java
index 39a7e6b..75f3a64 100644
--- a/src/adql/query/ADQLQuery.java
+++ b/src/adql/query/ADQLQuery.java
@@ -38,7 +38,7 @@ import adql.search.ISearchHandler;
  * <p>The resulting object of the {@link ADQLParser} is an object of this class.</p>
  * 
  * @author Gr&eacute;gory Mantelet (CDS;ARI)
- * @version 1.2 (11/2013)
+ * @version 1.2 (09/2014)
  */
 public class ADQLQuery implements ADQLObject {
 
@@ -262,7 +262,12 @@ public class ADQLQuery implements ADQLObject {
 			ADQLOperand operand = item.getOperand();
 			if (item instanceof SelectAllColumns){
 				try{
-					columns.addAll(from.getDBColumns());
+					// If "{table}.*", add all columns of the specified table:
+					if (((SelectAllColumns)item).getAdqlTable() != null)
+						columns.addAll(((SelectAllColumns)item).getAdqlTable().getDBColumns());
+					// Otherwise ("*"), add all columns of all selected tables:
+					else
+						columns.addAll(from.getDBColumns());
 				}catch(ParseException pe){
 					// Here, this error should not occur any more, since it must have been caught by the DBChecker!
 				}
diff --git a/src/adql/query/SelectAllColumns.java b/src/adql/query/SelectAllColumns.java
index b94159f..fec54b9 100644
--- a/src/adql/query/SelectAllColumns.java
+++ b/src/adql/query/SelectAllColumns.java
@@ -20,15 +20,16 @@ import adql.query.from.ADQLTable;
  * You should have received a copy of the GNU Lesser General Public License
  * along with ADQLLibrary.  If not, see <http://www.gnu.org/licenses/>.
  * 
- * Copyright 2012 - UDS/Centre de Données astronomiques de Strasbourg (CDS)
+ * Copyright 2012,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
+ *                       Astronomisches Rechen Institut (ARI)
  */
 
 /**
  * In ADQL it corresponds to the '*' and '{tableName}.*' items in the SELECT clause.
  * It means: 'select all columns'.
  * 
- * @author Gr&eacute;gory Mantelet (CDS)
- * @version 01/2012
+ * @author Gr&eacute;gory Mantelet (CDS;ARI)
+ * @version 1.2 (09/2014)
  */
 public final class SelectAllColumns extends SelectItem {
 
@@ -106,7 +107,7 @@ public final class SelectAllColumns extends SelectItem {
 	 * @param table	An {@link ADQLTable} (MUST NOT BE NULL).
 	 */
 	public final void setAdqlTable(final ADQLTable table){
-		if (table == null){
+		if (table != null){
 			adqlTable = table;
 			query = null;
 		}
@@ -128,6 +129,7 @@ public final class SelectAllColumns extends SelectItem {
 
 			private boolean tableGot = (adqlTable == null);
 
+			@Override
 			public ADQLObject next() throws NoSuchElementException{
 				if (tableGot)
 					throw new NoSuchElementException();
@@ -135,10 +137,12 @@ public final class SelectAllColumns extends SelectItem {
 				return adqlTable;
 			}
 
+			@Override
 			public boolean hasNext(){
 				return !tableGot;
 			}
 
+			@Override
 			public void replace(ADQLObject replacer) throws UnsupportedOperationException, IllegalStateException{
 				if (replacer == null)
 					remove();
@@ -150,6 +154,7 @@ public final class SelectAllColumns extends SelectItem {
 					adqlTable = (ADQLTable)replacer;
 			}
 
+			@Override
 			public void remove(){
 				if (!tableGot)
 					throw new IllegalStateException("remove() impossible: next() has not yet been called !");
-- 
GitLab