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;
}
__________________