Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
15364b8e
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
15364b8e
编写于
10月 22, 2020
作者:
F
freemine
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor
上级
fb17a79e
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
472 addition
and
1049 deletion
+472
-1049
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+1
-2
src/connector/odbc/src/todbc.c
src/connector/odbc/src/todbc.c
+182
-922
src/connector/odbc/src/todbc_conv.c
src/connector/odbc/src/todbc_conv.c
+241
-88
src/connector/odbc/src/todbc_conv.h
src/connector/odbc/src/todbc_conv.h
+46
-33
src/connector/odbc/src/todbc_util.h
src/connector/odbc/src/todbc_util.h
+0
-2
src/connector/odbc/tests/odbc.py
src/connector/odbc/tests/odbc.py
+2
-2
未找到文件。
src/client/src/tscPrepare.c
浏览文件 @
15364b8e
...
...
@@ -268,7 +268,6 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) {
if
(
1
)
{
// allow user bind param data with different type
short
size
=
0
;
union
{
int8_t
v1
;
int16_t
v2
;
...
...
@@ -600,7 +599,7 @@ static int doBindParam(char* data, SParamInfo* param, TAOS_BIND* bind) {
if
((
*
bind
->
length
)
>
(
uintptr_t
)
param
->
bytes
)
{
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
size
=
(
short
)
*
bind
->
length
;
s
hort
s
ize
=
(
short
)
*
bind
->
length
;
STR_WITH_SIZE_TO_VARSTR
(
data
+
param
->
offset
,
bind
->
buffer
,
size
);
return
TSDB_CODE_SUCCESS
;
}
break
;
...
...
src/connector/odbc/src/todbc.c
浏览文件 @
15364b8e
此差异已折叠。
点击以展开。
src/connector/odbc/src/todbc_conv.c
浏览文件 @
15364b8e
...
...
@@ -17,43 +17,102 @@
#include "todbc_util.h"
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
typedef
struct
buf_s
buf_t
;
struct
buf_s
{
char
buf
[
1024
*
16
+
1
];
char
*
ptr
;
};
static
char
*
buf_init
(
buf_t
*
buf
,
size_t
len
);
static
void
buf_clean
(
buf_t
*
buf
);
static
char
*
buf_init
(
buf_t
*
buf
,
size_t
len
)
{
if
(
len
>
sizeof
(
buf
->
buf
))
{
buf
->
ptr
=
(
char
*
)
malloc
(
len
);
}
else
if
(
len
>
0
)
{
buf
->
ptr
=
&
buf
->
buf
[
0
];
}
else
{
buf
->
ptr
=
NULL
;
}
return
buf
->
ptr
;
}
static
void
buf_clean
(
buf_t
*
buf
)
{
if
(
buf
->
ptr
&&
buf
->
ptr
!=
buf
->
buf
)
{
free
(
buf
->
ptr
);
buf
->
ptr
=
NULL
;
}
}
TSDB_CONV_CODE
tsdb_iconv_conv
(
iconv_t
cnv
,
const
unsigned
char
*
src
,
size_t
*
slen
,
unsigned
char
*
dst
,
size_t
*
dlen
)
{
if
(
cnv
==
(
iconv_t
)
-
1
)
return
TSDB_CONV_GENERAL
;
char
*
s
=
(
char
*
)
src
;
char
*
d
=
(
char
*
)
dst
;
size_t
sl
=
*
slen
;
size_t
dl
=
*
dlen
;
int
n
=
iconv
(
cnv
,
&
s
,
&
sl
,
&
d
,
&
dl
);
int
e
=
errno
;
if
(
dl
)
*
d
=
'\0'
;
// what if all consumed?
*
slen
=
sl
;
*
dlen
=
dl
;
if
(
e
==
0
)
{
if
(
n
)
return
TSDB_CONV_BAD_CHAR
;
return
TSDB_CONV_OK
;
}
iconv
(
cnv
,
NULL
,
NULL
,
NULL
,
NULL
);
switch
(
e
)
{
case
E2BIG
:
return
TSDB_CONV_TRUNC
;
case
EILSEQ
:
return
TSDB_CONV_BAD_CHAR
;
case
EINVAL
:
return
TSDB_CONV_BAD_CHAR
;
default:
return
TSDB_CONV_GENERAL
;
}
}
// src: int
TSDB_CONV_CODE
tsdb_int64_to_bit
(
int
todb
,
int
64_t
src
,
int8_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_int64_to_bit
(
int64_t
src
,
int8_t
*
dst
)
{
*
dst
=
(
int8_t
)
src
;
if
(
src
==
0
||
src
==
1
)
return
TSDB_CONV_OK
;
return
TSDB_CONV_OOR
;
}
TSDB_CONV_CODE
tsdb_int64_to_tinyint
(
int
todb
,
int
64_t
src
,
int8_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_int64_to_tinyint
(
int64_t
src
,
int8_t
*
dst
)
{
*
dst
=
(
int8_t
)
src
;
if
(
src
==
*
dst
)
return
TSDB_CONV_OK
;
return
TSDB_CONV_OOR
;
}
TSDB_CONV_CODE
tsdb_int64_to_smallint
(
int
todb
,
int
64_t
src
,
int16_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_int64_to_smallint
(
int64_t
src
,
int16_t
*
dst
)
{
*
dst
=
(
int16_t
)
src
;
if
(
src
==
*
dst
)
return
TSDB_CONV_OK
;
return
TSDB_CONV_OOR
;
}
TSDB_CONV_CODE
tsdb_int64_to_int
(
int
todb
,
int
64_t
src
,
int32_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_int64_to_int
(
int64_t
src
,
int32_t
*
dst
)
{
*
dst
=
(
int32_t
)
src
;
if
(
src
==
*
dst
)
return
TSDB_CONV_OK
;
return
TSDB_CONV_OOR
;
}
TSDB_CONV_CODE
tsdb_int64_to_bigint
(
int
todb
,
int
64_t
src
,
int64_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_int64_to_bigint
(
int64_t
src
,
int64_t
*
dst
)
{
*
dst
=
src
;
return
TSDB_CONV_OK
;
}
TSDB_CONV_CODE
tsdb_int64_to_ts
(
int
todb
,
int
64_t
src
,
int64_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_int64_to_ts
(
int64_t
src
,
int64_t
*
dst
)
{
*
dst
=
src
;
time_t
t
=
(
time_t
)(
src
/
1000
);
...
...
@@ -63,7 +122,7 @@ TSDB_CONV_CODE tsdb_int64_to_ts(int todb, int64_t src, int64_t *dst) {
return
TSDB_CONV_OOR
;
}
TSDB_CONV_CODE
tsdb_int64_to_float
(
int
todb
,
int
64_t
src
,
float
*
dst
)
{
TSDB_CONV_CODE
tsdb_int64_to_float
(
int64_t
src
,
float
*
dst
)
{
*
dst
=
(
float
)
src
;
int64_t
v
=
(
int64_t
)
*
dst
;
...
...
@@ -72,7 +131,7 @@ TSDB_CONV_CODE tsdb_int64_to_float(int todb, int64_t src, float *dst) {
return
TSDB_CONV_OOR
;
}
TSDB_CONV_CODE
tsdb_int64_to_double
(
int
todb
,
int
64_t
src
,
double
*
dst
)
{
TSDB_CONV_CODE
tsdb_int64_to_double
(
int64_t
src
,
double
*
dst
)
{
*
dst
=
(
double
)
src
;
int64_t
v
=
(
int64_t
)
*
dst
;
...
...
@@ -81,7 +140,7 @@ TSDB_CONV_CODE tsdb_int64_to_double(int todb, int64_t src, double *dst) {
return
TSDB_CONV_OOR
;
}
TSDB_CONV_CODE
tsdb_int64_to_char
(
int
todb
,
int
64_t
src
,
char
*
dst
,
size_t
dlen
)
{
TSDB_CONV_CODE
tsdb_int64_to_char
(
int64_t
src
,
char
*
dst
,
size_t
dlen
)
{
int
n
=
snprintf
(
dst
,
dlen
,
"%"
PRId64
""
,
src
);
if
(
n
<
dlen
)
return
TSDB_CONV_OK
;
...
...
@@ -90,7 +149,7 @@ TSDB_CONV_CODE tsdb_int64_to_char(int todb, int64_t src, char *dst, size_t dlen)
}
// src: double
TSDB_CONV_CODE
tsdb_double_to_bit
(
int
todb
,
double
src
,
int8_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_double_to_bit
(
double
src
,
int8_t
*
dst
)
{
*
dst
=
(
int8_t
)
src
;
if
(
src
<
0
||
src
>=
2
)
return
TSDB_CONV_OOR
;
...
...
@@ -102,7 +161,7 @@ TSDB_CONV_CODE tsdb_double_to_bit(int todb, double src, int8_t *dst) {
return
TSDB_CONV_TRUNC
;
}
TSDB_CONV_CODE
tsdb_double_to_tinyint
(
int
todb
,
double
src
,
int8_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_double_to_tinyint
(
double
src
,
int8_t
*
dst
)
{
*
dst
=
(
int8_t
)
src
;
if
(
src
<
SCHAR_MIN
||
src
>
SCHAR_MAX
)
return
TSDB_CONV_OOR
;
...
...
@@ -114,7 +173,7 @@ TSDB_CONV_CODE tsdb_double_to_tinyint(int todb, double src, int8_t *dst) {
return
TSDB_CONV_TRUNC
;
}
TSDB_CONV_CODE
tsdb_double_to_smallint
(
int
todb
,
double
src
,
int16_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_double_to_smallint
(
double
src
,
int16_t
*
dst
)
{
*
dst
=
(
int16_t
)
src
;
if
(
src
<
SHRT_MIN
||
src
>
SHRT_MAX
)
return
TSDB_CONV_OOR
;
...
...
@@ -126,7 +185,7 @@ TSDB_CONV_CODE tsdb_double_to_smallint(int todb, double src, int16_t *dst) {
return
TSDB_CONV_TRUNC
;
}
TSDB_CONV_CODE
tsdb_double_to_int
(
int
todb
,
double
src
,
int32_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_double_to_int
(
double
src
,
int32_t
*
dst
)
{
*
dst
=
(
int32_t
)
src
;
if
(
src
<
LONG_MIN
||
src
>
LONG_MAX
)
return
TSDB_CONV_OOR
;
...
...
@@ -138,7 +197,7 @@ TSDB_CONV_CODE tsdb_double_to_int(int todb, double src, int32_t *dst) {
return
TSDB_CONV_TRUNC
;
}
TSDB_CONV_CODE
tsdb_double_to_bigint
(
int
todb
,
double
src
,
int64_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_double_to_bigint
(
double
src
,
int64_t
*
dst
)
{
*
dst
=
(
int64_t
)
src
;
if
(
src
<
LLONG_MIN
||
src
>
LLONG_MAX
)
return
TSDB_CONV_OOR
;
...
...
@@ -150,8 +209,8 @@ TSDB_CONV_CODE tsdb_double_to_bigint(int todb, double src, int64_t *dst) {
return
TSDB_CONV_TRUNC
;
}
TSDB_CONV_CODE
tsdb_double_to_ts
(
int
todb
,
double
src
,
int64_t
*
dst
)
{
TSDB_CONV_CODE
code
=
tsdb_double_to_bigint
(
todb
,
src
,
dst
);
TSDB_CONV_CODE
tsdb_double_to_ts
(
double
src
,
int64_t
*
dst
)
{
TSDB_CONV_CODE
code
=
tsdb_double_to_bigint
(
src
,
dst
);
if
(
code
==
TSDB_CONV_OK
||
code
==
TSDB_CONV_TRUNC_FRACTION
)
{
int64_t
v
=
(
int64_t
)
src
;
...
...
@@ -165,8 +224,29 @@ TSDB_CONV_CODE tsdb_double_to_ts(int todb, double src, int64_t *dst) {
return
code
;
}
TSDB_CONV_CODE
tsdb_double_to_char
(
double
src
,
char
*
dst
,
size_t
dlen
)
{
int
n
=
snprintf
(
dst
,
dlen
,
"%lg"
,
src
);
if
(
n
<
dlen
)
return
TSDB_CONV_OK
;
return
TSDB_CONV_TRUNC
;
}
// src: SQL_TIMESTAMP_STRUCT
TSDB_CONV_CODE
tsdb_timestamp_to_char
(
SQL_TIMESTAMP_STRUCT
src
,
char
*
dst
,
size_t
dlen
)
{
int
n
=
snprintf
(
dst
,
dlen
,
"%04d-%02d-%02d %02d:%02d:%02d.%03d"
,
src
.
year
,
src
.
month
,
src
.
day
,
src
.
hour
,
src
.
minute
,
src
.
second
,
src
.
fraction
%
1000000
);
if
(
n
<
dlen
)
return
TSDB_CONV_OK
;
if
(
strlen
(
dst
)
>=
19
)
return
TSDB_CONV_TRUNC_FRACTION
;
return
TSDB_CONV_TRUNC
;
}
// src: chars
TSDB_CONV_CODE
tsdb_chars_to_bit
(
int
todb
,
const
char
*
src
,
int8_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_chars_to_bit
(
const
char
*
src
,
size_t
smax
,
int8_t
*
dst
)
{
if
(
strcmp
(
src
,
"0"
)
==
0
)
{
*
dst
=
0
;
return
TSDB_CONV_OK
;
...
...
@@ -189,11 +269,11 @@ TSDB_CONV_CODE tsdb_chars_to_bit(int todb, const char *src, int8_t *dst) {
return
TSDB_CONV_TRUNC_FRACTION
;
}
TSDB_CONV_CODE
tsdb_chars_to_tinyint
(
int
todb
,
const
char
*
src
,
int8_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_chars_to_tinyint
(
const
char
*
src
,
size_t
smax
,
int8_t
*
dst
)
{
int64_t
v
;
TSDB_CONV_CODE
code
=
tsdb_chars_to_bigint
(
todb
,
src
,
&
v
);
TSDB_CONV_CODE
code
=
tsdb_chars_to_bigint
(
src
,
smax
,
&
v
);
if
(
code
!=
TSDB_CONV_OK
)
return
code
;
*
dst
=
(
int8_t
)
v
;
if
(
v
==*
dst
)
return
TSDB_CONV_OK
;
...
...
@@ -201,11 +281,11 @@ TSDB_CONV_CODE tsdb_chars_to_tinyint(int todb, const char *src, int8_t *dst) {
return
TSDB_CONV_OOR
;
}
TSDB_CONV_CODE
tsdb_chars_to_smallint
(
int
todb
,
const
char
*
src
,
int16_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_chars_to_smallint
(
const
char
*
src
,
size_t
smax
,
int16_t
*
dst
)
{
int64_t
v
;
TSDB_CONV_CODE
code
=
tsdb_chars_to_bigint
(
todb
,
src
,
&
v
);
TSDB_CONV_CODE
code
=
tsdb_chars_to_bigint
(
src
,
smax
,
&
v
);
if
(
code
!=
TSDB_CONV_OK
)
return
code
;
*
dst
=
(
int16_t
)
v
;
if
(
v
==*
dst
)
return
TSDB_CONV_OK
;
...
...
@@ -213,11 +293,11 @@ TSDB_CONV_CODE tsdb_chars_to_smallint(int todb, const char *src, int16_t *dst) {
return
TSDB_CONV_OOR
;
}
TSDB_CONV_CODE
tsdb_chars_to_int
(
int
todb
,
const
char
*
src
,
int32_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_chars_to_int
(
const
char
*
src
,
size_t
smax
,
int32_t
*
dst
)
{
int64_t
v
;
TSDB_CONV_CODE
code
=
tsdb_chars_to_bigint
(
todb
,
src
,
&
v
);
TSDB_CONV_CODE
code
=
tsdb_chars_to_bigint
(
src
,
smax
,
&
v
);
if
(
code
!=
TSDB_CONV_OK
)
return
code
;
*
dst
=
(
int32_t
)
v
;
if
(
v
==*
dst
)
return
TSDB_CONV_OK
;
...
...
@@ -225,7 +305,7 @@ TSDB_CONV_CODE tsdb_chars_to_int(int todb, const char *src, int32_t *dst) {
return
TSDB_CONV_OOR
;
}
TSDB_CONV_CODE
tsdb_chars_to_bigint
(
int
todb
,
const
char
*
src
,
int64_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_chars_to_bigint
(
const
char
*
src
,
size_t
smax
,
int64_t
*
dst
)
{
int
bytes
;
int
n
=
sscanf
(
src
,
"%"
PRId64
"%n"
,
dst
,
&
bytes
);
...
...
@@ -244,11 +324,11 @@ TSDB_CONV_CODE tsdb_chars_to_bigint(int todb, const char *src, int64_t *dst) {
return
TSDB_CONV_OK
;
}
TSDB_CONV_CODE
tsdb_chars_to_ts
(
int
todb
,
const
char
*
src
,
int64_t
*
dst
)
{
TSDB_CONV_CODE
tsdb_chars_to_ts
(
const
char
*
src
,
size_t
smax
,
int64_t
*
dst
)
{
int64_t
v
;
TSDB_CONV_CODE
code
=
tsdb_chars_to_bigint
(
todb
,
src
,
&
v
);
TSDB_CONV_CODE
code
=
tsdb_chars_to_bigint
(
src
,
smax
,
&
v
);
if
(
code
!=
TSDB_CONV_OK
)
return
code
;
*
dst
=
v
;
if
(
v
==*
dst
)
{
...
...
@@ -260,7 +340,7 @@ TSDB_CONV_CODE tsdb_chars_to_ts(int todb, const char *src, int64_t *dst) {
return
TSDB_CONV_OOR
;
}
TSDB_CONV_CODE
tsdb_chars_to_float
(
int
todb
,
const
char
*
src
,
float
*
dst
)
{
TSDB_CONV_CODE
tsdb_chars_to_float
(
const
char
*
src
,
size_t
smax
,
float
*
dst
)
{
int
bytes
;
int
n
=
sscanf
(
src
,
"%g%n"
,
dst
,
&
bytes
);
...
...
@@ -271,7 +351,7 @@ TSDB_CONV_CODE tsdb_chars_to_float(int todb, const char *src, float *dst) {
return
TSDB_CONV_CHAR_NOT_NUM
;
}
TSDB_CONV_CODE
tsdb_chars_to_double
(
int
todb
,
const
char
*
src
,
double
*
dst
)
{
TSDB_CONV_CODE
tsdb_chars_to_double
(
const
char
*
src
,
size_t
smax
,
double
*
dst
)
{
int
bytes
;
int
n
=
sscanf
(
src
,
"%lg%n"
,
dst
,
&
bytes
);
...
...
@@ -282,82 +362,155 @@ TSDB_CONV_CODE tsdb_chars_to_double(int todb, const char *src, double *dst) {
return
TSDB_CONV_CHAR_NOT_NUM
;
}
TSDB_CONV_CODE
tsdb_chars_to_char
(
int
todb
,
const
char
*
src
,
char
*
dst
,
size_t
dlen
)
{
int
n
=
snprintf
(
dst
,
d
len
,
"%s"
,
src
);
if
(
n
<
d
len
)
return
TSDB_CONV_OK
;
TSDB_CONV_CODE
tsdb_chars_to_char
(
const
char
*
src
,
size_t
smax
,
char
*
dst
,
size_t
dmax
)
{
int
n
=
snprintf
(
dst
,
d
max
,
"%s"
,
src
);
if
(
n
<
d
max
)
return
TSDB_CONV_OK
;
return
TSDB_CONV_TRUNC
;
}
// src: wchars
TSDB_CONV_CODE
tsdb_wchars_to_bit
(
int
todb
,
const
unsigned
char
*
src
,
size_t
slen
,
int8_t
*
dst
)
{
char
buf
[
4096
];
char
*
p
=
buf
;
size_t
plen
=
sizeof
(
buf
);
if
(
slen
*
2
+
1
>=
sizeof
(
buf
))
{
plen
=
slen
*
2
+
1
;
p
=
(
char
*
)
malloc
(
plen
);
if
(
!
p
)
return
TSDB_CONV_OOM
;
TSDB_CONV_CODE
tsdb_wchars_to_bit
(
iconv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
int8_t
*
dst
)
{
if
(
cnv
==
(
iconv_t
)
-
1
)
return
TSDB_CONV_GENERAL
;
size_t
len
=
smax
*
2
;
buf_t
buf
;
buf_init
(
&
buf
,
len
+
1
);
if
(
!
buf
.
ptr
)
return
TSDB_CONV_OOM
;
size_t
dmax
=
len
+
1
;
TSDB_CONV_CODE
code
=
tsdb_iconv_conv
(
cnv
,
src
,
&
smax
,
(
unsigned
char
*
)
buf
.
ptr
,
&
dmax
);
if
(
code
==
TSDB_CONV_OK
)
{
code
=
tsdb_chars_to_bit
(
buf
.
ptr
,
len
+
1
-
dmax
,
dst
);
}
buf_clean
(
&
buf
);
return
code
;
}
TSDB_CONV_CODE
tsdb_wchars_to_tinyint
(
iconv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
int8_t
*
dst
)
{
if
(
cnv
==
(
iconv_t
)
-
1
)
return
TSDB_CONV_GENERAL
;
size_t
len
=
smax
*
2
;
buf_t
buf
;
buf_init
(
&
buf
,
len
+
1
);
if
(
!
buf
.
ptr
)
return
TSDB_CONV_OOM
;
size_t
dmax
=
len
+
1
;
TSDB_CONV_CODE
code
=
tsdb_iconv_conv
(
cnv
,
src
,
&
smax
,
(
unsigned
char
*
)
buf
.
ptr
,
&
dmax
);
if
(
code
==
TSDB_CONV_OK
)
{
code
=
tsdb_chars_to_tinyint
(
buf
.
ptr
,
len
+
1
-
dmax
,
dst
);
}
buf_clean
(
&
buf
);
return
code
;
}
TSDB_CONV_CODE
tsdb_wchars_to_smallint
(
iconv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
int16_t
*
dst
)
{
if
(
cnv
==
(
iconv_t
)
-
1
)
return
TSDB_CONV_GENERAL
;
size_t
len
=
smax
*
2
;
buf_t
buf
;
buf_init
(
&
buf
,
len
+
1
);
if
(
!
buf
.
ptr
)
return
TSDB_CONV_OOM
;
size_t
dmax
=
len
+
1
;
TSDB_CONV_CODE
code
=
tsdb_iconv_conv
(
cnv
,
src
,
&
smax
,
(
unsigned
char
*
)
buf
.
ptr
,
&
dmax
);
if
(
code
==
TSDB_CONV_OK
)
{
code
=
tsdb_chars_to_smallint
(
buf
.
ptr
,
len
+
1
-
dmax
,
dst
);
}
buf_clean
(
&
buf
);
return
code
;
}
TSDB_CONV_CODE
tsdb_wchars_to_int
(
iconv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
int32_t
*
dst
)
{
if
(
cnv
==
(
iconv_t
)
-
1
)
return
TSDB_CONV_GENERAL
;
size_t
len
=
smax
*
2
;
buf_t
buf
;
buf_init
(
&
buf
,
len
+
1
);
if
(
!
buf
.
ptr
)
return
TSDB_CONV_OOM
;
size_t
dmax
=
len
+
1
;
TSDB_CONV_CODE
code
=
tsdb_iconv_conv
(
cnv
,
src
,
&
smax
,
(
unsigned
char
*
)
buf
.
ptr
,
&
dmax
);
if
(
code
==
TSDB_CONV_OK
)
{
code
=
tsdb_chars_to_int
(
buf
.
ptr
,
len
+
1
-
dmax
,
dst
);
}
size_t
n
=
wchars_to_chars2
((
const
SQLWCHAR
*
)
src
,
slen
,
(
SQLCHAR
*
)
p
,
plen
);
TSDB_CONV_CODE
code
=
TSDB_CONV_OK
;
do
{
if
(
n
<
0
)
{
code
=
TSDB_CONV_CHAR_NOT_NUM
;
break
;
}
if
(
n
>=
plen
)
{
code
=
TSDB_CONV_CHAR_NOT_NUM
;
break
;
}
p
[
n
]
=
'\0'
;
code
=
tsdb_chars_to_bit
(
todb
,
p
,
dst
);
}
while
(
0
);
if
(
p
!=
buf
)
{
free
(
p
);
buf_clean
(
&
buf
);
return
code
;
}
TSDB_CONV_CODE
tsdb_wchars_to_bigint
(
iconv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
int64_t
*
dst
)
{
if
(
cnv
==
(
iconv_t
)
-
1
)
return
TSDB_CONV_GENERAL
;
size_t
len
=
smax
*
2
;
buf_t
buf
;
buf_init
(
&
buf
,
len
+
1
);
if
(
!
buf
.
ptr
)
return
TSDB_CONV_OOM
;
size_t
dmax
=
len
+
1
;
TSDB_CONV_CODE
code
=
tsdb_iconv_conv
(
cnv
,
src
,
&
smax
,
(
unsigned
char
*
)
buf
.
ptr
,
&
dmax
);
if
(
code
==
TSDB_CONV_OK
)
{
code
=
tsdb_chars_to_bigint
(
buf
.
ptr
,
len
+
1
-
dmax
,
dst
);
}
buf_clean
(
&
buf
);
return
code
;
}
TSDB_CONV_CODE
tsdb_wchars_to_tinyint
(
int
todb
,
const
unsigned
char
*
src
,
size_t
slen
,
int8_t
*
dst
)
{
char
buf
[
4096
];
char
*
p
=
buf
;
size_t
plen
=
sizeof
(
buf
);
if
(
slen
*
2
+
1
>=
sizeof
(
buf
))
{
plen
=
slen
*
2
+
1
;
p
=
(
char
*
)
malloc
(
plen
);
if
(
!
p
)
return
TSDB_CONV_OOM
;
TSDB_CONV_CODE
tsdb_wchars_to_ts
(
iconv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
int64_t
*
dst
)
{
return
tsdb_wchars_to_bigint
(
cnv
,
src
,
smax
,
dst
);
}
TSDB_CONV_CODE
tsdb_wchars_to_float
(
iconv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
float
*
dst
)
{
if
(
cnv
==
(
iconv_t
)
-
1
)
return
TSDB_CONV_GENERAL
;
size_t
len
=
smax
*
2
;
buf_t
buf
;
buf_init
(
&
buf
,
len
+
1
);
if
(
!
buf
.
ptr
)
return
TSDB_CONV_OOM
;
size_t
dmax
=
len
+
1
;
TSDB_CONV_CODE
code
=
tsdb_iconv_conv
(
cnv
,
src
,
&
smax
,
(
unsigned
char
*
)
buf
.
ptr
,
&
dmax
);
if
(
code
==
TSDB_CONV_OK
)
{
code
=
tsdb_chars_to_float
(
buf
.
ptr
,
len
+
1
-
dmax
,
dst
);
}
size_t
n
=
wchars_to_chars2
((
const
SQLWCHAR
*
)
src
,
slen
,
(
SQLCHAR
*
)
p
,
plen
);
TSDB_CONV_CODE
code
=
TSDB_CONV_OK
;
do
{
if
(
n
<
0
)
{
code
=
TSDB_CONV_CHAR_NOT_NUM
;
break
;
}
if
(
n
>=
sizeof
(
buf
))
{
code
=
TSDB_CONV_CHAR_NOT_NUM
;
break
;
}
buf
[
n
]
=
'\0'
;
code
=
tsdb_chars_to_tinyint
(
todb
,
buf
,
dst
);
}
while
(
0
);
if
(
p
!=
buf
)
{
free
(
p
);
buf_clean
(
&
buf
);
return
code
;
}
TSDB_CONV_CODE
tsdb_wchars_to_double
(
iconv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
double
*
dst
)
{
if
(
cnv
==
(
iconv_t
)
-
1
)
return
TSDB_CONV_GENERAL
;
size_t
len
=
smax
*
2
;
buf_t
buf
;
buf_init
(
&
buf
,
len
+
1
);
if
(
!
buf
.
ptr
)
return
TSDB_CONV_OOM
;
size_t
dmax
=
len
+
1
;
TSDB_CONV_CODE
code
=
tsdb_iconv_conv
(
cnv
,
src
,
&
smax
,
(
unsigned
char
*
)
buf
.
ptr
,
&
dmax
);
if
(
code
==
TSDB_CONV_OK
)
{
code
=
tsdb_chars_to_double
(
buf
.
ptr
,
len
+
1
-
dmax
,
dst
);
}
buf_clean
(
&
buf
);
return
code
;
}
TSDB_CONV_CODE
tsdb_wchars_to_char
(
iconv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
char
*
dst
,
size_t
dmax
)
{
return
tsdb_iconv_conv
(
cnv
,
src
,
&
smax
,
(
unsigned
char
*
)
dst
,
&
dmax
);
}
src/connector/odbc/src/todbc_conv.h
浏览文件 @
15364b8e
...
...
@@ -17,8 +17,12 @@
#define _todbc_conv_h_
#include <inttypes.h>
#include <sqltypes.h>
#include <stddef.h>
#include "iconv.h"
typedef
enum
{
TSDB_CONV_OK
=
0
,
TSDB_CONV_OOM
,
...
...
@@ -26,44 +30,53 @@ typedef enum {
TSDB_CONV_TRUNC_FRACTION
,
TSDB_CONV_TRUNC
,
TSDB_CONV_CHAR_NOT_NUM
,
TSDB_CONV_GENERAL
,
TSDB_CONV_BAD_CHAR
,
}
TSDB_CONV_CODE
;
TSDB_CONV_CODE
tsdb_int64_to_bit
(
int
todb
,
int64_t
src
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_tinyint
(
int
todb
,
int64_t
src
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_smallint
(
int
todb
,
int64_t
src
,
int16_t
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_int
(
int
todb
,
int64_t
src
,
int32_t
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_bigint
(
int
todb
,
int64_t
src
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_ts
(
int
todb
,
int64_t
src
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_float
(
int
todb
,
int64_t
src
,
float
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_double
(
int
todb
,
int64_t
src
,
double
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_char
(
int
todb
,
int64_t
src
,
char
*
dst
,
size_t
dlen
);
TSDB_CONV_CODE
tsdb_iconv_conv
(
iconv_t
cnv
,
const
unsigned
char
*
src
,
size_t
*
slen
,
unsigned
char
*
dst
,
size_t
*
dlen
);
TSDB_CONV_CODE
tsdb_int64_to_bit
(
int64_t
src
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_tinyint
(
int64_t
src
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_smallint
(
int64_t
src
,
int16_t
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_int
(
int64_t
src
,
int32_t
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_bigint
(
int64_t
src
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_ts
(
int64_t
src
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_float
(
int64_t
src
,
float
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_double
(
int64_t
src
,
double
*
dst
);
TSDB_CONV_CODE
tsdb_int64_to_char
(
int64_t
src
,
char
*
dst
,
size_t
dlen
);
TSDB_CONV_CODE
tsdb_double_to_bit
(
double
src
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_double_to_tinyint
(
double
src
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_double_to_smallint
(
double
src
,
int16_t
*
dst
);
TSDB_CONV_CODE
tsdb_double_to_int
(
double
src
,
int32_t
*
dst
);
TSDB_CONV_CODE
tsdb_double_to_bigint
(
double
src
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_double_to_ts
(
double
src
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_double_to_char
(
double
src
,
char
*
dst
,
size_t
dlen
);
TSDB_CONV_CODE
tsdb_double_to_bit
(
int
todb
,
double
src
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_double_to_tinyint
(
int
todb
,
double
src
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_double_to_smallint
(
int
todb
,
double
src
,
int16_t
*
dst
);
TSDB_CONV_CODE
tsdb_double_to_int
(
int
todb
,
double
src
,
int32_t
*
dst
);
TSDB_CONV_CODE
tsdb_double_to_bigint
(
int
todb
,
double
src
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_double_to_ts
(
int
todb
,
double
src
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_timestamp_to_char
(
SQL_TIMESTAMP_STRUCT
src
,
char
*
dst
,
size_t
dlen
);
TSDB_CONV_CODE
tsdb_chars_to_bit
(
int
todb
,
const
char
*
src
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_tinyint
(
int
todb
,
const
char
*
src
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_smallint
(
int
todb
,
const
char
*
src
,
int16_t
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_int
(
int
todb
,
const
char
*
src
,
int32_t
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_bigint
(
int
todb
,
const
char
*
src
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_ts
(
int
todb
,
const
char
*
src
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_float
(
int
todb
,
const
char
*
src
,
float
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_double
(
int
todb
,
const
char
*
src
,
double
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_char
(
int
todb
,
const
char
*
src
,
char
*
dst
,
size_t
dlen
);
TSDB_CONV_CODE
tsdb_chars_to_bit
(
const
char
*
src
,
size_t
smax
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_tinyint
(
const
char
*
src
,
size_t
smax
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_smallint
(
const
char
*
src
,
size_t
smax
,
int16_t
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_int
(
const
char
*
src
,
size_t
smax
,
int32_t
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_bigint
(
const
char
*
src
,
size_t
smax
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_ts
(
const
char
*
src
,
size_t
smax
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_float
(
const
char
*
src
,
size_t
smax
,
float
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_double
(
const
char
*
src
,
size_t
smax
,
double
*
dst
);
TSDB_CONV_CODE
tsdb_chars_to_char
(
const
char
*
src
,
size_t
smax
,
char
*
dst
,
size_t
dmax
);
TSDB_CONV_CODE
tsdb_wchars_to_bit
(
i
nt
todb
,
const
unsigned
char
*
src
,
size_t
slen
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_tinyint
(
i
nt
todb
,
const
unsigned
char
*
src
,
size_t
slen
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_smallint
(
i
nt
todb
,
const
unsigned
char
*
src
,
size_t
slen
,
int16_t
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_int
(
i
nt
todb
,
const
unsigned
char
*
src
,
size_t
slen
,
int32_t
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_bigint
(
i
nt
todb
,
const
unsigned
char
*
src
,
size_t
slen
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_ts
(
i
nt
todb
,
const
unsigned
char
*
src
,
size_t
slen
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_float
(
i
nt
todb
,
const
unsigned
char
*
src
,
size_t
slen
,
float
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_double
(
i
nt
todb
,
const
unsigned
char
*
src
,
size_t
slen
,
double
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_char
(
i
nt
todb
,
const
unsigned
char
*
src
,
size_t
slen
,
char
*
dst
,
size_t
dlen
);
TSDB_CONV_CODE
tsdb_wchars_to_bit
(
i
conv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_tinyint
(
i
conv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
int8_t
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_smallint
(
i
conv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
int16_t
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_int
(
i
conv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
int32_t
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_bigint
(
i
conv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_ts
(
i
conv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
int64_t
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_float
(
i
conv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
float
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_double
(
i
conv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
double
*
dst
);
TSDB_CONV_CODE
tsdb_wchars_to_char
(
i
conv_t
cnv
,
const
unsigned
char
*
src
,
size_t
smax
,
char
*
dst
,
size_t
dmax
);
#endif // _todbc_conv_h_
src/connector/odbc/src/todbc_util.h
浏览文件 @
15364b8e
...
...
@@ -42,8 +42,6 @@ do { \
abort(); \
} while (0)
const
char
*
sql_sql_type
(
int
type
);
const
char
*
sql_c_type
(
int
type
);
...
...
src/connector/odbc/tests/odbc.py
浏览文件 @
15364b8e
...
...
@@ -119,10 +119,10 @@ while row:
cursor
.
close
()
cursor
=
cnxn
.
cursor
()
cursor
.
execute
(
"create table db.f (ts timestamp, v1
bool
)"
)
cursor
.
execute
(
"create table db.f (ts timestamp, v1
float
)"
)
cursor
.
close
()
params
=
[
(
'2020-10-20 00:00:
00'
,
'acb
'
)
]
params
=
[
(
'2020-10-20 00:00:
10'
,
'123.3
'
)
]
cursor
=
cnxn
.
cursor
()
cursor
.
fast_executemany
=
True
cursor
.
executemany
(
"insert into db.f values (?, ?)"
,
params
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录