Setting Database Name During Connection

Поиск
Список
Период
Сортировка
От Daniel Homerick
Тема Setting Database Name During Connection
Дата
Msg-id 9570C4F8577FC041964C389777970D774A525D90A8@KITT.sensingsystems.com
обсуждение исходный текст
Ответы Re: Setting Database Name During Connection  ("Steve Marvin" <smarvin@pobox.com>)
Список 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)?

 

 

В списке pgsql-odbc по дате отправления:

Предыдущее
От: Alex Dunn
Дата:
Сообщение: Fwd: psqlodbc: HEAD fails to build with recent clang
Следующее
От: "Steve Marvin"
Дата:
Сообщение: Re: Setting Database Name During Connection