You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by do...@apache.org on 2022/01/24 00:03:28 UTC
[empire-db] branch version3 updated: EMPIREDB-362 DBDatabaseDriverSQLLite bugfix
This is an automated email from the ASF dual-hosted git repository.
doebele pushed a commit to branch version3
in repository https://gitbox.apache.org/repos/asf/empire-db.git
The following commit(s) were added to refs/heads/version3 by this push:
new 512e1cf EMPIREDB-362 DBDatabaseDriverSQLLite bugfix
512e1cf is described below
commit 512e1cfee3ee2b5cf96f5c33c99c4242155319e8
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Mon Jan 24 01:03:25 2022 +0100
EMPIREDB-362 DBDatabaseDriverSQLLite bugfix
---
.../db/driver/sqlite/DBDatabaseDriverSQLite.java | 117 +++++++++++++++------
1 file changed, 83 insertions(+), 34 deletions(-)
diff --git a/empire-db/src/main/java/org/apache/empire/db/driver/sqlite/DBDatabaseDriverSQLite.java b/empire-db/src/main/java/org/apache/empire/db/driver/sqlite/DBDatabaseDriverSQLite.java
index ca5482f..9702320 100644
--- a/empire-db/src/main/java/org/apache/empire/db/driver/sqlite/DBDatabaseDriverSQLite.java
+++ b/empire-db/src/main/java/org/apache/empire/db/driver/sqlite/DBDatabaseDriverSQLite.java
@@ -372,40 +372,6 @@ public class DBDatabaseDriverSQLite extends DBDatabaseDriverBase
}
}
- @Override
- public Object getResultValue(ResultSet rset, int columnIndex, DataType dataType) throws SQLException
- {
- 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");
- }
- }
- else if (dataType == DataType.CLOB)
- {
- java.sql.Clob clob = rset.getClob(columnIndex);
- return ((clob != null) ? clob.getSubString(1, (int) clob.length()) : null);
- }
- else if (dataType == DataType.BLOB)
- { // Get bytes of a binary large object
- java.sql.Blob blob = rset.getBlob(columnIndex);
- return ((blob != null) ? blob.getBytes(1, (int) blob.length()) : null);
- }
- else
- {
- return rset.getObject(columnIndex);
- }
- }
-
/**
* @see DBDatabaseDriver#getConvertPhrase(DataType, DataType, Object)
*/
@@ -448,6 +414,89 @@ public class DBDatabaseDriverSQLite extends DBDatabaseDriverBase
return "?";
}
}
+
+ /**
+ * Override since
+ * conn.prepareStatement(sqlCmd, Statement.RETURN_GENERATED_KEYS)
+ * is not supported by SQLLite driver
+ */
+ @Override
+ public int executeSQL(String sqlCmd, Object[] sqlParams, Connection conn, DBSetGenKeys genKeys) throws SQLException
+ {
+ Statement stmt = null;
+ int count = 0;
+ try
+ {
+ if (sqlParams != null)
+ { // Use a prepared statement
+ PreparedStatement pstmt = conn.prepareStatement(sqlCmd);
+ stmt = pstmt;
+ prepareStatement(pstmt, sqlParams);
+ count = pstmt.executeUpdate();
+ }
+ else
+ { // Execute a simple statement
+ stmt = conn.createStatement();
+ count = stmt.executeUpdate(sqlCmd);
+ }
+ // Retrieve any auto-generated keys
+ if (genKeys != null && count > 0)
+ { // Return Keys
+ ResultSet rs = stmt.getGeneratedKeys();
+ try
+ {
+ while (rs.next())
+ {
+ genKeys.set(rs.getObject(1));
+ }
+ }
+ finally
+ {
+ rs.close();
+ }
+ }
+ }
+ finally
+ {
+ closeStatement(stmt);
+ }
+ return count;
+ }
+
+
+ @Override
+ public Object getResultValue(ResultSet rset, int columnIndex, DataType dataType) throws SQLException
+ {
+ 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");
+ }
+ }
+ else if (dataType == DataType.CLOB)
+ {
+ java.sql.Clob clob = rset.getClob(columnIndex);
+ return ((clob != null) ? clob.getSubString(1, (int) clob.length()) : null);
+ }
+ else if (dataType == DataType.BLOB)
+ { // Get bytes of a binary large object
+ java.sql.Blob blob = rset.getBlob(columnIndex);
+ return ((blob != null) ? blob.getBytes(1, (int) blob.length()) : null);
+ }
+ else
+ {
+ return rset.getObject(columnIndex);
+ }
+ }
/**
* Overridden. Returns a timestamp that is used for record updates created