README.md 5.2 KB
Newer Older
F
freemine 已提交
1 2 3

# ODBC Driver #

F
freemine 已提交
4
- **on-going implementation of ODBC driver for TAOS**
F
freemine 已提交
5

F
freemine 已提交
6
- **currently exported ODBC functions are**:
F
freemine 已提交
7 8 9 10
SQLAllocEnv
SQLFreeEnv
SQLAllocConnect
SQLFreeConnect
F
freemine 已提交
11 12 13 14 15
SQLGetEnvAttr
SQLSetEnvAttr
SQLGetConnectAttr
SQLGetConnectOption
SQLGetInfo
F
freemine 已提交
16 17 18 19
SQLConnect
SQLDisconnect
SQLAllocStmt
SQLAllocHandle
F
freemine 已提交
20
SQLFreeHandle
F
freemine 已提交
21 22 23 24 25 26 27 28 29
SQLFreeStmt
SQLExecDirect
SQLNumResultCols
SQLRowCount
SQLColAttribute
SQLGetData
SQLFetch
SQLPrepare
SQLExecute
F
freemine 已提交
30 31
SQLParamData
SQLPutData
F
freemine 已提交
32 33
SQLGetDiagRec
SQLBindParameter
F
freemine 已提交
34
SQLDescribeParam
F
freemine 已提交
35 36 37
SQLDriverConnect
SQLSetConnectAttr
SQLDescribeCol
F
freemine 已提交
38
SQLBindCol
F
freemine 已提交
39 40
SQLNumParams
SQLSetStmtAttr
F
freemine 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
SQLBindParam
SQLCancel
SQLCancelHandle
SQLCloseCursor
SQLColumns
SQLCopyDesc
SQLDataSources
SQLEndTran
SQLFetchScroll
SQLGetCursorName
SQLGetDescField
SQLGetDescRec
SQLGetStmtAttr
SQLGetStmtOption
SQLGetTypeInfo
SQLSetConnectOption
SQLSetCursorName
SQLSetDescField
SQLSetDescRec
SQLSetParam
SQLSetStmtOption
SQLSpecialColumns
SQLStatistics
SQLTables
SQLTransact

