Is it possible to create a SQLite database on ESP32?

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
S420L
Posts: 1
Joined: Wed Apr 22, 2020 8:18 pm

Is it possible to create a SQLite database on ESP32?

Post by S420L » Wed Apr 22, 2020 8:32 pm

Hey--new user to micropython here.

I've used Ampy to load micropython and boot.py to my board (ESP32 devkitv1--I think this is basically a node MCU knockoff).

Importing SQLite3 like in normal Python didn't work, so I tried

Code: Select all

upip.install("micropython-sqlite3")
which was suggested by some sites, which didn't work.

Next I tried downloading the source code for SQLite3 and FFILIB from https://github.com/micropython/micropython-lib and putting these files directly on my board next to boot.py. At this point I got a NoneType error stemming from this line of code in SQLite3.py:

Code: Select all

sq3 = ffilib.open("libsqlite3")
I downloaded libsqlite3 from this site: https://cppget.org/libsqlite3 and running

Code: Select all

import sqlite3
in the REPL still resulted in a NoneType error.

Long story short--am I doing something wrong, or is it not even possible to run a SQLite database on the ESP32 yet?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Is it possible to create a SQLite database on ESP32?

Post by dhylands » Wed Apr 22, 2020 9:43 pm

micropython-sqlite3 will only work on versions of micropython which have FFI. It's basically just a frontend for the C version of sqlite3, which is probably way too big to run on an ESP32.

I suppose it might be possible to port it to an ESP32. The libsqlite3.a file on my Mac is 1.8 Mb. But I'm going to guess it would take a substantial amount of effort since I imagine that sqlite3 makes extensive use of the C runtime library functions, many of which are unimplemented for micro platforms. You'd probably also need quite a bit of RAM.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: Is it possible to create a SQLite database on ESP32?

Post by jimmo » Thu Apr 23, 2020 1:08 am

Some experiments were done a few years ago (~2014) which showed that a cut-down SQLite is about 200k of ROM, and apparantly wasn't that hard to implement.

I'm curious what sort of stuff you'd use SQLite for on a microcontroller though.

As Dave points out, micropython-lib is very confusing because half of the stuff there doesn't work on most ports. I'd like to fix this -- see https://github.com/micropython/micropython-lib/pull/376

Post Reply