Newbie Question on Database Retrieval

Hi all! I am writing an application for my own use. I have a 14,000+ row database in SQlite that I want to read. I’m able to connect to it and read through all the rows. My initial code does this on main window opening. As a test, I simply counted the number of rows just to see if I can get to them - this works and I will remove that part of the code, eventually.

However, I what I really want is to work with each individual row in the table in different windows. When I put my db.SelectSQL statement and associated code in another window, it tells me “This item does not exist”. How do I declare that db and its rowsets so they can be shared between multiple windows?

You can pass the database reference to the editor window. Create a db as SQLiteDatabase property on your editor window and do something like this:

var oEdit as new winEditor
oEdit.db = oCurrentDatabaseReference
oEdit.EditReocrd(oThisRecord)

The winEditor can use the db property to access the same database as the parent window. Closing the window cleans up the references, you only have to worry about closing and opening the database in one spot (for the main window).

Tim - thanks for the reply. While I was waiting, I found an AI response via Google that seems to work by defining and opening the database in the App Opening Event Handler. Referencing it in subsequent windows via having “App.” placed on the front of my select statements seems to work.

Will this cause any issues down the road?

Global variables can lead to spaghetti code and sometimes hard to track down bugs. The tighter you can scope something, the better the compiler can help you prevent errors before runtime.

By designing it so that your main window maintains the connection and passes it to helper windows, you could theoretically have multiple main windows (like my app Lifeboat). Should you ever need or desire multiple main windows.

I was always taught by people smarter than me to avoid global variables unless I absolutely needed them and had no better alternatives.

One last Q - is that winEditor something unique to the Windows OS? I am developing and running the app on a Mac.

No, I use type-prefixing and hungarian notation, so that means the class type is a window, and it’s my “Editor” window. winEditor.

It would be something you build and name in the Navigator. Your own Window design. You would add the db as SQLiteDatabase property and a public method named LoadRecord that accepts a single record by some means.

OK - got it - thanks Tim!

to build your app as cleanly as possible, take a look at the eddieelectronics example

it’s a full featured sqlite app with list and edit of each record.

Another small tip: Avoid processing computationally intensive objects or objects dependent on external resources in Open/Opening events. Otherwise, you’ll quickly find yourself in situations where your programs start slowly or windows open with a delay. :wink: