Page 1 of 1

Read data from a sqlite table

Posted: Thu Feb 26, 2009 9:37 pm
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
-------------------------------------------------------------------------------

Posted: Thu Feb 26, 2009 11:08 pm
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.

Posted: Fri Feb 27, 2009 1:48 am
by IndiQa
Put my code in the first post.

Thanks FB

Posted: Fri Feb 27, 2009 3:19 am
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

Posted: Fri Feb 27, 2009 2:39 pm
by IndiQa
AAAHHHHCCCCHHH............

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

Curt

Posted: Fri Feb 27, 2009 2:44 pm
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:)