Game Development Community

MySQL support for Torque Engine

by AIDan · in Torque Game Engine · 11/25/2001 (11:18 am) · 62 replies

Hi,

this is the first version of the MySQL support for the Torque Engine. It's a simple news script base on MySQL 1.7.1 database server.

We want to implement it directly in the SDK... may we?

Here are the screenshots and the script:

www.futureint.de/

cu
Felix
#21
08/11/2002 (5:34 pm)
When Compiling i get this error:

mysql.obj : error LNK2001: unresolved external symbol _mysql_free_result@4
mysql.obj : error LNK2001: unresolved external symbol _mysql_error@4
mysql.obj : error LNK2001: unresolved external symbol _mysql_real_connect@32
mysql.obj : error LNK2001: unresolved external symbol _mysql_close@4
mysql.obj : error LNK2001: unresolved external symbol _mysql_query@8
mysql.obj : error LNK2001: unresolved external symbol _mysql_store_result@4
mysql.obj : error LNK2001: unresolved external symbol _mysql_num_rows@4
mysql.obj : error LNK2001: unresolved external symbol _mysql_fetch_row@4
mysql.obj : error LNK2001: unresolved external symbol _mysql_num_fields@4
mysql.obj : error LNK2001: unresolved external symbol _mysql_fetch_field_direct@8
mysql.obj : error LNK2001: unresolved external symbol _mysql_field_count@4
mysql.obj : error LNK2001: unresolved external symbol _mysql_insert_id@4
mysql.obj : error LNK2001: unresolved external symbol _mysql_init@4
mysql.obj : error LNK2001: unresolved external symbol _mysql_shutdown@4
../example/torqueDemo_DEBUG.exe : fatal error LNK1120: 14 unresolved externals

Does anyone know how to fix this?

Thanks,

-Stuart
#22
08/12/2002 (3:22 am)
@Stuart Campbell,

From the looks of the error, it appears that you do not have the library libmySQL.lib included in your link step. You can check/add the library by following the below steps in Visual Studio:

1) Right click on Torque Demo files and select Settings from the pop-up menu
2) In the Settings For drop-down combo box select either Win32 Release or Win32 Debug depending upon which target you are making. NOTE: you will need to make the changes in both the Release and Debug settings if you are building both versions
3) Click on the Link tab (right side of the dialog box)
4) In the Category drop-down combo box select Input
5) In the Object/library modules entry field, add libmySQL.lib to the end of the line. Do not forget to add a space after the last library listed and libmySQL.lib
6) In the Additional library path entry field, add ,../../mysql/lib/opt to the end of the line. NOTE: you will need to modify the relative path based upon where you have installed MySQL

Rich

[edit]
Fixed my poor grammar.
[/edit]
#23
08/12/2002 (9:21 pm)
Well it just compiled =)..

Thank you Richard, without you help id still be fumbling my way around the IDE.

Its great to see a community that is willing to help others when they get stuck ( even if the problem is embarrasingly simple :) ).
#24
08/12/2002 (9:43 pm)
MySQL can readily be access from Python... which I am currently hooking up to Torque... This is how I will be using MySQL...

Good work on this stuff... if I do need to have C++ support, I will be glad this is around...

-J
#25
08/17/2002 (5:20 pm)
Hi!
Im having a problem with the MySQL plugin...
I've succesfully created a database with MySQL on my computer called: "Accounts". But everytime I try to run my app I get a console-error telling me that it can't connect to my MySQL server. I dosent get it!? I've both tried my computers local ip, and just writing "localhost". What should I do? Can it only open databases created on another computer?
#26
08/18/2002 (9:38 am)
@Mikkel,

Without seeing you Accounts database layout, I threw together a quick database and script to test connecting/disconnecting to a local database. All of this was tested under Windows 2000 using MySQL version 3.23.49-nt.

First I created a database called Accounts and assigned you privileges. This was done via the console program mysql. Below are the SQL commands that I used:
- create database Accounts;
- GRANT SELECT,INSERT,UPDATE,DELETE,INDEX,ALTER,CREATE,DROP,REFERENCES ON Accounts.* TO mikkel@localhost IDENTIFIED BY 'hempel';
- flush privileges;
- quit;
I then took the script mysqltest.cs and modified it to only connect/disconnect to the Accounts database. Below is the script:
// NEVER USE THE OBJECT AS GLOBAL ONE
// SOMEONE COULD RETRIEVE THE PASSWORD, THEN!!!

