Search code examples
delphiodbcdbexpress

How do I set an attribute on an ODBC connection via DBExpress?


Justification that you might as well skip reading but is included to filter out people telling me not to do something that I'm not sure of in the first place.

I'm trying to debug some multithreaded database hoopla, it's mostly experimental although if I get it working I'd be a very happy guy. I'm very new to DBExpress (only have been using it for 4-5 hours). I'm not using TSQLConnection or any designtime components because I'm trying to rewrite an existing ODBC32.dll interface in a painless an unnoticed way and once I'm done, I'll expose the rest of the awesomeness. The reason I mention this is because it's very apparent that I'm not using dbexpress in the normal way shown in many of the tutorials.


Here's the question

I'm using the TDBXConnection and connecting to an ODBC datasource, I want to try setting the SQL_ATTR_ASYNC_DBC_FUNCTIONS_ENABLE parameter on my connection, but I don't have a clue where to go about setting that particular parameter.


Solution

  • You've got FDBConnection : TDBXConnection; defined somehwere else so now you've got to:

    ....

    begin
      if FDBConnection is TDBXOdbcConnection then
      with FDBConnection as TDBXOdbcConnection do
      begin
        MethodTable.SQLSetEnvAttr(EnvironmentHandle, SQL_ASYNC_ENABLE, Pointer(SQL_ASYNC_ENABLE_ON), 0);
        MethodTable.SQLSetEnvAttr(EnvironmentHandle, SQL_ASYNC_DBC_FUNCTIONS, Pointer(SQL_ASYNC_DBC_CAPABLE), 0);
    
      end;
    end;
    

    That's pretty painless.

    Include Data.DBXODBC and System.ODBC in the uses and you're golden.