db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jakob Braeuchi <jbraeu...@gmx.ch>
Subject Re: fixed PlatformMySQLImpl to support LOBs
Date Sun, 23 Nov 2003 10:23:47 GMT
hi michael,

thanks for the patch. it's available in cvs now.

jakob

Michael Mogley wrote:

> All,
> 
> I believe I've fixed the problem.  The MySQL implementation was completely
> ignoring the special case of BLOB/CLOB.  I simply copied the LOB treatment
> in PlatformOracleImpl and merged this into PlatformMySQLImpl, with some
> minor changes.  Have not fully tested but it works fine for what I'm doing,
> which is inserting images into blob fields.
> 
> I'm not sure yet how to create patches, so here is the changed method in
> PlatformMySQLImpl:
> 
>     /*
>      * @see Platform#setObjectForStatement(PreparedStatement, int, Object,
> int)
>      */
>     public void setObjectForStatement(PreparedStatement ps, int index,
> Object value, int sqlType)
>         throws SQLException
>     {
>         switch (sqlType)
>         {
>             case Types.BIT:
>                  ps.setObject(index, value);
>             break;
> 
>             case Types.BLOB:
>             case Types.LONGVARBINARY:
>             case Types.VARBINARY:
>                 if (value instanceof byte[]) {
>                     byte buf[] = (byte[]) value;
>                     ByteArrayInputStream inputStream = new
> ByteArrayInputStream(buf);
>                     ps.setBinaryStream(index, inputStream, buf.length);
> 
>                     break;
>                 }
> 
>             case Types.CLOB:
>                 Reader reader = null;
>                 int length = 0;
> 
>                 if (value instanceof String)
>                 {
>                     reader = new StringReader((String) value);
>                     length = (((String) value)).length();
>                 }
>                 else if (value instanceof byte[])
>                 {
>                     byte buf[] = (byte[]) value;
>                     ByteArrayInputStream inputStream = new
> ByteArrayInputStream(buf);
>                     reader = new InputStreamReader(inputStream);
>                 }
> 
>                 ps.setCharacterStream(index, reader, length);
>             break;
> 
>             default:
>                  super.setObjectForStatement(ps,index,value,sqlType);
>             break;
>         }
>     }
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message