Hello!

I'm learning to use peers in Turbine. In my database (mysql) I've a column which type 
is mediumblob. 
And I was unable to do BasePeer.doSelect(Criteria) without this path to 
org.apache.turbine.util.db.SqlExpression.java:

@@ -158,6 +158,11 @@
         {
             criteria = quoteString(criteria.toString());
         }
+        else if( criteria instanceof byte[])
+        {
+            criteria = encodeBytes((byte[]) criteria);
+        }
+        
         if ( comparison.equals(Criteria.LIKE) )
         {
             return buildLike( columnName, (String)criteria, ignoreCase, db );
@@ -406,5 +411,27 @@
                                  .append(value)
                                  .append("'")
                                  .toString();
+    }
+    
+    /** 
+        Encodes a byte[] ready for placement in a SQL expression.
+
+        @param value the byte[] to quote
+        @return encoded value as String
+    */
+    static String encodeBytes(byte value[])
+    {
+         StringBuffer result = new StringBuffer("0x");
+        int count = value.length;       
+        for(int i=0; i<count; i++)
+        {
+            String hex = Integer.toHexString(value[i]&0xff);
+            if (hex.length()==1)
+            {
+                result.append("0");
+            }
+            result.append(hex);
+        }
+        return result.toString();
     }
 }

Is it making any sense?

Slawek



------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to