1
votes

I'm trying to install the ODBC driver (?) for Lua. I'm running Windows 10 and have followed the instructions at http://www.thijsschreijer.nl/blog/?p=863 as far as the command "lua -l socket"

Here is a screen copy of my command and the results

C:\Program Files (x86)\LuaRocks>luarocks install luasql-odbc
Installing https://luarocks.org/luasql-odbc-2.4.0-1.src.rock

C:\MinGW\bin\gcc.exe -O2 -c -o src/luasql.o -IC:\Program Files (x86)\Lua\5_3\include src/luasql.c -Ic:/mingw/include
C:\MinGW\bin\gcc.exe -O2 -c -o src/ls_odbc.o -IC:\Program Files (x86)\Lua\5_3\include src/ls_odbc.c -Ic:/mingw/include
C:\MinGW\bin\gcc.exe -shared -o luasql/odbc.dll src/luasql.o src/ls_odbc.o -Lc:/mingw -lodbc C:\Program Files (x86)\Lua\5_3\bin/lua53.dll -lm
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lodbc collect2.exe: error: ld returned 1 exit status

Error: Build error: Failed compiling module luasql/odbc.dll

Since I'm a newbie to the whole concept of C programs etc, it might well be that I'm missing something that the experts would say "Well, OBVIOUSLY he's done this, that or the other". Don't bet on it!!

I downloaded luasql-master.zip but I'm not sure if I need to unzip/copy it to a specific luarocks (?) library.

I should point out that I can access a DB2 Express database on the same computer using Reginald Rexx and ODBC, so the ODBC availability shouldn't (?) be an issue, but maybe I DO need to copy some file to somewhere or other.

Any suggestions much appreciated (and I've googled until my eyes bleed, but all the questions people have appended seem to do with problems accessing any database AFTER they'd installed the relevant LuaSQL driver).

Added after more experimentation I tried running the install using the --verbose option. These are the relevant (?) results (I have the complete output saved on my desktop)

os.execute: C: & cd "C:\Users\Michael\AppData\Local\Temp\luarocks_luasql-odbc-2.4.0-1-209\luasql" & "C:\Program Files (x86)\LuaRocks/tools/mkdir.exe" -p "luasql" Results: 3 1 (boolean): true 2 (string): exit 3 (number): 0 C:\MinGW\bin\gcc.exe -shared -o luasql/odbc.dll src/luasql.o src/ls_odbc.o -Lc:/mingw -lodbc c:\program files (x86)\lua\5_3\bin/lua53.dll -lm

os.execute: C: & cd "C:\Users\Michael\AppData\Local\Temp\luarocks_luasql-odbc-2.4.0-1-209\luasql" & C:\MinGW\bin\gcc.exe -shared "-o" "luasql/odbc.dll" "src/luasql.o" "src/ls_odbc.o" "-Lc:/mingw" "-lodbc" "c:\program files (x86)\lua\5_3\bin\lua53.dll" "-lm" c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: cannot find -lodbc collect2.exe: error: ld returned 1 exit status Results: 3 1 (nil): nil 2 (string): exit 3 (number): 1

Error: Build error: Failed compiling module luasql/odbc.dll

While I assume Val is much more qualified that I am, I can't help thinking he (?) is off track with his comment about odbc.dll being missing. My impression is that odbc.dll will be created as a result of the install (or am I wrong?). My feeling is that something is missing in MinGw possibly ???

1
Forgot to mention (don't know it it's relevant). I added LUA_PATH_5_2 and LUA_CPATH_5_2 as windows system variables with the contents c:\program files (x86)\LUA\5_3\Bin - Michael Simpson
Can't give full answer, but there are some hints: you have lua 5.3, so LUA_***_5_2 must be LUA_***_5_3, luasql-master.zip is source code from GitHub (or seems so) and you don't need it (luarocks do that for you). As for your main error, compiler/linker can't find library odbc (odbc.dll I guess). Try to find out why by yourself (there are a lot of questions about it on SO). - val is still with Monica
Thank you Val. The 5_2 that I read about gave the IMPRESSION that you specified 5_2 for any Lua version >= 5_2. On another thread elsewhere, someone wrote that you HAVE to have installed MySql - could that be what's required (I haven't installed it)? - Michael Simpson
No. As I said, your current problem is that compiler can't find odbc.dll. You should find out why. - val is still with Monica
I'm wondering whether it isn't something else, in the sense that I'm running Windows 10, and there, the only odbc.dll file (in the system directory) is called odbc32.dll instead. I've tried copying it to various libraries as well as copying it and renaming it to odbc.dll, but so far nothing seems to help. Same message all the time. - Michael Simpson

1 Answers

0
votes

After loads of experimentation, I found something at https://www.progress.com/tutorials/odbc/connecting-to-hive-from-lua-using-an-odbc-driver.

After reading this, I thought, "what the heck" and tried the following:-

luarocks install odbc

This was my printout

C:>luarocks install odb
Installing https://luarocks.org/odbc-0.3.1-1.src.rock

