pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
ecpg - `exec sql delete' failing
2+ messages / 2 participants
[nested] [flat]

* ecpg - `exec sql delete' failing
@ 1998-04-03 21:46 Tom Good <tomg@nrnet.org>
  1998-04-05 11:03 ` Re: [INTERFACES] ecpg - `exec sql delete' failing Herouth Maoz <herouth@oumail.openu.ac.il>
  0 siblings, 1 reply; 2+ messages in thread

From: Tom Good @ 1998-04-03 21:46 UTC (permalink / raw)
  To: pgsql-interfaces

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;

EXEC SQL INCLUDE sqlca;

main() 
{

EXEC SQL CONNECT 'registry';

  if(sqlca.sqlcode) {
    printf("Error connecting to database server.\n");
    exit(0);
  }
system("tput clear");
printf("\n\n");
printf("\t\t\tConnected to database server...\n");
printf("\t\t\tEnter Last Name of Client: ");
scanf("%s", &NameTag);

EXEC SQL SELECT client_id, client_lname, client_fname
INTO :ClientID, :LastName, :FirstName
  FROM central
  WHERE client_lname = :NameTag;

printf("\n");
printf("\t\tID: %d  Lastname: %s Firstname: %s\n", ClientID, LastName, FirstName);
printf("\t\t-------------------------------------------------------\n");

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);
}


    ----------- Sisters of Charity Medical Center ----------
                    Department of Psychiatry
                              ----     
 Thomas Good, System Administrator            <tomg@q8.nrnet.org>
 North Richmond CMHC/Residential Services     Phone: 718-354-5528
 75 Vanderbilt Ave, Quarters 8                Fax:   718-354-5056
 Staten Island, NY   10305




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [INTERFACES] ecpg - `exec sql delete' failing
  1998-04-03 21:46 ecpg - `exec sql delete' failing Tom Good <tomg@nrnet.org>
@ 1998-04-05 11:03 ` Herouth Maoz <herouth@oumail.openu.ac.il>
  0 siblings, 0 replies; 2+ messages in thread

From: Herouth Maoz @ 1998-04-05 11:03 UTC (permalink / raw)
  To: Tom Good <tomg@nrnet.org>; +Cc: pgsql-interfaces

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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~1998-04-05 11:03 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-04-03 21:46 ecpg - `exec sql delete' failing Tom Good <tomg@nrnet.org>
1998-04-05 11:03 ` Herouth Maoz <herouth@oumail.openu.ac.il>

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