DataMigrator has the capability to load image files into a database
table by specifying their location in the input data.
The first step is to create a table to store the images. The
table to load should have a column with a data type that can hold
binary data. In the current release of MS SQL Server, that would
be varbinary(max). In previous releases, it is image. In the synonym,
the USAGE and ACTUAL fields for the column are set to BLOB (Binary
Large OBject, as shown in the following image.
The following example outlines the remaining steps needed to
load images into a database table.
Example: Loading Images Into a Database Table
The
first step is to map an application directory. The location of the
files containing the images is specified in the usual appdir/filename
format. To map the application directory:
- Right-click Application
Directories, select New, and
then click Application Directory.
The Create
New Application dialog box opens.
- From the Application Type drop-down menu, select Application
Mapping to Disk.
- In the Application Name box, enter graph.
- In the Physical Location box, enter c:\ibi\srv77\home\graph.
- From the Profile drop-down menu, select the desired profile.
- Click OK.
Next, create a source file
and synonym. The source data needs a list of the names of the image
files. From the DMC:
- Right-click baseapp.
- Select New and then click File.
- Enter names as a header line, followed by the names of
some of the .gif files (without the extension).
- Click the Save button.
- Enter tiles as the name and click OK.
The
following image shows the result.
Then, create a synonym
for the file.
- Right-click Application Directories,
select New, and then click Synonym.
- Select <local> for the Under Delimited
Flat File. Click OK.
- Clear the Create multiple synonyms checkbox and select Server Side for
File Location.
- For Data File, enter baseapp/tiles.txt.
- Click Next twice.
- For Header, select Yes.
- Click Create Synonym
- Click Close.
Next, create a data flow
that loads the images into a database table. The source is the delimited
flat file tiles that contains the names of the image files. The
target is the existing database table textures.
- Right-click baseapp. Select New and
then click Flow.
- Right-click the left side of the workspace, select Add Source,
and then click baseapp/tiles.
- Right-click the right side of the workspace, select Add Target,
then Existing, and then click baseapp/textures.
- Double-click the SQL object to open it.
- Double-click Name to add it to selected
columns. Enter FNAME for SQL Alias.
- Double-click Name and click the calculator
button.
- For Alias, enter PICTURE. For Expression, enter 'graph/'
|| T1.NAME || '.gif'.
- Click the Test SQL button to see the
values for the columns.
- Close the Test SQL dialog box and click OK to
close the SQL object.
- Double-click the Target object.
The Transformations window
opens, as shown in the following image.
- Click the Automap button.
- Click OK to close the Transformations
window.
- On the toolbar, click the Run button
and click Submit.
- Enter loadim for the procedure name and click Save.
Wait
for the completed message to appear in the console log and then
click View Last Log to verify that the three
rows were loaded.
To see the images that were loaded into
the table, you need to write a FOCUS report that sends its output
to a PDF file.
- RIght-click baseapp, select New, and
then click Procedure.
- Enter the following lines:
TABLE FILE textures
PRINT PICTURE
BY FNAME
ON TABLE PCHOLD AS baseapp/texturpt FORMAT PDF
ON TABLE SET STYLE *
TYPE=REPORT,$
TYPE=DATA,COLUMN=PICTURE,IMAGE=(PICTURE),SIZE=(1 1),POSITION=(+0.5 +0.5),$
END
- Click Run.
The PDF file will open in
the workspace.