Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
12eafdd8
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
12eafdd8
编写于
10月 08, 2020
作者:
F
freemine
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add prepare/bind/execute support
上级
dc2df3a0
变更
2
展开全部
隐藏空白更改
内联
并排
Showing
2 changed file
with
763 addition
and
26 deletion
+763
-26
src/connector/odbc/src/todbc.c
src/connector/odbc/src/todbc.c
+581
-25
src/connector/odbc/tests/main.c
src/connector/odbc/tests/main.c
+182
-1
未找到文件。
src/connector/odbc/src/todbc.c
浏览文件 @
12eafdd8
此差异已折叠。
点击以展开。
src/connector/odbc/tests/main.c
浏览文件 @
12eafdd8
#include <sql.h>
#include <sqlext.h>
#include <stdio.h>
#include <string.h>
#include "os.h"
int
main
(
void
)
{
// static const char *dsn = "TAOS_DSN";
// static const char *uid = "root";
// static const char *pwd = "taosdata";
typedef
struct
data_s
data_t
;
struct
data_s
{
int64_t
ts
;
int8_t
b
;
int8_t
v1
;
int16_t
v2
;
int32_t
v4
;
int64_t
v8
;
float
f4
;
double
f8
;
char
bin
[
40
+
1
];
char
blob
[
40
+
1
];
// why 80? ref: tests/examples/c/apitest.c
};
static
const
char
*
pre_stmts
[]
=
{
"create database db"
,
"use db"
,
"create table t (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), blob nchar(10))"
};
static
const
char
*
pro_stmts
[]
=
{
// "insert into t values ('2019-07-15 00:00:00', 1)",
// "insert into t values ('2019-07-15 01:00:00', 2)",
"select * from t"
// "drop database db"
};
static
int
do_statement
(
SQLHSTMT
stmt
,
const
char
*
statement
)
{
SQLRETURN
r
=
0
;
do
{
fprintf
(
stderr
,
"prepare [%s]
\n
"
,
statement
);
r
=
SQLPrepare
(
stmt
,
(
SQLCHAR
*
)
statement
,
strlen
(
statement
));
if
(
r
)
break
;
fprintf
(
stderr
,
"execute [%s]
\n
"
,
statement
);
r
=
SQLExecute
(
stmt
);
if
(
r
)
break
;
fprintf
(
stderr
,
"done
\n
"
);
}
while
(
0
);
fprintf
(
stderr
,
"r: [%x][%d]
\n
"
,
r
,
r
);
return
r
;
}
static
int
do_insert
(
SQLHSTMT
stmt
,
data_t
data
)
{
SQLRETURN
r
=
0
;
SQLLEN
lbin
;
SQLLEN
lblob
;
const
char
*
statement
=
"insert into t values (?, ?, ?, ?, ?, ?, ?, ?, ?,?)"
;
int
ignore
=
0
;
do
{
fprintf
(
stderr
,
"prepare [%s]
\n
"
,
statement
);
r
=
SQLPrepare
(
stmt
,
(
SQLCHAR
*
)
statement
,
strlen
(
statement
));
if
(
r
)
break
;
fprintf
(
stderr
,
"bind 1 [%s]
\n
"
,
statement
);
r
=
SQLBindParameter
(
stmt
,
1
,
SQL_PARAM_INPUT
,
SQL_C_SBIGINT
,
SQL_TIMESTAMP
,
ignore
,
ignore
,
&
data
.
ts
,
ignore
,
NULL
);
if
(
r
)
break
;
fprintf
(
stderr
,
"bind 2 [%s]
\n
"
,
statement
);
r
=
SQLBindParameter
(
stmt
,
2
,
SQL_PARAM_INPUT
,
SQL_C_BIT
,
SQL_BIT
,
ignore
,
ignore
,
&
data
.
b
,
ignore
,
NULL
);
if
(
r
)
break
;
fprintf
(
stderr
,
"bind 3 [%s]
\n
"
,
statement
);
r
=
SQLBindParameter
(
stmt
,
3
,
SQL_PARAM_INPUT
,
SQL_C_TINYINT
,
SQL_TINYINT
,
ignore
,
ignore
,
&
data
.
v1
,
ignore
,
NULL
);
if
(
r
)
break
;
fprintf
(
stderr
,
"bind 4 [%s]
\n
"
,
statement
);
r
=
SQLBindParameter
(
stmt
,
4
,
SQL_PARAM_INPUT
,
SQL_C_SHORT
,
SQL_SMALLINT
,
ignore
,
ignore
,
&
data
.
v2
,
ignore
,
NULL
);
if
(
r
)
break
;
fprintf
(
stderr
,
"bind 5 [%s]
\n
"
,
statement
);
r
=
SQLBindParameter
(
stmt
,
5
,
SQL_PARAM_INPUT
,
SQL_C_LONG
,
SQL_INTEGER
,
ignore
,
ignore
,
&
data
.
v4
,
ignore
,
NULL
);
if
(
r
)
break
;
fprintf
(
stderr
,
"bind 6 [%s]
\n
"
,
statement
);
r
=
SQLBindParameter
(
stmt
,
6
,
SQL_PARAM_INPUT
,
SQL_C_SBIGINT
,
SQL_BIGINT
,
ignore
,
ignore
,
&
data
.
v8
,
ignore
,
NULL
);
if
(
r
)
break
;
fprintf
(
stderr
,
"bind 7 [%s]
\n
"
,
statement
);
r
=
SQLBindParameter
(
stmt
,
7
,
SQL_PARAM_INPUT
,
SQL_C_FLOAT
,
SQL_FLOAT
,
ignore
,
ignore
,
&
data
.
f4
,
ignore
,
NULL
);
if
(
r
)
break
;
fprintf
(
stderr
,
"bind 8 [%s]
\n
"
,
statement
);
SQLLEN
l8
=
SQL_NULL_DATA
;
r
=
SQLBindParameter
(
stmt
,
8
,
SQL_PARAM_INPUT
,
SQL_C_DOUBLE
,
SQL_DOUBLE
,
ignore
,
ignore
,
&
data
.
f8
,
ignore
,
&
l8
);
if
(
r
)
break
;
fprintf
(
stderr
,
"bind 9 [%s]
\n
"
,
statement
);
lbin
=
SQL_NTS
;
r
=
SQLBindParameter
(
stmt
,
9
,
SQL_PARAM_INPUT
,
SQL_C_BINARY
,
SQL_VARBINARY
,
sizeof
(
data
.
bin
)
-
1
,
ignore
,
&
data
.
bin
,
ignore
,
&
lbin
);
if
(
r
)
break
;
fprintf
(
stderr
,
"bind 10 [%s]
\n
"
,
statement
);
lblob
=
SQL_NTS
;
r
=
SQLBindParameter
(
stmt
,
10
,
SQL_PARAM_INPUT
,
SQL_C_CHAR
,
SQL_VARCHAR
,
sizeof
(
data
.
blob
)
-
1
,
ignore
,
&
data
.
blob
,
ignore
,
&
lblob
);
if
(
r
)
break
;
fprintf
(
stderr
,
"execute [%s]
\n
"
,
statement
);
r
=
SQLExecute
(
stmt
);
if
(
r
)
break
;
// ts += 1;
// v = 2;
// fprintf(stderr, "execute [%s]\n", statement);
// r = SQLExecute(stmt);
// if (r) break;
fprintf
(
stderr
,
"done
\n
"
);
}
while
(
0
);
fprintf
(
stderr
,
"r: [%x][%d]
\n
"
,
r
,
r
);
return
r
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
4
)
return
1
;
const
char
*
dsn
=
argv
[
1
];
const
char
*
uid
=
argv
[
2
];
const
char
*
pwd
=
argv
[
3
];
SQLRETURN
r
;
SQLHENV
env
=
{
0
};
SQLHDBC
conn
=
{
0
};
...
...
@@ -12,6 +137,62 @@ int main(void) {
do
{
r
=
SQLAllocConnect
(
env
,
&
conn
);
if
(
r
!=
SQL_SUCCESS
)
break
;
do
{
r
=
SQLConnect
(
conn
,
(
SQLCHAR
*
)
dsn
,
strlen
(
dsn
),
(
SQLCHAR
*
)
uid
,
strlen
(
uid
),
(
SQLCHAR
*
)
pwd
,
strlen
(
pwd
));
if
(
r
!=
SQL_SUCCESS
)
break
;
do
{
SQLHSTMT
stmt
=
{
0
};
r
=
SQLAllocHandle
(
SQL_HANDLE_STMT
,
conn
,
&
stmt
);
if
(
r
!=
SQL_SUCCESS
)
break
;
do
{
do_statement
(
stmt
,
"drop database db"
);
for
(
size_t
i
=
0
;
i
<
sizeof
(
pre_stmts
)
/
sizeof
(
pre_stmts
[
0
]);
++
i
)
{
r
=
do_statement
(
stmt
,
pre_stmts
[
i
]);
if
(
r
!=
SQL_SUCCESS
)
break
;
}
do
{
data_t
data
=
{
0
};
data
.
ts
=
1591060628001
;
data
.
b
=
1
;
data
.
v1
=
127
;
data
.
v2
=
32767
;
data
.
v4
=
2147483647
;
data
.
v8
=
9223372036854775807
;
data
.
f4
=
123
.
456
;
data
.
f8
=
9999999
.
999999
;
memset
(
data
.
bin
,
0
,
sizeof
(
data
.
bin
));
memset
(
data
.
blob
,
0
,
sizeof
(
data
.
blob
));
snprintf
(
data
.
bin
,
sizeof
(
data
.
bin
),
"hello"
);
snprintf
(
data
.
blob
,
sizeof
(
data
.
blob
),
"world"
);
SQLHSTMT
stmt
=
{
0
};
r
=
SQLAllocHandle
(
SQL_HANDLE_STMT
,
conn
,
&
stmt
);
if
(
r
!=
SQL_SUCCESS
)
break
;
do
{
r
=
do_insert
(
stmt
,
data
);
if
(
r
!=
SQL_SUCCESS
)
break
;
}
while
(
0
);
SQLFreeHandle
(
SQL_HANDLE_STMT
,
stmt
);
// r = SQLAllocHandle(SQL_HANDLE_STMT, conn, &stmt);
// if (r!=SQL_SUCCESS) break;
// do {
// r = do_insert(stmt, ts++, v++);
// if (r!=SQL_SUCCESS) break;
// } while (0);
// SQLFreeHandle(SQL_HANDLE_STMT, stmt);
}
while
(
0
);
if
(
r
!=
SQL_SUCCESS
)
break
;
for
(
size_t
i
=
0
;
i
<
sizeof
(
pro_stmts
)
/
sizeof
(
pro_stmts
[
0
]);
++
i
)
{
r
=
do_statement
(
stmt
,
pro_stmts
[
i
]);
if
(
r
!=
SQL_SUCCESS
)
break
;
}
}
while
(
0
);
SQLFreeHandle
(
SQL_HANDLE_STMT
,
stmt
);
}
while
(
0
);
SQLDisconnect
(
conn
);
}
while
(
0
);
SQLFreeConnect
(
conn
);
}
while
(
0
);
SQLFreeEnv
(
env
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录