[ Pobierz całość w formacie PDF ]
.Before you store these items in the database, you createor manage them as platform- or product-specific files or data structures, such as:TIFF, PICT,.BMP,.WMF,.GEM, TARGA or other bitmapped or vector-graphic filesMIDI or.WAV sound filesAudio Video Interleaved Format (.AVI) or QuickTime video filesASCII,.MIF,.DOC,.WPx or other text filesCAD filesYou must programmatically load these files from memory into the database, as you doany other data items or records you intend to store in InterBase.For more informationabout creating a Blob and storing data into it, see Writing data to a Blob on page 122.Blob subtypesAlthough you manage Blob data in ways similar to other datatypes, InterBase providesmore flexible data typing rules for Blob data.Because there are many native datatypesthat you can define as Blob data, InterBase treats them generically and allows you todefine your own datatype, known as a subtype.InterBase also provides two predefinedsubtypes: 0, an unstructured subtype generally applied to binary data or data of anindeterminate type, and 1, applied to plain text.User-defined subtypes must always be represented as negative integers between 1 and 32,678.A Blob column s subtype is specified when the Blob column is defined.API GUIDE 115CHAPTER 7 WORKING WITH BLOB DATAThe application is responsible for ensuring that data stored in a Blob column agrees withits subtype; InterBase does not check the type or format of Blob data.Blob database storageRather than storing Blob data directly in the Blob field of a table record, InterBase storesa Blob ID there.A Blob ID is a unique numeric value that references Blob data.The Blobdata is stored elsewhere in the database, in a series of Blob segments, units of Blob dataread and written in chunks.Blob segments can be of varying length.The length of anindividual segment is specified when it is written.Segments are handy when working with data that is too large for one application memorybuffer.But it is not necessary to use multiple segments; you can put all your Blob data ina single segment.When an application creates a Blob, it must write data to it a segment at a time.When anapplication reads a Blob, it reads a segment at a time.For more information about writingsegments, see Writing data to a Blob on page 122.For more information aboutreading segments, see Reading data from a Blob on page 117.Blob data operationsInterBase supports the following operations on Blob data:Reading from a BlobWriting to a Blob, which involves the following operations:1.Inserting a new row that includes Blob data.2.Replacing the data referenced by a Blob column of a row.3.Updating the data referenced by a Blob column of a row.Deleting a BlobThe following sections describe how to perform these operations.These examples do notinclude the use of filters to convert data from one subtype to another as it is read orwritten.For information about using filters, see Writing an application that requestsfiltering on page 139.116 INTERBASE 5BLOB DATA OPERATIONSDynamic SQL (DSQL) API functions and the XSQLDA data structure are needed to executeSELECT, INSERT, and UPDATE statements required to select, insert, or update relevant Blobdata.The following sections include descriptions of the DSQL programming methodsrequired to execute the sample statements provided.For more information about DSQLprogramming, see Chapter 6, Working with Dynamic SQL.Reading data from a BlobThere are six steps required for reading data from an existing Blob:1.Create a SELECT statement query that specifies selection of the Blob column(and any other columns desired) in the rows of interest.2.Prepare an output XSQLDA structure to hold the column data for each row thatis fetched.3.Prepare the SELECT statement for execution.4.Execute the statement.5.Fetch the selected rows one by one.6.Read and processing the Blob data from each row.Creating the SELECT statementElicit a statement string from the user or create one that consists of the SQL query thatwill select rows containing the Blob data of interest.For example, the following createsan SQL query statement string that selects three columns from various rows in thePROJECT table:char *str ="SELECT PROJ_NAME, PROJ_DESC, PRODUCT FROM PROJECT WHERE \PRODUCT IN ("software", "hardware", "other") ORDER BY PROJ_NAME";Preparing the output XSQLDAMost queries return one or more rows of data, referred to as a select-list
[ Pobierz całość w formacie PDF ]