Commit ee14711c authored by Michael Meskes's avatar Michael Meskes

- Fixed variable handling in AT statement.

        - Fixed bug that caused segfault when given incorrect DB name.
        - Fixed bug in ecpglib causing indicator to list the size of the
          variable instead of the size of the data.
parent 15790465
...@@ -1154,5 +1154,12 @@ Wed Nov 14 11:50:27 CET 2001 ...@@ -1154,5 +1154,12 @@ Wed Nov 14 11:50:27 CET 2001
Tue Dec 4 13:30:32 CET 2001 Tue Dec 4 13:30:32 CET 2001
- Fixed dumping of structures without indicators. - Fixed dumping of structures without indicators.
Wed Dec 5 12:27:25 CET 2001
- Fixed variable handling in AT statement.
- Fixed bug that caused segfault when given incorrect DB name.
- Fixed bug in ecpglib causing indicator to list the size of the
variable instead of the size of the data.
- Set ecpg version to 2.9.0. - Set ecpg version to 2.9.0.
- Set library version to 3.3.0. - Set library version to 3.3.0.
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.15 2001/11/14 11:11:49 meskes Exp $ */ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.16 2001/12/05 15:32:06 meskes Exp $ */
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -387,6 +387,10 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd, ...@@ -387,6 +387,10 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
host = strdup(dbname + offset); host = strdup(dbname + offset);
} }
else
{
realname = strdup(dbname);
}
} }
else else
realname = strdup(dbname); realname = strdup(dbname);
......
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/data.c,v 1.19 2001/11/14 11:11:49 meskes Exp $ */ /* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/data.c,v 1.20 2001/12/05 15:32:06 meskes Exp $ */
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -277,15 +277,15 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -277,15 +277,15 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
{ {
case ECPGt_short: case ECPGt_short:
case ECPGt_unsigned_short: case ECPGt_unsigned_short:
((short *) ind)[act_tuple] = varcharsize; ((short *) ind)[act_tuple] = strlen(pval);
break; break;
case ECPGt_int: case ECPGt_int:
case ECPGt_unsigned_int: case ECPGt_unsigned_int:
((int *) ind)[act_tuple] = varcharsize; ((int *) ind)[act_tuple] = strlen(pval);
break; break;
case ECPGt_long: case ECPGt_long:
case ECPGt_unsigned_long: case ECPGt_unsigned_long:
((long *) ind)[act_tuple] = varcharsize; ((long *) ind)[act_tuple] = strlen(pval);
break; break;
default: default:
break; break;
...@@ -300,12 +300,12 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -300,12 +300,12 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
struct ECPGgeneric_varchar *variable = struct ECPGgeneric_varchar *variable =
(struct ECPGgeneric_varchar *) ((long) var + offset * act_tuple); (struct ECPGgeneric_varchar *) ((long) var + offset * act_tuple);
variable->len = strlen(pval);
if (varcharsize == 0) if (varcharsize == 0)
strncpy(variable->arr, pval, strlen(pval)); strncpy(variable->arr, pval, variable->len);
else else
strncpy(variable->arr, pval, varcharsize); strncpy(variable->arr, pval, varcharsize);
variable->len = strlen(pval);
if (varcharsize > 0 && variable->len > varcharsize) if (varcharsize > 0 && variable->len > varcharsize)
{ {
/* truncation */ /* truncation */
...@@ -313,15 +313,15 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -313,15 +313,15 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
{ {
case ECPGt_short: case ECPGt_short:
case ECPGt_unsigned_short: case ECPGt_unsigned_short:
((short *) ind)[act_tuple] = varcharsize; ((short *) ind)[act_tuple] = variable->len;
break; break;
case ECPGt_int: case ECPGt_int:
case ECPGt_unsigned_int: case ECPGt_unsigned_int:
((int *) ind)[act_tuple] = varcharsize; ((int *) ind)[act_tuple] = variable->len;
break; break;
case ECPGt_long: case ECPGt_long:
case ECPGt_unsigned_long: case ECPGt_unsigned_long:
((long *) ind)[act_tuple] = varcharsize; ((long *) ind)[act_tuple] = variable->len;
break; break;
default: default:
break; break;
......
...@@ -392,7 +392,16 @@ statement: ecpgstart opt_at stmt ';' { connection = NULL; } ...@@ -392,7 +392,16 @@ statement: ecpgstart opt_at stmt ';' { connection = NULL; }
| blockend { fputs($1, yyout); free($1); } | blockend { fputs($1, yyout); free($1); }
; ;
opt_at: AT connection_target { connection = $2; }; opt_at: AT connection_target {
connection = $2;
/*
if we have a variable as connection
target, remove it from the variable
list or else it will be used twice
*/
if (argsinsert != NULL)
argsinsert = NULL;
};
stmt: AlterSchemaStmt { output_statement($1, 0, connection); } stmt: AlterSchemaStmt { output_statement($1, 0, connection); }
| AlterTableStmt { output_statement($1, 0, connection); } | AlterTableStmt { output_statement($1, 0, connection); }
...@@ -3877,6 +3886,13 @@ connection_target: database_name opt_server opt_port ...@@ -3877,6 +3886,13 @@ connection_target: database_name opt_server opt_port
| db_prefix ':' server opt_port '/' database_name opt_options | db_prefix ':' server opt_port '/' database_name opt_options
{ {
/* new style: <tcp|unix>:postgresql://server[:port][/dbname] */ /* new style: <tcp|unix>:postgresql://server[:port][/dbname] */
printf("%s\n", $1);
if (strncmp($1, "unix:postgresql", strlen("unix:postgresql")) != 0 && strncmp($1, "tcp:postgresql", strlen("tcp:postgresql")) != 0)
{
sprintf(errortext, "only protocols 'tcp' and 'unix' and database type 'postgresql' are supported");
mmerror(ET_ERROR, errortext);
}
if (strncmp($3, "//", strlen("//")) != 0) if (strncmp($3, "//", strlen("//")) != 0)
{ {
sprintf(errortext, "Expected '://', found '%s'", $3); sprintf(errortext, "Expected '://', found '%s'", $3);
...@@ -3891,12 +3907,6 @@ connection_target: database_name opt_server opt_port ...@@ -3891,12 +3907,6 @@ connection_target: database_name opt_server opt_port
mmerror(ET_ERROR, errortext); mmerror(ET_ERROR, errortext);
} }
if (strncmp($1, "unix", strlen("unix")) != 0 && strncmp($1, "tcp", strlen("tcp")) != 0)
{
sprintf(errortext, "only protocols 'tcp' and 'unix' are supported");
mmerror(ET_ERROR, errortext);
}
$$ = make3_str(make3_str(make_str("\""), $1, make_str(":")), $3, make3_str(make3_str($4, make_str("/"), $6), $7, make_str("\""))); $$ = make3_str(make3_str(make_str("\""), $1, make_str(":")), $3, make3_str(make3_str($4, make_str("/"), $6), $7, make_str("\"")));
} }
| StringConst | StringConst
......
...@@ -35,6 +35,7 @@ exec sql begin declare section; ...@@ -35,6 +35,7 @@ exec sql begin declare section;
char name[AMOUNT][8]; char name[AMOUNT][8];
char letter[AMOUNT][1]; char letter[AMOUNT][1];
char command[128]; char command[128];
char *connection="pm";
exec sql end declare section; exec sql end declare section;
exec sql var name is string(AMOUNT); exec sql var name is string(AMOUNT);
char msg[128]; char msg[128];
...@@ -94,7 +95,7 @@ exec sql end declare section; ...@@ -94,7 +95,7 @@ exec sql end declare section;
exec sql at pm begin transaction; exec sql at pm begin transaction;
strcpy(msg, "select"); strcpy(msg, "select");
exec sql select name, amount, letter into :name, :amount, :letter from "Test"; exec sql select * into :name, :amount, :letter from "Test";
printf("Database: mm\n"); printf("Database: mm\n");
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++) for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
...@@ -113,7 +114,7 @@ exec sql end declare section; ...@@ -113,7 +114,7 @@ exec sql end declare section;
} }
strcpy(msg, "select"); strcpy(msg, "select");
exec sql at pm select * into :name, :amount, :letter from "Test"; exec sql at :connection select name, amount, letter into :name, :amount, :letter from "Test";
printf("Database: pm\n"); printf("Database: pm\n");
for (i=0, j=sqlca.sqlerrd[2]; i<j; i++) for (i=0, j=sqlca.sqlerrd[2]; i<j; i++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment