Quantcast

Question about ODBC SQLGetConnectAttr() call.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Question about ODBC SQLGetConnectAttr() call.

d4t4full
Hi there.

Intro: I'm enhancing Gambas3 (a VisualBasic lookalike for Linux, "but not a clone!") ODBC component. It was kinda non-functional and still lacks functionality, but I got it to the point of being able to connect and retrieve data from MSSQL servers via unixODBC and FreeTDS.

I also installed the ODBC driver for Firebird because a Gambas user noticed that the component was retrieving Firebird data incorrectly. The problem was fixed and the component now is up to par with MSSQL,  except for one thing.

The component populates a high level BASIC property with the Database name (this would be the Catalog name in MSSQL parlance). I cannot get this name correctly from Firebird. I'm calling SQLGetConnectAttr() with the SQL_ATTR_CURRENT_CATALOG attribute, but it does not seem to return anything meaningful. It usually returns a 2-char string, whose 2nd char is not printable, and the first one is normally a lowercase "L", but the database has no L's in its name.

Since this is an ODBC-2 attribute I thought it should work. It certainly does under MSSQL. Is there anything I can do to get the DB/catalog name correctly?

Thanks,
zxMarce.

------------------------------------------------------------------------------

_______________________________________________
Firebird-odbc-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/firebird-odbc-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about ODBC SQLGetConnectAttr() call.

Dimitry Sibiryakov-3
16.11.2016 20:32, [hidden email] wrote:
> I'm calling SQLGetConnectAttr() with the SQL_ATTR_CURRENT_CATALOG attribute, but it does
> not seem to return anything meaningful.

   Do you check its return value? It must be SQL_NO_DATA if you didn't call
SQLSetConnectAttr() beforehand.


--
   WBR, SD.

------------------------------------------------------------------------------
_______________________________________________
Firebird-odbc-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/firebird-odbc-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about ODBC SQLGetConnectAttr() call.

d4t4full
On 16/11/16 17:07, Dimitry Sibiryakov wrote:
16.11.2016 20:32, [hidden email] wrote:
I'm calling SQLGetConnectAttr() with the SQL_ATTR_CURRENT_CATALOG attribute, but it does not seem to return anything meaningful.
Do you check its return value? It must be SQL_NO_DATA if you didn't call SQLSetConnectAttr() beforehand.
I don't call SQLSetConnectAttr() before. Explanation below.
Actually, I'm calling SQLGetConnectAttr() twice: One to get the necessary buffer (string) lenght. The second time is to actually retrieve the string. None fails.
My code is this:

    SQLRETURN    retcode;
    SQLINTEGER    charsNeeded = 0;
    char        *dbName;

    retcode = SQLGetConnectAttr(connHandle, SQL_ATTR_CURRENT_CATALOG, NULL, (SQLINTEGER) 0, (SQLINTEGER *) &charsNeeded);
    if (SQL_SUCCEEDED(retcode))
    {
        dbName = malloc(charsNeeded++); //Add one to get a buffer with a trailing NULL
        dbName[charsNeeded++] = 0; //Append NULL
        retcode = SQLGetConnectAttr(connHandle, SQL_ATTR_CURRENT_CATALOG, dbName, charsNeeded, &charsNeeded);
        if (SQL_SUCCEEDED(retcode))
        {
            desc->name = GB.NewZeroString(dbName); //This creates a Gambas string with a copy of the ODBC-retrieved string.
        } else {
            reportODBCError("SQLGetConnectAttr SQL_ATTR_CURRENT_CATALOG (string)", connHandle, SQL_HANDLE_DBC);
        }
    } else {
        reportODBCError("SQLGetConnectAttr SQL_ATTR_CURRENT_CATALOG (len)", connHandle, SQL_HANDLE_DBC);
    }

The calls do not actually fail (reportODBCError() is never called), and the calls do fetch data, but it is not what I am looking for.
Also, I never call SQLSetConnectAttr() with SQL_ATTR_CURRENT_CATALOG, as I am normally connecting with SQLDriverConnect(), directly passing a connection string which includes the database name.
It looks like the driver does not populate its database name attribute from the connection string. Just in case, the connstring I'm using is "Driver=Firebird;DataSource=localhost;Port=3050;Database=localhost:/tmp/FBExample;UId=SYSDBA;Pwd=password;".
The routine to get the database name is called only when the component connects to the DB successfully.

------------------------------------------------------------------------------

_______________________________________________
Firebird-odbc-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/firebird-odbc-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about ODBC SQLGetConnectAttr() call.

Dimitry Sibiryakov-3
17.11.2016 11:51, ML wrote:
> It looks like the driver does not populate its database name attribute from the connection
> string.

   According to MSDN, it must not. But it must return SQL_NO_DATA. Register ticket in
tracker, please.


--
   WBR, SD.

------------------------------------------------------------------------------
_______________________________________________
Firebird-odbc-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/firebird-odbc-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Question about ODBC SQLGetConnectAttr() call.

d4t4full
On 17/11/16 08:06, Dimitry Sibiryakov wrote:
17.11.2016 11:51, ML wrote:
It looks like the driver does not populate its database name attribute from the connection string.
According to MSDN, it must not. But it must return SQL_NO_DATA. Register ticket in tracker, please.
Well that's strange because FreeTDS does it. Did not test any other driver, though, just these two.
But I guess ODBC is a little bit anarchic in these regards; the documentation itself says in several places "some drivers do this" or even "most drivers return that" or things like those; there seems not to exist a formal requirements list.
Thanks a lot for your help, Dimitry, I will file the bug.
--
zxMarce

------------------------------------------------------------------------------

_______________________________________________
Firebird-odbc-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/firebird-odbc-devel
Loading...