#201 Passing Strings as arguments to procedures with Object args

open
nobody
None
5
2008-07-25
2008-07-25
No

If I define a Java function like:

public static Object dosomething(Object arg) {...}

and then try and call it in a SQL statement with a string, e.g.:

select dosomething('MO')

I get the error:

hexadecimal string contains non hex character in statement

This is because in Column.convertObject() the following code is executed:

case Types.OTHER :
if (o instanceof JavaObject) {
return o;
} else if (o instanceof String) {

/**
* @todo fredt - we need this for script processing only
* handle the script separately and allow normal Sting
* objects to be stored as JavaObject
*/
return new JavaObject(
StringConverter.hexToByte((String) o));
} else if (o instanceof Binary) {
return new JavaObject(((Binary) o).getBytes());
}

return new JavaObject((Serializable) o);

In fact, it would be useful if it just left the string alone then the Java function can check the type itself and downcast appropriately.

Discussion

  • Fred Toussi

    Fred Toussi - 2008-09-14

    Yes, the call method can be improved to pass the object directly when it is not an instance of JavaObject.

     
  • Fred Toussi

    Fred Toussi - 2010-03-16

    Implementation has changed in version 2. Now polymorphism is supported and argument types should be compatible.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks