Commit 87157899 authored by Michael Meskes's avatar Michael Meskes

Made sure SET DESCRIPTOR accepts all data types including constants.

parent a72dd7a9
...@@ -1825,6 +1825,15 @@ Sun Jun 27 13:50:58 CEST 2004 ...@@ -1825,6 +1825,15 @@ Sun Jun 27 13:50:58 CEST 2004
Mon Jun 28 11:08:42 CEST 2004 Mon Jun 28 11:08:42 CEST 2004
- Arrays can be read as arrays or as character strings now. - Arrays can be read as arrays or as character strings now.
Wed Jun 30 16:56:32 CEST 2004
- Added SET DESCRIPTOR command.
- Cleaned up error handling in preprocessor.
Sun Jul 4 16:53:53 CEST 2004
- Made sure SET DESCRIPTOR accepts all data types including constants.
- Set pgtypes library version to 1.2. - Set pgtypes library version to 1.2.
- Set ecpg version to 3.2.0. - Set ecpg version to 3.2.0.
- Set compat library version to 1.2. - Set compat library version to 1.2.
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.25 2004/06/28 11:47:41 meskes Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.26 2004/07/04 15:02:22 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL #define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -76,10 +76,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno, ...@@ -76,10 +76,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
* and 0 if not * and 0 if not
*/ */
if (PQgetisnull(results, act_tuple, act_field)) if (PQgetisnull(results, act_tuple, act_field))
{
printf("MM NULL\n");
value_for_indicator = -1; value_for_indicator = -1;
}
switch (ind_type) switch (ind_type)
{ {
......
/* dynamic SQL support routines /* dynamic SQL support routines
* *
* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.9 2004/07/01 18:32:58 meskes Exp $ * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.10 2004/07/04 15:02:22 meskes Exp $
*/ */
#define POSTGRES_ECPG_INTERNAL #define POSTGRES_ECPG_INTERNAL
...@@ -436,6 +436,7 @@ ECPGset_desc(int lineno, char *desc_name, int index,...) ...@@ -436,6 +436,7 @@ ECPGset_desc(int lineno, char *desc_name, int index,...)
va_list args; va_list args;
struct descriptor *desc; struct descriptor *desc;
struct descriptor_item *desc_item; struct descriptor_item *desc_item;
struct variable *var;
for (desc = all_descriptors; desc; desc = desc->next) for (desc = all_descriptors; desc; desc = desc->next)
{ {
...@@ -463,69 +464,59 @@ ECPGset_desc(int lineno, char *desc_name, int index,...) ...@@ -463,69 +464,59 @@ ECPGset_desc(int lineno, char *desc_name, int index,...)
desc->items = desc_item; desc->items = desc_item;
} }
if (!(var = (struct variable *) ECPGalloc(sizeof(struct variable), lineno)))
return false;
va_start(args, index); va_start(args, index);
do do
{ {
enum ECPGdtype itemtype; enum ECPGdtype itemtype;
long varcharsize; enum ECPGttype type;
long offset; const char *tobeinserted = NULL;
long arrsize; bool malloced;
enum ECPGttype vartype;
void *var;
itemtype = va_arg(args, enum ECPGdtype); itemtype = va_arg(args, enum ECPGdtype);
if (itemtype == ECPGd_EODT) if (itemtype == ECPGd_EODT)
break; break;
vartype = va_arg(args, enum ECPGttype); type = va_arg(args, enum ECPGttype);
var = va_arg(args, void *); ECPGget_variable(&args, type, var, false);
varcharsize = va_arg(args, long);
arrsize = va_arg(args, long);
offset = va_arg(args, long);
switch (itemtype) switch (itemtype)
{ {
case ECPGd_data: case ECPGd_data:
{ {
// FIXME: how to do this in general? if (!ECPGstore_input(lineno, true, var, &tobeinserted, &malloced))
switch (vartype)
{ {
case ECPGt_char: ECPGfree(var);
desc_item->data = strdup((char *)var); return false;
break;
case ECPGt_int:
{
char buf[20];
snprintf(buf, 20, "%d", *(int *)var);
desc_item->data = strdup(buf);
break;
}
default:
abort();
} }
desc_item->data = (char *) tobeinserted;
tobeinserted = NULL;
break; break;
} }
case ECPGd_indicator: case ECPGd_indicator:
set_int_item(lineno, &desc_item->indicator, var, vartype); set_int_item(lineno, &desc_item->indicator, var->pointer, var->type);
break; break;
case ECPGd_length: case ECPGd_length:
set_int_item(lineno, &desc_item->length, var, vartype); set_int_item(lineno, &desc_item->length, var->pointer, var->type);
break; break;
case ECPGd_precision: case ECPGd_precision:
set_int_item(lineno, &desc_item->precision, var, vartype); set_int_item(lineno, &desc_item->precision, var->pointer, var->type);
break; break;
case ECPGd_scale: case ECPGd_scale:
set_int_item(lineno, &desc_item->scale, var, vartype); set_int_item(lineno, &desc_item->scale, var->pointer, var->type);
break; break;
case ECPGd_type: case ECPGd_type:
set_int_item(lineno, &desc_item->type, var, vartype); set_int_item(lineno, &desc_item->type, var->pointer, var->type);
break; break;
default: default:
...@@ -533,6 +524,7 @@ ECPGset_desc(int lineno, char *desc_name, int index,...) ...@@ -533,6 +524,7 @@ ECPGset_desc(int lineno, char *desc_name, int index,...)
char type_str[20]; char type_str[20];
snprintf(type_str, sizeof(type_str), "%d", itemtype); snprintf(type_str, sizeof(type_str), "%d", itemtype);
ECPGraise(lineno, ECPG_UNKNOWN_DESCRIPTOR_ITEM, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, type_str); ECPGraise(lineno, ECPG_UNKNOWN_DESCRIPTOR_ITEM, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR, type_str);
ECPGfree(var);
return false; return false;
} }
} }
...@@ -544,6 +536,7 @@ ECPGset_desc(int lineno, char *desc_name, int index,...) ...@@ -544,6 +536,7 @@ ECPGset_desc(int lineno, char *desc_name, int index,...)
}*/ }*/
} }
while (true); while (true);
ECPGfree(var);
return true; return true;
} }
......
This diff is collapsed.
...@@ -124,6 +124,8 @@ PGresult **ECPGdescriptor_lvalue (int line, const char *descriptor); ...@@ -124,6 +124,8 @@ PGresult **ECPGdescriptor_lvalue (int line, const char *descriptor);
bool ECPGstore_result (const PGresult * results, int act_field, bool ECPGstore_result (const PGresult * results, int act_field,
const struct statement *stmt, struct variable *var); const struct statement *stmt, struct variable *var);
bool ECPGstore_input(const int, const bool, const struct variable *, const char **, bool *);
void ECPGget_variable(va_list *, enum ECPGttype, struct variable *, bool);
/* SQLSTATE values generated or processed by ecpglib (intentionally /* SQLSTATE values generated or processed by ecpglib (intentionally
* not exported -- users should refer to the codes directly) */ * not exported -- users should refer to the codes directly) */
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "libpq-fe.h" #include "libpq-fe.h"
#include "ecpgtype.h" #include "ecpgtype.h"
#include <string.h>
#ifndef __BEOS__ #ifndef __BEOS__
#ifndef __cplusplus #ifndef __cplusplus
......
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.290 2004/06/30 15:01:57 meskes Exp $ */ /* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.291 2004/07/04 15:02:23 meskes Exp $ */
/* Copyright comment */ /* Copyright comment */
%{ %{
...@@ -504,7 +504,7 @@ add_additional_variables(char *name, bool insert) ...@@ -504,7 +504,7 @@ add_additional_variables(char *name, bool insert)
%type <str> AlterUserSetStmt privilege_list privilege privilege_target %type <str> AlterUserSetStmt privilege_list privilege privilege_target
%type <str> opt_grant_grant_option opt_revoke_grant_option cursor_options %type <str> opt_grant_grant_option opt_revoke_grant_option cursor_options
%type <str> transaction_mode_list_or_empty transaction_mode_list %type <str> transaction_mode_list_or_empty transaction_mode_list
%type <str> function_with_argtypes_list function_with_argtypes %type <str> function_with_argtypes_list function_with_argtypes IntConstVar
%type <str> DropdbStmt ClusterStmt grantee RevokeStmt Bit DropOpClassStmt %type <str> DropdbStmt ClusterStmt grantee RevokeStmt Bit DropOpClassStmt
%type <str> GrantStmt privileges PosAllConst constraints_set_list %type <str> GrantStmt privileges PosAllConst constraints_set_list
%type <str> ConstraintsSetStmt AllConst CreateDomainStmt opt_nowait %type <str> ConstraintsSetStmt AllConst CreateDomainStmt opt_nowait
...@@ -4204,6 +4204,17 @@ IntConst: PosIntConst { $$ = $1; } ...@@ -4204,6 +4204,17 @@ IntConst: PosIntConst { $$ = $1; }
| '-' PosIntConst { $$ = cat2_str(make_str("-"), $2); } | '-' PosIntConst { $$ = cat2_str(make_str("-"), $2); }
; ;
IntConstVar: Iconst
{
char *length = mm_alloc(32);
sprintf(length, "%d", (int) strlen($1));
new_variable($1, ECPGmake_simple_type(ECPGt_const, length), 0);
$$ = $1;
}
| cvariable { $$ = $1; }
;
StringConst: Sconst { $$ = $1; } StringConst: Sconst { $$ = $1; }
| civar { $$ = $1; } | civar { $$ = $1; }
; ;
...@@ -5283,8 +5294,8 @@ opt_output: SQL_OUTPUT { $$ = make_str("output"); } ...@@ -5283,8 +5294,8 @@ opt_output: SQL_OUTPUT { $$ = make_str("output"); }
/* /*
* dynamic SQL: descriptor based access * dynamic SQL: descriptor based access
* written by Christof Petig <christof.petig@wtal.de> * originall written by Christof Petig <christof.petig@wtal.de>
* and Peter Eisentraut <peter.eisentraut@credativ.de> * and Peter Eisentraut <peter.eisentraut@credativ.de>
*/ */
/* /*
...@@ -5319,7 +5330,7 @@ ECPGGetDescHeaderItems: ECPGGetDescHeaderItem ...@@ -5319,7 +5330,7 @@ ECPGGetDescHeaderItems: ECPGGetDescHeaderItem
| ECPGGetDescHeaderItems ',' ECPGGetDescHeaderItem | ECPGGetDescHeaderItems ',' ECPGGetDescHeaderItem
; ;
ECPGGetDescHeaderItem: CVARIABLE '=' desc_header_item ECPGGetDescHeaderItem: cvariable '=' desc_header_item
{ push_assignment($1, $3); } { push_assignment($1, $3); }
; ;
...@@ -5331,8 +5342,10 @@ ECPGSetDescHeaderItems: ECPGSetDescHeaderItem ...@@ -5331,8 +5342,10 @@ ECPGSetDescHeaderItems: ECPGSetDescHeaderItem
| ECPGSetDescHeaderItems ',' ECPGSetDescHeaderItem | ECPGSetDescHeaderItems ',' ECPGSetDescHeaderItem
; ;
ECPGSetDescHeaderItem: desc_header_item '=' CVARIABLE ECPGSetDescHeaderItem: desc_header_item '=' IntConstVar
{ push_assignment($3, $1); } {
push_assignment($3, $1);
}
; ;
...@@ -5343,9 +5356,7 @@ desc_header_item: SQL_COUNT { $$ = ECPGd_count; } ...@@ -5343,9 +5356,7 @@ desc_header_item: SQL_COUNT { $$ = ECPGd_count; }
* manipulate a descriptor * manipulate a descriptor
*/ */
ECPGGetDescriptor: GET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE CVARIABLE ECPGGetDescItems ECPGGetDescriptor: GET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE IntConstVar ECPGGetDescItems
{ $$.str = $5; $$.name = $3; }
| GET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE Iconst ECPGGetDescItems
{ $$.str = $5; $$.name = $3; } { $$.str = $5; $$.name = $3; }
; ;
...@@ -5353,12 +5364,10 @@ ECPGGetDescItems: ECPGGetDescItem ...@@ -5353,12 +5364,10 @@ ECPGGetDescItems: ECPGGetDescItem
| ECPGGetDescItems ',' ECPGGetDescItem | ECPGGetDescItems ',' ECPGGetDescItem
; ;
ECPGGetDescItem: CVARIABLE '=' descriptor_item { push_assignment($1, $3); }; ECPGGetDescItem: cvariable '=' descriptor_item { push_assignment($1, $3); };
ECPGSetDescriptor: SET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE CVARIABLE ECPGSetDescItems ECPGSetDescriptor: SET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE IntConstVar ECPGSetDescItems
{ $$.str = $5; $$.name = $3; }
| SET SQL_DESCRIPTOR quoted_ident_stringvar SQL_VALUE Iconst ECPGSetDescItems
{ $$.str = $5; $$.name = $3; } { $$.str = $5; $$.name = $3; }
; ;
...@@ -5366,7 +5375,11 @@ ECPGSetDescItems: ECPGSetDescItem ...@@ -5366,7 +5375,11 @@ ECPGSetDescItems: ECPGSetDescItem
| ECPGSetDescItems ',' ECPGSetDescItem | ECPGSetDescItems ',' ECPGSetDescItem
; ;
ECPGSetDescItem: descriptor_item '=' CVARIABLE { push_assignment($3, $1); }; ECPGSetDescItem: descriptor_item '=' IntConstVar
{
push_assignment($3, $1);
}
;
descriptor_item: SQL_CARDINALITY { $$ = ECPGd_cardinality; } descriptor_item: SQL_CARDINALITY { $$ = ECPGd_cardinality; }
......
...@@ -419,7 +419,7 @@ dump_variables(struct arguments * list, int mode) ...@@ -419,7 +419,7 @@ dump_variables(struct arguments * list, int mode)
/* Then the current element and its indicator */ /* Then the current element and its indicator */
ECPGdump_a_type(yyout, list->variable->name, list->variable->type, ECPGdump_a_type(yyout, list->variable->name, list->variable->type,
list->indicator->name, list->indicator->type, list->indicator->name, list->indicator->type,
NULL, NULL, 0, NULL, NULL); NULL, NULL, make_str("0"), NULL, NULL);
/* Then release the list element. */ /* Then release the list element. */
if (mode != 0) if (mode != 0)
......
...@@ -31,8 +31,7 @@ main() ...@@ -31,8 +31,7 @@ main()
EXEC SQL EXECUTE foo1 USING DESCRIPTOR indesc; EXEC SQL EXECUTE foo1 USING DESCRIPTOR indesc;
//EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 2; EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = 2;
EXEC SQL SET DESCRIPTOR indesc VALUE 1 DATA = :val1output;
EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2null, DATA = :val2; EXEC SQL SET DESCRIPTOR indesc VALUE 2 INDICATOR = :val2null, DATA = :val2;
EXEC SQL EXECUTE foo1 USING DESCRIPTOR indesc; EXEC SQL EXECUTE foo1 USING DESCRIPTOR indesc;
......
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