ef7ad30f8fa8fca5c4fac2fcf99a4ecdc92dfceb
3 /***************************************************************************
4 * Copyright (C) 2003-2007 Polytechnique.org *
5 * http://opensource.polytechnique.org/ *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the Free Software *
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
21 ***************************************************************************/
23 // {{{ function showHelp()
25 function showHelp($error = null
) {
27 echo 'Ligne de commande non-valide : ' . $error, "\n\n";
29 echo 'csv2sql.php -t table [-i source] [-r phpfile]', "\n\n";
30 echo 'options:', "\n";
31 echo ' -t table: table in which insertion is to be done', "\n";
32 echo ' -i source: CSV source file (stdin if not defined or if source is \'-\'', "\n";
33 echo ' -r phpfile: PHP file which define relations', "\n";
37 // {{{ function processArgs()
39 function processArgs()
41 global $sourceName, $table, $includedFile;
42 $opts = getopt('i:t:r:d:');
43 if ($opts['i'] == '-' ||
empty($opts['i'])) {
44 $sourceName = 'php://stdin';
46 $sourceName = $opts['i'];
49 if ($opts['r'] && !empty($opts['r'])) {
50 $includedFile = $opts['r'];
53 if (!$opts['t'] ||
empty($opts['t'])) {
54 showHelp('Table non définie');
63 require_once(dirname(__FILE__
) . '/../classes/csvimporter.php');
64 require_once(dirname(__FILE__
) . '/../classes/xdb.php');
66 $source = file_get_contents($sourceName);
67 $insert_relation = null
;
68 $update_relation = null
;
71 if (isset($includedFile)) {
72 require_once($includedFile);
75 $translater = new CSVImporter($table, $key, !$debug);
76 $translater->setCSV($source);
77 $translater->run($action, $insert_relation, $update_relation);
79 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: