From 9f89a1296a1b4a0195a4c3f828654c0189eb12b0 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sun, 7 Nov 2021 16:48:57 +0100 Subject: [PATCH] Add GetInt64 --- src/engine/server/databases/connection.h | 1 + src/engine/server/databases/mysql.cpp | 29 ++++++++++++++++++++++++ src/engine/server/databases/sqlite.cpp | 6 +++++ 3 files changed, 36 insertions(+) diff --git a/src/engine/server/databases/connection.h b/src/engine/server/databases/connection.h index 6ac18a92c..e4126d23c 100644 --- a/src/engine/server/databases/connection.h +++ b/src/engine/server/databases/connection.h @@ -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 diff --git a/src/engine/server/databases/mysql.cpp b/src/engine/server/databases/mysql.cpp index 542915757..f3fadec75 100644 --- a/src/engine/server/databases/mysql.cpp +++ b/src/engine/server/databases/mysql.cpp @@ -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; diff --git a/src/engine/server/databases/sqlite.cpp b/src/engine/server/databases/sqlite.cpp index d6c3fb5ea..b4cfc7391 100644 --- a/src/engine/server/databases/sqlite.cpp +++ b/src/engine/server/databases/sqlite.cpp @@ -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);