Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
196d0dd1
Commit
196d0dd1
authored
May 29, 2003
by
Michael Meskes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed variable parsing so struct[n].attr works.
parent
bbe99022
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
121 additions
and
159 deletions
+121
-159
src/interfaces/ecpg/ChangeLog
src/interfaces/ecpg/ChangeLog
+5
-0
src/interfaces/ecpg/preproc/descriptor.c
src/interfaces/ecpg/preproc/descriptor.c
+1
-1
src/interfaces/ecpg/preproc/extern.h
src/interfaces/ecpg/preproc/extern.h
+2
-2
src/interfaces/ecpg/preproc/pgc.l
src/interfaces/ecpg/preproc/pgc.l
+2
-2
src/interfaces/ecpg/preproc/preproc.y
src/interfaces/ecpg/preproc/preproc.y
+14
-45
src/interfaces/ecpg/preproc/type.c
src/interfaces/ecpg/preproc/type.c
+13
-71
src/interfaces/ecpg/preproc/type.h
src/interfaces/ecpg/preproc/type.h
+2
-4
src/interfaces/ecpg/preproc/variable.c
src/interfaces/ecpg/preproc/variable.c
+70
-22
src/interfaces/ecpg/test/num_test.pgc
src/interfaces/ecpg/test/num_test.pgc
+12
-12
No files found.
src/interfaces/ecpg/ChangeLog
View file @
196d0dd1
...
@@ -1453,6 +1453,11 @@ Tue May 27 16:33:36 CEST 2003
...
@@ -1453,6 +1453,11 @@ Tue May 27 16:33:36 CEST 2003
Thu May 29 13:58:25 CEST 2003
Thu May 29 13:58:25 CEST 2003
- ecpg should now be able to parse forward struct definition.
- ecpg should now be able to parse forward struct definition.
Thu May 29 15:45:57 CEST 2003
- Changed parsing of variables to be able to reference one attribute
of the n-th entry in an array of structs.
- Set ecpg version to 2.12.0.
- Set ecpg version to 2.12.0.
- Set ecpg library to 3.4.2.
- Set ecpg library to 3.4.2.
- Set pgtypes library to 1.0.0
- Set pgtypes library to 1.0.0
...
...
src/interfaces/ecpg/preproc/descriptor.c
View file @
196d0dd1
...
@@ -192,7 +192,7 @@ output_get_descr(char *desc_name, char *index)
...
@@ -192,7 +192,7 @@ output_get_descr(char *desc_name, char *index)
break
;
break
;
}
}
fprintf
(
yyout
,
"%s,"
,
get_dtype
(
results
->
value
));
fprintf
(
yyout
,
"%s,"
,
get_dtype
(
results
->
value
));
ECPGdump_a_type
(
yyout
,
v
->
name
,
v
->
type
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
NULL
,
make_str
(
"0"
),
NULL
,
NULL
);
ECPGdump_a_type
(
yyout
,
v
->
name
,
v
->
type
,
NULL
,
NULL
,
NULL
,
NULL
,
make_str
(
"0"
),
NULL
,
NULL
);
}
}
drop_assignments
();
drop_assignments
();
fputs
(
"ECPGd_EODT);
\n
"
,
yyout
);
fputs
(
"ECPGd_EODT);
\n
"
,
yyout
);
...
...
src/interfaces/ecpg/preproc/extern.h
View file @
196d0dd1
...
@@ -73,8 +73,8 @@ extern void add_descriptor(char *, char *);
...
@@ -73,8 +73,8 @@ extern void add_descriptor(char *, char *);
extern
void
drop_descriptor
(
char
*
,
char
*
);
extern
void
drop_descriptor
(
char
*
,
char
*
);
extern
struct
descriptor
*
lookup_descriptor
(
char
*
,
char
*
);
extern
struct
descriptor
*
lookup_descriptor
(
char
*
,
char
*
);
extern
struct
variable
*
descriptor_variable
(
const
char
*
name
,
int
input
);
extern
struct
variable
*
descriptor_variable
(
const
char
*
name
,
int
input
);
extern
void
add_variable
(
struct
arguments
**
,
struct
variable
*
,
char
*
i
,
struct
variable
*
,
char
*
);
extern
void
add_variable
(
struct
arguments
**
,
struct
variable
*
,
struct
variable
*
);
extern
void
append_variable
(
struct
arguments
**
,
struct
variable
*
,
char
*
,
struct
variable
*
,
char
*
);
extern
void
append_variable
(
struct
arguments
**
,
struct
variable
*
,
struct
variable
*
);
extern
void
dump_variables
(
struct
arguments
*
,
int
);
extern
void
dump_variables
(
struct
arguments
*
,
int
);
extern
struct
typedefs
*
get_typedef
(
char
*
);
extern
struct
typedefs
*
get_typedef
(
char
*
);
extern
void
adjust_array
(
enum
ECPGttype
,
char
**
,
char
**
,
char
*
,
char
*
,
int
);
extern
void
adjust_array
(
enum
ECPGttype
,
char
**
,
char
**
,
char
*
,
char
*
,
int
);
...
...
src/interfaces/ecpg/preproc/pgc.l
View file @
196d0dd1
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.11
2 2003/05/29 12:00:21
meskes Exp $
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.11
3 2003/05/29 13:59:26
meskes Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -540,7 +540,7 @@ cppline {space}*#(.*\\{space})+.*
...
@@ -540,7 +540,7 @@ cppline {space}*#(.*\\{space})+.*
yylval.str = mm_strdup(yytext);
yylval.str = mm_strdup(yytext);
return FCONST;
return FCONST;
}
}
<SQL>:{identifier}((
"->"|\.){identifier}
)* {
<SQL>:{identifier}((
("->"|\.){identifier})|(\[{array}\])
)* {
yylval.str = mm_strdup(yytext+1);
yylval.str = mm_strdup(yytext+1);
return(CVARIABLE);
return(CVARIABLE);
}
}
...
...
src/interfaces/ecpg/preproc/preproc.y
View file @
196d0dd1
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.22
4 2003/05/29 12:00:21
meskes Exp $ */
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.22
5 2003/05/29 13:59:26
meskes Exp $ */
/* Copyright comment */
/* Copyright comment */
%{
%{
...
@@ -668,10 +668,10 @@ stmt: AlterDatabaseSetStmt { output_statement($1, 0, connection); }
...
@@ -668,10 +668,10 @@ stmt: AlterDatabaseSetStmt { output_statement($1, 0, connection); }
{
{
/* merge variables given in prepare statement with those given here */
/* merge variables given in prepare statement with those given here */
for (p = ptr->argsinsert; p; p = p->next)
for (p = ptr->argsinsert; p; p = p->next)
append_variable(&argsinsert, p->variable, p->
var_array_element, p->indicator, p->ind_array_element
);
append_variable(&argsinsert, p->variable, p->
indicator
);
for (p = ptr->argsresult; p; p = p->next)
for (p = ptr->argsresult; p; p = p->next)
add_variable(&argsresult, p->variable, p->
var_array_element, p->indicator, p->ind_array_element
);
add_variable(&argsresult, p->variable, p->
indicator
);
output_statement(mm_strdup(ptr->command), 0, ptr->connection ? mm_strdup(ptr->connection) : NULL);
output_statement(mm_strdup(ptr->command), 0, ptr->connection ? mm_strdup(ptr->connection) : NULL);
}
}
...
@@ -4234,7 +4234,7 @@ ECPGCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR ident
...
@@ -4234,7 +4234,7 @@ ECPGCursorStmt: DECLARE name cursor_options CURSOR opt_hold FOR ident
sprintf(thisquery->name, "ECPGprepared_statement(\"%s\")", $7);
sprintf(thisquery->name, "ECPGprepared_statement(\"%s\")", $7);
this->argsinsert = NULL;
this->argsinsert = NULL;
add_variable(&(this->argsinsert), thisquery,
NULL, &no_indicator, NULL
);
add_variable(&(this->argsinsert), thisquery,
&no_indicator
);
cur = this;
cur = this;
...
@@ -5095,7 +5095,7 @@ ECPGExecute : EXECUTE IMMEDIATE execstring
...
@@ -5095,7 +5095,7 @@ ECPGExecute : EXECUTE IMMEDIATE execstring
thisquery->next = NULL;
thisquery->next = NULL;
thisquery->name = $3;
thisquery->name = $3;
add_variable(&argsinsert, thisquery,
NULL, &no_indicator, NULL
);
add_variable(&argsinsert, thisquery,
&no_indicator
);
$$ = make_str("?");
$$ = make_str("?");
}
}
...
@@ -5109,7 +5109,7 @@ ECPGExecute : EXECUTE IMMEDIATE execstring
...
@@ -5109,7 +5109,7 @@ ECPGExecute : EXECUTE IMMEDIATE execstring
thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement(\"\")") + strlen($2));
thisquery->name = (char *) mm_alloc(sizeof("ECPGprepared_statement(\"\")") + strlen($2));
sprintf(thisquery->name, "ECPGprepared_statement(\"%s\")", $2);
sprintf(thisquery->name, "ECPGprepared_statement(\"%s\")", $2);
add_variable(&argsinsert, thisquery,
NULL, &no_indicator, NULL
);
add_variable(&argsinsert, thisquery,
&no_indicator
);
}
}
opt_ecpg_using opt_ecpg_into
opt_ecpg_using opt_ecpg_into
{
{
...
@@ -5150,7 +5150,7 @@ ecpg_into: INTO into_list
...
@@ -5150,7 +5150,7 @@ ecpg_into: INTO into_list
}
}
| INTO opt_sql SQL_DESCRIPTOR quoted_ident_stringvar
| INTO opt_sql SQL_DESCRIPTOR quoted_ident_stringvar
{
{
add_variable(&argsresult, descriptor_variable($4,0),
NULL, &no_indicator, NULL
);
add_variable(&argsresult, descriptor_variable($4,0),
&no_indicator
);
$$ = EMPTY;
$$ = EMPTY;
}
}
;
;
...
@@ -5970,57 +5970,26 @@ c_args: /*EMPTY*/ { $$ = EMPTY; }
...
@@ -5970,57 +5970,26 @@ c_args: /*EMPTY*/ { $$ = EMPTY; }
| c_list { $$ = $1; }
| c_list { $$ = $1; }
;
;
coutputvariable: CVARIABLE '[' Iresult ']' indicator '[' Iresult ']'
coutputvariable: CVARIABLE indicator
{ add_variable(&argsresult, find_variable($1), $3, find_variable($5), $7); }
{ add_variable(&argsresult, find_variable($1), find_variable($2)); }
| CVARIABLE indicator '[' Iresult ']'
{ add_variable(&argsresult, find_variable($1), NULL, find_variable($2), $4); }
| CVARIABLE '[' Iresult ']' indicator
{ add_variable(&argsresult, find_variable($1), $3, find_variable($5), NULL); }
| CVARIABLE indicator
{ add_variable(&argsresult, find_variable($1), NULL, find_variable($2), NULL); }
| CVARIABLE '[' Iresult ']'
{ add_variable(&argsresult, find_variable($1), $3, &no_indicator, NULL); }
| CVARIABLE
| CVARIABLE
{ add_variable(&argsresult, find_variable($1),
NULL, &no_indicator, NULL
); }
{ add_variable(&argsresult, find_variable($1),
&no_indicator
); }
;
;
civarind: CVARIABLE '[' Iresult ']' indicator '[' Iresult ']'
civarind: CVARIABLE indicator
{
add_variable(&argsinsert, find_variable($1), $3, find_variable($5), $7);
$$ = create_questionmarks($1, true);
}
| CVARIABLE indicator '[' Iresult ']'
{
add_variable(&argsinsert, find_variable($1), NULL, find_variable($2), $4);
$$ = create_questionmarks($1, false);
}
| CVARIABLE '[' Iresult ']' indicator
{
if (find_variable($5)->type->type == ECPGt_array)
mmerror(PARSE_ERROR, ET_ERROR, "arrays of indicators are not allowed on input");
add_variable(&argsinsert, find_variable($1), $3, find_variable($5), NULL);
$$ = create_questionmarks($1, true);
}
| CVARIABLE indicator
{
{
if (find_variable($2)->type->type == ECPGt_array)
if (find_variable($2)->type->type == ECPGt_array)
mmerror(PARSE_ERROR, ET_ERROR, "arrays of indicators are not allowed on input");
mmerror(PARSE_ERROR, ET_ERROR, "arrays of indicators are not allowed on input");
add_variable(&argsinsert, find_variable($1),
NULL, find_variable($2), NULL
);
add_variable(&argsinsert, find_variable($1),
find_variable($2)
);
$$ = create_questionmarks($1, false);
$$ = create_questionmarks($1, false);
}
}
;
;
civar: CVARIABLE '[' Iresult ']'
civar: CVARIABLE
{
add_variable(&argsinsert, find_variable($1), mm_strdup($3), &no_indicator, NULL);
$$ = create_questionmarks($1, true);
}
| CVARIABLE
{
{
add_variable(&argsinsert, find_variable($1),
NULL, &no_indicator, NULL
);
add_variable(&argsinsert, find_variable($1),
&no_indicator
);
$$ = create_questionmarks($1, false);
$$ = create_questionmarks($1, false);
}
}
;
;
...
...
src/interfaces/ecpg/preproc/type.c
View file @
196d0dd1
...
@@ -214,8 +214,7 @@ static void ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, c
...
@@ -214,8 +214,7 @@ static void ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, c
void
void
ECPGdump_a_type
(
FILE
*
o
,
const
char
*
name
,
struct
ECPGtype
*
type
,
ECPGdump_a_type
(
FILE
*
o
,
const
char
*
name
,
struct
ECPGtype
*
type
,
const
char
*
var_array_element
,
const
char
*
ind_name
,
const
char
*
ind_name
,
struct
ECPGtype
*
ind_type
,
struct
ECPGtype
*
ind_type
,
const
char
*
ind_array_element
,
const
char
*
prefix
,
const
char
*
ind_prefix
,
const
char
*
prefix
,
const
char
*
ind_prefix
,
char
*
arr_str_siz
,
const
char
*
struct_sizeof
,
char
*
arr_str_siz
,
const
char
*
struct_sizeof
,
const
char
*
ind_struct_sizeof
)
const
char
*
ind_struct_sizeof
)
...
@@ -232,65 +231,20 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type,
...
@@ -232,65 +231,20 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type,
break
;
break
;
case
ECPGt_struct
:
case
ECPGt_struct
:
case
ECPGt_union
:
case
ECPGt_union
:
/* If var_array_element is not equal
* NULL, we have to use the
* <var_array_element>th entry and
* not the whole array */
if
(
var_array_element
==
NULL
)
ECPGdump_a_struct
(
o
,
name
,
ECPGdump_a_struct
(
o
,
name
,
ind_name
,
ind_name
,
type
->
size
,
type
->
size
,
type
->
u
.
element
,
type
->
u
.
element
,
(
ind_type
->
type
==
ECPGt_NO_INDICATOR
)
?
ind_type
:
ind_type
->
u
.
element
,
(
ind_type
->
type
==
ECPGt_NO_INDICATOR
)
?
ind_type
:
ind_type
->
u
.
element
,
NULL
,
prefix
,
ind_prefix
);
NULL
,
prefix
,
ind_prefix
);
else
{
char
*
array_element
=
(
char
*
)
mm_alloc
(
strlen
(
name
)
+
strlen
(
var_array_element
)
+
sizeof
(
"[]
\0
"
)),
*
ind_array_element
;
sprintf
(
array_element
,
"%s[%s]"
,
name
,
var_array_element
);
if
(
ind_type
->
type
!=
ECPGt_NO_INDICATOR
)
{
ind_array_element
=
(
char
*
)
mm_alloc
(
strlen
(
ind_name
)
+
strlen
(
ind_array_element
)
+
sizeof
(
"+
\0
"
));
sprintf
(
ind_array_element
,
"%s[%s]"
,
ind_name
,
ind_array_element
);
ECPGdump_a_struct
(
o
,
array_element
,
ind_array_element
,
make_str
(
"1"
),
type
->
u
.
element
,
ind_type
->
u
.
element
,
NULL
,
prefix
,
ind_prefix
);
free
(
ind_array_element
);
}
else
ECPGdump_a_struct
(
o
,
array_element
,
ind_name
,
make_str
(
"1"
),
type
->
u
.
element
,
ind_type
,
NULL
,
prefix
,
ind_prefix
);
free
(
array_element
);
}
break
;
break
;
default:
default:
if
(
!
IS_SIMPLE_TYPE
(
type
->
u
.
element
->
type
))
if
(
!
IS_SIMPLE_TYPE
(
type
->
u
.
element
->
type
))
yyerror
(
"Internal error: unknown datatype, please inform pgsql-bugs@postgresql.org"
);
yyerror
(
"Internal error: unknown datatype, please inform pgsql-bugs@postgresql.org"
);
/* If var_array_element is not equal
* NULL, we have to use the
* <var_array_element>th entry and not
* the whole array */
if
(
var_array_element
==
NULL
)
ECPGdump_a_simple
(
o
,
name
,
ECPGdump_a_simple
(
o
,
name
,
type
->
u
.
element
->
type
,
type
->
u
.
element
->
type
,
type
->
u
.
element
->
size
,
type
->
size
,
NULL
,
prefix
);
type
->
u
.
element
->
size
,
type
->
size
,
NULL
,
prefix
);
else
{
char
*
array_element
=
(
char
*
)
mm_alloc
(
strlen
(
name
)
+
strlen
(
var_array_element
)
+
sizeof
(
"+
\0
"
));
sprintf
(
array_element
,
"%s+%s"
,
name
,
var_array_element
);
ECPGdump_a_simple
(
o
,
array_element
,
type
->
u
.
element
->
type
,
type
->
u
.
element
->
size
,
make_str
(
"1"
),
NULL
,
prefix
);
free
(
array_element
);
}
if
(
ind_type
!=
NULL
)
if
(
ind_type
!=
NULL
)
{
{
...
@@ -298,20 +252,8 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type,
...
@@ -298,20 +252,8 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * type,
ECPGdump_a_simple
(
o
,
ind_name
,
ind_type
->
type
,
ind_type
->
size
,
make_str
(
"-1"
),
NULL
,
ind_prefix
);
ECPGdump_a_simple
(
o
,
ind_name
,
ind_type
->
type
,
ind_type
->
size
,
make_str
(
"-1"
),
NULL
,
ind_prefix
);
else
else
{
{
if
(
ind_array_element
==
NULL
)
ECPGdump_a_simple
(
o
,
ind_name
,
ind_type
->
u
.
element
->
type
,
ECPGdump_a_simple
(
o
,
ind_name
,
ind_type
->
u
.
element
->
type
,
ind_type
->
u
.
element
->
size
,
ind_type
->
size
,
NULL
,
prefix
);
ind_type
->
u
.
element
->
size
,
ind_type
->
size
,
NULL
,
prefix
);
else
{
char
*
array_element
=
(
char
*
)
mm_alloc
(
strlen
(
ind_name
)
+
strlen
(
ind_array_element
)
+
sizeof
(
"+
\0
"
));
sprintf
(
array_element
,
"%s+%s"
,
ind_name
,
ind_array_element
);
ECPGdump_a_simple
(
o
,
array_element
,
ind_type
->
u
.
element
->
type
,
ind_type
->
u
.
element
->
size
,
make_str
(
"1"
),
NULL
,
prefix
);
free
(
array_element
);
}
}
}
}
}
}
}
...
@@ -516,9 +458,9 @@ ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsiz,
...
@@ -516,9 +458,9 @@ ECPGdump_a_struct(FILE *o, const char *name, const char *ind_name, char *arrsiz,
for
(
p
=
type
->
u
.
members
;
p
;
p
=
p
->
next
)
for
(
p
=
type
->
u
.
members
;
p
;
p
=
p
->
next
)
{
{
ECPGdump_a_type
(
o
,
p
->
name
,
p
->
type
,
NULL
,
ECPGdump_a_type
(
o
,
p
->
name
,
p
->
type
,
(
ind_p
!=
NULL
)
?
ind_p
->
name
:
NULL
,
(
ind_p
!=
NULL
)
?
ind_p
->
name
:
NULL
,
(
ind_p
!=
NULL
)
?
ind_p
->
type
:
NULL
,
NULL
,
(
ind_p
!=
NULL
)
?
ind_p
->
type
:
NULL
,
prefix
,
ind_prefix
,
arrsiz
,
type
->
struct_sizeof
,
prefix
,
ind_prefix
,
arrsiz
,
type
->
struct_sizeof
,
(
ind_p
!=
NULL
)
?
ind_type
->
struct_sizeof
:
NULL
);
(
ind_p
!=
NULL
)
?
ind_type
->
struct_sizeof
:
NULL
);
if
(
ind_p
!=
NULL
&&
ind_p
!=
&
struct_no_indicator
)
if
(
ind_p
!=
NULL
&&
ind_p
!=
&
struct_no_indicator
)
...
...
src/interfaces/ecpg/preproc/type.h
View file @
196d0dd1
...
@@ -49,8 +49,8 @@ void ECPGfree_type(struct ECPGtype *);
...
@@ -49,8 +49,8 @@ void ECPGfree_type(struct ECPGtype *);
size is the maxsize in case it is a varchar. Otherwise it is the size of
size is the maxsize in case it is a varchar. Otherwise it is the size of
the variable (required to do array fetches of structs).
the variable (required to do array fetches of structs).
*/
*/
void
ECPGdump_a_type
(
FILE
*
,
const
char
*
,
struct
ECPGtype
*
,
const
char
*
,
void
ECPGdump_a_type
(
FILE
*
,
const
char
*
,
struct
ECPGtype
*
,
const
char
*
,
struct
ECPGtype
*
,
const
char
*
,
const
char
*
,
const
char
*
,
struct
ECPGtype
*
,
const
char
*
,
const
char
*
,
char
*
,
const
char
*
,
const
char
*
);
const
char
*
,
char
*
,
const
char
*
,
const
char
*
);
/* A simple struct to keep a variable and its type. */
/* A simple struct to keep a variable and its type. */
...
@@ -147,9 +147,7 @@ struct variable
...
@@ -147,9 +147,7 @@ struct variable
struct
arguments
struct
arguments
{
{
struct
variable
*
variable
;
struct
variable
*
variable
;
char
*
var_array_element
;
struct
variable
*
indicator
;
struct
variable
*
indicator
;
char
*
ind_array_element
;
struct
arguments
*
next
;
struct
arguments
*
next
;
};
};
...
...
src/interfaces/ecpg/preproc/variable.c
View file @
196d0dd1
...
@@ -22,8 +22,8 @@ new_variable(const char *name, struct ECPGtype * type, int brace_level)
...
@@ -22,8 +22,8 @@ new_variable(const char *name, struct ECPGtype * type, int brace_level)
static
struct
variable
*
static
struct
variable
*
find_struct_member
(
char
*
name
,
char
*
str
,
struct
ECPGstruct_member
*
members
,
int
brace_level
)
find_struct_member
(
char
*
name
,
char
*
str
,
struct
ECPGstruct_member
*
members
,
int
brace_level
)
{
{
char
*
next
=
str
chr
(
++
str
,
'.'
),
char
*
next
=
str
pbrk
(
++
str
,
".-["
),
c
=
'\0'
;
*
end
,
c
=
'\0'
;
if
(
next
!=
NULL
)
if
(
next
!=
NULL
)
{
{
...
@@ -35,7 +35,7 @@ find_struct_member(char *name, char *str, struct ECPGstruct_member * members, in
...
@@ -35,7 +35,7 @@ find_struct_member(char *name, char *str, struct ECPGstruct_member * members, in
{
{
if
(
strcmp
(
members
->
name
,
str
)
==
0
)
if
(
strcmp
(
members
->
name
,
str
)
==
0
)
{
{
if
(
c
==
'\0'
)
if
(
next
==
NULL
)
{
{
/* found the end */
/* found the end */
switch
(
members
->
type
->
type
)
switch
(
members
->
type
->
type
)
...
@@ -52,13 +52,57 @@ find_struct_member(char *name, char *str, struct ECPGstruct_member * members, in
...
@@ -52,13 +52,57 @@ find_struct_member(char *name, char *str, struct ECPGstruct_member * members, in
else
else
{
{
*
next
=
c
;
*
next
=
c
;
if
(
c
==
'-'
)
if
(
c
==
'['
)
{
int
count
;
/* We don't care about what's inside the array braces
* so just eat up the character */
for
(
count
=
1
,
end
=
next
+
1
;
count
;
end
++
)
{
switch
(
*
end
)
{
case
'['
:
count
++
;
break
;
case
']'
:
count
--
;
break
;
default
:
break
;
}
}
}
else
end
=
next
;
switch
(
*
end
)
{
case
'\0'
:
/* found the end, but this time it has to be an array element */
if
(
members
->
type
->
type
!=
ECPGt_array
)
{
{
next
++
;
snprintf
(
errortext
,
sizeof
(
errortext
),
"incorrectly formed variable %s"
,
name
)
;
return
(
find_struct_member
(
name
,
next
,
members
->
type
->
u
.
element
->
u
.
members
,
brace_level
)
);
mmerror
(
PARSE_ERROR
,
ET_FATAL
,
errortext
);
}
}
switch
(
members
->
type
->
u
.
element
->
type
)
{
case
ECPGt_array
:
return
(
new_variable
(
name
,
ECPGmake_array_type
(
members
->
type
->
u
.
element
->
u
.
element
,
members
->
type
->
u
.
element
->
size
),
brace_level
));
case
ECPGt_struct
:
case
ECPGt_union
:
return
(
new_variable
(
name
,
ECPGmake_struct_type
(
members
->
type
->
u
.
element
->
u
.
members
,
members
->
type
->
u
.
element
->
type
,
members
->
type
->
u
.
element
->
struct_sizeof
),
brace_level
));
default:
return
(
new_variable
(
name
,
ECPGmake_simple_type
(
members
->
type
->
u
.
element
->
type
,
members
->
type
->
u
.
element
->
size
),
brace_level
));
}
break
;
case
'-'
:
return
(
find_struct_member
(
name
,
end
,
members
->
type
->
u
.
element
->
u
.
members
,
brace_level
));
break
;
case
'.'
:
if
(
members
->
type
->
type
!=
ECPGt_array
)
return
(
find_struct_member
(
name
,
end
,
members
->
type
->
u
.
element
->
u
.
members
,
brace_level
));
else
else
return
(
find_struct_member
(
name
,
next
,
members
->
type
->
u
.
members
,
brace_level
));
return
(
find_struct_member
(
name
,
next
,
members
->
type
->
u
.
members
,
brace_level
));
break
;
default
:
snprintf
(
errortext
,
sizeof
(
errortext
),
"incorrectly formed variable %s"
,
name
);
mmerror
(
PARSE_ERROR
,
ET_FATAL
,
errortext
);
break
;
}
}
}
}
}
}
}
...
@@ -155,8 +199,6 @@ find_variable(char *name)
...
@@ -155,8 +199,6 @@ find_variable(char *name)
struct
variable
*
p
;
struct
variable
*
p
;
int
count
;
int
count
;
printf
(
"MM: find %s
\n
"
,
name
);
next
=
strpbrk
(
name
,
".[-"
);
next
=
strpbrk
(
name
,
".[-"
);
if
(
next
)
if
(
next
)
{
{
...
@@ -183,6 +225,16 @@ find_variable(char *name)
...
@@ -183,6 +225,16 @@ find_variable(char *name)
*
next
=
'\0'
;
*
next
=
'\0'
;
p
=
find_simple
(
name
);
p
=
find_simple
(
name
);
*
next
=
c
;
*
next
=
c
;
switch
(
p
->
type
->
u
.
element
->
type
)
{
case
ECPGt_array
:
return
(
new_variable
(
name
,
ECPGmake_array_type
(
p
->
type
->
u
.
element
->
u
.
element
,
p
->
type
->
u
.
element
->
size
),
p
->
brace_level
));
case
ECPGt_struct
:
case
ECPGt_union
:
return
(
new_variable
(
name
,
ECPGmake_struct_type
(
p
->
type
->
u
.
element
->
u
.
members
,
p
->
type
->
u
.
element
->
type
,
p
->
type
->
u
.
element
->
struct_sizeof
),
p
->
brace_level
));
default:
return
(
new_variable
(
name
,
ECPGmake_simple_type
(
p
->
type
->
u
.
element
->
type
,
p
->
type
->
u
.
element
->
size
),
p
->
brace_level
));
}
}
}
}
}
else
p
=
find_struct
(
name
,
next
,
next
);
else
p
=
find_struct
(
name
,
next
,
next
);
...
@@ -243,21 +295,19 @@ reset_variables(void)
...
@@ -243,21 +295,19 @@ reset_variables(void)
/* Insert a new variable into our request list. */
/* Insert a new variable into our request list. */
void
void
add_variable
(
struct
arguments
**
list
,
struct
variable
*
var
,
char
*
var_array_element
,
struct
variable
*
ind
,
char
*
ind_array_element
)
add_variable
(
struct
arguments
**
list
,
struct
variable
*
var
,
struct
variable
*
ind
)
{
{
struct
arguments
*
p
=
(
struct
arguments
*
)
mm_alloc
(
sizeof
(
struct
arguments
));
struct
arguments
*
p
=
(
struct
arguments
*
)
mm_alloc
(
sizeof
(
struct
arguments
));
p
->
variable
=
var
;
p
->
variable
=
var
;
p
->
var_array_element
=
var_array_element
;
p
->
indicator
=
ind
;
p
->
indicator
=
ind
;
p
->
ind_array_element
=
ind_array_element
;
p
->
next
=
*
list
;
p
->
next
=
*
list
;
*
list
=
p
;
*
list
=
p
;
}
}
/* Append a new variable to our request list. */
/* Append a new variable to our request list. */
void
void
append_variable
(
struct
arguments
**
list
,
struct
variable
*
var
,
char
*
var_array_element
,
struct
variable
*
ind
,
char
*
ind_array_element
)
append_variable
(
struct
arguments
**
list
,
struct
variable
*
var
,
struct
variable
*
ind
)
{
{
struct
arguments
*
p
,
struct
arguments
*
p
,
*
new
=
(
struct
arguments
*
)
mm_alloc
(
sizeof
(
struct
arguments
));
*
new
=
(
struct
arguments
*
)
mm_alloc
(
sizeof
(
struct
arguments
));
...
@@ -265,9 +315,7 @@ append_variable(struct arguments ** list, struct variable * var, char * var_arra
...
@@ -265,9 +315,7 @@ append_variable(struct arguments ** list, struct variable * var, char * var_arra
for
(
p
=
*
list
;
p
&&
p
->
next
;
p
=
p
->
next
);
for
(
p
=
*
list
;
p
&&
p
->
next
;
p
=
p
->
next
);
new
->
variable
=
var
;
new
->
variable
=
var
;
new
->
var_array_element
=
var_array_element
;
new
->
indicator
=
ind
;
new
->
indicator
=
ind
;
new
->
ind_array_element
=
ind_array_element
;
new
->
next
=
NULL
;
new
->
next
=
NULL
;
if
(
p
)
if
(
p
)
...
@@ -294,8 +342,8 @@ dump_variables(struct arguments * list, int mode)
...
@@ -294,8 +342,8 @@ dump_variables(struct arguments * list, int mode)
dump_variables
(
list
->
next
,
mode
);
dump_variables
(
list
->
next
,
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
,
list
->
var_array_element
,
ECPGdump_a_type
(
yyout
,
list
->
variable
->
name
,
list
->
variable
->
type
,
list
->
indicator
->
name
,
list
->
indicator
->
type
,
list
->
ind_array_element
,
list
->
indicator
->
name
,
list
->
indicator
->
type
,
NULL
,
NULL
,
0
,
NULL
,
NULL
);
NULL
,
NULL
,
0
,
NULL
,
NULL
);
/* Then release the list element. */
/* Then release the list element. */
...
...
src/interfaces/ecpg/test/num_test.pgc
View file @
196d0dd1
...
@@ -21,37 +21,37 @@ main()
...
@@ -21,37 +21,37 @@ main()
exec sql create table test (text char(5), num decimal(14,7));
exec sql create table test (text char(5), num decimal(14,7));
value1 = PGTYPESnew();
value1 = PGTYPESnew();
PGTYPESnumeric_
iton
(1407, value1);
PGTYPESnumeric_
from_int
(1407, value1);
text = PGTYPESnumeric_
ntoa(value1
);
text = PGTYPESnumeric_
to_asc(value1, 0
);
printf("long = %s\n", text);
printf("long = %s\n", text);
value1 = PGTYPESnumeric_
aton
("2369.7", NULL);
value1 = PGTYPESnumeric_
from_asc
("2369.7", NULL);
value2 = PGTYPESnumeric_
aton
("10.0", NULL);
value2 = PGTYPESnumeric_
from_asc
("10.0", NULL);
res = PGTYPESnew();
res = PGTYPESnew();
dec
add(value1, value2, res);
PGTYPESnumeric_
add(value1, value2, res);
text = PGTYPESnumeric_
ntoa(res
);
text = PGTYPESnumeric_
to_asc(res, 0
);
printf("add = %s\n", text);
printf("add = %s\n", text);
PGTYPESnumeric_sub(res, value2, res);
PGTYPESnumeric_sub(res, value2, res);
text = PGTYPESnumeric_
ntoa(res
);
text = PGTYPESnumeric_
to_asc(res, 0
);
printf("sub = %s\n", text);
printf("sub = %s\n", text);
PGTYPESnumeric_copy(res, &des);
PGTYPESnumeric_copy(res, &des);
exec sql insert into test (text, num) values ('test', :des);
exec sql insert into test (text, num) values ('test', :des);
value2 = PGTYPESnumeric_
aton
("2369.7", NULL);
value2 = PGTYPESnumeric_
from_asc
("2369.7", NULL);
PGTYPESnumeric_mul(value1, value2, res);
PGTYPESnumeric_mul(value1, value2, res);
exec sql select num into :des from test where text = 'test';
exec sql select num into :des from test where text = 'test';
PGTYPESnumeric_mul(res, &des, res);
PGTYPESnumeric_mul(res, &des, res);
text = PGTYPESnumeric_
ntoa(res
);
text = PGTYPESnumeric_
to_asc(res, 0
);
printf("mul = %s\n", text);
printf("mul = %s\n", text);
value2 = PGTYPESnumeric_
aton
("10000", NULL);
value2 = PGTYPESnumeric_
from_asc
("10000", NULL);
PGTYPESnumeric_div(res, value2, res);
PGTYPESnumeric_div(res, value2, res);
text = PGTYPESnumeric_
ntoa(res
);
text = PGTYPESnumeric_
to_asc(res, 0
);
PGTYPESnumeric_
ntod
(res, &d);
PGTYPESnumeric_
to_double
(res, &d);
printf("div = %s %e\n", text, d);
printf("div = %s %e\n", text, d);
exec sql rollback;
exec sql rollback;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment