mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
Clean up bogus checking of date and numeric fields in DBF files,
per report from Boris van Schooten.
This commit is contained in:
parent
fbdb203a39
commit
b4176e9f4c
@ -63,31 +63,8 @@ char *Escape_db(char *);
|
|||||||
char *convert_charset(char *string);
|
char *convert_charset(char *string);
|
||||||
#endif
|
#endif
|
||||||
void usage(void);
|
void usage(void);
|
||||||
unsigned int isinteger(char *);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unsigned int
|
|
||||||
isinteger(char *buff)
|
|
||||||
{
|
|
||||||
char *i = buff;
|
|
||||||
|
|
||||||
while (*i != '\0')
|
|
||||||
{
|
|
||||||
if (i == buff)
|
|
||||||
if ((*i == '-') ||
|
|
||||||
(*i == '+'))
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!isdigit((unsigned char) *i))
|
|
||||||
return 0;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
strtoupper(char *string)
|
strtoupper(char *string)
|
||||||
{
|
{
|
||||||
@ -471,8 +448,15 @@ do_inserts(PGconn *conn, char *table, dbhead * dbh)
|
|||||||
/* handle the date first - liuk */
|
/* handle the date first - liuk */
|
||||||
if (fields[h].db_type == 'D')
|
if (fields[h].db_type == 'D')
|
||||||
{
|
{
|
||||||
if ((strlen(foo) == 8) && isinteger(foo))
|
if (strlen(foo) == 0)
|
||||||
{
|
{
|
||||||
|
/* assume empty string means a NULL */
|
||||||
|
strcat(query, "\\N");
|
||||||
|
}
|
||||||
|
else if (strlen(foo) == 8 &&
|
||||||
|
strspn(foo, "0123456789") == 8)
|
||||||
|
{
|
||||||
|
/* transform YYYYMMDD to Postgres style */
|
||||||
snprintf(pgdate, 11, "%c%c%c%c-%c%c-%c%c",
|
snprintf(pgdate, 11, "%c%c%c%c-%c%c-%c%c",
|
||||||
foo[0], foo[1], foo[2], foo[3],
|
foo[0], foo[1], foo[2], foo[3],
|
||||||
foo[4], foo[5], foo[6], foo[7]);
|
foo[4], foo[5], foo[6], foo[7]);
|
||||||
@ -480,27 +464,20 @@ do_inserts(PGconn *conn, char *table, dbhead * dbh)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
/* try to insert it as-is */
|
||||||
* empty field must be inserted as NULL value in
|
|
||||||
* this way
|
|
||||||
*/
|
|
||||||
strcat(query, "\\N");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ((fields[h].db_type == 'N') &&
|
|
||||||
(fields[h].db_dec == 0))
|
|
||||||
{
|
|
||||||
if (isinteger(foo))
|
|
||||||
strcat(query, foo);
|
strcat(query, foo);
|
||||||
else
|
|
||||||
{
|
|
||||||
strcat(query, "\\N");
|
|
||||||
if (verbose)
|
|
||||||
fprintf(stderr, "Illegal numeric value found "
|
|
||||||
"in record %d, field \"%s\"\n",
|
|
||||||
i, fields[h].db_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (fields[h].db_type == 'N')
|
||||||
|
{
|
||||||
|
if (strlen(foo) == 0)
|
||||||
|
{
|
||||||
|
/* assume empty string means a NULL */
|
||||||
|
strcat(query, "\\N");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
strcat(query, foo);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcat(query, foo); /* must be character */
|
strcat(query, foo); /* must be character */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user