1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
-
- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
- project.
-
- Copyright (C) 1998-2018 OpenLink Software
-
- This project is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; only version 2 of the License, dated June 1991.
-
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
-->
<refentry id="fn_csv_load_file">
<refmeta>
<refentrytitle>csv_load_file</refentrytitle>
<refmiscinfo>file</refmiscinfo>
</refmeta>
<refnamediv>
<refname>csv_load_file</refname>
<refpurpose>Imports a CSV file into table.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<funcsynopsis id="fsyn_csv_load_file">
<funcprototype id="fproto_csv_load_file">
<funcdef><function>csv_load_file</function></funcdef>
<paramdef>in <parameter>file_name</parameter> varchar</paramdef>
<paramdef><optional>in <parameter>from_line</parameter> integer</optional></paramdef>
<paramdef><optional>in <parameter>to_line</parameter> integer</optional></paramdef>
<paramdef><parameter>table_name</parameter> varchar</paramdef>
<paramdef><optional>in <parameter>trx_log_mode</parameter> integer</optional></paramdef>
<paramdef><optional>in <parameter>opts</parameter> any</optional></paramdef>
</funcprototype>
</funcsynopsis>
</refsynopsisdiv>
<refsect1 id="desc_csv_load_file">
<title>Description</title>
<para>Imports a CSV file into table.</para>
</refsect1>
<refsect1 id="params_csv_load_file">
<title>Parameters</title>
<refsect2><title>file_name</title>
<para>Given as an input file_name will be parsed as CSV where it will
insert into the table specified as table_name the lines between from_line and to_line offsets.
</para>
</refsect2>
<refsect2><title>from_line</title>
<para>Default - 0, This means counted from the begining.</para>
</refsect2>
<refsect2><title>to_line</title>
<para>Default - null, This means counted to the end.</para>
</refsect2>
<refsect2><title>table_name</title>
<para>The table the data to be inserted into.</para>
</refsect2>
<refsect2><title>trx_log_mode</title>
<para>Default - 2. The trx_log_mode is used to do row auto commit and to log
or not the transaction. The default mode is to do not log and do auto commit.</para>
</refsect2>
<refsect2><title>opts</title>
<para>Default - null. The opts paramater is used to specify the delimiter
and quote. It should look like this:
</para>
<programlisting><![CDATA[
vector ('csv-delimiter', self.delim, 'csv-quote', self.quot)
]]></programlisting>
</refsect2>
</refsect1>
<!--<refsect1 id="ret_csv_load_file"><title>Return Types</title>
<para>Returns a vector with field values.</para>
</refsect1>-->
<refsect1 id="errors_csv_load_file">
<title>Errors</title>
<para>If table is not suitable in respect of number of columns or
type of columns error will be signaled.</para>
</refsect1>
<refsect1 id="examples_csv_load_file">
<title>Examples</title>
<example id="ex_csv_load_file"><title>Simple Use</title>
<programlisting><![CDATA[
SQL>create procedure my_csv_lf (in file_name varchar)
{
declare tb_name varchar;
declare ar any;
-- to get the name of the table
ar := csv_table_def(file_name);
ar := split_and_decode(ar, 0,'\0\0 ');
tb_name := trim (ar[2], '"');
dbg_obj_print(tb_name);
-- to create the table
exec(csv_table_def(file_name));
-- loading the data
csv_load_file(file_name,0, null, concat('DB.DBA.', tb_name));
}
;
Done. -- 10 msec.
SQL>select my_csv_lf('tmp/MyContacts.csv');
callret
VARCHAR
______________________________________________
0
1 Rows. -- 231 msec.
SQL>select * from DB.DBA.tmp_MyContacts_csv;
First_Name_Last_Name_Middle_Name_Name_Nickname_E_mail_Addre
VARCHAR
_______________________________________________________________________________
First Name;Last Name;Middle Name;Name;Nickname;E-mail Address;Home Street;Home City;Home Postal Code;Home State;Home Country/Region;Home Phone;Home Fa
x;Mobile Phone;Personal Web Page;Business Street;Business City;Business Postal Code;Business State;Business Country/Region;Business Web Page;Business
Phone;Business Fax;Pager;Company;Job Title;Department;Office Location;Notes
;;; Virtuoso Nightly Builds on oplusaix2 ;;virtuoso-nightly-builds@openlinksw.com;;;;;;;;;;;;;;;;;;;;;;;
......
202 Rows. -- 341 msec.
]]></programlisting>
</example>
</refsect1>
<refsect1 id="seealso_csv_load_file">
<title>See Also</title>
<para><link linkend="fn_get_csv_row"><function>get_csv_row</function></link></para>
<para><link linkend="fn_csv_load"><function>csv_load</function></link></para>
<para><link linkend="fn_csv_parse"><function>csv_parse</function></link></para>
<para><link linkend="fn_csv_cols_def"><function>csv_cols_def</function></link></para>
<para><link linkend="fn_csv_table_def"><function>csv_table_def</function></link></para>
</refsect1>
</refentry>
|