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 
 
SQLServer 2.0

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



Joined: 20 Jan 2005
Posts: 431

PostPosted: Mon Oct 20, 2008 4:36    Post subject: SQLServer 2.0 Reply with quote

SQLServer plugin

Well it's here... a SQLServer 2.0 plugin for NWNX^2

There has been some major rework of the back-end hence the separate plugin, and not an extra option for the existing ODBC plugin.

I think the major 'usability' improvement, that you'll all love is the removal of all the SQL syntax string manipulation. It's still here, but you have an alternative where it's not required.

Introducing Parameters. Add a parameter indicator ('?') to your SQL Statement and this will be replaced by the value of a SQLBind...() function.

SQLPrepare("{call [stored_proc] (?)}");
// or SQLPrepare("select value from table where key=?");
SQLBindString("MyKey");

Note the new function SQLPrepare(), allows us to SQLBind...() variables, in sequence, before we SQLExecute(). If you are using parameters you must SQLPrepare() the SQL command first. Your SQL will be easier to write AND much easier to read. Wink

Technically we've added 'usability' to Objects. Objects and other data types can now be returned in the same result set. No need for a separate query to get the Object data.

int i = SQLGetInt(1);
object o = SQLGetObject(2);
string s = SQLGetString(3);

will all work from the same result-set (*columns must be accessed in sequence)

With the improvements to Object fetching, I no longer needed this - but I left it in, MARS - Multiple ACTIVE result sets. You can now have up to 4 active result sets. A new command SQLContext() enables you to switch between each 'context' to use the results of one as in 'input' for another, without destroying the original.

Getting into trouble? Full ODBC diagnostics are added into the log file, to assist with those queries that 'break' on you Wink

You get all this and more...
(but only with SQLServer 2005 or better - defaulting to the EXPRESS editions *the free ones)
at the give-away price of - Oh yeah I'm giving it away!

Advances in 2.0
* Native Client support
the .ini now accepts a 'nativeclient' value 2005(default) or 2008 for the SQLServer version being used.
* Object Parameter improvements.
SQLGetObject() & SQLSetObject() are no longer constrained to the final parameter, and the 1 object limit has been removed. So multiple 'object columns' can be bound in the same SQL statement. eg
SQLPrepare("update table set obj1=?, obj2=? where key=?");
SQLBindObject(oItem1);
SQLBindObject(oItem2);
SQLBindString("KeyToRow");
SQLExecute();

Cheers
Gryphyn

PS. Compiled on VistaUltimate SP1 using VisualStudio2008.
The source is available Cool

[Ed: Sorry I couldn't update the text on my contributions page, don't know why not. At any rate the SQLServer 2.0 project is now available]
Back to top
View user's profile Send private message
RamaDeveloper



Joined: 19 Mar 2009
Posts: 13
Location: UK

PostPosted: Fri Mar 27, 2009 4:36    Post subject: Missing NWNXBase.cpp Reply with quote

Hello again, I finally got some free time to download the plugin you generously provide and have loaded up the source but find that I have no NWNXBase.cpp file, I've had a dig around the forums but can't find it elsewhere, would it be possible to get hold of a copy or a paste of the source ?

Cheers, Chris
_________________
Chris
Back to top
View user's profile Send private message Visit poster's website
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Fri Mar 27, 2009 7:41    Post subject: Re: Missing NWNXBase.cpp Reply with quote

RamaDeveloper wrote:
Hello again, I finally got some free time to download the plugin you generously provide and have loaded up the source but find that I have no NWNXBase.cpp file, I've had a dig around the forums but can't find it elsewhere, would it be possible to get hold of a copy or a paste of the source ?

Cheers, Chris

