Skip to content

Commit 9c2480c

Browse files
author
Alex Kwiatkowski
committed
add mariadb odbc driver and tests
1 parent ae8cd46 commit 9c2480c

File tree

9 files changed

+84
-48
lines changed

9 files changed

+84
-48
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This extension is tested and known to work with the ODBC drivers of the followin
3535
| Oracle | [odbc_scan_oracle](./test/sql/odbc_scan_oracle.test) | `[ ]` | `[ ]` | `[ ]` | `[ ]` |
3636
| Postgres | [odbc_scan_postgres](./test/sql/odbc_scan_postgres.test) | `[x]` | `[x]` | `[x]` | `[x]` |
3737
| MySQL | [odbc_scan_mysql](./test/sql/odbc_scan_mysql.test) | `[ ]` | `[ ]` | `[ ]` | `[ ]` |
38-
| MariaDB | [odbc_scan_mariadb](./test/sql/odbc_scan_mariadb.test) | `[ ]` | `[ ]` | `[ ]` | `[ ]` |
38+
| MariaDB | [odbc_scan_mariadb](./test/sql/odbc_scan_mariadb.test) | `[x]` | `[x]` | `[x]` | `[x]` |
3939
| Snowflake | [odbc_scan_snowflake](./test/sql/odbc_scan_snowflake.test) | `[ ]` | `[ ]` | `[ ]` | `[ ]` |
4040
| BigQuery | [odbc_scan_big_query](./test/sql/odbc_scan_big_query.test) | `[ ]` | `[ ]` | `[ ]` | `[ ]` |
4141
| MongoDB | [odbc_scan_mongo_db](./test/sql/odbc_scan_mongo_db.test) | `[ ]` | `[ ]` | `[ ]` | `[ ]` |

docker/docker-compose.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ services:
7474
mariadb:
7575
image: mariadb:11.0.2
7676
ports:
77-
- "3306:3306"
77+
- "3307:3306"
7878
volumes:
7979
- mariadb_data:/var/lib/mysql
8080
environment:
8181
- MARIADB_USER=mariadb
8282
- MARIADB_PASSWORD=password
8383
- MARIADB_ROOT_PASSWORD=password
84+
# healthcheck:
85+
# test: ["CMD", "mariadb-admin" ,"ping", "-h", "localhost"]
86+
# interval: 1s
87+
# retries: 120
8488

8589
volumes:
8690
db2_data: {}