function MySQLtest()
{
    // ----------------------------------------------------
    %mysqltest = new MySQL();

   // ----------------------------------------------------
   // set host info

//   %mysqltest.host = "192.168.1.100";    // default: "localhost"
//   %mysqltest.port = 6660;               // default: 3306

   // user information
   %mysqltest.user = "mikkel";           // NO default!
   %mysqltest.pwd  = "hempel";           // default: ""

   // connection flags
   %mysqltest.flag_compress = false;     // default: false
   %mysqltest.flag_ssl      = true;      // default: false

   // database to use
   %mysqltest.db = "Accounts";           // NO default!

   // ----------------------------------------------------
   %mysqltest.ValidateSettings();        // optional

   %mysqltest.Connect();

   %mysqltest.Close();
}

MySQLtest();
NOTE: As you can see from the above script, I have commented out the setting of the variables host and port as I want to use the defaults.
I then executed the above script from the console using the below command:
exec("fps/database/mysqltest.cs");
I did not have any problems connecting/disconnecting to the database.

I would recommend that you download MySQL-Front and attempt to connect to the Accounts database to eliminate any setup errors.

Rich
#27
08/18/2002 (10:27 am)
@Richard

Wow thanks!!!
Now it works! My only fault was that I'd not given my self permission to connect to the database.

Thx!

-Roq-
#28
08/19/2002 (8:29 am)
You also might want to take a look at the stuff I posted for ODBC access, as that lets you work with mySQL as well as MS SQL Server, Oracle, and just about every other database out there.

You can find it here

Josh
#29
08/19/2002 (1:47 pm)
I think I've done everything that the instructions say (included "libmysql.lib" in Project->Settings->Link,added TORQUE\ENGINE\GAME\MYSQL\MYSQL to my include files and \TORQUE\ENGINE\GAME\MYSQL\MYSQL\LIB to my libraries files), but I still get:
E:\Images\torque\engine\game\mysql\mysql.h(15) : fatal error C1083: Cannot open include file: 'mysql_1.7.1/include/mysql.h': No such file or directory
mysql_cs.cc
E:\Images\torque\engine\game\mysql\mysql.h(15) : fatal error C1083: Cannot open include file: 'mysql_1.7.1/include/mysql.h': No such file or directory
Error executing cl.exe.
The 'mysql_1.7.1/include' definately doesn't exist, but I suppose thats where the libmysql.lib comes in....?
Any ideas???
#30
08/19/2002 (2:42 pm)
@Stefan,

From the error that you are getting it appears that you have not specified the correct path to the mysql.h file. The below steps should correct the problem:

1) Right click on Torque Demo files and select Settings from the pop-up menu
2) In the Settings For drop-down combo box select either Win32 Release or Win32 Debug depending upon which target you are making. NOTE: you will need to make the changes in both the Release and Debug settings if you are building both versions
3) Click on the C/C++ tab (right side of the dialog box)
4) In the Category drop-down combo box select Preprocessor
5) In the Additional include directories entry field, add ,../../mysql/include to the end of the line. NOTE: you will need to modify the relative path based upon where you have installed MySQL

Make sure that the #include for the mysql.h file in fimysql.h is set to:
[b]#include "mysql.h"[/b]
Rich

PS Love the work you did on JEdit!

[edit]
Fixed broken URL.
[/edit]
#31
08/19/2002 (9:54 pm)
Thanks, Rich,
but I still get this same error...
I still don't get it how it is supposed to find
#include "mysql_1.7.1/include/mysql.h"
if this path doesn't exist...
(I've also tried
#include "mysql/include/mysql.h"
and
#include "mysql/mysql.h")

I've added the downloaded files in the "torque/lib/mysql" and "torque/lib/mysql/lib" dirs, and like you said, I've included ",../lib/mysql," (I've also tried ",../lib/mysql/include," although there is no include dir) to the additional directories entry...

And I still got both dirs in my global include and lib setttings...
what more can I do???

P.S. Glad you like JEdit... :)
#32
08/20/2002 (3:40 am)
Sorry about that Stefan, I should have taken more time to read over the error.

In order for you to have the MySQL includes and libraries, you will need to install MySQL for Windows. Now this can be a problem especially if you have several developers. The below steps should get you and any one else you are working with up and running:

1) I made you a little Zip of only the Windows includes and libraries. Click here to download
2) Unzip the above file to your root Torque directory. The Zip file contains the fully qualified path lib/mysql/, so it will expand correctly to the Torque library directory
3) While you are making the changes in Step 4 below, remove the MySQL directories that you previously added
4) Modify the below project settings to use the new lib/mysql/ directory for the includes and libraries:
[b]C/C++->Preprocessor:[/b] In the [b]Additional include directories[/b] entry field, add [b],../lib/mysql/include[/b] to the end of the line
[b]Link->Input:[/b]: In the [b]Object/library modules[/b] entry field, add [b]libmySQL.lib[/b] to the end of the line
[b]Link->Input:[/b]: In the [b]Additional library path[/b] entry field, add [b],../lib/mysql/lib/opt[/b] to the end of the line
5) Copy the file lib\mysql\lib\opt\libmySQL.dll to your Torque root directory\example directory

