save. Saving string to a file

^string.save[path_and_filename]   
^string.save[append;path_and_filename]
^string.save[path_and_filename;options]
   [3.4.0]   

Saves or appends
string to a file in specified directory.
While being saved, string fragments undergo necessary transformation, see "Transforming data".

The
options are hash, with such keys as:
$.charset[charset]
$.append(true)

Example
Task: retrieve data from SQL-server A and store them to SQL-server B.

If both servers are accessible from some computer, it can be done this way:

^connect[À]{
    $data[
#       code to fill 'data' with data from SQL-server A
    ]
    ^connect[Á]{
         ^
void:sql{insert into table x (x) values ('$data')}
    }
}

In this case,
$data in SQL-query insert will be correctly adapted to SQL-dialect used by server B.

Yet, if one CANNOT access both servers from one computer, the task may be accomplished the following way:

^connect[À]{
    $data[
#       code to fill 'data' with data from SQL-server A
    ]
    $string[^
untaint[sql]{insert into table x (x) values ('$data')}]
    ^connect[local fictitious B]{
#       this connection is needed
#       only to specify rules to conform SQL-syntax used by SQL-server B
        ^string.save[B-inserts.sql]
    }
}

In this case file
B-inserts.sql will contain correctly transformed SQL-query.


Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 19.09.2009