Build SQLite extension on Linux: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
(Compile instructions for Linux)
 
(+crossref)
Line 38: Line 38:
     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
=== See also ===
* [[Build SQLite extension on windows]]


[[Category:FAQ]]
[[Category:FAQ]]
[[Category:Vector]]
[[Category:Vector]]

Revision as of 10:47, 12 March 2017

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 into an extra 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:
# 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".

Now libsqlitefunctions.so is built and can be used by v.db.update (example from the manual):

   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

See also