1

I'm trying to load a local DB with SQLite under a RedHat Linux server. I have a C code to load the database from a very large file spliting the columns. The bad new is that sqlite3 is not installed in the machine (fatal error: sqlite3.h: No such file or directory) and I won't be able to have permissions to install libsqlite3-dev (acording to this) , so I could only use it throuth bash or python:

[dhernandez@zl1:~]$ locate sqlite3
/opt/xiv/host_attach/xpyv/lib/libsqlite3.so
/opt/xiv/host_attach/xpyv/lib/libsqlite3.so.0
/opt/xiv/host_attach/xpyv/lib/libsqlite3.so.0.8.6
/opt/xiv/host_attach/xpyv/lib/python2.7/sqlite3
/opt/xiv/host_attach/xpyv/lib/python2.7/lib-dynload/_sqlite3.so
/opt/xiv/host_attach/xpyv/lib/python2.7/sqlite3/__init__.py
/opt/xiv/host_attach/xpyv/lib/python2.7/sqlite3/dbapi2.py
/opt/xiv/host_attach/xpyv/lib/python2.7/sqlite3/dump.py
/usr/bin/sqlite3
/usr/lib64/libsqlite3.so.0
/usr/lib64/libsqlite3.so.0.8.6
/usr/lib64/python2.6/sqlite3
/usr/lib64/python2.6/lib-dynload/_sqlite3.so
/usr/lib64/python2.6/sqlite3/__init__.py
/usr/lib64/python2.6/sqlite3/__init__.pyc
/usr/lib64/python2.6/sqlite3/__init__.pyo
/usr/lib64/python2.6/sqlite3/dbapi2.py
/usr/lib64/python2.6/sqlite3/dbapi2.pyc
/usr/lib64/python2.6/sqlite3/dbapi2.pyo
/usr/lib64/python2.6/sqlite3/dump.py
/usr/lib64/python2.6/sqlite3/dump.pyc
/usr/lib64/python2.6/sqlite3/dump.pyo
/usr/lib64/xulrunner/libmozsqlite3.so
/usr/share/man/man1/sqlite3.1.gz
/usr/share/mime/application/x-kexiproject-sqlite3.xml
/usr/share/mime/application/x-sqlite3.xml

What would be faster of the following options?

  1. Split the columns in my C program, and then execute the insert like this:

    system("echo 'insert into t values(1,2);'" | sqlite3 mydb.db);
    
  2. Split the columns in my C program, save it to a temp file and when I've got 500.000 rows I execute the script like this (and then empty the temp file to continue loading rows):

    system("sqlite3 mydb.db < temp.sql);
    
  3. Split the columns in my C program adding a delimiter between them, save it to a temp file and import it like this:

    .delimiter '@'
    .import temp.txt t
    
Community
  • 1
  • 1
mllamazares
  • 7,876
  • 17
  • 61
  • 89

3 Answers3

3

You can use the amalgation version. It is a single .c file you can include in your project, and all of SQLite is available. No need for dynamic linking.

Bart Friederichs
  • 33,050
  • 15
  • 95
  • 195
  • I've downloaded the file `C source code as an amalgamation, version 3.11.1.` of the download page, I've uploaded it to my home, and then I've put on the top `#include "/home/llami/sqlite3.c"` but it returns a lot of compilation errors: https://gist.github.com/mllamazing/18c33c2ff55b25c94293 Am I dismissing something? – mllamazares Mar 08 '16 at 15:10
  • 1
    "Include in your project" is not the same as "include in some .c file". Just compile it like any of your other .c files. – CL. Mar 08 '16 at 15:36
  • Yeah, sorry. Finally I solve it using these steps: http://www.mail-archive.com/sqlite-users@sqlite.org/msg30132.html Thank you so much! :) – mllamazares Mar 08 '16 at 15:41
0

You could probably try to dynamically load the sqlite3 library at runtime. There are quite few stuff to learn about it, but that's a powerful functionality and I am quite sure this would solve your problem.

Here is a link describing how you can do it : http://tldp.org/HOWTO/Program-Library-HOWTO/dl-libraries.html

Swann
  • 2,413
  • 2
  • 20
  • 28
0

Download the devel package and use it from your project directory. You only need it for the compilation.

Koshinae
  • 2,240
  • 2
  • 30
  • 40