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

Commit 29e2916

Browse files
author
Michael Meskes
committed
*** empty log message ***
1 parent 9a4344e commit 29e2916

File tree

8 files changed

+101
-40
lines changed

8 files changed

+101
-40
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,10 @@ Mon Apr 12 17:56:14 CEST 1999
555555
- Fixed ECPG variable handling.
556556
- Make no_auto_trans be accessible via SET command.
557557
- Do not eat comments so line numbering should be correct.
558+
559+
Wed Apr 14 17:59:06 CEST 1999
560+
561+
- Added simple calculations for array bounds.
558562
- Set library version to 3.0.0
559563
- Set ecpg version to 2.6.0
560564

src/interfaces/ecpg/include/ecpglib.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ extern "C"
4545
struct cursor *next;
4646
};
4747

48-
extern int no_auto_trans;
49-
5048
/* define this for simplicity as well as compatibility */
5149

5250
#define SQLCODE sqlca.sqlcode

src/interfaces/ecpg/lib/ecpglib.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static struct connection
5555
char *name;
5656
PGconn *connection;
5757
bool committed;
58-
int no_auto_trans;
58+
int autocommit;
5959
struct connection *next;
6060
} *all_connections = NULL, *actual_connection = NULL;
6161

@@ -660,7 +660,7 @@ ECPGexecute(struct statement * stmt)
660660

661661
/* Now the request is built. */
662662

663-
if (stmt->connection->committed && !stmt->connection->no_auto_trans)
663+
if (stmt->connection->committed && !stmt->connection->autocommit)
664664
{
665665
if ((results = PQexec(stmt->connection->connection, "begin transaction")) == NULL)
666666
{
@@ -1164,7 +1164,7 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
11641164

11651165
if (con)
11661166
{
1167-
if (con->no_auto_trans == true && strncmp(mode, "ON", strlen("ON")) == 0)
1167+
if (con->autocommit == true && strncmp(mode, "OFF", strlen("OFF")) == 0)
11681168
{
11691169
if (con->committed)
11701170
{
@@ -1176,9 +1176,9 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
11761176
PQclear(results);
11771177
con->committed = false;
11781178
}
1179-
con->no_auto_trans = false;
1179+
con->autocommit = false;
11801180
}
1181-
else if (con->no_auto_trans == false && strncmp(mode, "OFF", strlen("OFF")) == 0)
1181+
else if (con->autocommit == false && strncmp(mode, "ON", strlen("ON")) == 0)
11821182
{
11831183
if (!con->committed)
11841184
{
@@ -1190,7 +1190,7 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name)
11901190
PQclear(results);
11911191
con->committed = true;
11921192
}
1193-
con->no_auto_trans = true;
1193+
con->autocommit = true;
11941194
}
11951195
}
11961196
else
@@ -1220,7 +1220,7 @@ ECPGsetconn(int lineno, const char *connection_name)
12201220
}
12211221

12221222
bool
1223-
ECPGconnect(int lineno, const char *dbname, const char *user, const char *passwd, const char *connection_name, int no_auto_trans)
1223+
ECPGconnect(int lineno, const char *dbname, const char *user, const char *passwd, const char *connection_name, int autocommit)
12241224
{
12251225
struct connection *this = (struct connection *) ecpg_alloc(sizeof(struct connection), lineno);
12261226

@@ -1258,7 +1258,7 @@ ECPGconnect(int lineno, const char *dbname, const char *user, const char *passwd
12581258
}
12591259

12601260
this->committed = true;
1261-
this->no_auto_trans = no_auto_trans;
1261+
this->autocommit = autocommit;
12621262

12631263
return true;
12641264
}

src/interfaces/ecpg/preproc/ecpg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern char *optarg;
2323
#include "extern.h"
2424

2525
struct _include_path *include_paths;
26-
int no_auto_trans = 0;
26+
int autocommit = 0;
2727
struct cursor *cur = NULL;
2828
struct typedefs *types = NULL;
2929

@@ -76,7 +76,7 @@ main(int argc, char *const argv[])
7676
add_include_path(optarg);
7777
break;
7878
case 't':
79-
no_auto_trans = 1;
79+
autocommit = 1;
8080
break;
8181
case 'v':
8282
fprintf(stderr, "ecpg - the postgresql preprocessor, version: %d.%d.%d\n", MAJOR_VERSION, MINOR_VERSION, PATCHLEVEL);

