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

Commit82bade7

Browse files
committed
dbf2pg - Insert xBase-style .dbf-files into a PostgreSQL-table
There is an option "-s oldname=newname", which changes the old field name of the dbf-file to the newname in PostgeSQL. If the length of the new name is 0, the field is skiped. If you want to skip the first field of the dbf-file, you get the wildest error-messages from the backend. dbf2pg load the dbf-file via "COPY tablename FROM STDIN". If you skip the first field, it is an \t to much in STDIN.A fix could be an counter j=0, which increments only, if a field is imported(IF (strlen(fields[h].db_name)> 0) j++. And only if j > 1 (if an other field isimported) the \t is printed.An other small bug in the README:-s start Specify the first record-number in the xBase-file we will insert.should be-e start Specify the first record-number in the xBase-file we will insert.Thomas Behr
1 parent52347b6 commit82bade7

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

‎contrib/dbase/README.dbf2pg

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SYNOPSIS
1212
"dbf2pg [options] dbf-file"
1313
Options:
1414
[-v[v]] [-f] [-u | -l] [-c | -D] [-d database] [-t table]
15-
[-h host] [-s oldname=newname[,oldname=newname]] [-s
15+
[-h host] [-s oldname=[newname][,oldname=[newname]]] [-b
1616
start] [-e end] [-W] [-U username] [-Btransaction_size]
1717
[-F charset_from [-T charset_to]]
1818

@@ -70,15 +70,19 @@ DESCRIPTION
7070
dbf2sql(1L) dbf2sql(1L)
7171

7272

73-
-s oldname=newname[,oldname=newname]
73+
-s oldname=[newname][,oldname=[newname]]
7474
Change the name of a field from oldname to newname.
7575
This ismainlyused to avoid using reserved SQL-
76-
keywords. Example:
77-
-s SELECT=SEL,COMMIT=doit
76+
keywords. When the new fieldname is empty, the field
77+
is skipped in both the CREATE-clause and the
78+
INSERT-clauses, in common words: it will not be present
79+
in the SQL-table.
80+
Example:
81+
-s SELECT=SEL,remark=,COMMIT=doit
7882
This is done before the -f operator has taken
7983
effect!
8084

81-
-s start
85+
-b start
8286
Specify the first record-number in the xBase-file
8387
we will insert.
8488

‎contrib/dbase/dbf2pg.1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ dbf2sql \- Insert xBase\-style .dbf\-files into a PostgreSQL\-table
88
Options:
99
.br
1010
[-v[v]] [-f] [-u | -l] [-c | -D] [-d database] [-t table]
11-
[-h host] [-s oldname=newname[,oldname=newname]]
12-
[-s start] [-e end] [-W] [-U username] [-B transaction_size]
11+
[-h host] [-s oldname=[newname][,oldname=[newname]]]
12+
[-b start] [-e end] [-W] [-U username] [-B transaction_size]
1313
[-F charset_from [-T charset_to]]
1414

1515
.SH DESCRIPTION
@@ -78,7 +78,7 @@ the
7878
.IR -f
7979
operator has taken effect!
8080
.TP
81-
.I"-sstart"
81+
.I"-bstart"
8282
Specify the first record-number in the xBase-file we will insert.
8383
.TP
8484
.I"-eend"

‎contrib/dbase/dbf2pg.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ usage(void)
194194
printf("dbf2pg\n"
195195
"usage: dbf2pg [-u | -l] [-h hostname] [-W] [-U username]\n"
196196
" [-B transaction_size] [-F charset_from [-T charset_to]]\n"
197-
" [-s oldname=newname[,oldname=newname[...]]] [-d dbase]\n"
197+
" [-s oldname=[newname][,oldname=[newname][...]]] [-d dbase]\n"
198198
" [-t table] [-c | -D] [-f] [-v[v]] dbf-file\n");
199199
}
200200

@@ -359,6 +359,7 @@ do_inserts(PGconn *conn, char *table, dbhead * dbh)
359359
field*fields;
360360
inti,
361361
h,
362+
j,
362363
result;
363364
char*query,
364365
*foo;
@@ -442,12 +443,19 @@ do_inserts(PGconn *conn, char *table, dbhead * dbh)
442443
if (result==DBF_VALID)
443444
{
444445
query[0]='\0';
446+
j=0;/* counter for fields in the output */
445447
for (h=0;h<dbh->db_nfields;h++)
446448
{
447-
if (!strlen(fields[h].db_name))
449+
if (!strlen(fields[h].db_name))/* When the new fieldname is empty, the field is skipped */
450+
{
448451
continue;
452+
}
453+
else
454+
{
455+
j++;
456+
}
449457

450-
if (h!=0)/* not for the first field! */
458+
if (j>1)/* not for the first field! */
451459
strcat(query,"\t");/* COPY statement field
452460
* separator */
453461

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp