File: sql_code_2pc.c

package info (click to toggle)
virtuoso-opensource 6.1.6+dfsg2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 260,992 kB
  • ctags: 125,220
  • sloc: ansic: 652,748; sql: 458,419; xml: 282,834; java: 61,031; sh: 40,031; cpp: 36,890; cs: 25,240; php: 12,692; yacc: 9,523; lex: 7,018; makefile: 6,157; jsp: 4,484; awk: 1,643; perl: 1,013; ruby: 1,003; python: 326
file content (241 lines) | stat: -rw-r--r-- 6,414 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/* This file is automatically generated by sql_to_c.awk */

#include "sqlnode.h"
#include "sqlfn.h"
#include "sqltype.h"

/* 2pc.sql */

static const char *tbl0 = 
"create table _2PC.DBA.TRANSACTIONS (TRX_ID INTEGER, TRX_STATE VARCHAR)\n";

static const char *proc0 = 
"#line 27 \"[executable]/2pc.sql\"\n"
"create procedure _2PC.DBA._FFFF_GET_SEQ_NEXT (IN seqobj VARCHAR, IN _min INTEGER, IN _max INTEGER)\n"
"{\n"
"DECLARE id INTEGER;\n"
"id := sequence_next (seqobj);\n"
"IF ((id < _min) OR (id > _max))\n"
"{\n"
"sequence_set (seqobj, _min, 0);\n"
"return _min;\n"
"}\n"
"return sequence_next (seqobj);\n"
"}\n"
"--src 2pc.sql:25\n";

static const char *proc1 = 
"#line 40 \"[executable]/2pc.sql\"\n"
"create procedure\n"
"_2PC.DBA._0001_ADD_ENTRY ()\n"
"{\n"
"DECLARE _trx_id0 INTEGER;\n"
"DECLARE _trx_id INTEGER;\n"
"_trx_id0 := -1;\n"
"again:\n"
"_trx_id := _2PC.DBA._FFFF_GET_SEQ_NEXT (\'_2PC/TRANSACTIONS/_ID\', 1, 10000);\n"
"IF (_trx_id0 = -1)\n"
"{\n"
"_trx_id0 := _trx_id;\n"
"} ELSE IF (_trx_id0 = _trx_id)\n"
"{\n"
"signal (\'TP000\', sprintf (\'Not enough space in system table for new entry, try to empty _2PC.DBA.TRANSACTIONS table\'));\n"
"RETURN;\n"
"}\n"
"\n"
"WHENEVER SQLSTATE \'23000\' GOTO again;\n"
"INSERT INTO _2PC.DBA.TRANSACTIONS (TRX_ID, TRX_STATE)\n"
"VALUES (_trx_id, \'STARTED\');\n"
"RETURN _trx_id;\n"
"}\n"
"--src 2pc.sql:38\n";

static const char *proc2 = 
"#line 64 \"[executable]/2pc.sql\"\n"
"create procedure _2PC.DBA._FFFF_CHECK_TRX_ID ( IN _trx_id INTEGER)\n"
"{\n"
"FOR SELECT TRX_ID FROM _2PC.DBA.TRANSACTIONS WHERE TRX_ID=_trx_id DO\n"
"{\n"
"RETURN;\n"
"}\n"
"signal (\'TP000\', sprintf (\'No such transaction id [%lx]\', _trx_id));\n"
"}\n"
"--src 2pc.sql:62\n";

static const char *proc3 = 
"#line 75 \"[executable]/2pc.sql\"\n"
"create procedure _2PC.DBA._0001_TRX_SSTATE ( IN _trx_id INTEGER, IN _state VARCHAR)\n"
"{\n"
"_2PC.DBA._FFFF_CHECK_TRX_ID (_trx_id);\n"
"\n"
"IF ((_state = \'COMMITTED\') OR (_state = \'ROLLBACKED\'))\n"
"{\n"
"DELETE FROM _2PC.DBA.TRANSACTIONS WHERE TRX_ID=_trx_id;\n"
"RETURN 0;\n"
"}\n"
"UPDATE _2PC.DBA.TRANSACTIONS SET TRX_STATE=_state WHERE TRX_ID=_trx_id;\n"
"RETURN 0;\n"
"}\n"
"--src 2pc.sql:73\n";

static const char *proc4 = 
"#line 89 \"[executable]/2pc.sql\"\n"
"create procedure _2PC.DBA._0001_GET_TRX_STATE (IN _trx_id INTEGER)\n"
"{\n"
"_2PC.DBA._FFFF_CHECK_TRX_ID (_trx_id);\n"
"FOR SELECT TRX_STATE FROM _2PC.DBA.TRANSACTIONS WHERE TRX_ID=_trx_id DO\n"
"{\n"
"\n"
"IF (TRX_STATE=\'COMMIT_PENDING\')\n"
"RETURN 0;\n"
"\n"
"IF (TRX_STATE=\'ROLLBACK_PENDING\')\n"
"RETURN 1;\n"
"signal (\'TP000\', \'VirtDTC error - unexpected state [%s]\', TRX_STATE);\n"
"RETURN;\n"
"}\n"
"}\n"
"--src 2pc.sql:87\n";

static const char *proc5 = 
"#line 106 \"[executable]/2pc.sql\"\n"
"create procedure _2PC.DBA.virt_tp_enlist_branch (IN trx_cookie VARCHAR)\n"
"{\n"
"virt_tp_update_cli_001 (trx_cookie);\n"
"}\n"
"--src 2pc.sql:104\n";

