author | František Kučera <franta-hg@frantovo.cz> |
Tue, 04 Aug 2020 00:59:32 +0200 | |
branch | v_0 |
changeset 313 | a43265235e5a |
parent 300 | b9bd0f06b4a1 |
child 324 | 3cbce8bb28c3 |
permissions | -rw-r--r-- |
297
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
<stránka |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana" |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro"> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
<nadpis>Accessing SQLite, PostgreSQL and MySQL through ODBC</nadpis> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
<perex>use various DBMS for SQL transformations or data access</perex> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
<m:pořadí-příkladu>04200</m:pořadí-příkladu> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
<text xmlns="http://www.w3.org/1999/xhtml"> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
Since <m:a href="release-v0.16">v0.16</m:a> the <code>relpipe-tr-sql</code> module |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
uses the ODBC abstraction layer and thus we can access data in any DBMS (database management system). |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
Our program depends only on the generic API and the driver for particular DBMS is loaded dynamically depending on the configuration. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
<blockquote> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
19 |
ODBC (Open Database Connectivity) is an industry standard and provides API for accessing a DBMS. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
In late 80s several vendors (mostly from the Unix and database communities) established the SQL Access Group (SAG) |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
and then specified the Call Level Interface (CLI). ODBC, which is based on CLI, was published in early 90s. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
ODBC is available on many operating systems and there are at least two free software implementations: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
<a href="http://www.unixodbc.org/">unixODBC</a> and <a href="http://www.iodbc.org/">iODBC</a>. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
</blockquote> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
<p>For more information see the <m:a href="release-v0.16">v0.16 release notes</m:a>.</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
28 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
<h2>General concepts and configuration</h2> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
<strong>ODBC</strong>: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
the API consisting of C functions; see the files <code>sql.h</code> and <code>sqlext.h</code> e.g. in unixODBC. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
<strong>Database driver</strong>: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
37 |
a shared library (an <code>.so</code> file) |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
that implements the API and connects to particular DBMS (SQLite, PostgreSQL, MySQL, MariaDB, Firebird etc.); |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
is usually provided by the authors of given DBMS, sometimes writen by a third-party |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
<strong>Client</strong>: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
a program that calls the API in order to access a database; our <code>relpipe-tr-sql</code> is a client |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
<strong>Data Source Name (DSN)</strong>: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
the name of a preconfigured data source – when connecting, we need to know only the DSN – all parameters |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
48 |
(like server name, user name, password etc.) can be then looked-up in the configuration |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
49 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
50 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
51 |
<strong>Connection string</strong>: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
52 |
a text string consisting of serialized parameters needed for connecting |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
– we can specify all parameters ad-hoc in the connection string without creating any permanent configuration; |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
a connection string can also refer to a DSN and add or override some parameters |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
55 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
56 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
57 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
58 |
There is some global configuration in the <code>/etc</code> directory. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
In <code>/etc/odbcinst.ini</code> we can a find list of ODBC drivers. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
Thanks to it, we can refer to a driver by its name (e.g. <code>SQLite3</code>) |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
instead of the path to the shared library (e.g. <code>/usr/lib/x86_64-linux-gnu/odbc/libsqlite3odbc.so</code>). |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
62 |
In <code>/etc/odbc.ini</code> we can find a list of global (for given computer) data sources. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
63 |
It is uncommon to put complete configurations in this file, because anyone would be able to read the passwords, |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
64 |
but we can provide here just a <i>template</i> with public parameters like server name, port etc. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
65 |
and user will supply his own user name and password in the connection string or in his personal configuration file. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
66 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
67 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
68 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
69 |
The <code>~/.odbc.ini</code> contains personal configuration of given user. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
70 |
There are usually data sources including the passwords. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
71 |
Thus this file must be readable only by given user (<code>chmod 600 ~/.odbc.ini</code>). |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
72 |
Providing passwords in connection strings passed as CLI arguments is not a good practice due to security reasons: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
73 |
by default it is stored in the shell history and it is also visible to other users of the same machine in the list of running processes. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
74 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
75 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
76 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
77 |
The section name – in the <code>[]</code> brackets – is the DSN. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
78 |
Then there are parameters in form of <code>key=value</code> on each line. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
79 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
80 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
81 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
82 |
<h2>CLI options</h2> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
83 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
84 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
85 |
The <code>relpipe-tr-sql</code> and <code>relpipe-in-sql</code> support these relevant CLI options: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
86 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
87 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
88 |
<ul> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
89 |
<li> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
90 |
<code>--list-data-sources</code>: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
91 |
lists available (configured) data sources in relational format (so we pipe the output to some output filter e.g. to <code>relpipe-out-tabular</code>) |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
92 |
</li> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
93 |
<li> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
94 |
<code>--data-source-name</code>: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
95 |
specifies the DSN of a configured data source |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
96 |
</li> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
97 |
<li> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
98 |
<code>--data-source-string</code>: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
99 |
specifies the connections string for ad-hoc connection without need of any configuration |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
100 |
</li> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
101 |
</ul> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
102 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
103 |
<pre><![CDATA[$ relpipe-tr-sql --list-data-sources | relpipe-out-tabular |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
104 |
data_source: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
105 |
╭───────────────┬──────────────────────╮ |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
106 |
│ name (string) │ description (string) │ |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
107 |
├───────────────┼──────────────────────┤ |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
108 |
│ sqlite-memory │ SQLite3 │ |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
109 |
│ relpipe │ PostgreSQL Unicode │ |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
110 |
╰───────────────┴──────────────────────╯ |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
111 |
Record count: 2]]></pre> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
112 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
113 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
114 |
Because output of this command is relational, we can further process it in our relational pipelines. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
115 |
This output is also used for the Bash-completion for suggesting the DSN. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
116 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
117 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
118 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
119 |
If neither <code>--data-source-name</code> nor <code>--data-source-string</code> option is provided, |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
120 |
a temporary in-memory SQLite database is used as default. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
121 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
122 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
123 |
<h2>SQLite</h2> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
124 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
125 |
<p>In Debian GNU/Linux and similar distributions we can install <a href="https://sqlite.org/">SQLite</a> ODBC driver by this command:</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
126 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
127 |
<pre>apt install libsqliteodbc</pre> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
128 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
129 |
<p>Which also installs the SQLite library that is all we need (because SQLite is a <i>serverless and self-contained</i> database).</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
130 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
131 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
132 |
Then we can use the default in-memory temporary database or specify the connection string ad-hoc, |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
133 |
<m:a href="examples-in-sql-selecting-existing-database">access existing SQLite databases</m:a> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
134 |
or <m:a href="examples-in-filesystem-tr-sql-indexing">create new ones</m:a> – e.g. this command: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
135 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
136 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
137 |
<pre>… | relpipe-tr-sql --data-source-string 'Driver=SQLite3;Database=file:MyDatabase.sqlite'</pre> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
138 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
139 |
<p>will create the <code>MyDatabase.sqlite</code> file and fill it with relations that came from STDIN.</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
140 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
141 |
<p>For frequently used databases it is convenient to configure a data source in <code>~/.odbc.ini</code>:</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
142 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
143 |
<m:pre jazyk="ini"><![CDATA[[MyDatabase] |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
144 |
Driver=SQLite3 |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
145 |
Database=file:/home/hacker/MyDatabase.sqlite]]></m:pre> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
146 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
147 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
148 |
and then connect to it simply using <code>--data-source-name MyDatabase</code> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
149 |
(both the option and the name will be suggested by Bash-completion). |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
150 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
151 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
152 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
153 |
The <a href="http://www.ch-werner.de/sqliteodbc/html/index.html">SQLite ODBC driver</a> supports several parameters that are described in its documentation. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
154 |
One of them is <code>LoadExt</code> that loads SQLite extensions: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
155 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
156 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
157 |
<m:pre jazyk="ini"><![CDATA[LoadExt=/home/hacker/libdemo.so]]></m:pre> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
158 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
159 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
160 |
So we can write our own SQLite extension with custom functions or other features |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
161 |
(<a href="https://blog.frantovo.cz/c/383/Komplexita%20softwaru%3A%20%C5%98e%C5%A1en%C3%AD%20a%C2%A0prevence#toc_sqlite">example</a>) |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
162 |
or chose some existing one and load it into the SQLite connected through ODBC. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
163 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
164 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
165 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
166 |
<h2>PostgreSQL</h2> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
167 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
168 |
<p>In Debian GNU/Linux and similar distributions we can install <a href="https://www.postgresql.org/">PostgreSQL</a> ODBC driver by this command:</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
169 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
170 |
<pre>apt install odbc-postgresql</pre> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
171 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
172 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
173 |
PostgreSQL is very powerful DBMS (probably most advanced free software relational database system) |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
174 |
and utilizes the client-server architecture. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
175 |
This means that we also needs a server (can be also installed through <code>apt</code> like the driver). |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
176 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
177 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
178 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
179 |
Once we have a server – remote or local – we need to create a user (role). |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
180 |
For SQL transformations we configure a dedicated role that has no persistent schema and uses the temporary one as default, |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
181 |
which means that all relations we create are lost at the end of the session (when the <code>relpipe-tr-sql</code> command finishes), |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
182 |
thus it behaves very similar to the SQLite in-memory database. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
183 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
184 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
185 |
<m:pre jazyk="sql"><![CDATA[CREATE USER relpipe WITH PASSWORD 'someSecretPassword'; |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
186 |
ALTER ROLE relpipe SET search_path TO 'pg_temp';]]></m:pre> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
187 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
188 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
189 |
And then we <a href="https://odbc.postgresql.org/docs/config.html">configure</a> the ODBC data source: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
190 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
191 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
192 |
<m:pre jazyk="ini"><![CDATA[[postgresql-temp] |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
193 |
Driver=PostgreSQL Unicode |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
194 |
Database=postgres |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
195 |
Servername=localhost |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
196 |
Port=5432 |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
197 |
Username=relpipe |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
198 |
Password=someSecretPassword]]></m:pre> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
199 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
200 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
201 |
Now we can use advanced PostgreSQL features for transforming data in our pipelines. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
202 |
We can also configure a DSN for another database that contains some useful data and other database objects, |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
203 |
call existing business functions installed in such database, load data to or from this DB etc. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
204 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
205 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
206 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
207 |
<h2>MySQL</h2> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
208 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
209 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
210 |
If the <code>libmyodbc</code> package is missing in our distribution, |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
211 |
the ODBC driver for <a href="https://dev.mysql.com/downloads/connector/odbc/">MySQL</a> can be downloaded from their website. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
212 |
We can get a binary package (<code>.deb</code>, <code>.rpm</code> etc.) or source code. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
213 |
If we are compiling from sources, we do something like this: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
214 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
215 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
216 |
<m:pre jazyk="bash"><![CDATA[cd mysql-connector-odbc-*-src/ |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
217 |
mkdir build |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
218 |
cd build |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
219 |
cmake ../ -DWITH_UNIXODBC=1 |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
220 |
make]]></m:pre> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
221 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
222 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
223 |
We should use the driver in the same or similar version as the MySQL client library installed on our system. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
224 |
For example 8.x driver will not work with 5.x library. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
225 |
Successful compilation results in <code>libmyodbc*.so</code> files. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
226 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
227 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
228 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
229 |
Like PostgreSQL, also MySQL is a client-server, |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
230 |
so we need a server where we create a database and some user account. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
231 |
As root through the <code>mysql mysql</code> command we execute: |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
232 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
233 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
234 |
<m:pre jazyk="sql"><![CDATA[CREATE DATABASE relpipe CHARACTER SET = utf8; |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
235 |
CREATE USER 'relpipe'@'localhost' IDENTIFIED BY 'someSecretPassword'; |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
236 |
GRANT ALL PRIVILEGES ON relpipe.* TO 'relpipe'@'localhost'; |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
237 |
FLUSH PRIVILEGES;]]></m:pre> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
238 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
239 |
<p>As a normal user we add new data source to our <code>~/.odbc.ini</code> file:</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
240 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
241 |
<m:pre jazyk="ini"><![CDATA[[mysql-relpipe-localhost] |
300
b9bd0f06b4a1
MySQL seems to works well even with libmyodbc5a.so not only libmyodbc5w.so ODBC driver
František Kučera <franta-hg@frantovo.cz>
parents:
297
diff
changeset
|
242 |
Driver=/home/hacker/src/mysql/build/lib/libmyodbc5a.so |
297
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
243 |
Server=localhost |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
244 |
Port=3306 |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
245 |
Socket=/var/run/mysqld/mysqld.sock |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
246 |
User=relpipe |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
247 |
Password=someSecretPassword |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
248 |
Database=relpipe |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
249 |
InitStmt=SET SQL_MODE=ANSI_QUOTES; |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
250 |
Charset=utf8]]></m:pre> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
251 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
252 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
253 |
See that we have compiled the ODBC driver in our home directory |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
254 |
and even without installing it anywhere and registering it in the <code>/etc/odbcinst.ini</code> file, |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
255 |
we can simply refer to the <code>.so</code> file from our <code>~/.odbc.ini</code>. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
256 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
257 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
258 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
259 |
If we set <code>Server=localhost</code>, the client-server communication does not go through TCP/IP |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
260 |
but rather through the unix domain socket specified in the <code>Socket</code> field. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
261 |
If we set <code>Server=127.0.0.1</code> or some remote IP address or domain name, the communication goes through TCP/IP on given port. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
262 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
263 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
264 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
265 |
The <code>SET SQL_MODE=ANSI_QUOTES;</code> init statement is important, |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
266 |
because it tells MySQL server that it should support standard SQL "quoted" identifiers |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
267 |
instead of that `weird` MySQL style. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
268 |
We use the standard SQL while creating the tables. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
269 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
270 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
271 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
272 |
There are many other parameters, quite well |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
273 |
<a href="https://dev.mysql.com/doc/connector-odbc/en/connector-odbc-configuration-connection-parameters.html">documented</a>. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
274 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
275 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
276 |
<p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
277 |
Now we can use MySQL as the <i>SQL engine</i> for transformations in our pipelines |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
278 |
and we can also access existing MySQL databases, |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
279 |
load data to and from them |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
280 |
or call functions and procedures installed on the server. |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
281 |
</p> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
282 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
283 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
284 |
</text> |
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
285 |
|
192b0059a6c4
Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
286 |
</stránka> |