relpipe-data/examples-tr-sqlite-custom-version.xml
author František Kučera <franta-hg@frantovo.cz>
Sat, 06 Jun 2020 01:57:24 +0200
branchv_0
changeset 297 192b0059a6c4
parent 286 37c50bb1f36f
permissions -rw-r--r--
Release v0.16 – ODBC in SQL + JACK MIDI
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
285
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
<stránka
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
	xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
	
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
	<nadpis>Using custom version of SQLite (LD_PRELOAD)</nadpis>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
	<perex>switch to a newer or modified version of library using a little hack</perex>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
	<m:pořadí-příkladu>03600</m:pořadí-příkladu>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
	<text xmlns="http://www.w3.org/1999/xhtml">
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
		<p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
			One of reasons why we prefer shared libraries (<code>.so</code>) rather than static linking,
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
			is that shared libraries are much more hacker-friendly and allow the user switching to a newer or modified library without recompiling the program.
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
		</p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
		<p>
297
192b0059a6c4 Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents: 286
diff changeset
    17
			<strong>
192b0059a6c4 Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents: 286
diff changeset
    18
				n.b. This method is obsolete since <m:a href="release-v0.16">v0.16</m:a> that does not use SQLite library directly 
192b0059a6c4 Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents: 286
diff changeset
    19
				and uses arbitrary database driver (including SQLite one) through an abstraction layer (ODBC).
192b0059a6c4 Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents: 286
diff changeset
    20
				This article is still valid as an example of the LD_PRELOAD hack and can be used with older versions of <m:name/>.
192b0059a6c4 Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents: 286
diff changeset
    21
				Since v0.16 we can easily replace whole ODBC driver (and thus use also different version of the SQLite),
192b0059a6c4 Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents: 286
diff changeset
    22
				there is no need for LD_PRELOAD hacking
192b0059a6c4 Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents: 286
diff changeset
    23
				– we can just configure desired driver (the <code>.so</code> file) in the INI file or ad-hoc in the connection string.
192b0059a6c4 Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents: 286
diff changeset
    24
			</strong>
192b0059a6c4 Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents: 286
diff changeset
    25
		</p>
192b0059a6c4 Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents: 286
diff changeset
    26
		
192b0059a6c4 Release v0.16 – ODBC in SQL + JACK MIDI
František Kučera <franta-hg@frantovo.cz>
parents: 286
diff changeset
    27
		<p>
285
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
			By default, <code>relpipe-tr-sql</code> links to the SQLite library available in our distribution (e.g. 3.22).
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
			As we can check:
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
		</p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
		<m:pre jazyk="text"><![CDATA[$ ldd $(which relpipe-tr-sql) | grep sqlite
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
    libsqlite3.so.0 => /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007f4c73888000)]]></m:pre>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
	
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
		<p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
			But what if we want to use some new features like <a href="https://www.sqlite.org/windowfunctions.html">window functions</a> that are available in later (3.25) library versions?
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
			Or what if we want to add our own custom modifications to this library?
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
			Do we have to recompile the <m:name/> tools?
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
		</p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		<p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
			No, we can just plug the new/modified library in and use it instead of the distribution one.
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
		</p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		<h2>Download and compile SQLite library</h2>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		<p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
			The build process of SQLite should be straightforward:
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		</p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
		<m:pre jazyk="bash"><![CDATA[
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
# Switch to the user for such experiments (optional but recommended):
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
su - hacker
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
# Create directories, download and extract sources:
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
mkdir -p ~/src/sqlite
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
cd ~/src/sqlite
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
wget https://www.sqlite.org/2019/sqlite-autoconf-3300100.tar.gz
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
tar xvzf sqlite-autoconf-3300100.tar.gz
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
cd sqlite-autoconf-3300100/
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
			
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
# Optional: do some changes to the source code
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
# Build SQLite:
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
./configure
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
make
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
# Test it:
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
echo "SELECT 'hello world'" | ./sqlite3
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
]]></m:pre>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
		<p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
			The desired shared libraries are located in the <code>.libs</code> directory.
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
		</p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
		<h2>Use this library in the <m:name/> tools</h2>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
		<p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
			We have already build/installed <code>relpipe-tr-sql</code> which is linked to the SQLite library available in our distribution.
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
			Then switching to a custom version of the library is very easy – we just need to set an environment variable.
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
		</p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    83
		<m:pre jazyk="bash"><![CDATA[export LD_PRELOAD=~/src/sqlite/sqlite-autoconf-3300100/.libs/libsqlite3.so.0]]></m:pre>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
		<p>And then <code>relpipe-tr-sql</code> will use the newer library version as we can check:</p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
		<m:pre jazyk="text"><![CDATA[$ ldd $(which relpipe-tr-sql) | grep sqlite
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
    /home/hacker/src/sqlite/sqlite-autoconf-3300100/.libs/libsqlite3.so.0 (0x00007f9979578000)]]></m:pre>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
		<p>Now we can use new features like window functions:</p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
		<m:pre jazyk="bash"><![CDATA[relpipe-in-fstab \
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
	| relpipe-tr-sql \
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
		--relation "fs_types" "
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    95
			SELECT 
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    96
				mount_point, 
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    97
				type, 
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    98
				count(*) OVER (PARTITION BY type) AS same_type_count 
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    99
			FROM fstab" \
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   100
	| relpipe-out-tabular]]></m:pre>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   101
	
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   102
		<p>And get result like this one:</p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   103
		<m:pre jazyk="text"><![CDATA[fstab:
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   104
 ╭──────────────────────┬───────────────┬──────────────────────────╮
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   105
 │ mount_point (string) │ type (string) │ same_type_count (string) │
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   106
 ├──────────────────────┼───────────────┼──────────────────────────┤
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   107
 │ /home                │ btrfs         │ 1                        │
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   108
 │ /                    │ ext4          │ 2                        │
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   109
 │ /mnt/data            │ ext4          │ 2                        │
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   110
 │ /media/cdrom0        │ udf,iso9660   │ 1                        │
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   111
 │ /mnt/private         │ xfs           │ 1                        │
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   112
 ╰──────────────────────┴───────────────┴──────────────────────────╯
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   113
Record count: 5]]></m:pre>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   114
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   115
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   116
		<p>That would not be possible with older versions of the SQLite library – as we can check by unsetting the <code>LD_PRELOAD</code> variable:</p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   117
		<m:pre jazyk="bash"><![CDATA[unset LD_PRELOAD]]></m:pre>
