mirror of
https://github.com/postgres/postgres.git
synced 2025-06-26 12:21:12 +03:00
- Finished major rewrite to use new protocol version
- Really prepare statements - Added more regression tests - Added auto-prepare mode - Use '$n' for positional variables, '?' is still possible via ecpg option - Cleaned up the sources a little bit
This commit is contained in:
@ -65,7 +65,7 @@ main(void)
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 24 "execute.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "create table test ( name char ( 8 ) , amount int , letter char ( 1 ) ) ", ECPGt_EOIT, ECPGt_EORT);
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "create table test ( name char ( 8 ) , amount int , letter char ( 1 ) ) ", ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 25 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
@ -79,9 +79,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
|
||||
|
||||
|
||||
sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 1, 'f')");
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "?",
|
||||
ECPGt_char_variable,(command),(long)1,(long)1,(1)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 2, command, ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 29 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
@ -89,9 +87,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
|
||||
|
||||
|
||||
sprintf(command, "insert into test (name, amount, letter) values ('db: ''r1''', 2, 't')");
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "?",
|
||||
ECPGt_char_variable,(command),(long)1,(long)1,(1)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 2, command, ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 32 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
@ -99,9 +95,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
|
||||
|
||||
|
||||
sprintf(command, "insert into test (name, amount, letter) select name, amount+10, letter from test");
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "?",
|
||||
ECPGt_char_variable,(command),(long)1,(long)1,(1)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 2, command, ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 35 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
@ -110,16 +104,14 @@ if (sqlca.sqlcode < 0) sqlprint();}
|
||||
|
||||
printf("Inserted %ld tuples via execute immediate\n", sqlca.sqlerrd[2]);
|
||||
|
||||
sprintf(command, "insert into test (name, amount, letter) select name, amount+?, letter from test");
|
||||
{ ECPGprepare(__LINE__, "I" , command);
|
||||
sprintf(command, "insert into test (name, amount, letter) select name, amount+$1, letter from test");
|
||||
{ ECPGprepare(__LINE__, NULL, 0, "i", command);
|
||||
#line 40 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 40 "execute.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "?",
|
||||
ECPGt_char_variable,(ECPGprepared_statement("I")),(long)1,(long)1,(1)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 1, "i",
|
||||
ECPGt_int,&(increment),(long)1,(long)1,sizeof(int),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 41 "execute.pgc"
|
||||
@ -139,25 +131,25 @@ if (sqlca.sqlcode < 0) sqlprint();}
|
||||
|
||||
sprintf (command, "select * from test");
|
||||
|
||||
{ ECPGprepare(__LINE__, "F" , command);
|
||||
{ ECPGprepare(__LINE__, NULL, 0, "f", command);
|
||||
#line 49 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 49 "execute.pgc"
|
||||
|
||||
/* declare CUR cursor for ? */
|
||||
/* declare CUR cursor for $1 */
|
||||
#line 50 "execute.pgc"
|
||||
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "declare CUR cursor for ?",
|
||||
ECPGt_char_variable,(ECPGprepared_statement("F")),(long)1,(long)1,(1)*sizeof(char),
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "declare CUR cursor for $1",
|
||||
ECPGt_char_variable,(ECPGprepared_statement("f", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 52 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 52 "execute.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "fetch 8 in CUR", ECPGt_EOIT,
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "fetch 8 in CUR", ECPGt_EOIT,
|
||||
ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||
ECPGt_int,(amount),(long)1,(long)8,sizeof(int),
|
||||
@ -189,46 +181,52 @@ if (sqlca.sqlcode < 0) sqlprint();}
|
||||
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
|
||||
}
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "close CUR", ECPGt_EOIT, ECPGt_EORT);
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "close CUR", ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 66 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 66 "execute.pgc"
|
||||
|
||||
|
||||
sprintf (command, "select * from test where amount = ?");
|
||||
|
||||
{ ECPGprepare(__LINE__, "F" , command);
|
||||
#line 70 "execute.pgc"
|
||||
{ ECPGdeallocate(__LINE__, 0, "f");
|
||||
#line 67 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 70 "execute.pgc"
|
||||
#line 67 "execute.pgc"
|
||||
|
||||
/* declare CUR2 cursor for ? */
|
||||
|
||||
sprintf (command, "select * from test where amount = $1");
|
||||
|
||||
{ ECPGprepare(__LINE__, NULL, 0, "f", command);
|
||||
#line 71 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 71 "execute.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "declare CUR2 cursor for ?",
|
||||
ECPGt_char_variable,(ECPGprepared_statement("F")),(long)1,(long)1,(1)*sizeof(char),
|
||||
/* declare CUR2 cursor for $1 */
|
||||
#line 72 "execute.pgc"
|
||||
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "declare CUR2 cursor for $1",
|
||||
ECPGt_char_variable,(ECPGprepared_statement("f", __LINE__)),(long)1,(long)1,(1)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||
ECPGt_const,"1",(long)1,(long)1,strlen("1"),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 73 "execute.pgc"
|
||||
#line 74 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 73 "execute.pgc"
|
||||
#line 74 "execute.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "fetch in CUR2", ECPGt_EOIT,
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "fetch in CUR2", ECPGt_EOIT,
|
||||
ECPGt_char,(name),(long)8,(long)8,(8)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||
ECPGt_int,(amount),(long)1,(long)8,sizeof(int),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
|
||||
ECPGt_char,(letter),(long)1,(long)8,(1)*sizeof(char),
|
||||
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
|
||||
#line 74 "execute.pgc"
|
||||
#line 75 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 74 "execute.pgc"
|
||||
#line 75 "execute.pgc"
|
||||
|
||||
|
||||
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
|
||||
@ -237,42 +235,42 @@ if (sqlca.sqlcode < 0) sqlprint();}
|
||||
|
||||
|
||||
|
||||
#line 79 "execute.pgc"
|
||||
#line 80 "execute.pgc"
|
||||
char n [ 8 ] , l = letter [ i ] [ 0 ] ;
|
||||
|
||||
#line 80 "execute.pgc"
|
||||
#line 81 "execute.pgc"
|
||||
int a = amount [ i ] ;
|
||||
/* exec sql end declare section */
|
||||
#line 81 "execute.pgc"
|
||||
#line 82 "execute.pgc"
|
||||
|
||||
|
||||
strncpy(n, name[i], 8);
|
||||
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, n, i, a, i, l);
|
||||
}
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "close CUR2", ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 87 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 87 "execute.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, "drop table test ", ECPGt_EOIT, ECPGt_EORT);
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "close CUR2", ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 88 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 88 "execute.pgc"
|
||||
|
||||
{ ECPGdo(__LINE__, 0, 1, NULL, 0, 0, "drop table test ", ECPGt_EOIT, ECPGt_EORT);
|
||||
#line 89 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 89 "execute.pgc"
|
||||
|
||||
{ ECPGtrans(__LINE__, NULL, "commit");
|
||||
#line 89 "execute.pgc"
|
||||
#line 90 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 89 "execute.pgc"
|
||||
#line 90 "execute.pgc"
|
||||
|
||||
{ ECPGdisconnect(__LINE__, "CURRENT");
|
||||
#line 90 "execute.pgc"
|
||||
#line 91 "execute.pgc"
|
||||
|
||||
if (sqlca.sqlcode < 0) sqlprint();}
|
||||
#line 90 "execute.pgc"
|
||||
#line 91 "execute.pgc"
|
||||
|
||||
|
||||
return (0);
|
||||
|
Reference in New Issue
Block a user