Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
89508a84
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
89508a84
编写于
3月 27, 2003
作者:
M
Michael Meskes
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More changes to pgtypeslib and set optimization to -O1.
上级
5e5c5cd3
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
263 addition
and
109 deletion
+263
-109
src/interfaces/ecpg/ChangeLog
src/interfaces/ecpg/ChangeLog
+7
-0
src/interfaces/ecpg/ecpglib/data.c
src/interfaces/ecpg/ecpglib/data.c
+31
-6
src/interfaces/ecpg/ecpglib/execute.c
src/interfaces/ecpg/ecpglib/execute.c
+45
-3
src/interfaces/ecpg/ecpglib/typename.c
src/interfaces/ecpg/ecpglib/typename.c
+3
-1
src/interfaces/ecpg/include/datetime.h
src/interfaces/ecpg/include/datetime.h
+2
-1
src/interfaces/ecpg/include/decimal.h
src/interfaces/ecpg/include/decimal.h
+7
-7
src/interfaces/ecpg/include/ecpgerrno.h
src/interfaces/ecpg/include/ecpgerrno.h
+10
-6
src/interfaces/ecpg/include/ecpgtype.h
src/interfaces/ecpg/include/ecpgtype.h
+2
-1
src/interfaces/ecpg/include/pgtypes_interval.h
src/interfaces/ecpg/include/pgtypes_interval.h
+20
-0
src/interfaces/ecpg/include/pgtypes_numeric.h
src/interfaces/ecpg/include/pgtypes_numeric.h
+25
-18
src/interfaces/ecpg/pgtypeslib/Makefile
src/interfaces/ecpg/pgtypeslib/Makefile
+2
-2
src/interfaces/ecpg/pgtypeslib/common.c
src/interfaces/ecpg/pgtypeslib/common.c
+0
-1
src/interfaces/ecpg/pgtypeslib/numeric.c
src/interfaces/ecpg/pgtypeslib/numeric.c
+48
-49
src/interfaces/ecpg/pgtypeslib/timestamp.c
src/interfaces/ecpg/pgtypeslib/timestamp.c
+25
-2
src/interfaces/ecpg/preproc/ecpg.c
src/interfaces/ecpg/preproc/ecpg.c
+3
-2
src/interfaces/ecpg/preproc/preproc.y
src/interfaces/ecpg/preproc/preproc.y
+19
-7
src/interfaces/ecpg/preproc/type.c
src/interfaces/ecpg/preproc/type.c
+12
-1
src/interfaces/ecpg/test/num_test.pgc
src/interfaces/ecpg/test/num_test.pgc
+2
-2
未找到文件。
src/interfaces/ecpg/ChangeLog
浏览文件 @
89508a84
...
...
@@ -1369,6 +1369,13 @@ Fri Mar 21 15:13:42 CET 2003
- Made sure preprocessor accepts new datatypes.
- Do not free prepared statements at the end of a transaction.
Thu Mar 27 15:23:58 CET 2003
- Some more updates to pgtypeslib.
- Set optimization to -O1 until I find the reason why code is broken
with -O2.
- Set ecpg version to 2.12.0.
- Set ecpg library to 3.4.2.
- Set pgtypes library to 1.0.0
...
...
src/interfaces/ecpg/ecpglib/data.c
浏览文件 @
89508a84
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.
2 2003/03/20 15:56:50
meskes Exp $ */
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/data.c,v 1.
3 2003/03/27 14:29:17
meskes Exp $ */
#include "postgres_fe.h"
...
...
@@ -13,6 +13,7 @@
#include "pgtypes_numeric.h"
#include "pgtypes_date.h"
#include "pgtypes_timestamp.h"
#include "pgtypes_interval.h"
bool
ECPGget_data
(
const
PGresult
*
results
,
int
act_tuple
,
int
act_field
,
int
lineno
,
...
...
@@ -100,9 +101,10 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
unsigned
long
ures
;
double
dres
;
char
*
scan_length
;
Numeric
Var
*
nres
;
Numeric
*
nres
;
Date
ddres
;
Timestamp
tres
;
Interval
*
ires
;
case
ECPGt_short
:
case
ECPGt_int
:
...
...
@@ -392,16 +394,39 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if
((
isarray
&&
*
scan_length
!=
','
&&
*
scan_length
!=
'}'
)
||
(
!
isarray
&&
*
scan_length
!=
'\0'
))
/* Garbage left */
{
ECPGraise
(
lineno
,
ECPG_
FLOAT
_FORMAT
,
pval
);
ECPGraise
(
lineno
,
ECPG_
NUMERIC
_FORMAT
,
pval
);
return
(
false
);
}
}
else
nres
=
PGTYPESnumeric_aton
(
"0.0"
,
&
scan_length
);
PGTYPESnumeric_copy
(
nres
,
(
Numeric
Var
*
)(
var
+
offset
*
act_tuple
));
PGTYPESnumeric_copy
(
nres
,
(
Numeric
*
)(
var
+
offset
*
act_tuple
));
break
;
case
ECPGt_interval
:
if
(
pval
)
{
if
(
isarray
&&
*
pval
==
'"'
)
ires
=
PGTYPESinterval_atoi
(
pval
+
1
,
&
scan_length
);
else
ires
=
PGTYPESinterval_atoi
(
pval
,
&
scan_length
);
if
(
isarray
&&
*
scan_length
==
'"'
)
scan_length
++
;
if
((
isarray
&&
*
scan_length
!=
','
&&
*
scan_length
!=
'}'
)
||
(
!
isarray
&&
*
scan_length
!=
'\0'
))
/* Garbage left */
{
ECPGraise
(
lineno
,
ECPG_INTERVAL_FORMAT
,
pval
);
return
(
false
);
}
}
else
ires
=
PGTYPESinterval_atoi
(
"0 seconds"
,
NULL
);
PGTYPESinterval_copy
(
ires
,
(
Interval
*
)(
var
+
offset
*
act_tuple
));
break
;
case
ECPGt_date
:
if
(
pval
)
{
...
...
@@ -416,7 +441,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if
((
isarray
&&
*
scan_length
!=
','
&&
*
scan_length
!=
'}'
)
||
(
!
isarray
&&
*
scan_length
!=
'\0'
))
/* Garbage left */
{
ECPGraise
(
lineno
,
ECPG_
FLOAT
_FORMAT
,
pval
);
ECPGraise
(
lineno
,
ECPG_
DATE
_FORMAT
,
pval
);
return
(
false
);
}
...
...
@@ -438,7 +463,7 @@ ECPGget_data(const PGresult *results, int act_tuple, int act_field, int lineno,
if
((
isarray
&&
*
scan_length
!=
','
&&
*
scan_length
!=
'}'
)
||
(
!
isarray
&&
*
scan_length
!=
'\0'
))
/* Garbage left */
{
ECPGraise
(
lineno
,
ECPG_
FLOAT
_FORMAT
,
pval
);
ECPGraise
(
lineno
,
ECPG_
TIMESTAMP
_FORMAT
,
pval
);
return
(
false
);
}
...
...
src/interfaces/ecpg/ecpglib/execute.c
浏览文件 @
89508a84
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.
5 2003/03/25 02:44:36 momjian
Exp $ */
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.
6 2003/03/27 14:29:17 meskes
Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
...
...
@@ -29,6 +29,7 @@
#include "pgtypes_numeric.h"
#include "pgtypes_date.h"
#include "pgtypes_timestamp.h"
#include "pgtypes_interval.h"
/* variables visible to the programs */
struct
sqlca
sqlca
=
...
...
@@ -846,7 +847,7 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
{
for
(
element
=
0
;
element
<
var
->
arrsize
;
element
++
)
{
str
=
PGTYPESnumeric_ntoa
((
Numeric
Var
*
)((
var
+
var
->
offset
*
element
)
->
value
));
str
=
PGTYPESnumeric_ntoa
((
Numeric
*
)((
var
+
var
->
offset
*
element
)
->
value
));
slen
=
strlen
(
str
);
if
(
!
(
mallocedval
=
ECPGrealloc
(
mallocedval
,
strlen
(
mallocedval
)
+
slen
+
5
,
stmt
->
lineno
)))
...
...
@@ -862,7 +863,48 @@ ECPGstore_input(const struct statement * stmt, const struct variable * var,
}
else
{
str
=
PGTYPESnumeric_ntoa
((
NumericVar
*
)(
var
->
value
));
str
=
PGTYPESnumeric_ntoa
((
Numeric
*
)(
var
->
value
));
slen
=
strlen
(
str
);
if
(
!
(
mallocedval
=
ECPGalloc
(
slen
+
1
,
stmt
->
lineno
)))
return
false
;
strncpy
(
mallocedval
,
str
,
slen
);
mallocedval
[
slen
]
=
'\0'
;
}
*
tobeinserted_p
=
mallocedval
;
*
malloced_p
=
true
;
free
(
str
);
}
break
;
case
ECPGt_interval
:
{
char
*
str
=
NULL
;
int
slen
;
if
(
var
->
arrsize
>
1
)
{
for
(
element
=
0
;
element
<
var
->
arrsize
;
element
++
)
{
str
=
PGTYPESinterval_itoa
((
Interval
*
)((
var
+
var
->
offset
*
element
)
->
value
));
slen
=
strlen
(
str
);
if
(
!
(
mallocedval
=
ECPGrealloc
(
mallocedval
,
strlen
(
mallocedval
)
+
slen
+
5
,
stmt
->
lineno
)))
return
false
;
if
(
!
element
)
strcpy
(
mallocedval
,
"'{"
);
strncpy
(
mallocedval
+
strlen
(
mallocedval
),
str
,
slen
+
1
);
strcpy
(
mallocedval
+
strlen
(
mallocedval
),
","
);
}
strcpy
(
mallocedval
+
strlen
(
mallocedval
)
-
1
,
"}'"
);
}
else
{
str
=
PGTYPESinterval_itoa
((
Interval
*
)(
var
->
value
));
slen
=
strlen
(
str
);
if
(
!
(
mallocedval
=
ECPGalloc
(
slen
+
1
,
stmt
->
lineno
)))
...
...
src/interfaces/ecpg/ecpglib/typename.c
浏览文件 @
89508a84
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.
2 2003/03/20 15:56:50
meskes Exp $ */
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/typename.c,v 1.
3 2003/03/27 14:29:17
meskes Exp $ */
#include "postgres_fe.h"
...
...
@@ -53,6 +53,8 @@ ECPGtype_name(enum ECPGttype typ)
return
"date"
;
case
ECPGt_timestamp
:
return
"timestamp"
;
case
ECPGt_interval
:
return
"interval"
;
default:
abort
();
}
...
...
src/interfaces/ecpg/include/datetime.h
浏览文件 @
89508a84
#include <pgtypes_timestamp.h>
#include <pgtypes_interval.h>
#ifndef dtime_t
#define dtime_t Timestamp
#endif
/* dtime_t */
#ifndef intrvl_t
#define intrvl_t
Timestamp
#define intrvl_t
Interval
#endif
/* intrvl_t */
extern
void
dtcurrent
(
dtime_t
*
);
...
...
src/interfaces/ecpg/include/decimal.h
浏览文件 @
89508a84
#include <pgtypes_numeric.h>
#ifndef dec_t
#define dec_t Numeric
Var
#define dec_t Numeric
#endif
/* dec_t */
int
decadd
(
dec_t
*
,
Numeric
Var
*
,
NumericVar
*
);
int
deccmp
(
dec_t
*
,
Numeric
Var
*
);
void
deccopy
(
dec_t
*
,
Numeric
Var
*
);
int
decadd
(
dec_t
*
,
Numeric
*
,
Numeric
*
);
int
deccmp
(
dec_t
*
,
Numeric
*
);
void
deccopy
(
dec_t
*
,
Numeric
*
);
int
deccvasc
(
char
*
,
int
,
dec_t
*
);
int
deccvdbl
(
double
,
dec_t
*
);
int
deccvint
(
int
,
dec_t
*
);
int
deccvlong
(
long
,
dec_t
*
);
int
decdiv
(
dec_t
*
,
Numeric
Var
*
,
NumericVar
*
);
int
decmul
(
dec_t
*
,
Numeric
Var
*
,
NumericVar
*
);
int
decsub
(
dec_t
*
,
Numeric
Var
*
,
NumericVar
*
);
int
decdiv
(
dec_t
*
,
Numeric
*
,
Numeric
*
);
int
decmul
(
dec_t
*
,
Numeric
*
,
Numeric
*
);
int
decsub
(
dec_t
*
,
Numeric
*
,
Numeric
*
);
int
dectoasc
(
dec_t
*
,
char
*
,
int
,
int
);
int
dectodbl
(
dec_t
*
,
double
*
);
int
dectoint
(
dec_t
*
,
int
*
);
...
...
src/interfaces/ecpg/include/ecpgerrno.h
浏览文件 @
89508a84
...
...
@@ -20,12 +20,16 @@
#define ECPG_INT_FORMAT -204
#define ECPG_UINT_FORMAT -205
#define ECPG_FLOAT_FORMAT -206
#define ECPG_CONVERT_BOOL -207
#define ECPG_EMPTY -208
#define ECPG_MISSING_INDICATOR -209
#define ECPG_NO_ARRAY -210
#define ECPG_DATA_NOT_ARRAY -211
#define ECPG_ARRAY_INSERT -212
#define ECPG_NUMERIC_FORMAT -207
#define ECPG_INTERVAL_FORMAT -208
#define ECPG_DATE_FORMAT -209
#define ECPG_TIMESTAMP_FORMAT -210
#define ECPG_CONVERT_BOOL -211
#define ECPG_EMPTY -212
#define ECPG_MISSING_INDICATOR -213
#define ECPG_NO_ARRAY -214
#define ECPG_DATA_NOT_ARRAY -215
#define ECPG_ARRAY_INSERT -216
#define ECPG_NO_CONN -220
#define ECPG_NOT_CONN -221
...
...
src/interfaces/ecpg/include/ecpgtype.h
浏览文件 @
89508a84
...
...
@@ -54,7 +54,8 @@ enum ECPGttype
ECPGt_descriptor
,
/* sql descriptor, no C variable */
ECPGt_numeric
,
ECPGt_date
,
ECPGt_timestamp
ECPGt_timestamp
,
ECPGt_interval
};
/* descriptor items */
...
...
src/interfaces/ecpg/include/pgtypes_interval.h
0 → 100644
浏览文件 @
89508a84
#ifndef PGTYPES_INTERVAL
#define PGTYPES_INTERVAL
#include <pgtypes_timestamp.h>
typedef
struct
{
#ifdef HAVE_INT64_TIMESTAMP
int64
time
;
/* all time units other than months and years */
#else
double
time
;
/* all time units other than months and years */
#endif
long
month
;
/* months and years, after time for alignment */
}
Interval
;
extern
Interval
*
PGTYPESinterval_atoi
(
char
*
,
char
**
);
extern
char
*
PGTYPESinterval_itoa
(
Interval
*
);
extern
int
PGTYPESinterval_copy
(
Interval
*
,
Interval
*
);
#endif
/* PGTYPES_INTERVAL */
src/interfaces/ecpg/include/pgtypes_numeric.h
浏览文件 @
89508a84
#ifndef PGTYPES_NUMERIC
#define PGTYPES_NUMERIC
#define NUMERIC_POS 0x0000
#define NUMERIC_NEG 0x4000
#define NUMERIC_MAX_PRECISION 1000
#define NUMERIC_MAX_DISPLAY_SCALE NUMERIC_MAX_PRECISION
#define NUMERIC_MIN_DISPLAY_SCALE 0
#define NUMERIC_MIN_SIG_DIGITS 16
typedef
unsigned
char
NumericDigit
;
typedef
struct
NumericVar
typedef
struct
{
int
ndigits
;
/* number of digits in digits[] - can be 0! */
int
weight
;
/* weight of first digit */
...
...
@@ -11,23 +18,23 @@ typedef struct NumericVar
int
sign
;
/* NUMERIC_POS, NUMERIC_NEG, or NUMERIC_NAN */
NumericDigit
*
buf
;
/* start of alloc'd space for digits[] */
NumericDigit
*
digits
;
/* decimal digits */
}
Numeric
Var
;
}
Numeric
;
Numeric
Var
*
PGTYPESnew
(
void
);
void
PGTYPESnumeric_free
(
Numeric
Var
*
);
Numeric
Var
*
PGTYPESnumeric_aton
(
char
*
,
char
**
);
char
*
PGTYPESnumeric_ntoa
(
Numeric
Var
*
);
int
PGTYPESnumeric_add
(
Numeric
Var
*
,
NumericVar
*
,
NumericVar
*
);
int
PGTYPESnumeric_sub
(
Numeric
Var
*
,
NumericVar
*
,
NumericVar
*
);
int
PGTYPESnumeric_mul
(
Numeric
Var
*
,
NumericVar
*
,
NumericVar
*
);
int
PGTYPESnumeric_div
(
Numeric
Var
*
,
NumericVar
*
,
NumericVar
*
);
int
PGTYPESnumeric_cmp
(
Numeric
Var
*
,
NumericVar
*
);
int
PGTYPESnumeric_iton
(
signed
int
,
Numeric
Var
*
);
int
PGTYPESnumeric_lton
(
signed
long
int
,
Numeric
Var
*
);
int
PGTYPESnumeric_copy
(
Numeric
Var
*
,
NumericVar
*
);
int
PGTYPESnumeric_dton
(
double
,
Numeric
Var
*
);
int
PGTYPESnumeric_ntod
(
Numeric
Var
*
,
double
*
);
int
PGTYPESnumeric_ntoi
(
Numeric
Var
*
,
int
*
);
int
PGTYPESnumeric_ntol
(
Numeric
Var
*
,
long
*
);
Numeric
*
PGTYPESnew
(
void
);
void
PGTYPESnumeric_free
(
Numeric
*
);
Numeric
*
PGTYPESnumeric_aton
(
char
*
,
char
**
);
char
*
PGTYPESnumeric_ntoa
(
Numeric
*
);
int
PGTYPESnumeric_add
(
Numeric
*
,
Numeric
*
,
Numeric
*
);
int
PGTYPESnumeric_sub
(
Numeric
*
,
Numeric
*
,
Numeric
*
);
int
PGTYPESnumeric_mul
(
Numeric
*
,
Numeric
*
,
Numeric
*
);
int
PGTYPESnumeric_div
(
Numeric
*
,
Numeric
*
,
Numeric
*
);
int
PGTYPESnumeric_cmp
(
Numeric
*
,
Numeric
*
);
int
PGTYPESnumeric_iton
(
signed
int
,
Numeric
*
);
int
PGTYPESnumeric_lton
(
signed
long
int
,
Numeric
*
);
int
PGTYPESnumeric_copy
(
Numeric
*
,
Numeric
*
);
int
PGTYPESnumeric_dton
(
double
,
Numeric
*
);
int
PGTYPESnumeric_ntod
(
Numeric
*
,
double
*
);
int
PGTYPESnumeric_ntoi
(
Numeric
*
,
int
*
);
int
PGTYPESnumeric_ntol
(
Numeric
*
,
long
*
);
#endif
/* PGTYPES_NUMERIC */
src/interfaces/ecpg/pgtypeslib/Makefile
浏览文件 @
89508a84
...
...
@@ -4,7 +4,7 @@
#
# Copyright (c) 1994, Regents of the University of California
#
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.
2 2003/03/20 15:56:50
meskes Exp $
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.
3 2003/03/27 14:29:17
meskes Exp $
#
#-------------------------------------------------------------------------
...
...
@@ -16,7 +16,7 @@ NAME= pgtypes
SO_MAJOR_VERSION
=
1
SO_MINOR_VERSION
=
0.0
override CPPFLAGS
:
= -g -I$(top_srcdir)/src/interfaces/ecpg/include -I$(top_srcdir)/src/include/utils $(CPPFLAGS)
override CPPFLAGS
:
= -
O1 -
g -I$(top_srcdir)/src/interfaces/ecpg/include -I$(top_srcdir)/src/include/utils $(CPPFLAGS)
OBJS
=
numeric.o datetime.o common.o dt_common.o timestamp.o
...
...
src/interfaces/ecpg/pgtypeslib/common.c
浏览文件 @
89508a84
#include <errno.h>
#include <stdlib.h>
#include "extern.h"
...
...
src/interfaces/ecpg/pgtypeslib/numeric.c
浏览文件 @
89508a84
...
...
@@ -8,14 +8,13 @@
#include "c.h"
#include "extern.h"
#include "numeric.h"
#include "pgtypes_error.h"
#include "decimal.h"
#define Max(x, y) ((x) > (y) ? (x) : (y))
#define Min(x, y) ((x) < (y) ? (x) : (y))
#define init_var(v) memset(v,0,sizeof(Numeric
Var
))
#define init_var(v) memset(v,0,sizeof(Numeric))
#define digitbuf_alloc(size) ((NumericDigit *) pgtypes_alloc(size))
#define digitbuf_free(buf) \
...
...
@@ -35,7 +34,7 @@
* ----------
*/
static int
apply_typmod(Numeric
Var
*var, long typmod)
apply_typmod(Numeric *var, long typmod)
{
int precision;
int scale;
...
...
@@ -115,7 +114,7 @@ apply_typmod(NumericVar *var, long typmod)
* ----------
*/
static
int
alloc_var
(
Numeric
Var
*
var
,
int
ndigits
)
alloc_var
(
Numeric
*
var
,
int
ndigits
)
{
digitbuf_free
(
var
->
buf
);
var
->
buf
=
digitbuf_alloc
(
ndigits
+
1
);
...
...
@@ -127,12 +126,12 @@ alloc_var(NumericVar *var, int ndigits)
return
0
;
}
Numeric
Var
*
Numeric
*
PGTYPESnew
(
void
)
{
Numeric
Var
*
var
;
Numeric
*
var
;
if
((
var
=
(
Numeric
Var
*
)
pgtypes_alloc
(
sizeof
(
NumericVar
)))
==
NULL
)
if
((
var
=
(
Numeric
*
)
pgtypes_alloc
(
sizeof
(
Numeric
)))
==
NULL
)
return
NULL
;
if
(
alloc_var
(
var
,
0
)
<
0
)
{
...
...
@@ -149,7 +148,7 @@ PGTYPESnew(void)
* ----------
*/
static
int
set_var_from_str
(
char
*
str
,
char
**
ptr
,
Numeric
Var
*
dest
)
set_var_from_str
(
char
*
str
,
char
**
ptr
,
Numeric
*
dest
)
{
bool
have_dp
=
FALSE
;
int
i
=
0
;
...
...
@@ -278,7 +277,7 @@ set_var_from_str(char *str, char **ptr, NumericVar *dest)
* ----------
*/
static
char
*
get_str_from_var
(
Numeric
Var
*
var
,
int
dscale
)
get_str_from_var
(
Numeric
*
var
,
int
dscale
)
{
char
*
str
;
char
*
cp
;
...
...
@@ -370,10 +369,10 @@ get_str_from_var(NumericVar *var, int dscale)
* Input function for numeric data type
* ----------
*/
Numeric
Var
*
Numeric
*
PGTYPESnumeric_aton
(
char
*
str
,
char
**
endptr
)
{
Numeric
Var
*
value
=
(
NumericVar
*
)
pgtypes_alloc
(
sizeof
(
NumericVar
));
Numeric
*
value
=
(
Numeric
*
)
pgtypes_alloc
(
sizeof
(
Numeric
));
int
ret
;
#if 0
long typmod = -1;
...
...
@@ -403,7 +402,7 @@ PGTYPESnumeric_aton(char *str, char **endptr)
* ----------
*/
char
*
PGTYPESnumeric_ntoa
(
Numeric
Var
*
num
)
PGTYPESnumeric_ntoa
(
Numeric
*
num
)
{
return
(
get_str_from_var
(
num
,
num
->
dscale
));
}
...
...
@@ -416,7 +415,7 @@ PGTYPESnumeric_ntoa(NumericVar *num)
* ----------
*/
static
void
zero_var
(
Numeric
Var
*
var
)
zero_var
(
Numeric
*
var
)
{
digitbuf_free
(
var
->
buf
);
var
->
buf
=
NULL
;
...
...
@@ -427,7 +426,7 @@ zero_var(NumericVar *var)
}
void
PGTYPESnumeric_free
(
Numeric
Var
*
var
)
PGTYPESnumeric_free
(
Numeric
*
var
)
{
digitbuf_free
(
var
->
buf
);
free
(
var
);
...
...
@@ -443,7 +442,7 @@ PGTYPESnumeric_free(NumericVar *var)
* ----------
*/
static
int
cmp_abs
(
Numeric
Var
*
var1
,
NumericVar
*
var2
)
cmp_abs
(
Numeric
*
var1
,
Numeric
*
var2
)
{
int
i1
=
0
;
int
i2
=
0
;
...
...
@@ -501,7 +500,7 @@ cmp_abs(NumericVar *var1, NumericVar *var2)
* ----------
*/
static
int
add_abs
(
Numeric
Var
*
var1
,
NumericVar
*
var2
,
NumericVar
*
result
)
add_abs
(
Numeric
*
var1
,
Numeric
*
var2
,
Numeric
*
result
)
{
NumericDigit
*
res_buf
;
NumericDigit
*
res_digits
;
...
...
@@ -589,7 +588,7 @@ add_abs(NumericVar *var1, NumericVar *var2, NumericVar *result)
* ----------
*/
static
int
sub_abs
(
Numeric
Var
*
var1
,
NumericVar
*
var2
,
NumericVar
*
result
)
sub_abs
(
Numeric
*
var1
,
Numeric
*
var2
,
Numeric
*
result
)
{
NumericDigit
*
res_buf
;
NumericDigit
*
res_digits
;
...
...
@@ -673,7 +672,7 @@ sub_abs(NumericVar *var1, NumericVar *var2, NumericVar *result)
* ----------
*/
int
PGTYPESnumeric_add
(
Numeric
Var
*
var1
,
NumericVar
*
var2
,
NumericVar
*
result
)
PGTYPESnumeric_add
(
Numeric
*
var1
,
Numeric
*
var2
,
Numeric
*
result
)
{
/*
* Decide on the signs of the two variables what to do
...
...
@@ -802,7 +801,7 @@ PGTYPESnumeric_add(NumericVar *var1, NumericVar *var2, NumericVar *result)
* ----------
*/
int
PGTYPESnumeric_sub
(
Numeric
Var
*
var1
,
NumericVar
*
var2
,
NumericVar
*
result
)
PGTYPESnumeric_sub
(
Numeric
*
var1
,
Numeric
*
var2
,
Numeric
*
result
)
{
/*
* Decide on the signs of the two variables what to do
...
...
@@ -933,7 +932,7 @@ PGTYPESnumeric_sub(NumericVar *var1, NumericVar *var2, NumericVar *result)
* ----------
*/
int
PGTYPESnumeric_mul
(
Numeric
Var
*
var1
,
NumericVar
*
var2
,
NumericVar
*
result
)
PGTYPESnumeric_mul
(
Numeric
*
var1
,
Numeric
*
var2
,
Numeric
*
result
)
{
NumericDigit
*
res_buf
;
NumericDigit
*
res_digits
;
...
...
@@ -1024,7 +1023,7 @@ PGTYPESnumeric_mul(NumericVar *var1, NumericVar *var2, NumericVar *result)
* Note that this must be called before div_var.
*/
static
int
select_div_scale
(
Numeric
Var
*
var1
,
NumericVar
*
var2
,
int
*
rscale
)
select_div_scale
(
Numeric
*
var1
,
Numeric
*
var2
,
int
*
rscale
)
{
int
weight1
,
weight2
,
...
...
@@ -1091,14 +1090,14 @@ select_div_scale(NumericVar *var1, NumericVar *var2, int *rscale)
}
int
PGTYPESnumeric_div
(
Numeric
Var
*
var1
,
NumericVar
*
var2
,
NumericVar
*
result
)
PGTYPESnumeric_div
(
Numeric
*
var1
,
Numeric
*
var2
,
Numeric
*
result
)
{
NumericDigit
*
res_digits
;
int
res_ndigits
;
int
res_sign
;
int
res_weight
;
Numeric
Var
dividend
;
Numeric
Var
divisor
[
10
];
Numeric
dividend
;
Numeric
divisor
[
10
];
int
ndigits_tmp
;
int
weight_tmp
;
int
rscale_tmp
;
...
...
@@ -1214,7 +1213,7 @@ PGTYPESnumeric_div(NumericVar *var1, NumericVar *var2, NumericVar *result)
int
i
;
long
sum
=
0
;
memcpy
(
&
divisor
[
guess
],
&
divisor
[
1
],
sizeof
(
Numeric
Var
));
memcpy
(
&
divisor
[
guess
],
&
divisor
[
1
],
sizeof
(
Numeric
));
divisor
[
guess
].
buf
=
digitbuf_alloc
(
divisor
[
guess
].
ndigits
);
divisor
[
guess
].
digits
=
divisor
[
guess
].
buf
;
for
(
i
=
divisor
[
1
].
ndigits
-
1
;
i
>=
0
;
i
--
)
...
...
@@ -1297,7 +1296,7 @@ PGTYPESnumeric_div(NumericVar *var1, NumericVar *var2, NumericVar *result)
int
PGTYPESnumeric_cmp
(
Numeric
Var
*
var1
,
NumericVar
*
var2
)
{
PGTYPESnumeric_cmp
(
Numeric
*
var1
,
Numeric
*
var2
)
{
/* use cmp_abs function to calculate the result */
...
...
@@ -1327,14 +1326,14 @@ PGTYPESnumeric_cmp(NumericVar *var1, NumericVar *var2) {
}
int
PGTYPESnumeric_iton
(
signed
int
int_val
,
Numeric
Var
*
var
)
{
PGTYPESnumeric_iton
(
signed
int
int_val
,
Numeric
*
var
)
{
/* implicit conversion */
signed
long
int
long_int
=
int_val
;
return
PGTYPESnumeric_lton
(
long_int
,
var
);
}
int
PGTYPESnumeric_lton
(
signed
long
int
long_val
,
Numeric
Var
*
var
)
{
PGTYPESnumeric_lton
(
signed
long
int
long_val
,
Numeric
*
var
)
{
/* calculate the size of the long int number */
/* a number n needs log_10 n digits */
/* however we multiply by 10 each time and compare instead of
...
...
@@ -1386,7 +1385,7 @@ PGTYPESnumeric_lton(signed long int long_val, NumericVar *var) {
}
int
PGTYPESnumeric_copy
(
Numeric
Var
*
src
,
NumericVar
*
dst
)
{
PGTYPESnumeric_copy
(
Numeric
*
src
,
Numeric
*
dst
)
{
int
i
;
zero_var
(
dst
);
...
...
@@ -1407,10 +1406,10 @@ PGTYPESnumeric_copy(NumericVar *src, NumericVar *dst) {
}
int
PGTYPESnumeric_dton
(
double
d
,
Numeric
Var
*
dst
)
PGTYPESnumeric_dton
(
double
d
,
Numeric
*
dst
)
{
char
buffer
[
100
];
Numeric
Var
*
tmp
;
Numeric
*
tmp
;
if
(
sprintf
(
buffer
,
"%f"
,
d
)
==
0
)
return
-
1
;
...
...
@@ -1424,7 +1423,7 @@ PGTYPESnumeric_dton(double d, NumericVar *dst)
}
static
int
numericvar_to_double_no_overflow
(
Numeric
Var
*
var
,
double
*
dp
)
numericvar_to_double_no_overflow
(
Numeric
*
var
,
double
*
dp
)
{
char
*
tmp
;
double
val
;
...
...
@@ -1448,7 +1447,7 @@ numericvar_to_double_no_overflow(NumericVar *var, double *dp)
}
int
PGTYPESnumeric_ntod
(
Numeric
Var
*
nv
,
double
*
dp
)
{
PGTYPESnumeric_ntod
(
Numeric
*
nv
,
double
*
dp
)
{
double
tmp
;
int
i
;
...
...
@@ -1459,7 +1458,7 @@ PGTYPESnumeric_ntod(NumericVar* nv, double* dp) {
}
int
PGTYPESnumeric_ntoi
(
Numeric
Var
*
nv
,
int
*
ip
)
{
PGTYPESnumeric_ntoi
(
Numeric
*
nv
,
int
*
ip
)
{
long
l
;
int
i
;
...
...
@@ -1476,7 +1475,7 @@ PGTYPESnumeric_ntoi(NumericVar* nv, int* ip) {
}
int
PGTYPESnumeric_ntol
(
Numeric
Var
*
nv
,
long
*
lp
)
{
PGTYPESnumeric_ntol
(
Numeric
*
nv
,
long
*
lp
)
{
int
i
;
long
l
=
0
;
...
...
@@ -1502,7 +1501,7 @@ PGTYPESnumeric_ntol(NumericVar* nv, long* lp) {
/* Finally we need some wrappers for the INFORMIX functions */
int
decadd
(
Numeric
Var
*
arg1
,
NumericVar
*
arg2
,
NumericVar
*
sum
)
decadd
(
Numeric
*
arg1
,
Numeric
*
arg2
,
Numeric
*
sum
)
{
int
i
=
PGTYPESnumeric_add
(
arg1
,
arg2
,
sum
);
...
...
@@ -1515,7 +1514,7 @@ decadd(NumericVar *arg1, NumericVar *arg2, NumericVar *sum)
}
int
deccmp
(
Numeric
Var
*
arg1
,
NumericVar
*
arg2
)
deccmp
(
Numeric
*
arg1
,
Numeric
*
arg2
)
{
int
i
=
PGTYPESnumeric_cmp
(
arg1
,
arg2
);
...
...
@@ -1524,7 +1523,7 @@ deccmp(NumericVar *arg1, NumericVar *arg2)
}
void
deccopy
(
Numeric
Var
*
src
,
NumericVar
*
target
)
deccopy
(
Numeric
*
src
,
Numeric
*
target
)
{
PGTYPESnumeric_copy
(
src
,
target
);
}
...
...
@@ -1547,7 +1546,7 @@ strndup(char *str, int len)
}
int
deccvasc
(
char
*
cp
,
int
len
,
Numeric
Var
*
np
)
deccvasc
(
char
*
cp
,
int
len
,
Numeric
*
np
)
{
char
*
str
=
strndup
(
cp
,
len
);
/* Numeric_in always converts the complete string */
int
ret
=
0
;
...
...
@@ -1575,25 +1574,25 @@ deccvasc(char *cp, int len, NumericVar *np)
}
int
deccvdbl
(
double
dbl
,
Numeric
Var
*
np
)
deccvdbl
(
double
dbl
,
Numeric
*
np
)
{
return
(
PGTYPESnumeric_dton
(
dbl
,
np
));
}
int
deccvint
(
int
in
,
Numeric
Var
*
np
)
deccvint
(
int
in
,
Numeric
*
np
)
{
return
(
PGTYPESnumeric_iton
(
in
,
np
));
}
int
deccvlong
(
long
lng
,
Numeric
Var
*
np
)
deccvlong
(
long
lng
,
Numeric
*
np
)
{
return
(
PGTYPESnumeric_lton
(
lng
,
np
));
}
int
decdiv
(
Numeric
Var
*
n1
,
NumericVar
*
n2
,
NumericVar
*
n3
)
decdiv
(
Numeric
*
n1
,
Numeric
*
n2
,
Numeric
*
n3
)
{
int
i
=
PGTYPESnumeric_div
(
n1
,
n2
,
n3
),
ret
=
0
;
...
...
@@ -1612,7 +1611,7 @@ decdiv(NumericVar *n1, NumericVar *n2, NumericVar *n3)
}
int
decmul
(
Numeric
Var
*
n1
,
NumericVar
*
n2
,
NumericVar
*
n3
)
decmul
(
Numeric
*
n1
,
Numeric
*
n2
,
Numeric
*
n3
)
{
int
i
=
PGTYPESnumeric_mul
(
n1
,
n2
,
n3
),
ret
=
0
;
...
...
@@ -1629,7 +1628,7 @@ decmul(NumericVar *n1, NumericVar *n2, NumericVar *n3)
}
int
decsub
(
Numeric
Var
*
n1
,
NumericVar
*
n2
,
NumericVar
*
n3
)
decsub
(
Numeric
*
n1
,
Numeric
*
n2
,
Numeric
*
n3
)
{
int
i
=
PGTYPESnumeric_sub
(
n1
,
n2
,
n3
),
ret
=
0
;
...
...
@@ -1646,7 +1645,7 @@ decsub(NumericVar *n1, NumericVar *n2, NumericVar *n3)
}
int
dectoasc
(
Numeric
Var
*
np
,
char
*
cp
,
int
len
,
int
right
)
dectoasc
(
Numeric
*
np
,
char
*
cp
,
int
len
,
int
right
)
{
char
*
str
;
...
...
@@ -1666,13 +1665,13 @@ dectoasc(NumericVar *np, char *cp, int len, int right)
}
int
dectodbl
(
Numeric
Var
*
np
,
double
*
dblp
)
dectodbl
(
Numeric
*
np
,
double
*
dblp
)
{
return
(
PGTYPESnumeric_ntod
(
np
,
dblp
));
}
int
dectoint
(
Numeric
Var
*
np
,
int
*
ip
)
dectoint
(
Numeric
*
np
,
int
*
ip
)
{
int
ret
=
PGTYPESnumeric_ntoi
(
np
,
ip
);
...
...
@@ -1683,7 +1682,7 @@ dectoint(NumericVar *np, int *ip)
}
int
dectolong
(
Numeric
Var
*
np
,
long
*
lngp
)
dectolong
(
Numeric
*
np
,
long
*
lngp
)
{
int
ret
=
PGTYPESnumeric_ntol
(
np
,
lngp
);
...
...
src/interfaces/ecpg/pgtypeslib/timestamp.c
浏览文件 @
89508a84
...
...
@@ -13,6 +13,7 @@
#include "extern.h"
#include "pgtypes_error.h"
#include "pgtypes_timestamp.h"
#include "pgtypes_interval.h"
#include "datetime.h"
#ifdef HAVE_INT64_TIMESTAMP
...
...
@@ -368,7 +369,7 @@ dtcvasc (char *str, Timestamp *ts)
}
int
dtsub
(
Timestamp
*
ts1
,
Timestamp
*
ts2
,
Timestamp
*
iv
)
dtsub
(
Timestamp
*
ts1
,
Timestamp
*
ts2
,
Interval
*
iv
)
{
return
0
;
}
...
...
@@ -386,8 +387,30 @@ dttofmtasc (Timestamp *ts, char *output, int str_len, char *fmtstr)
}
int
intoasc
(
Timestamp
*
i
,
char
*
str
)
intoasc
(
Interval
*
i
,
char
*
str
)
{
return
0
;
}
Interval
*
PGTYPESinterval_atoi
(
char
*
str
,
char
**
endptr
)
{
Interval
*
result
=
NULL
;
return
result
;
}
char
*
PGTYPESinterval_itoa
(
Interval
*
intvl
)
{
char
buf
[
MAXDATELEN
+
1
];
return
pgtypes_strdup
(
buf
);
}
int
PGTYPESinterval_copy
(
Interval
*
intvlsrc
,
Interval
*
intrcldest
)
{
return
0
;
}
src/interfaces/ecpg/preproc/ecpg.c
浏览文件 @
89508a84
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.6
3 2003/03/18 10:46:39
meskes Exp $ */
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.6
4 2003/03/27 14:29:17
meskes Exp $ */
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
...
...
@@ -157,7 +157,8 @@ main(int argc, char *const argv[])
if
(
strcmp
(
optarg
,
"INFORMIX"
)
==
0
)
{
compat
=
ECPG_COMPAT_INFORMIX
;
add_preprocessor_define
(
"dec_t=NumericVar"
);
add_preprocessor_define
(
"dec_t=Numeric"
);
add_preprocessor_define
(
"intrvl_t=Interval"
);
}
else
{
...
...
src/interfaces/ecpg/preproc/preproc.y
浏览文件 @
89508a84
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.21
4 2003/03/21 14:17:4
7 meskes Exp $ */
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/Attic/preproc.y,v 1.21
5 2003/03/27 14:29:1
7 meskes Exp $ */
/* Copyright comment */
%{
...
...
@@ -4258,8 +4258,8 @@ single_vt_type: common_type
}
else if (strcmp($1, "interval") == 0)
{
$$.type_enum = ECPGt_
timestamp
;
$$.type_str =
make_str("Timestamp")
;
$$.type_enum = ECPGt_
interval
;
$$.type_str =
EMPTY
;
$$.type_dimension = -1;
$$.type_index = -1;
$$.type_sizeof = NULL;
...
...
@@ -4526,8 +4526,8 @@ var_type: common_type
}
else if (strcmp($1, "interval") == 0)
{
$$.type_enum = ECPGt_
timestamp
;
$$.type_str =
make_str("Timestamp")
;
$$.type_enum = ECPGt_
interval
;
$$.type_str =
EMPTY
;
$$.type_dimension = -1;
$$.type_index = -1;
$$.type_sizeof = NULL;
...
...
@@ -4732,9 +4732,21 @@ variable: opt_pointer ECPGColLabelCommon opt_array_bounds opt_initializer
type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
if (dimension < 0)
$$ = cat_str(4, mm_strdup(actual_storage[struct_level]), make_str("NumericVar"), mm_strdup($2), $4);
$$ = cat_str(4, mm_strdup(actual_storage[struct_level]), make_str("Numeric"), mm_strdup($2), $4);
else
$$ = cat_str(5, mm_strdup(actual_storage[struct_level]), make_str("Numeric"), mm_strdup($2), mm_strdup(dim), $4);
break;
case ECPGt_interval:
if (dimension < 0)
type = ECPGmake_simple_type(actual_type[struct_level].type_enum, length);
else
type = ECPGmake_array_type(ECPGmake_simple_type(actual_type[struct_level].type_enum, length), dimension);
if (dimension < 0)
$$ = cat_str(4, mm_strdup(actual_storage[struct_level]), make_str("Interval"), mm_strdup($2), $4);
else
$$ = cat_str(5, mm_strdup(actual_storage[struct_level]), make_str("
NumericVar
"), mm_strdup($2), mm_strdup(dim), $4);
$$ = cat_str(5, mm_strdup(actual_storage[struct_level]), make_str("
Interval
"), mm_strdup($2), mm_strdup(dim), $4);
break;
default:
...
...
src/interfaces/ecpg/preproc/type.c
浏览文件 @
89508a84
...
...
@@ -172,6 +172,9 @@ get_type(enum ECPGttype type)
case
ECPGt_numeric
:
return
(
"ECPGt_numeric"
);
break
;
case
ECPGt_interval
:
return
(
"ECPGt_interval"
);
break
;
case
ECPGt_descriptor
:
return
(
"ECPGt_descriptor"
);
break
;
...
...
@@ -334,7 +337,15 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype type,
* we have to use a pointer here
*/
sprintf
(
variable
,
"&(%s%s)"
,
prefix
?
prefix
:
""
,
name
);
sprintf
(
offset
,
"sizeof(struct NumericVar)"
);
sprintf
(
offset
,
"sizeof(Numeric)"
);
break
;
case
ECPGt_interval
:
/*
* we have to use a pointer here
*/
sprintf
(
variable
,
"&(%s%s)"
,
prefix
?
prefix
:
""
,
name
);
sprintf
(
offset
,
"sizeof(Interval)"
);
break
;
case
ECPGt_date
:
...
...
src/interfaces/ecpg/test/num_test.pgc
浏览文件 @
89508a84
#include <stdio.h>
#include <pgtypes_numeric.h>
#include <decimal.h>
int
main()
{
char *text="error\n";
Numeric
Var
*value1, *value2, *res;
Numeric *value1, *value2, *res;
exec sql begin declare section;
decimal(14,7) des = {0, 0, 0, 0, 0, NULL, NULL} ;
numeric num;
exec sql end declare section;
double d;
FILE *dbgs;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录