Botan  1.11.15
src/lib/utils/database.h
Go to the documentation of this file.
00001 /*
00002 * SQL database interface
00003 * (C) 2014 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_SQL_DATABASE_H__
00009 #define BOTAN_SQL_DATABASE_H__
00010 
00011 #include <botan/types.h>
00012 #include <string>
00013 #include <chrono>
00014 #include <vector>
00015 
00016 namespace Botan {
00017 
00018 class BOTAN_DLL SQL_Database
00019    {
00020    public:
00021       class BOTAN_DLL Statement
00022          {
00023          public:
00024             /* Bind statement parameters */
00025             virtual void bind(int column, const std::string& str) = 0;
00026 
00027             virtual void bind(int column, size_t i) = 0;
00028 
00029             virtual void bind(int column, std::chrono::system_clock::time_point time) = 0;
00030 
00031             virtual void bind(int column, const std::vector<byte>& blob) = 0;
00032 
00033             /* Get output */
00034             virtual std::pair<const byte*, size_t> get_blob(int column) = 0;
00035 
00036             virtual size_t get_size_t(int column) = 0;
00037 
00038             /* Run to completion */
00039             virtual void spin() = 0;
00040 
00041             /* Maybe update */
00042             virtual bool step() = 0;
00043 
00044             virtual ~Statement() {}
00045          };
00046 
00047       /*
00048       * Create a new statement for execution.
00049       * Use ?1, ?2, ?3, etc for parameters to set later with bind
00050       */
00051       virtual std::shared_ptr<Statement> new_statement(const std::string& base_sql) const = 0;
00052 
00053       virtual size_t row_count(const std::string& table_name) = 0;
00054 
00055       virtual void create_table(const std::string& table_schema) = 0;
00056 
00057       virtual ~SQL_Database() {}
00058 };
00059 
00060 }
00061 
00062 #endif