pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedSetting Database Name During Connection
2+ messages / 2 participants
[nested] [flat]
* Setting Database Name During Connection
@ 2015-05-20 17:59 Daniel Homerick <daniel.homerick@2d3sensing.com>
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Homerick @ 2015-05-20 17:59 UTC (permalink / raw)
To: pgsql-odbc
The common way to control which database you connect to is apparently through the DSN, or connection string. However, ODBC also allows the database name (distinct from which host/port) to be specified programmatically, but it appears that this may be unimplemented in psqlODBC.
Calling SQLSetConnectAttr with the SQL_ATTR_CURRENT_CATALOG attribute should allow you to specify which database. My expectation is that doing so should override any value specified in the DSN or connection string.
In practice, the SQLSetConnectAttr call returns SQL_SUCCESS, regardless of what database ("catalog") name you specify, and regardless of whether you call it prior to SQLConnect or after. However, calling SQLGetConnectAttr afterwards reveals that nothing was changed by the Set. Attempting to use the specified database fails, consistent with the current database still being whatever was specified in the DSN.
I downloaded the current snapshot (psqlodbc-355ac88) and grepped around, but did not find any references to SQL_ATTR_CURRENT_CATALOG, nor to 3D000 which is the error code for an "Invalid catalog name", which leads me to think it may just be unimplemented and not a more subtle bug. I did not do a more serious investigation however, so take that with a large grain of salt.
Tested on Windows 7, using the odbc driver "Postgre SQL ANSI(x64) 9.03.03.00" with PostgreSQL 9.2. Testing using the same code works as expected for SQL Server.
-
As an aside from the bug report, is it correct that there is NOT a way to change the current database through a SQL command with Postgres (i.e. there is no equivalent to "USE" in SQL Server)?
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Setting Database Name During Connection
@ 2015-05-20 20:26 Steve Marvin <smarvin@pobox.com>
parent: Daniel Homerick <daniel.homerick@2d3sensing.com>
0 siblings, 0 replies; 2+ messages in thread
From: Steve Marvin @ 2015-05-20 20:26 UTC (permalink / raw)
To: pgsql-odbc
SQL_ATTR_CURRENT_CATALOG maps to SQL_CURRENT_QUALIFIER in the SQLext .h file.
Looking in options.c at line 396 in function PGAPI_SetConnectOption()
I see case SQL_CURRENT_QUALIFIER: /* ignored */
The equivalent in PGAPI_GetConnectOption() function at line 570 returns
the database/catalog name using p = CurrCatString(conn);
---------------------------------
On Wed, 20 May 2015 10:59:46 -0700, Daniel Homerick wrote:
>The common way to control which database you connect to is apparently through the DSN, or connection string. However, ODBC also allows the database name (distinct from which host/port) to be specified programmatically, but it appears that this may be unimplemented in psqlODBC.
>Calling SQLSetConnectAttr with the SQL_ATTR_CURRENT_CATALOG attribute should allow you to specify which database. My expectation is that doing so should override any value specified in the DSN or connection string.
>In practice, the SQLSetConnectAttr call returns SQL_SUCCESS, regardless of what database ("catalog") name you specify, and regardless of whether you call it prior to SQLConnect or after. However, calling SQLGetConnectAttr afterwards reveals that nothing was changed by the Set. Attempting to use the specified database fails, consistent with the current database still being whatever was specified in the DSN.
>I downloaded the current snapshot (psqlodbc-355ac88) and grepped around, but did not find any references to SQL_ATTR_CURRENT_CATALOG, nor to 3D000 which is the error code for an "Invalid catalog name", which leads me to think it may just be unimplemented and not a more subtle bug. I did not do a more serious investigation however, so take that with a large grain of salt.
>Tested on Windows 7, using the odbc driver "Postgre SQL ANSI(x64) 9.03.03.00" with PostgreSQL 9.2. Testing using the same code works as expected for SQL Server.
>-
>As an aside from the bug report, is it correct that there is NOT a way to change the current database through a SQL command with Postgres (i.e. there is no equivalent to "USE" in SQL Server)?
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2015-05-20 20:26 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-05-20 17:59 Setting Database Name During Connection Daniel Homerick <daniel.homerick@2d3sensing.com>
2015-05-20 20:26 ` Steve Marvin <smarvin@pobox.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox