Hi Gregor,
First off all, try to connect to MySql directly by a shell command :
echo "select 1" | isql -v my-connector
Expected response :
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> select 1
+---------------------+
| 1 |
+---------------------+
| 1 |
+---------------------+
SQLRowCount returns 1
1 rows fetched
Where /etc/odbc.ini :
[my-connector]
Description = MySQL connection to database
Driver = MySQL
Database = example
Server = localhost
User = example
Password = example
Port = 3306
Socket = /var/run/mysqld/mysqld.sock
and /etc/odbcinst.ini
[MySQL]
Description = ODBC for MySQL
Driver = /usr/local/lib/libmyodbc8a.so
Setup = /usr/local/lib/libmyodbc8w.so
FileUsage = 1
If you successfully connected to your mysql database, then you can use it in IRIS/Caché/Ensemble :
Here is an example with %SQLGatewayConnection
set gc=##class(%SQLGatewayConnection).%New()
set pDSN="my-connector"
set sc=gc.Connect(pDSN,"example","example")
set sc=gc.AllocateStatement(.hstmt)
set pQuery= "select 1"
set sc=gc.Prepare(hstmt,pQuery)
set sc=gc.Execute(hstmt)
set sc=gc.Fetch(hstmt)
set sc=gc.GetData(hstmt, 1, 1, .val)
zw val
set sc=gc.CloseCursor(hstmt)
set sc=gc.Disconnect()
To go further check those links :
- https://docs.intersystems.com/irisforhealthlatest/csp/docbook/DocBook.UI.Page.cls?KEY=BSQG_odbc
- https://docs.intersystems.com/irisforhealthlatest/csp/docbook/DocBook.UI.Page.cls?KEY=BSQG_prog
Or even better check this training, it's with an JDBC connector but most part is applicable has DSN will fit your odbc config.
- Log in to post comments