static const char *proc6 = 
"#line 112 \"[executable]/2pc.sql\"\n"
"create procedure _2PC.DBA.XA_GET_ALL_XIDS_COUNT ()\n"
"{\n"
"DECLARE xid VARCHAR;\n"
"DECLARE c INTEGER;\n"
"\n"
"c := 0;\n"
"\n"
"get_rec_xid_beg ();\n"
"xid := get_rec_xid ();\n"
"WHILE (xid IS NOT NULL)\n"
"{\n"
"c := c + 1;\n"
"xid := get_rec_xid ();\n"
"}\n"
"get_rec_xid_end();\n"
"RETURN c;\n"
"}\n"
"--src 2pc.sql:110\n";

static const char *proc7 = 
"#line 131 \"[executable]/2pc.sql\"\n"
"create procedure _2PC.DBA.OLD_XA_GET_ALL_XIDS ()\n"
"{\n"
"declare xid varchar;\n"
"\n"
"result_names (xid);\n"
"\n"
"get_rec_xid_beg ();\n"
"xid := get_rec_xid ();\n"
"while (xid is not null)\n"
"{\n"
"result (xid);\n"
"xid := get_rec_xid ();\n"
"}\n"
"get_rec_xid_end();\n"
"return NULL;\n"
"}\n"
"--src 2pc.sql:129\n";

static const char *proc8 = 
"#line 149 \"[executable]/2pc.sql\"\n"
"create procedure _2PC.DBA.XA_GET_ALL_XIDS ()\n"
"{\n"
"declare xid varchar;\n"
"\n"
"result_names (xid);\n"
"\n"
"declare xids any;\n"
"xids := txa_get_all_trx();\n"
"if (xids is not null)\n"
"{\n"
"declare idx integer;\n"
"idx := 0;\n"
"while (idx < length (xids))\n"
"{\n"
"declare st varchar;\n"
"st := xids[idx][3];\n"
"if (substring (st, 1, 3) = \'PRP\')\n"
"{\n"
"result (txa_bin_encode (xids[idx][0]));\n"
"}\n"
"idx := idx + 1;\n"
"}\n"
"}\n"
"return NULL;\n"
"}\n"
"--src 2pc.sql:147\n";

static const char *other0 = 
"grant execute on \"_2PC.DBA._0001_ADD_ENTRY\" to public\n";
static const char *other1 = 
"grant execute on \"_2PC.DBA._0001_TRX_SSTATE\" to public\n";
static const char *other2 = 
"grant execute on \"_2PC.DBA._0001_GET_TRX_STATE\" to public\n";
static const char *other3 = 
"grant execute on \"DB.DBA.XA_GET_ALL_XIDS_COUNT\" to public\n";
static const char *other4 = 
"grant execute on \"DB.DBA.XA_GET_ALL_XIDS\" to public\n";
static int
sch_proc_def_exists (client_connection_t *cli, const char *proc_name, const int report)
{
  query_t *proc = NULL;
  char *full_name = sch_full_proc_name (isp_schema(NULL), proc_name,
	cli->cli_qualifier, CLI_OWNER (cli));
  if (full_name)
    proc = sch_proc_def (isp_schema(NULL), full_name);
  if (report && proc != NULL)
     log_debug ("built-in procedure \"%s\" overruled by the RDBMS", proc_name);
  return (proc != NULL);
}

#define DEFINE_PROC(name, proc) \
   if (!sch_proc_def_exists (bootstrap_cli, (name), log_proc_overwrite)) \
     ddl_std_proc_1 (proc, 0x0, 1)


#define DEFINE_PUBLIC_PROC(name, proc) \
   if (!sch_proc_def_exists (bootstrap_cli, (name), log_proc_overwrite)) \
     ddl_std_proc_1 (proc, 0x1, 1)


#define DEFINE_OVERWRITE_PROC(name, proc) \
   ddl_std_proc_1 (proc, 0x1, 1)


void
sqls_define_2pc (void)
{
  /* 2pc.sql */

  ddl_ensure_table ("_2PC.DBA.TRANSACTIONS", tbl0);
  DEFINE_PROC ("_2PC.DBA._FFFF_GET_SEQ_NEXT", proc0);
  DEFINE_PROC ("_2PC.DBA._0001_ADD_ENTRY", proc1);
  DEFINE_PROC ("_2PC.DBA._FFFF_CHECK_TRX_ID", proc2);
  DEFINE_PROC ("_2PC.DBA._0001_TRX_SSTATE", proc3);
  DEFINE_PROC ("_2PC.DBA._0001_GET_TRX_STATE", proc4);
  DEFINE_PROC ("_2PC.DBA.virt_tp_enlist_branch", proc5);
  DEFINE_PROC ("_2PC.DBA.XA_GET_ALL_XIDS_COUNT", proc6);
  DEFINE_PROC ("_2PC.DBA.OLD_XA_GET_ALL_XIDS", proc7);
  DEFINE_PROC ("_2PC.DBA.XA_GET_ALL_XIDS", proc8);
  ddl_ensure_table ("do this always", other0);
  ddl_ensure_table ("do this always", other1);
  ddl_ensure_table ("do this always", other2);
  ddl_ensure_table ("do this always", other3);
  ddl_ensure_table ("do this always", other4);
}


void
sqls_arfw_define_2pc (void)
{
}