docs/ODBC_CONNECTION_STRING_AND_DSN_FORMATS.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from [connectionstrings.com](https://www.connectionstrings.com).
99
nix run .#odbc-driver-paths
1010
db2 /nix/store/6flbacf9h5bk09iw37b7sncgjn9mdkwj-db2-odbc-driver-11.5.8/lib/libdb2.so
1111
postgres /nix/store/j648cwmz16prd2n35h0xdhji9b02pip6-postgres-odbc-driver-15.00.0000/lib/psqlodbca.so
12+
mariadb /nix/store/i2i0jj2bxxkq9yc74217b00ddcjnygsg-mariadb-odbc-driver-3.1.9/lib/mariadb/libmaodbc.so
1213
```
1314

1415
## DSN's
@@ -33,13 +34,22 @@ Driver = postgres
3334
```
3435

3536
```odbcinst.ini
36-
[db2]
37-
Driver = ${DB2_DRIVER_PATH}
38-
3937
[postgres]
4038
Driver = ${POSTGRES_DRIVER_PATH}
4139
```
4240

41+
### MariaDB
42+
43+
```odbc.ini
44+
[mariadb odbc_test]
45+
Driver = mariadb
46+
```
47+
48+
```odbcinst.ini
49+
[mariadb]
50+
Driver = ${MARIADB_DRIVER_PATH}
51+
```
52+
4353
## Connection Strings
4454

4555
### Db2
@@ -53,3 +63,9 @@ Driver=/nix/store/py6m0q4ij50pwjk6a5f18qhhahrvf2sk-db2-driver-11.5.8/lib/libdb2.
5363
```
5464
Driver=/nix/store/j648cwmz16prd2n35h0xdhji9b02pip6-postgres-odbc-driver-15.00.0000/lib/psqlodbca.so;Server=localhost;Database=odbc_test;Uid=postgres;Pwd=password;Port=5432
5565
```
66+
67+
### MariaDB
68+
69+
```
70+
Driver=/nix/store/i2i0jj2bxxkq9yc74217b00ddcjnygsg-mariadb-odbc-driver-3.1.9/lib/mariadb/libmaodbc.so;Server=localhost;Database=odbc_test;Uid=mysql;Pwd=password;Port=3306
71+
```

flake.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
packages = {
3434
db2-odbc-driver = pkgs.db2-odbc-driver {};
3535
postgres-odbc-driver = pkgs.postgres-odbc-driver {};
36+
mariadb-odbc-driver = pkgs.mariadb-odbc-driver {};
3637
};
3738

3839
# nix run
@@ -61,6 +62,7 @@
6162
program = toString (pkgs.writeScript "generate-odbcinst-ini" ''
6263
DB2_DRIVER_PATH=${packages.db2-odbc-driver}/lib/${if stdenv.isDarwin then "libdb2.dylib" else "libdb2.so"} \
6364
POSTGRES_DRIVER_PATH=${packages.postgres-odbc-driver}/lib/psqlodbca.so \
65+
MARIADB_DRIVER_PATH=${packages.mariadb-odbc-driver}/lib/mariadb/libmaodbc.so \
6466
envsubst < ./templates/.odbcinst.ini.template > .odbcinst.ini
6567
'');
6668
};
@@ -69,6 +71,7 @@
6971
program = toString (pkgs.writeScript "ls-odbc-driver-paths" ''
7072
echo "db2 ${packages.db2-odbc-driver}/lib/${if stdenv.isDarwin then "libdb2.dylib" else "libdb2.so"}"
7173
echo "postgres ${packages.postgres-odbc-driver}/lib/psqlodbca.so"
74+
echo "mariadb ${packages.mariadb-odbc-driver}/lib/mariadb/libmaodbc.so"
7275
'');
7376
};
7477
load-db2-schema = {
@@ -89,6 +92,7 @@
8992
openssl
9093
packages.db2-odbc-driver
9194
packages.postgres-odbc-driver
95+
packages.mariadb-odbc-driver
9296
]
9397
)}:$PATH"
9498
export CC=${stdenv.cc}/bin/clang
@@ -114,6 +118,7 @@
114118
openssl
115119
packages.db2-odbc-driver
116120
packages.postgres-odbc-driver
121+
packages.mariadb-odbc-driver
117122
]
118123
)}:$PATH"
119124
export CC=${stdenv.cc}/bin/clang
@@ -148,6 +153,7 @@
148153
pkgs.postgresql_15
149154
packages.db2-odbc-driver
150155
packages.postgres-odbc-driver
156+
packages.mariadb-odbc-driver
151157
];
152158
};
153159
});

templates/.odbc.ini.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ Driver = db2
33

44
[postgres odbc_test]
55
Driver = postgres
6+
7+
[mariadb odbc_test]
8+
Driver = mariadb

templates/.odbcinst.ini.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ Driver = ${DB2_DRIVER_PATH}
33

44
[postgres]
55
Driver = ${POSTGRES_DRIVER_PATH}
6+
7+
[mariadb]
8+
Driver = ${MARIADB_DRIVER_PATH}