286
37c50bb1f36f examples: Using custom version of SQLite (LD_PRELOAD), alias instead of global variable
František Kučera <franta-hg@frantovo.cz>
parents: 285
diff changeset
   118
		<p>Which returns us to the previous state where SQLite from our distribution was used. And then calling the same SQL query leads to an error.</p>
285
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   119
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   120
		<p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   121
			The <code>LD_PRELOAD</code> hack can be used with any other software – it is not specific to <m:name/>.
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   122
			Another example is the <a href="https://mouse.globalcode.info/v_0/spacenav-hack.xhtml">Spacenav Hack</a>  which bridges/translates two APIs of a library.
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   123
		</p>
286
37c50bb1f36f examples: Using custom version of SQLite (LD_PRELOAD), alias instead of global variable
František Kučera <franta-hg@frantovo.cz>
parents: 285
diff changeset
   124
		
37c50bb1f36f examples: Using custom version of SQLite (LD_PRELOAD), alias instead of global variable
František Kučera <franta-hg@frantovo.cz>
parents: 285
diff changeset
   125
		<p>
37c50bb1f36f examples: Using custom version of SQLite (LD_PRELOAD), alias instead of global variable
František Kučera <franta-hg@frantovo.cz>
parents: 285
diff changeset
   126
			n.b. if we do <code>export LD_PRELOAD</code> it will affect all programs started from given shell session
37c50bb1f36f examples: Using custom version of SQLite (LD_PRELOAD), alias instead of global variable
František Kučera <franta-hg@frantovo.cz>
parents: 285
diff changeset
   127
			and if we even put it in our <code>.bashrc</code>, it will affect all Bash sessions started later and programs started from them.
37c50bb1f36f examples: Using custom version of SQLite (LD_PRELOAD), alias instead of global variable
František Kučera <franta-hg@frantovo.cz>
parents: 285
diff changeset
   128
			Which might not be a desired behavior. So sometimes it is better to set the <code>LD_PRELOAD</code> variable only for a single command, not globally.
37c50bb1f36f examples: Using custom version of SQLite (LD_PRELOAD), alias instead of global variable
František Kučera <franta-hg@frantovo.cz>
parents: 285
diff changeset
   129
			This can be done through a custom wrapper script or an alias:
37c50bb1f36f examples: Using custom version of SQLite (LD_PRELOAD), alias instead of global variable
František Kučera <franta-hg@frantovo.cz>
parents: 285
diff changeset
   130
		</p>
37c50bb1f36f examples: Using custom version of SQLite (LD_PRELOAD), alias instead of global variable
František Kučera <franta-hg@frantovo.cz>
parents: 285
diff changeset
   131
		<m:pre jazyk="bash"><![CDATA[alias relpipe-tr-sql='LD_PRELOAD=~/src/sqlite/sqlite-autoconf-3300100/.libs/libsqlite3.so.0 relpipe-tr-sql']]></m:pre>
37c50bb1f36f examples: Using custom version of SQLite (LD_PRELOAD), alias instead of global variable
František Kučera <franta-hg@frantovo.cz>
parents: 285
diff changeset
   132
		<p>We can safely put this this line into our <code>.bashrc</code> without affecting any other software.</p>
285
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   133
				
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   134
		<h2>ABI compatibility</h2>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   135
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   136
		<p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   137
			The prerequisite for such easy library swapping is the compatibility of the ABI (application binary interface).
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   138
			It means that we can change the library internals (the SQL language features in this case) but we must retain the compiled representation of the C functions compatible
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   139
			so the both parts (the library and the program) will still fit together. We can not e.g. remove a C function.
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   140
			And we should also not do any incompatible changes on the semantic level (although it could still link together, it would lead to unwanted results).
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   141
		</p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   142
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   143
		<p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   144
			In case of libraries that follow the <a href="https://semver.org/">Semantic versioning</a> (as required by <a href="https://sane-software.globalcode.info/">Sane software manifesto</a>) for their ABI,
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   145
			it is easy to say which versions are compatible and which would require recompiling the program or even changing its source code.
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   146
			If the <em>patch</em> or <em>minor</em> version numbers were changed, the libraries could be swapped this way.
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   147
			If the <em>major</em> version was changed, it would be probably necessary to also modify the software that uses this library.
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   148
		</p>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   149
		
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   150
	</text>
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   151
a6df8cac399e examples: Using custom version of SQLite (LD_PRELOAD)
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   152
</stránka>