Page 1 of 1

How to read SQLite format 3?

Posted: Thu May 18, 2017 5:41 pm
by Wolfram
I'm try to read a file which seams to be a SQLite format 3 file, abut I can't see any records.
What do I wrong?

Code: Select all

UseSQLiteDatabase()

DatabaseFile$ = "/Users/Me/Desktop/MyDatabase"


If OpenDatabase(0, DatabaseFile$, "", "")
  
    Debug DatabaseColumns(0)
    Debug DatabaseColumnName(0, 0)
    
    While NextDatabaseRow(0)
      Debug GetDatabaseString(0, 0)
    Wend

  
    CloseDatabase(0)
    
Else
  Debug "Can't open database !"
EndIf

Re: How to read SQLite format 3?

Posted: Thu May 18, 2017 6:19 pm
by spikey
Although you've opened the database, you haven't performed actually a query of any kind.
Consequently all the query dependent commands which follow have no results - which is why you aren't seeing any!

Try this, if the file is an SQLite3 database it should list the names of all the tables present in the file.

An important warning though - don't alter sqlite_master using an update - not if you want to keep your database working anyway!

Code: Select all

UseSQLiteDatabase()

DatabaseFile$ = "/Users/Me/Desktop/MyDatabase"

If OpenDatabase(0, DatabaseFile$, "", "")
  
  If DatabaseQuery(0, "select * from sqlite_master where type = 'table';")
    
    While NextDatabaseRow(0)
      Debug GetDatabaseString(0, 0) + " " + GetDatabaseString(0, 1)
    Wend
    
    FinishDatabaseQuery(0)
  Else
    Debug DatabaseError()

  EndIf
  
  CloseDatabase(0)
  
Else
  Debug "Can't open database !"
  Debug DatabaseError()
EndIf
Once you know the table names you can change the query to be something like "select * from tablename;" to see what data they contain.

Re: How to read SQLite format 3?

Posted: Fri May 19, 2017 9:00 am
by Wolfram
Thanks, that was the missing step.