Build SQLite extension on Linux

From GRASS-Wiki
Jump to: navigation, search

Problem: SQLite lacks by default log(), sqrt(), and other functions.

Solution: In v.db.update there is the following option:

   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 "" -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:

	wget -c "" -O extension-functions.c
	gcc -fPIC -lm -shared extension-functions.c -o
	@echo "Usage:"
	@echo "  sqlite> SELECT load_extension('/path/to/');"
	@echo "  sqlite> select value, log(value) from test;1|0.0"

	@rm -f
    • To compile then just run "make".

Now 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)" \

See also