! ! Copyright 1998, Ray Ontko and Co, Richmond, IN, US. ! ! This file may only be used and distributed under the ! terms of the GNU General Public License. See COPYING.TXT ! included with this file for specific terms of the license. ! !++ ! ! Name ! ! csv_import.sqr ! ! Description ! ! This is a sample program which reads a comma-separated, variable- ! length (.csv) file and loads it into a database table. This program ! is intended as a template; modify to suit your needs. ! !-- ! ! Author ! ! Ray Ontko ! Ray Ontko & Co ! rayo@ontko.com ! ! Modification History ! ! Name Date Comment ! ---------------- ---------- ---------------------------------------- ! Ray Ontko 1998/04/23 Created ! #include 'csv.sqh' #define IFILE 1 #define IMAX 1000 begin-program do main end-program ! ! add or remove csv_get_field calls to meet your needs. ! begin-procedure main input $iname 'Input file' open $iname as {IFILE} for-reading record={IMAX}:vary while 1 read {IFILE} into $line:{IMAX} if #end-file break end-if do csv_get_field( $line , $empno ) do csv_get_field( $line , $ename ) do csv_get_field( $line , $sal ) do insert_record add 1 to #count if mod(#count,100)=0 show #count edit 999999 ' records inserted.' end-if end-while close {IFILE} show #count edit 999999 ' records inserted.' end-procedure ! ! modify this insert_record procedure to meet your needs ! begin-procedure insert_record begin-sql insert into emp ( empno , ename , sal ) values ( to_number( $empno ) , $ename , to_number( $sal ) ) end-sql end-procedure ! insert_record