-
Notifications
You must be signed in to change notification settings - Fork 19
Create openresty-odbc-connection.md #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,69 @@ | ||||||
# Openresty Exasol ODBC connection | ||||||
Below are steps to connect to Exasol from Openresty. | ||||||
|
||||||
* Install openresty [Openresty Installation manual](https://openresty.org/en/linux-packages.html#ubuntu) | ||||||
* install Luarocks | ||||||
|
||||||
```markup | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
wget https://github.com/luarocks/luarocks/archive/v3.0.0.tar.gz | ||||||
|
||||||
tar zxvf v3.0.0.tar.gz | ||||||
|
||||||
./configure --prefix=/usr/local/openresty/luajit/ --with-lua=/usr/local/openresty/luajit/ --lua-suffix=jit --with-lua-include=/usr/local/openresty/luajit/include/luajit-2.1 | ||||||
|
||||||
sudo make build | ||||||
|
||||||
sudo make install | ||||||
``` | ||||||
|
||||||
* install ODBC package in luarocks | ||||||
```markup | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
luarocks install odbc | ||||||
``` | ||||||
|
||||||
* install Exasol ODBC driver, create DSN for Exasol DB [ODBC Drivers for Linux/FreeBSD | Exasol Documentation](https://docs.exasol.com/db/latest/connect_exasol/drivers/odbc/odbc_linux.htm) | ||||||
|
||||||
* Execute connection test scripts | ||||||
|
||||||
**odbctest.sh** | ||||||
```markup | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
# set -x | ||||||
# ORHOME is the path to the OpenResty install | ||||||
export ORHOME="/usr/local/openresty" | ||||||
export ODBCINI="${ORHOME}/odbc/.odbc.ini" | ||||||
export LD_LIBRARY_PATH="${ORHOME}/luajit/lib" | ||||||
export PATH="$PATH:${ORHOME}/bin/" | ||||||
resty odbctest.lua $1 | ||||||
echo "Retun code from resty $?" | ||||||
``` | ||||||
**odbctest.lua** | ||||||
```markup | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
local odbc = require("odbc") | ||||||
local call = [[select * from sys.exa_all_tables]] | ||||||
print("Using dsn " .. arg[1]) | ||||||
local DSN = arg[1] | ||||||
print("About to connect") | ||||||
local cnn,err = odbc.connect(DSN) | ||||||
if cnn == nil then | ||||||
print("Failed to connect" .. err.message) | ||||||
else | ||||||
print("Connected") | ||||||
end | ||||||
local stmt,err = cnn:statement() | ||||||
if stmt == nil then | ||||||
print("Failed to prepare Statement" ..err.message) | ||||||
else | ||||||
print("Prepared statement" ) | ||||||
end | ||||||
local ret,err = stmt:execute(call) | ||||||
if ret == nil then | ||||||
print("Failed to execute statement" .. err.message) | ||||||
else | ||||||
print("Executed satement") | ||||||
end | ||||||
local cols = ret:colnames() | ||||||
if string.upper(cols[1]) == [[ERR]] then | ||||||
-- There has been some sort of error | ||||||
print("Some sort of error was raised " .. ret:fetch()) | ||||||
end | ||||||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.