This is an automated email from the ASF dual-hosted git repository.

doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git


The following commit(s) were added to refs/heads/master by this push:
     new 8afc556  Bugfix TEST DBMSHandlerSQLite
8afc556 is described below

commit 8afc55604f14aefe627ae52cf4711ed13e274c43
Author: Rainer Döbele <[email protected]>
AuthorDate: Tue Mar 8 12:17:16 2022 +0100

    Bugfix TEST DBMSHandlerSQLite
---
 .../empire/db/codegen/CodeGenParserTest.java       | 15 ++++++++++---
 .../main/java/org/apache/empire/db/DBReader.java   | 10 ++++++---
 .../empire/dbms/sqlite/DBMSHandlerSQLite.java      | 26 +++++++++++++---------
 .../empire/dbms/sqlite/DBMSHandlerSQLiteTest.java  |  7 +++++-
 4 files changed, 40 insertions(+), 18 deletions(-)

diff --git 
a/empire-db-codegen/src/test/java/org/apache/empire/db/codegen/CodeGenParserTest.java
 
b/empire-db-codegen/src/test/java/org/apache/empire/db/codegen/CodeGenParserTest.java
index 6848c71..0451a61 100644
--- 
a/empire-db-codegen/src/test/java/org/apache/empire/db/codegen/CodeGenParserTest.java
+++ 
b/empire-db-codegen/src/test/java/org/apache/empire/db/codegen/CodeGenParserTest.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
 
 import java.sql.Connection;
+import java.sql.SQLException;
 import java.util.List;
 
 import org.apache.empire.db.DBColumn;
