blob: 51970dd5794838a2c27e823e8c8710defa757e5c [file] [log] [blame]
Alexander Afanasyev71b43e72012-12-27 01:03:43 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Alexander Afanasyeva199f972013-01-02 19:37:26 -08003 * Copyright (c) 2012-2013 University of California, Los Angeles
Alexander Afanasyev71b43e72012-12-27 01:03:43 -08004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
19 * Zhenkai Zhu <zhenkai@cs.ucla.edu>
20 */
21
Alexander Afanasyeva199f972013-01-02 19:37:26 -080022#ifndef DB_HELPER_H
23#define DB_HELPER_H
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080024
Alexander Afanasyev3abe2252013-01-02 20:45:29 -080025#include <stdint.h>
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080026#include <sqlite3.h>
27#include <openssl/evp.h>
28#include <boost/exception/all.hpp>
29#include <string>
Alexander Afanasyeva199f972013-01-02 19:37:26 -080030#include "hash-helper.h"
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080031
Alexander Afanasyeva199f972013-01-02 19:37:26 -080032typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080033
34class DbHelper
35{
36public:
37 DbHelper (const std::string &path);
Alexander Afanasyeva199f972013-01-02 19:37:26 -080038 virtual ~DbHelper ();
Alexander Afanasyevae43c502012-12-29 17:26:37 -080039
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080040private:
41 static void
Alexander Afanasyevde1cdd02012-12-29 14:41:46 -080042 hash_xStep (sqlite3_context *context, int argc, sqlite3_value **argv);
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080043
44 static void
Alexander Afanasyevde1cdd02012-12-29 14:41:46 -080045 hash_xFinal (sqlite3_context *context);
46
Alexander Afanasyeva199f972013-01-02 19:37:26 -080047protected:
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080048 sqlite3 *m_db;
49};
50
51namespace Error {
52struct Db : virtual boost::exception, virtual std::exception { };
53}
54
Alexander Afanasyeva199f972013-01-02 19:37:26 -080055typedef boost::shared_ptr<DbHelper> DbHelperPtr;
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080056
Alexander Afanasyeva199f972013-01-02 19:37:26 -080057
58#endif // DB_HELPER_H