@@ -63,31 +63,8 @@ char *Escape_db(char *);
6363char * convert_charset (char * string );
6464#endif
6565void usage (void );
66- unsigned int isinteger (char * );
6766
6867
69-
70- unsigned int
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 ((unsigned char ) * 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 */
472449 if (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 */
476460 snprintf (pgdate , 11 , "%c%c%c%c-%c%c-%c%c" ,
477461 foo [0 ], foo [1 ], foo [2 ], foo [3 ],
478462 foo [4 ], foo [5 ], foo [6 ], foo [7 ]);
479463 strcat (query , pgdate );
480464 }
481465 else
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 */
497476 strcat (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 }
504481 else
505482 {
0 commit comments