@@ -63,31 +63,8 @@ char *Escape_db(char *);
6363char * convert_charset (char * string );
6464#endif
6565void usage (void );
66- unsignedint isinteger (char * );
6766
6867
69-
70- unsignedint
71- isinteger (char * buff )
72- {
73- char * i = buff ;
74-
75- while (* i != '\0' )
76- {
77- if (i == buff )
78- if ((* i == '-' )||
79- (* i == '+' ))
80- {
81- i ++ ;
82- continue ;
83- }
84- if (!isdigit ((unsignedchar )* i ))
85- return 0 ;
86- i ++ ;
87- }
88- return 1 ;
89- }
90-
9168static inline void
9269strtoupper (char * string )
9370{
@@ -471,35 +448,35 @@ do_inserts(PGconn *conn, char *table, dbhead * dbh)
471448/* handle the date first - liuk */
472449if (fields [h ].db_type == 'D' )
473450{
474- if (( strlen (foo )== 8 ) && isinteger ( foo ) )
451+ if (strlen (foo )== 0 )
475452{
453+ /* assume empty string means a NULL */
454+ strcat (query ,"\\N" );
455+ }
456+ else if (strlen (foo )== 8 &&
457+ strspn (foo ,"0123456789" )== 8 )
458+ {
459+ /* transform YYYYMMDD to Postgres style */
476460snprintf (pgdate ,11 ,"%c%c%c%c-%c%c-%c%c" ,
477461foo [0 ],foo [1 ],foo [2 ],foo [3 ],
478462foo [4 ],foo [5 ],foo [6 ],foo [7 ]);
479463strcat (query ,pgdate );
480464}
481465else
482466{
483- /*
484- * empty field must be inserted as NULL value in
485- * this way
486- */
487- strcat (query ,"\\N" );
467+ /* try to insert it as-is */
468+ strcat (query ,foo );
488469}
489470}
490- else if ((fields [h ].db_type == 'N' )&&
491- (fields [h ].db_dec == 0 ))
471+ else if (fields [h ].db_type == 'N' )
492472{
493- if (isinteger (foo ))
494- strcat (query ,foo );
495- else
473+ if (strlen (foo )== 0 )
496474{
475+ /* assume empty string means a NULL */
497476strcat (query ,"\\N" );
498- if (verbose )
499- fprintf (stderr ,"Illegal numeric value found "
500- "in record %d, field \"%s\"\n" ,
501- i ,fields [h ].db_name );
502477}
478+ else
479+ strcat (query ,foo );
503480}
504481else
505482{