Skip to content

Is it possible to access to sqlite3_column_table_name sqlite3 function from SQLite::Statement? #555

Description

@Feneck91

Actually it is not possible to access to sqlite3 sqlite3_column_table_name function directly from SQLite::Statement.
It is because we have not access to sqlite3_stmt: because Statement::getPreparedStatement is private.

So it is possible to:

  1. Let Statement::getPreparedStatement is to be protected (or public)?
  2. Or add a function into statement to call sqlite3_column_table_name

Actually I must prepare 2 statements!
This code is like this, not really optimized!

class Statement::Impl : public std::enable_shared_from_this<Statement::Impl>
{
public:
    explicit Impl(SQLite::Database &_rDatabase, SQLite::Statement && _rrStatment);

    /// @brief Destructor
    virtual ~Impl();

protected:
    SQLite::Database &              m_rDatabase;    ///< Reference to database
    SQLite::Statement               m_Statement;    ///< Internal statement
    sqlite3_stmt *                  m_pRawStmt;     ///< Pointer on statement, this used ONLY FOR sqlite3_column_table_name
};

Statement::Impl::Impl(SQLite::Database &_rDatabase, SQLite::Statement && _rrStatment)
    : m_rDatabase(_rDatabase)
    , m_Statement(std::move(_rrStatment))
    , m_pRawStmt(nullptr)
{
    // Prepare C raw handle to access to metadata table name
    sqlite3_prepare_v2(m_rDatabase.getDatabase()->getHandle(), m_Statement.getExpandedSQL().c_str(), -1, &m_pRawStmt, nullptr);
}

Statement::Impl::~Impl()
{
    if (m_pRawStmt != nullptr)
    {
        sqlite3_finalize(m_pRawStmt);
        m_pRawStmt = nullptr;
    }
}

std::string Statement::Impl::getTableName(int _iIndexColumn) const
{
    return sqlite3_column_table_name(m_pRawStmt, _iIndexColumn);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions