Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 42fcad6

Browse files
author
Michael Meskes
committed
Add test case for two phase commit. Also by Masahiko Sawada.
1 parent 43c79c7 commit 42fcad6

File tree

6 files changed

+194
-0
lines changed

6 files changed

+194
-0
lines changed

src/interfaces/ecpg/test/ecpg_schedule

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ test: sql/indicators
4646
test: sql/oldexec
4747
test: sql/quote
4848
test: sql/show
49+
test: sql/twophase
4950
test: sql/insupd
5051
test: sql/parser
5152
test: thread/thread
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* Processed by ecpg (regression mode) */
2+
/* These include files are added by the preprocessor */
3+
#include <ecpglib.h>
4+
#include <ecpgerrno.h>
5+
#include <sqlca.h>
6+
/* End of automatic include section */
7+
#define ECPGdebug(X,Y) ECPGdebug((X)+100,(Y))
8+
9+
#line 1 "twophase.pgc"
10+
#include <stdio.h>
11+
#include <stdlib.h>
12+
#include <string.h>
13+
14+
15+
#line 1 "regression.h"
16+
17+
18+
19+
20+
21+
22+
#line 5 "twophase.pgc"
23+
24+
25+
/* exec sql whenever sqlerror sqlprint ; */
26+
#line 7 "twophase.pgc"
27+
28+
29+
int main(void)
30+
{
31+
char msg[128];
32+
33+
ECPGdebug(1, stderr);
34+
35+
strcpy(msg, "connect");
36+
{ ECPGconnect(__LINE__, 0, "ecpg1_regression" , NULL, NULL , NULL, 0);
37+
#line 16 "twophase.pgc"
38+
39+
if (sqlca.sqlcode < 0) sqlprint();}
40+
#line 16 "twophase.pgc"
41+
42+
{ ECPGsetcommit(__LINE__, "off", NULL);
43+
#line 17 "twophase.pgc"
44+
45+
if (sqlca.sqlcode < 0) sqlprint();}
46+
#line 17 "twophase.pgc"
47+
48+
49+
strcpy(msg, "create");
50+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "create table t1 ( c int )", ECPGt_EOIT, ECPGt_EORT);
51+
#line 20 "twophase.pgc"
52+
53+
if (sqlca.sqlcode < 0) sqlprint();}
54+
#line 20 "twophase.pgc"
55+
56+
57+
strcpy(msg, "commit");
58+
{ ECPGtrans(__LINE__, NULL, "commit");
59+
#line 23 "twophase.pgc"
60+
61+
if (sqlca.sqlcode < 0) sqlprint();}
62+
#line 23 "twophase.pgc"
63+
64+
65+
strcpy(msg, "begin");
66+
{ ECPGtrans(__LINE__, NULL, "begin");
67+
#line 26 "twophase.pgc"
68+
69+
if (sqlca.sqlcode < 0) sqlprint();}
70+
#line 26 "twophase.pgc"
71+
72+
73+
strcpy(msg, "insert");
74+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "insert into t1 values ( 1 )", ECPGt_EOIT, ECPGt_EORT);
75+
#line 29 "twophase.pgc"
76+
77+
if (sqlca.sqlcode < 0) sqlprint();}
78+
#line 29 "twophase.pgc"
79+
80+
81+
strcpy(msg, "prepare transaction");
82+
{ ECPGtrans(__LINE__, NULL, "prepare transaction 'gxid'");
83+
#line 32 "twophase.pgc"
84+
85+
if (sqlca.sqlcode < 0) sqlprint();}
86+
#line 32 "twophase.pgc"
87+
88+
89+
strcpy(msg, "commit prepared");
90+
{ ECPGtrans(__LINE__, NULL, "commit prepared 'gxid'");
91+
#line 35 "twophase.pgc"
92+
93+
if (sqlca.sqlcode < 0) sqlprint();}
94+
#line 35 "twophase.pgc"
95+
96+
97+
strcpy(msg, "drop");
98+
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "drop table t1", ECPGt_EOIT, ECPGt_EORT);
99+
#line 38 "twophase.pgc"
100+
101+
if (sqlca.sqlcode < 0) sqlprint();}
102+
#line 38 "twophase.pgc"
103+
104+
105+
strcpy(msg, "disconnect");
106+
{ ECPGdisconnect(__LINE__, "CURRENT");
107+
#line 41 "twophase.pgc"
108+
109+
if (sqlca.sqlcode < 0) sqlprint();}
110+
#line 41 "twophase.pgc"
111+
112+
113+
return (0);
114+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[NO_PID]: ECPGdebug: set to 1
2+
[NO_PID]: sqlca: code: 0, state: 00000
3+
[NO_PID]: ECPGconnect: opening database ecpg1_regression on <DEFAULT> port <DEFAULT>
4+
[NO_PID]: sqlca: code: 0, state: 00000
5+
[NO_PID]: ECPGsetcommit on line 17: action "off"; connection "ecpg1_regression"
6+
[NO_PID]: sqlca: code: 0, state: 00000
7+
[NO_PID]: ecpg_execute on line 20: query: create table t1 ( c int ); with 0 parameter(s) on connection ecpg1_regression
8+
[NO_PID]: sqlca: code: 0, state: 00000
9+
[NO_PID]: ecpg_execute on line 20: using PQexec
10+
[NO_PID]: sqlca: code: 0, state: 00000
11+
[NO_PID]: ecpg_process_output on line 20: OK: CREATE TABLE
12+
[NO_PID]: sqlca: code: 0, state: 00000
13+
[NO_PID]: ECPGtrans on line 23: action "commit"; connection "ecpg1_regression"
14+
[NO_PID]: sqlca: code: 0, state: 00000
15+
[NO_PID]: ECPGtrans on line 26: action "begin"; connection "ecpg1_regression"
16+
[NO_PID]: sqlca: code: 0, state: 00000
17+
[NO_PID]: ecpg_execute on line 29: query: insert into t1 values ( 1 ); with 0 parameter(s) on connection ecpg1_regression
18+
[NO_PID]: sqlca: code: 0, state: 00000
19+
[NO_PID]: ecpg_execute on line 29: using PQexec
20+
[NO_PID]: sqlca: code: 0, state: 00000
21+
[NO_PID]: ecpg_process_output on line 29: OK: INSERT 0 1
22+
[NO_PID]: sqlca: code: 0, state: 00000
23+
[NO_PID]: ECPGtrans on line 32: action "prepare transaction 'gxid'"; connection "ecpg1_regression"
24+
[NO_PID]: sqlca: code: 0, state: 00000
25+
[NO_PID]: ECPGtrans on line 35: action "commit prepared 'gxid'"; connection "ecpg1_regression"
26+
[NO_PID]: sqlca: code: 0, state: 00000
27+
[NO_PID]: ecpg_execute on line 38: query: drop table t1; with 0 parameter(s) on connection ecpg1_regression
28+
[NO_PID]: sqlca: code: 0, state: 00000
29+
[NO_PID]: ecpg_execute on line 38: using PQexec
30+
[NO_PID]: sqlca: code: 0, state: 00000
31+
[NO_PID]: ecpg_process_output on line 38: OK: DROP TABLE
32+
[NO_PID]: sqlca: code: 0, state: 00000
33+
[NO_PID]: ecpg_finish: connection ecpg1_regression closed
34+
[NO_PID]: sqlca: code: 0, state: 00000

