xHarbour Reference Documentation > Function Reference |
Imports a file into a binary large object (BLOB).
BlobDirectImport( <nOldBlobID>, <cSourceFile> ) --> nNewBlobID
All data of <nOldBlobID> is discarded, and the BLOB receives a new ID which is returned by the function. If zero is passed, a new BLOB is added to the BLOB file.
If <cSourceFile> does not exist, a runtime error is raised. If the file cannot be opened due to another process having exclusive access to the file, function NetErr() is set to .T. (true).
The function returns a numeric value which is the BLOB identifier of the new BLOB. The return value is zero, when the operation fails.
BlobDirectImport() copies the contents of an external file into a single binary large object (BLOB). The object is identified by its numeric ID. A BLOB is stored either in a memo field (DBFCDX RDD) or in a stand alone DBV file which is not associated with a database file (DBFBLOB RDD). BlobDirectImport() is usually required for the latter case. If BLOBs are stored in a database with an associated memo file, function FieldPut() is more comfortable to use, since it accepts a numeric field position of a memo field, rather than a numeric Blob identifier.
The numeric Blob ID is obtained using DbFieldInfo() or must be taken from the array returned by BlobRootGet().
When data is imported into an existing BLOB, the BLOB is entirely discarded and a new BLOB is created. As a consequence, the existing BLOB ID <nOldBlobID> becomes invalid, and BlobDirectImport() returns a new BLOB ID. The imported data can only be accessed via the new BLOB ID.
Notes: BLOBs are stored in memo files having the .FPT or .DBV extension. They are maintained by the RDDs DBFCDX or DBFBLOB. DBFNTX, in contrast, does not support BLOBs.
The file Blob.ch must be #included for BlobDirectImport() to work.
See also: | BlobDirectGet(), BlobDirectExport(), BlobExport(), BlobGet(), BlobImport(), BlobRootGet(), DbFieldInfo() |
Category: | Blob functions , Database functions |
Header: | blob.ch |
Source: | rdd\dbcmd.c, rdd\dbffpt\dbffpt1.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example demonstrates how to import JPG files into a DBV file. #include "Blob.ch" REQUEST DBFBLOB PROCEDURE Main LOCAL aFile LOCAL aFiles := Directory( "*.jpg" ) LOCAL aBlobID := {} DbCreate( "ImageArchive", {}, "DBFBLOB" ) USE ImageArchive NEW VIA "DBFBLOB" FOR EACH aFile IN aFiles AAdd( aBlobID, BlobDirectImport( 0, aFile[1] ) ) NEXT IF BlobRootLock() .AND. BlobRootPut( aBlobID ) BlobRootUnlock() ELSE Alert( "Unable to lock BLOB root;try again later" ) ENDIF USE RETURN
http://www.xHarbour.com