fixed issue 22559: SqlC does execute all queries at compile time
authorStefan Hühner <stefan.huehner@openbravo.com>
Thu, 16 Jun 2016 10:04:13 +0200
changeset 29651 21698df6e4fe
parent 29650 47723fdf90f2
child 29652 d1bf16311eab
fixed issue 22559: SqlC does execute all queries at compile time

SqlC does execute all select queries at compile time when it is processing
xsql files.

Technically that is needed to get the number, names & data-types of the columns
in the result as that info is used to generate the fields and data-reading code
in the to be generated java file.

However the jdbc spec does have a optional method to get that same information
for a query without executing it.

As this method is supported in current jdbc drivers for both Oracle and PostgreSQL,
now it is used instead of executing the whole queries.
src-core/src/org/openbravo/data/Sqlc.java
--- a/src-core/src/org/openbravo/data/Sqlc.java	Thu Jun 16 09:28:41 2016 +0200
+++ b/src-core/src/org/openbravo/data/Sqlc.java	Thu Jun 16 10:04:13 2016 +0200
@@ -1,6 +1,6 @@
 /*
  ************************************************************************************
- * Copyright (C) 2001-2015 Openbravo S.L.U.
+ * Copyright (C) 2001-2016 Openbravo S.L.U.
  * Licensed under the Apache Software License version 2.0
  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  * Unless required by applicable law or agreed to  in writing,  software  distributed
@@ -736,10 +736,9 @@
       // Get the ResultSetMetaData. This will be used for
       // the column headings
       if (sql.executeType.equals("executeQuery")) {
-        result = preparedStatement.executeQuery();
-        if (log4j.isDebugEnabled())
-          log4j.debug("query done");
-        rsmd = result.getMetaData();
+        // No need to really run the query. Both pg & ora allow to get ResultSetMetaData from a
+        // PreparedStatement already
+        rsmd = preparedStatement.getMetaData();
         // Get the number of columns in the result set
         numCols = rsmd.getColumnCount();
         if (log4j.isDebugEnabled())