Git Product home page Git Product logo

erlang-sqlite3's Introduction

Erlang wrapper for SQLite3

CI Coverage Status Hex version

This library allows you to work with SQLite3 databases from Erlang.

It is compatible with Windows and Linux, and should probably work on other OSes as well.

See also esqlite for an alternative library.

Requirements

Erlang/OTP R14B or later is required (tested up to 17.3 at this writing), and SQLite 3 minimum version is 3.6.1.

Compiling

Linux

  1. Install SQLite3 by running sudo apt-get install sqlite3 or the equivalent for your package manager, or by compiling from the source.

  2. make.

Cross-compiling

If you want to use erlang-sqlite3 on an embedded device, it can be cross-compiled.

  1. Cross-compile SQLite3 and Erlang.

  2. Change variables and paths in rebar.cross_compile.config.sample to the desired values and rename it to rebar.cross_compile.config.

  3. make cross_compile.

Windows with MS Visual C++

To build both SQLite3 and sqlite3-erlang:

  1. If MSVC tools (cl, link, etc.) are not in the path, run vcvars32.bat or vcvars64.bat depending on whether you use 32-bit or 64-bit Erlang. build_port_win32.bat and build_port_win64.bat have the standard paths for VC10.0.

  2. nmake.

Alternately, you can use prebuilt versions of sqlite3.dll and sqlite3.def. To make sqlite3.lib, use lib /def:sqlite3.def. Then remove sqlite3.dll and sqlite3.lib targets from Makefile and do as above.

Potential compilation problems

  • If SQLite was built with SQLITE_OMIT_LOAD_EXTENSION option, you'll need to undefine ERLANG_SQLITE3_LOAD_EXTENSION macro in <c_src/sqlite3_drv.h>.

Running the test suite

Linux

make test

Windows

  1. nmake tests

  2. If you get the error "Error loading sqlite3_drv: The specified module could not be found", this is because sqlite3.dll isn't in the search path.

Example usage

See tests test/sqlite3_test.erl for a starting point. On Windows note that sqlite3.dll must be in your application's working directory or somewhere in the DLL search path.

Authors

See ./AUTHORS

erlang-sqlite3's People

Contributors

alexeyr avatar badlop avatar booo avatar brigadier avatar dnet avatar maxlapshin avatar mrcsparker avatar mremond avatar nosnilmot avatar prefiks avatar rflynn avatar rflynn93 avatar saa avatar sergey-miryanov avatar stentroad avatar ttyerlsol avatar uwiger avatar varnerac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

erlang-sqlite3's Issues

Where col = null

Hello

Sqlite3 expects the following syntax when when checking for NULL:

SELECT 1 FROM items WHERE col is NULL;

The query where "col = NULL" ( with equal sign ) is used, returns no records.

rebar included in repo do not work with new Erlang

When you run rebar it raises error:

deps/sqlite3$ ./rebar
escript: exception error: undefined function rebar:main/1
in function escript:run/2 (escript.erl, line 750)
in call from escript:start/1 (escript.erl, line 277)
in call from init:start_em/1
in call from init:do_boot/3

Erlang 25

Using sqlite3 from gen_server

Hello

I'm using this code:
{ok, Pid0} = sqlite3:open(DbName, [{file, TempFn1}])

Sometimes I receive errors like the following.

2023-02-21 20:35:10 =CRASH REPORT====
  crasher:
    initial call: sqlite_server:init/1
    pid: <0.866.0>
    registered_name: sqlite_server
    exception error: {{badmatch,{error,{already_started,<0.25418.0>}}},[{sqlite_server,open_db,4,[{file,"src/sqlite_se
rver.erl"},{line,324}]},{sqlite_server,handle_cast,2,[{file,"src/sqlite_server.erl"},{line,211}]},{gen_server,try_disp
atch,4,[{file,"gen_server.erl"},{line,689}]},{gen_server,handle_msg,6,[{file,"gen_server.erl"},{line,765}]},{proc_lib,
init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]}
    ancestors: [<0.842.0>]
    message_queue_len: 0
    messages: []
    links: [<0.25418.0>,<0.842.0>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 4185
    stack_size: 28
    reductions: 481871
  neighbours:
    neighbour: [{pid,<0.25418.0>},{registered_name,db_files},{initial_call,{sqlite3,init,['Argument__1']}},{current_fu
nction,{gen_server,loop,7}},{ancestors,[sqlite_server,<0.842.0>]},{message_queue_len,0},{links,[<0.866.0>,#Port<0.1391
9>]},{trap_exit,false},{status,waiting},{heap_size,376},{stack_size,12},{reductions,153},{current_stacktrace,[{gen_ser
ver,loop,7,[{file,"gen_server.erl"},{line,437}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,226}]}]}]

As I can see, the reason is in this line in sqlite3:open/2
true -> gen_server:start_link({local, DbName}, ?MODULE, Opts, [])

It starts a named process and since previous registered process exists with that name, it fails.
Docstring for that function says:

If the name is an atom other than 'anonymous', it's used for registering the gen_server and must be unique.

I think that approach is prone to errors.

Utf-8 encoding of table names

sqlite> .tables
Asetukset      Hyppääjät   Lentäjät     Pokat          Tarvikkeet   
Eurot          Hypyt          Luokat         Pondimaksut    Tyypit       
Hinnat         Koneet         Maksut         Stuff          Varjot       
Hyppymestarit  Korvaukset     Ostokset       Suoritukset

But:

([email protected])2> sqlite3:list_tables(hlu).
['Asetukset','Eurot','Hinnat','Hyppääjät',
 'Hyppymestarit','Hypyt','Koneet','Korvaukset','Lentäjät',
 'Luokat','Maksut','Ostokset','Pokat','Pondimaksut','Stuff',
 'Suoritukset','Tarvikkeet','Tyypit','Varjot']

Although:

([email protected])3> sqlite3:sql_exec(hlu, "select count(id)i from Hyppääjät where id >0;").    
[{columns,["i"]},{rows,[{1270}]}]

There is the very same issue of the column names also.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.