From 99c4483cd77ff96c5181fda3d6e2fcf2ea50421b Mon Sep 17 00:00:00 2001 From: Michael Chan Date: Mon, 27 Apr 2009 16:28:51 -0700 Subject: Allow caller-supplied column aliases in queries even when a projection map is used. Modified SQLiteQueryBuilder to allow caller-spplied column alias ("AS") instead restricting to the keys of the supplied projection map. This is needed for UNION queries where new columns may be created on the fly such as "1 AS flag" --- .../java/android/database/sqlite/SQLiteQueryBuilder.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'core/java/android/database') diff --git a/core/java/android/database/sqlite/SQLiteQueryBuilder.java b/core/java/android/database/sqlite/SQLiteQueryBuilder.java index 519a81c..ab7c827 100644 --- a/core/java/android/database/sqlite/SQLiteQueryBuilder.java +++ b/core/java/android/database/sqlite/SQLiteQueryBuilder.java @@ -486,12 +486,20 @@ public class SQLiteQueryBuilder String userColumn = projectionIn[i]; String column = mProjectionMap.get(userColumn); - if (column == null) { - throw new IllegalArgumentException( - "Invalid column " + projectionIn[i]); - } else { + if (column != null) { projection[i] = column; + continue; } + + if (userColumn.contains(" AS ") + || userColumn.contains(" as ")) { + /* A column alias already exist */ + projection[i] = userColumn; + continue; + } + + throw new IllegalArgumentException("Invalid column " + + projectionIn[i]); } return projection; } else { -- cgit v1.1