You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by Michael Mogley <mm...@adelphia.net> on 2003/12/18 23:22:04 UTC

PlatformMySQLImpl bug fix

All,

I just fixed a bug in PlatformMySQLImpl that prevents char[] types from being persisted as CLOBs.  Here is the new setObjectForStatement method:

    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 char[])
                {
                    String string = new String((char[])value);
                    reader = new StringReader(string);
                    length = string.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);

        }
    }

Michael

Re: PlatformMySQLImpl bug fix

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi michael,

thanks for the patch, it's available in repository now.

jakob

Michael Mogley wrote:

> All,
> 
> I just fixed a bug in PlatformMySQLImpl that prevents char[] types from being persisted as CLOBs.  Here is the new setObjectForStatement method:
> 
>     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 char[])
>                 {
>                     String string = new String((char[])value);
>                     reader = new StringReader(string);
>                     length = string.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);
> 
>         }
>     }
> 
> Michael


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