This is an example:
var query = datasources.db.example.orders.createSelect();
query.result.addPk();
query.where.add(query.columns.date_order.between(date_start,date_end))
I probably did not make myself clear in describing the problem. dateTest is a Javascript variable, not a table column name. dateStart and dateEnd are table column names. I want to select all records in the table where dateTest falls between dateStart and dateEnd. The SQL where clause works…I am trying to convert the SQL to a QB object using the .between() function. I am guessing that what I am attempting is not supported in QB, but thought I would post to see if someone had a solution.
However, you can’t pass (SQL) object names as prepared statement parameters.
But I think, since you would use some (solution) code logic anyway to change your SQL to use the specific column name you can do the same to pass the proper QB column object to your QB Select.
Or am I missing something?
Thank you all for responding…I really appreciate your feedback!
…asks whether a column’s value is between two given values…
Too bad QB won’t take an external value like in my original SQL where clause. The only reason I tried to make dateTest a QB parameter was to use the QB .between() function, but it appears the function is not supported for parameters. For the alternate query, I think I would just skip the parameter business and pass the variable directly:
Note that you have to set the parameter value after defining the parameter in the query, not before.
What is the reason for the precedence? I thought you could manipulate the query object in any way until it is executed (e.g. .getDataSetByQuery( query, -1 )).
What is the reason for the precedence? I thought you could manipulate the query object in any way until it is executed (e.g. .getDataSetByQuery( query, -1 )).
query.params[ 'dateTest' ] = dateTest
Looks for a parameter with that name and sets is value, it does not create it.
I guess we could support it the other order as well if people would need that.
I would like to see this implemented for the QB between function…it makes the code simpler and cleaner, and I believe it would be useful for other developers. Of course, this is just my opinion.