3

I use sqlite3 on Ubuntu and would like to add the acos and asin functions that are provided by the extension-functions.c file.

https://github.com/seth/RSQLite.extfuns/blob/master/src/extension-functions.c

When I follow the instructions given in the source code, I get the following error and I didn't find any answer on how I could get this working. I tried on Ubuntu 15.04, 15.10 and now 16.04.

extension-functions.c: In function ‘print_elem’:
extension-functions.c:1942:10: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘int64_t {aka long int}’ [-Wformat=]
   printf("%d => %lld\n", ee,c);
          ^

Here's what I did:

  • I installed sqlite3, libsqlite3-0, libsqlite3-3:i386, and libsqlite3-dev.
  • I downloaded the extension-functions.c into a new folder
  • inside the new folder I executed $ gcc -fPIC -lm -shared extension-functions.c -o libsqlitefunctions.so as suggested in the source code.

=> and then I get the error mentioned above.

What am I doing wong?

Mohit Jain
  • 30,259
  • 8
  • 73
  • 100
Dominik
  • 141
  • 1
  • 3
  • 14
  • [This post](http://stackoverflow.com/questions/6299083/cross-platform-printing-of-64-bit-integers-with-printf) may be useful. – LPs Apr 29 '16 at 12:12

2 Answers2

4

To summarize what I did:

I modified the file to include the <inttypes.h> and changed the printf statements as instructed by Mohit Jain.

Then I executed

gcc -fPIC -shared extension-functions.c -o libsqlitefunctions.so -lm

to compile the c file. Note that the -lm is at the end. Apparently this does matter.

After that you can include the libsqlitefunctions.so by calling

SELECT load_extension('/full/path/to/libsqlitefunctions.so');

before calling any of the new math functions.

Cheers, D.

PS: if you want to use it with Doctrine, you might want to follow this thread.

Dominik
  • 141
  • 1
  • 3
  • 14
2

Correct way to print an int64_t is:

#include <inttypes.h>
...
printf("%d => %" PRId64 "\n", ee, c);

In your program / library, you can change the way you print to get the desired result.

Complete list of print formats can be found here. You can use a script to fix the printing.

Mohit Jain
  • 30,259
  • 8
  • 73
  • 100