Friday, June 13, 2008

export/import contents of a single table in FrontBase

Jon found this:

The WRITE TABLE statement is a way to dump just the content of a table into a flat-file.

Syntax:


WRITE TABLE <table name>
OUTPUT('<path of output file>' [, '<column sep>', '<row sep>']);


Example:


CREATE TABLE T0(C0 INT, C1 VARCHAR(1000000));
INSERT INTO T0 VALUES (1, 'Smith'), (2, 'Jones');
WRITE TABLE T0 OUTPUT('/tmp/T0.txt', '~', '~\n');


Resulting file (T0.txt):


<table Expr>
2
1 "C0","~"
2 "C1","~\n"
1~Smith~
2~Jones~


This file can then be imported into some other table by executing:


INSERT INTO <table name> FROM 'FrontBase' INPUT('/tmp/T0.txt');


Please note that if the column names of the table the data is to be imported into are different, you will have to edit T0.txt accordingly.

A while ago WRITE TABLE was actually enhanced to, in addition to a table name, accept a table expression, i.e. a way to dump out the result set of a SELECT.

Examples:


WRITE TABLE SELECT C1 FROM T0 WHERE C0 < 2 OUTPUT('/tmp/T0.txt', '~', '~\n');

WRITE TABLE VALUES('3⁄4?') OUTPUT('/tmp/T0.txt', '~', '~\n');


The latter example is a good way to see how FrontBase expects national characters to be represented:


<table Expr>
1
1 "_VALUES001","~\n"
\195\166\195\184\195\165\195\134\195\152\195\133~

No comments: