Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb4176e9

Browse files
committed
Clean up bogus checking of date and numeric fields in DBF files,
per report from Boris van Schooten.
1 parentfbdb203 commitb4176e9

File tree

1 file changed

+15
-38
lines changed

1 file changed

+15
-38
lines changed

‎contrib/dbase/dbf2pg.c

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,8 @@ char *Escape_db(char *);
6363
char*convert_charset(char*string);
6464
#endif
6565
voidusage(void);
66-
unsignedintisinteger(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-
return0;
86-
i++;
87-
}
88-
return1;
89-
}
90-
9168
staticinlinevoid
9269
strtoupper(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+
elseif (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-
elseif ((fields[h].db_type=='N')&&
491-
(fields[h].db_dec==0))
471+
elseif (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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp