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

IN clause & Stored Procedures Call Support #34

Closed
HussDev opened this issue Mar 29, 2017 · 2 comments
Closed

IN clause & Stored Procedures Call Support #34

HussDev opened this issue Mar 29, 2017 · 2 comments
Assignees
Labels

Comments

@HussDev
Copy link

HussDev commented Mar 29, 2017

Hi

is there any special support for SQL IN clause
and also for calling stored procedures and getting out param ?

Thanks

@komu komu added the question label Mar 29, 2017
@komu komu self-assigned this Mar 29, 2017
@komu
Copy link
Member

komu commented Mar 29, 2017

Hi,

For SQL IN clauses I generally try to keep the query constant and pass an array to database. For example, using PostgreSQL the following would work:

List<Integer> ids = ...
SqlArray idArray = SqlArray.of("int", ids); // "int" here is database specific type name
List<Foo> foos = db.findAll(Foo.class, "select bar, baz from foo where id = any(?)", array);

Unfortunately not all databases support passing arrays easily, so you need to create the query manually in that case. QueryBuilder.appendPlaceholders is helpful in those cases:

SqlQuery q = new QueryBuilder("select bar baz from foo where id in ")
        .appendPlaceholders(ids)
        .build();

With QueryBuilder, you lose static the static analysis provided by IDEA though. ☹️

There's no support for calling stored procedures. I've had very little need for that myself, so I've never gotten around to implementing that. Of course you can execute a transaction callback and then do whatever you wish against the connection, but that's as far as Dalesbred supports you. But anyway that's a good idea for future development.

@komu
Copy link
Member

komu commented Mar 29, 2017

I added #35 for tracking stored procedure support, but I have no immediately plans on starting working on it. Design ideas, prototypes or pull requests would be appreciated.

@komu komu closed this as completed Mar 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants