From: Herouth Maoz <herouth@oumail.openu.ac.il>
To: Tom Good <tomg@nrnet.org>
Cc: PostgreSQL Interfaces List <pgsql-interfaces@postgreSQL.org>
Subject: Re: [INTERFACES] ecpg - `exec sql delete' failing
Date: Sun, 5 Apr 1998 14:03:39 +0300
Message-ID: <v04003a06b14d14bde5cd@[147.233.55.121]> (raw)
In-Reply-To: <Pine.LNX.3.95.980403164223.2163A-100000@mailhost.nrnet.org>
At 0:46 +0300 on 4/4/98, Tom Good wrote:
> Hi. Can't fathom why this code precompiles, compiles, links and
> seems to execute - but won't delete records.
> As always - any assistance greatly appreciated!
> Tom
> --- pgc code follows ---
>
> #include <stdio.h>
>
> EXEC SQL BEGIN DECLARE SECTION;
> int ClientID; /* client_id */
> char FirstName[16]; /* client_fname */
> char LastName[16]; /* client_lname */
> char NameTag[16]; /* usr buffer */
> char reply; /* usr buffer */
> int delete_num; /* usr buffer */
> EXEC SQL END DECLARE SECTION;
[snip]
> printf("\t\tRemove this record (y/n): ");
> scanf("%s", &reply);
> if(reply == 'y') {
> printf("\t\tEnter Client ID Number: ");
> scanf("%d", &delete_num);
> EXEC SQL DELETE FROM central WHERE client_id = delete_num;
> }
> else printf("Exiting...record not removed.\n");
> exit(0);
> }
Reminds me of a mistake a friend of mine did in one of his university
exercises. The variable reply is declared as char, but you're scanning to
it as string, so there is a "\0" which enters somewhere (perhaps the
alignment bytes of delete_num, who knows), and causes a garble. Why don't
you try to scan it using "%c", not "%s"?
Herouth
--
Herouth Maoz, B.Sc. Work: herouth@oumail.openu.ac.il
Home: herutma@telem.openu.ac.il
HOME PAGE: http://homes.openu.ac.il/~herouth/
Internet technical assistant Open University, Telem Project
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: herouth@oumail.openu.ac.il, tomg@nrnet.org
Subject: Re: [INTERFACES] ecpg - `exec sql delete' failing
In-Reply-To: <v04003a06b14d14bde5cd@[147.233.55.121]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox