How to read SQLite format 3?

Just starting out? Need help? Post your questions and find answers here.
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

How to read SQLite format 3?

Post 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
macOS Catalina 10.15.7
User avatar
spikey
Enthusiast
Enthusiast
Posts: 581
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: How to read SQLite format 3?

Post 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.
Wolfram
Enthusiast
Enthusiast
Posts: 567
Joined: Thu May 30, 2013 4:39 pm

Re: How to read SQLite format 3?

Post by Wolfram »

Thanks, that was the missing step.
macOS Catalina 10.15.7
Post Reply