KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using the Keyword INFILE in the 4D v11.3 SQL Command INSERT
PRODUCT: 4D | VERSION: 11.3 | PLATFORM: Mac & Win
Published On: December 23, 2008

As of Release 3 (11.3) the keyword "INFILE" is new to the SQL Commands avalable in 4D v11 SQL. The INFILE keyword lets you use the contents of an external file to specify the values of a new record. The operative word that bears emphasis is "a", as in a singular record. INFILE is not intended for, nor does it support, multi-row data from one external document. It's purpose is to provide a way to import for one field, data contained in an external file, Text or BLOB. If you are transfering graphics you must first save them as BLOBs. You can include multiple instances of INFILE in the VALUES clause but only on a field by field basis. Here is a generic example:

INSERT INTO {sql_name | sql_string}
[(column_reference, ..., column_reference)]
[VALUES({[INFILE]arithmetic_expression |NULL}, ..., {[INFILE]arithmetic_expression |NULL};)
|subquery]



This keyword must only be used with VARCHAR type expressions. When the INFILE keyword is passed, the arithmetic_expression value is evaluated as a file pathname; if the file is found, the contents of the file are inserted into the corresponding column. Only fields of the Text or BLOB type can receive values from an INFILE. The contents of the file are transferred as raw data, with no interpretation.

The file searched for must be on the computer hosting the SQL engine, even if the query comes from a remote client. Similarly, the pathname must be expressed respecting the syntax of the operating system of the SQL engine. It can be absolute or relative. The examples below are first Mac OS absolute path and then Windows absolute path. The code will insert the entire contents, text or BLOB, of "myfile" into "theColumn".

Begin SQL
  INSERT INTO theTable ( ID, theColumn )
  VALUES (1, INFILE "myHD:myFolder:myFolder2:myFile");

End SQL


Begin SQL
  INSERT INTO theTable ( ID, theColumn )
  VALUES (1, INFILE "C:\\myFolder\myFolder2\myFile");

End SQL