Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tricks: passing arrays to PreparedStatement #72

Closed
dimzon opened this issue Apr 6, 2014 · 3 comments
Closed

tricks: passing arrays to PreparedStatement #72

dimzon opened this issue Apr 6, 2014 · 3 comments
Assignees
Milestone

Comments

@dimzon
Copy link
Contributor

dimzon commented Apr 6, 2014

this is my know-how :) represent array as XML string and pass as CLOB parameter
Your SQL code must expect XML - most of databases have XML-to-TABLE functions

@aldenquimby
Copy link
Contributor

I'm not sure this needs to be built in to sql2o. I think people who want this could add a custom converter like this:

public class ArrayXmlConverter implements Converter<byte[]> {

    public byte[] convert(Object val) throws ConverterException {
        // get XML from Clob and return byte[]
    }

    public Object toDatabaseParam(byte[] val) {
        // convert to XML string and return Clob
    }
}

The current NamedParameterStatement doesn't support setClob() directly, but setObject may work for a java.sql.Clob, I'm not sure

@dimzon
Copy link
Contributor Author

dimzon commented Apr 6, 2014

Yes, this can be done via extension
In my closed-source ORM I use ParamSetter interface. ParamSetterFactory is provided by Quirks since different Databases and JDBC drivers works different (Timestamp for DB2 is a good example)

@aldenquimby
Copy link
Contributor

Yes once the quirks PR is merged, this will work fine:

public class MyQuirks extends NoQuirks {
    @Override
    public Map<Class, Converter> customConverters() {
        Map<Class, Converter> converters = new HashMap<Class, Converter>();

        converters.put(byte[].class, new ArrayXmlConverter());

        // add other custom converters

        return converters;
    }
}

I think I'll close this issue because the quirks + two-way converter will solve it. Are you ok with that?

@aaberg aaberg added this to the 1.5.0 milestone May 5, 2014
@aaberg aaberg assigned dimzon and aldenquimby and unassigned dimzon May 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants