Skip to content
Snippets Groups Projects
Commit 09fac540 authored by Grégory Mantelet's avatar Grégory Mantelet
Browse files

[ADQL] In the FROM, set a default alias for each table reference

(i.e. not a subquery).

The idea is to avoid ambiguous error messages coming from the database when
raising an error on a table or column name having different DB and ADQL names.

This commit sets by default an alias on each table reference. This default
alias is the ADQL table name as it is used in the ADQL query.

_This commit fixes the GitHub issue #108 ._
parent e136017d
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ package adql.query.from;
* 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-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
* Copyright 2012-2019 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
* Astronomisches Rechen Institut (ARI)
*/
......@@ -40,7 +40,7 @@ import adql.query.TextPosition;
* A table reference may have an alias (MUST if it is a sub-query).
*
* @author Gr&eacute;gory Mantelet (CDS;ARI)
* @version 1.4 (09/2017)
* @version 1.5 (09/2019)
*/
public class ADQLTable implements ADQLObject, FromContent {
......@@ -56,7 +56,8 @@ public class ADQLTable implements ADQLObject, FromContent {
/** A sub-query whose the result will be used as a table. */
private ADQLQuery subQuery;
/** Label of the table reference. */
/** Label of the table reference.
* If not a sub-query, this attribute is set by default to the table name. */
private String alias = null;
/** Lets specify the case sensitivity of the catalog, schema, table and alias parts. */
......@@ -273,12 +274,26 @@ public class ADQLTable implements ADQLObject, FromContent {
* @param newTableName The new name of the table.
*/
public void setTableName(String newTableName){
// Normalise the table name:
final String temp = normalizeName(newTableName, IdentifierField.TABLE);
// Remove the DB metadata ONLY if the table name is different:
if ((this.table == null && temp != null) || (this.table != null && !this.table.equalsIgnoreCase(temp)))
dbLink = null;
// Set the table name:
this.table = temp;
// Ensure no sub-query is set:
if (table != null)
subQuery = null;
// Finally set this table name as default table alias:
/* Note: this aims to avoid ambiguous error messages coming from the
* database when the DB and the ADQL names of a table are
* different. */
setAlias(this.table);
setCaseSensitive(IdentifierField.ALIAS, isCaseSensitive(IdentifierField.TABLE));
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment