Build SQLite extension on Linux
Jump to navigation
Jump to search
Problem: SQLite lacks by default log(), sqrt(), and other functions.
Solution: In v.db.update there is the following option:
sqliteextra=name Name of SQLite extension file for extra functions (SQLite backend only)
For build SQLite extension for Linux follow these steps:
- Install a compiler like "gcc"
- Install the SQLite development package (named "sqlite-dev" or "sqlite-devel")
- Download extension-functions.c from here:
wget -c "https://sqlite.org/contrib/download/extension-functions.c/download/extension-functions.c?get=25" -O extension-functions.c
- Compile the file to get the SQLite extension function library:
- You can simply save this convenient Makefile (note: indentation must the done with <tab>!) into the same directory in which extension-functions.c is stored (for example, $HOME/software/sqlite_extra):
# https://sqlite.org/contrib/download/extension-functions.c
default:
wget -c "https://sqlite.org/contrib/download/extension-functions.c/download/extension-functions.c?get=25" -O extension-functions.c
gcc -fPIC -lm -shared extension-functions.c -o libsqlitefunctions.so
@echo "Usage:"
@echo " sqlite> SELECT load_extension('/path/to/libsqlitefunctions.so');"
@echo " sqlite> select value, log(value) from test;1|0.0"
clean:
@rm -f libsqlitefunctions.so
- To compile then just run "make" within the directory where you saved extension-functions.c and the Makefile. If all went fine, you now also have the libsqlitefunctions.so in the directory.
Now libsqlitefunctions.so is built and can be used by v.db.update:
# Windows g.copy vect=precip_30ynormals,myprecip_30ynormals v.db.addcolumn myprecip_30ynormals column="logjuly double precision" v.db.update myprecip_30ynormals column="logjuly" query_column="log(jul)" \ sqliteextra=C:\OSGeo4Wdev\src\sqliteextension\libsqlitefunctions.dll # Linux g.copy vect=precip_30ynormals,myprecip_30ynormals v.db.addcolumn myprecip_30ynormals column="logjuly double precision" v.db.update myprecip_30ynormals column="logjuly" query_column="log(jul)" \ sqliteextra=$HOME/software/sqlite_extra/libsqlitefunctions.so