Difference between revisions of "SQLiteDatabase.OpenBLOB"

From Xojo Documentation

(Created page with '<ShowIf version=2013r1> {{MethodBox | name=OpenBlob | owner=SQLiteDatabase | ownertype=class | scope=public | parameters=tableName As String, columnName As String, row As UIn…')
 
Line 19: Line 19:
 
* Creating a new blob automatically zeros the entire blob
 
* Creating a new blob automatically zeros the entire blob
 
* The row must exist when calling CreateBlob, it does not create a new record for you
 
* The row must exist when calling CreateBlob, it does not create a new record for you
 +
 +
 +
== Example ==
 +
This example reads the Logo (stored as a binary picture) from the Logo column for rowID = 1 in the Team table:
 +
 +
<rbcode>
 +
Dim blob As SQLiteBlob
 +
blob = db.OpenBlob("Team", "Logo", 1, True)
 +
If blob <> Nil Then
 +
  Dim data As String
 +
  While Not blob.EOF
 +
    data = data + blob.Read(1000)
 +
    If blob.ReadError Then
 +
      MsgBox("Error reading from BLOB.")
 +
      Exit While
 +
    End If
 +
  Wend
 +
  blob.Close
 +
  // Do something with the data
 +
End If
 +
</rbcode>
  
  

Revision as of 13:42, 10 April 2013


Method

SQLiteDatabase.OpenBlob(tableName As String, columnName As String, row As UInt64, readWrite As Boolean, databaseName As String = "") As SQLiteBlob

Supported for all project types and targets.

Opens a BLOB column for the specified table and column at the specified row (rowID).


Notes

  • The row parameter is the rowid value, and not the actual row number, for example if you only have one record in your database, with a rowid of 100 then you would pass in a row of 100 and not 1 for example.
  • Pass in false as the readWrite parameter to open the blob for reading only.
  • The blob cannot be resized
  • Creating a new blob automatically zeros the entire blob
  • The row must exist when calling CreateBlob, it does not create a new record for you


Example

This example reads the Logo (stored as a binary picture) from the Logo column for rowID = 1 in the Team table:

Dim blob As SQLiteBlob
blob = db.OpenBlob("Team", "Logo", 1, True)
If blob <> Nil Then
Dim data As String
While Not blob.EOF
data = data + blob.Read(1000)
If blob.ReadError Then
MsgBox("Error reading from BLOB.")
Exit While
End If
Wend
blob.Close
// Do something with the data
End If


See Also

SQLiteBlob, SQLiteDatabase.CreateBlob