Stale SQLite connection
In my code I'm opening a sqlite connection and keeping it open rather than opening and closing one on each transaction. Generally it's working well. I often save and close my image. When I then reopen the image I still have a connection and it says it's open, but using it gives me an error. This is easily recovered. I just open a new connection. Is there a way I can see if a connection is still good, in my code? Or should I be opening and closing connections every transaction? I haven't benchmarked it but I'm assuming it would be slower. I guess I could set my connection to nil in a start-up script. That would cause my code to get a new connection after a break from development. Any recommendations? Thanks, Jeff. -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
Hi Jeff Is this you from Brisbane? Did you used to come to the meetups at the State Library? Well anyway, I used to do something similar to what you describe, by lazy initializing the connection and also checking to see if it is open. dbConnection dbConnection ifNil: [ dbConenction := SQLiteConnection on: self dbFilePath ]. dbConnection isOpen ifFalse: [ dbConnection open ]. ^ dbConnection I have not noticed it being "slow", but then I use transactions wherever I can. Hope that helps. Vince -----Original Message----- From: Pharo-users <pharo-users-bounces@lists.pharo.org> On Behalf Of Jeff Gray Sent: Friday, 13 March 2020 3:21 PM To: pharo-users@lists.pharo.org Subject: [Pharo-users] Stale SQLite connection EXTERNAL: Do not click links or open attachments if you do not recognize the sender. In my code I'm opening a sqlite connection and keeping it open rather than opening and closing one on each transaction. Generally it's working well. I often save and close my image. When I then reopen the image I still have a connection and it says it's open, but using it gives me an error. This is easily recovered. I just open a new connection. Is there a way I can see if a connection is still good, in my code? Or should I be opening and closing connections every transaction? I haven't benchmarked it but I'm assuming it would be slower. I guess I could set my connection to nil in a start-up script. That would cause my code to get a new connection after a break from development. Any recommendations? Thanks, Jeff. -- Sent from: https://urldefense.com/v3/__http://forum.world.st/Pharo-Smalltalk-Users-f131...
Hey Vince! Yes it's me. Hope you're well. Those meetings were fun. Shame they petered out, though I now live much further away so I wouldn't be attending anymore. Yep - that lazy eval looks very similar to my code. I think that in general operation, my application would not normally have a problem as the connection won't become stale so for convenience I think I'll set the connection to nil in my start-up script. Thanks guys. -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
Jeff, You could have a look at SmalltalkImage>>#addToShutDownList: and SmalltalkImage>>#addToStartUpList: to stop/(re)start the connection when image is closed or a snapshot is taken. Add a method #startUp: to handle reconnecting. See for example Clipboard>>#startUp: Cheers, Erik -- Sent from: http://forum.world.st/Pharo-Smalltalk-Users-f1310670.html
participants (3)
-
Erik Stel -
Jeff Gray -
Vince Refiti