Code: Select all
Structure
  name.s
  phone.s
  homes.s()
EndStructure
Darryl
Code: Select all
Structure
  name.s
  phone.s
  homes.s()
EndStructure

There are a lot of home made linked list implementations posted on these forums, mainly for solving this problem.LDSang wrote:Does anyone have a simple work around for this. I've been wracking my brain all weekend and haven't come up with anything. Thanks in advance.

Code: Select all
;Dynamic List-in-an-Array example
; by Demivec
;18 Feb 2008
;-structures
Structure homeList
  home.s
  notLast.l ;this serves as a pointer to next element in homes(), 0 indicates this is end of list
EndStructure
Structure owner
  name.s
  phone.s
  homes.l
EndStructure
;-init
Global NewList owner.owner()
Global maxHomesArraySize.l = 100 ;this records maximum # of homes record, it may go up or down
Global Dim homes.homeList(maxHomesArraySize) ;this holds all homes and links to next home, it's an array of list elements.
Global freeHomeStart.l = 1  ;this shows the first available home, we don't use the zero'th element
For I = freeHomeStart To maxHomesArraySize - 1  ;this initializes list to point to next available home element
  homes(I)\notLast = I + 1
Next 
;-procedures
Procedure increaseHomesArray() ;increase size of homes array and initialize
  Protected I.l
  maxHomesArraySize + 50 ;increase size of homes array
  freeHomeStart = maxHomesArraySize + 1 ;free element list will start at the addition to array
  Redim homes.homeList(maxHomesArraySize) 
  For I = freeHomeStart To maxHomesArraySize - 1  ;this initializes list to point to next available home element
    homes(I)\notLast = I + 1
  Next   
EndProcedure
Procedure.l findOwner(name.s) ;points owner() list to desired name
  FirstElement(owner())
  ForEach owner()  ;look for owner
    If owner()\name = name
      ProcedureReturn 1 ;found
      Break
    EndIf
  Next 
  ProcedureReturn 0 ;didn't find
EndProcedure
Procedure.q findHome(home.s) ;called after owner() list points to desired owner
  Protected homeList.l = owner()\homes,lastIndex.q = homeList
  Repeat 
    If homes(homeList)\home = home 
      PokeL(@lastIndex+4,homeList)
      ProcedureReturn lastIndex ;found homeList index of home (previousIndex is at @,homeIndex is at @+4)
    EndIf 
    lastIndex = homeList
    homeList = homes(homeList)\notLast
  Until homes(homeList)\notLast = #False
  
  ProcedureReturn 0 ;didn't find
EndProcedure
Procedure addNewHome(home.s,homeIndex.l = 0) ;called after owner() list points to desired owner
  If homeIndex = 0 ;start a new list for a new owner
    owner()\homes = freeHomeStart
    homeIndex = freeHomeStart
  Else ;update links to add another home
    homes(homeIndex)\notLast = freeHomeStart
    homeIndex = freeHomeStart
  EndIf 
   
  If homes(freeHomeStart)\notLast = #False
    increaseHomesArray()
  Else      
    freeHomeStart = homes(freeHomeStart)\notLast ;move pointer to next free element
  EndIf   
  homes(homeIndex)\home = home
  homes(homeIndex)\notLast = #False ;signal as last home in list
EndProcedure
Procedure.l AddHomeToOwner(name.s,home.s,phone.s = "NA") ;if owner doesn't exist yet it will be created first
  Protected homeList.l
  If findOwner(name)
    homeList = owner()\homes
    While homes(homeList)\notLast <> #False ;find end of list
      homeList = homes(homeList)\notLast
    Wend
    addNewHome(home,homeList)
    ProcedureReturn 1 ;added to an existing owner
  Else
    AddElement(owner())
    owner()\name = name
    owner()\phone = phone
    addNewHome(home) 
    ProcedureReturn -1 ;added to a new owner
  EndIf 
EndProcedure
Procedure removeHome(homeIndex.l,lastIndex.l) ;called after owner() list points to desired owner
  If lastIndex = homeIndex ;modification to list of owners needed
    If homes(lastIndex)\notLast = #False ;this was the only home in list
      DeleteElement(owner())
    Else  ;this was the first home, so update pointer to the new first home
      owner()\homes = homes(lastIndex)\notLast
    EndIf 
  Else
    homes(homes(lastIndex)\notLast)\notLast = homes(homeIndex)\notLast ;relink home list
  EndIf
  homes(homeIndex)\home = ""
  homes(homeIndex)\notLast = freeHomeStart ;link removed home in list of free homes
  freeHomeStart = homeIndex
EndProcedure
Procedure.l removeHomeFromOwner(name.s,home.s) ;if no homes left after removal, owner will be removed also
  Protected homeIndex.q
  If findOwner(name)
    homeIndex = findHome(home)
    If homeIndex = 0
      ProcedureReturn 0 ;didn't find home
    Else
      removeHome(PeekL(@homeIndex),PeekL(@homeIndex+4))
    EndIf 
    ProcedureReturn 1 ;added to an existing owner
  Else
    ProcedureReturn -1 ;didn't find owner
  EndIf
EndProcedure
Procedure  displayOwnerList() ;debugs owners and homeslist
  Protected homeList.l,homecount.l
  Debug "---------------"
  FirstElement(owner())
  ForEach owner()
    Debug "Owner: " + owner()\name
    homeList = owner()\homes
    homecount = 1
    While homes(homeList)\notLast ;find end of list
      Debug "  home #" + Str(homecount) + ": " + homes(homeList)\home
      homecount + 1
      homeList = homes(homeList)\notLast
    Wend
    Debug "  home #" + Str(homecount) + ": " + homes(homeList)\home
  Next 
EndProcedure
;-example 
AddHomeToOwner("Donald","1 Maple Dr","555-5555") ;creates a new owner
AddHomeToOwner("Trump","4 Baltic Ave") ;creates a new owner
AddHomeToOwner("Trump","28 Pennsylvania Ave")
AddHomeToOwner("Trump","35 Park Place")
AddHomeToOwner("Trump","50 Broadway")
AddHomeToOwner("Trump","18 Illinois Ave")
AddHomeToOwner("tinman","57.1604N, 2.1345W") ;creates a new owner
AddHomeToOwner("hellhound66","16 Freiberg Strasse") ;creates a new owner
AddHomeToOwner("Demivec","2 Sherwood Forest","555-AROW") ;creates a new owner
displayOwnerList()
removeHomeFromOwner("Trump","4 Baltic Ave")
removeHomeFromOwner("Donald","1 Maple Dr")
displayOwnerList()
I thought about doing this but then I thought I may have more than one query at a time, and the db functions (I'm using SQLite) seem to reference the entire database handle as opposed to the last result.pdwyer wrote:If this all goes to disk anyway, just use a DB then query it when you need the info.
So how do you do the multiple concurrent queries in PureBasic for SQLite? It seems like the commands only reference the entire database used and not the "result set".pdwyer wrote:Fair enough,
On the SQLite thing though, you can have multiple concurrent queries, you can only have one write operation at a time though (update, insert, delete etc) Selects are fine.