diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b34bc0d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,14 @@ +set(COMPONENT_SRCDIRS + "src" + ) + +set(COMPONENT_ADD_INCLUDEDIRS + "src" + ) + +# Arduino-ESP32 core https://github.com/espressif/arduino-esp32 +set(COMPONENT_REQUIRES + "arduino-esp32" + ) + +register_component() diff --git a/README.md b/README.md index be96904..7bc457c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Sqlite3 Arduino library for ESP32 +Note: This is a general purpose library based on the Sqlite codebase. For logging sensor data into database please use [Sqlite Micro Logger](https://github.com/siara-cc/sqlite_micro_logger_arduino), which is faster and memory efficient. + This library enables access to SQLite database files from SPIFFS or SD Cards through ESP32 SoC. Given below is a picture of a board that has a ready-made Micro SD slot (using SDMMC 4 bit mode - see example sqlite3_sdmmc): ![](ESP_WROOM_32_breakout.png?raw=true) diff --git a/examples/sqlite3_littlefs/sqlite3_littlefs.ino b/examples/sqlite3_littlefs/sqlite3_littlefs.ino new file mode 100644 index 0000000..6a821ba --- /dev/null +++ b/examples/sqlite3_littlefs/sqlite3_littlefs.ino @@ -0,0 +1,147 @@ +/* + This creates two empty databases, populates values, and retrieves them back + from the LITTLEFS file system +*/ +#include +#include +#include +#include +#include +#include "LittleFS.h" + +/* You only need to format LITTLEFS the first time you run a + test or else use the LITTLEFS plugin to create a partition + https://github.com/lorol/arduino-esp32fs-plugin/releases */ +#define FORMAT_LITTLEFS_IF_FAILED true + +const char* data = "Callback function called"; +static int callback(void *data, int argc, char **argv, char **azColName) { + int i; + Serial.printf("%s: ", (const char*)data); + for (i = 0; i 0) { - rc = sqlite3_prepare_v2(db1, sql.c_str(), 1000, &res, &tail); + rc = sqlite3_prepare_v2(db1, sql.c_str(), -1, &res, &tail); if (rc != SQLITE_OK) { String resp = F("Failed to fetch data: "); resp += sqlite3_errmsg(db1); @@ -251,7 +251,7 @@ void setup(void) { sql += server.arg("so_loc_count"); } } - rc = sqlite3_prepare_v2(db1, sql.c_str(), 1000, &res, &tail); + rc = sqlite3_prepare_v2(db1, sql.c_str(), -1, &res, &tail); if (rc != SQLITE_OK) { String resp = F("Failed to fetch data: "); resp += sqlite3_errmsg(db1); diff --git a/examples/sqlite3_web_console/sqlite3_web_console.ino b/examples/sqlite3_web_console/sqlite3_web_console.ino index f34b9db..0702693 100644 --- a/examples/sqlite3_web_console/sqlite3_web_console.ino +++ b/examples/sqlite3_web_console/sqlite3_web_console.ino @@ -194,7 +194,7 @@ void setup ( void ) { //sql += "' and '"; //sql += server.arg("to"); //sql += "'"; - //rc = sqlite3_prepare_v2(db1, sql.c_str(), 1000, &res, &tail); + //rc = sqlite3_prepare_v2(db1, sql.c_str(), -1, &res, &tail); //if (rc != SQLITE_OK) { // String resp = "Failed to fetch data: "; // resp += sqlite3_errmsg(db1); @@ -218,7 +218,7 @@ void setup ( void ) { //} //sqlite3_finalize(res); - rc = sqlite3_prepare_v2(db1, sql.c_str(), 1000, &res, &tail); + rc = sqlite3_prepare_v2(db1, sql.c_str(), -1, &res, &tail); if (rc != SQLITE_OK) { String resp = "Failed to fetch data: "; resp += sqlite3_errmsg(db1); diff --git a/examples/sqlite3_webquery/sqlite3_webquery.ino b/examples/sqlite3_webquery/sqlite3_webquery.ino index f2e7d24..2511781 100644 --- a/examples/sqlite3_webquery/sqlite3_webquery.ino +++ b/examples/sqlite3_webquery/sqlite3_webquery.ino @@ -167,7 +167,7 @@ void setup ( void ) { sql += "' and '"; sql += server.arg("to"); sql += "'"; - rc = sqlite3_prepare_v2(db1, sql.c_str(), 1000, &res, &tail); + rc = sqlite3_prepare_v2(db1, sql.c_str(), -1, &res, &tail); if (rc != SQLITE_OK) { String resp = "Failed to fetch data: "; resp += sqlite3_errmsg(db1); @@ -196,7 +196,7 @@ void setup ( void ) { sql += "' and '"; sql += server.arg("to"); sql += "'"; - rc = sqlite3_prepare_v2(db1, sql.c_str(), 1000, &res, &tail); + rc = sqlite3_prepare_v2(db1, sql.c_str(), -1, &res, &tail); if (rc != SQLITE_OK) { String resp = "Failed to fetch data: "; resp += sqlite3_errmsg(db1); diff --git a/library.properties b/library.properties index 4ad3768..17a7317 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Sqlite3Esp32 -version=2.3 +version=2.4 author=Arundale Ramanathan maintainer=Arun sentence=Sqlite3 database library for ESP32 core diff --git a/src/config_ext.h b/src/config_ext.h index 1029cff..a26f1e5 100644 --- a/src/config_ext.h +++ b/src/config_ext.h @@ -10,7 +10,6 @@ #define SQLITE_DEFAULT_LOOKASIDE 512,64 #define YYSTACKDEPTH 20 #define SQLITE_SMALL_STACK 1 -#define SQLITE_DEFAULT_PAGE_SIZE 4096 #define SQLITE_SORTER_PMASZ 4 #define SQLITE_DEFAULT_CACHE_SIZE -1 #define SQLITE_DEFAULT_MEMSTATUS 0 @@ -25,7 +24,7 @@ #define SQLITE_LIKE_DOESNT_MATCH_BLOBS 1 #define SQLITE_DEFAULT_FOREIGN_KEYS 0 #define SQLITE_DEFAULT_LOCKING_MODE 1 -#define SQLITE_DEFAULT_PAGE_SIZE 4096 +#define SQLITE_DEFAULT_PAGE_SIZE 512 #define SQLITE_DEFAULT_PCACHE_INITSZ 8 #define SQLITE_MAX_DEFAULT_PAGE_SIZE 32768 #define SQLITE_POWERSAFE_OVERWRITE 1 diff --git a/src/esp32.cpp b/src/esp32.cpp index 5f731de..3774401 100644 --- a/src/esp32.cpp +++ b/src/esp32.cpp @@ -300,7 +300,7 @@ static int ESP32FileSize(sqlite3_file *pFile, sqlite_int64 *pSize){ struct stat st; int fno = fileno(p->fp); - if (fno == -1) + if (fno < 0) return SQLITE_IOERR_FSTAT; if (fstat(fno, &st)) return SQLITE_IOERR_FSTAT; @@ -433,7 +433,7 @@ static int ESP32Open( memset(&st, 0, sizeof(struct stat)); int rc = stat( zName, &st ); //Serial.println(zName); - if (rc == -1) { + if (rc < 0) { strcpy(mode, "w+"); //int fd = open(zName, (O_CREAT | O_RDWR | O_EXCL), S_IRUSR | S_IWUSR); //close(fd);