GetDatabaseBlob()

Syntax

*Buffer = GetDatabaseBlob(#Database, Column)
Description
Returns the content of the specified database colum as a new memory buffer. This command is only valid after a successful FirstDatabaseRow() or NextDatabaseRow().

Parameters

#Database The database to use.
Column The column to use. DatabaseColumnIndex() is available to get the index of a named column.

Return value

Returns the new memory buffer contained the blob, or zero if it failed. The returned memory buffer is allocated with AllocateMemory()() and must be freed with FreeMemory()() when no more used.

Remarks

To determine the size of the blob, MemorySize() can be used.

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

GetDatabaseDouble(), GetDatabaseFloat(), GetDatabaseLong(), GetDatabaseString(), GetDatabaseQuad()

Supported OS

All

<- FirstDatabaseRow() - Database Index - GetDatabaseDouble() ->