F
freemine 已提交
67 68
`

F
freemine 已提交
69
- **internationalized, you can specify charset for SQLCHAR/SQLWCHAR/taos_charset/system-locale to coordinate with the environment**.
F
freemine 已提交
70

F
freemine 已提交
71
- **enable ODBC-aware software to communicate with TAOS, no matter what platform it's running on, currently we support linux/macosx/windows**
F
freemine 已提交
72

F
freemine 已提交
73
- **enable any language with ODBC-bindings/ODBC-plugings to communicate with TAOS, currently c/nodejs/python/rust/go are all passed in our test environment, we believe other languages with ODBC-bindings/plugins are available-out-of-box**
F
freemine 已提交
74

F
freemine 已提交
75
- **still going on**...
F
freemine 已提交
76 77 78

# Building and Testing
**Note**: all `work` is done in TDengine's project directory
F
freemine 已提交
79 80 81 82 83 84 85
**Note**: please make sure src/connector/odbc is included in src/CMakeLists.txt
```
...
ADD_SUBDIRECTORY(dnode)
ADD_SUBDIRECTORY(connector/odbc)
ADD_SUBDIRECTORY(connector/jdbc)
```
F
freemine 已提交
86 87 88 89 90 91 92 93

# Building under Linux, use Ubuntu as example
```
sudo apt install unixodbc unixodbc-dev flex
rm -rf debug && cmake -B debug && cmake --build debug && cmake --install debug && echo yes
```
# Building under Windows, use Windows 10 as example
- install windows `flex` port. We use [https://github.com/lexxmark/winflexbison](url) at the moment. Please be noted to append `<path_to_win_flex.exe>` to your `PATH`.
F
freemine 已提交
94 95
- install Microsoft Visual Studio, take VS2019 as example here
- `"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"`
F
freemine 已提交
96 97 98 99
- `rmdir /s /q debug`
- `cmake -G "NMake Makefiles" -B debug`
- `cmake --build debug`
- `cmake --install debug`
F
freemine 已提交
100
- open your `Command Prompt` with Administrator's priviledge
F
freemine 已提交
101 102
- install TAOS ODBC driver that was just built: run `odbcconf /A {INSTALLDRIVER "TAOS | Driver=C:/TDengine/driver/todbc.dll | ConnectFunctions=YYN | DriverODBCVer=03.00"}`
- add a new user dsn: run `odbcconf /A {CONFIGDSN "TAOS" "DSN=TAOS_DSN | Server=host:port"}`
F
freemine 已提交
103 104

# Test
F
freemine 已提交
105
we highly suggest that you build both in linux(ubuntu) and windows(windows 10) platform, because currently TAOS has not server-side port on windows platform.
F
freemine 已提交
106 107
**Note1**: content within <> shall be modified to match your environment
**Note2**: `.stmts` source files are all encoded in `UTF-8`
F
freemine 已提交
108
## start taosd in linux, suppose charset is `UTF-8` as default, please follow TAOS doc for starting up
F
freemine 已提交
109 110
## create data in linux
```
F
freemine 已提交
111
./debug/build/bin/tcodbc --dsn TAOS_DSN --uid <uid> --pwd <pwd> --sts ./src/connector/odbc/samples/create_data.stmts
F
freemine 已提交
112
--<or with driver connection string -->
F
freemine 已提交
113
./debug/build/bin/tcodbc -C 'DSN=TAOS_DSN;UID=<uid>;PWD=<pwd>;Server=<fqdn>:<port>' --sts ./src/connector/odbc/samples/create_data.stmts
F
freemine 已提交
114 115 116
```
## query data in windows
```
F
freemine 已提交
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
.\debug\build\bin\tcodbc -C "DSN=TAOS_DSN;UID=<uid>;PWD=<pwd>;Server=<fqdn>:<port>;enc_char=UTF-8" --sts .\src\connector\odbc\samples\query_data.stmts
```
## query data in MacOSX
```
./debug/build/bin/tcodbc -C "DSN=TAOS_DSN;UID=<uid>;PWD=<pwd>;Server=<fqdn>:<port>" --sts ./src/connector/odbc/samples/query_data.stmts
```

## code examples
- src/connector/odbc/examples/c
- src/connector/odbc/examples/js
- src/connector/odbc/examples/py
- src/connector/odbc/examples/rust
- src/connector/odbc/examples/go

on linux/MacOSX, here after are script-snippet for you to play with:
**Note**: don't forget to replace <host>:<port> with whatever on your environment
**Note**: you need to install node/python3/rust/go on you machine
**Note**: you also need to install odbc-bindings/odbc-pluggins on those language platform, such as:
-- node-odbc for nodejs: https://www.npmjs.com/package/odbc
-- pyodbc for python:    https://pypi.org/project/pyodbc/
-- rust-odbc for rust:   https://docs.rs/odbc/0.17.0/odbc/
-- go-odbc for go:       https://github.com/alexbrainman/odbc

```
echo c &&
./debug/build/bin/tcodbc -C "DSN=TAOS_DSN;Server=<host>:<port>" --sts src/connector/odbc/samples/create_data.stmts &&
echo nodejs &&
./src/connector/odbc/examples/js/odbc.js -C 'DSN=TAOS_DSN;Server=<host>:<port>' &&
echo python &&
python3 src/connector/odbc/examples/py/odbc.py -C 'DSN=TAOS_DSN;Server=<host>:<port>' &&
echo rust &&
pushd src/connector/odbc/examples/rust/main && DSN='DSN=TAOS_DSN;Server=<host>:<port>' cargo run && popd &&
echo go &&
DSN='DSN=TAOS_DSN;Server=<host>:<port>' go run src/connector/odbc/examples/go/odbc.go &&
```

## see how fast prepared-statment could bring up with:
```
./debug/build/bin/tcodbc -C "DSN=TAOS_DSN;Server=<host>:<port>" --insert --batch_size 200 --batchs 10000
F
freemine 已提交
156 157 158
```