Please tell me how you can create a simple database. I think I need only one table inside and two columns(both type are string). The first is the full path to the file, the second is md5-hash. I already have all data in the list(json-file). And now I would like to transfer them to the database. What is goal? I want to find all duplicate files by hash data. So I decided to use sqlite. Now the list has this structure:
Code: Select all
Structure LogData
FullPath.s
FSize.q
FHash.s
EndStructure
Global NewList FObjects.LogData()
Code: Select all
UseSQLiteDatabase()
dbfile$ = "db.sqlite"
If CreateFile(0, dbfile$)
CloseFile(0)
glDBSQLite = OpenDatabase(0, dbfile$, "", "", #PB_Database_SQLite)
If glDBSQLite
psSQLRequest.s = "CREATE TABLE IF NOT EXISTS fobjects ("
psSQLRequest + "id_fobject INTEGER PRIMARY KEY AUTOINCREMENT Not NULL, "
psSQLRequest + "fobject_fpath TEXT Not NULL, "
psSQLRequest + "fobject_hash TEXT Not NULL, "
psSQLRequest + "fobject_size INTEGER"
psSQLRequest + ")"
If DatabaseUpdate(glDBSQLite, psSQLRequest)=0
MessageRequester("error", "can't create the table"+#CRLF$+DatabaseError())
Else
FinishDatabaseQuery(glDBSQLite)
; FirstDatabaseRow(0)
; ForEach FObjects()
; SetDatabaseString(glDBSQLite, 0, FObjects()\FullPath)
; SetDatabaseString(glDBSQLite, 1, FObjects()\FHash)
; NextDatabaseRow(glDBSQLite)
; Next
ForEach FObjects()
psSQLRequest = "INSERT INTO fobjects"
psSQLRequest + "(fobject_fpath, fobject_hash, fobject_size)"
psSQLRequest + "VALUES ("
psSQLRequest + "'"+FObjects()\FullPath+"',"
psSQLRequest + "'"+FObjects()\FHash+"',"
psSQLRequest + "'"+FObjects()\FSize+"')"
If DatabaseUpdate(glDBSQLite, psSQLRequest) = 0
MessageRequester("error", "can't insert data into the table"+#CRLF$+DatabaseError())
EndIf
Next
CloseDatabase(glDBSQLite)
EndIf
Else
MessageRequester("error", "can't open the table"+#CRLF$+DatabaseError())
EndIf
Else
MessageRequester("error", "can't create the db-file")
EndIf