-
Notifications
You must be signed in to change notification settings - Fork 74
SQL Updates #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
8 seconds sounds quite high for a 40 row table on LITTLEFS, unless the row length is huge and all rows are updated. |
I think the issue you are facing is unusual so need more info or a reproducible sample to suggest further opinion. |
Hi Arun Thanks for taking the trouble to look at this issue I have created a sample code snippet which is largly based on your littlefs example In my sample I test two databases The first, small database has only one table, tblConfig in it and 2 columns. I found that wrapping the UPDATE query within a transaction significaly improved the update speed. What you will see when running the sample code is
So is it best practice to use transactions when updating? (My gut feeling is that is shouldn't matter in this case) Also do you expect the size of the database to impact the UPDATE, even though the UPDATE is not affecting any of those extra tables? main.zip I've zipped up the code, the two sample databases and the platformm.ini. If there's anything else you need please let me know Garry |
@BackInFiveMinutes I am having trouble loading the data onto the board, so unable to test what you have provided. It may help to try using Prepared Statements instead of plain SQL statements and using a WITHOUT ROWID table. |
Hello, Can you please point me in the right direction? I'm using two approaches, neither of which is working.
I was trying actually delete the file via file browser and programmatically with And no effect. PRAGMA main.page_size = 1024;
PRAGMA main.page_size; |
@trianglesis Have you tried setting the PRAGMA page_size=512 just before you do CREATE TABLE? There have been issues reported about doing VACUUM because of limited memory. |
char db_name[32];
snprintf(db_name, sizeof(db_name)-1, "%s/stats.db", DB_ROOT);
// Open database
sqlite3 *db;
int rc = db_open(db_name, &db); // will print "Opened database successfully"
if (rc != SQLITE_OK) {
ESP_LOGE(TAG, "Cannot open database: %s resp: %d", db_name, rc);
vTaskDelete(NULL);
} else {
ESP_LOGI(TAG, "Opened database: %s resp: %d", db_name, rc);
}
// Set page size, read page size: "PRAGMA page_size;"
// Inquiry
rc = db_query(xMessageBufferQuery, db, "PRAGMA page_size=512; VACUUM;");
if (rc != SQLITE_OK) {
ESP_LOGE(TAG, "Set PRAGMA page_size FAILED!");
} Yes, I ran this query from the very beginning. Later, I downloaded a freshly created DB and checked its pragmas in |
@trianglesis Can you try with Arduino IDE? I have not used other IDEs. I do remember changing the default to 512 and saw that it took effect. So there should not be a need to use PRAGMA and VACUUM. |
Thanks, Strangely, this
I will ask the author. Thanks. |
The default page size is 512 as set in the line shown above. If a new table is created with this setting the PRAGMA and VACUUM are not needed. |
Brilliant library and really appriciate it. I have an issue with my code which hopefully someone can help
I have a small databast circa 170K in size. There is a config table of around 40 rows, no indexing. It takes me arounf 8 seconds to perform a SQL update which is pretty slow.
If I use SQLite Expert to perform the same update, the time is around 20ms.
I used this example
https://github.com/siara-cc/esp32_arduino_sqlite3_lib/blob/master/examples/sqlite3_littlefs/sqlite3_littlefs.ino
and pointed to my database and added a SQL update
This reproduces the same (slow) SQL update.
So do I have to live woth the slow SQL updates or is there something I can do that will speed the SQL updates up.
As a side note I am definatly an amateur with coding!
Thanks for reading
Garry
The text was updated successfully, but these errors were encountered: