SetDatabaseBlob()

Syntax

SetDatabaseBlob(#Database, StatementIndex, *Buffer, BufferLength)
Description
Set the blob for future use with DatabaseUpdate().

Parameters

#Database The database to use.
StatementIndex Undefined query parameter index the blob should be inserted for. The first undefined parameter index starts from zero. The SQL syntax to specify undefined parameter is database manager dependent. See the following examples to see how to proceed.
*Buffer The address of the blob data.
BufferLength The size of the blob data in bytes.

Return value

None.

Example

  ; Create a new empty database in memory
  If OpenDatabase(0) 
  
    ; Add new table in it
    DatabaseUpdate(0, "CREATE TABLE food (name CHAR(50), image BLOB)")
    
    
    ; Create a dummy blob (125 kb)
    *Buffer = AllocateMemory(125000)
    
    ; Add a record with a blob. For this, we need to use the bind method using '?'
    SetDatabaseString(0, 0, "blob test")
    SetDatabaseBlob(0, 1, *Buffer, MemorySize(*Buffer)) ; Assign it to the 2nd paramater
    
    DatabaseUpdate(0, "INSERT INTO food (name, image) VALUES (?, ?)")
    
    ; Now check if it's really in the db
    If DatabaseQuery(0, "SELECT * FROM food")
    
      While NextDatabaseRow(0)
        Debug "name: '" + GetDatabaseString(0, 0) + "', blob size: " + MemorySize(GetDatabaseBlob(0, 1))
      Wend
    
      FinishDatabaseQuery(0)
    Else 
      Debug  "query error: " + DatabaseError()
    EndIf
  EndIf

See Also

DatabaseUpdate(), GetDatabaseBlob()
<- OpenDatabase() - Database Index - SetDatabaseDouble() ->