summaryrefslogtreecommitdiffstats
path: root/src/com/iciql/QueryWhere.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/iciql/QueryWhere.java')
-rw-r--r--src/com/iciql/QueryWhere.java43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/com/iciql/QueryWhere.java b/src/com/iciql/QueryWhere.java
index df93439..0a07c40 100644
--- a/src/com/iciql/QueryWhere.java
+++ b/src/com/iciql/QueryWhere.java
@@ -112,7 +112,7 @@ public class QueryWhere<T> {
return addPrimitive(ConditionAndOr.AND, x);
}
- private <A> QueryCondition<T, A> addPrimitive(ConditionAndOr condition, A x) {
+ private <A> QueryCondition<T, A> addPrimitive(ConditionAndOr condition, A x) {
query.addConditionToken(condition);
A alias = query.getPrimitiveAliasByValue(x);
if (alias == null) {
@@ -234,10 +234,6 @@ public class QueryWhere<T> {
return this;
}
- public <X, Z> List<X> select(Z x) {
- return query.select(x);
- }
-
public String getSQL() {
SQLStatement stat = new SQLStatement(query.getDb());
stat.appendSQL("SELECT *");
@@ -245,6 +241,43 @@ public class QueryWhere<T> {
return stat.getSQL().trim();
}
+ /**
+ * toSQL returns a static string version of the query with runtime variables
+ * properly encoded. This method is also useful when combined with the where
+ * clause methods like isParameter() or atLeastParameter() which allows
+ * iciql to generate re-usable parameterized string statements.
+ *
+ * @return the sql query as plain text
+ */
+ public String toSQL() {
+ return this.toSQL(false);
+ }
+
+ /**
+ * toSQL returns a static string version of the query with runtime variables
+ * properly encoded. This method is also useful when combined with the where
+ * clause methods like isParameter() or atLeastParameter() which allows
+ * iciql to generate re-usable parameterized string statements.
+ *
+ * @param distinct
+ * if true SELECT DISTINCT is used for the query
+ * @return the sql query as plain text
+ */
+ public String toSQL(boolean distinct) {
+ SQLStatement stat = new SQLStatement(query.getDb());
+ if (distinct) {
+ stat.appendSQL("SELECT DISTINCT *");
+ } else {
+ stat.appendSQL("SELECT *");
+ }
+ query.appendFromWhere(stat);
+ return stat.toSQL().trim();
+ }
+
+ public <X, Z> List<X> select(Z x) {
+ return query.select(x);
+ }
+
public <X, Z> List<X> selectDistinct(Z x) {
return query.selectDistinct(x);
}