OpenVMS Source-Code Demos

mysql_import_helper_basic_template_107_part3

	!
	! start of template 3/3
	!33333333333333333333333333333333333333333333333333333333333333333333333
	!=======================================================================
	! file   : mysql_import_helper_basic_template_106_part7.bas
	! author : Neil Rieck
	! history:
	! 100 NSR 140708 original effort
	! 101 NSR 150106 added code to debug a corrupt datafile
	! 102 NSR 160226 documentation changes in utf-8 area
	! 103 NSR 170314 changes to the unicode routine
	! 106 NSR 170314 adding true unicode support
	!     NSR 170315 more work
	!     NSR 170316 appended two new external functions
	! 107 NSR 200106 1. modified code to do better unicode data conversion to ISO (picking up new modules)
	!		 2. changed the default datatype from UTF-8 to CP1252
	!     NSR 200107 3. modified code to do better unicode data conversion to CP1252 (picking up new modules)
	!         200108 4. disabled "set character-set='latin1';" (now do something similar in "load data")
	!	  200109 5. a few more changes after a good night's sleep (I'm now dreaming in code again)		bf_107.5
	!=======================================================================
		count_o% = count_o% + 1						!
	    next								!
	use									!
	    handler_error% = err						! oops
	end when								!
	select handler_error%							!
	    case 11								!
		print "-i-status :"; handler_error%				!
	    case else								!
		print "-e-status :"; handler_error%				!
	end select								!
	print "-i-finish : "+ date4$(0) +" "+ time$(0)				!
	print "-i-records read   :"; count_i%)					!
	print "-i-records written:"; count_o%)					!
	if handler_error% <> 11 then						!
	    when error in							!
		print "-w-additional information"; bel				!
		print "   VMS-STATUS: ";vmsstatus				!
		print "   RMS-STATUS: ";RMSSTATUS( 100%, STATUS )		!
		print "   RMS-VALUE : ";RMSSTATUS( 100%, VALUE )		!
		sleep 1								!
	    use									!
	    end when								!
	end if									!
	print "-i-closing channels"						!
	when error in								!
	    close #100								!
	    close #99								!
	use									!
	end when								!
	print "-i-program exit -------------------------"			!
32000	end									! <<<---***
	!#######################################################################
	!	external functions
	!#######################################################################
	!
	!	cleanup the data before writing to csv
	!
32100	function string cleanup(string inbound$, long requested_datatype%)	!
	option type=explicit							!
	external string function unicode_array_to_iso(long dim(),long)		!					ver_107.1
	external string function unicode_array_to_cp1252(long dim(),long)	!					ver_107.3
	external long	function mixed_to_unicode_array(string,long dim())	!					ver_107.3
	external string	function unicode_array_to_utf8(long dim(),long)		!					ver_107.3
	declare  string	junk$							!
	declare  long	char_count%						!
	declare  long   unicode%(511)						! 511 4-byte wide characters per line
	!-----------------------------------------------------------------------
	!	main (of the function)
	!-----------------------------------------------------------------------
	junk$ = edit$(inbound$, 128+16+8)					! trailing, compress, leading (DO NOT upcase)
	!
	!    There are two ways import a backslash
	!    1) use this clause in your import statement: FIELDS ESCAPED BY ''
	!	because escape is defaulted to "\"
	!    2) remove the backsashes from the data
	!
!	declare long i%, j%					x
!	j% = len(junk$)						x
!	for i% = 1 to j%					x
!	    if  mid$(junk$,i%,1) = "\" then			x
!		mid$(junk$,i%,1) = "/"				x
!	    end if						x
!	end if							x
	!
	select requested_datatype%					!
	case 0								! as-is (do nothing)
	case 1								! ISO-8859-1
	    char_count% = mixed_to_unicode_array(junk$,unicode%())	! assume it is mixed (fix up what you can)
	    unicode%(0) = char_count%					!
	    junk$ = unicode_array_to_iso(unicode%(),7%)			! convert to ISO
	case 2								! cp-1252
	    char_count% = mixed_to_unicode_array(junk$,unicode%())	! assume it is mixed (fix up what you can)
	    unicode%(0) = char_count%					!
	    junk$ = unicode_array_to_cp1252(unicode%(),7%)		! convert to CP1252
	case 3								! utf8
	    char_count% = mixed_to_unicode_array(junk$,unicode%())	!
	    unicode%(0) = char_count%					!
	    junk$ = unicode_array_to_utf8(unicode%(),7%) 		!
	end select							!
	!
	cleanup = junk$						!
	end function						!
	!
32120	%include "[code.dvlp.fun]mixed_to_unicode_array_107.fun"
	!
32130	%include "[code.dvlp.fun]unicode_array_to_utf8_107.fun"
	!
32140   %include "[code.dvlp.fun]unicode_array_to_iso_107.fun"
	!
32150   %include "[code.dvlp.fun]unicode_array_to_cp1252_107.fun"
	!
	!33333333333333333333333333333333333333333333333333333333333333333333333
	! end of template 3/3
	!