ID:63983
 
BYOND Version:438
Operating System:Windows XP Home
Web Browser:Firefox
Video Card:
Component:Dream Maker
Game/Hub:
Status: Deferred

This issue may be low priority or very difficult to fix, and has been put on the back burner for the time being.
Descriptive Problem Summary:
DBQuery errors on a multi-statement query. ErrorMsg() returns that there is an error in the syntax for the query, specifically the beginning of the 2nd statement.

Numbered Steps to Reproduce Problem:
Create a MySQL database called TestDB on localhost.
Create a user called DMTest with the password of testing with create privileges on that database.
Make a new DBConnection to the database and a new DBQuery from the connection and a multi-statement sql statement. Execute the query and use DBQuery.ErrorMsg() to read the error returned. I suggest using/modifying the snippet below.

Code Snippet (if applicable) to Reproduce Problem:
mob/verb/DBTest()
var/DBConnection/DBCon = new("dbi:mysql:TestDB:localhost:3306","DMTest","testing")
//change TestDB to your DB name, localhost to the server name, and 3306 to your server's port
//change DMTest to a user with create permissions on the DB, and testing to that user's password
if(!DBCon.IsConnected()) DBCon.Connect()
var/DBQuery/query = DBCon.NewQuery({"
DROP TABLE IF EXISTS `TestDB`.`TestTable`;
CREATE TABLE `TestDB`.`TestTable` (
`field1` INT(10),
`field2` VARCHAR(255),
) ENGINE=InnoDB DEFAULT CHARSET=latin1;"}
)
query.Execute()
usr<<query.ErrorMsg()


Expected Results:
Successful execution of the query.

Actual Results:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE `TestDB`.`TestTable` (
`field1` INT(10),
`field2` VARCHAR(25' at line 2

Does the problem occur:
Every time, without fail.

When does the problem NOT occur?
Never, without workarounds (see blow).

Workarounds:
I have started pre-parsing my queries and generating new DBQuery objects for each statement with the assumption the the ";" character signifies the end of a statement.

-------------

The query will work fine if run through the MySQL Query Browser. I have not tried the command line but I imagine that if I were to save the query to a file and try it would work just fine. I don't know if DM's built in DB handling strips queries of the ";" character or what. It seems the most logical conclusion based on the present evidence and the error message returned. The only way that the query would work in a usual MySQL environment but give the syntax error for DM is if DM is changing the syntax in some way. Perhaps this is done because of the way ErrorMsg() handles the error reports?
Setting CLIENT_MULTI_STATEMENTS in libmysql should resolve this problem.
Nadrew wrote:
Setting CLIENT_MULTI_STATEMENTS in libmysql should resolve this problem.

Can I assume that's an internal variable in the code underlying Dream Maker? Or am I blind and didn't notice the libmysql library?
CriticalBotch wrote:
Nadrew wrote:
Setting CLIENT_MULTI_STATEMENTS in libmysql should resolve this problem.

Can I assume that's an internal variable in the code underlying Dream Maker? Or am I blind and didn't notice the libmysql library?


libmysql is the name of the library BYOND itself uses to hook into MySQL. The change I mentioned would be done in the internals of the system.

Nadrew wrote:
CriticalBotch wrote:
Nadrew wrote:
Setting CLIENT_MULTI_STATEMENTS in libmysql should resolve this problem.

Can I assume that's an internal variable in the code underlying Dream Maker? Or am I blind and didn't notice the libmysql library?


libmysql is the name of the library BYOND itself uses to hook into MySQL. The change I mentioned would be done in the internals of the system.

That's what I figured, but wanted to make sure :) Thanks for the update.
Once again I'd like to note that enabling CLIENT_MULTI_STATEMENTS alone will leave MySQL support in an almost equally lacking state. We'll need a way to call mysql_next_result(query), or we won't be able to step through the result sets.
I've more or less replicated this function with my own database library I'm working on by creating a meta-query handler, which mimics the functions of DBQuery while storing and accessing many DBQuery objects (one per statement in the SQL statement).

While this is a sufficient and transparent (on the end-user side) way of doing this, it'd be nice to indeed have access to the ability built in. If nothing else it'll save on the datum limits. It may not be much, but any place you can save on limits is a good thing, in my opinion.

Alathon wrote:
Once again I'd like to note that enabling CLIENT_MULTI_STATEMENTS alone will leave MySQL support in an almost equally lacking state. We'll need a way to call mysql_next_result(query), or we won't be able to step through the result sets.
while(query.NextRow()) already does this.
I was referring to usage when dealing with multi-statement queries. My work-around essentially increments through the DBQuery objects held in the Query handler object and returns it.

Currently there are two such functions, one to increment and one to decrement.

Nadrew wrote:
while(query.NextRow()) already does this.

While enabling CLIENT_MULTI_STATEMENTS is trivial, as Alathon noted, the implementation is incomplete without a way to step through the results (in mysql, mysql_next_result() as well as some supporting memory functions). This involves adding functionality to the DB layer (mysql being just one of many potential databases that can be "plugged in" in this model).

Since this is a bit of work and the problem isn't a showstopper, I am deferring this for the time being.