mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge #4334
4334: Add GetInt64 r=def- a=ChillerDragon Comes in handy for my downstream Co-authored-by: ChillerDragon <ChillerDragon@gmail.com>
This commit is contained in:
commit
9bd3bc8480
|
@ -72,6 +72,7 @@ public:
|
|||
virtual bool IsNull(int Col) = 0;
|
||||
virtual float GetFloat(int Col) = 0;
|
||||
virtual int GetInt(int Col) = 0;
|
||||
virtual int64_t GetInt64(int Col) = 0;
|
||||
// ensures that the string is null terminated
|
||||
virtual void GetString(int Col, char *pBuffer, int BufferSize) = 0;
|
||||
// returns number of bytes read into the buffer
|
||||
|
|
|
@ -91,6 +91,7 @@ public:
|
|||
virtual bool IsNull(int Col);
|
||||
virtual float GetFloat(int Col);
|
||||
virtual int GetInt(int Col);
|
||||
virtual int64_t GetInt64(int Col);
|
||||
virtual void GetString(int Col, char *pBuffer, int BufferSize);
|
||||
virtual int GetBlob(int Col, unsigned char *pBuffer, int BufferSize);
|
||||
|
||||
|
@ -550,6 +551,34 @@ int CMysqlConnection::GetInt(int Col)
|
|||
return Value;
|
||||
}
|
||||
|
||||
int64_t CMysqlConnection::GetInt64(int Col)
|
||||
{
|
||||
Col -= 1;
|
||||
|
||||
MYSQL_BIND Bind;
|
||||
int64_t Value;
|
||||
my_bool IsNull;
|
||||
mem_zero(&Bind, sizeof(Bind));
|
||||
Bind.buffer_type = MYSQL_TYPE_LONGLONG;
|
||||
Bind.buffer = &Value;
|
||||
Bind.buffer_length = sizeof(Value);
|
||||
Bind.length = nullptr;
|
||||
Bind.is_null = &IsNull;
|
||||
Bind.is_unsigned = false;
|
||||
Bind.error = nullptr;
|
||||
if(mysql_stmt_fetch_column(m_pStmt.get(), &Bind, Col, 0))
|
||||
{
|
||||
StoreErrorStmt("fetch_column:int64");
|
||||
dbg_msg("mysql", "error fetching column %s", m_aErrorDetail);
|
||||
dbg_assert(0, "error in GetInt64");
|
||||
}
|
||||
if(IsNull)
|
||||
{
|
||||
dbg_assert(0, "error getting int: NULL");
|
||||
}
|
||||
return Value;
|
||||
}
|
||||
|
||||
void CMysqlConnection::GetString(int Col, char *pBuffer, int BufferSize)
|
||||
{
|
||||
Col -= 1;
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
virtual bool IsNull(int Col);
|
||||
virtual float GetFloat(int Col);
|
||||
virtual int GetInt(int Col);
|
||||
virtual int64_t GetInt64(int Col);
|
||||
virtual void GetString(int Col, char *pBuffer, int BufferSize);
|
||||
// passing a negative buffer size is undefined behavior
|
||||
virtual int GetBlob(int Col, unsigned char *pBuffer, int BufferSize);
|
||||
|
@ -274,6 +275,11 @@ int CSqliteConnection::GetInt(int Col)
|
|||
return sqlite3_column_int(m_pStmt, Col - 1);
|
||||
}
|
||||
|
||||
int64_t CSqliteConnection::GetInt64(int Col)
|
||||
{
|
||||
return sqlite3_column_int64(m_pStmt, Col - 1);
|
||||
}
|
||||
|
||||
void CSqliteConnection::GetString(int Col, char *pBuffer, int BufferSize)
|
||||
{
|
||||
str_copy(pBuffer, (const char *)sqlite3_column_text(m_pStmt, Col - 1), BufferSize);
|
||||
|
|
Loading…
Reference in a new issue