blob: 24f8c3f1790e114113657cc540e63a4e268a7aca [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 Afanasyev68f2a952013-01-08 14:34:16 -080031#include <boost/filesystem.hpp>
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080032
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080033typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info_str;
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080034
35class DbHelper
36{
37public:
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080038 DbHelper (const boost::filesystem::path &path, const std::string &dbname);
Alexander Afanasyeva199f972013-01-02 19:37:26 -080039 virtual ~DbHelper ();
Alexander Afanasyeva35756b2013-01-22 16:59:11 -080040
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080041private:
42 static void
Alexander Afanasyevde1cdd02012-12-29 14:41:46 -080043 hash_xStep (sqlite3_context *context, int argc, sqlite3_value **argv);
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080044
45 static void
Alexander Afanasyevde1cdd02012-12-29 14:41:46 -080046 hash_xFinal (sqlite3_context *context);
47
Alexander Afanasyeva199f972013-01-02 19:37:26 -080048protected:
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080049 sqlite3 *m_db;
50};
51
52namespace Error {
53struct Db : virtual boost::exception, virtual std::exception { };
54}
55
Alexander Afanasyeva199f972013-01-02 19:37:26 -080056typedef boost::shared_ptr<DbHelper> DbHelperPtr;
Alexander Afanasyev71b43e72012-12-27 01:03:43 -080057
Alexander Afanasyeva199f972013-01-02 19:37:26 -080058
59#endif // DB_HELPER_H