Code: Select all
EnableExplicit
UseSQLiteDatabase()
Enumeration;{
#MainWindow=10
#btnOpenDatabase
#btnFindFirst
#FindNext
#dBase
EndEnumeration
;}
Global searchQuery$="", Quit
Procedure OpenDatabaseFile()
Protected dbFilename$
dbFilename$ = OpenFileRequester("Get database", "", "*.db", 0)
If Not OpenDatabase(#dBase, dbFilename$, "", "", #PB_Database_SQLite )
EndIf
EndProcedure
Procedure FindFirst()
searchQuery$="SELECT Title, Description, rowid, COUNT(*) FROM tblBooks"
If DatabaseQuery(#dBase, searchQuery$, #PB_Database_DynamicCursor)
NextDatabaseRow(#dBase)
Debug GetDatabaseString(#dBase, 0)
EndIf
EndProcedure
Procedure FindNext()
NextDatabaseRow(#dBase)
Debug GetDatabaseString(#dBase, 0)
EndProcedure
OpenWindow(#MainWindow, 0, 0, 512, 170, "Main window", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
ButtonGadget(#btnOpenDatabase, 10, 50, 100, 22, "Open database")
ButtonGadget(#btnFindFirst, 120, 50, 100, 22, "Find first record")
ButtonGadget(#FindNext, 230, 50, 100, 22, "Find next record")
Repeat ;{
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
If EventWindow() = #MainWindow
Quit=#True
EndIf
Case #PB_Event_Gadget
Select EventGadget()
Case #btnOpenDatabase: OpenDatabaseFile()
Case #btnFindFirst:FindFirst()
Case #FindNext: FindNext()
EndSelect
EndSelect
Until Quit=#True
If IsDatabase(#dBase)
CloseDatabase(#dBase)
EndIf
Why is this function not getting successive rows in the database? HOw can I resolve this issue? The help file shows how to use a while statement to iterate through relevant rows but I need a function that will get the next row in the database when the "Find next record" is clicked.