What I want to know is whether this is possible in embedded sql in
Informix. If so how do I write embedded sql statements for such things
( what is the syntax ? some sample code could help !)
Art S. Kagel
http://www.informix.com/answers/english/alpha.thm#E
Good luck,
James
here is my source code
#include <stdio.h>
#include <string.h>
$include sqlca;
int main(int argc, char** argv)
{
$ char query[512];
$ char name[21];
char ch;
int i;
$ database "joseph";
printf("%d\n", sqlca.sqlcode); /* error -256 */
printf(":%c:\n", sqlca.sqlwarn.sqlwarn1);
$ set lock mode to wait ;
printf("%d\n", sqlca.sqlcode);
sprintf(query,"%s","insert into my_temp1(name) values(?)");
$ begin work;
printf("%d\n", sqlca.sqlcode);
printf("Press any key to continue:");
getchar();
$ prepare ins_query from $query;
printf("%d\n", sqlca.sqlcode);
for(i=1; i<argc; i++)
{
strncpy(name, argv[i], sizeof(name)-1);
$ execute ins_query using $name;
printf("%d\n", sqlca.sqlcode);
}
printf("Press any key to continue:");
ch = getchar();
if(ch = 'c')
$ commit work;
else
$ rollback work;
printf("%d\n", sqlca.sqlcode); /* error -256 */
$ close database ;
printf("%d\n", sqlca.sqlcode);
return 0;
}
You need to have database logging switched on. Set your TAPEDEV to
/dev/null or nul and run
ontape -s -L 0 -B yourdatabasename
I am not quite done with it , I get an error code of -256 (Transaction
not available) and the sqlca.sqlwarn.sqlwarn1 is a space character ('
'). I tried to follow the code in informix/demo/esqlc/unload.ec
here is my source code
May be the problem with ANSI Compliant database. Remove Begin work and try. The BEGIN WORK statement is not needed because transactions are implicit. A warning is generated if you use a BEGIN WORK statement immediately after one of the following statements:
DATABASE
COMMIT WORK
CREATE DATABASE
ROLLBACK WORK
An error is generated if you use a BEGIN WORK statement after any other statement.
Check now.
Cheers,
Manjunath Shetty S.
joseph v d'silva wrote:
> I am not quite done with it , I get an error code of -256 (Transaction
> not available) and the sqlca.sqlwarn.sqlwarn1 is a space character ('
> '). I tried to follow the code in informix/demo/esqlc/unload.ec
>
> here is my source code
>
> #include <stdio.h>
> #include <string.h>
>
> $include sqlca;
>
> int main(int argc, char** argv)
> {
> $ char query[512];
> $ char name[21];
> char ch;
> int i;
>
> $ database "joseph";
> printf("%d\n", sqlca.sqlcode); /* error -256 */
I seriously doubt that you got -256 from a DATABASE statement.
> printf(":%c:\n", sqlca.sqlwarn.sqlwarn1);
OK that means that sqlca.sqlwarn.sqlwarn2 is not set to 'W' meaning that
your database was created without logging and therefore does not
support transactions. Either drop the database and create it again with
logging (preferably UNBUFFERED log) or use ontape or onbar to change the
logging status of the database to BUFFERED or UNBUFFERED (preferred).
THEN you will have transaction support.
>
> $ set lock mode to wait ;
> printf("%d\n", sqlca.sqlcode);
>
> sprintf(query,"%s","insert into my_temp1(name) values(?)");
>
> $ begin work;
> printf("%d\n", sqlca.sqlcode);
Here's where you likely got the -256 error.
>
> printf("Press any key to continue:");
> getchar();
>
> $ prepare ins_query from $query;
> printf("%d\n", sqlca.sqlcode);
>
> for(i=1; i<argc; i++)
> {
> strncpy(name, argv[i], sizeof(name)-1);
> $ execute ins_query using $name;
> printf("%d\n", sqlca.sqlcode);
> }
>
> printf("Press any key to continue:");
> ch = getchar();
>
> if(ch = 'c')
> $ commit work;
> else
> $ rollback work;
>
> printf("%d\n", sqlca.sqlcode); /* error -256 */
>
> $ close database ;
> printf("%d\n", sqlca.sqlcode);
>
> return 0;
> }
>
BTW using the dollar sign ($) to introduce SQL is Informix specific.
For portablility I prefer to use the EXEC SQL ANSI Embedded SQL standard.
Art S. Kagel