pacman82/odbc-api

`Environment.driver` only returns the first attribute.

keraion opened this issue · 1 comments

The Environment.drivers function only returns the first attribute in a driver's list.

Example code:

use odbc_api::Environment;

let env = Environment::new ()?;
for driver_info in env.drivers()? {
    println!("{:#?}", driver_info);
}

This returns something like this:

[
    DriverInfo {
        description: "DB2",
        attributes: {
            "Driver": "/opt/ibm/db2/clidriver/lib/libdb2.so",
        },
    },
    DriverInfo {
        description: "DB2_LIBDB2",
        attributes: {
            "Description": "DB2 Driver",
        },
    },
    DriverInfo {
        description: "ODBC Driver 17 for SQL Server",
        attributes: {
            "Description": "Microsoft ODBC Driver 17 for SQL Server",
        },
    },
]

However, each driver has more attributes than just the first one and should look more like this:

[
    DriverInfo {
        description: "DB2",
        attributes: {
            "dontdlclose": "1",
            "Description": "DB2 Driver",
            "fileusage": "1",
            "Driver64": "/opt/ibm/db2/clidriver/lib/libdb2o.so",
            "Driver": "/opt/ibm/db2/clidriver/lib/libdb2.so",
        },
    },
    DriverInfo {
        description: "DB2_LIBDB2",
        attributes: {
            "Description": "DB2 Driver",
            "Driver": "/opt/ibm/db2/clidriver/lib/libdb2.so",
            "fileusage": "1",
            "dontdlclose": "1",
            "Driver64": "/opt/ibm/db2/clidriver/lib/libdb2.so",
        },
    },
    DriverInfo {
        description: "ODBC Driver 17 for SQL Server",
        attributes: {
            "Description": "Microsoft ODBC Driver 17 for SQL Server",
            "Driver": "/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.5.1",
            "UsageCount": "1",
        },
    },
]

From what I can tell, let attributes = attr_buf.to_utf8() is truncating to the first null found, and the attributes_iter isn't doing anything more with the input as a single null-terminated item.

let description = desc_buf.to_utf8();
let attributes = attr_buf.to_utf8();
let attributes = attributes_iter(&attributes).collect();

Hello @keraion

odbc-api 6.0.1 has been released including a fix which should list all attributes. Thanks for reporting the issue and drilling into the cause of the error.

Best, Markus