View previous topic :: View next topic |
Author |
Message |
eeriegeek
Joined: 07 Jan 2008 Posts: 59
|
Posted: Mon Apr 16, 2012 9:03 Post subject: Extended database plugin beta |
|
|
I've put a beta version of a revised database plugin (odbc/odmbc) in my core-2.8 branch for anybody who wants to experiment with some extended functionality. the plugin has been renamed "db" so it will not interfere with the current odbmc plugin (although you can only use one at a time). Changes include:
- ability to call prepared statements
- correct handling of empty strings and NULL
- safe handling of all non-null string characters
- multi-statement queries allowed for mysql and pgsql
- multi-result sets allowed for mysql
- added charset passing for pgsql
- function to call to the native database string escape
- GetField/SetParameter methods for objects.
There is also a new API which exposes virusman's object serialization functions for placeables, triggers, and merchants as well as the original items and creatures allowing:
- Freeze/Thaw (serialization) of all supported objects
- Encode/Decode frozen objects to hex strings
GIT Repository: https://github.com/eeriegeek/nwnx2-linux/tree/db_exp/plugins/db
tar archive: http://www.isleclostridia.net/nwnx/
There is an example module in the package which has several examples of how to use the database and serialization api's. As an example of calling a parameterized query with an object, here is one of the examples. The following script is called by tag by a rod and clones any object it is used on by storing a copy to the database and then creating a copy at any location when it is used a second time.
Code: |
#include "x2_inc_switches"
#include "nwnx_db"
void main()
{
SetExecutedScriptReturnValue(X2_EXECUTE_SCRIPT_END);
if (GetUserDefinedItemEventNumber()==X2_ITEM_EVENT_ACTIVATE) {
object oTarget = GetItemActivatedTarget();
if (oTarget!=OBJECT_INVALID) {
NWNX_DB_Execute("drop table rod_o_clone");
NWNX_DB_Execute("create table rod_o_clone ( ref varchar(16), obj mediumblob )");
NWNX_DB_Prepare("insert into rod_o_clone (ref,obj) values (?,?)");
NWNX_DB_SetParam_String(1,GetResRef(oTarget));
NWNX_DB_SetParam_Object(2,oTarget);
NWNX_DB_ExecutePrepared();
} else {
location mLoc = GetItemActivatedTargetLocation();
if (GetIsObjectValid(GetAreaFromLocation(mLoc))) {
NWNX_DB_Prepare("select ref,obj from rod_o_clone");
NWNX_DB_ExecutePrepared();
while (NWNX_DB_FetchPrepared()) {
object o = NWNX_DB_GetField_ObjectToLocation(2,mLoc);
}
}
}
}
}
|
There are more notes in the README file with the package describing other changes/limitations of the plugin.
Last edited by eeriegeek on Wed Jan 22, 2014 4:01; edited 1 time in total |
|
Back to top |
|
|
Ravine
Joined: 26 Jul 2006 Posts: 105
|
Posted: Thu Apr 19, 2012 17:57 Post subject: |
|
|
I have to tell that this looks impressive, but i'm scared as hell to think about converting all my stuff into this... but i'll probably do it later. |
|
Back to top |
|
|
Squatting Monk
Joined: 28 Jun 2007 Posts: 76
|
Posted: Wed Jul 25, 2012 4:02 Post subject: |
|
|
Forgive my stupid, but how do I get this to compile? I'm used to just running the install.sh. The readme talks about using make, but when I try that, I just get the following:
Code: | make: *** No targets specified and no makefile found. Stop. |
Cmake generates a few other files, but doesn't produce any .so's.
Help the Linux n00b? |
|
Back to top |
|
|
eeriegeek
Joined: 07 Jan 2008 Posts: 59
|
Posted: Wed Jul 25, 2012 22:09 Post subject: |
|
|
Hey, this version of the db plugin needs to be built along with the rest of the core-2.8 source tree. After checking out core-2.8 from gtithub, you unpack or check out the db plugin in your plugins directory.
To use the new cmake build, change directory to your top level nwnx source tree and type "cmake ." (cmake followed by dot) and then "make".
You may want to make sure you can build the baseline core-2.8 tree before trying to add additional plugins. If you have trouble with the base build, you might want to start a new topic here showing the flavor and version of linux you're using and any error messages you get. |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
Posted: Wed Jul 25, 2012 22:27 Post subject: |
|
|
eeriegeek, update your repository, the build system in the main repo has been updated (along with API and a few other things). _________________ In Soviet Russia, NWN plays you! |
|
Back to top |
|
|
Squatting Monk
Joined: 28 Jun 2007 Posts: 76
|
Posted: Thu Jul 26, 2012 5:01 Post subject: |
|
|
Thanks for the quick help, eeriegeek.
There were some errors compiling it.
Code: | [ 15%] Building CXX object plugins/db/CMakeFiles/db_mysql.dir/mysql.cpp.o
/opt/nwn/nwnx2-linux/branches/core-2.8/plugins/db/mysql.cpp: In member function âvirtual int CMySQL::Prepare(char*)â:
/opt/nwn/nwnx2-linux/branches/core-2.8/plugins/db/mysql.cpp:441: error: âmysql_stmt_next_resultâ was not declared in this scope
/opt/nwn/nwnx2-linux/branches/core-2.8/plugins/db/mysql.cpp: In member function âvirtual char* CMySQL::FetchPrepared(char*, unsigned int)â:
/opt/nwn/nwnx2-linux/branches/core-2.8/plugins/db/mysql.cpp:944: error: âmysql_stmt_next_resultâ was not declared in this scope
make[2]: *** [plugins/db/CMakeFiles/db_mysql.dir/mysql.cpp.o] Error 1
make[1]: *** [plugins/db/CMakeFiles/db_mysql.dir/all] Error 2
make: *** [all] Error 2 |
Is this due to the updates needed as virusman was pointing out? |
|
Back to top |
|
|
eeriegeek
Joined: 07 Jan 2008 Posts: 59
|
Posted: Thu Jul 26, 2012 5:29 Post subject: |
|
|
Possibly, although it looks at first glance like the mysql headers are not getting included somehow. Its possible cmake is not finding your mysql install properly. I'll merge the updates soon and see if they seem to have any effect. |
|
Back to top |
|
|
eeriegeek
Joined: 07 Jan 2008 Posts: 59
|
Posted: Thu Jul 26, 2012 8:00 Post subject: |
|
|
Squatting Monk,
I merged the latest updates into my fork and locally it built fine. On looking again at your error I noticed which function this is... mysql_stmt_next_result() appears to be missing. This is a newish function added in MySQL 5.5.3 (I'm currently using 5.5.21 for my client builds.) Is there a chance you are using an older (than 5.5.3) version of the client libraries? |
|
Back to top |
|
|
Squatting Monk
Joined: 28 Jun 2007 Posts: 76
|
Posted: Thu Jul 26, 2012 9:40 Post subject: |
|
|
Ahh... yeah, the version I was at was 5.1.63. The newest generally available MySQL version is 5.5.25a, but the development version is 5.6.5. Will try that.
Edit: Ah. There's no newer version of MySQL in the Ubuntu repositories because Oracle decided not to release Debian packages for them. I tried installing it manually, following three different guides. None of them worked, so it looks like I'm stuck with 5.1 for now. Too bad.
Anyway, thanks for the help. |
|
Back to top |
|
|
Ravine
Joined: 26 Jul 2006 Posts: 105
|
Posted: Mon Jan 20, 2014 9:55 Post subject: |
|
|
Hi,
the git repo is unavailable, and the standard mysql in debian is newer as i see. Is this plugin available somewhere?
thx |
|
Back to top |
|
|
virusman
Joined: 30 Jan 2005 Posts: 1020 Location: Russia
|
|
Back to top |
|
|
Ravine
Joined: 26 Jul 2006 Posts: 105
|
Posted: Mon Jan 20, 2014 12:17 Post subject: |
|
|
Thanks virusman |
|
Back to top |
|
|
Ravine
Joined: 26 Jul 2006 Posts: 105
|
Posted: Wed Jan 22, 2014 0:12 Post subject: |
|
|
Yeah, just as i suspected. It is awesome. Anyone using this already? Any cons? |
|
Back to top |
|
|
eeriegeek
Joined: 07 Jan 2008 Posts: 59
|
Posted: Wed Jan 22, 2014 3:57 Post subject: |
|
|
Hey, sorry I didn't see your first post. I'll have to fix those dead links.
Consider this beta and also a bit stale. The current db drivers have gotten some updates and there is another fix in the works. I'm considering re-writing this to use the new hook mechanism as well. It should be possible to build alternate backends independently that way and even run multiple databases.
This version of the extended drivers does do more complicated handling of the data (more vm instructions) so theoretically a tiny bit slower. |
|
Back to top |
|
|
Ravine
Joined: 26 Jul 2006 Posts: 105
|
Posted: Wed Jan 22, 2014 15:23 Post subject: |
|
|
All right. I'm gonna wait then a bit more Is it possible to merge this to the trunk?
Anyone using multi-statement, or multiple resultsets? I don't (probably no one else does ).
The prepared statements are very nice, and the serializer looks great too (i'm currently using virusman's code for in-game banks (saving placeables, works really well)). This hex-encoding to string has any limitation? I've cloned a dozen full bag of holding into a barrel, and cloned it. Everything was okay so far. |
|
Back to top |
|
|
|