0

Suddenly I've realized that while this works in groovy just like it is expeceted:

Sql.newInstance(connectionParams).rows("SELECT FROM ITEMS WHERE id = ?", [200])

this won't work

Sql.newInstance(connectionParams).rows("SELECT FROM ITEMS WHERE name LIKE '%?%'", ["some"])

All you can get is

Failed to execute: SELECT FROM ITEMS WHERE name LIKE '%?%' because: The column index is out of range: 1, number of columns: 0.

My questions are:

  • Is it intentionally implemented this way? I've never needed to have a parametrized text search, so I'm not sure where this behaviour is typical or not.
  • How can I nevertheless safely parametrize statement with text search in it?
shabunc
  • 23,119
  • 19
  • 77
  • 102

1 Answers1

2

I believe you want to include the %'s in the parameter, like:

Sql.newInstance(connectionParams).rows("SELECT FROM ITEMS WHERE name LIKE ?", ["%some%"])
bhamby
  • 15,112
  • 1
  • 45
  • 66
  • well, it is the first thing I've tried actually, but had failed, does this work for you, are you sure? also, have no idea why this actually should work, while in first form it shouldn't – shabunc Jun 17 '13 at 04:20