Hello my sqlite script dont save.
mysql:
downloads:
and the startcode:
and the log: INSERT INTO `downloads` (`trackID`) VALUES ('14')
but the db is empty
mysql:
B4X:
Sub Class_Globals
Public sql As SQL
End Sub
Sub createTable(db As String)
If db.EqualsIgnoreCase("tracks") Then
'Füllen
End If
If db.EqualsIgnoreCase("playlist") Then
sql.ExecNonQuery("CREATE TABLE IF NOT EXISTS `playlist` (`id` INTEGER Not Null PRIMARY KEY AUTOINCREMENT, `trackID` INTEGER);")
End If
If db.EqualsIgnoreCase("favorites") Then
sql.ExecNonQuery("CREATE TABLE IF NOT EXISTS `favorites` (`id` INTEGER Not Null PRIMARY KEY AUTOINCREMENT, `trackID` INTEGER);")
End If
If db.EqualsIgnoreCase("downloads") Then
sql.ExecNonQuery("CREATE TABLE IF NOT EXISTS `downloads` (`id` INTEGER Not Null PRIMARY KEY AUTOINCREMENT, `trackID` INTEGER, `key` INTEGER);")
End If
If db.EqualsIgnoreCase("settings") Then
'füllen
End If
End Sub
Public Sub Initialize(db As String)
If db.EqualsIgnoreCase("tracks") Then
sql.Initialize(File.DirDocuments,"database.sqlite",True)
createTable(db)
End If
If db.EqualsIgnoreCase("playlist") Then
sql.Initialize(File.DirDocuments,"playlist.sqlite",True)
createTable(db)
End If
If db.EqualsIgnoreCase("favorites") Then
sql.Initialize(File.DirDocuments,"favorites.sqlite",True)
createTable(db)
End If
If db.EqualsIgnoreCase("downloads") Then
sql.Initialize(File.DirDocuments,"downloads.sqlite",True)
createTable(db)
End If
If db.EqualsIgnoreCase("settings") Then
sql.Initialize(File.DirDocuments,"settings.sqlite",True)
createTable(db)
End If
End Sub
Public Sub my_sql_load_wert(table As String, index As String, indexwert As String, suche As String, zusatz As String) As String
Dim rs As ResultSet
rs = sql.ExecQuery("SELECT * FROM `" & table & "` WHERE `" & index & "`='" & indexwert & "' " & zusatz)
If rs.NextRow = True Then
Return rs.GetString(suche)
End If
Return Null
End Sub
Public Sub my_sql_load_arr(table As String, index As String, indexwert As String, suche As String, zusatz As String) As List
Dim l As List
l.Initialize()
Dim rs As ResultSet
rs = sql.ExecQuery("SELECT * FROM `" & table & "` WHERE `" & index & "`='" & indexwert & "' " & zusatz)
Do While rs.NextRow == True
Try
l.Add(rs.GetString(suche))
Catch
Log(LastException)
End Try
Loop
Return l
End Sub
Public Sub my_sql_load_arr2(table As String, suche As String, zusatz As String) As List
Dim l As List
l.Initialize()
Dim rs As ResultSet
rs = sql.ExecQuery("SELECT * FROM `" & table & "` " & zusatz)
Do While rs.NextRow == True
Try
l.Add(rs.GetString(suche))
Catch
Log(LastException)
End Try
Loop
Return l
End Sub
Public Sub my_sql_new_wert(table As String, index As String, indexwert As String) As Int
Dim rs As ResultSet
Log("INSERT INTO `" & table & "` (`" & index & "`) VALUES ('" & indexwert & "')")
rs = sql.ExecQuery("INSERT INTO `" & table & "` (`" & index & "`) VALUES ('" & indexwert & "')")
Return rs.ColumnCount
End Sub
Public Sub my_sql_update_wert(table As String, index As String, indexwert As String, update As String, updatewert As String)
End Sub
Public Sub my_sql_exists_wert(table As String, index As String, indexwert As String)
End Sub
Public Sub ExecNonQuery(s As String)
sql.ExecNonQuery(s)
End Sub
Public Sub ExecMysqlQuery(s As String) As ResultSet
Try
Dim rs As ResultSet = sql.ExecQuery(s)
Return rs
Catch
Log(LastException)
Return Null
End Try
End Sub
Sub CStr(o As Object) As String
Return "" & o
End Sub
Sub CInt(o As Object) As Int
Return Floor(o)
End Sub
Sub CLng(o As Object) As Long
Return Floor(o)
End Sub
downloads:
B4X:
Sub Class_Globals
Dim sql As mysql
Dim binaural As Boolean
End Sub
Public Sub Initialize(b As Boolean)
sql.Initialize("downloads")
binaural = b
End Sub
Public Sub getDownloads As List
Return sql.my_sql_load_arr2("downloads", "trackID", "")
End Sub
Public Sub addDownload(id As String)
sql.my_sql_new_wert("downloads", "trackID", id)
End Sub
Public Sub removeDownload(id As String)
sql.ExecNonQuery("DELETE FROM `downloads` WHERE `trackID` = '" & id & "'")
Dim sql2 As mysql
sql2.Initialize("tracks")
If binaural Then
File.Delete(File.DirDocuments, sql2.my_sql_load_wert("tracks", "id", id, "binuralFile", ""))
Else
File.Delete(File.DirDocuments, sql2.my_sql_load_wert("tracks", "id", id, "isocronFile", ""))
End If
End Sub
and the startcode:
B4X:
Dim d As downloads
d.Initialize(true)
d.addDownload(14)
and the log: INSERT INTO `downloads` (`trackID`) VALUES ('14')
but the db is empty