Difference between revisions of "SQLiteDatabase.CreateBLOB"

From Xojo Documentation

(Example)
(Example)
 
Line 40: Line 40:
 
     blob.Write(data)
 
     blob.Write(data)
 
     If blob.WriteError Then
 
     If blob.WriteError Then
       MesageBox("Error writing to BLOB.")
+
       MessageBox("Error writing to BLOB.")
 
       Exit While
 
       Exit While
 
     End If
 
     End If

Latest revision as of 02:50, 26 February 2022

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
MessageBox("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