aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/dbase/README.dbf2pg14
-rw-r--r--contrib/dbase/dbf2pg.16
-rw-r--r--contrib/dbase/dbf2pg.c14
3 files changed, 23 insertions, 11 deletions
diff --git a/contrib/dbase/README.dbf2pg b/contrib/dbase/README.dbf2pg
index 7203be4029b..71548196550 100644
--- a/contrib/dbase/README.dbf2pg
+++ b/contrib/dbase/README.dbf2pg
@@ -12,7 +12,7 @@ SYNOPSIS
"dbf2pg [options] dbf-file"
Options:
[-v[v]] [-f] [-u | -l] [-c | -D] [-d database] [-t table]
- [-h host] [-s oldname=newname[,oldname=newname]] [-s
+ [-h host] [-s oldname=[newname][,oldname=[newname]]] [-b
start] [-e end] [-W] [-U username] [-B transaction_size]
[-F charset_from [-T charset_to]]
@@ -70,15 +70,19 @@ DESCRIPTION
dbf2sql(1L) dbf2sql(1L)
- -s oldname=newname[,oldname=newname]
+ -s oldname=[newname][,oldname=[newname]]
Change the name of a field from oldname to newname.
This is mainly used to avoid using reserved SQL-
- keywords. Example:
- -s SELECT=SEL,COMMIT=doit
+ keywords. When the new fieldname is empty, the field
+ is skipped in both the CREATE-clause and the
+ INSERT-clauses, in common words: it will not be present
+ in the SQL-table.
+ Example:
+ -s SELECT=SEL,remark=,COMMIT=doit
This is done before the -f operator has taken
effect!
- -s start
+ -b start
Specify the first record-number in the xBase-file
we will insert.
diff --git a/contrib/dbase/dbf2pg.1 b/contrib/dbase/dbf2pg.1
index a377e489c83..e62d3323b59 100644
--- a/contrib/dbase/dbf2pg.1
+++ b/contrib/dbase/dbf2pg.1
@@ -8,8 +8,8 @@ dbf2sql \- Insert xBase\-style .dbf\-files into a PostgreSQL\-table
Options:
.br
[-v[v]] [-f] [-u | -l] [-c | -D] [-d database] [-t table]
-[-h host] [-s oldname=newname[,oldname=newname]]
-[-s start] [-e end] [-W] [-U username] [-B transaction_size]
+[-h host] [-s oldname=[newname][,oldname=[newname]]]
+[-b start] [-e end] [-W] [-U username] [-B transaction_size]
[-F charset_from [-T charset_to]]
.SH DESCRIPTION
@@ -78,7 +78,7 @@ the
.IR -f
operator has taken effect!
.TP
-.I "-s start"
+.I "-b start"
Specify the first record-number in the xBase-file we will insert.
.TP
.I "-e end"
diff --git a/contrib/dbase/dbf2pg.c b/contrib/dbase/dbf2pg.c
index b57b5c76885..0ae53cd126d 100644
--- a/contrib/dbase/dbf2pg.c
+++ b/contrib/dbase/dbf2pg.c
@@ -194,7 +194,7 @@ usage(void)
printf("dbf2pg\n"
"usage: dbf2pg [-u | -l] [-h hostname] [-W] [-U username]\n"
" [-B transaction_size] [-F charset_from [-T charset_to]]\n"
- " [-s oldname=newname[,oldname=newname[...]]] [-d dbase]\n"
+ " [-s oldname=[newname][,oldname=[newname][...]]] [-d dbase]\n"
" [-t table] [-c | -D] [-f] [-v[v]] dbf-file\n");
}
@@ -359,6 +359,7 @@ do_inserts(PGconn *conn, char *table, dbhead * dbh)
field *fields;
int i,
h,
+ j,
result;
char *query,
*foo;
@@ -442,12 +443,19 @@ do_inserts(PGconn *conn, char *table, dbhead * dbh)
if (result == DBF_VALID)
{
query[0] = '\0';
+ j = 0; /* counter for fields in the output */
for (h = 0; h < dbh->db_nfields; h++)
{
- if (!strlen(fields[h].db_name))
+ if (!strlen(fields[h].db_name)) /* When the new fieldname is empty, the field is skipped */
+ {
continue;
+ }
+ else
+ {
+ j++;
+ }
- if (h != 0) /* not for the first field! */
+ if (j > 1) /* not for the first field! */
strcat(query, "\t"); /* COPY statement field
* separator */