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

ENH: Add bind parameter expansion for SqlUpdate #1632

Closed
rbygrave opened this issue Feb 7, 2019 · 0 comments
Closed

ENH: Add bind parameter expansion for SqlUpdate #1632

rbygrave opened this issue Feb 7, 2019 · 0 comments
Assignees
Milestone

Comments

@rbygrave
Copy link
Member

rbygrave commented Feb 7, 2019

Bind parameters can use the form of ?1, ?2, ?3 ... for binding collection parameters that we want to get expanded into multiple bind values.

Note that when we use databases that support binding Array types such as Postgres we could tend to use that (e.g. Postgres ANY).

This is more useful when we are not using such a database and want to bind an in clause with a list/collection of bind values.

Example

DB.sqlUpdate("delete from o_customer where id in (?1)")
  .setParameter(1, asList(9991, 9992, 9993))
  .execute();

// translates to:
delete from o_customer where id in (?,?,?);  -- bind(9991, 9992, 9993)

We only use the position suffix for the parameters that we want to expand. For the example below we only use ? for the first parameter as we don't want that expanded. We use ?2 for the parameter we want expanded.

DB.sqlUpdate("delete from o_customer where status = ? and id in (?2)")
  .setParameter(1, "NEW")
  .setParameter(2, asList(9991, 9992, 9993))
  .execute();
delete from o_customer where status = ? and id in (?,?,?);  -- bind("NEW", 9991, 9992, 9993)

We can also use setParams() with bind parameters set using varargs.

DB.sqlUpdate("delete from o_customer where status = ? and id in (?2)")
  .setParams( "NEW", asList(9991, 9992, 9993))
  .execute();
@rbygrave rbygrave added this to the 11.34.1 milestone Feb 7, 2019
@rbygrave rbygrave self-assigned this Feb 7, 2019
@rbygrave rbygrave closed this as completed Feb 7, 2019
rbygrave added a commit that referenced this issue Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant