Raised This Month: $32 Target: $400
 8% 

Need Data Access Layer For Plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ajaxx
Senior Member
Join Date: Oct 2009
Old 12-03-2009 , 11:36   Need Data Access Layer For Plugin
Reply With Quote #1

I’m trying to create an MS SQL DAL for my plugin. I have it working as in I’m able to pass parameters to my stored procedures and return a recordset. But it seems kind of clunky and I can’t really tell the difference between returning 0 (as in the int) and returning NULL (as in no recordset). Has anyone already created a DAL I can use or have some examples for best practices I can follow?
Ajaxx is offline
recon0
Veteran Member
Join Date: Sep 2007
Location: US
Old 12-04-2009 , 02:47   Re: Need Data Access Layer For Plugin
Reply With Quote #2

NULL is 0.

As for DALs, SourceMod might have some interesting code for you to look at.
__________________
recon0 is offline
Ajaxx
Senior Member
Join Date: Oct 2009
Old 12-04-2009 , 11:06   Re: Need Data Access Layer For Plugin
Reply With Quote #3

I know NULL is 0 that’s the point. How do you tell the difference? Say you have a function that looks up an int in the database and returns it. So the function has a return value of int. In your database you have a table that looks like this:

Code:
 
Name  Value
A       1
B       0
How do you tell the difference between:

Code:
SELECT Value FROM Table WHERE Name = B
And
Code:
SELECT Value FROM Table WHERE Name = C
When C isn’t found it’s going to return NULL but this is the same as returning 0 or the same result as a query for B.

I don’t want my DAL to return a variant when I know the return type is an int or a double or whatever. Maybe I’m going about this the wrong way. Maybe I should just setup my database to never have a 0 in an int field. But this doesn’t seem right.

SourceMod has a provider for MySQL I believe, I was looking for a MS SQL provider.

I’m just looking for something really simple, a DAL you pass the SP name and parameters to and it gives you back an int, double, string, date, or record set. Is there such a thing as nullable types in C++?

I don’t know what that guy in the other thread was talking about I always get a helpful answer here!
Ajaxx is offline
recon0
Veteran Member
Join Date: Sep 2007
Location: US
Old 12-04-2009 , 18:29   Re: Need Data Access Layer For Plugin
Reply With Quote #4

Quote:
Originally Posted by Ajaxx View Post
I know NULL is 0 that’s the point. How do you tell the difference?

Is there such a thing as nullable types in C++?
You can't. Consider:
PHP Code:
// This is how NULL is defined
#define NULL 0

// NULL is an integer
int i 0;

// This is true
== NULL 
Not in the standard library. Boost doesn't seem to have them either.

You could write your own nullable type class. Just be careful not to create a magic number when you define your NULL (DB_NULL perhaps). A pointer to a singleton could work.
__________________
recon0 is offline
L. Duke
Veteran Member
Join Date: Apr 2005
Location: Walla Walla
Old 12-04-2009 , 22:55   Re: Need Data Access Layer For Plugin
Reply With Quote #5

Generally when working with a database you will first check to make sure that the record count is greater than zero. Then when you get the result after that you know that it is a valid number.
__________________
"Good grammar is essential, Robin."
- Batman
L. Duke is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:04.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode