Skip site navigation (1) Skip section navigation (2)

ESQL/C TRUNCATE TABLE results in DROP TABLE

From: Lee Kindness <lkindness(at)csl(dot)co(dot)uk>
To: pgsql-bugs(at)postgresql(dot)org
Cc: lkindness(at)csl(dot)co(dot)uk, pgsql-interfaces(at)postgresql(dot)org
Subject: ESQL/C TRUNCATE TABLE results in DROP TABLE
Date: 2001-10-01 10:27:47
Message-ID: 15288.17699.564891.383422@elsick.csl.co.uk (view raw or flat)
Thread:
Lists: pgsql-bugspgsql-interfaces
Your name		: Lee Kindness
Your email address	: lkindness(at)csl(dot)co(dot)uk

System Configuration
---------------------
  Architecture (example: Intel Pentium)  	: Intel Pentium
  Operating System (example: Linux 2.0.26 ELF) 	: Linux 2.2.16-22, RedHat 7.0
  PostgreSQL version (example: PostgreSQL-7.1.3): PostgreSQL-7.1.3
  Compiler used (example:  gcc 2.95.2)		: RPM

Please enter a FULL description of your problem:
------------------------------------------------

'TRUNCATE TABLE' in embedded SQL results in the table being dropped!


Please describe a way to repeat the problem.   Please try to provide a
concise reproducible example, if at all possible: 
----------------------------------------------------------------------

Execute the following commands:

 createdb copytest
 echo 'CREATE TABLE copytest (f1 INTEGER, f2 INTEGER);' psql copytest
 echo 'CREATE UNIQUE INDEX copytest_idx ON copytest USING BTREE (f1, f2);' psql copytest
 ecpg copy.pgc
 gcc copy.c -I /usr/include/pgsql -lecpg -lpq
 ./a.out

Which will result in the following output from 'a.out':

 Error -400: 'ERROR:  Relation 'copytest' does not exist' in line 17.

given the following source 'copytest.pgc':

 #include <stdlib.h>
 #include <time.h>
 #include <sys/time.h>
 #include <unistd.h>

 EXEC SQL INCLUDE sqlca;

 int main(int argc, char **argv)
 {
  EXEC SQL CONNECT TO copytest;
  if( sqlca.sqlcode != 0 )
    return( 1 );

  EXEC SQL TRUNCATE TABLE copytest;
  if( sqlca.sqlcode < 0 )
    return( 1 );

  EXEC SQL COPY copytest FROM '/tmp/copytest';
  if( sqlca.sqlcode < 0 )
    {
      printf("Error %ld: %s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
      return( 1 );
    }

  EXEC SQL COMMIT;
  EXEC SQL DISCONNECT;

  return( 0 );
 }

and the following '/tmp/copytest' (not used):

 1	1
 2	2
 3	3
 4	4
 5	5
 6	6

If you add an 'EXEC SQL COMMIT' after the TRUNCATE and then do a '\d'
in psql the table is not shown - it has been dropped.

If you know how this problem might be fixed, list the solution below:
---------------------------------------------------------------------

Responses

pgsql-bugs by date

Next:From: Michael MeskesDate: 2001-10-01 11:50:37
Subject: Re: ESQL/C TRUNCATE TABLE results in DROP TABLE
Previous:From: Sascha DemetrioDate: 2001-09-29 15:00:34
Subject: MM Bug in libecpg

pgsql-interfaces by date

Next:From: Michael MeskesDate: 2001-10-01 11:50:37
Subject: Re: ESQL/C TRUNCATE TABLE results in DROP TABLE
Previous:From: Peter WasemDate: 2001-09-28 16:58:48
Subject: Re: JDBC: Exception when calling ResultSet.previous()

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group