I’d appreciate comments about this scenario:
user creates items consisting of two sub-items: ID and its associated text. Although no more than 40000 items are expected to be created, actually I think that only a few hundreds will be created.
Up to now, my approach has been to store IDs & associated texts into an array of pairs (a property); and to update a dictionary (value ID & text).
By looping thru the array I populate a listbox with pair.left (ID), and selecting a row, the pair.right is shown in a textarea.
Another function is to return a text retrieving it from the dictionary.value(ID).
Besides this, the only operations allowed are to modify the text associated to an ID or to delete an item; IDs may not be modified.
So, no searching for particular words inside texts etc. etc.
When the app quits, I write the array to a file. When the app starts, the file is read and the array & dictionary are created.
One hour ago I rewrote the app dumping the array of pairs and using instead a sqlitedatabase (plus dictionary) to perform the same job, and so now I have to decide which of the two approaches I should keep. In terms of speed (which is not the most important matter), it SEEMS that the old approach (array) is more quick.
Should I maintain this approach, or shift to a sqlitedatabase? I ask, because I have a feeling that for this simple scenario, the database might be overkill.
Given the max of 40000 items or an expected avg of hundreds, i would stay with a text file. Easy to backup/restore, can be edited outside the app… etc etc, but i am oldskool and still love INI style files for config/preferences. I would use a DB if there is a multiuser/network scenario, transaction and locking needs, performance, search etc.
If all that isnt the case, why add a additional layer of complexity?
if your user makes lots of modifications on a day without saving, if the app hangs or a power failure, you don’t have time to save
all the work is gone…
if you want to be sure that the ID are unique, not that easy with text file
if anyday you want to search for some text (even if now you dont need it) it will be difficult with a text file
so for all of these (plus I prefer databases because I wrote routines to handle it easily) I prefer the database way.
Dim result As String
Soft Declare Function NSClassFromString Lib "Cocoa" ( clsName As cfstringref ) As ptr
Soft Declare Function UUID Lib "Cocoa" selector "UUID" ( clsRef As ptr ) As ptr
Soft Declare Function UUIDString Lib "Cocoa" selector "UUIDString" ( obj_id As ptr ) As cfstringref
Dim classPtr As Ptr = NSClassFromString( "NSUUID" )
Dim NSUUID As ptr = UUID( classPtr )
result = UUIDString( NSUUID )
Const kLibName = "win32.Rpcrt4"
Soft Declare Function UUIDCreate Lib kLibName alias "UuidCreate" ( ByRef uuid As WindowsUUID ) As Integer
Soft Declare Function UUIDToString Lib kLibName alias "UuidToStringA" ( ByRef inUUID As WindowsUUID, ByRef outString As CString ) As Integer
Dim uuid As WindowsUUID
Dim out As CString
result = out
result = result.DefineEncoding( Encodings.UTF8 )
result = result.Uppercase