Project

General

Profile

Actions

Feature #2807

closed

SQLite PIB implementation

Added by Yingdi Yu almost 9 years ago. Updated almost 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Security
Target version:
Start date:
Due date:
% Done:

100%

Estimated time:

Description

Implement PibImpl using a SQLite database as underlying storage.

Actions #1

Updated by Alex Afanasyev almost 9 years ago

I missed this before. Why "Sqlite3" appears upfront? Name should be just PibSqlite3, there is no need for additional "Impl" suffix, as Sqlite3 is implementation of Pib.

Actions #2

Updated by Yingdi Yu almost 9 years ago

Alex Afanasyev wrote:

I missed this before. Why "Sqlite3" appears upfront? Name should be just PibSqlite3, there is no need for additional "Impl" suffix, as Sqlite3 is implementation of Pib.

But it inherits from PibImpl? And there is another class Pib, I do not want to give people an impression that PibSqlite3 inherits from Pib...

Actions #3

Updated by Alex Afanasyev almost 9 years ago

It doesn't really matter from what it inherits. "Sqlite3" suffix (for me) already indicates that it is a concrete implementation and the name does not necessarily need to reflect the inheritance.

Actions #4

Updated by Yingdi Yu almost 9 years ago

how about PibImplSqlite3?

Actions #5

Updated by Yingdi Yu almost 9 years ago

  • Assignee changed from Michael Sweatt to Yingdi Yu
Actions #6

Updated by Yingdi Yu almost 9 years ago

  • Status changed from New to Code review
  • Target version set to v0.4
  • % Done changed from 0 to 80
Actions #7

Updated by Junxiao Shi almost 9 years ago

In commit:216a9229c43ec62fdeab3bd673a9793bc4ca66af, the need for sqlite3_finalize makes code cluttered, because that function must be called in every code path before a method returns.

I suggest introducing a helper to solve this problem:

/** \brief wraps an SQLite prepared statement
 */
class PreparedStatement
{
public:
  /** \brief prepares a statement
   *  \throw std::domain_error SQL statement is bad
   */
  PreparedStatement(sqlite3* database, const std::string& sql)
  {
    int res = sqlite3_prepare_v2(database, sql.c_str(), -1, &m_stmt, nullptr);
    if (res != SQLITE_OK) {
      throw std::domain_error("bad SQL statement: " + str);
    }
  }

  /** \brief finalizes the statement
   */
  ~PreparedStatement()
  {
    sqlite3_finalize(m_stmt);
  }

  /** \brief implicitly converts to sqlite3_stmt* to be used in SQLite C API
   */
  operator sqlite3_stmt*()
  {
    return m_stmt;
  }

private:
  sqlite3_stmt* m_stmt;
};

This helper should be placed in util/sqlite-helper.hpp so that it can be reused in other modules.

Actions #8

Updated by Yingdi Yu almost 9 years ago

I think it is a good idea. One question, would this be public, or local to PibSqlite3? I do not want to make it public, because its implementation details, and it is not related to ndn. However, we use sqlite3 in several places, so it may cause some code duplication.

Actions #9

Updated by Junxiao Shi almost 9 years ago

Answer to note-8:

The header is public, but it can be marked as "implementation detail" in Doxygen (similar to common.hpp which is marked as "implementation detail").

Actions #10

Updated by Junxiao Shi almost 9 years ago

  • Tracker changed from Task to Feature
  • Subject changed from Implement Sqlite3PibImpl to PibSqlite3
Actions #11

Updated by Junxiao Shi almost 9 years ago

  • Subject changed from PibSqlite3 to SQLite PIB implementation
  • Description updated (diff)
  • Start date deleted (05/13/2015)
Actions #12

Updated by Yingdi Yu almost 9 years ago

  • Status changed from Code review to Closed
  • % Done changed from 80 to 100
Actions

Also available in: Atom PDF