Hi Duffer123. Here's a fully working example that demonstrates the creation, writing, and reading of such a database, with text and images. You could substitute the images with your own, or download them from the Dropbox links below
Code: Select all
UseSQLiteDatabase()
UseJPEGImageDecoder()
Enumeration
#MainWindow
#img1
#txt1
#txt2
#btn1
#btn2
#dbID
EndEnumeration
Global dbFileName.s = "sample.db", currentRecord = 1
Procedure createSampleDatabase()
If CreateFile(0, dbFileName)
CloseFile(0)
If OpenDatabase(#dbID, dbFileName, "", "")
DatabaseUpdate(#dbID, "CREATE TABLE bio (idx INT, name CHAR(20), picture BLOB, dob CHAR(20))")
Read.s name$
Read.s dob$
SetDatabaseBlob(#dbID, 0, ?picAlbert, ?picIsaac - ?picAlbert)
queryString.s = "INSERT INTO bio (idx, name, picture, dob) values (1, '" + name$ + "', ?, '" + dob$ + "')"
DatabaseUpdate(#dbID, queryString)
Read.s name$
Read.s dob$
SetDatabaseBlob(#dbID, 0, ?picIsaac, ?picLeo - ?picIsaac)
queryString.s = "INSERT INTO bio (idx, name, picture, dob) values (2, '" + name$ + "', ?, '" + dob$ + "')"
DatabaseUpdate(#dbID, queryString)
Read.s name$
Read.s dob$
SetDatabaseBlob(#dbID, 0, ?picLeo, ?binaryEnd - ?picLeo)
queryString.s = "INSERT INTO bio (idx, name, picture, dob) values (3, '" + name$ + "', ?, '" + dob$ + "')"
DatabaseUpdate(#dbID, queryString)
CloseDatabase(#dbID)
EndIf
EndIf
EndProcedure
Procedure getNextRecord()
If DatabaseQuery(#dbID, "SELECT * FROM bio WHERE idx = '" + currentRecord + "'")
While NextDatabaseRow(#dbID)
SetGadgetText(#txt1, GetDatabaseString(#dbID, 1))
pictureSize = DatabaseColumnSize(#dbId, 2)
*picture = AllocateMemory(pictureSize)
GetDatabaseBlob(#dbID, 2, *picture, pictureSize)
CatchImage(1, *picture, pictureSize)
ResizeImage(1, 300, 300)
SetGadgetState(#img1, ImageID(1))
SetGadgetText(#txt2, GetDatabaseString(#dbID, 3))
Wend
FinishDatabaseQuery(#dbID)
FreeMemory(*picture)
EndIf
EndProcedure
createSampleDatabase()
If OpenDatabase(#dbID, dbFileName, "", "")
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, 0, 0, 320, 390, "Database Example", wFlags)
ImageGadget(#img1, 10, 10, 300, 300, 0)
TextGadget(#txt1, 80, 320, 160, 30, "", #PB_Text_Center)
TextGadget(#txt2, 80, 350, 160, 30, "", #PB_Text_Center)
ButtonGadget(#btn1, 10, 320, 60, 30, "<< PREV")
ButtonGadget(#btn2, 250, 320, 60, 30, "NEXT >>")
getNextRecord()
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case #btn1
currentRecord - 1
If currentRecord < 1
currentRecord = 3
EndIf
getNextRecord()
Case #btn2
currentRecord + 1
If currentRecord > 3
currentRecord = 1
EndIf
getNextRecord()
EndSelect
EndSelect
Until appQuit = 1
CloseDatabase(#dbID)
DataSection
bio:
Data.s "Albert Einstein", "March 14, 1879", "Isaac Newton", "January 4, 1643", "Leonardo da Vinci", "April 15, 1452"
picAlbert:
IncludeBinary "albert.jpg"
picIsaac:
IncludeBinary "isaac.jpg"
picLeo:
IncludeBinary "leonardo.jpg"
binaryEnd:
EndDataSection
Alternatively, this zip file contains the source code as well as all the images; just unzip them and run:
Hope it helps.