mirror of
https://github.com/postgres/postgres.git
synced 2025-11-01 21:31:19 +03:00
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 is
imported) 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
This commit is contained in:
@@ -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 */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user