SQLiteDatabase.CreateBLOB

From Xojo Documentation

Revision as of 19:28, 18 February 2022 by Gperlman (talk | contribs) (Example)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
Method

SQLiteDatabase.CreateBlob(tableName As String, columnName As String, row As UInt64, length As UInt64, databaseName As String = "") As SQLiteBlob

Supported for all project types and targets.

Creates a new 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.
  • 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

You can use the Database constants: MainDatabase ("main") and TempDatabase ("temp") as necessary.

Example

This example stores a picture in a BLOB (db is a preexisting database):

Var file As FolderItem
file = FolderItem.ShowOpenFileDialog("")

Var blob As SQLiteBlob
Var dbRowID As Integer = 1
blob = db.CreateBlob("Team", "Logo", dbRowID, file.Length)

If blob <> Nil Then
Var bd As BinaryStream
bd = BinaryStream.Open(file, False)

Var data As String
While Not bd.EOF
data = bd.Read(1000)

blob.Write(data)
If blob.WriteError Then
MesageBox("Error writing to BLOB.")
Exit While
End If
Wend
bd.Close
blob.Close

// Do something with the data
End If

See Also

SQLiteBlob, SQLiteDatabase.OpenBlob