Use Ini-files in combination with ODBC

14 views
Skip to first unread message

Ben Engbers

unread,
Aug 20, 2014, 9:25:44 AM8/20/14
to swi-p...@googlegroups.com
I have an application which connects to a database. To open the database I use "odbc_connect(<DSNname>,  _, [user(<username>),  alias(<aliasname>), open(once)])"

Is it possible to define DSNname, username and aliasname in a ini-file. load this ini-file in the .pl and use odbc_connect with the names that are defined in the ini-file?
What is the best approach to do this?

Ben

Jan Wielemaker

unread,
Aug 20, 2014, 11:13:17 AM8/20/14
to Ben Engbers, swi-p...@googlegroups.com
At least using unixODBC, you can put the credentials in .odbc.ini and
only specify the DSN. This has, AFAIK, nothing to do with Prolog,
but with the ODBC setup. Of course, you can parse a .ini file in
Prolog and grab the user/password from there as a work-around.

Cheers --- Jan

>
> Ben
>
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

Carlo Capelli

unread,
Aug 20, 2014, 12:10:50 PM8/20/14
to Ben Engbers, swi-p...@googlegroups.com
Instead of relying on .ini files, I use

myodbc_connect_db(Db, Uid, Pwd, Cn) :-
    format(atom(S), 'driver=mysql;db=~w;uid=~w;pwd=~w', [Db, Uid, Pwd]),
    odbc_driver_connect(S, Cn, [encoding(utf8)]).

HTH Carlo
 
Ben

--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.

Ben Engbers

unread,
Aug 20, 2014, 1:52:10 PM8/20/14
to swi-p...@googlegroups.com, ben.e...@gmail.com


Op woensdag 20 augustus 2014 17:13:17 UTC+2 schreef Jan Wielemaker:
On 08/20/2014 03:25 PM, Ben Engbers wrote:
> I have an application which connects to a database. To open the database
> I use "odbc_connect(<DSNname>,  _, [user(<username>),
> alias(<aliasname>), open(once)])"
>
> Is it possible to define DSNname, username and aliasname in a ini-file.
> load this ini-file in the .pl and use odbc_connect with the names that
> are defined in the ini-file?
> What is the best approach to do this?

At least using unixODBC, you can put the credentials in .odbc.ini and
only specify the DSN.  This has, AFAIK, nothing to do with Prolog,
but with the ODBC setup.  Of course, you can parse a .ini file in
Prolog and grab the user/password from there as a work-around.

        Cheers --- Jan

>
> Ben
 
Maybe I should have made myself clearer (I'm not that fluent in English).

My point is that the routine I've developed uses a DSN on my personal development machine. And I know for certain that whenever this routine will be migrated to the production-environment, an other DSN will be used.
It is not desirable to alter the prolog-code for every change in the used database environment.

My idea was to define alle the necessary properties in a .ini-file and parse that file in prolog. Doing so I could change the DSN without having to change the prolog-code.
I have been searching for ways to parse a .ini-file but can't find examples for that.

To make my question more general, what is the best approach to parse .ini-files from prolog?

Cheers -- Ben
And Carlo, thanks for your suggestions

Reply all
Reply to author
Forward
0 new messages