lunarmodules / luasql

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

odbc can not receive data from mssql , after win10 update #148

Open lingbl opened 1 year ago

lingbl commented 1 year ago

lua 5.1 , luasql 2.6.0 , can not receive data from mssql , when win10 installed patch KB5019959. win10 version: 19044.2251 no error message data = cur:fetch({})

i have try to uninstall KB5019959, and luasql work again. The problem is file c:\windows\SysWOW64\sqlsrv32.dll is updated by patch. when use old version dll file to replace , luasql work again

lingbl commented 1 year ago

I compile luasql in mysys2 mingw32, should I use visual studio ???

lingbl commented 1 year ago

I replace float by varchar(20) in database, the luasql can work properly

https://learn.microsoft.com/en-us/answers/questions/1091666/kb5019959-sqlserver-instruction-isnullamount0-some.html

lingbl commented 1 year ago

SQLcmd = "select Week from Production_2011 where Production_LOTNO = '20221123N7E'"

luaopen_luasql_odbc()... create_metatables()... create_environment()... env_connect()... create_connection()... conn_execute()... conn_prepare()... desc_params()... raw_execute()... create_cursor()... create_colinfo()... sqltypetolua()... type:6 sqltypetolua(): number cur_fetch()... getcursor()... SQLFetch()... cur_fetch():num 1 cur_fetch():alpha 0 push_column()... pushcolumn(): nUmber SQLGetData()...               / FAIL AT HERE /_ fail()... fail():SQLGetDiagRec()... fail(): [Microsoft][ODBC SQL Server Driver] Unknown token received from SQL Server fail():SQLGetDiagRec()... fail(): SQL_NO_DATA cur_close()... cur_shut()... stmt_shut()... free_stmt_params()... stmt_close()... conn_close()... env_close()...

Exit code: 1

Anyone can help meeeeeeeeeeeee !

lingbl commented 1 year ago

Use float instead of double, that too small !

/ deal with data according to type / switch (type) { / nUmber / case 'u': { printf("push_column(): nUmber\n"); /SQLDOUBLE num; / float num; SQLLEN got;

        printf("SQLGetData()...\n");
        /*SQLRETURN rc = SQLGetData(hstmt, i, SQL_C_DOUBLE, &num, 0, &got);*/
        SQLRETURN rc = SQLGetData(hstmt, i, SQL_C_FLOAT, &num, 0, &got);

        if (error(rc))
            return fail(L, hSTMT, hstmt);

        if (got == SQL_NULL_DATA)
            lua_pushnil(L);
        else
            lua_pushnumber(L, num);
        printf("push_column(): num: %f \n", num);
        return 0;
    }
tomasguisasola commented 1 year ago

Hi lingbl

I don't have a Windows machine nor the SQL Server to test it, sorry.

I didn't understand why you replaced a double by a float -- or did I misunderstood you attempt above? A double is bigger than a float...

Did you try to print out the value of variable 'tname'? Maybe there is another type not foreseen...

Regards, Tomás

lingbl commented 1 year ago

the luasql can get data "Week" correctly , when use SQL_C_FLOAT , by the way this is not my idea https://stackoverflow.com/questions/74447805/sqlgetdata-doesnt-work-in-the-same-way-after-install-kb5019959 https://stackoverflow.com/questions/74451813/unknown-token-received-from-sql-server-error-just-started-happening-on-windows?r=SearchResults&s=3%7C21.8408

The data "Week" store in MSSQL as "float" type . The bug is: all "float" type data in MSSQL can not recieve by luasql.

tomasguisasola commented 1 year ago

Hi lingbl

This problem with float X double does not seem to be a bug in LuaSQL, but in MSSQL, don't you agree? The documentation assure all C types must be supported:

https://learn.microsoft.com/en-us/sql/odbc/reference/appendixes/c-data-types?view=sql-server-ver16

Anyway, it is obvious that we can change the type of variable num from double to float, but will that change produce other incompatibilities?

Regards, Tomás

lingbl commented 1 year ago

Thank you Tomás !! , If this is a bug from patch, I will wait next patch to fix it.
Change "float" type to "numeric(18, 6)" in MSSQL may be a way to skip this bug.

lingbl commented 1 year ago

Install microsoft odbc driver , and reset DSN.

lingbl commented 1 year ago

https://github.com/qgis/QGIS/issues/50865#issuecomment-1314973751

syslog-dw commented 1 year ago

We are experiencing the same issue in production. Will report back if updating the ODBC driver on the client side helps or if another solution (other than rolling back the Windows update) is found.

syslog-dw commented 1 year ago

As far as I'm concerned, updating the MSSQL ODBC Driver on the client fixes or works around this issue.