Commit 84ede4bf authored by gmantele's avatar gmantele
Browse files

[ADQL] Fix a bug reported by M. Taylor about qualified table name:

when in a table definition (extension of DBTable) no schema is
specified, it was possible to prefix the table name by a fake
schema name ; it was checked at all:
e.g. "SELECT * FROM no_schema.foo".
This is no longer possible: if no schema is specified, no schema
must be used in an ADQL query. But if one is specified, the schema
prefix is optional.
parent b49f8160
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -97,7 +97,7 @@ import adql.search.SimpleSearchHandler;
 * </i></p>
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 1.4 (06/2015)
 * @version 1.4 (08/2015)
 */
public class DBChecker implements QueryChecker {

@@ -581,7 +581,7 @@ public class DBChecker implements QueryChecker {
			return tables.get(0);
		// but if more than one: ambiguous table name !
		else if (tables.size() > 1)
			throw new UnresolvedTableException(table, tables.get(0).getADQLSchemaName() + "." + tables.get(0).getADQLName(), tables.get(1).getADQLSchemaName() + "." + tables.get(1).getADQLName());
			throw new UnresolvedTableException(table, (tables.get(0).getADQLSchemaName() == null ? "" : tables.get(0).getADQLSchemaName() + ".") + tables.get(0).getADQLName(), (tables.get(1).getADQLSchemaName() == null ? "" : tables.get(1).getADQLSchemaName() + ".") + tables.get(1).getADQLName());
		// otherwise (no match): unknown table !
		else
			throw new UnresolvedTableException(table);
+10 −3
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ package adql.db;
 * 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,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 * Copyright 2012,2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 */

@@ -24,7 +24,7 @@ package adql.db;
 * Default implementation of {@link DBColumn}.
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 1.3 (10/2014)
 * @version 1.4 (08/2015)
 */
public class DefaultDBColumn implements DBColumn {

@@ -96,9 +96,11 @@ public class DefaultDBColumn implements DBColumn {
	 * @param dbName	Database column name.
	 * 					<b>Only the column name is expected. Contrary to {@link DefaultDBTable},
	 * 					if a whole column reference is given, no split will be done.</b>
	 *              	<b>REQUIRED parameter: it must be not NULL.</b> 
	 * @param adqlName	Column name used in ADQL queries.
	 * 					<b>Only the column name is expected. Contrary to {@link DefaultDBTable},
	 * 					if a whole column reference is given, no split will be done.</b>
	 *                	<em>If NULL, it will be set to dbName.</em>
	 * @param type		Type of the column.
	 *            		<i>Note: there is no default value. Consequently if this parameter is NULL,
	 *            		the type should be considered as unknown. It means that any comparison with
@@ -108,8 +110,13 @@ public class DefaultDBColumn implements DBColumn {
	 * @since 1.3
	 */
	public DefaultDBColumn(final String dbName, final String adqlName, final DBType type, final DBTable table){

		if (dbName == null || dbName.length() == 0)
			throw new NullPointerException("Missing DB name!");

		this.dbName = dbName;
		this.adqlName = adqlName;
		this.adqlName = (adqlName == null) ? dbName : adqlName;

		this.type = type;
		this.table = table;
	}
+8 −5
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ package adql.db;
 * 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-2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 */

@@ -29,7 +29,7 @@ import java.util.Map;
 * Default implementation of {@link DBTable}.
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 1.3 (11/2014)
 * @version 1.4 (08/2015)
 */
public class DefaultDBTable implements DBTable {

@@ -107,10 +107,13 @@ public class DefaultDBTable implements DBTable {
	 * 
	 * @param dbCatName		Database catalog name.
	 * @param adqlCatName	Catalog name used in ADQL queries.
	 *                   	<em>If NULL, it will be set to dbCatName.</em>
	 * @param dbSchemName	Database schema name.
	 * @param adqlSchemName	Schema name used in ADQL queries.
	 *                   	<em>If NULL, it will be set to dbSchemName.</em>
	 * @param dbName		Database table name.
	 * @param adqlName		Table name used in ADQL queries.
	 *                   	<em>If NULL, it will be set to dbName.</em>
	 */
	public DefaultDBTable(final String dbCatName, final String adqlCatName, final String dbSchemName, final String adqlSchemName, final String dbName, final String adqlName){

@@ -118,13 +121,13 @@ public class DefaultDBTable implements DBTable {
			throw new NullPointerException("Missing DB name !");

		this.dbName = dbName;
		this.adqlName = adqlName;
		this.adqlName = (adqlName == null) ? dbName : adqlName;

		dbSchemaName = dbSchemName;
		adqlSchemaName = adqlSchemName;
		adqlSchemaName = (adqlSchemName == null) ? dbSchemName : adqlSchemName;

		dbCatalogName = dbCatName;
		adqlCatalogName = adqlCatName;
		adqlCatalogName = (adqlCatName == null) ? dbCatName : adqlCatName;
	}

	@Override
+9 −3
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ package adql.db;
 * 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-2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 * Copyright 2012-2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS),
 *                       Astronomisches Rechen Institut (ARI)
 */

@@ -46,7 +46,7 @@ import cds.utils.TextualSearchList;
 * </i></p>
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 1.3 (02/2015)
 * @version 1.4 (08/2015)
 */
public class SearchColumnList extends TextualSearchList<DBColumn> {
	private static final long serialVersionUID = 1L;
@@ -284,7 +284,10 @@ public class SearchColumnList extends TextualSearchList<DBColumn> {
					}

					// test the schema name:
					if (schema != null && matchTable.getADQLSchemaName() != null){
					if (schema != null){
						// No schema name (<=> no schema), then this table can not be a good match:
						if (matchTable.getADQLSchemaName() == null)
							continue;
						if (IdentifierField.SCHEMA.isCaseSensitive(caseSensitivity)){
							if (!matchTable.getADQLSchemaName().equals(schema))
								continue;
@@ -295,6 +298,9 @@ public class SearchColumnList extends TextualSearchList<DBColumn> {

						// test the catalog name:
						if (catalog != null){
							// No catalog name (<=> no catalog), then this table can not be a good match:
							if (matchTable.getADQLCatalogName() == null)
								continue;
							if (IdentifierField.CATALOG.isCaseSensitive(caseSensitivity)){
								if (!matchTable.getADQLCatalogName().equals(catalog))
									continue;
+20 −16
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ package adql.db;
 * 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,2014 - UDS/Centre de Données astronomiques de Strasbourg (CDS)
 * Copyright 2012,2015 - UDS/Centre de Données astronomiques de Strasbourg (CDS)
 *                       Astronomisches Rechen Institut (ARI)
 */

@@ -36,7 +36,7 @@ import cds.utils.TextualSearchList;
 * </p>
 * 
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 1.3 (02/2015)
 * @version 1.4 (08/2015)
 */
public class SearchTableList extends TextualSearchList<DBTable> {
	private static final long serialVersionUID = 1L;
@@ -156,7 +156,9 @@ public class SearchTableList extends TextualSearchList<DBTable> {
			ArrayList<DBTable> result = new ArrayList<DBTable>();

			for(DBTable match : tmpResult){
				if (match.getADQLSchemaName() != null){
				// No schema name (<=> no schema), then this table can not be a good match:
				if (match.getADQLSchemaName() == null)
					continue;
				if (IdentifierField.SCHEMA.isCaseSensitive(caseSensitivity)){
					if (!match.getADQLSchemaName().equals(schema))
						continue;
@@ -165,7 +167,10 @@ public class SearchTableList extends TextualSearchList<DBTable> {
						continue;
				}

					if (catalog != null && match.getADQLCatalogName() != null){
				if (catalog != null){
					// No catalog name (<=> no catalog), then this table can not be a good match:
					if (match.getADQLCatalogName() == null)
						continue;
					if (IdentifierField.CATALOG.isCaseSensitive(caseSensitivity)){
						if (!match.getADQLCatalogName().equals(catalog))
							continue;
@@ -174,7 +179,6 @@ public class SearchTableList extends TextualSearchList<DBTable> {
							continue;
					}
				}
				}

				result.add(match);
			}
Loading