The Windows includes and libraries are based on MySQL version 3.23.49-nt. Depending upon which version of MySQL you are using, they may or may not work. If your version of MySQL is close to 3.23.49, you should not run into any problems.

Rich
#33
08/20/2002 (3:47 am)
thanks again, Rich!!
I really appreciate your efforts to help me out here! :)
I'll try it as soon as I get home (although I still got like 5 hrs to work... :-/)
I'll let you know if it works!
... /ME still wonders why it works for all the other people here - the way it is explained on the futureint website does definatley NOT work...
#34
08/20/2002 (4:05 am)
You are welcome Stefan. I am just sorry that I lead you down the wrong path yesterday.

I am based in New York, so I will still be working when you get home today. I will monitor this thread to see if you where able to get it complied.
#35
08/20/2002 (9:33 am)
Rich, I can't believe it, I still get this error:
E:\Images\torque\engine\game\mysql\mysql.h(16) : fatal error C1083: Cannot open include file: 'mysql_1.7.1/include/mysql.h': No such file or directory
mysql_cs.cc
E:\Images\torque\engine\game\mysql\mysql.h(16) : fatal error C1083: Cannot open include file: 'mysql_1.7.1/include/mysql.h': No such file or directory
could you please check your mysql.h file to see what you have there as include path?
Thanks a lot!! :-)
#36
08/20/2002 (10:55 am)
Stefan,

You getting the same error puzzle me. If you look at the mysql.h in the Zip file, there are no references to mysql_1.7.1/include.

Check the file game/mysql/fimysql.h and make sure the include for mysql.h is:

#include "mysql.h"

If everything looks good, Zip up and email me the below files:

game\mysql\fimysql.h
engine\game\mysql\mysql.cc
game\mysql\mysql_cs.cc
vc6\Torque Demo.dsp

Rich
#37
08/20/2002 (12:21 pm)
Rich, now I got it!! :)
The problem was that my file wasn't called "fimysql.h", it was simply called "mysql.h"...
and I really had this strange include ("mysql_1.7.1/...") in there...
and if I changed this include statement to simply "mysql.h" (the one in "../lib/.../inlcude") it would try to include itself ("game/mysql/...") and gave me like 78 errors... :p

So the solution was to RENAME the "game/mysql/mysql.h" to a different name ("fimysql.h" e.g.) and change the include directive to "#include mysql.h"...
that's all, now it works as a charm!!!
So the instructions on the futureint website are totally wrong, the #include directive is wrong and the header file should be named differently...
I really wonder how all the other guys here managed to get it running with all these problems...
Anyhow, thanks again for your help!! :-))
#38
08/21/2002 (4:03 am)
Stefan,

It has been a long time since I integrated the MySQL code, that I completely forgot about changing the name of the mysql.h file to fimysql.h to correct the problem you found. I just diffed my version against the one on Futureint Website. I made the below changes to circumvent the Access Violation you will get if you call GetRowCell with a column name that is not in the table:

Replace the entire function StringTableEntry MySQL::GetRowCell (S32 _iResult, StringTableEntry _sFieldName) (around line # 337) in module game\mysql\mysql.cc with the below:
StringTableEntry MySQL::GetRowCell (S32 _iResult, StringTableEntry _sFieldName)
{
    MYSQL_RES   *pRes;
    MYSQL_FIELD *pField;

    MySQLGetResultEx (pRes, 0);

    // Go through all of the fields
    for (U32 i = 0; i < pRes->field_count; i++)
        {
        // Get a field
        pField = mysql_fetch_field_direct(pRes, i);
        // Do we have a match
        if (dStrcmp(pField->name, _sFieldName) == 0)
           {
           // Yes we do
           return(GetRowCell(_iResult, i));
           }
        }

    // Let the user know
    Con::errorf ("MySQL: unknown field name: %s", _sFieldName);

    return(0);
}

Rich
#39
08/24/2002 (12:11 am)
This is very nice. I can use this fine from VC++, but I'd love to use it with MinGW. Can someone post the changes to the make files to incorporate this? I've found most of them but I'm having trouble with the libs and linking.

I know what I'm doing, honest! :) It's just been a looooooooooong time since I've had to work directly with make files.
#40
11/13/2002 (5:41 am)
looks like the only way i can d/l this would be to log in to the site .. but their is no option to register or anything like that