Repository navigation
|
I have a query similar to the following (as part of a larger query that has multiple parameters): connection.execute("INSERT INTO A ([EXAMPLE]) VALUES (?);", (&VarCharSlice::NULL));with the field When I run this against SQL Server or Access I get errors from the driver like the following:
The error from the driver seems a little misleading though, because if I write the query without the parameter ( Is odbc-api/odbc-api/src/parameter/varchar.rs Line 251 in 5ab0287 This isn't a big deal either way because I can easily workaround it, but I'm curious about how this is intended to work. Maybe I have to specify the size somewhere (even though it's already specified on the field)? |
Replies: 3 comments 7 replies
|
Hi @grovesNL , this is not what I intended to happen 😅 . Maybe I find time to investigate this after work or at the weekend. Guessing from the error message though it is about the length associated with the parameter type. Consider: odbc-api/odbc-api/src/parameter/varchar.rs Line 247 in 8af4fd8 impl<'a> VarCharSlice<'a> {
/// Indicates missing data
pub const NULL: Self = Self {
buffer: &[],
indicator: NULL_DATA,
};
}As you can see the buffer type is empty, which should lead it to be bound as a VARCHAR with length 0. I can see a driver object to that, but the weird thing is I tested this with MSSQL: odbc-api/odbc-api/tests/integration.rs Line 1512 in 8af4fd8
tl;dr I'd be thankful for a reproducing test, or more information, as the API as you use it is intended to work. Cheers, Markus |
#[test_case(MSSQL; "Microsoft SQL Server")]
#[test_case(MARIADB; "Maria DB")]
#[test_case(SQLITE_3; "SQLite 3")]
fn varchar_null(profile: &Profile) {
let table_name = "VarcharNull";
let conn = ENV.connect_with_connection_string(profile.connection_string).unwrap();
setup_empty_table(&conn, profile.index_type, table_name, &["VARCHAR(10)"]).unwrap();
let insert = format!("INSERT INTO {} (a) VALUES (?)", table_name);
conn.execute(&insert, &VarCharSlice::NULL).unwrap();
let actual = table_to_string(&conn, table_name, &["a"]);
assert_eq!("NULL", actual)
}Tried to reproduce the issue, but works on my machine. What system, driver and database are you using?. You can find the test on the newest master here: odbc-api/odbc-api/tests/integration.rs Line 2342 in 138e17c |
|
Since version connection.execute("INSERT INTO A ([EXAMPLE]) VALUES (?);", &None::<&str>.into_parameter());
connection.execute("INSERT INTO A ([EXAMPLE]) VALUES (?);", &VarCharSlice::NULL);
connection.execute("INSERT INTO A ([EXAMPLE]) VALUES (?);", (&VarCharSlice::NULL,));
connection.execute("INSERT INTO A ([EXAMPLE]) VALUES (?);", &VarCharBox::null());
connection.execute("INSERT INTO A ([EXAMPLE]) VALUES (?);", &VarCharArray::<1>::NULL); |
Since version
0.22.3the answer is that anyone of these is going to work: