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

Commit cdbaec7

Browse files
committed
From: Michael Meskes <Michael.Meskes@usa.net> See attached file. Now accepts "exec sql whenever sqlwarning".
1 parent 1f37905 commit cdbaec7

File tree

6 files changed

+51
-18
lines changed

6 files changed

+51
-18
lines changed

src/interfaces/ecpg/ChangeLog

+12-6
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ Thu Sep 17 08:55:33 CEST 1998
335335

336336
Thu Sep 17 19:23:24 CEST 1998
337337

338-
- Added missing �;� in preproc.y
338+
- Added missing ';' in preproc.y
339339
- Set version to 2.4.2
340340

341341
Tue Sep 29 10:22:00 CEST 1998
@@ -357,23 +357,29 @@ Thu Okt 15 10:05:04 CEST 1998
357357
- Synced preproc.y with gram.y yet again.
358358
- Set version to 2.4.4
359359

360-
Wed Dec 9 11:24:54 MEZ 1998
360+
Wed Dec 9 20:24:54 MEZ 1998
361361

362362
- Synced preproc.y with gram.y and the keywords.c files to add CASE
363363
statement.
364364

365-
Tue Dec 22 14:16:11 CET 1998
365+
Tue Dec 22 19:16:11 CET 1998
366366

367367
- Synced preproc.y with gram.y for locking statements.
368368
- Set version to 2.4.5
369369

370-
Tue Jan 7 15:19:34 CET 1999
370+
Tue Jan 7 19:19:34 CET 1999
371371

372372
- Synced preproc.y with gram.y for for-update clause and changes in
373373
handling of numerics
374374

375-
Mon Jan 18 11:22:44 CET 1999
375+
Mon Jan 18 19:22:44 CET 1999
376376

377377
- Added INTERSECT, EXCEPT and UNION for Select statements
378378
- Put keywords.c in sync again after forgettimg it the last time.
379-
- Set version to 2.4.6
379+
380+
Thu Jan 21 21:29:00 CET 1999
381+
382+
- Fixed libecpg to not segfault if there is no connection.
383+
- Set library version to 2.6.3
384+
- Added 'exec sql whenever sqlwarning'.
385+
- Set ecpg version to 2.4.6

src/interfaces/ecpg/lib/Makefile.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
# Copyright (c) 1994, Regents of the University of California
77
#
88
# IDENTIFICATION
9-
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.39 1999/01/17 06:19:24 momjian Exp $
9+
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.40 1999/01/21 20:01:32 scrappy Exp $
1010
#
1111
#-------------------------------------------------------------------------
1212

1313
NAME= ecpg
1414
SO_MAJOR_VERSION= 2
15-
SO_MINOR_VERSION= 6.2
15+
SO_MINOR_VERSION= 6.3
1616

1717
SRCDIR= @top_srcdir@
1818
include $(SRCDIR)/Makefile.global

src/interfaces/ecpg/lib/ecpglib.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -886,12 +886,17 @@ ECPGtrans(int lineno, const char *transaction)
886886
PGresult *res;
887887

888888
ECPGlog("ECPGtrans line %d action = %s\n", lineno, transaction);
889-
if ((res = PQexec(actual_connection->connection, transaction)) == NULL)
889+
890+
/* if we have no connection we just simulate the command */
891+
if (actual_connection && actual_connection->connection)
890892
{
891-
register_error(ECPG_TRANS, "Error in transaction processing line %d.", lineno);
892-
return FALSE;
893+
if ((res = PQexec(actual_connection->connection, transaction)) == NULL)
894+
{
895+
register_error(ECPG_TRANS, "Error in transaction processing line %d.", lineno);
896+
return FALSE;
897+
}
898+
PQclear(res);
893899
}
894-
PQclear(res);
895900
if (strcmp(transaction, "commit") == 0 || strcmp(transaction, "rollback") == 0)
896901
committed = 1;
897902
return TRUE;

