FredyH / MySQLOO

MySQLOO
GNU Lesser General Public License v2.1
138 stars 55 forks source link

tmysql wrapper is outdated #5

Closed R4K0 closed 7 years ago

R4K0 commented 7 years ago

Wrapper seems to be outdated, since it doesn't fully support the newest tmysql. Detected upon installing Prometheus from Garry's Mod store, mysqloo has been installed alongside with the wrapper. Upon talking with developer of Prometheus he directed me here, explaining why this is happening SetCharacterSet doesn't seem to exist thus breaks compatibility with Prometheus. Upon uninstalling the wrapper everything worked.

[ERROR] addons/prometheus/lua/prometheus/database.lua:68: attempt to call method 'SetCharacterSet' (a nil value)
  1. Callback - addons/prometheus/lua/prometheus/database.lua:68
   2. Connect - addons/prometheus/lua/prometheus/tmysql.lua:10
    3. Connect - addons/prometheus/lua/prometheus/database.lua:77
     4. fn - addons/prometheus/lua/prometheus/init.lua:181
      5. unknown - addons/ulib/lua/ulib/shared/hook.lua:109
FredyH commented 7 years ago

Yeah I think I forgot that one. Can you maybe post the code where it calls that function, so I can see what the function does? The documentation for tmysql unfortunately doesn't exist anymore :S

R4K0 commented 7 years ago

Yep I just got permission from one of the script devs to post a part of their code here, so there you go:

The documentation for tmysql unfortunately doesn't exist anymore :S

I wonder why is that ;)

Note: tmysqlSucc is true when successful connection has been established using tmysql module, if not, then it tries to default to mysqloo - Script prefers tmysql at this moment (Dev mentioned that they have to change that)

function Prometheus.DB.Connect()
    Prometheus.Debug("Connecting to database.")

    if Prometheus.DB.ModuleFail then return end

    local function LCallback(Err)
        if Err then
            Prometheus.DB.StopQueue(P_DB_CONNECTED)
            Prometheus.Error("DB Connection failed! Error msg: " .. Err, true, "DBConnect")
        else
            Prometheus.DB.StartQueue(P_DB_CONNECTED)
            Msg("[Prometheus] DB Connection succesful\n")
            Prometheus.Debug("Connected to database successfully.")
            Prometheus.RemoveRepeat("DBConnect")
            hook.Run("PrometheusDBConnected")
            if tmysqlSucc then
                Prometheus.DB.Module.DB:SetCharacterSet("utf8")
                Prometheus.DB.GetSettings()
            else
                Prometheus.DB.Query("SET NAMES utf8", function() Prometheus.DB.GetSettings() end)
            end
        end

    end

    Prometheus.DB.Module.Connect(LCallback)
end
Kefta commented 7 years ago

tmysql4 docs can still be found here: https://lab.facepunch.com/gmoddons/cv1r/tmysql4_a_multi_connection_version_of_tmysql3_now_with_mysqloo_wrapper_/page/1 https://github.com/bkacjios/gm_tmysql4/blob/master/README.md

Looks like it was never documented in the first place.

SetCharacterSet C++ code: https://github.com/bkacjios/gm_tmysql4/blob/835ca867fd7c14d133c2bd3beace832e3d8d3051/src/database.cpp#L145-L165

FredyH commented 7 years ago

This should work now, you need to get the latest version of the wrapper and the binary module.