src/interfaces/ecpg/preproc/ecpg_keywords.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
static ScanKeyword ScanKeywords[] = {
2222
/* name value */
2323
{"at", SQL_AT},
24+
{"autocommit", SQL_AUTOCOMMIT},
2425
{"bool", SQL_BOOL},
2526
{"break", SQL_BREAK},
2627
{"call", SQL_CALL},
@@ -39,6 +40,7 @@ static ScanKeyword ScanKeywords[] = {
3940
{"indicator", SQL_INDICATOR},
4041
{"int", SQL_INT},
4142
{"long", SQL_LONG},
43+
{"off", SQL_OFF},
4244
{"open", SQL_OPEN},
4345
{"prepare", SQL_PREPARE},
4446
{"reference", SQL_REFERENCE},

src/interfaces/ecpg/preproc/extern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/* variables */
66

77
extern int braces_open,
8-
no_auto_trans, struct_level;
8+
autocommit, struct_level;
99
extern char *yytext, errortext[128];
1010
extern int yylineno,
1111
yyleng;

src/interfaces/ecpg/preproc/preproc.y

Lines changed: 79 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -654,12 +654,12 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
654654
}
655655

656656
/* special embedded SQL token */
657-
%token SQL_AT SQL_BOOL SQL_BREAK
657+
%token SQL_AT SQL_AUTOCOMMIT SQL_BOOL SQL_BREAK
658658
%token SQL_CALL SQL_CONNECT SQL_CONNECTION SQL_CONTINUE
659659
%token SQL_DEALLOCATE SQL_DISCONNECT SQL_ENUM
660660
%token SQL_FOUND SQL_FREE SQL_GO SQL_GOTO
661661
%token SQL_IDENTIFIED SQL_IMMEDIATE SQL_INDICATOR SQL_INT SQL_LONG
662-
%token SQL_OPEN SQL_PREPARE SQL_RELEASE SQL_REFERENCE
662+
%token SQL_OFF SQL_OPEN SQL_PREPARE SQL_RELEASE SQL_REFERENCE
663663
%token SQL_SECTION SQL_SHORT SQL_SIGNED SQL_SQLERROR SQL_SQLPRINT
664664
%token SQL_SQLWARNING SQL_START SQL_STOP SQL_STRUCT SQL_UNSIGNED
665665
%token SQL_VAR SQL_WHENEVER
@@ -831,7 +831,7 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
831831
%type <str> ECPGFree ECPGDeclare ECPGVar sql_variable_declarations
832832
%type <str> sql_declaration sql_variable_list sql_variable opt_at
833833
%type <str> struct_type s_struct declaration variable_declarations
834-
%type <str> s_struct s_union union_type
834+
%type <str> s_struct s_union union_type ECPGSetAutocommit on_off
835835

836836
%type <type_enum> simple_type varchar_type
837837

@@ -842,6 +842,7 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim
842842
%type <index> opt_array_bounds nest_array_bounds opt_type_array_bounds
843843
%type <index> nest_type_array_bounds
844844

845+
%type <ival> Iresult
845846
%%
846847
prog: statements;
847848

@@ -913,7 +914,7 @@ stmt: AddAttrStmt { output_statement($1, 0); }
913914
if (connection)
914915
yyerror("no at option for connect statement.\n");
915916

916-
fprintf(yyout, "ECPGconnect(__LINE__, %s, %d);", $1, no_auto_trans);
917+
fprintf(yyout, "ECPGconnect(__LINE__, %s, %d);", $1, autocommit);
917918
whenever_action(0);
918919
free($1);
919920
}
@@ -981,6 +982,11 @@ stmt: AddAttrStmt { output_statement($1, 0); }
981982
free($1);
982983
}
983984
| ECPGRelease { /* output already done */ }
985+
| ECPGSetAutocommit {
986+
fprintf(yyout, "ECPGsetcommit(__LINE__, \"%s\", %s);", $1, connection ? connection : "NULL");
987+
whenever_action(0);
988+
free($1);
989+
}
984990
| ECPGSetConnection {
985991
if (connection)
986992
yyerror("no at option for set connection statement.\n");
@@ -3170,11 +3176,14 @@ opt_array_bounds: '[' ']' nest_array_bounds
31703176
$$.index2 = $3.index1;
31713177
$$.str = cat2_str(make1_str("[]"), $3.str);
31723178
}
3173-
| '[' Iconst ']' nest_array_bounds
3179+
| '[' Iresult ']' nest_array_bounds
31743180
{
3175-
$$.index1 = atol($2);
3181+
char *txt = mm_alloc(20L);
3182+
3183+
sprintf (txt, "%d", $2);
3184+
$$.index1 = $2;
31763185
$$.index2 = $4.index1;
3177-
$$.str = cat4_str(make1_str("["), $2, make1_str("]"), $4.str);
3186+
$$.str = cat4_str(make1_str("["), txt, make1_str("]"), $4.str);
31783187
}
31793188
| /* EMPTY */
31803189
{
@@ -3190,11 +3199,14 @@ nest_array_bounds: '[' ']' nest_array_bounds
31903199
$$.index2 = $3.index1;
31913200
$$.str = cat2_str(make1_str("[]"), $3.str);
31923201
}
3193-
| '[' Iconst ']' nest_array_bounds
3202+
| '[' Iresult ']' nest_array_bounds
31943203
{
3195-
$$.index1 = atol($2);
3204+
char *txt = mm_alloc(20L);
3205+
3206+
sprintf (txt, "%d", $2);
3207+
$$.index1 = $2;
31963208
$$.index2 = $4.index1;
3197-
$$.str = cat4_str(make1_str("["), $2, make1_str("]"), $4.str);
3209+
$$.str = cat4_str(make1_str("["), txt, make1_str("]"), $4.str);
31983210
}
31993211
| /* EMPTY */
32003212
{
@@ -3204,6 +3216,16 @@ nest_array_bounds: '[' ']' nest_array_bounds
32043216
}
32053217
;
32063218

