tmysql4 - A multi-connection version of tmysql3 (Now with mysqloo wrapper!)

Dead module, find another.

Nice to see you and the module back, but as far as I can tell from the source it still lacks multiple
result sets. Any chance of that getting added?

Please update documentation:
tmysql.Initialize -> tmysql.initialize

Experimal support for this module has been added to MySQLite:

And the net change is only 15 added lines :smiley:

MySQLite is an abstraction mechanism I use in FPP and DarkRP. Regardless of whether the end user decides to use SQLite, MySQLOO or tmysql4, the interface of MySQL remains the same. It’s very useful.

I haven’t merged it with FPP and DarkRP yet because I want people to test it :slight_smile:

I take it tmysql4 is better than MySQLOO then looking at the comparisons. I’ve never had a crash with MySQLOO in years of using it though, can’t understand why people are having these issues.

Alright, Giraffen93 helped me find a bug: everything is a string.



] lua_run MySQLite.query("SELECT * FROM darkrp_player LIMIT 1", function(a) PrintTable(a) for k,v in pairs(a[1]) do print(k, type(v)) end end, print)
> MySQLite.query("SELECT * FROM darkrp_player LIMIT 1", function(a) PrintTable(a) for k,v in pairs(a[1]) do print(k, type(v)) end end, print)...
1:
		rpname	=	(FPtje) Falco
		salary	=	45
		uid	=	2044737759
		wallet	=	12540
rpname	string
salary	string
uid	string
wallet	string



The darkrp_player table looks like this:

This is the output when using MySQLOO:



] lua_run MySQLite.query("SELECT * FROM darkrp_player LIMIT 1", function(a) PrintTable(a) for k,v in pairs(a[1]) do print(k, type(v)) end end, print)
> MySQLite.query("SELECT * FROM darkrp_player LIMIT 1", function(a) PrintTable(a) for k,v in pairs(a[1]) do print(k, type(v)) end end, print)...
1:
		rpname	=	(FPtje) Falco
		salary	=	45
		uid	=	2044737759
		wallet	=	12585
rpname	string
salary	number
uid	string
wallet	number


Please fix this, I don’t want to try to cast everything to int in MySQLite.

It’s not really a bug, that’s just what tmysql has always done, but I’ll see if I can change it.

[editline]18th December 2014[/editline]

I think I got it.

[cpp]if (row* == NULL)
LUA->PushNil();
else if (field->type == MYSQL_TYPE_DECIMAL ||
field->type == MYSQL_TYPE_NEWDECIMAL ||
field->type == MYSQL_TYPE_FLOAT ||
field->type == MYSQL_TYPE_DOUBLE ||
field->type == MYSQL_TYPE_TINY ||
field->type == MYSQL_TYPE_SHORT ||
field->type == MYSQL_TYPE_INT24 ||
field->type == MYSQL_TYPE_BIT ||
field->type == MYSQL_TYPE_LONG)
LUA->PushNumber(atof(row*));
else
LUA->PushString(row*);[/cpp]

Am I missing anything? MySQL data types are so weird.

[editline]18th December 2014[/editline]

Well, I updated the downloads to have it convert the value into a number if the field type is one of those types above. The repo has been updated too.

Does this fix sql errors not showing up as well?

Edit: No it does not.

In your Example:

[lua]local function onPlayerCompleted( ply, results, status, error )[/lua]

Should be:

[lua]local function onPlayerCompleted( results, ply, status, error )[/lua]
After my testing.

Dude, I love you x10

miles better than mysqloo, thank you. we’ve needed a decent mysql module for a while.

That’s a bug then, the object should come first so you can call methods that use self. I fixed this and uploaded new dlls.

[editline]20th December 2014[/editline]

Yes it does.

how would one go to check the status of the connection, like mysqloo with its status()?

edit: also, since this doesn’t seem to have something like lastInsert() like mysqloo, does anyone know how I should go by this issue? I’m trying to convert a sourcebans module, but I’m unsure as to how I would find the most recent ban id without something like lastInsert().

nvm, went a different way. discovered it isn’t even needed, but having lastInsert() or something like this on tmysql4 would probably be useful.

still wondering though what are some ways I could go by using some type of status() when checking a connection.

great module btw

[nevermind, I’m wrong]

There’s really no need for it. The module will automatically try to reconnect and attempt the query again if the connection fails for some reason. Please see point number 3 in AzuiSleet’s post. Plus, there’s actually two connections being made per Database object.

Use QUERY_FLAG_LASTID

This will cause the error argument in the callback to be the last id inserted.

Example:
[lua]Database:Query(“INSERT INTO members VALUES(‘Something’, 23, ‘other stuff’)”, function(results, status, lastid)
print(“ID was”, lastid)
end, QUERY_FLAG_LASTID)[/lua]

What library does the linux version of tmysql4 require?
[lua]
> require(“tmysql4”)…

[ERROR] lua_run:1: Couldn’t load module library!
[/lua]

The only dependency it should need is libmysqlclient.so

You can run ldd on it to see what you are missing.


ldd gmsv_tmysql4_linux.dll
        linux-gate.so.1 (0xb7714000)
        libmysqlclient.so.18 => /usr/lib/i386-linux-gnu/libmysqlclient.so.18 (0xb73ba000)
        libstdc++.so.6 => /usr/lib/i386-linux-gnu/libstdc++.so.6 (0xb72c8000)
        libm.so.6 => /lib/i386-linux-gnu/i686/cmov/libm.so.6 (0xb7281000)
        libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xb7264000)
        libc.so.6 => /lib/i386-linux-gnu/i686/cmov/libc.so.6 (0xb70b9000)
        /lib/ld-linux.so.2 (0xb7717000)
        libpthread.so.0 => /lib/i386-linux-gnu/i686/cmov/libpthread.so.0 (0xb709d000)
        libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xb7080000)
        libdl.so.2 => /lib/i386-linux-gnu/i686/cmov/libdl.so.2 (0xb707a000)

It doesn’t seem to catch errors from stored procedures.

Scratch that, it does error on normal queries, but gives this error instead -

http://teddi.eu/ss/2014-12-21_00-47-05.png

(just throwing out there when queries are successful it does return 0 and data is returned)

The commands out of sync error means that the client did not handle result sets correctly. It is because the module only expects a single result set, but most mysql CALLs produce more than that. tmysql only handles the first, and leaves the rest there, causing an error. There is even a full chapter about that in the mysql docs

Which is problematic as I’m only returning 1 result set :). This only happens if the query has an error - think invalid syntax. It doesn’t happen with queries that are actually functioning as intended (or procedures).

(I have read the mySQL docs which is why I’m flagging this as an error and not an issue on my side).