mwebster Posted March 8, 2023 Report Posted March 8, 2023 I've got a weird one that I can't seem to find the answer for. When I try to update a row in an existing table, it seems to work OK, subsequent queries show the updated data is there. However, after I close the connection and reopen it, the old data is still there. Is there some in-memory copy that's not getting flushed out with UPDATE? Insert's work fine... This is just a two-field table, SN primary unique string key and PN string. Creating them saves them almost instantly after finalize (checking with external viewer). Update doesn't save them where external viewer can see it, but doing a query in LabVIEW does see it until I restart the connection, as mentioned before. I've also tried it without binding using format into string where I just have the SQLite statement say UPDATE UUT SET PN='10029-201' WHERE SN=123 but the same thing happens. Am I missing something simple here? Quote
LogMAN Posted March 8, 2023 Report Posted March 8, 2023 Sounds like an uncommitted transaction. Make sure you have committed all transactions before closing the file. Uncommitted transactions are lost. 1 Quote
IvanLis Posted March 8, 2023 Report Posted March 8, 2023 (edited) 48 minutes ago, mwebster said: Am I missing something simple here? Now there is no time for experiments. When I update record, in all projects, I use template with a restore point. SQLite is quite paranoid about data integrity. But I am using old version of pushit SQLite Library v1.10.0.85 Although I think on new versions, this template will work. Edited March 8, 2023 by IvanLis 1 Quote
mwebster Posted March 8, 2023 Report Posted March 8, 2023 (edited) I originally had it wrapped in a Begin/Commit as well but removed them to see if that was part of the problem. Same issue there, the in-memory copy had the update, but not saved to file. Thanks for the syntax check though, I didn't see an UPDATE in the example code, so wasn't completely sure about that. Okay, I found it. I was attempting an Insert originally and, if that failed, I was trying an Update. So, for whatever reason, the Insert transaction wasn't getting closed out properly on error. For a named transaction, when there's an error, it is doing SAVEPOINT X / ROLLBACK TO X, but this isn't closing the transaction. I didn't get an error on this until I tried an unnamed transaction for the update, which attempt to do BEGIN IMMEDIATE / (COMMIT or ROLLBACK depending on error state). When the update function tried to do BEGIN IMMEDIATE, the API threw an error saying you couldn't begin a transaction without closing the previous one. I then went back to the Insert and removed the names from that (so it does BEGIN IMMEDIATE / ROLLBACK when it hits an error) and then the subsequent UPDATE call works as intended. Not sure why ROLLBACK TO X didn't close the transaction, but that was the root cause. Thanks again for the help.... Mike Edited March 8, 2023 by mwebster Quote
LogMAN Posted March 9, 2023 Report Posted March 9, 2023 9 hours ago, mwebster said: Not sure why ROLLBACK TO X didn't close the transaction, but that was the root cause. This is explained in the SQLITE help pages: https://www.sqlite.org/lang_savepoint.html#savepoints Quote The ROLLBACK TO command reverts the state of the database back to what it was just after the corresponding SAVEPOINT. Note that unlike that plain ROLLBACK command (without the TO keyword) the ROLLBACK TO command does not cancel the transaction. Instead of cancelling the transaction, the ROLLBACK TO command restarts the transaction again at the beginning. All intervening SAVEPOINTs are canceled, however. 1 Quote
drjdpowell Posted March 9, 2023 Author Report Posted March 9, 2023 Hi @mwebster, Can you upload an example showing this problem? Something is wrong somewhere, as a Savepoint outside of an open transaction should behave the same as Begin-Rollback, to my understanding. Quote
mwebster Posted March 9, 2023 Report Posted March 9, 2023 LabVIEW 2020. Example.vi I removed the savepoint hookups in the Modify UUT Info.vi to make the error come out explicitly. If you hook those up, it fails silent. I "fixed" it by removing the savepoint hookups in the Save UUT Info.vi so it just does a BEGIN IMMEDIATE/ROLLBACK. SQLite Transaction failure example.zip Quote
mwebster Posted March 9, 2023 Report Posted March 9, 2023 7 hours ago, LogMAN said: This is explained in the SQLITE help pages: https://www.sqlite.org/lang_savepoint.html#savepoints I think you're right. I was expecting it behave like RELEASE. ROLLBACK TO doesn't commit, you're still inside the SAVEPOINT transaction. Quote
drjdpowell Posted March 9, 2023 Author Report Posted March 9, 2023 2 hours ago, mwebster said: LabVIEW 2020. Example.vi As an aside, you should look into the Upsert clause, which allows doing INSERT or UPDATE in a single SQL statement. Also, note that you don't need savepoints about a single transaction (all single statements are their own transaction, and either succeed or rollback automatically). 1 Quote
drjdpowell Posted March 9, 2023 Author Report Posted March 9, 2023 (edited) Re the main issue, this seems to be my misunderstanding about how Savepoints work (as distinct from BEGIN and ROLLBACK). Here is a relevant discussion. From that discussion, I see I should, instead of "ROLLBACK TO <Savepoint>" I should do "ROLLBACK TO <Savepoint>; RELEASE <Savepoint>;" Issue 22 Edited March 9, 2023 by drjdpowell 2 Quote
mwebster Posted March 9, 2023 Report Posted March 9, 2023 18 minutes ago, drjdpowell said: As an aside, you should look into the Upsert clause, which allows doing INSERT or UPDATE in a single SQL statement. Also, note that you don't need savepoints about a single transaction (all single statements are their own transaction, and either succeed or rollback automatically). Yep, I was thinking exactly that after I got it working, no need to wrap single statements.... Thanks for the links! Quote
Bil 6 Posted May 21, 2024 Report Posted May 21, 2024 Hello world, Thank you so much for the great work drjdpowell !! Wonderful library ! I have a question concerning the possibility to get all the tables of a database : is it possible to list all the tables of a database (here an array containing [table_1, table_80, Table_9012]) with the library ? It seems the ".tables" request in SQLite is not understood: I tried a lot of other request, ("show tables", "SELECT * FROM information_schema.tables;", etc), same result. I'm working with LabVIEW 23 Q3. Does somebody know if there's a solution for my problem by using this library ? BR ! Bilsix Quote
drjdpowell Posted May 21, 2024 Author Report Posted May 21, 2024 You're looking for the sqlite-schema table: https://www.sqlite.org/schematab.html Quote
Bil 6 Posted May 22, 2024 Report Posted May 22, 2024 Thanks for your answer Dr. James ! In fact, the database is already created, I only would like to read the tables already created in the database, I don't need to create a new table. Do you confirm sqlite_schema is the request I need to do so ? Thx & KR ! Bilsix Quote
drjdpowell Posted May 22, 2024 Author Report Posted May 22, 2024 Why don't you just try it? Open your SQLite viewer app if choice and execute "SELECT * FROM sqlite_schema" 1 Quote
Bil 6 Posted May 22, 2024 Report Posted May 22, 2024 It works... Thank you so much, I didn't understand this table contains all the info I wanted Thank you again ! KR, Bilsix Quote
ionpol Posted June 18, 2025 Report Posted June 18, 2025 Hi @drjdpowell! I ran into an issue using the library on LV2024 Q3 64 bit and LV2025Q1 64 bit (only tested it on these two versions). It appears to have something to do with the "Load Extension" functions. Error 402860 occurred at SQLite.lvlib:Connection.lvclass:Execute SQL (No results).vi:3980001:Step SQL--> "SELECT load_extension('C:\Program Files\National Instruments\LabVIEW 2025\vi.lib\drjdpowell\SQLite Library\SQL Connection\extension-functions_64.dll');" MAIN db name-->"C:\Projects\A Project\A Project_Config\Unit_SomeUnitId\database\hse_test_sqlite.db" SQLITE_ERROR(1): The specified module could not be found. Possible reason(s): SQLite returned SQLITE_ERROR(1), see www.sqlite.org/rescode.html#error Any suggestions towards solving this would be greatly appreciated. Thanks! Quote
drjdpowell Posted June 18, 2025 Author Report Posted June 18, 2025 Does that DLL exist at the stated path? Quote
ionpol Posted June 19, 2025 Report Posted June 19, 2025 Yes, the DLL is there. Furthermore, when calling it directly from sqlite3 it also works. Quote
ionpol Posted June 19, 2025 Report Posted June 19, 2025 (edited) Just in case the previous info was a bit vague, this is what I mean: SQLite version 3.50.1 2025-06-06 14:52:32 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database. sqlite> sqlite> .load "C:/Program Files/National Instruments/LabVIEW 2025/vi.lib/drjdpowell/SQLite Library/SQL Connection/extension-functions_64.dll" ...> The DLL seems to work fine and can be loaded into sqlite, but the LabVIEW method seems to have a problem. Edited June 19, 2025 by ionpol Quote
drjdpowell Posted June 22, 2025 Author Report Posted June 22, 2025 I checked that it works for me, in LabVIEW 2021. Does code this simple fail for you: Quote
ionpol Posted June 23, 2025 Report Posted June 23, 2025 Unfortunately, it fails. The original error I posted is from within the MATH.vi so it would make sense that nothing downstream of that would work. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.