Build SQLite extension on Linux: Difference between revisions
Jump to navigation
Jump to search
(Compile instructions for Linux) |
Veroandreo (talk | contribs) (cosmetics) |
||
(One intermediate revision by one other user not shown) | |||
Line 14: | Line 14: | ||
wget -c "https://sqlite.org/contrib/download/extension-functions.c/download/extension-functions.c?get=25" -O extension-functions.c | wget -c "https://sqlite.org/contrib/download/extension-functions.c/download/extension-functions.c?get=25" -O extension-functions.c | ||
* Compile the file | * 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: | ** 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): | ||
<source lang="Makefile"> | <source lang="Makefile"> | ||
Line 30: | Line 30: | ||
@rm -f libsqlitefunctions.so | @rm -f libsqlitefunctions.so | ||
</source> | </source> | ||
** To compile then just run "make". | ** 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 | Now '''libsqlitefunctions.so''' is built and can be used by v.db.update: | ||
# Windows | |||
g.copy vect=precip_30ynormals,myprecip_30ynormals | g.copy vect=precip_30ynormals,myprecip_30ynormals | ||
v.db.addcolumn myprecip_30ynormals column="logjuly double precision" | v.db.addcolumn myprecip_30ynormals column="logjuly double precision" | ||
v.db.update myprecip_30ynormals column="logjuly" query_column="log(jul)" \ | v.db.update myprecip_30ynormals column="logjuly" query_column="log(jul)" \ | ||
sqliteextra=C:\OSGeo4Wdev\src\sqliteextension\libsqlitefunctions.dll | 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 | |||
=== See also === | |||
* [[Build SQLite extension on windows]] | |||
[[Category:FAQ]] | [[Category:FAQ]] | ||
[[Category:Vector]] | [[Category:Vector]] |
Latest revision as of 21:08, 6 November 2018
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