sqlite handle: Initial implementation

Note that this commit does not properly implement ChildSelector==1
(rightmost). Currently, this selector just means the max value of
names vector, but it is not right. This is a known issue and is tracked
as part of refs #1433 (http://redmine.named-data.net/issues/1433).

Change-Id: I4d6dfaa5d52a3ab955aefa21d7b330cff7c68be6
diff --git a/storage/sqlite/sqlite-handle.hpp b/storage/sqlite/sqlite-handle.hpp
new file mode 100644
index 0000000..a2091c8
--- /dev/null
+++ b/storage/sqlite/sqlite-handle.hpp
@@ -0,0 +1,128 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (C) 2013 Regents of the University of California.
+ * See COPYING for copyright and distribution information.
+ */
+
+#ifndef REPO_STORAGE_SQLITE_SQLITE_HANDLE_HPP
+#define REPO_STORAGE_SQLITE_SQLITE_HANDLE_HPP
+
+#include "../storage-handle.hpp"
+
+#include <string>
+#include <iostream>
+#include <sqlite3.h>
+#include <stdlib.h>
+#include <vector>
+#include <queue>
+#include <algorithm>
+
+namespace repo {
+
+using std::queue;
+
+class SqliteHandle : public StorageHandle
+{
+public:
+  class Error : public StorageHandle::Error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : StorageHandle::Error(what)
+    {
+    }
+  };
+
+  SqliteHandle();
+
+  explicit
+  SqliteHandle(const string& dbPath);
+
+  virtual
+  ~SqliteHandle();
+
+
+  // from StorageHandle
+
+  virtual bool
+  insertData(const Data& data);
+
+  virtual bool
+  deleteData(const Name& name);
+
+  virtual bool
+  readData(const Interest& interest, Data& data);
+
+  virtual bool
+  hasName(const Name& name);
+
+  virtual bool
+  readNameAny(const Name& name, const Selectors& selectors, vector<Name>& names);
+
+private:
+  void
+  initializeRepo();
+
+  /**
+  * @brief find data with the exact name matched
+  * @param[out] data Data matching Interest.
+  * @return if no data or something is wrong, return false
+  */
+  bool
+  readData(const Name& name, Data& data);
+
+  /**
+  * @brief check whether there is one row with this parentName = parentName in database
+  * @return if no data or something is wrong, return false.
+  */
+  bool
+  hasParentName(const Name& parentName) const;
+
+  /**
+  * @brief This function is for no selector, it will reply the leftmost data
+  * @param[out] data Data matching Interest.
+  * @return if no data or something is wrong, return false.
+  */
+  bool
+  readDataPlain(const Name& name, Data& data);
+
+  /**
+  * @brief  read data with this prefix or name
+  * @param name indicates name or prefix of interest
+  * @param[out] names is vector to contain the result of this function.
+  * @return success return true, error return false
+  */
+  bool
+  readDataName(const Name& name, vector<Name>& names) const;
+
+  /**
+  * @brief  read data with this prefix or name and selectors including  MinSuffixComponents,
+  * MaxSuffixComponents, PublisherPublicKeyLocator, and Exclude.
+  * This method does not consider ChildSelector and MustBeFresh.
+  *
+  * @param name indicates name or prefix of interest
+  * @param[out] names is vector to contain the result of this function.
+  * @return success return true, error return false
+  */
+  bool
+  readNameSelector(const Interest& interest, vector<Name>& names) const;
+
+  /**
+  * @brief ChildSelector filter
+  * @param names list of candidate names for ChildSelector filter
+  * @param[out] resultName is the result of selected name
+  * @return success return true, error return false
+  */
+  bool
+  filterNameChild(const Name& name, int childSelector,
+                  const vector<Name>& names, Name& resultName);
+
+private:
+  sqlite3* m_db;
+  string m_dbPath;
+};
+
+} // namespace repo
+
+#endif