C:\MinGW\bin\gcc.exe -O2 -c -o src/l52util.o -Ic:\program files (x86)\lua\5_3\include src/l52util.c -DUNIXODBC -DLUAODBC_EXPORTS -DLODBC_ERROR_AS_OBJECT -DLODBC_MIN_PAR_BUFSIZE=64 -I./include -Ic:/external/include C:\MinGW\bin\gcc.exe -O2 -c -o src/lcnn.o -Ic:\program files (x86)\lua\5_3\include src/lcnn.c -DUNIXODBC -DLUAODBC_EXPORTS -DLODBC_ERROR_AS_OBJECT -DLODBC_MIN_PAR_BUFSIZE=64 -I./include -Ic:/external/include C:\MinGW\bin\gcc.exe -O2 -c -o src/lenv.o -Ic:\program files (x86)\lua\5_3\include src/lenv.c -DUNIXODBC -DLUAODBC_EXPORTS -DLODBC_ERROR_AS_OBJECT -DLODBC_MIN_PAR_BUFSIZE=64 -I./include -Ic:/external/include C:\MinGW\bin\gcc.exe -O2 -c -o src/lerr.o -Ic:\program files (x86)\lua\5_3\include src/lerr.c -DUNIXODBC -DLUAODBC_EXPORTS -DLODBC_ERROR_AS_OBJECT -DLODBC_MIN_PAR_BUFSIZE=64 -I./include -Ic:/external/include C:\MinGW\bin\gcc.exe -O2 -c -o src/libopt.o -Ic:\program files (x86)\lua\5_3\include src/libopt.c -DUNIXODBC -DLUAODBC_EXPORTS -DLODBC_ERROR_AS_OBJECT -DLODBC_MIN_PAR_BUFSIZE=64 -I./include -Ic:/external/include C:\MinGW\bin\gcc.exe -O2 -c -o src/lodbc.o -Ic:\program files (x86)\lua\5_3\include src/lodbc.c -DUNIXODBC -DLUAODBC_EXPORTS -DLODBC_ERROR_AS_OBJECT -DLODBC_MIN_PAR_BUFSIZE=64 -I./include -Ic:/external/include C:\MinGW\bin\gcc.exe -O2 -c -o src/lstmt.o -Ic:\program files (x86)\lua\5_3\include src/lstmt.c -DUNIXODBC -DLUAODBC_EXPORTS -DLODBC_ERROR_AS_OBJECT -DLODBC_MIN_PAR_BUFSIZE=64 -I./include -Ic:/external/include C:\MinGW\bin\gcc.exe -O2 -c -o src/lval.o -Ic:\program files (x86)\lua\5_3\include src/lval.c -DUNIXODBC -DLUAODBC_EXPORTS -DLODBC_ERROR_AS_OBJECT -DLODBC_MIN_PAR_BUFSIZE=64 -I./include -Ic:/external/include C:\MinGW\bin\gcc.exe -O2 -c -o src/parlist.o -Ic:\program files (x86)\lua\5_3\include src/parlist.c -DUNIXODBC -DLUAODBC_EXPORTS -DLODBC_ERROR_AS_OBJECT -DLODBC_MIN_PAR_BUFSIZE=64 -I./include -Ic:/external/include C:\MinGW\bin\gcc.exe -O2 -c -o src/utils.o -Ic:\program files (x86)\lua\5_3\include src/utils.c -DUNIXODBC -DLUAODBC_EXPORTS -DLODBC_ERROR_AS_OBJECT -DLODBC_MIN_PAR_BUFSIZE=64 -I./include -Ic:/external/include C:\MinGW\bin\gcc.exe -shared -o odbc/core.dll src/l52util.o src/lcnn.o src/lenv.o src/lerr.o src/libopt.o src/lodbc.o src/lstmt.o src/lval.o src/parlist.o src/utils.o -Lc:/external -lodbc32 -lodbccp32 c:\program files (x86)\lua\5_3\bin/lua53.dll -lm odbc 0.3.1-1 is now installed in c:\program files (x86)\lua\5_3\ (license: MIT/X11)

Well, that was unexpected!!!.
Next test, let's see if I can connect to DB2 Express via ODBC from within Zerobrane.

Here's my code

odbc = require "odbc"
dbassert = odbc.assert
print("About to connect")
cnn = odbc.connect('DB2 Express', 'windows_userid', 'windows_pw')
if cnn == nil then
  print("Could not connect")
  return
else  
  print("Successful connection")
end

stmt = cnn:execute('SELECT count(*) FROM windows_userid.act')
print("After execute and select")

stmt:foreach(function(f1)
  i = i or 0
  i = i + 1
  print("After foreach i ",i)
  print("count ", f1, i);

end)
assert(stmt:closed()) -- foreach close cursor
assert(not stmt:destroyed()) -- statement valid  

... and the output from the script

About to connect
Successful connection
After execute and select
After foreach i 1
count 18 1

Now to actually try and learn Lua and then apply all this, but FINALLY, I'm on my way!!!