src/interfaces/ecpg/test/expected/sql-twophase.stdout

Whitespace-only changes.

src/interfaces/ecpg/test/sql/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ TESTS = array array.c \
2222
parser parser.c \
2323
quote quote.c \
2424
show show.c \
25+
twophase twophase.c \
2526
insupd insupd.c
2627

2728
all: $(TESTS)
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
5+
exec sql include ../regression;
6+
7+
exec sql whenever sqlerror sqlprint;
8+
9+
int main(void)
10+
{
11+
char msg[128];
12+
13+
ECPGdebug(1, stderr);
14+
15+
strcpy(msg, "connect");
16+
exec sql connect to REGRESSDB1;
17+
exec sql set autocommit to off;
18+
19+
strcpy(msg, "create");
20+
exec sql create table t1(c int);
21+
22+
strcpy(msg, "commit");
23+
exec sql commit;
24+
25+
strcpy(msg, "begin");
26+
exec sql begin;
27+
28+
strcpy(msg, "insert");
29+
exec sql insert into t1 values(1);
30+
31+
strcpy(msg, "prepare transaction");
32+
exec sql prepare transaction 'gxid';
33+
34+
strcpy(msg, "commit prepared");
35+
exec sql commit prepared 'gxid';
36+
37+
strcpy(msg, "drop");
38+
exec sql drop table t1;
39+
40+
strcpy(msg, "disconnect");
41+
exec sql disconnect current;
42+
43+
return (0);
44+
}

0 commit comments

Comments
 (0)