Skip to content

Add bind_parameter support for "container" types #680

@aljazerzen

Description

@aljazerzen

Related to #619

Bind parameter does not support Value::Struct, Value::Array, Value::Map or Value::Union:

    // generic because many of these branches can constant fold away.
    fn bind_parameter<P: ?Sized + ToSql>(&self, param: &P, col: usize) -> Result<()> {
        let value = param.to_sql()?;

        let ptr = unsafe { self.stmt.ptr() };
        let value = match value {
            ToSqlOutput::Borrowed(v) => v,
            ToSqlOutput::Owned(ref v) => ValueRef::from(v),
        };
        // TODO: bind more
        let rc = match value {
            ...
            _ => unreachable!("not supported: {}", value.data_type()),
        };
        ...

A test:

use duckdb::types::Value;
use duckdb::{params, Connection, Result};

fn main() -> Result<()> {
    let conn = Connection::open_in_memory()?;

    conn.execute("CREATE TABLE test (id INTEGER, numbers INTEGER[])", [])?;

    let list_value = Value::List(vec![Value::Int(1), Value::Int(2), Value::Int(3)]);
    conn.execute("INSERT INTO test VALUES (?, ?)", params![1, &list_value])?;

    Ok(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions