[comp.databases] ingres embedded SQL/C problem

ubiquity@cs.utexas.edu (Richard Hoffman) (01/27/91)

In article <1991Jan27.023129.721@eng.ufl.edu> tsao@helios.tcad.ee.ufl.edu 
(Tsao) writes:

>	I am trying to insert new data into a table, and I have compiled and
>run the program without any error, but then I check the table, new data
>is not there. 
>
>	exec sql SAVEPOINT savept;
>	exec sql insert into testtbl(name,age)
>		values (:tbl);
>	exec sql ROLLBACK to savept;

Uh, don't you want to COMMIT?  By using ROLLBACK, you are telling the engine
to dump all work since the savepoint, which it is apparently doing 
successfully.

-- 
Richard Hoffman       IBM Personal Systems Database Development   (512) 823-1822
1529 Ben Crenshaw Way
Austin, TX 78746         "Life is a gamble at terrible odds; 
(512) 327-9232            if it were a bet you wouldn't take it"  (Tom Stoppard)

rpburry@ncs.dnd.ca (Paul Burry) (01/27/91)

In article <1991Jan27.023129.721@eng.ufl.edu> tsao@helios.tcad.ee.ufl.edu (Tsao) writes:
|
|	Hello, everybody. I just started working with Ingres' embedded SQL
|with C, and I have got the following problem:
|
|	I am trying to insert new data into a table, and I have compiled and
|run the program without any error, but then I check the table, new data
|is not there. 
|
....
|
|#include <stdio.h>
|
|main()
|{
|	exec sql include sqlca;
|
|exec sql begin declare section;
|
|/* Description of table testtbl from database vlsi */
|  EXEC SQL DECLARE testtbl TABLE
|	(name	char(20),
|	 age	integer);
|
|  struct testtbl_ {
|	char	name[21];
|	long	age;
|  } testtbl;
|
|exec sql end declare section;
|
|	exec sql connect 'vlsi';
|	exec sql SAVEPOINT savept;
|	exec sql whenever sqlerror continue;
|
|	strncpy(tbl.name,"dude");
|	tbl.age = 20L;
|
|	
|	exec sql insert into testtbl(name,age)
|		values (:tbl);
|	
|	exec sql ROLLBACK to savept;
|
|	exec sql disconnect;	
|}

Rather than rolling back your transaction when the record was successfully
inserted, you should have 'commited':

ie.
	exec sql COMMIT;


At least I think that's right.  (I always thought Ingres' requirement for
explicit commiting of individual statements was a little screwy.)
-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Paul Burry			
Voice: (613)-991-7325		Internet: rpburry@ncs.dnd.ca
Fax:   (613)-991-7323		UUCP:	  ..!{uunet,cunews}!ncs.dnd.ca!rpburry

price@helios.unl.edu (Chad Price) (01/28/91)

tsao@helios.tcad.ee.ufl.edu (Tsao) writes:


>	Hello, everybody. I just started working with Ingres' embedded SQL
>with C, and I have got the following problem:

>	I am trying to insert new data into a table, and I have compiled and
>run the program without any error, but then I check the table, new data
>is not there. 

>	Any help will be greatly appreciated.

>	I am using Ingres SunOS(unix) version, release 6.3.

>	Following is the program I tried:

>------------------------------------------------------------------
>/* this program is trying to use esql to insert data into a table

>#include <stdio.h>

>main()
>{

>	exec sql include sqlca;

>exec sql begin declare section;

>/* Description of table testtbl from database vlsi */
>  EXEC SQL DECLARE testtbl TABLE
>	(name	char(20),
>	 age	integer);

>  struct testtbl_ {
>	char	name[21];
>	long	age;
>  } testtbl;

>exec sql end declare section;

>	exec sql connect 'vlsi';
>	exec sql SAVEPOINT savept;
>	exec sql whenever sqlerror continue;

>	strncpy(tbl.name,"dude");
>	tbl.age = 20L;

>	
>	exec sql insert into testtbl(name,age)
>		values (:tbl);
>	
>	exec sql ROLLBACK to savept;

>	exec sql disconnect;	
>
I am unfamiliar with Ingres, however Informix uses the sqlca structure
for error reporting. Unless you explicitly check for errors you will
never know what when wrong. Thus - check the values fo the appropriate
member of the sqlca structure after EVERY exec sql statement to ensure
that it was completed without error. There appears to be no other way to
determine what goes wrong when an esql c statement fails.

chad price
price@fergvax.unl.edu