From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | thomas(dot)behr(at)BNV-Bamberg(dot)De |
Cc: | pgsql-bugs(at)postgresql(dot)org, thomas(dot)Behr(at)uvw(dot)uni-bayreuth(dot)de |
Subject: | Re: Small problem in contrib/dbase/dbf2pg.c |
Date: | 2003-07-24 02:29:21 |
Message-ID: | 200307240229.h6O2TLb18708@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Thomas, would you send me a context diff (diff -c) of the change and I
will get into 7.4. Thanks.
---------------------------------------------------------------------------
Thomas Behr wrote:
> Your name : Thomas Behr
> Your email address : ------(dot)----(at)bnv-bamberg(dot)de
> System Configuration
> ---------------------
> Architecture (example: Intel Pentium) : ALL
> Operating System (example: Linux 2.0.26 ELF) : ALL
> PostgreSQL version (example: PostgreSQL-7.3.3): PostgreSQL-7.3.3
> Compiler used (example: gcc 2.95.2) : WorkShop Compilers 5.0 98/12/15 C 5.0
> Please enter a FULL description of your problem:
> ------------------------------------------------
> 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.
> Please describe a way to repeat the problem. Please try to provide a
> concise reproducible example, if at all possible:
> ----------------------------------------------------------------------
> dbf2pg -s first_field_name=,other_fieldname=,reserved_fieldname=new_fieldname
> -c -d testdb -t testtable -h dbhost -U testuser -F IBM437 -T ISO-8859-1 -vv
> test.dbf
>
> If you know how this problem might be fixed, list the solution below:
> ---------------------------------------------------------------------
>
> 440 /* build line and submit */
> 441 result = dbf_get_record(dbh, fields, i);
> 442 if (result == DBF_VALID)
> 443 {
> 444 query[0] = '\0';
> 445 for (h = 0; h < dbh->db_nfields; h++)
> 446 {
> 447 if (!strlen(fields[h].db_name))
> 448 continue;
> 449
> 450 if (h != 0) /* not for the first field! */
> 451 strcat(query, "\t"); /* COPY statement field
> 452 * separator */
>
>
>
> 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.
>
> ...
> int j;
> ...
>
> if (result == DBF_VALID)
> {
> query[0] = '\0';
> j = 0;
> for (h = 0; h < dbh->db_nfields; h++)
> {
> if (!strlen(fields[h].db_name))
> {
> continue;
> }
> else
> {
> j++;
> }
>
> if (j > 1) /* not for the first field! */
> strcat(query, "\t"); /* COPY statement field
> * separator */
>
>
> 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.
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From | Date | Subject | |
---|---|---|---|
Next Message | Admin Gaston | 2003-07-24 07:29:28 | libpq incompatibility |
Previous Message | Tom Lane | 2003-07-24 00:31:15 | Re: [GENERAL] Convert TimeStamp to Date |