Skip to content

Inserting NULL values with ColumnarBulkInserter #449

Discussion options

You must be logged in to vote

Short answer: yes you can. Adapting the code example from the documentation to show how it is done:

use odbc_api::{Connection, Error, IntoParameter, buffers::BufferDesc};

fn insert_birth_years(conn: &Connection, names: &[&str], years: &[Option<i16>]) -> Result<(), Error> {

    // All columns must have equal length.
    assert_eq!(names.len(), years.len());

    let prepared = conn.prepare("INSERT INTO Birthdays (name, year) VALUES (?, ?)")?;

    // Create a columnar buffer which fits the input parameters.
    let buffer_description = [
        BufferDesc::Text { max_str_len: 255 }, // <- variadic sized types are always nullable
        BufferDesc::I16 { nullable: true}, // <- Important…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@jamesetaylor-tudor
Comment options

@pacman82
Comment options

Answer selected by jamesetaylor-tudor
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants