Обсуждение: Way to retrieve UserName/Password
Hi, ALL, I successfully built the server and I previously had the odbc driver installed. I can successfully connect from psql from the Terminal, and from isql unixODBC utility. However, what I wonder is - is there a simple way to retrieve UsrerName and Password from odbc.ini file? Below is my current configuration to connect. WHat I'd like to do in my software is to get those parameters and use them in the "Connect To DB" dialog. The easiest would probably be to save it in my local program configuration file, but in this case the information will be duplicated and I'd like to avoid it. Thank you. [code] igor@WaylandGnome ~/dbhandler/Debug $ cat /etc/unixODBC/odbcinst.ini [ODBC] Trace=Yes TraceFile=/var/log/unixodbc.log [postgres] Description=Postgres ODBC Driver Driver=/usr/lib64/psqlodbcw.so FileUsage=1 igor@WaylandGnome ~/dbhandler/Debug $ cat /etc/unixODBC/odbc.ini [postgres] Driver=Postgres Description=Postgres ODBC Driver UserId=postgres Password=wasqra Servername=localhost Database=draft Port=5432 [ODBC] Trace = Yes TraceFile = /home/igor/odbc.log [ODBC Data Sources] postgres=PostgreSQL Driver testing igor@WaylandGnome ~/dbhandler/Debug $ [/code]
On Sat, Nov 22, 2025 at 10:22 PM Igor Korot <ikorot01@gmail.com> wrote:
Hi, ALL,
I successfully built the server and I previously had the odbc driver installed.
I can successfully connect from psql from the Terminal, and from isql
unixODBC utility.
However, what I wonder is - is there a simple way to retrieve UsrerName
and Password from odbc.ini file?
Below is my current configuration to connect.
WHat I'd like to do in my software is to get those parameters and use
them in the "Connect To DB" dialog.
The easiest would probably be to save it in my local program configuration file,
but in this case the information will be duplicated and I'd like to avoid it.
Grep the ini file, and add it to your local program's config file?
I sympathize with you about password duplication, though. My .pgpass files are chock full of duplicate passwords (primary server and multiple replication servers, plus server-name and server-name.example.com.
Regular expression parsing and case-insensitivity would make users (including DBAs) lives a lot easier.
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!
On Saturday, November 22, 2025, Igor Korot <ikorot01@gmail.com> wrote:
WHat I'd like to do in my software is to get those parameters and use
them in the "Connect To DB" dialog.
There is pretty much nothing special about this situation pertaining to PostgreSQL. What specific challenge are you encountering? I have to imagine nearly all languages have a module/library that handles this 30+ year old file format.
David J.
Hi, David, On Sat, Nov 22, 2025 at 9:37 PM David G. Johnston <david.g.johnston@gmail.com> wrote: > > On Saturday, November 22, 2025, Igor Korot <ikorot01@gmail.com> wrote: >> >> >> WHat I'd like to do in my software is to get those parameters and use >> them in the "Connect To DB" dialog. > > > There is pretty much nothing special about this situation pertaining to PostgreSQL. What specific challenge are you encountering? I have to imagine nearly all languages have a module/library that handles this 30+ year old file format. The simplest solution would be to use SQLGetPrivateProfileString(). However, as much as I'd like to, this function distinguishes between "UserId" and "UserID". There is also a problem where the odbc.ini file location is different from distro to distro, which the function above nicely handles, but I'll need to roll my own some 3rd party library. Thank you. > > David J.
David, On Sat, Nov 22, 2025 at 9:37 PM David G. Johnston <david.g.johnston@gmail.com> wrote: > > On Saturday, November 22, 2025, Igor Korot <ikorot01@gmail.com> wrote: >> >> >> WHat I'd like to do in my software is to get those parameters and use >> them in the "Connect To DB" dialog. > > > There is pretty much nothing special about this situation pertaining to PostgreSQL. What specific challenge are you encountering? I have to imagine nearly all languages have a module/library that handles this 30+ year old file format. Also, my understanding is that there is no unified way of writing "UserId" inside odbc.ini. Some use "UserId" and some "UID". And some might use something else. Thank you. > > David J.