Sqlite vanishing information!

hi everyone!

i’m very confused…

i have this method. i insert the information. it saves on database. when i quit the app and open again, it’s not there!

why?

Var db As New SQLiteDatabase

Var dbFile As FolderItem = SpecialFolder.resources.Child("mydb.sqlite")

If dbFile <> Nil And dbFile.Exists Then
  db.DatabaseFile = dbFile
  
  Try
    db.Connect
    
    Var row As New DatabaseRow
    
    If idLevel = 0 Then
      row.Column("level").StringValue = levelText
      row.Column("author").StringValue = author
      row.Column("created").StringValue = created
      db.AddRow("levels", row)
    Else
      row.Column("idLevel").IntegerValue = idLevel
      row.Column("level").StringValue = levelText
      row.Column("author").StringValue = author
      row.Column("created").StringValue = created
      Try
        db.AddRow("levels", row)
        
      Catch err As DatabaseException
        // Se já existir, atualiza
        db.ExecuteSQL("UPDATE levels SET level = ?, author = ?, created = ? WHERE idLevel = ?", levelText, author, created, idLevel)
      End Try
    End If
    
    
    // put here just to check…
    Var sql As String = "SELECT * FROM levels"
    Var rs As RowSet = db.SelectSQL(sql)
    Var temp As String
    If rs <> Nil Then
      While Not rs.AfterLastRow
        temp = temp + "ID: " + rs.Column("idLevel").StringValue + ", " + _
        "Level: " + rs.Column("level").StringValue + ", " + _
        "Author: " + rs.Column("author").StringValue + ", " + _
        "Created: " + rs.Column("created").StringValue + EndOfLine
        rs.MoveToNextRow
      Wend
      rs.Close
    End If
    
    
  Catch err As DatabaseException
    MessageBox("Erro: " + err.Message)
  End Try
  
End If

Your database is being copied to your built Resources folder. That’s the SQLite file being modified, which ceases to exist when your debug run ends and a fresh copy is grabbed the next time you debug.

You can use #If DebugBuild Then to use the permanent path in your source directory.

3 Likes

omg, so stupid i was…

thank you!