提交 b53955f3 编写于 作者: M Michael Meskes

*** empty log message ***

上级 dd979f66
......@@ -775,5 +775,21 @@ Mon Jan 17 21:55:40 CET 2000
- Synced preproc.y with gram.y.
- Changed FETCH syntax using Rene's final patch. Made it more
standard compliant.
Thu Jan 20 10:00:50 CET 2000
- Synced preproc.y with gram.y.
Fri Jan 21 14:52:27 CET 2000
- Added more log output to ecpglib.
Thu Jan 27 08:12:05 CET 2000
- Added another patch by Rene Hogendoorn.
- Fixed error messages in pgc.l.
- Improved variable parsing.
- Synced preproc.y with gram.y.
- Set library version to 3.0.10.
- Set ecpg version to 2.7.0.
......@@ -9,7 +9,7 @@
slightly modified)
*/
/* Taken over as part of PostgreSQL by Michael Meskes <meskes@debian.org>
/* Taken over as part of PostgreSQL by Michael Meskes <meskes@postgresql.org>
on Feb. 5th, 1998 */
#include <stdio.h>
......@@ -724,6 +724,9 @@ ECPGexecute(struct statement * stmt)
*((void **) var->pointer) = var->value;
add_mem(var->value, stmt->lineno);
}
ECPGlog("ECPGexecute line %d: TYPE db: %d c: %d\n", stmt->lineno, PQftype(results, act_field), var->type);
for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++)
{
......@@ -764,7 +767,7 @@ ECPGexecute(struct statement * stmt)
status = false;
break;
}
switch (var->type)
{
long res;
......
......@@ -19,25 +19,26 @@
*/
static ScanKeyword ScanKeywords[] = {
/* name value */
{"VARCHAR", S_VARCHAR},
{"VARCHAR", VARCHAR},
{"auto", S_AUTO},
{"bool", S_BOOL},
{"char", S_CHAR},
{"bool", SQL_BOOL},
{"char", CHAR},
{"const", S_CONST},
{"double", S_DOUBLE},
{"enum", S_ENUM},
{"double", DOUBLE},
{"enum", SQL_ENUM},
{"extern", S_EXTERN},
{"float", S_FLOAT},
{"int", S_INT},
{"long", S_LONG},
{"float", FLOAT},
{"int", SQL_INT},
{"long", SQL_LONG},
{"register", S_REGISTER},
{"short", S_SHORT},
{"signed", S_SIGNED},
{"short", SQL_SHORT},
{"signed", SQL_SIGNED},
{"static", S_STATIC},
{"struct", S_STRUCT},
{"union", S_UNION},
{"unsigned", S_UNSIGNED},
{"varchar", S_VARCHAR},
{"struct", SQL_STRUCT},
{"union", UNION},
{"unsigned", SQL_UNSIGNED},
{"varchar", VARCHAR},
{"volatile", S_VOLATILE},
};
ScanKeyword *
......
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
/* (C) Michael Meskes <meskes@debian.org> Feb 5th, 1998 */
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
/* Placed under the same copyright as PostgresSQL */
#include <unistd.h>
......
......@@ -40,6 +40,7 @@ extern int yylex(void);
extern void yyerror(char *);
extern void *mm_alloc(size_t), *mm_realloc(void *, size_t);
extern char *mm_strdup(const char *);
extern void mmerror(enum errortype, char * );
ScanKeyword *ScanECPGKeywordLookup(char *);
ScanKeyword *ScanCKeywordLookup(char *);
......
......@@ -12,7 +12,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.49 2000/01/26 05:58:41 momjian Exp $
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.50 2000/01/27 19:00:39 meskes Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -246,7 +246,7 @@ cppline {space}*#(.*\\{line_end})*.*
errno = 0;
yylval.ival = strtol(literalbuf, &endptr, 2);
if (*endptr != '\0' || errno == ERANGE)
yyerror("ERROR: Bad binary integer input!");
mmerror(ET_ERROR, "Bad binary integer input!");
return ICONST;
}
<xh>{xhinside} |
......@@ -268,7 +268,7 @@ cppline {space}*#(.*\\{line_end})*.*
errno = 0;
yylval.ival = strtol(literalbuf, &endptr, 16);
if (*endptr != '\0' || errno == ERANGE)
yyerror("ERROR: Bad hexadecimal integer input");
mmerror(ET_ERROR, "Bad hexadecimal integer input");
return ICONST;
}
......@@ -355,7 +355,7 @@ cppline {space}*#(.*\\{line_end})*.*
errno = 0;
yylval.dval = strtod((char *)yytext,&endptr);
if (*endptr != '\0' || errno == ERANGE)
yyerror("ERROR: Bad float8 input");
mmerror(ET_ERROR, "Bad float8 input");
return FCONST;
}
yylval.str = mm_strdup((char*)yytext);
......@@ -367,7 +367,7 @@ cppline {space}*#(.*\\{line_end})*.*
errno = 0;
yylval.dval = strtod((char *)yytext,&endptr);
if (*endptr != '\0' || errno == ERANGE)
yyerror("ERROR: Bad float input");
mmerror(ET_ERROR, "Bad float input");
return FCONST;
}
<SQL>:{identifier}(("->"|\.){identifier})* {
......@@ -385,6 +385,13 @@ cppline {space}*#(.*\\{line_end})*.*
if (isascii((unsigned char)lower_text[i]) && isupper(lower_text[i]))
lower_text[i] = tolower(lower_text[i]);
if (i >= NAMEDATALEN)
{
sprintf(errortext, "Identifier \"%s\" will be truncated to \"%.*s\"", yytext, NAMEDATALEN-1, yytext);
mmerror (ET_WARN, errortext);
yytext[NAMEDATALEN-1] = '\0';
}
keyword = ScanKeywordLookup((char*)lower_text);
if (keyword != NULL) {
return keyword->value;
......@@ -509,10 +516,10 @@ cppline {space}*#(.*\\{line_end})*.*
<C,xskip>{exec_sql}{elif}{space_or_nl}* { /* pop stack */
if ( preproc_tos == 0 ) {
yyerror("ERROR: missing matching 'EXEC SQL IFDEF / EXEC SQL IFNDEF'");
mmerror(ET_FATAL, "Missing matching 'EXEC SQL IFDEF / EXEC SQL IFNDEF'");
}
else if ( stacked_if_value[preproc_tos].else_branch ) {
yyerror("ERROR: missing 'EXEC SQL ENDIF;'");
mmerror(ET_FATAL, "Missing 'EXEC SQL ENDIF;'");
}
else {
preproc_tos--;
......@@ -523,7 +530,7 @@ cppline {space}*#(.*\\{line_end})*.*
<C,xskip>{exec_sql}{else}{space_or_nl}*";" { /* only exec sql endif pops the stack, so take care of duplicated 'else' */
if ( stacked_if_value[preproc_tos].else_branch ) {
yyerror("ERROR: duplicated 'EXEC SQL ELSE;'");
mmerror(ET_FATAL, "Duplicated 'EXEC SQL ELSE;'");
}
else {
stacked_if_value[preproc_tos].else_branch = TRUE;
......@@ -541,7 +548,7 @@ cppline {space}*#(.*\\{line_end})*.*
}
<C,xskip>{exec_sql}{endif}{space_or_nl}*";" {
if ( preproc_tos == 0 ) {
yyerror("ERROR: unmatched 'EXEC SQL ENDIF;'");
mmerror(ET_FATAL, "Unmatched 'EXEC SQL ENDIF;'");
}
else {
preproc_tos--;
......@@ -559,7 +566,7 @@ cppline {space}*#(.*\\{line_end})*.*
<xcond>{identifier}{space_or_nl}*";" {
if ( preproc_tos >= MAX_NESTED_IF-1 ) {
yyerror("ERROR: too many nested 'EXEC SQL IFDEF' conditions");
mmerror(ET_FATAL, "Too many nested 'EXEC SQL IFDEF' conditions");
}
else {
struct _defines *defptr;
......@@ -680,7 +687,7 @@ cppline {space}*#(.*\\{line_end})*.*
if ( preproc_tos > 0 ) {
preproc_tos = 0;
yyerror("ERROR: missing 'EXEC SQL ENDIF;'");
mmerror(ET_FATAL, "Missing 'EXEC SQL ENDIF;'");
}
if (yy_buffer == NULL)
......
......@@ -138,3 +138,5 @@ struct arguments
struct variable *indicator;
struct arguments *next;
};
enum errortype {ET_WARN, ET_ERROR, ET_FATAL};
all: test1 test2 test3 test4 perftest
all: stp.so test1 test2 test3 test4 test5 perftest
#LDFLAGS=-g -I /usr/local/pgsql/include -L/usr/local/pgsql/lib -lecpg -lpq -lcrypt
LDFLAGS=-g -I../include -I/usr/include/postgresql -L/usr/lib/postgresql -L../lib -lecpg -lpq -lcrypt
#LDFLAGS=-g -I/usr/include/postgresql -lecpg -lpq -lcrypt
#ECPG=/usr/local/pgsql/bin/ecpg
ECPG=../preproc/ecpg -I../include
#ECPG=/usr/bin/ecpg -I/usr/include/postgresql
.SUFFIXES: .pgc .c
......@@ -12,10 +14,16 @@ test1: test1.c
test2: test2.c
test3: test3.c
test4: test4.c
test5: test5.c
perftest: perftest.c
.pgc.c:
$(ECPG) $?
stp.so: stp.c
cc -fPIC -I../include -I/usr/include/postgresql -c -o stp.o stp.c
cc -shared -Wl,-soname,stp.so -o stp.so stp.o -lpq -lecpg
clean:
-/bin/rm test1 test2 test3 test4 perftest *.c log
-/bin/rm test1 test2 test3 test4 test5 perftest *.c log stp.o stp.so
EXEC SQL INCLUDE sqlca;
int my_fun (void)
{
EXEC SQL BEGIN DECLARE SECTION;
int sql_index = 0;
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLERROR GOTO Error;
EXEC SQL SELECT MIN(index) INTO :sql_index FROM tab;
return (sql_index);
Error:
return (sqlca.sqlcode);
}
......@@ -94,11 +94,20 @@ exec sql end declare section;
strcpy(msg, "select");
exec sql select name, amount, letter into :name, :amount, :letter from "Test";
printf("Database: mm\n");
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
{
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, name[i], i, amount[i],i, letter[i][0]);
amount[i]+=1000;
}
strcpy(msg, "insert");
exec sql at pm insert into "Test" (name, amount, letter) values (:name, :amount, :letter);
strcpy(msg, "select");
exec sql at pm select * into :name, :amount, :letter from "Test";
printf("Database: pm\n");
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
printf("name[%d]=%8.8s\tamount[%d]=%d\tletter[%d]=%c\n", i, name[i], i, amount[i],i, letter[i][0]);
......
......@@ -62,7 +62,7 @@ exec sql end declare section;
while (1) {
strcpy(msg, "fetch");
exec sql fetch from cur into :personal:ind_personal, :married:ind_married, :children.integer:ind_children.smallint;
exec sql fetch cur into :personal:ind_personal, :married:ind_married, :children.integer:ind_children.smallint;
printf("%8.8s", personal.name.arr);
if (ind_personal.ind_birth.born >= 0)
printf(", born %d", personal.birth.born);
......
......@@ -19,7 +19,7 @@ exec sql begin declare section;
int ind_children;
str *married = NULL;
char *wifesname="Petra";
char *query="select * from meskes where name = :var1";
char *query="select * from meskes where name = ?";
exec sql end declare section;
exec sql declare cur cursor for
......@@ -54,7 +54,7 @@ exec sql end declare section;
while (1) {
strcpy(msg, "fetch");
exec sql fetch cur into :personal:ind_personal, :married:ind_married, :children:ind_children;
exec sql fetch from cur into :personal:ind_personal, :married:ind_married, :children:ind_children;
printf("%8.8s", personal.name.arr);
if (ind_personal.ind_birth.born >= 0)
printf(", born %d", personal.birth.born);
......@@ -74,7 +74,7 @@ exec sql end declare section;
exec sql close cur;
/* and now a query with prepare */
exec sql prepare MM from "select name, born, age, married, children from meskes where name = ?";
exec sql prepare MM from :query;
exec sql declare prep cursor for MM;
strcpy(msg, "open");
......
#include <stdlib.h>
#include <stdio.h>
EXEC SQL INCLUDE sqlca;
static void ErrorExit (void);
int main (void)
{
EXEC SQL BEGIN DECLARE SECTION;
int result;
int values[2], i;
EXEC SQL END DECLARE SECTION;
FILE *dbgs;
if ((dbgs = fopen("log", "w")) != NULL)
ECPGdebug(1, dbgs);
EXEC SQL WHENEVER SQLERROR DO ErrorExit();
EXEC SQL CONNECT TO 'mm';
EXEC SQL CREATE TABLE tab (index int);
EXEC SQL INSERT INTO tab(index) values(14);
EXEC SQL INSERT INTO tab(index) values(7);
EXEC SQL COMMIT;
EXEC SQL CREATE FUNCTION my_fun () RETURNS int AS
'/home/postgres/pgsql/src/interfaces/ecpg.mm/test/stp.so' LANGUAGE 'C';
EXEC SQL COMMIT;
EXEC SQL SELECT index INTO :values FROM tab;
for (i = 0; i < 2; i++)
printf("tab[%d] = %d\n", i, values[i]);
EXEC SQL SELECT my_fun () INTO :result;
printf ("result = %d\n", result);
EXEC SQL DROP TABLE tab;
EXEC SQL DROP FUNCTION my_fun ();
EXEC SQL COMMIT;
EXEC SQL DISCONNECT;
if (dbgs != NULL)
fclose(dbgs);
exit (0);
}
static void ErrorExit (void)
{
EXEC SQL WHENEVER SQLERROR CONTINUE;
sqlprint();
EXEC SQL DROP TABLE tab;
EXEC SQL DROP FUNCTION my_fun ();
EXEC SQL COMMIT;
EXEC SQL DISCONNECT;
exit (-1);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册