SL-Pirate / dart_odbc

A Dart package for interacting with ODBC databases. It allows you to connect to ODBC data sources and execute SQL queries directly from your Dart applications.
MIT License
5 stars 2 forks source link

ANSI support #1

Closed dweberlj closed 2 months ago

dweberlj commented 4 months ago

Hello!

How do we use this with an ANSI database?

Thanks, Dean

SL-Pirate commented 4 months ago

I am not sure if it need any specific configurations. Microsoft's ODBC documentation does not specify anything about it. Have you tried to see if it wors out of the box? To my knowledge the driver should be able to handle the encoding by itself.

If you have already tried, are you facing any issues?

dweberlj commented 4 months ago

Thanks for the reply, I believe the issue I was running into was the fixed size of 256 which would cause an exception in the ODBC driver when accessing a stored image. The data type of the column is memo. Thoughts on querying the column data size and allocating memory accordingly?

Thank you.

https://github.com/SL-Pirate/dart_odbc/blob/af18a40429ad860d0ba4306225ed5ce7560aacf8/lib/src/dart_odbc_base.dart#L285

      final columnName = calloc.allocate<Uint16>(sizeOf<Uint16>() * 256);
      tryOdbc(
        _sql.SQLDescribeColW(
          hStmt,
          i,
          columnName.cast(),
          256,
          columnNameLength,
          nullptr,
          nullptr,
          nullptr,
          nullptr,
        ),
        handle: hStmt,
        onException: FetchException(),
      );
SL-Pirate commented 4 months ago

Yes it definitely could be. I will expose a way to provide column size. In the mean time please try if you can fix the issue by giving a higher value final columnValue = calloc.allocate<Uint16>(sizeOf<Uint16>() * 256) here than 256.

Edit: It also could be the fact I provide a hardcoded value as SQL_C_WCHAR as column type when fetching data. Refer the code down below

          _sql.SQLGetData(
            hStmt,
            i,
            SQL_C_WCHAR,
            columnValue.cast(),
            256,
            columnValueLength,
          ),
SL-Pirate commented 4 months ago

@dweberlj I updated the package to version 2.0.0+1 Please provide the column type to the execute method and set the size of the column to the required value and see if it fixes your issue. Keep me posted on your progress.

For more information refer to the updated documentation.

SL-Pirate commented 2 months ago

Closing due to inactivity