3219+
Iresult: Iconst { $$ = atol($1); }
3220+
| '(' Iresult ')' { $$ = $2; }
3221+
| Iresult '+' Iresult { $$ = $1 + $3};
3222+
| Iresult '-' Iresult { $$ = $1 - $3};
3223+
| Iresult '*' Iresult { $$ = $1 * $3};
3224+
| Iresult '/' Iresult { $$ = $1 / $3};
3225+
| Iresult '%' Iresult { $$ = $1 % $3};
3226+
3227+
3228+
32073229
/*****************************************************************************
32083230
*
32093231
* Type syntax
@@ -3239,6 +3261,7 @@ Generic: generic
32393261
generic: ident { $$ = $1; }
32403262
| TYPE_P { $$ = make1_str("type"); }
32413263
| SQL_AT { $$ = make1_str("at"); }
3264+
| SQL_AUTOCOMMIT { $$ = make1_str("autocommit"); }
32423265
| SQL_BOOL { $$ = make1_str("bool"); }
32433266
| SQL_BREAK { $$ = make1_str("break"); }
32443267
| SQL_CALL { $$ = make1_str("call"); }
@@ -3255,6 +3278,7 @@ generic: ident { $$ = $1; }
32553278
| SQL_INDICATOR { $$ = make1_str("indicator"); }
32563279
| SQL_INT { $$ = make1_str("int"); }
32573280
| SQL_LONG { $$ = make1_str("long"); }
3281+
| SQL_OFF { $$ = make1_str("off"); }
32583282
| SQL_OPEN { $$ = make1_str("open"); }
32593283
| SQL_PREPARE { $$ = make1_str("prepare"); }
32603284
| SQL_RELEASE { $$ = make1_str("release"); }
@@ -4475,7 +4499,6 @@ ColId: ident { $$ = $1; }
44754499
| SQL_BREAK { $$ = make1_str("break"); }
44764500
| SQL_CALL { $$ = make1_str("call"); }
44774501
| SQL_CONNECT { $$ = make1_str("connect"); }
4478-
| SQL_CONNECTION { $$ = make1_str("connection"); }
44794502
| SQL_CONTINUE { $$ = make1_str("continue"); }
44804503
| SQL_DEALLOCATE { $$ = make1_str("deallocate"); }
44814504
| SQL_DISCONNECT { $$ = make1_str("disconnect"); }
@@ -4487,6 +4510,7 @@ ColId: ident { $$ = $1; }
44874510
| SQL_INDICATOR { $$ = make1_str("indicator"); }
44884511
| SQL_INT { $$ = make1_str("int"); }
44894512
| SQL_LONG { $$ = make1_str("long"); }
4513+
| SQL_OFF { $$ = make1_str("off"); }
44904514
| SQL_OPEN { $$ = make1_str("open"); }
44914515
| SQL_PREPARE { $$ = make1_str("prepare"); }
44924516
| SQL_RELEASE { $$ = make1_str("release"); }
@@ -5138,13 +5162,27 @@ ECPGRelease: TransactionStmt SQL_RELEASE
51385162
free($1);
51395163
}
51405164

5165+
/*
5166+
* set/reset the automatic transaction mode, this needs a differnet handling
5167+
* as the other set commands
5168+
*/
5169+
ECPGSetAutocommit: SET SQL_AUTOCOMMIT to_equal on_off
5170+
{
5171+
$$ = $4;
5172+
}
5173+
5174+
on_off: ON { $$ = make1_str("on"); }
5175+
| SQL_OFF { $$ = make1_str("off"); }
5176+
5177+
to_equal: TO | "=";
5178+
51415179
/*
51425180
* set the actual connection, this needs a differnet handling as the other
51435181
* set commands
51445182
*/
5145-
ECPGSetConnection: SET SQL_CONNECTION connection_object
5183+
ECPGSetConnection: SET SQL_CONNECTION to_equal connection_object
51465184
{
5147-
$$ = $3;
5185+
$$ = $4;
51485186
}
51495187