<root>\trunk\NWNXdll\NWNXBase.cpp
(it's included from the NWNXdll code path)
Back to top
View user's profile Send private message
MaxRock



Joined: 24 Jan 2008
Posts: 196

PostPosted: Wed May 20, 2009 19:32    Post subject: Reply with quote

I've been toying with the idea of switching our PW from mysql to sqlserver, mainly because of the stored proc and multiple record sets functionality, and finally got a little test module up (no other scripts except the sqlserver() for modload and the test script; no other nwnx plugins loaded

all the test script does is
Code:

SQLExecute("SELECT isadmin FROM trinity_dms WHERE CDKey='" +sCDKey+ "'");


and it seems to work fine for the first query but calling the script again crashes the server.

nwnx_sqlserver.log
Code:

NWNX^2 SQLServer plugin v1.69.2.0
(c) 2008 by Rob Lobbe (Gryphyn@TheFold.org)
visit us at http://www.nwnx.org

o Started [2009-05-20 12:21:50]
o Hooking StoreCampainObject()...hooked at 5d5830
o Hooking RetrieveCampainObject()...hooked at 5d5710
o Configuration
! E:\games\NWN\nwnx_sqlserver.ini
! Instance: .\SQLEXPRESS
! Database: nwn
! Trusted Connection
! Driver={SQL Server Native Client 10.0};Server={.\SQLEXPRESS};Database={nwn};Trusted_Connection=yes;MARS_Connection=yes;
! Logging 2 (everything)
o Connecting to SQLServer
! [01000] [Microsoft][SQL Server Native Client 10.0][SQL Server]Changed database context to 'nwn'.
! [01000] [Microsoft][SQL Server Native Client 10.0][SQL Server]Changed language setting to us_english.
o Executing: SELECT isadmin FROM trinity_dms WHERE CDKey='QC4EPX6N'
o EXECUTE: 1
o Flushing residual result set(s)


Am I missing something?
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Wed May 20, 2009 22:40    Post subject: Reply with quote

MaxRock wrote:
I've been toying with the idea of switching our PW from mysql to sqlserver, mainly because of the stored proc and multiple record sets functionality, and finally got a little test module up (no other scripts except the sqlserver() for modload and the test script; no other nwnx plugins loaded

all the test script does is
Code:

SQLExecute("SELECT isadmin FROM trinity_dms WHERE CDKey='" +sCDKey+ "'");


and it seems to work fine for the first query but calling the script again crashes the server.

nwnx_sqlserver.log
Code:

NWNX^2 SQLServer plugin v1.69.2.0
(c) 2008 by Rob Lobbe (Gryphyn@TheFold.org)
visit us at http://www.nwnx.org

o Started [2009-05-20 12:21:50]
o Hooking StoreCampainObject()...hooked at 5d5830
o Hooking RetrieveCampainObject()...hooked at 5d5710
o Configuration
! E:\games\NWN\nwnx_sqlserver.ini
! Instance: .\SQLEXPRESS
! Database: nwn
! Trusted Connection
! Driver={SQL Server Native Client 10.0};Server={.\SQLEXPRESS};Database={nwn};Trusted_Connection=yes;MARS_Connection=yes;
! Logging 2 (everything)
o Connecting to SQLServer
! [01000] [Microsoft][SQL Server Native Client 10.0][SQL Server]Changed database context to 'nwn'.
! [01000] [Microsoft][SQL Server Native Client 10.0][SQL Server]Changed language setting to us_english.
o Executing: SELECT isadmin FROM trinity_dms WHERE CDKey='QC4EPX6N'
o EXECUTE: 1
o Flushing residual result set(s)


Am I missing something?


I don't see any code there for fetching the result-set.

o EXECUTE: 1 -> the query ran successfully.

o Flushing residual result set(s) -> a 2nd Execute (without a Fetch or Commit) - can sometimes occur with a Prepare as well.

*even so not sure why you're 'crashing' it should still keep going.
Check the error log, it will have the full ODBC error sequence.

Also which mode are you using? APS or SQL?

your code should look something like this.
SQLExecute("SELECT isadmin FROM trinity_dms WHERE CDKey='QC4EPX6N'");
SQLFetch();
int isadmin = SQLGetInt(1);
SQLCommit();


Try the new syntax

SQLPrepare("SELECT isadmin FROM trinity_dms WHERE CDKey=?");
SQLBindString("QC4EPX6N"); --can be a function parameter
SQLExecute();
SQLFetch();
int isadmin = SQLGetInt(1);
SQLCommit();

the ? is a parameter marker, and the SQLBind<type>() functions, bind in sequence (ie p1 = the first bind, p2 = the 2nd bind etc)

Cheers
Gryphyn
Back to top
View user's profile Send private message
MaxRock



Joined: 24 Jan 2008
Posts: 196

PostPosted: Wed May 20, 2009 23:39    Post subject: Reply with quote

The new syntax works just fine.

I only had the SQLExecute(...) line.
Apparently running two of those without fetch and/or commit takes the server down.

Thank you for your help Very Happy
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Thu May 21, 2009 8:46    Post subject: Reply with quote

MaxRock wrote:
The new syntax works just fine.

I only had the SQLExecute(...) line.
Apparently running two of those without fetch and/or commit takes the server down.

Thank you for your help Very Happy

It shouldn't - that's what the
o Flushing residual result set(s)
is all about. A second SQLExecute() should 'clear' any previous activity's but it shouldn't crash the server.

I'll have a look into it.

Cheers
Gryphyn
Back to top
View user's profile Send private message
MaxRock



Joined: 24 Jan 2008
Posts: 196

PostPosted: Thu May 21, 2009 20:12    Post subject: Reply with quote

In case it helps any:
I'm using the express 2008 version on xp 32 sp3
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows 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