Fix Author's gid getter 31/319831/2
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 18 Feb 2025 15:01:33 +0000 (16:01 +0100)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Wed, 19 Feb 2025 07:07:02 +0000 (07:07 +0000)
Change-Id: If66f65ed01854c88b8229b4fe606ef7302d2107a

src/common/privilege_db.cpp
src/dpl/db/include/dpl/db/sql_connection.h
src/dpl/db/src/sql_connection.cpp

index 57dff3c5d8e607333cc3fb4773e35487e1c0571b..7f3d1eb0b7a6ce27d8889f45146b3f3707993b0d 100644 (file)
@@ -986,7 +986,7 @@ bool PrivilegeDb::GetAuthorGId(const std::string& pkgName, gid_t& authorGId)
         auto command = getStatement(StmtType::EGetAuthorId);
         command->BindString(1, pkgName);
 
-        if (command->Step()) {
+        if (command->Step() && !command->IsNull(0)) {
             authorGId = command->GetColumnInteger(0);
             return true;
         }
index 4173b1946e370b99c72a5703dd1727a7d4ec7f8d..b21f151ba066341598d8aa034457d2114e22207d 100644 (file)
@@ -154,6 +154,13 @@ class SqlConnection final
          * @throw Exception::InvalidColumn
          */
         std::string GetColumnString(ColumnIndex column);
+
+        /**
+         * Check if the column is null in the current row.
+         *
+         * @throw Exception::InvalidColumn
+         */
+        bool IsNull(SqlConnection::ColumnIndex column);
     };
 
     // Move on copy semantics
index b190c1a0c9f7325de05c03e62bf4c7b14dba3a5b..72e679279996dc2c0ca4777675528907f56c9d75 100644 (file)
@@ -300,6 +300,14 @@ std::string SqlConnection::DataCommand::GetColumnString(
     return std::string(value);
 }
 
+bool SqlConnection::DataCommand::IsNull(SqlConnection::ColumnIndex column)
+{
+    LogDB("SQL data command check if column is null: [" << column << "]");
+    CheckColumnIndex(column);
+
+    return SQLITE_NULL == sqlite3_column_type(m_stmt, column);
+}
+
 void SqlConnection::Connect(const std::string &address,
                             Flag::Type type,
                             Flag::Option flag)