51505188
/*
@@ -5204,17 +5242,23 @@ opt_type_array_bounds: '[' ']' nest_type_array_bounds
52045242
$$.index2 = $3.index1;
52055243
$$.str = cat2_str(make1_str("[]"), $3.str);
52065244
}
5207-
| '[' Iconst ']' nest_type_array_bounds
5245+
| '[' Iresult ']' nest_type_array_bounds
52085246
{
5209-
$$.index1 = atol($2);
5247+
char *txt = mm_alloc(20L);
5248+
5249+
sprintf (txt, "%d", $2);
5250+
$$.index1 = $2;
52105251
$$.index2 = $4.index1;
5211-
$$.str = cat4_str(make1_str("["), $2, make1_str("]"), $4.str);
5252+
$$.str = cat4_str(make1_str("["), txt, make1_str("]"), $4.str);
52125253
}
5213-
| '(' Iconst ')' nest_type_array_bounds
5254+
| '(' Iresult ')' nest_type_array_bounds
52145255
{
5215-
$$.index1 = atol($2);
5256+
char *txt = mm_alloc(20L);
5257+
5258+
sprintf (txt, "%d", $2);
5259+
$$.index1 = $2;
52165260
$$.index2 = $4.index1;
5217-
$$.str = cat4_str(make1_str("["), $2, make1_str("]"), $4.str);
5261+
$$.str = cat4_str(make1_str("["), txt, make1_str("]"), $4.str);
52185262
}
52195263
| /* EMPTY */
52205264
{
@@ -5236,17 +5280,23 @@ nest_type_array_bounds: '[' ']' nest_type_array_bounds
52365280
$$.index2 = $3.index1;
52375281
$$.str = cat2_str(make1_str("[]"), $3.str);
52385282
}
5239-
| '[' Iconst ']' nest_type_array_bounds
5283+
| '[' Iresult ']' nest_type_array_bounds
52405284
{
5241-
$$.index1 = atol($2);
5285+
char *txt = mm_alloc(20L);
5286+
5287+
sprintf (txt, "%d", $2);
5288+
$$.index1 = $2;
52425289
$$.index2 = $4.index1;
5243-
$$.str = cat4_str(make1_str("["), $2, make1_str("]"), $4.str);
5290+
$$.str = cat4_str(make1_str("["), txt, make1_str("]"), $4.str);
52445291
}
5245-
| '(' Iconst ')' nest_type_array_bounds
5292+
| '(' Iresult ')' nest_type_array_bounds
52465293
{
5247-
$$.index1 = atol($2);
5294+
char *txt = mm_alloc(20L);
5295+
5296+
sprintf (txt, "%d", $2);
5297+
$$.index1 = $2;
52485298
$$.index2 = $4.index1;
5249-
$$.str = cat4_str(make1_str("["), $2, make1_str("]"), $4.str);
5299+
$$.str = cat4_str(make1_str("["), txt, make1_str("]"), $4.str);
52505300
}
52515301
| /* EMPTY */
52525302
{
@@ -5954,6 +6004,10 @@ c_anything: IDENT { $$ = $1; }
59546004
| Iconst { $$ = $1; }
59556005
| Fconst { $$ = $1; }
59566006
| '*' { $$ = make1_str("*"); }
6007+
| '+' { $$ = make1_str("+"); }
6008+
| '-' { $$ = make1_str("-"); }
6009+
| '/' { $$ = make1_str("/"); }
6010+
| '%' { $$ = make1_str("%"); }
59576011
| S_AUTO { $$ = make1_str("auto"); }
59586012
| S_BOOL { $$ = make1_str("bool"); }
59596013
| S_CHAR { $$ = make1_str("char"); }

src/interfaces/ecpg/test/test1.pgc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ exec sql whenever sqlerror sqlprint;
22

33
exec sql include sqlca;
44

5+
/* comment */
56
exec sql define AMOUNT 4;
67

78
exec sql type intarray is int[AMOUNT];
@@ -42,7 +43,7 @@ exec sql end declare section;
4243
exec sql commit;
4344

4445
strcpy(msg, "set connection");
45-
exec sql set connection main;
46+
exec sql set connection to main;
4647

4748
strcpy(msg, "execute insert 1");
4849
sprintf(command, "insert into test(name, amount, letter) values ('db: mm', 1, 'f')");
@@ -69,7 +70,9 @@ exec sql end declare section;
6970

7071
strcpy(msg, "commit");
7172
exec sql commit;
72-
exec sql at pm commit;
73+
74+
/* Stop automatic transactioning for connection pm. */
75+
exec sql at pm set autocommit to off;
7376

7477
strcpy(msg, "select");
7578
exec sql select name, amount, letter into :name, :amount, :letter from test;

0 commit comments

Comments
 (0)