params (like id = ?) doesn't work with HFSQL
Closed this issue · 3 comments
It works if I use SELECT id FROM clients LIMIT 2;
but not when using a param.
With this query I get all the rows. Same thing if I do WHERE id = ?
.
deps
[dependencies]
anyhow = "1.0.75"
dotenvy = "0.15.7"
odbc-api = { version = "2.2.0", features = ["iodbc"] }
code
use anyhow::Error;
use dotenvy::dotenv;
use odbc_api::buffers::{BufferDesc, ColumnarBuffer};
use odbc_api::{ConnectionOptions, Cursor, Environment};
use std::env;
const BATCH_SIZE: usize = 5000;
fn main() -> Result<(), Error> {
dotenv().ok();
let environment = Environment::new()?;
let bd_driver = env::var("BD_DRIVER").unwrap();
let bd_host = env::var("BD_HOST").unwrap();
let bd_port = env::var("BD_PORT").unwrap();
let bd_database = env::var("BD_DATABASE").unwrap();
let bd_user = env::var("BD_USER").unwrap();
let bd_password = env::var("BD_PASSWORD").unwrap();
let conn_str = format!(
"DRIVER={};Server Name={};Server Port={};Database={};UID={};PWD={}",
bd_driver, bd_host, bd_port, bd_database, bd_user, bd_password
);
let connection =
environment.connect_with_connection_string(&conn_str, ConnectionOptions::default())?;
// Execute a one of query without any parameters.
match connection.execute(
"SELECT id FROM clients LIMIT ?;",
&2,
)? {
Some(cursor) => {
let mut buffers =
ColumnarBuffer::from_descs(BATCH_SIZE, [BufferDesc::I64 { nullable: true }]);
let mut row_set_cursor = cursor.bind_buffer(&mut buffers)?;
while let Some(batch) = row_set_cursor.fetch()? {
dbg!(&batch.num_rows());
}
}
None => {
eprintln!("Query came back empty. No output has been created.");
}
}
Ok(())
}
You do not get any error? odbc-api
is just forwarding placeholders and parameters to your ODBC driver. Nothing I can do here.
You're trying to use a bind parameter in the LIMIT
clause for the failing code example; this is not supported as mentioned in the WINDEV docs
The LIMIT clause accepts one or two numeric arguments. These arguments must be constant integers.
bind parameters are parsed separately and bound to the query as variable arguments, not constants.
If you trust where the integer value for the LIMIT
clause comes from, you could opt for formatting it in, otherwise you'll need to find another way to sanitize the input.