empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From franci...@apache.org
Subject svn commit: r1365137 - in /empire-db/trunk/empire-db/src: main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java
Date Tue, 24 Jul 2012 15:40:41 GMT
Author: francisdb
Date: Tue Jul 24 15:40:41 2012
New Revision: 1365137

URL: http://svn.apache.org/viewvc?rev=1365137&view=rev
Log:
EMPIREDB-147 fix BLOB reading in postgresql

Modified:
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
    empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java?rev=1365137&r1=1365136&r2=1365137&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
(original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
Tue Jul 24 15:40:41 2012
@@ -452,18 +452,19 @@ public class DBDatabaseDriverPostgreSQL 
     }
     
     /**
-     * Postgre needs special handling for CLOBs
+     * Postgre needs special handling for CLOBs and BLOB's
      */
     @Override
     public Object getResultValue(ResultSet rset, int columnIndex, DataType dataType)
         throws SQLException
     {
-        if (dataType == DataType.CLOB)
-        {
-            return rset.getString(columnIndex);
-        }
-        // default handling
-        return super.getResultValue(rset, columnIndex, dataType);
+    	switch(dataType)
+    	{
+    		case BLOB: return rset.getBytes(columnIndex);
+    		case CLOB:	return rset.getString(columnIndex);
+    		default:   return super.getResultValue(rset, columnIndex, dataType);
+    	}
     }
+
     
 }

Modified: empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java?rev=1365137&r1=1365136&r2=1365137&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java
(original)
+++ empire-db/trunk/empire-db/src/test/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQLTest.java
Tue Jul 24 15:40:41 2012
@@ -19,18 +19,23 @@
 package org.apache.empire.db.postgresql;
 
 import java.sql.Connection;
+import java.sql.SQLException;
 
 import org.apache.empire.DBResource;
 import org.apache.empire.DBResource.DB;
 import org.apache.empire.db.CompanyDB;
 import org.apache.empire.db.DBCommand;
 import org.apache.empire.db.DBDatabaseDriver;
+import org.apache.empire.db.DBReader;
+import org.apache.empire.db.DBRecord;
 import org.apache.empire.db.DBSQLScript;
 import org.apache.empire.db.exceptions.QueryFailedException;
+import org.junit.Assert;
 import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 
+// Ignored as the db is not available everywhere
 @Ignore
 public class DBDatabaseDriverPostgreSQLTest 
 {
@@ -39,14 +44,14 @@ public class DBDatabaseDriverPostgreSQLT
 	public DBResource dbResource = new DBResource(DB.POSTGRESQL);
 
 	@Test
-	public void testBlob() 
+	public void testBlobDDL() throws SQLException 
 	{
 		Connection conn = dbResource.getConnection();
 
 		DBDatabaseDriver driver = dbResource.newDriver();
 		CompanyDB db = new CompanyDB();
 
-		// Encoding issue occur when prepared statement is disabled
+		// Encoding issue occurs when prepared statement is disabled
 		//db.setPreparedStatementsEnabled(true);
 
 		db.open(driver, dbResource.getConnection());
@@ -57,6 +62,38 @@ public class DBDatabaseDriverPostgreSQLT
 			System.out.println(script.toString());
 			script.run(db.getDriver(), dbResource.getConnection(), false);
 		}
+		
+		conn.close();
+	}
+	
+	@Test
+	public void testBlobWritingReading() throws SQLException 
+	{
+		Connection conn = dbResource.getConnection();
+
+		DBDatabaseDriver driver = dbResource.newDriver();
+		CompanyDB db = new CompanyDB();
+
+		// Encoding issue occurs when prepared statement is disabled
+		//db.setPreparedStatementsEnabled(true);
+
+		db.open(driver, dbResource.getConnection());
+		
+		DBRecord emp = new DBRecord();
+        emp.create(db.DATA);
+        emp.setValue(db.DATA.DATA, new byte[]{1,2,3});
+        emp.update(conn);
+		
+		// read a value
+		DBCommand cmd = db.createCommand();
+		cmd.select(db.DATA.DATA);
+		DBReader reader = new DBReader();
+		reader.open(cmd, conn);
+		while(reader.moveNext()){
+			byte[] value = (byte[]) reader.getValue(db.DATA.DATA);
+			Assert.assertArrayEquals(new byte[]{1,2,3}, value);
+		}
+		conn.close();
 	}
 	
 	/**



Mime
View raw message