From b20dd1db024c107f9fed75c882b70943289ce285 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Thu, 16 Oct 2025 22:22:56 +0200 Subject: [PATCH 01/17] Driver/ODBC: Add dedicated page --- docs/_assets/icon/odbc-logo.png | Bin 0 -> 4060 bytes docs/connect/index.md | 24 +++++ docs/connect/odbc.md | 159 ++++++++++++++++++++++++++++++++ 3 files changed, 183 insertions(+) create mode 100644 docs/_assets/icon/odbc-logo.png create mode 100644 docs/connect/odbc.md diff --git a/docs/_assets/icon/odbc-logo.png b/docs/_assets/icon/odbc-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..ad1e061a00bd82ccf782c980350a95f34cbcc781 GIT binary patch literal 4060 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 RC7XXej10_B^~k%4{{vt%Ns|Bo literal 0 HcmV?d00001 diff --git a/docs/connect/index.md b/docs/connect/index.md index c22c8f1a..e2e4951e 100644 --- a/docs/connect/index.md +++ b/docs/connect/index.md @@ -110,6 +110,29 @@ CrateDB drivers and adapters for supported programming languages, frameworks, an ::::: +:::{rubric} Language-agnostic drivers +::: + +:::::{grid} 2 2 2 4 +:margin: 4 4 0 0 +:padding: 0 + +::::{grid-item-card} ODBC +:link: connect-odbc +:link-type: ref +:link-alt: Connect to CrateDB using ODBC +:padding: 3 +:text-align: center +:class-card: sd-pt-3 +:class-body: sd-fs-1 +:class-title: sd-fs-6 +```{image} /_assets/icon/odbc-logo.png +:height: 80px +``` +:::: + +::::: + :::{rubric} Protocol Support ::: @@ -181,6 +204,7 @@ javascript php python ruby +odbc natural All drivers ``` diff --git a/docs/connect/odbc.md b/docs/connect/odbc.md new file mode 100644 index 00000000..7b0e6c5a --- /dev/null +++ b/docs/connect/odbc.md @@ -0,0 +1,159 @@ +(odbc)= +(connect-odbc)= + +# ODBC + +:::{include} /_include/links.md +::: + +:::{div} sd-text-muted +Connect to CrateDB with ODBC. +::: + +## General information + +:::{rubric} About +::: + +:::{div} +Open Database Connectivity ([ODBC]) is a standard application programming +interface (API) for accessing database management systems (DBMS), +conceived to be independent of database systems and operating systems. +The application uses ODBC functions through an _ODBC driver manager_ and +addresses the driver and database using a _Data Source Name (DSN)_. +::: + +:::{rubric} Prerequisites +::: + +While Windows OS typically includes an ODBC driver manager, you can +install the [unixODBC] driver manager on Linux and macOS systems. +The PostgreSQL ODBC driver is called [psqlodbc]. + +:::{rubric} DSN +::: + +A typical connection string for CrateDB is: + +```text +ODBC;Driver={PostgreSQL};Server=localhost;Port=5432;Uid=crate;Pwd=crate;MaxVarcharSize=1073741824; +``` + +## Examples + +A few examples to demonstrate CrateDB connectivity with ODBC. While the examples +enumerated below use `Driver={PostgreSQL}` for addressing the driver, you can +also address a named connection using `Dsn=your_dsn_name` instead. + +### C# + +Use the ODBC .NET Data Provider to access data from your C Sharp ADO\.NET +applications. The [.NET Framework Data Provider for ODBC] is available +through the [System.Data.Odbc] namespace. + +```c# +using System.Data.Odbc; + +// Open connection +string connection_string = "ODBC;Driver={PostgreSQL};Server=localhost;Port=5432;Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824;"; +OdbcConnection connection = new OdbcConnection(connection_string); +connection.Open(); + +// Invoke query +OdbcCommand command = new OdbcCommand("SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 5"); +OdbcDataReader reader = command.ExecuteReader(); + +// Display results +while(reader.Read()) +{ + String mountain = reader.GetString(0); + Integer height = reader.GetString(1); + Console.Write(mountain + ": " + height); + Console.WriteLine(); +} + +// Clean up +reader.Close(); +command.Dispose(); +connection.Close(); +``` + +### Python + +[pyodbc] is an open source Python module that makes accessing ODBC databases +simple. It implements the DB API 2.0 specification and adds other Pythonic +convenience. For more information, please visit the +[pyodbc installation instructions] and [connecting to PostgreSQL with pyodbc]. + +```shell +pip install pyodbc +``` +```python +import pyodbc + +# Open connection +connection_string = \ + "ODBC;Driver={PostgreSQL};Server=localhost;Port=5432;" \ + "Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824;" +connection = pyodbc.connect(connection_string) + +# Invoke query +cursor = connection.cursor() +cursor.execute("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 5") + +# Display results +for row in cursor: + print(row) + +# Clean up +cursor.close() +connection.close() +``` + +### Visual Basic + +See also [psqlODBC with Visual Basic]. Please navigate to [psqlodbc download] +to download and install the `psqlodbc` driver for Windows systems. + +```visualbasic +Dim cn as New ADODB.Connection +Dim rs as New ADODB.Recordset + +'Open connection +cn.Open "DSN=;" & _ + "Server=localhost;" & _ + "Port=5432;" & _ + "Uid=crate;" & _ + "Pwd=crate;" & _ + "Database=doc;" & _ + "MaxVarcharSize=1073741824;" + +'Invoke query +rs.Open "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 5", cn + +'Display results +While Not rs.EOF + Debug.Print rs!mountain & ": " & rs!height + rs.MoveNext +Wend + +'Clean up +rs.Close +cn.Close +``` + +## See also + +- {ref}`Turbodbc -- a high-performance ODBC library ` + + +[.NET Framework Data Provider for ODBC]: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/data-providers#net-framework-data-provider-for-odbc +[Connecting to PostgreSQL with pyodbc]: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-PostgreSQL +[postgres]: https://crates.io/crates/postgres +[psqlodbc]: https://odbc.postgresql.org/ +[psqlodbc download]: https://www.postgresql.org/ftp/odbc/releases/ +[psqlODBC with Visual Basic]: https://odbc.postgresql.org/howto-vb.html +[pyodbc]: https://github.com/mkleehammer/pyodbc +[pyodbc installation instructions]: https://github.com/mkleehammer/pyodbc/wiki/Install +[System.Data.Odbc]: https://learn.microsoft.com/en-us/dotnet/api/system.data.odbc +[unixODBC]: https://www.unixodbc.org/ From f85558297b575f7152a1c925220632e12536e3b1 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Thu, 16 Oct 2025 23:06:26 +0200 Subject: [PATCH 02/17] Driver/ODBC: Implement suggestions by CodeRabbit --- docs/connect/odbc.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/connect/odbc.md b/docs/connect/odbc.md index 7b0e6c5a..ff7a0480 100644 --- a/docs/connect/odbc.md +++ b/docs/connect/odbc.md @@ -80,7 +80,7 @@ connection.Close(); ### Python -[pyodbc] is an open source Python module that makes accessing ODBC databases +[pyodbc] is an open-source Python module that makes accessing ODBC databases simple. It implements the DB API 2.0 specification and adds other Pythonic convenience. For more information, please visit the [pyodbc installation instructions] and [connecting to PostgreSQL with pyodbc]. @@ -149,7 +149,6 @@ cn.Close [.NET Framework Data Provider for ODBC]: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/data-providers#net-framework-data-provider-for-odbc [Connecting to PostgreSQL with pyodbc]: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-PostgreSQL -[postgres]: https://crates.io/crates/postgres [psqlodbc]: https://odbc.postgresql.org/ [psqlodbc download]: https://www.postgresql.org/ftp/odbc/releases/ [psqlODBC with Visual Basic]: https://odbc.postgresql.org/howto-vb.html From c4902e98508bf68d223f160d6625a121121281b1 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 19 Oct 2025 19:36:03 +0200 Subject: [PATCH 03/17] Driver/ODBC: Generalize "Prerequisites" section --- docs/_include/links.md | 3 ++ docs/connect/index.md | 2 +- docs/connect/{odbc.md => odbc/index.md} | 47 ++++++------------ docs/connect/odbc/setup-body.md | 64 +++++++++++++++++++++++++ docs/connect/odbc/setup-widget.md | 11 +++++ 5 files changed, 93 insertions(+), 34 deletions(-) rename docs/connect/{odbc.md => odbc/index.md} (71%) create mode 100644 docs/connect/odbc/setup-body.md create mode 100644 docs/connect/odbc/setup-widget.md diff --git a/docs/_include/links.md b/docs/_include/links.md index 21385cd8..66499c79 100644 --- a/docs/_include/links.md +++ b/docs/_include/links.md @@ -70,6 +70,8 @@ [ODBC]: https://en.wikipedia.org/wiki/Open_Database_Connectivity [PostgreSQL JDBC Driver]: https://jdbc.postgresql.org/ [PostgreSQL wire protocol]: https://www.postgresql.org/docs/current/protocol.html +[psqlODBC]: https://odbc.postgresql.org/ +[psqlODBC download site]: https://www.postgresql.org/ftp/odbc/releases/ [python-dbapi-by-example]: inv:crate-python:*:label#by-example [python-sqlalchemy-by-example]: inv:sqlalchemy-cratedb:*:label#by-example [query DSL based on JSON]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html @@ -82,5 +84,6 @@ [TF–IDF]: https://en.wikipedia.org/wiki/Tf%E2%80%93idf [timeseries-queries-and-visualization-colab]: https://colab.research.google.com/github/crate/cratedb-examples/blob/main/topic/timeseries/timeseries-queries-and-visualization.ipynb [timeseries-queries-and-visualization-github]: https://github.com/crate/cratedb-examples/blob/main/topic/timeseries/timeseries-queries-and-visualization.ipynb +[unixODBC]: https://www.unixodbc.org/ [Vector Database (Product)]: https://cratedb.com/solutions/vector-database [Vector Database]: https://en.wikipedia.org/wiki/Vector_database diff --git a/docs/connect/index.md b/docs/connect/index.md index e2e4951e..e9e6b458 100644 --- a/docs/connect/index.md +++ b/docs/connect/index.md @@ -204,7 +204,7 @@ javascript php python ruby -odbc +odbc/index natural All drivers ``` diff --git a/docs/connect/odbc.md b/docs/connect/odbc/index.md similarity index 71% rename from docs/connect/odbc.md rename to docs/connect/odbc/index.md index ff7a0480..a449f24e 100644 --- a/docs/connect/odbc.md +++ b/docs/connect/odbc/index.md @@ -23,26 +23,13 @@ The application uses ODBC functions through an _ODBC driver manager_ and addresses the driver and database using a _Data Source Name (DSN)_. ::: -:::{rubric} Prerequisites +:::{include} setup-widget.md ::: -While Windows OS typically includes an ODBC driver manager, you can -install the [unixODBC] driver manager on Linux and macOS systems. -The PostgreSQL ODBC driver is called [psqlodbc]. - -:::{rubric} DSN -::: - -A typical connection string for CrateDB is: - -```text -ODBC;Driver={PostgreSQL};Server=localhost;Port=5432;Uid=crate;Pwd=crate;MaxVarcharSize=1073741824; -``` - ## Examples A few examples to demonstrate CrateDB connectivity with ODBC. While the examples -enumerated below use `Driver={PostgreSQL}` for addressing the driver, you can +enumerated below use `Driver={PostgreSQL ODBC}` for addressing the driver, you can also address a named connection using `Dsn=your_dsn_name` instead. ### C# @@ -54,8 +41,8 @@ through the [System.Data.Odbc] namespace. ```c# using System.Data.Odbc; -// Open connection -string connection_string = "ODBC;Driver={PostgreSQL};Server=localhost;Port=5432;Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824;"; +// Connect to database +string connection_string = "ODBC;Driver={PostgreSQL ODBC};Server=localhost;Port=5432;Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824"; OdbcConnection connection = new OdbcConnection(connection_string); connection.Open(); @@ -78,7 +65,7 @@ command.Dispose(); connection.Close(); ``` -### Python +### Python (pyodbc) [pyodbc] is an open-source Python module that makes accessing ODBC databases simple. It implements the DB API 2.0 specification and adds other Pythonic @@ -86,15 +73,15 @@ convenience. For more information, please visit the [pyodbc installation instructions] and [connecting to PostgreSQL with pyodbc]. ```shell -pip install pyodbc +pip install --upgrade pyodbc ``` ```python import pyodbc -# Open connection +# Connect to database connection_string = \ - "ODBC;Driver={PostgreSQL};Server=localhost;Port=5432;" \ - "Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824;" + "Driver={PostgreSQL ODBC};Server=localhost;Port=5432;" \ + "Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824" connection = pyodbc.connect(connection_string) # Invoke query @@ -112,15 +99,16 @@ connection.close() ### Visual Basic -See also [psqlODBC with Visual Basic]. Please navigate to [psqlodbc download] -to download and install the `psqlodbc` driver for Windows systems. +See also [psqlODBC with Visual Basic]. Please navigate to the +[psqlODBC download site] to download and install the `psqlodbc` +driver for Windows systems. ```visualbasic Dim cn as New ADODB.Connection Dim rs as New ADODB.Recordset -'Open connection -cn.Open "DSN=;" & _ +'Connect to database +cn.Open "Dsn=;" & _ "Server=localhost;" & _ "Port=5432;" & _ "Uid=crate;" & _ @@ -142,17 +130,10 @@ rs.Close cn.Close ``` -## See also - -- {ref}`Turbodbc -- a high-performance ODBC library ` - [.NET Framework Data Provider for ODBC]: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/data-providers#net-framework-data-provider-for-odbc [Connecting to PostgreSQL with pyodbc]: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-PostgreSQL -[psqlodbc]: https://odbc.postgresql.org/ -[psqlodbc download]: https://www.postgresql.org/ftp/odbc/releases/ [psqlODBC with Visual Basic]: https://odbc.postgresql.org/howto-vb.html [pyodbc]: https://github.com/mkleehammer/pyodbc [pyodbc installation instructions]: https://github.com/mkleehammer/pyodbc/wiki/Install [System.Data.Odbc]: https://learn.microsoft.com/en-us/dotnet/api/system.data.odbc -[unixODBC]: https://www.unixodbc.org/ diff --git a/docs/connect/odbc/setup-body.md b/docs/connect/odbc/setup-body.md new file mode 100644 index 00000000..35dd2598 --- /dev/null +++ b/docs/connect/odbc/setup-body.md @@ -0,0 +1,64 @@ +--- +orphan: true +--- + +:::{rubric} Prerequisites +::: + +While Windows OS typically includes an ODBC driver manager, you can +install the [unixODBC] driver manager on Linux and macOS systems. +The PostgreSQL ODBC driver is called [psqlODBC]. + +:Windows: + + On Windows, download the latest 64 bit driver installer + (MSI file) from the [psqlODBC download site] and invoke it. + [Installing PostgreSQL ODBC Drivers] includes a walkthrough + including screenshots. + +:Linux and macOS: + + On Linux and macOS, install the [unixODBC] ODBC driver manager, + then install and register psqlODBC. + +`odbcinst.ini` +```ini +[PostgreSQL ODBC] +Description = ODBC Driver for PostgreSQL + +# Linux Arch +# pacman -Sy psqlodbc +# Driver = /usr/lib/psqlodbcw.so + +# Linux Debian +# apt install --yes odbc-postgresql odbcinst unixodbc +# Driver = /usr/lib/x86_64-linux-gnu/odbc/psqlodbcw.so + +# Linux Red Hat +# yum install -y postgresql-odbc +# Driver = /usr/lib64/psqlodbcw.so + +# Linux Generic +# Driver = /usr/lib64/libodbcpsql.so +# Setup = /usr/lib64/libodbcpsqlS.so + +# macOS +# brew install psqlodbc unixodbc +Driver = /usr/local/lib/psqlodbcw.so +``` +Before registering the driver, enable the `Driver` line matching your system. +```shell +odbcinst -i -d -f odbcinst.ini +``` + +:::{rubric} DSN-less configuration +::: + +A typical connection string for CrateDB is: + +```text +ODBC;Driver={PostgreSQL ODBC};Server=localhost;Port=5432;Uid=crate;Pwd=crate;MaxVarcharSize=1073741824 +``` + + +[Installing PostgreSQL ODBC Drivers]: https://help.campbellsci.com/PC400%20Manual/viewpro/installing_postgresql_odbc_drivers.htm diff --git a/docs/connect/odbc/setup-widget.md b/docs/connect/odbc/setup-widget.md new file mode 100644 index 00000000..aee6a703 --- /dev/null +++ b/docs/connect/odbc/setup-widget.md @@ -0,0 +1,11 @@ +--- +orphan: true +--- + +The PostgreSQL ODBC driver [psqlODBC] +can be used to connect to CrateDB from ODBC environments. + +::::{dropdown} Learn how to install and configure the PostgreSQL ODBC driver +:::{include} setup-body.md +::: +:::: From 936529f4b51461ab65594a0dc164a980bb0703d5 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 19 Oct 2025 19:37:47 +0200 Subject: [PATCH 04/17] Driver/ODBC: Add Erlang --- docs/connect/odbc/index.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/connect/odbc/index.md b/docs/connect/odbc/index.md index a449f24e..cd58ed03 100644 --- a/docs/connect/odbc/index.md +++ b/docs/connect/odbc/index.md @@ -65,6 +65,24 @@ command.Dispose(); connection.Close(); ``` +### Erlang + +The [Erlang ODBC application] provides an interface to communicate +with relational SQL-databases out of the box. + +```erlang +odbc:start(), +{ok, Ref} = odbc:connect("Driver={PostgreSQL ODBC};Server=localhost;Port=5432;Uid=crate;Pwd=crate", []), +io:fwrite("~p~n", [odbc:sql_query(Ref, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3")]), +``` + +:::{todo} +Enable with the [Erlang patch](https://github.com/crate/cratedb-guide/pull/420). +``` +- {ref}`connect-erlang` +``` +::: + ### Python (pyodbc) [pyodbc] is an open-source Python module that makes accessing ODBC databases @@ -133,6 +151,7 @@ cn.Close [.NET Framework Data Provider for ODBC]: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/data-providers#net-framework-data-provider-for-odbc [Connecting to PostgreSQL with pyodbc]: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-PostgreSQL +[Erlang ODBC application]: https://www.erlang.org/docs/28/apps/odbc/odbc.html [psqlODBC with Visual Basic]: https://odbc.postgresql.org/howto-vb.html [pyodbc]: https://github.com/mkleehammer/pyodbc [pyodbc installation instructions]: https://github.com/mkleehammer/pyodbc/wiki/Install From 8e040ed9d68e180200f538c9fe9c46813a02df43 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 19 Oct 2025 19:38:05 +0200 Subject: [PATCH 05/17] Driver/ODBC: Add Python (turbodbc) --- docs/connect/odbc/index.md | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/connect/odbc/index.md b/docs/connect/odbc/index.md index cd58ed03..33e0a0da 100644 --- a/docs/connect/odbc/index.md +++ b/docs/connect/odbc/index.md @@ -115,6 +115,44 @@ cursor.close() connection.close() ``` +### Python (turbodbc) + +[turbodbc] is a Python module to access relational databases via the Open +Database Connectivity (ODBC) interface. turbodbc offers built-in NumPy and +Apache Arrow for maximum performance. + +```shell +pip install --upgrade turbodbc +``` +```python +import turbodbc + +# Connect to database +connection_string = \ + "Driver={PostgreSQL ODBC};Server=localhost;Port=5432;" \ + "Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824" +connection = turbodbc.connect(connection_string) + +# Invoke query +cursor = connection.cursor() +cursor.execute("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 5") + +# Display results +for row in cursor: + print(row) + +# Clean up +cursor.close() +connection.close() +``` + +:::{todo} +Enable with the [Python patch](https://github.com/crate/cratedb-guide/pull/403). +``` +- {ref}`Turbodbc -- a high-performance ODBC library ` +``` +::: + ### Visual Basic See also [psqlODBC with Visual Basic]. Please navigate to the @@ -156,3 +194,4 @@ cn.Close [pyodbc]: https://github.com/mkleehammer/pyodbc [pyodbc installation instructions]: https://github.com/mkleehammer/pyodbc/wiki/Install [System.Data.Odbc]: https://learn.microsoft.com/en-us/dotnet/api/system.data.odbc +[turbodbc]: https://turbodbc.readthedocs.io/ From ff03d66f4f5aa39dd8d3b7e72c0f1568a47dcc16 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sun, 19 Oct 2025 20:01:50 +0200 Subject: [PATCH 06/17] Driver/ODBC: Implement suggestions by CodeRabbit --- docs/connect/odbc/index.md | 10 +++++----- docs/connect/odbc/setup-body.md | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/connect/odbc/index.md b/docs/connect/odbc/index.md index 33e0a0da..c82ec4ec 100644 --- a/docs/connect/odbc/index.md +++ b/docs/connect/odbc/index.md @@ -47,14 +47,14 @@ OdbcConnection connection = new OdbcConnection(connection_string); connection.Open(); // Invoke query -OdbcCommand command = new OdbcCommand("SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 5"); +OdbcCommand command = new OdbcCommand("SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 5", connection); OdbcDataReader reader = command.ExecuteReader(); // Display results -while(reader.Read()) +while(reader.Read()) { - String mountain = reader.GetString(0); - Integer height = reader.GetString(1); + String mountain = reader.GetString(0); + int height = reader.GetInt32(1); Console.Write(mountain + ": " + height); Console.WriteLine(); } @@ -188,7 +188,7 @@ cn.Close [.NET Framework Data Provider for ODBC]: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/data-providers#net-framework-data-provider-for-odbc -[Connecting to PostgreSQL with pyodbc]: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-PostgreSQL +[connecting to PostgreSQL with pyodbc]: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-PostgreSQL [Erlang ODBC application]: https://www.erlang.org/docs/28/apps/odbc/odbc.html [psqlODBC with Visual Basic]: https://odbc.postgresql.org/howto-vb.html [pyodbc]: https://github.com/mkleehammer/pyodbc diff --git a/docs/connect/odbc/setup-body.md b/docs/connect/odbc/setup-body.md index 35dd2598..108e9881 100644 --- a/docs/connect/odbc/setup-body.md +++ b/docs/connect/odbc/setup-body.md @@ -11,7 +11,7 @@ The PostgreSQL ODBC driver is called [psqlODBC]. :Windows: - On Windows, download the latest 64 bit driver installer + On Windows, download the latest 64-bit driver installer (MSI file) from the [psqlODBC download site] and invoke it. [Installing PostgreSQL ODBC Drivers] includes a walkthrough including screenshots. @@ -57,8 +57,10 @@ odbcinst -i -d -f odbcinst.ini A typical connection string for CrateDB is: ```text -ODBC;Driver={PostgreSQL ODBC};Server=localhost;Port=5432;Uid=crate;Pwd=crate;MaxVarcharSize=1073741824 +ODBC;Driver={PostgreSQL ODBC};Server=localhost;Port=5432;Uid=crate;Pwd=crate;MaxVarcharSize=1073741824 ``` +For some drivers, you will need to omit the `ODBC;` prefix. + [Installing PostgreSQL ODBC Drivers]: https://help.campbellsci.com/PC400%20Manual/viewpro/installing_postgresql_odbc_drivers.htm From e17d1bac6a972fcf432f9a43a4d0efe13ee891cb Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Mon, 20 Oct 2025 00:18:23 +0200 Subject: [PATCH 07/17] Driver/ODBC: Add isql to page about applications --- docs/connect/application.md | 48 +++++++++++++++++++++++++++++++ docs/connect/odbc/index.md | 2 +- docs/connect/odbc/setup-widget.md | 2 +- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/docs/connect/application.md b/docs/connect/application.md index 4ebf1f0f..c12c7714 100644 --- a/docs/connect/application.md +++ b/docs/connect/application.md @@ -186,6 +186,54 @@ crash --command "SELECT 42.42;" :::: +(isql)= +### isql + +`isql` and `iusql` are unixODBC command-line tools allowing users to execute +SQL interactively or in batches. +The tools provide several useful features, including an option to generate +output wrapped in an HTML table. + +:::{include} /connect/odbc/setup-widget.md +::: + +::::{tab-set} + +:::{tab-item} CrateDB Cloud +:sync: server +```{code} ini +[CrateDB Cloud] +Driver = PostgreSQL ODBC +Servername = testcluster.cratedb.net +Port = 5432 +Sslmode = require +Username = admin +Password = password +``` +```shell +echo "SELECT 42.42" | iusql "CrateDB Cloud" +``` +::: + +:::{tab-item} CrateDB on localhost +:sync: localhost +```{code} ini +[CrateDB] +Driver = PostgreSQL ODBC +Servername = localhost +Port = 5432 +Sslmode = disable +Username = crate +Password = crate +``` +```shell +echo "SELECT 42.42" | iusql "CrateDB" +``` +::: + +:::: + + (psql)= ### psql diff --git a/docs/connect/odbc/index.md b/docs/connect/odbc/index.md index c82ec4ec..dc1dd152 100644 --- a/docs/connect/odbc/index.md +++ b/docs/connect/odbc/index.md @@ -23,7 +23,7 @@ The application uses ODBC functions through an _ODBC driver manager_ and addresses the driver and database using a _Data Source Name (DSN)_. ::: -:::{include} setup-widget.md +:::{include} /connect/odbc/setup-widget.md ::: ## Examples diff --git a/docs/connect/odbc/setup-widget.md b/docs/connect/odbc/setup-widget.md index aee6a703..e8aecc5e 100644 --- a/docs/connect/odbc/setup-widget.md +++ b/docs/connect/odbc/setup-widget.md @@ -6,6 +6,6 @@ The PostgreSQL ODBC driver [psqlODBC] can be used to connect to CrateDB from ODBC environments. ::::{dropdown} Learn how to install and configure the PostgreSQL ODBC driver -:::{include} setup-body.md +:::{include} /connect/odbc/setup-body.md ::: :::: From 76c66cc7cb7c8028081659d879d00f667f18687e Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Tue, 28 Oct 2025 17:26:22 +0100 Subject: [PATCH 08/17] Connect/ODBC: Improve "Installation" and "Configuration" sections --- docs/connect/odbc/configure-body.md | 54 ++++++++++++++++ docs/connect/odbc/index.md | 28 +++++---- docs/connect/odbc/setup-body.md | 95 ++++++++++++++++------------- 3 files changed, 121 insertions(+), 56 deletions(-) create mode 100644 docs/connect/odbc/configure-body.md diff --git a/docs/connect/odbc/configure-body.md b/docs/connect/odbc/configure-body.md new file mode 100644 index 00000000..6f22c6c9 --- /dev/null +++ b/docs/connect/odbc/configure-body.md @@ -0,0 +1,54 @@ +--- +orphan: true +--- + +For connecting to CrateDB, either address the database using a named +connection (DSN), e.g. using `Dsn=CrateDB`, or address it directly +using the driver, like `Driver={PostgreSQL Unicode}`. + +:::{rubric} DSN configuration +::: + +For connecting to the database using a DSN, +a typical connection string for CrateDB is: +```text +Dsn=CrateDB +``` + +:::::{tab-set} + +::::{tab-item} Windows +On Windows, you will create a DSN using the ODBC driver manager UI. +To set up a DSN (Data Source Name), click the "System DSN" tab. Click "Add". +Select "PostgreSQL Unicode" and click "Finish". +The [illustrated walkthrough][Installing PostgreSQL ODBC drivers on Windows] +also covers that part. +:::: + +::::{tab-item} Linux and macOS +With unixODBC, configure a DSN within an `.odbc.ini` or `/etc/odbc.ini` +file. + +`~/.odbc.ini` +```ini +[CrateDB] +Description=CrateDB +Driver=PostgreSQL Unicode +Server=localhost +Port=5432 +Uid=crate +Pwd=crate +MaxVarcharSize=1073741824 +``` + +:::{rubric} DSN-less configuration +::: + +For directly connecting using a driver, without a registered DSN, +a typical connection string for CrateDB is: +```text +Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Uid=crate;Pwd=crate;MaxVarcharSize=1073741824 +``` +:::: + +::::: diff --git a/docs/connect/odbc/index.md b/docs/connect/odbc/index.md index dc1dd152..a7002c45 100644 --- a/docs/connect/odbc/index.md +++ b/docs/connect/odbc/index.md @@ -10,11 +10,6 @@ Connect to CrateDB with ODBC. ::: -## General information - -:::{rubric} About -::: - :::{div} Open Database Connectivity ([ODBC]) is a standard application programming interface (API) for accessing database management systems (DBMS), @@ -23,14 +18,19 @@ The application uses ODBC functions through an _ODBC driver manager_ and addresses the driver and database using a _Data Source Name (DSN)_. ::: -:::{include} /connect/odbc/setup-widget.md +## Installation + +:::{include} /connect/odbc/setup-body.md +::: + +## Configuration + +:::{include} /connect/odbc/configure-body.md ::: ## Examples -A few examples to demonstrate CrateDB connectivity with ODBC. While the examples -enumerated below use `Driver={PostgreSQL ODBC}` for addressing the driver, you can -also address a named connection using `Dsn=your_dsn_name` instead. +A few examples to demonstrate CrateDB connectivity with ODBC. ### C# @@ -42,7 +42,7 @@ through the [System.Data.Odbc] namespace. using System.Data.Odbc; // Connect to database -string connection_string = "ODBC;Driver={PostgreSQL ODBC};Server=localhost;Port=5432;Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824"; +string connection_string = "ODBC;Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824"; OdbcConnection connection = new OdbcConnection(connection_string); connection.Open(); @@ -72,7 +72,7 @@ with relational SQL-databases out of the box. ```erlang odbc:start(), -{ok, Ref} = odbc:connect("Driver={PostgreSQL ODBC};Server=localhost;Port=5432;Uid=crate;Pwd=crate", []), +{ok, Ref} = odbc:connect("Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Uid=crate;Pwd=crate", []), io:fwrite("~p~n", [odbc:sql_query(Ref, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3")]), ``` @@ -98,7 +98,7 @@ import pyodbc # Connect to database connection_string = \ - "Driver={PostgreSQL ODBC};Server=localhost;Port=5432;" \ + "Driver={PostgreSQL Unicode};Server=localhost;Port=5432;" \ "Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824" connection = pyodbc.connect(connection_string) @@ -129,7 +129,7 @@ import turbodbc # Connect to database connection_string = \ - "Driver={PostgreSQL ODBC};Server=localhost;Port=5432;" \ + "Driver={PostgreSQL Unicode};Server=localhost;Port=5432;" \ "Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824" connection = turbodbc.connect(connection_string) @@ -155,9 +155,11 @@ Enable with the [Python patch](https://github.com/crate/cratedb-guide/pull/403). ### Visual Basic +:::{div} See also [psqlODBC with Visual Basic]. Please navigate to the [psqlODBC download site] to download and install the `psqlodbc` driver for Windows systems. +::: ```visualbasic Dim cn as New ADODB.Connection diff --git a/docs/connect/odbc/setup-body.md b/docs/connect/odbc/setup-body.md index 108e9881..857156b6 100644 --- a/docs/connect/odbc/setup-body.md +++ b/docs/connect/odbc/setup-body.md @@ -2,65 +2,74 @@ orphan: true --- -:::{rubric} Prerequisites -::: - -While Windows OS typically includes an ODBC driver manager, you can +While Windows typically includes an ODBC driver manager, you can install the [unixODBC] driver manager on Linux and macOS systems. The PostgreSQL ODBC driver is called [psqlODBC]. -:Windows: - - On Windows, download the latest 64-bit driver installer - (MSI file) from the [psqlODBC download site] and invoke it. - [Installing PostgreSQL ODBC Drivers] includes a walkthrough - including screenshots. +:::::{tab-set} -:Linux and macOS: +::::{tab-item} Windows +On Windows, download the latest 64-bit driver (MSI file) +from the [psqlODBC download site] and install it. +[Installing PostgreSQL ODBC drivers on Windows] includes an illustrated walkthrough. +:::: - On Linux and macOS, install the [unixODBC] ODBC driver manager, - then install and register psqlODBC. +::::{tab-item} Linux +On Linux, install the [unixODBC] ODBC driver manager +and the psqlODBC driver. +[Installing PostgreSQL ODBC drivers on Linux] includes an illustrated walkthrough. -`odbcinst.ini` -```ini -[PostgreSQL ODBC] -Description = ODBC Driver for PostgreSQL - -# Linux Arch -# pacman -Sy psqlodbc -# Driver = /usr/lib/psqlodbcw.so - -# Linux Debian -# apt install --yes odbc-postgresql odbcinst unixodbc -# Driver = /usr/lib/x86_64-linux-gnu/odbc/psqlodbcw.so +Arch Linux +```shell +pacman -Sy psqlodbc +``` +Debian and derivatives +```shell +apt install --yes odbc-postgresql odbcinst unixodbc +``` +Red Hat and derivatives +```shell +yum install -y postgresql-odbc +``` -# Linux Red Hat -# yum install -y postgresql-odbc -# Driver = /usr/lib64/psqlodbcw.so +Verify installation. +```shell +odbcinst -q -d +``` +``` +[PostgreSQL ANSI] +[PostgreSQL Unicode] +``` +:::: -# Linux Generic -# Driver = /usr/lib64/libodbcpsql.so -# Setup = /usr/lib64/libodbcpsqlS.so +::::{tab-item} macOS +On macOS, install the [unixODBC] ODBC driver manager +and the psqlODBC driver, then register it. +```shell # macOS -# brew install psqlodbc unixodbc +brew install psqlodbc unixodbc +``` +`odbcinst.ini` +```ini +[PostgreSQL Unicode] +Description = PostgreSQL ODBC driver (Unicode version) Driver = /usr/local/lib/psqlodbcw.so ``` -Before registering the driver, enable the `Driver` line matching your system. ```shell odbcinst -i -d -f odbcinst.ini ``` - -:::{rubric} DSN-less configuration -::: - -A typical connection string for CrateDB is: - -```text -ODBC;Driver={PostgreSQL ODBC};Server=localhost;Port=5432;Uid=crate;Pwd=crate;MaxVarcharSize=1073741824 +Verify installation. +```shell +odbcinst -q -d +``` +``` +[PostgreSQL Unicode] ``` +:::: -For some drivers, you will need to omit the `ODBC;` prefix. +::::: -[Installing PostgreSQL ODBC Drivers]: https://help.campbellsci.com/PC400%20Manual/viewpro/installing_postgresql_odbc_drivers.htm +[Installing PostgreSQL ODBC drivers on Linux]: https://www.dbi-services.com/blog/installing-the-odbc-drivers-for-postgresql/ +[Installing PostgreSQL ODBC drivers on Windows]: https://help.campbellsci.com/PC400%20Manual/viewpro/installing_postgresql_odbc_drivers.htm From cfb6d4d3a69f9d5823dccd20cfef7543a8fd176f Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Tue, 28 Oct 2025 17:34:00 +0100 Subject: [PATCH 09/17] Connect/ODBC: Rename auxiliary files --- docs/connect/application.md | 2 +- docs/connect/odbc/{configure-body.md => configure.md} | 8 +++++--- docs/connect/odbc/index.md | 4 ++-- .../connect/odbc/{setup-widget.md => install-dropdown.md} | 2 +- docs/connect/odbc/{setup-body.md => install.md} | 0 5 files changed, 9 insertions(+), 7 deletions(-) rename docs/connect/odbc/{configure-body.md => configure.md} (99%) rename docs/connect/odbc/{setup-widget.md => install-dropdown.md} (81%) rename docs/connect/odbc/{setup-body.md => install.md} (100%) diff --git a/docs/connect/application.md b/docs/connect/application.md index c12c7714..82a829f7 100644 --- a/docs/connect/application.md +++ b/docs/connect/application.md @@ -194,7 +194,7 @@ SQL interactively or in batches. The tools provide several useful features, including an option to generate output wrapped in an HTML table. -:::{include} /connect/odbc/setup-widget.md +:::{include} /connect/odbc/install-dropdown.md ::: ::::{tab-set} diff --git a/docs/connect/odbc/configure-body.md b/docs/connect/odbc/configure.md similarity index 99% rename from docs/connect/odbc/configure-body.md rename to docs/connect/odbc/configure.md index 6f22c6c9..ad8ff792 100644 --- a/docs/connect/odbc/configure-body.md +++ b/docs/connect/odbc/configure.md @@ -41,6 +41,11 @@ Pwd=crate MaxVarcharSize=1073741824 ``` +:::: + +::::: + + :::{rubric} DSN-less configuration ::: @@ -49,6 +54,3 @@ a typical connection string for CrateDB is: ```text Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Uid=crate;Pwd=crate;MaxVarcharSize=1073741824 ``` -:::: - -::::: diff --git a/docs/connect/odbc/index.md b/docs/connect/odbc/index.md index a7002c45..2cdbf0ac 100644 --- a/docs/connect/odbc/index.md +++ b/docs/connect/odbc/index.md @@ -20,12 +20,12 @@ addresses the driver and database using a _Data Source Name (DSN)_. ## Installation -:::{include} /connect/odbc/setup-body.md +:::{include} /connect/odbc/install.md ::: ## Configuration -:::{include} /connect/odbc/configure-body.md +:::{include} /connect/odbc/configure.md ::: ## Examples diff --git a/docs/connect/odbc/setup-widget.md b/docs/connect/odbc/install-dropdown.md similarity index 81% rename from docs/connect/odbc/setup-widget.md rename to docs/connect/odbc/install-dropdown.md index e8aecc5e..dcff99f3 100644 --- a/docs/connect/odbc/setup-widget.md +++ b/docs/connect/odbc/install-dropdown.md @@ -6,6 +6,6 @@ The PostgreSQL ODBC driver [psqlODBC] can be used to connect to CrateDB from ODBC environments. ::::{dropdown} Learn how to install and configure the PostgreSQL ODBC driver -:::{include} /connect/odbc/setup-body.md +:::{include} /connect/odbc/install-dropdown.md ::: :::: diff --git a/docs/connect/odbc/setup-body.md b/docs/connect/odbc/install.md similarity index 100% rename from docs/connect/odbc/setup-body.md rename to docs/connect/odbc/install.md From 58c5b8181cb7a5527de2b2bda1a5579c25558bc3 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Tue, 28 Oct 2025 18:16:02 +0100 Subject: [PATCH 10/17] Connect/ODBC: Use separate pages for each item --- docs/connect/odbc/csharp.md | 64 +++++++++++++++++++++++++++++++++++++ docs/connect/odbc/index.md | 37 ++------------------- 2 files changed, 67 insertions(+), 34 deletions(-) create mode 100644 docs/connect/odbc/csharp.md diff --git a/docs/connect/odbc/csharp.md b/docs/connect/odbc/csharp.md new file mode 100644 index 00000000..36f9a809 --- /dev/null +++ b/docs/connect/odbc/csharp.md @@ -0,0 +1,64 @@ +(odbc-csharp)= + +# C# + +Use the ODBC .NET Data Provider to access data from your C Sharp ADO\.NET +applications. The [.NET Framework Data Provider for ODBC] is available +through the [System.Data.Odbc] namespace. + +`example.csproj` +```xml + + + + Exe + net$(NETCoreAppMaximumVersion) + false + + + + + + + +``` +`example.cs` +```c# +using System; +using System.Data.Odbc; + +// Connect to database +string connection_string = "Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Uid=crate;Pwd=crate;Database=crate;MaxVarcharSize=1073741824"; +OdbcConnection connection = new OdbcConnection(connection_string); +connection.Open(); + +// Invoke query +OdbcCommand command = new OdbcCommand("SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 5", connection); +OdbcDataReader reader = command.ExecuteReader(); + +// Display results +while (reader.Read()) + Console.WriteLine($"{reader.GetString(0)}: {reader.GetInt32(1)}"); + +// Clean up +reader.Close(); +command.Dispose(); +connection.Close(); +``` + +```text +System.DllNotFoundException: Dependency unixODBC with minimum version 2.3.1 is required. +Unable to load shared library 'libodbc.2.dylib' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibodbc.2.dylib, 0x0001): tried: 'liblibodbc.2.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSliblibodbc.2.dylib' (no such file), '/usr/lib/liblibodbc.2.dylib' (no such file, not in dyld cache), 'liblibodbc.2.dylib' (no such file), '/usr/local/lib/liblibodbc.2.dylib' (no such file), '/usr/lib/liblibodbc.2.dylib' (no such file, not in dyld cache +``` + +```shell +sudo ln -s /usr/local/lib/libodbc.2.dylib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/9.0.10/ +``` + +```csharp +string connection_string = "Driver={PostgreSQL Unicode};Server=testcluster.cratedb.net;Port=5432;Sslmode=require;Uid=admin;Pwd=password"; +``` + + +[.NET Framework Data Provider for ODBC]: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/data-providers#net-framework-data-provider-for-odbc +[System.Data.Odbc]: https://learn.microsoft.com/en-us/dotnet/api/system.data.odbc diff --git a/docs/connect/odbc/index.md b/docs/connect/odbc/index.md index 2cdbf0ac..20b0d6ec 100644 --- a/docs/connect/odbc/index.md +++ b/docs/connect/odbc/index.md @@ -32,38 +32,9 @@ addresses the driver and database using a _Data Source Name (DSN)_. A few examples to demonstrate CrateDB connectivity with ODBC. -### C# - -Use the ODBC .NET Data Provider to access data from your C Sharp ADO\.NET -applications. The [.NET Framework Data Provider for ODBC] is available -through the [System.Data.Odbc] namespace. - -```c# -using System.Data.Odbc; - -// Connect to database -string connection_string = "ODBC;Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824"; -OdbcConnection connection = new OdbcConnection(connection_string); -connection.Open(); - -// Invoke query -OdbcCommand command = new OdbcCommand("SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 5", connection); -OdbcDataReader reader = command.ExecuteReader(); - -// Display results -while(reader.Read()) -{ - String mountain = reader.GetString(0); - int height = reader.GetInt32(1); - Console.Write(mountain + ": " + height); - Console.WriteLine(); -} - -// Clean up -reader.Close(); -command.Dispose(); -connection.Close(); -``` +:::{toctree} +csharp +::: ### Erlang @@ -189,11 +160,9 @@ cn.Close ``` -[.NET Framework Data Provider for ODBC]: https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/data-providers#net-framework-data-provider-for-odbc [connecting to PostgreSQL with pyodbc]: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-PostgreSQL [Erlang ODBC application]: https://www.erlang.org/docs/28/apps/odbc/odbc.html [psqlODBC with Visual Basic]: https://odbc.postgresql.org/howto-vb.html [pyodbc]: https://github.com/mkleehammer/pyodbc [pyodbc installation instructions]: https://github.com/mkleehammer/pyodbc/wiki/Install -[System.Data.Odbc]: https://learn.microsoft.com/en-us/dotnet/api/system.data.odbc [turbodbc]: https://turbodbc.readthedocs.io/ From 88990b01be99fb7544de6e036491b06bccc25de8 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Tue, 28 Oct 2025 18:31:05 +0100 Subject: [PATCH 11/17] fixup! Connect/ODBC: Rename auxiliary files --- docs/connect/odbc/install-dropdown.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/connect/odbc/install-dropdown.md b/docs/connect/odbc/install-dropdown.md index dcff99f3..3c8c4716 100644 --- a/docs/connect/odbc/install-dropdown.md +++ b/docs/connect/odbc/install-dropdown.md @@ -6,6 +6,6 @@ The PostgreSQL ODBC driver [psqlODBC] can be used to connect to CrateDB from ODBC environments. ::::{dropdown} Learn how to install and configure the PostgreSQL ODBC driver -:::{include} /connect/odbc/install-dropdown.md +:::{include} /connect/odbc/install.md ::: :::: From 8f344f2e6656a181f85e89b16f414b5b93b89f85 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Tue, 28 Oct 2025 19:22:30 +0100 Subject: [PATCH 12/17] Connect/ODBC: Use separate pages for each item --- docs/connect/odbc/csharp.md | 27 +++-- docs/connect/odbc/erlang.md | 32 ++++++ docs/connect/odbc/index.md | 138 ++------------------------ docs/connect/odbc/install-dropdown.md | 2 +- docs/connect/odbc/install.md | 4 +- docs/connect/odbc/python.md | 129 ++++++++++++++++++++++++ docs/connect/odbc/visualbasic.md | 55 ++++++++++ 7 files changed, 246 insertions(+), 141 deletions(-) create mode 100644 docs/connect/odbc/erlang.md create mode 100644 docs/connect/odbc/python.md create mode 100644 docs/connect/odbc/visualbasic.md diff --git a/docs/connect/odbc/csharp.md b/docs/connect/odbc/csharp.md index 36f9a809..5c983cca 100644 --- a/docs/connect/odbc/csharp.md +++ b/docs/connect/odbc/csharp.md @@ -1,11 +1,17 @@ (odbc-csharp)= -# C# +# ODBC with C# + +:::{rubric} About +::: Use the ODBC .NET Data Provider to access data from your C Sharp ADO\.NET applications. The [.NET Framework Data Provider for ODBC] is available through the [System.Data.Odbc] namespace. +:::{rubric} Synopsis +::: + `example.csproj` ```xml @@ -46,15 +52,24 @@ command.Dispose(); connection.Close(); ``` -```text -System.DllNotFoundException: Dependency unixODBC with minimum version 2.3.1 is required. -Unable to load shared library 'libodbc.2.dylib' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibodbc.2.dylib, 0x0001): tried: 'liblibodbc.2.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSliblibodbc.2.dylib' (no such file), '/usr/lib/liblibodbc.2.dylib' (no such file, not in dyld cache), 'liblibodbc.2.dylib' (no such file), '/usr/local/lib/liblibodbc.2.dylib' (no such file), '/usr/lib/liblibodbc.2.dylib' (no such file, not in dyld cache -``` +:::{rubric} Example +::: +Create the files `example.csproj` and `example.cs` including the synopsis code shared above. + +:::{include} ../_cratedb.md +::: +Invoke program. ```shell -sudo ln -s /usr/local/lib/libodbc.2.dylib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/9.0.10/ +dotnet run ``` +:::{rubric} CrateDB Cloud +::: + +For connecting to CrateDB Cloud, use the `Sslmode=require` parameter, +and replace username, password, and hostname with values matching +your environment. ```csharp string connection_string = "Driver={PostgreSQL Unicode};Server=testcluster.cratedb.net;Port=5432;Sslmode=require;Uid=admin;Pwd=password"; ``` diff --git a/docs/connect/odbc/erlang.md b/docs/connect/odbc/erlang.md new file mode 100644 index 00000000..404f7ee2 --- /dev/null +++ b/docs/connect/odbc/erlang.md @@ -0,0 +1,32 @@ +(odbc-erlang)= + +# ODBC with Erlang + +:::{rubric} About +::: + +The [Erlang ODBC application] provides an interface to communicate +with relational SQL-databases out of the box. + +:::{rubric} Synopsis +::: + +`example.erl` +```erlang +odbc:start(), +{ok, Ref} = odbc:connect("Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Uid=crate;Pwd=crate", []), +io:fwrite("~p~n", [odbc:sql_query(Ref, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3")]), +``` + +:::{rubric} Example +::: + +:::{todo} +Enable with the [Erlang patch](https://github.com/crate/cratedb-guide/pull/420). +``` +- {ref}`connect-erlang` +``` +::: + + +[Erlang ODBC application]: https://www.erlang.org/docs/28/apps/odbc/odbc.html diff --git a/docs/connect/odbc/index.md b/docs/connect/odbc/index.md index 20b0d6ec..4d9b3fba 100644 --- a/docs/connect/odbc/index.md +++ b/docs/connect/odbc/index.md @@ -30,139 +30,13 @@ addresses the driver and database using a _Data Source Name (DSN)_. ## Examples -A few examples to demonstrate CrateDB connectivity with ODBC. +A few examples that demonstrate CrateDB connectivity with ODBC. :::{toctree} -csharp -::: - -### Erlang - -The [Erlang ODBC application] provides an interface to communicate -with relational SQL-databases out of the box. - -```erlang -odbc:start(), -{ok, Ref} = odbc:connect("Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Uid=crate;Pwd=crate", []), -io:fwrite("~p~n", [odbc:sql_query(Ref, "SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 3")]), -``` +:maxdepth: 1 -:::{todo} -Enable with the [Erlang patch](https://github.com/crate/cratedb-guide/pull/420). -``` -- {ref}`connect-erlang` -``` +C# +Erlang +Python +Visual Basic ::: - -### Python (pyodbc) - -[pyodbc] is an open-source Python module that makes accessing ODBC databases -simple. It implements the DB API 2.0 specification and adds other Pythonic -convenience. For more information, please visit the -[pyodbc installation instructions] and [connecting to PostgreSQL with pyodbc]. - -```shell -pip install --upgrade pyodbc -``` -```python -import pyodbc - -# Connect to database -connection_string = \ - "Driver={PostgreSQL Unicode};Server=localhost;Port=5432;" \ - "Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824" -connection = pyodbc.connect(connection_string) - -# Invoke query -cursor = connection.cursor() -cursor.execute("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 5") - -# Display results -for row in cursor: - print(row) - -# Clean up -cursor.close() -connection.close() -``` - -### Python (turbodbc) - -[turbodbc] is a Python module to access relational databases via the Open -Database Connectivity (ODBC) interface. turbodbc offers built-in NumPy and -Apache Arrow for maximum performance. - -```shell -pip install --upgrade turbodbc -``` -```python -import turbodbc - -# Connect to database -connection_string = \ - "Driver={PostgreSQL Unicode};Server=localhost;Port=5432;" \ - "Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824" -connection = turbodbc.connect(connection_string) - -# Invoke query -cursor = connection.cursor() -cursor.execute("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 5") - -# Display results -for row in cursor: - print(row) - -# Clean up -cursor.close() -connection.close() -``` - -:::{todo} -Enable with the [Python patch](https://github.com/crate/cratedb-guide/pull/403). -``` -- {ref}`Turbodbc -- a high-performance ODBC library ` -``` -::: - -### Visual Basic - -:::{div} -See also [psqlODBC with Visual Basic]. Please navigate to the -[psqlODBC download site] to download and install the `psqlodbc` -driver for Windows systems. -::: - -```visualbasic -Dim cn as New ADODB.Connection -Dim rs as New ADODB.Recordset - -'Connect to database -cn.Open "Dsn=;" & _ - "Server=localhost;" & _ - "Port=5432;" & _ - "Uid=crate;" & _ - "Pwd=crate;" & _ - "Database=doc;" & _ - "MaxVarcharSize=1073741824;" - -'Invoke query -rs.Open "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 5", cn - -'Display results -While Not rs.EOF - Debug.Print rs!mountain & ": " & rs!height - rs.MoveNext -Wend - -'Clean up -rs.Close -cn.Close -``` - - -[connecting to PostgreSQL with pyodbc]: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-PostgreSQL -[Erlang ODBC application]: https://www.erlang.org/docs/28/apps/odbc/odbc.html -[psqlODBC with Visual Basic]: https://odbc.postgresql.org/howto-vb.html -[pyodbc]: https://github.com/mkleehammer/pyodbc -[pyodbc installation instructions]: https://github.com/mkleehammer/pyodbc/wiki/Install -[turbodbc]: https://turbodbc.readthedocs.io/ diff --git a/docs/connect/odbc/install-dropdown.md b/docs/connect/odbc/install-dropdown.md index 3c8c4716..79cbdad2 100644 --- a/docs/connect/odbc/install-dropdown.md +++ b/docs/connect/odbc/install-dropdown.md @@ -5,7 +5,7 @@ orphan: true The PostgreSQL ODBC driver [psqlODBC] can be used to connect to CrateDB from ODBC environments. -::::{dropdown} Learn how to install and configure the PostgreSQL ODBC driver +::::{dropdown} Install and configure the PostgreSQL ODBC driver :::{include} /connect/odbc/install.md ::: :::: diff --git a/docs/connect/odbc/install.md b/docs/connect/odbc/install.md index 857156b6..c84535b9 100644 --- a/docs/connect/odbc/install.md +++ b/docs/connect/odbc/install.md @@ -9,8 +9,8 @@ The PostgreSQL ODBC driver is called [psqlODBC]. :::::{tab-set} ::::{tab-item} Windows -On Windows, download the latest 64-bit driver (MSI file) -from the [psqlODBC download site] and install it. +Please navigate to the [psqlODBC download site] to download and install +the latest psqlODBC driver for Windows systems. [Installing PostgreSQL ODBC drivers on Windows] includes an illustrated walkthrough. :::: diff --git a/docs/connect/odbc/python.md b/docs/connect/odbc/python.md new file mode 100644 index 00000000..e66c1bce --- /dev/null +++ b/docs/connect/odbc/python.md @@ -0,0 +1,129 @@ +(odbc-python)= + +# ODBC with Python + +(odbc-pyodbc)= + +## pyodbc + +:::{rubric} About +::: + +[pyodbc] is an open-source Python module that makes accessing ODBC databases +simple. It implements the DB API 2.0 specification and adds other Pythonic +convenience. For more information, please visit the +[pyodbc installation instructions] and [connecting to PostgreSQL with pyodbc]. + +:::{rubric} Install +::: + +```shell +pip install --upgrade pyodbc +``` + +:::{rubric} Synopsis +::: + +`example.py` +```python +import pyodbc + +# Connect to database +connection_string = \ + "Driver={PostgreSQL Unicode};Server=localhost;Port=5432;" \ + "Uid=crate;Pwd=crate;Database=crate;MaxVarcharSize=1073741824" +connection = pyodbc.connect(connection_string) + +# Invoke query +cursor = connection.cursor() +cursor.execute("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 5") + +# Display results +for row in cursor: + print(row) + +# Clean up +cursor.close() +connection.close() +``` + +(odbc-turbodbc)= + +## turbodbc + +:::{rubric} About +::: + +[turbodbc] is a Python module to access relational databases via the Open +Database Connectivity (ODBC) interface. turbodbc offers built-in NumPy and +Apache Arrow for maximum performance. + +:::{rubric} Install +::: + +```shell +pip install --upgrade turbodbc +``` + +:::{rubric} Synopsis +::: + +`example.py` +```python +import turbodbc + +# Connect to database +connection_string = \ + "Driver={PostgreSQL Unicode};Server=localhost;Port=5432;" \ + "Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824" +connection = turbodbc.connect(connection_string) + +# Invoke query +cursor = connection.cursor() +cursor.execute("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 5") + +# Display results +for row in cursor: + print(row) + +# Clean up +cursor.close() +connection.close() +``` + +:::{todo} +Enable with the [Python patch](https://github.com/crate/cratedb-guide/pull/403). +``` +- {ref}`Turbodbc -- a high-performance ODBC library ` +``` +::: + +## Example + +Create the file `example.py` including the synopsis code shared above and +install the prerequisites like outlined above. + +:::{include} ../_cratedb.md +::: +Invoke program. +```shell +python example.py +``` + +## CrateDB Cloud + +For connecting to CrateDB Cloud, use the `Sslmode=require` parameter, +and replace username, password, and hostname with values matching +your environment. +```python +connection_string = \ + "Driver={PostgreSQL Unicode};Server=testcluster.cratedb.net;Port=5432;" \ + "Uid=admin;Pwd=password;Database=crate;MaxVarcharSize=1073741824" +``` + + + +[connecting to PostgreSQL with pyodbc]: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-PostgreSQL +[pyodbc]: https://github.com/mkleehammer/pyodbc +[pyodbc installation instructions]: https://github.com/mkleehammer/pyodbc/wiki/Install +[turbodbc]: https://turbodbc.readthedocs.io/ diff --git a/docs/connect/odbc/visualbasic.md b/docs/connect/odbc/visualbasic.md new file mode 100644 index 00000000..658bd26e --- /dev/null +++ b/docs/connect/odbc/visualbasic.md @@ -0,0 +1,55 @@ +(odbc-visualbasic)= + +# ODBC with Visual Basic + +:::{include} /_include/links.md +::: + +:::{rubric} About +::: + +Use ADODB to access data from your Visual Basic applications. + +:::{rubric} Install +::: + +:::{include} /connect/odbc/install-dropdown.md +::: + +:::{rubric} Synopsis +::: + +`example.vb` +```visualbasic +Dim cn as New ADODB.Connection +Dim rs as New ADODB.Recordset + +'Connect to database +cn.Open "Dsn=;" & _ + "Server=localhost;" & _ + "Port=5432;" & _ + "Uid=crate;" & _ + "Pwd=crate;" & _ + "Database=doc;" & _ + "MaxVarcharSize=1073741824;" + +'Invoke query +rs.Open "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 5", cn + +'Display results +While Not rs.EOF + Debug.Print rs!mountain & ": " & rs!height + rs.MoveNext +Wend + +'Clean up +rs.Close +cn.Close +``` + +:::{seealso} +Example: [psqlODBC with Visual Basic]. +::: + + +[psqlODBC with Visual Basic]: https://odbc.postgresql.org/howto-vb.html From e9886e2982aa77181ebf69873465159da70887a1 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Tue, 28 Oct 2025 19:24:43 +0100 Subject: [PATCH 13/17] Connect/ODBC: This and that --- docs/connect/odbc/configure.md | 3 +-- docs/connect/odbc/install.md | 4 ++-- docs/connect/odbc/python.md | 7 +++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/connect/odbc/configure.md b/docs/connect/odbc/configure.md index ad8ff792..643cc3b7 100644 --- a/docs/connect/odbc/configure.md +++ b/docs/connect/odbc/configure.md @@ -9,8 +9,7 @@ using the driver, like `Driver={PostgreSQL Unicode}`. :::{rubric} DSN configuration ::: -For connecting to the database using a DSN, -a typical connection string for CrateDB is: +When using a DSN, a typical connection string for CrateDB is: ```text Dsn=CrateDB ``` diff --git a/docs/connect/odbc/install.md b/docs/connect/odbc/install.md index c84535b9..17293114 100644 --- a/docs/connect/odbc/install.md +++ b/docs/connect/odbc/install.md @@ -36,7 +36,7 @@ Verify installation. ```shell odbcinst -q -d ``` -``` +```text [PostgreSQL ANSI] [PostgreSQL Unicode] ``` @@ -63,7 +63,7 @@ Verify installation. ```shell odbcinst -q -d ``` -``` +```text [PostgreSQL Unicode] ``` :::: diff --git a/docs/connect/odbc/python.md b/docs/connect/odbc/python.md index e66c1bce..06239232 100644 --- a/docs/connect/odbc/python.md +++ b/docs/connect/odbc/python.md @@ -54,10 +54,17 @@ connection.close() :::{rubric} About ::: +```{div} .float-right .text-right +[![Python turbodbc](https://github.com/crate/cratedb-examples/actions/workflows/lang-python-turbodbc.yml/badge.svg)](https://github.com/crate/cratedb-examples/actions/workflows/lang-python-turbodbc.yml) +``` + [turbodbc] is a Python module to access relational databases via the Open Database Connectivity (ODBC) interface. turbodbc offers built-in NumPy and Apache Arrow for maximum performance. +```{div} .clearfix +``` + :::{rubric} Install ::: From f03f86c1b6ac29d0d230fb86b75cc83d50e5814b Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Tue, 28 Oct 2025 20:02:49 +0100 Subject: [PATCH 14/17] Connect/ODBC: Implement suggestions by CodeRabbit --- docs/connect/odbc/csharp.md | 2 +- docs/connect/odbc/erlang.md | 2 +- docs/connect/odbc/python.md | 8 ++++---- docs/connect/odbc/visualbasic.md | 1 - 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/connect/odbc/csharp.md b/docs/connect/odbc/csharp.md index 5c983cca..7e3e998d 100644 --- a/docs/connect/odbc/csharp.md +++ b/docs/connect/odbc/csharp.md @@ -34,7 +34,7 @@ using System; using System.Data.Odbc; // Connect to database -string connection_string = "Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Uid=crate;Pwd=crate;Database=crate;MaxVarcharSize=1073741824"; +string connection_string = "Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Uid=crate;Pwd=crate;MaxVarcharSize=1073741824"; OdbcConnection connection = new OdbcConnection(connection_string); connection.Open(); diff --git a/docs/connect/odbc/erlang.md b/docs/connect/odbc/erlang.md index 404f7ee2..480161d8 100644 --- a/docs/connect/odbc/erlang.md +++ b/docs/connect/odbc/erlang.md @@ -23,7 +23,7 @@ io:fwrite("~p~n", [odbc:sql_query(Ref, "SELECT mountain, height FROM sys.summits :::{todo} Enable with the [Erlang patch](https://github.com/crate/cratedb-guide/pull/420). -``` +```md - {ref}`connect-erlang` ``` ::: diff --git a/docs/connect/odbc/python.md b/docs/connect/odbc/python.md index 06239232..ef8b24a3 100644 --- a/docs/connect/odbc/python.md +++ b/docs/connect/odbc/python.md @@ -31,7 +31,7 @@ import pyodbc # Connect to database connection_string = \ "Driver={PostgreSQL Unicode};Server=localhost;Port=5432;" \ - "Uid=crate;Pwd=crate;Database=crate;MaxVarcharSize=1073741824" + "Uid=crate;Pwd=crate;MaxVarcharSize=1073741824" connection = pyodbc.connect(connection_string) # Invoke query @@ -82,7 +82,7 @@ import turbodbc # Connect to database connection_string = \ "Driver={PostgreSQL Unicode};Server=localhost;Port=5432;" \ - "Uid=crate;Pwd=crate;Database=doc;MaxVarcharSize=1073741824" + "Uid=crate;Pwd=crate;MaxVarcharSize=1073741824" connection = turbodbc.connect(connection_string) # Invoke query @@ -100,7 +100,7 @@ connection.close() :::{todo} Enable with the [Python patch](https://github.com/crate/cratedb-guide/pull/403). -``` +```md - {ref}`Turbodbc -- a high-performance ODBC library ` ``` ::: @@ -125,7 +125,7 @@ your environment. ```python connection_string = \ "Driver={PostgreSQL Unicode};Server=testcluster.cratedb.net;Port=5432;" \ - "Uid=admin;Pwd=password;Database=crate;MaxVarcharSize=1073741824" + "Uid=admin;Pwd=password;MaxVarcharSize=1073741824" ``` diff --git a/docs/connect/odbc/visualbasic.md b/docs/connect/odbc/visualbasic.md index 658bd26e..0342b835 100644 --- a/docs/connect/odbc/visualbasic.md +++ b/docs/connect/odbc/visualbasic.md @@ -30,7 +30,6 @@ cn.Open "Dsn=;" & _ "Port=5432;" & _ "Uid=crate;" & _ "Pwd=crate;" & _ - "Database=doc;" & _ "MaxVarcharSize=1073741824;" 'Invoke query From 4371a06cf3320e4800e919fdf97fbe75e5e857ec Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Wed, 29 Oct 2025 20:26:30 +0100 Subject: [PATCH 15/17] Connect/ODBC: Refactor install widget details --- docs/_include/links.md | 4 ---- docs/connect/odbc/csharp.md | 6 ++++++ docs/connect/odbc/erlang.md | 6 ++++++ docs/connect/odbc/index.md | 5 ++++- docs/connect/odbc/install-dropdown.md | 4 +++- docs/connect/odbc/install.md | 5 +++++ docs/connect/odbc/links.md | 11 +++++++++++ docs/connect/odbc/python.md | 5 ++++- docs/connect/odbc/visualbasic.md | 3 --- 9 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 docs/connect/odbc/links.md diff --git a/docs/_include/links.md b/docs/_include/links.md index 66499c79..cbe34c74 100644 --- a/docs/_include/links.md +++ b/docs/_include/links.md @@ -67,11 +67,8 @@ [Multi-model Database]: https://cratedb.com/solutions/multi-model-database [nearest neighbor search]: https://en.wikipedia.org/wiki/Nearest_neighbor_search [Nested Data Structure]: https://cratedb.com/product/features/nested-data-structure -[ODBC]: https://en.wikipedia.org/wiki/Open_Database_Connectivity [PostgreSQL JDBC Driver]: https://jdbc.postgresql.org/ [PostgreSQL wire protocol]: https://www.postgresql.org/docs/current/protocol.html -[psqlODBC]: https://odbc.postgresql.org/ -[psqlODBC download site]: https://www.postgresql.org/ftp/odbc/releases/ [python-dbapi-by-example]: inv:crate-python:*:label#by-example [python-sqlalchemy-by-example]: inv:sqlalchemy-cratedb:*:label#by-example [query DSL based on JSON]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html @@ -84,6 +81,5 @@ [TF–IDF]: https://en.wikipedia.org/wiki/Tf%E2%80%93idf [timeseries-queries-and-visualization-colab]: https://colab.research.google.com/github/crate/cratedb-examples/blob/main/topic/timeseries/timeseries-queries-and-visualization.ipynb [timeseries-queries-and-visualization-github]: https://github.com/crate/cratedb-examples/blob/main/topic/timeseries/timeseries-queries-and-visualization.ipynb -[unixODBC]: https://www.unixodbc.org/ [Vector Database (Product)]: https://cratedb.com/solutions/vector-database [Vector Database]: https://en.wikipedia.org/wiki/Vector_database diff --git a/docs/connect/odbc/csharp.md b/docs/connect/odbc/csharp.md index 7e3e998d..d1962285 100644 --- a/docs/connect/odbc/csharp.md +++ b/docs/connect/odbc/csharp.md @@ -9,6 +9,12 @@ Use the ODBC .NET Data Provider to access data from your C Sharp ADO\.NET applications. The [.NET Framework Data Provider for ODBC] is available through the [System.Data.Odbc] namespace. +:::{rubric} Install +::: + +:::{include} /connect/odbc/install-dropdown.md +::: + :::{rubric} Synopsis ::: diff --git a/docs/connect/odbc/erlang.md b/docs/connect/odbc/erlang.md index 480161d8..481ba087 100644 --- a/docs/connect/odbc/erlang.md +++ b/docs/connect/odbc/erlang.md @@ -8,6 +8,12 @@ The [Erlang ODBC application] provides an interface to communicate with relational SQL-databases out of the box. +:::{rubric} Install +::: + +:::{include} /connect/odbc/install-dropdown.md +::: + :::{rubric} Synopsis ::: diff --git a/docs/connect/odbc/index.md b/docs/connect/odbc/index.md index 4d9b3fba..0ad8ac5e 100644 --- a/docs/connect/odbc/index.md +++ b/docs/connect/odbc/index.md @@ -11,7 +11,7 @@ Connect to CrateDB with ODBC. ::: :::{div} -Open Database Connectivity ([ODBC]) is a standard application programming +Open Database Connectivity ([ODBC][ODBC definition]) is a standard application programming interface (API) for accessing database management systems (DBMS), conceived to be independent of database systems and operating systems. The application uses ODBC functions through an _ODBC driver manager_ and @@ -40,3 +40,6 @@ Erlang Python Visual Basic ::: + + +[ODBC definition]: https://en.wikipedia.org/wiki/Open_Database_Connectivity diff --git a/docs/connect/odbc/install-dropdown.md b/docs/connect/odbc/install-dropdown.md index 79cbdad2..494c80e4 100644 --- a/docs/connect/odbc/install-dropdown.md +++ b/docs/connect/odbc/install-dropdown.md @@ -2,8 +2,10 @@ orphan: true --- -The PostgreSQL ODBC driver [psqlODBC] +:::{div} +The PostgreSQL ODBC driver can be used to connect to CrateDB from ODBC environments. +::: ::::{dropdown} Install and configure the PostgreSQL ODBC driver :::{include} /connect/odbc/install.md diff --git a/docs/connect/odbc/install.md b/docs/connect/odbc/install.md index 17293114..8fbad255 100644 --- a/docs/connect/odbc/install.md +++ b/docs/connect/odbc/install.md @@ -2,9 +2,14 @@ orphan: true --- +:::{include} /connect/odbc/links.md +::: + +:::{div} While Windows typically includes an ODBC driver manager, you can install the [unixODBC] driver manager on Linux and macOS systems. The PostgreSQL ODBC driver is called [psqlODBC]. +::: :::::{tab-set} diff --git a/docs/connect/odbc/links.md b/docs/connect/odbc/links.md new file mode 100644 index 00000000..914ef147 --- /dev/null +++ b/docs/connect/odbc/links.md @@ -0,0 +1,11 @@ +--- +orphan: true +--- + + + + +[ODBC]: https://en.wikipedia.org/wiki/Open_Database_Connectivity +[psqlODBC]: https://odbc.postgresql.org/ +[psqlODBC download site]: https://www.postgresql.org/ftp/odbc/releases/ +[unixODBC]: https://www.unixodbc.org/ diff --git a/docs/connect/odbc/python.md b/docs/connect/odbc/python.md index ef8b24a3..173392e0 100644 --- a/docs/connect/odbc/python.md +++ b/docs/connect/odbc/python.md @@ -17,6 +17,10 @@ convenience. For more information, please visit the :::{rubric} Install ::: +:::{include} /connect/odbc/install-dropdown.md +::: + +Install the required Python package. ```shell pip install --upgrade pyodbc ``` @@ -129,7 +133,6 @@ connection_string = \ ``` - [connecting to PostgreSQL with pyodbc]: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-PostgreSQL [pyodbc]: https://github.com/mkleehammer/pyodbc [pyodbc installation instructions]: https://github.com/mkleehammer/pyodbc/wiki/Install diff --git a/docs/connect/odbc/visualbasic.md b/docs/connect/odbc/visualbasic.md index 0342b835..4c1fa119 100644 --- a/docs/connect/odbc/visualbasic.md +++ b/docs/connect/odbc/visualbasic.md @@ -2,9 +2,6 @@ # ODBC with Visual Basic -:::{include} /_include/links.md -::: - :::{rubric} About ::: From 53c46e4188b12a934e00a603fbcba1f23dccb33c Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Wed, 29 Oct 2025 21:09:07 +0100 Subject: [PATCH 16/17] Connect/ODBC: Implement suggestions by CodeRabbit --- docs/connect/odbc/csharp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/connect/odbc/csharp.md b/docs/connect/odbc/csharp.md index d1962285..384bef72 100644 --- a/docs/connect/odbc/csharp.md +++ b/docs/connect/odbc/csharp.md @@ -29,7 +29,7 @@ through the [System.Data.Odbc] namespace. - + From a22281dd7f2cdc623fe1579f12970b85a669b4e4 Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Wed, 29 Oct 2025 21:17:01 +0100 Subject: [PATCH 17/17] Connect/ODBC: Implement suggestions by CodeRabbit --- docs/connect/odbc/csharp.md | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/docs/connect/odbc/csharp.md b/docs/connect/odbc/csharp.md index 384bef72..0f9a849f 100644 --- a/docs/connect/odbc/csharp.md +++ b/docs/connect/odbc/csharp.md @@ -41,21 +41,19 @@ using System.Data.Odbc; // Connect to database string connection_string = "Driver={PostgreSQL Unicode};Server=localhost;Port=5432;Uid=crate;Pwd=crate;MaxVarcharSize=1073741824"; -OdbcConnection connection = new OdbcConnection(connection_string); -connection.Open(); - -// Invoke query -OdbcCommand command = new OdbcCommand("SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 5", connection); -OdbcDataReader reader = command.ExecuteReader(); - -// Display results -while (reader.Read()) - Console.WriteLine($"{reader.GetString(0)}: {reader.GetInt32(1)}"); - -// Clean up -reader.Close(); -command.Dispose(); -connection.Close(); +using (OdbcConnection connection = new OdbcConnection(connection_string)) +{ + connection.Open(); + + // Invoke query + using (OdbcCommand command = new OdbcCommand("SELECT mountain, height FROM sys.summits ORDER BY height DESC LIMIT 5", connection)) + using (OdbcDataReader reader = command.ExecuteReader()) + { + // Display results + while (reader.Read()) + Console.WriteLine($"{reader.GetString(0)}: {reader.GetInt32(1)}"); + } +} ``` :::{rubric} Example