mirror of
https://gitea.invidious.io/iv-org/shard-crystal-sqlite3.git
synced 2024-08-15 00:53:26 +00:00
Docs on how to compile and link SQLite
This commit is contained in:
parent
985bfa2d7c
commit
82758c7890
2 changed files with 88 additions and 0 deletions
|
@ -48,3 +48,7 @@ end
|
|||
|
||||
* `Time` is implemented as `TEXT` column using `SQLite3::DATE_FORMAT_SUBSECOND` format (or `SQLite3::DATE_FORMAT_SECOND` if the text does not contain a dot).
|
||||
* `Bool` is implemented as `INT` column mapping `0`/`1` values.
|
||||
|
||||
## Guides
|
||||
|
||||
- [Compile and link SQLite](compile_and_link_sqlite.md)
|
||||
|
|
84
compile_and_link_sqlite.md
Normal file
84
compile_and_link_sqlite.md
Normal file
|
@ -0,0 +1,84 @@
|
|||
# How to Compile And Link SQLite
|
||||
|
||||
|
||||
## Install Prerequisites (Ubuntu)
|
||||
|
||||
On Ubuntu you will need build-essential installed at a minimum.
|
||||
|
||||
```sh
|
||||
sudo apt update
|
||||
sudo apt install build-essential
|
||||
```
|
||||
|
||||
|
||||
## Download And Extract The Source Code
|
||||
|
||||
Source code for the latest release can be downloaded from the [SQLite Download Page](https://sqlite.org/download.html).
|
||||
Look for "C source code as an amalgamation", It should be the first one on the page.
|
||||
|
||||
```sh
|
||||
wget https://sqlite.org/2021/sqlite-amalgamation-3370000.zip
|
||||
unzip sqlite-amalgamation-3370000.zip
|
||||
cd sqlite-amalgamation-3370000
|
||||
```
|
||||
|
||||
|
||||
## Compile SQLite
|
||||
|
||||
Compile the sqlite command.
|
||||
|
||||
```sh
|
||||
gcc shell.c sqlite3.c -lpthread -ldl -o sqlite3
|
||||
./sqlite3 --version
|
||||
```
|
||||
|
||||
Compile libsqlite.
|
||||
|
||||
```sh
|
||||
gcc -lpthread -ldl -shared -o libsqlite3.so.0 -fPIC sqlite3.c
|
||||
```
|
||||
|
||||
## Using The New Version of SQLite
|
||||
|
||||
The path to libsqlite can be specified at runtime with "LD_LIBRARY_PATH".
|
||||
|
||||
```sh
|
||||
# Crystal run
|
||||
LD_LIBRARY_PATH=../sqlite-amalgamation-3370000 crystal run src/app.cr
|
||||
|
||||
# This way will allow specifying the library location at runtime if it is different from the system default.
|
||||
crystal build --release --link-flags -L"$(realpath ../sqlite-amalgamation-3370000/libsqlite3.so.0)" src/app.cr
|
||||
LD_LIBRARY_PATH=../sqlite-amalgamation-3370000 ./app
|
||||
|
||||
# ldd can be used to see which libsqlite is being linked
|
||||
LD_LIBRARY_PATH=../sqlite-amalgamation-3370000 ldd ./app
|
||||
```
|
||||
|
||||
Or the absolute path to libsqlite can be specified at compile time.
|
||||
|
||||
```sh
|
||||
crystal run --link-flags "$(realpath ../sqlite-amalgamation-3370000/libsqlite3.so.0)" src/app.cr
|
||||
|
||||
# This will create a version that only works if libsqlite in the excact same location as when it was compiled.
|
||||
crystal build --release --link-flags "$(realpath ../sqlite-amalgamation-3370000/libsqlite3.so.0)" src/app.cr
|
||||
./app
|
||||
|
||||
# Use ldd to see which libsqlite is being linked
|
||||
ldd ./app
|
||||
```
|
||||
|
||||
|
||||
## Check SQLite Version From Crystal
|
||||
|
||||
To check which version of SQLite is being used from Crystal.
|
||||
|
||||
```crystal
|
||||
# src/app.cr
|
||||
|
||||
DB_URI = "sqlite3://:memory:"
|
||||
|
||||
DB.open DB_URI do |db|
|
||||
db_version = db.scalar "select sqlite_version();"
|
||||
puts "SQLite #{db_version}"
|
||||
end
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue