Thread: Re: ecpg - `exec sql delete' failing (fwd)
At 3:28 +0100 on 6/4/98, Thomas Good wrote: > > 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); > } I've already told you about scanning into a char with %s - and you haven't fixed it. Anyway, I have another suspicion - shouldn't the delete above be "DELETE FROM central WHERE client_id = :delete_num" (with ":")? Seems to me that without using colon, it may think that delet_num is a column name. Herouth
On Mon, 6 Apr 1998, Herouth Maoz wrote: > > 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); > > } > I've already told you about scanning into a char with %s - and you haven't Good morning, Herouth! Roger that - I tried it and it broke the code. The difficulty here is not with scanning usr input. If I hack this stanza to display stdout via printf instead of running `exec sql' I get whatever str printf holds echoed back to me when I reply with a `y'. Similarly, if I enter `n' I get the `else printf' value. Conversely, If I change the conversion specifier to a single char (%c) I get only the `else printf' valued echoed back... :-( > fixed it. Anyway, I have another suspicion - shouldn't the delete above be > "DELETE FROM central WHERE client_id = :delete_num" (with ":")? I will give it a shot and get back to you. Thanks for the reply! > Seems to me that without using colon, it may think that delet_num is a > column name. I'm also going to section this off as a separate function() and see how that goes...will advise. Cheers, Tom > Herouth > > > ----------- 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
On Mon, 6 Apr 1998, Herouth Maoz wrote: > > 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); > > } > > I've already told you about scanning into a char with %s - and you haven't > fixed it. Anyway, I have another suspicion - shouldn't the delete above be > "DELETE FROM central WHERE client_id = :delete_num" (with ":")? Herouth - tried it just now... > Seems to me that without using colon, it may think that delet_num is a > column name. This fails as well...hmm...back to the drawing board! Let me try it as a separate function. ----------- 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
I have a question on the libpq( c language) libraries. The included testlibpq.c can extract data from the postgres95 database. Modifing the testlibpq.c enable me to extract data from any database in the postgres95. Hovever, when I changed the "select" query to "insert" query, the code seems doesn't work. Could somebody tell me is it another way to do "insert" or something I have missed? eg. res=PQexec(conn, "DECLARE myportal CURSOR FOR select * ......."); was changed to res=PQexec(conn, "DECLARE myportal CURSOR FOR insert into ......."); But can't do insert. -- Regards, Christopher Luk System Analyst - The Hong Kong Council of the Church of Christ in China Phone : (852) 2397-1022 Fax : (852) 2397-7405 mailto:wluk@hkcccc.org URL : http://www.hkcccc.org (Chinese based)