test/sql/odbc_scan_mariadb.test

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
# # name: test/sql/odbc_scan_mariadb.test
2-
# # description: test odbc_scanner extension
3-
# # group: [odbc_scan]
4-
#
5-
# # Before we load the extension, this will fail
6-
# statement error
7-
# SELECT * FROM odbc_scan(
8-
# 'Driver=/opt/homebrew/Cellar/psqlodbc/15.00.0000/lib/psqlodbca.so;Server=localhost;Database=odbc_scanner_duckdb_extension_test;Uid=mariadb;Pwd=password;Port=5432',
9-
# 'db2inst1',
10-
# 'people'
11-
# );
12-
# ----
13-
# Catalog Error: Table Function with name odbc_scan does not exist!
14-
#
15-
# # Require statement will ensure this test is run with this extension loaded
16-
# require odbc_scanner
17-
#
18-
# # Confirm the extension works
19-
# query I
20-
# SELECT * FROM odbc_scan(
21-
# 'Driver=/opt/homebrew/Cellar/psqlodbc/15.00.0000/lib/psqlodbca.so;Server=localhost;Database=odbc_scanner_duckdb_extension_test;Uid=mariadb;Pwd=password;Port=5432',
22-
# 'db2inst1',
23-
# 'people'
24-
# );
25-
# ----
26-
# Lebron James
27-
# Spiderman
28-
# Wonder Woman
29-
# David Bowie
1+
# name: test/sql/odbc_scan_mariadb.test
2+
# description: test odbc_scanner extension
3+
# group: [odbc_scan]
4+
5+
# Before we load the extension, this will fail
6+
statement error
7+
SELECT * FROM odbc_scan(
8+
'DSN={mariadb odbc_test};Server=localhost;Database=odbc_test;Uid=mariadb;Pwd=password;Port=3307',
9+
'',
10+
'people'
11+
)
12+
ORDER BY salary ASC;
13+
----
14+
Catalog Error: Table Function with name odbc_scan does not exist!
15+
16+
# Require statement will ensure this test is run with this extension loaded
17+
require odbc_scanner
18+
19+
# Confirm the extension works
20+
query III
21+
SELECT * FROM odbc_scan(
22+
'DSN={mariadb odbc_test};Server=localhost;Database=odbc_test;Uid=mariadb;Pwd=password;Port=3307',
23+
'',
24+
'people'
25+
)
26+
ORDER BY salary ASC;
27+
----
28+
Lebron James 37 100.1
29+
Spiderman 25 200.2
30+
Wonder Woman 21 300.3
31+
David Bowie 69 400.4

test/sql/odbc_scan_mysql.test

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@
55
# # Before we load the extension, this will fail
66
# statement error
77
# SELECT * FROM odbc_scan(
8-
# 'Driver=/opt/homebrew/Cellar/psqlodbc/15.00.0000/lib/psqlodbca.so;Server=localhost;Database=odbc_scanner_duckdb_extension_test;Uid=mysql;Pwd=password;Port=5432',
9-
# 'db2inst1',
8+
# 'DSN={mysql odbc_test};Server=localhost;Database=odbc_test;Uid=mysql;Pwd=password;Port=3306',
9+
# '',
1010
# 'people'
11-
# );
11+
# )
12+
# ORDER BY salary ASC;
1213
# ----
1314
# Catalog Error: Table Function with name odbc_scan does not exist!
1415
#
1516
# # Require statement will ensure this test is run with this extension loaded
1617
# require odbc_scanner
1718
#
1819
# # Confirm the extension works
19-
# query I
20+
# query III
2021
# SELECT * FROM odbc_scan(
21-
# 'Driver=/opt/homebrew/Cellar/psqlodbc/15.00.0000/lib/psqlodbca.so;Server=localhost;Database=odbc_scanner_duckdb_extension_test;Uid=mysql;Pwd=password;Port=5432',
22-
# 'db2inst1',
22+
# 'DSN={mysql odbc_test};Server=localhost;Database=odbc_test;Uid=mysql;Pwd=password;Port=3306',
23+
# '',
2324
# 'people'
24-
# );
25+
# )
26+
# ORDER BY salary ASC;
2527
# ----
26-
# Lebron James 37 100.10
27-
# Spiderman 25 200.20
28-
# Wonder Woman 21 300.30
29-
# David Bowie 68 400.40
28+
# Lebron James 37 100.1
29+
# Spiderman 25 200.2
30+
# Wonder Woman 21 300.3
31+
# David Bowie 69 400.4

0 commit comments

Comments
 (0)