src/interfaces/ecpg/preproc/ecpg_keywords.c

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static ScanKeyword ScanKeywords[] = {
3838
{"section", SQL_SECTION},
3939
{"sqlerror", SQL_SQLERROR},
4040
{"sqlprint", SQL_SQLPRINT},
41+
{"sqlwarning", SQL_SQLWARNING},
4142
{"stop", SQL_STOP},
4243
{"whenever", SQL_WHENEVER},
4344
};

src/interfaces/ecpg/preproc/preproc.y

+14-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ output_line_number()
4545
/*
4646
* store the whenever action here
4747
*/
48-
static struct when when_error, when_nf;
48+
static struct when when_error, when_nf, when_warn;
4949

5050
static void
5151
print_action(struct when *w)
@@ -76,6 +76,12 @@ whenever_action(int mode)
7676
fprintf(yyout, "\nif (sqlca.sqlcode == ECPG_NOT_FOUND) ");
7777
print_action(&when_nf);
7878
}
79+
if (when_warn.code != W_NOTHING)
80+
{
81+
output_line_number();
82+
fprintf(yyout, "\nif (sqlca.sqlwarn[0] == 'W') ");
83+
print_action(&when_warn);
84+
}
7985
if (when_error.code != W_NOTHING)
8086
{
8187
output_line_number();
@@ -517,7 +523,7 @@ output_statement(char * stmt, int mode)
517523
%token SQL_DISCONNECT SQL_FOUND SQL_GO SQL_GOTO
518524
%token SQL_IDENTIFIED SQL_IMMEDIATE SQL_INDICATOR SQL_OPEN SQL_RELEASE
519525
%token SQL_SECTION SQL_SEMI SQL_SQLERROR SQL_SQLPRINT SQL_START
520-
%token SQL_STOP SQL_WHENEVER
526+
%token SQL_STOP SQL_WHENEVER SQL_SQLWARNING
521527

522528
/* C token */
523529
%token S_ANYTHING S_AUTO S_BOOL S_CHAR S_CONST S_DOUBLE S_ENUM S_EXTERN
@@ -4630,9 +4636,7 @@ ECPGSetConnection: SET SQL_CONNECTION connection_object
46304636
}
46314637
/*
46324638
* whenever statement: decide what to do in case of error/no data found
4633-
* according to SQL standards we miss: SQLSTATE, CONSTRAINT, SQLEXCEPTION
4634-
* and SQLWARNING
4635-
4639+
* according to SQL standards we lack: SQLSTATE, CONSTRAINT and SQLEXCEPTION
46364640
*/
46374641
ECPGWhenever: SQL_WHENEVER SQL_SQLERROR action {
46384642
when_error.code = $<action>3.code;
@@ -4644,6 +4648,11 @@ ECPGWhenever: SQL_WHENEVER SQL_SQLERROR action {
46444648
when_nf.command = $<action>4.command;
46454649
$$ = cat3_str(make1_str("/* exec sql whenever not found "), $4.str, make1_str("; */\n"));
46464650
}
4651+
| SQL_WHENEVER SQL_SQLWARNING action {
4652+
when_warn.code = $<action>3.code;
4653+
when_warn.command = $<action>3.command;
4654+
$$ = cat3_str(make1_str("/* exec sql whenever sql_warning "), $3.str, make1_str("; */\n"));
4655+
}
46474656

46484657
action : SQL_CONTINUE {
46494658
$<action>$.code = W_NOTHING;
+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
exec sql include sqlca;
22

3-
exec sql whenever sqlerror sqlprint;
3+
exec sql whenever sqlerror do print_and_stop();
4+
exec sql whenever sqlwarning do warn();
5+
6+
void print_and_stop(void)
7+
{
8+
sqlprint();
9+
exit(-1);
10+
}
11+
12+
void warn(void)
13+
{
14+
fprintf(stderr, "Warning: At least one column was truncated\n");
15+
}

0 commit comments

Comments
 (0)