Read data from a sqlite table

Just starting out? Need help? Post your questions and find answers here.
IndiQa
New User
New User
Posts: 7
Joined: Thu Jan 22, 2009 4:41 pm
Location: US

Read data from a sqlite table

Post by IndiQa »

OK I have a sqlite db with table set up.

Verified thru the SQLite browser application.

I try to read each column from each row. When I call the
While NextDatabaseRow(Number of the db)

The number is returned from the
DBnumber = OpenDatabase(#PB_Any, Filename$, "", "", PB_Database_SQLite)

So the db identifier should be correct.

The while/wend nextdatabaserow loop never executes because it is always returning 0. (zero)

Is this the way to get table data back out of a sqlite db? And into variables.

I have no problem adding data to the db. And all the data is string data. Other than the main index.

There is data in all the cells of the table I want to read.

What info I have in the way of retrieving data I have pieced from various snippets and stuff from several places.

Is there good example of this operation somewhere that works so I can see where the heck I went wrong?

Thanks

Curt

OK FB thanks. Here is the code I am trying to use:

---------------------------------------------------------------------------

UseSQLiteDatabase()

Pattern$ = "Database (*.sqlite)|*.sqlite|All files (*.*)|*.*"

StandardFile$ = "*.sqlite"

Filename$ = OpenFileRequester("Load a Database", StandardFile$, Pattern$, 0)

DB.l = OpenDatabase(#PB_Any, Filename$, "", "", #PB_Database_SQLite)

DBOK.l = IsDatabase(DB.l)

If DBOK.l >0

While NextDatabaseRow(DB.l)

Temp_String1$ = GetDatabaseString(DB.l,0)
Temp_String2$ = GetDatabaseString( DB.l,1 )
Temp_String3$ = GetDatabaseString( DB.l , 2 )
Temp_String4$ = GetDatabaseString( DB.l , 3 )

AddGadgetItem(Gadget_MainForm_ListIcon_Log, - 1, Temp_String1$ + Chr(10) + Temp_String2$ + Chr(10) + Temp_String3$ + Chr(10) + Temp_String4$ )
; Adding or trying to add each cell of the table to a stringgrid (listicon for non Delphi users)

Wend


EndIf
-------------------------------------------------------------------------------
Last edited by IndiQa on Fri Feb 27, 2009 1:42 am, edited 1 time in total.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

Please paste your problem code here so that we can see where you might have a problem. Very hard to guess without it.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
IndiQa
New User
New User
Posts: 7
Joined: Thu Jan 22, 2009 4:41 pm
Location: US

Post by IndiQa »

Put my code in the first post.

Thanks FB
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

G'day, you need more coffee (grin). You haven't put in a query to get anything back yet, that's why nothing happens!

Code: Select all

UseSQLiteDatabase()

Pattern$ = "Database (*.sqlite)|*.sqlite|All files (*.*)|*.*"

StandardFile$ = "*.sqlite"

Filename$ = OpenFileRequester("Load a Database", StandardFile$, Pattern$, 0)

dbHandle = OpenDatabase(#PB_Any, Filename$, "", "", #PB_Database_SQLite)

If dbHandle

  If DatabaseQuery(dbHandle, "SELECT * FROM addresses")
  
    While NextDatabaseRow(dbHandle)
    
      Debug GetDatabaseString(dbHandle, 0)
      Debug GetDatabaseString(dbHandle, 1)
      Debug GetDatabaseString(dbHandle, 2)
      Debug GetDatabaseString(dbHandle, 3)
    
    Wend
  
  EndIf
  
  FinishDatabaseQuery()
  
Else

  Debug "No database handle"
  
EndIf
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
IndiQa
New User
New User
Posts: 7
Joined: Thu Jan 22, 2009 4:41 pm
Location: US

Post by IndiQa »

AAAHHHHCCCCHHH............

Thank you.. I am such a db noob......

Curt
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

IndiQa wrote:AAAHHHHCCCCHHH............

Thank you.. I am such a db noob......

Curt
Ha! You should see the wonderful mistakes I make. Some days I shouldn't even get out of bed:)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Post Reply