Reading specific bitmap blop from database

tamadon

Active Member
Licensed User
Longtime User
I have a code something like the following:

Code: Copy
Sub readQuestionData

   Dim imgFile As RandomAccessFile
   Dim buffer() As Byte
   Dim i As Int
   
   cursorQuestion = sqlQuestion.ExecQuery("SELECT * FROM question")
   
   For i = 0 To cursorQuestion.RowCount - 1
      cursorQuestion.Position = i
      buffer = cursorQuestion.GetBlob("QUESTION")
      imgFile.Initialize3(buffer, True)
      imgFile.WriteObject(QuestionList, True, imgFile.CurrentPosition)
      
   Next
   
   cursorQuestion.Close
   
   
   Dim imgIS As InputStream
   Dim imgBuffer() As Byte

   imgBuffer = imgFile.ReadObject(0)
   imgIS.InitializeFromBytesArray(imgBuffer, 0, imgBuffer.Length)
   
   Dim imgQuestion As Bitmap
   imgQuestion.Initialize2(imgIS)
   imgIS.Close
   Activity.SetBackgroundImage(imgQuestion)
   

End Sub

Let say I want to access the first bitmap blob, since the data already in Byte, I just assigned it to

Code: Copy
imgBuffer = imgFile.ReadObject(0)
?

However I get an error saying InputStream is not initialized.

My second question is how do you access a particular blob inside the RandomAccessFile? Can we just use imgIS.ReadObject(0), imgIS.ReadObject(5) and assign those to byte objects?

Thank you.
 
Thanks for the response Erel.

However what I am trying to do is actually read all the image blob and assign them to a list object or something than can hold them, then display one by one in a random order.

That's why I need to know how can I assign blob from RandomAccessFile into a list and randomize the list before displaying the image.
 
Upvote 0
Nevermind I think the way I did it is making it more complicated.

I can just randomize the rowID and pick the associated blob using normal SQL queries!
 
Upvote 0
Back
Top