@@ -48,8 +49,6 @@ public class CodeGenParserTest {
         public DBDatabase parseModel(final CodeGenConfig config) {
             // get the DBMS
             DBMSHandler dbms = getDBMSHandler(config);
-            // get the JDBC-Connection
-            Connection conn = getJDBCConnection(config);
             // read the database model
             // CodeGenParser parser = new CodeGenParser(config);
             DBModelParser modelParser = 
dbms.createModelParser(config.getDbCatalog(), config.getDbSchema());
@@ -57,7 +56,17 @@ public class CodeGenParserTest {
             modelParser.setStandardIdentityColumnName 
(config.getIdentityColumn());
             
modelParser.setStandardTimestampColumnName(config.getTimestampColumn());
             // parse now
-            modelParser.parseModel(conn);
+            // get the JDBC-Connection
+            Connection conn = getJDBCConnection(config);
+            try {
+                modelParser.parseModel(conn);
+            } finally {
+                try {
+                    conn.close();
+                } catch (SQLException e) {
+                    System.err.println("Unable to close connection");
+                }
+            }
             // done
             return modelParser.getDatabase();
         }
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBReader.java 
b/empire-db/src/main/java/org/apache/empire/db/DBReader.java
index f33465b..88e2a84 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBReader.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBReader.java
@@ -40,6 +40,7 @@ import org.apache.empire.db.exceptions.EmpireSQLException;
 import org.apache.empire.db.exceptions.NoPrimaryKeyException;
 import org.apache.empire.db.exceptions.QueryNoResultException;
 import org.apache.empire.db.list.DataBean;
+import org.apache.empire.dbms.DBMSHandler;
 import org.apache.empire.exceptions.BeanInstantiationException;
 import org.apache.empire.exceptions.InvalidArgumentException;
 import org.apache.empire.exceptions.ObjectNotValidException;
@@ -252,6 +253,7 @@ public class DBReader extends DBRecordData implements 
Closeable
     private DBDatabase     db      = null;
     private DBColumnExpr[] columns = null;
     private ResultSet      rset    = null;
+    private DBMSHandler    dbms    = null;
     // the field index map
     private Map<ColumnExpr, Integer> fieldIndexMap = null;
 
@@ -402,10 +404,10 @@ public class DBReader extends DBRecordData implements 
Closeable
         try
         {   // Get Value from Resultset
             DataType dataType = columns[index].getDataType();
-            return context.getDbms().getResultValue(rset, index + 1, dataType);
+            return dbms.getResultValue(rset, index + 1, dataType);
 
-        } catch (SQLException e)
-        { // Operation failed
+        } catch (SQLException e) {
+            // Operation failed
             throw new EmpireSQLException(context.getDbms(), e);
         }
     }
@@ -556,6 +558,7 @@ public class DBReader extends DBRecordData implements 
Closeable
             // Detach columns
             columns = null;
             rset = null;
+            dbms = null;
             // clear FieldIndexMap
             if (fieldIndexMap!=null)
                 fieldIndexMap.clear();
@@ -896,6 +899,7 @@ public class DBReader extends DBRecordData implements 
Closeable
     protected void init(DBDatabase db, DBColumnExpr[] columns, ResultSet rset)
     {
         this.db = db;
+        this.dbms = db.getDbms();
         this.columns = columns;
         this.rset = rset;
         // clear fieldIndexMap         
diff --git 
a/empire-db/src/main/java/org/apache/empire/dbms/sqlite/DBMSHandlerSQLite.java 
b/empire-db/src/main/java/org/apache/empire/dbms/sqlite/DBMSHandlerSQLite.java
index 16b1545..c2de819 100644
--- 
a/empire-db/src/main/java/org/apache/empire/dbms/sqlite/DBMSHandlerSQLite.java
+++ 
b/empire-db/src/main/java/org/apache/empire/dbms/sqlite/DBMSHandlerSQLite.java
@@ -470,17 +470,21 @@ public class DBMSHandlerSQLite extends DBMSHandlerBase
     {
         if (dataType == DataType.DATETIME || dataType == DataType.TIMESTAMP)
         {
-            // SQLite does not have a Date type, or any kind of type :(
-            String datePattern = 
getSQLPhrase(DBSqlPhrase.SQL_DATETIME_PATTERN);
-            DateFormat dateFormat = new SimpleDateFormat(datePattern);
-            try
-            {
-                Date timestamp = dateFormat.parse(rset.getString(columnIndex));
-                return new java.sql.Timestamp(timestamp.getTime());
-            }
-            catch (ParseException e)
-            {
-                throw new 
UnexpectedReturnValueException(rset.getString(columnIndex), "getResultValue");
+            try {
+                // try timestamp
+                return rset.getTimestamp(columnIndex);
+            } catch(Exception ex) {
+                try
+                {   // try Convert from String
+                    String datePattern = 
getSQLPhrase(DBSqlPhrase.SQL_DATETIME_PATTERN);
+                    DateFormat dateFormat = new SimpleDateFormat(datePattern);
+                    Date timestamp = 
dateFormat.parse(rset.getString(columnIndex));
+                    return new java.sql.Timestamp(timestamp.getTime());
+                }
+                catch (ParseException e)
+                {   
+                    throw new 
UnexpectedReturnValueException(rset.getString(columnIndex), "getResultValue");
+                }
             }
         }
         else if (dataType == DataType.CLOB)
diff --git 
a/empire-db/src/test/java/org/apache/empire/dbms/sqlite/DBMSHandlerSQLiteTest.java
 
b/empire-db/src/test/java/org/apache/empire/dbms/sqlite/DBMSHandlerSQLiteTest.java
index c5dfc84..a809541 100644
--- 
a/empire-db/src/test/java/org/apache/empire/dbms/sqlite/DBMSHandlerSQLiteTest.java
+++ 
b/empire-db/src/test/java/org/apache/empire/dbms/sqlite/DBMSHandlerSQLiteTest.java
@@ -55,6 +55,7 @@ public class DBMSHandlerSQLiteTest{
         DBContext context = new DBContextStatic(dbms, conn); 
         
         CompanyDB db = new CompanyDB();
+        
         db.open(context);
         DBSQLScript script = new DBSQLScript(context);
         db.getCreateDDLScript(script);
@@ -86,7 +87,11 @@ public class DBMSHandlerSQLiteTest{
         
         // Update an Employee
         emp = new DBRecord(context, db.EMPLOYEE);
-        emp.read(id);
+        try {
+            emp.read(id);
+        } catch(Throwable t) {
+            System.out.println(t.toString());
+        }
         // Set
         emp.set(db.EMPLOYEE.PHONE_NUMBER, "123456");
         emp.update();

Reply via email to