logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Extended database plugin beta

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Linux development
View previous topic :: View next topic  
Author Message
eeriegeek



Joined: 07 Jan 2008
Posts: 59

PostPosted: Mon Apr 16, 2012 9:03    Post subject: Extended database plugin beta Reply with quote

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
View user's profile Send private message
Ravine



Joined: 26 Jul 2006
Posts: 105

PostPosted: Thu Apr 19, 2012 17:57    Post subject: Reply with quote

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
View user's profile Send private message
Squatting Monk



Joined: 28 Jun 2007
Posts: 76

PostPosted: Wed Jul 25, 2012 4:02    Post subject: Reply with quote

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? Embarassed
Back to top
View user's profile Send private message
eeriegeek



Joined: 07 Jan 2008
Posts: 59

PostPosted: Wed Jul 25, 2012 22:09    Post subject: Reply with quote

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
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Wed Jul 25, 2012 22:27    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website Yahoo Messenger
Squatting Monk



Joined: 28 Jun 2007
Posts: 76

PostPosted: Thu Jul 26, 2012 5:01    Post subject: Reply with quote

Thanks for the quick help, eeriegeek. Smile

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
View user's profile Send private message
eeriegeek



Joined: 07 Jan 2008
Posts: 59

PostPosted: Thu Jul 26, 2012 5:29    Post subject: Reply with quote

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
View user's profile Send private message
eeriegeek



Joined: 07 Jan 2008
Posts: 59

PostPosted: Thu Jul 26, 2012 8:00    Post subject: Reply with quote

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
View user's profile Send private message
Squatting Monk



Joined: 28 Jun 2007
Posts: 76

PostPosted: Thu Jul 26, 2012 9:40    Post subject: Reply with quote

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
View user's profile Send private message
Ravine



Joined: 26 Jul 2006
Posts: 105

PostPosted: Mon Jan 20, 2014 9:55    Post subject: Reply with quote

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
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Mon Jan 20, 2014 11:54    Post subject: Reply with quote

https://github.com/eeriegeek/nwnx2-linux/tree/db_exp/plugins/db
_________________
In Soviet Russia, NWN plays you!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Ravine



Joined: 26 Jul 2006
Posts: 105

PostPosted: Mon Jan 20, 2014 12:17    Post subject: Reply with quote

Thanks virusman Smile
Back to top
View user's profile Send private message
Ravine



Joined: 26 Jul 2006
Posts: 105

PostPosted: Wed Jan 22, 2014 0:12    Post subject: Reply with quote

Yeah, just as i suspected. It is awesome. Anyone using this already? Any cons?
Back to top
View user's profile Send private message
eeriegeek



Joined: 07 Jan 2008
Posts: 59

PostPosted: Wed Jan 22, 2014 3:57    Post subject: Reply with quote

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
View user's profile Send private message
Ravine



Joined: 26 Jul 2006
Posts: 105

PostPosted: Wed Jan 22, 2014 15:23    Post subject: Reply with quote

All right. I'm gonna wait then a bit more Smile Is it possible to merge this to the trunk?
Anyone using multi-statement, or multiple resultsets? I don't (probably no one else does Smile ).
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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Linux development All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group