Raised This Month: $51 Target: $400
 12% 

[Suggestion]for the Database interface


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 05-21-2015 , 23:30   [Suggestion]for the Database interface
Reply With Quote #1

sorry for this thread if I post a wrong section.
when I use the Database from the SourceMod, I found that there was something could be improve
for example, according to the current version, get the data we used to "SQL_FetchString,SQL_FetchFloat,SQL_FetchInt" , and we have to sort the column index,
I think we can add more native get the data with the column name,
and I make some Pseudocode :

Code:
class IResultRow {     virtual DBResult GetString(const char *szColumn, const char **pString, size_t *length);     virtual DBResult GetFloat(const char *szColumn, float *pFloat);     virtual DBResult GetInt(const char *szColumn, int *pInt);     //.... }

and then use a hashmap to store the column index with the name key

this for the mysql code, untest
Code:
if (m_pRes) {     MYSQL_FIELD *f = ::mysql_fetch_field(m_pRes);     int i = 1;     while (f)     {         if (f->name)         {             ke::HashMap<ke::AString, int, StringPolicy>::Insert it = m_nmap.findForAdd(f->name);             m_nmap.add(it, ke::AString(f->name), i);             f = ::mysql_fetch_field(m_pRes);             i++;         }     } } //.... DBResult MyBasicResults::GetString(const char *szColumn, const char **pString, size_t *length) {     ke::HashMap<ke::AString, int, StringPolicy>::Result re = m_nmap.find(szColumn);     if (!re.found())         return DBVal_Error;     if (re->value >= m_ColCount)         return DBVal_Error;     else if (m_Row[re->value] == NULL) {         *pString = "";         if (length)         {             *length = 0;         }         return DBVal_Null;     }     *pString = m_Row[re->value];     if (length)     {         *length = (size_t)m_Lengths[re->value];     }     return DBVal_Data; }
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
necavi
Veteran Member
Join Date: Sep 2010
Old 05-22-2015 , 01:02   Re: [Suggestion]for the Database interface
Reply With Quote #2

There is: https://sm.alliedmods.net/new-api/db...FieldNameToNum but it can be a bit awkward to use.
necavi is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 05-22-2015 , 07:04   Re: [Suggestion]for the Database interface
Reply With Quote #3

another thing:
PHP Code:
ke::HashMap<ke::AStringintStringPolicy
to:
PHP Code:
StringHashMap<int
reason:
https://github.com/alliedmodders/sou...hashmap.h#L102
__________________
WildCard65 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 19:02.


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