I am working to connect to a database hosted by a cloud provider in SWI-Prolog.
The cloud database can be accessed over ODBC.
Having worked with databases and ODBC connections for decades I was not expecting it to be a trivial matter.
As such, I have focused on getting a smaller, local ODBC connection to a SQLite3 database working first.
(NB: Before posting, I have read SWI-Prolog connecting to PostgreSQL via ODBC but did not find a solution)
Setup:
Host OS: Ubuntu 20.04
unixodbc: 2.3.6-0.1build1
sqlite3: 3.31.1-4ubuntu0.2
libsqliteodbc:amd64: 0.9996-3
SWI-Prolog is installed via snap.
To help swipl access to the ODBC drivers and the sqlite3 database file I have placed a copy under my home directory:
sam@radon:~$ tree snap/mnt/odbc/
snap/mnt/odbc/
├── drivers
│ └── libsqlite3odbc.so
└── sqlite3
└── cw4.db
My ~/.odbc.ini contains
[testsqlite]
Description = Connection to SQLite test db
Driver = /home/sam/snap/mnt/odbc/drivers/libsqlite3odbc.so
Database = /home/sam/snap/mnt/odbc/sqlite3/cw4.db
Timeout = 2000
And I can access this through the ODBC complexities:
sam@radon:~$ isql -v testsqlite
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> select uid from conn limit 5;
+-------------------------+
| uid |
+-------------------------+
| C0V3Y136ykoRwmFyma |
| C2SoYstPCZw1ZSip3 |
| C3EKIp2njiZ5V3p7Sj |
| C4hOrH2esSc78G862 |
| CAHnVL1tzmdstqg998 |
+-------------------------+
SQLRowCount returns 0
5 rows fetched
SQL>
So far, so good.
I now try to connect to the same ODBC DSN in swipl
sam@radon:~$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.26)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- odbc_connect(testsqlite, C, []).
ERROR: ODBC: State IM002: [unixODBC][Driver Manager]Data source name not found, and no default driver specified
ERROR: In:
ERROR: [10] odbc:odbc_connect(testsqlite,_20108,[])
ERROR: [9] toplevel_call(user:user: …) at /snap/swi-prolog/35/usr/lib/swipl/boot/toplevel.pl:1115
?- ls('/home/sam/snap/mnt/odbc/drivers/libsqlite3odbc.so').
% /home/sam/snap/mnt/odbc/drivers/libsqlite3odbc.so
true.
?- ls('/home/sam/snap/mnt/odbc/sqlite3/cw4.db').
% /home/sam/snap/mnt/odbc/sqlite3/cw4.db
true.
?- ^D
% halt
It seems that the ODBC driver and the sqlite3 file are visible to the snap of SWI-Prolog.
Please let me know what I am doing wrong.
Many thanks in advance,
Steve