-1

I am trying to connect to a mysql server using LuaSql via a mysql proxy. I try to execute a simple program (db.lua):

require("luasql.mysql")
local _sqlEnv = assert(luasql.mysql())
local _con = nil

function read_auth(auth)
local host, port = string.match(proxy.backends[1].address, "(.*):(.*)")
_con = assert(_sqlEnv:connect( "db_name", "username", "password", "hostname", "3306"))
end 

function disconnect_client()
assert(_con:close())
end 

function read_query(packet)
local cur = con:execute("select * from t1")
myTable = {}
row = cur:fetch(myTable, "a") 
print(myTable.id,myTable.user)
end

This code executes well when I execute it without mysql-proxy. When I am connecting with mysql-proxy, the error-log displays these errors:

mysql.lua:8: bad argument #1 to 'insert' (table expected, got nil) db.lua:1: loop or previous error loading module 'luasql.mysql'

mysql.lua is a default file of LuaSql:

---------------------------------------------------------------------
-- MySQL specific tests and configurations.
-- $Id: mysql.lua,v 1.4 2006/01/25 20:28:30 tomas Exp $
---------------------------------------------------------------------

QUERYING_STRING_TYPE_NAME = "binary(65535)"

table.insert (CUR_METHODS, "numrows")
table.insert (EXTENSIONS, numrows)

---------------------------------------------------------------------
-- Build SQL command to create the test table.
---------------------------------------------------------------------
local _define_table = define_table
function define_table (n)
        return _define_table(n) .. " TYPE = InnoDB;"
end

---------------------------------------------------------------------
-- MySQL versions 4.0.x do not implement rollback.
---------------------------------------------------------------------
local _rollback = rollback
function rollback ()
        if luasql._MYSQLVERSION and string.sub(luasql._MYSQLVERSION, 1, 3) == "4.0" then
                io.write("skipping rollback test (mysql version 4.0.x)")
                return
        else
                _rollback ()
        end
end
luchaninov
  • 6,792
  • 6
  • 60
  • 75
robin
  • 19
  • 1
  • 10
  • What does this mean: "connecting with mysql-proxy"? Is this a module? A script? How do you use it? – Oliver Jul 05 '14 at 01:15
  • @Schollii it is a lua script(db.lua) that i specify in my mysql-proxy.cnf file of mysql proxy.I use it through mysql proxy to access mysql server from mysql-proxy..Am i clear? – robin Jul 05 '14 at 03:57
  • Based on the [mysql-proxy docs](http://dev.mysql.com/doc/refman/5.0/en/mysql-proxy-scripting-read-query.html) and the code you posted I am guessing that you are trying to script mysql-proxy rather than connect to a mys1l server through a mysql proxy. In that case what do you mean by "executes well when i execute them without myql-proxy". The error you get means that the proxy does not create the CUR_METHODS table. What makes you think that creating a db connection from within the proxy is allowed? – Oliver Jul 05 '14 at 06:49
  • @Schollii What i mean by "executes well when i execute them without myql-proxy" is i can connect to mysql database using LuaSql,but i am unable to connect the same with mysql-proxy.Is it possible to connect mysql server via mysql-proxy? P.S: Now i have made some changes in the code..So please check it now – robin Jul 19 '14 at 05:04
  • @Schollii i also have another doubt is it possible to use luasql script through mysql proxy? – robin Jul 19 '14 at 05:05

1 Answers1

1

As stated in my previous comment, the error indicates that table.insert (CUR_METHODS, ...) is getting a nil as first arg. Since the first arg is CUR_METHODS, it means that this object CUR_METHODS has not been defined yet. Since this happens near top of the luasql.mysql module, my guess is that the luasql initialization was incomplete, maybe because the mysql DLL was not found. My guess is that the LUA_CPATH does not find the MySQL DLL for luasql, but I'm surprised that you wouldn't get a package error, so something odd is going on. You'll have to dig into the luasql module and C file to figure out why it is not being created.

Update: alternately, update your post to show the output of print("LUA path:", package.path) and print("LUA path:", package.cpath) from your mysql-proxy script and also show the path of folder where luasql is installed and contents of that folder.

Oliver
  • 27,510
  • 9
  • 72
  • 103
  • but mysql.so is present at a particular.I specified that path in the mysql-proxy.cnf for LUA_CPATH.But still the same error. – robin Jul 21 '14 at 04:30
  • 1
    @robin you accepted this answer, but your last comment indicates still problem, can you clarify what is actual status? – Oliver Jul 21 '14 at 12:40
  • the status is that the same error prevails even after changing the LUA_CPATH. – robin Jul 22 '14 at 03:46
  • i got it the actual mistake is in including the right LUA_CPATH in the mysql-proxy config file.It works well now :) Thanks for your help. – robin Jul 23 '14 at 04:59