lunarmodules / luasql

LuaSQL is a simple interface from Lua to a DBMS.
http://lunarmodules.github.io/luasql
535 stars 192 forks source link

Unix Socket Support for mysql #72

Closed lal12 closed 6 years ago

lal12 commented 7 years ago

I needed, support for unix socket connection, so I added it. But it would be a nice feature for others, too. I simply changed in file ls_mysql.c in func env_connect at line 489:

    const char *sourcename = luaL_checkstring(L, 2);
    const char *username = luaL_optstring(L, 3, NULL);
    const char *password = luaL_optstring(L, 4, NULL);
    const char *host = luaL_optstring(L, 5, NULL);
    const char *unixsocket = NULL;
    const char *localhost = "localhost";
    if(host[0] == '/'){
            unixsocket = host;
            host = localhost;
    }
    const int port = luaL_optinteger(L, 6, 0);

and at line 509

    if (!mysql_real_connect(conn, host, username, password,
            sourcename, port, unixsocket, 0))
    {

Of course a nicer implementation would be preferable, also there had to be an #ifdef WIN32 or simular to check for the current OS.

lal12 commented 7 years ago

Please delete, I just saw there is already a pull request.