File: dummy_driver.h

package info (click to toggle)
cppdb 0.3.1+dfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 668 kB
  • sloc: cpp: 7,373; sh: 133; ansic: 72; makefile: 7
file content (173 lines) | stat: -rw-r--r-- 4,948 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
///////////////////////////////////////////////////////////////////////////////
//                                                                             
//  Copyright (C) 2010-2011  Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>     
//                                                                             
//  Distributed under:
//
//                   the Boost Software License, Version 1.0.
//              (See accompanying file LICENSE_1_0.txt or copy at 
//                     http://www.boost.org/LICENSE_1_0.txt)
//
//  or (at your opinion) under:
//
//                               The MIT License
//                 (See accompanying file MIT.txt or a copy at
//              http://www.opensource.org/licenses/mit-license.php)
//
///////////////////////////////////////////////////////////////////////////////
#include <cppdb/backend.h>

namespace dummy {

	int results = 0;
	int statements = 0;
	int connections = 0;
	int drivers = 0;

	class result : public cppdb::backend::result {
	public:
		virtual next_row has_next()
		{
			return next_row_unknown;
		}
		virtual bool next() 
		{
			if(called_)
				return false;
			called_ = true;
			return true;
		}
		virtual bool fetch(int,short &)
		{
			return false;
		}
		virtual bool fetch(int,unsigned short &){ return false; }
		virtual bool fetch(int,int &){ return false; }
		virtual bool fetch(int,unsigned &){ return false; }
		virtual bool fetch(int,long &){ return false; }
		virtual bool fetch(int,unsigned long &){ return false; }
		virtual bool fetch(int,long long &){ return false; }
		virtual bool fetch(int,unsigned long long &){ return false; }
		virtual bool fetch(int,float &){ return false; }
		virtual bool fetch(int,double &){ return false; }
		virtual bool fetch(int,long double &){ return false; }
		virtual bool fetch(int,std::string &){ return false; }
		virtual bool fetch(int,std::ostream &){ return false; }
		virtual bool fetch(int,std::tm &){ return false; }
		virtual bool is_null(int){ return true; }
		virtual int cols() { return 10; }
		virtual int name_to_column(std::string const &) {
			return -1;
		}
		virtual std::string column_to_name(int) 
		{
			throw cppdb::not_supported_by_backend("unsupported");
		}

		// End of API
		result() : called_(false) 
		{
			results++;
		}
		~result()
		{
			results--;
		}
		
	private:
		bool called_;
	};

	class statement : public cppdb::backend::statement {
	public:
		virtual void reset(){}
		std::string const &sql_query() { return q_; }
		virtual void bind(int,std::string const &) {}
		virtual void bind(int,char const *){}
		virtual void bind(int,char const *,char const *){}
		virtual void bind(int,std::tm const &){}
		virtual void bind(int,std::istream &){}
		virtual void bind(int,int){}
		virtual void bind(int,unsigned){}
		virtual void bind(int,long){}
		virtual void bind(int,unsigned long){}
		virtual void bind(int,long long){}
		virtual void bind(int,unsigned long long){}
		virtual void bind(int,double){}
		virtual void bind(int,long double){}
		virtual void bind_null(int){}
		virtual long long sequence_last(std::string const &/*sequence*/) { throw cppdb::not_supported_by_backend("unsupported"); }
		virtual unsigned long long affected() { return 0; }
		virtual result *query() { return new result(); }
		virtual void exec() {}
		statement(std::string const &q) : q_(q) 
		{
			statements++;
		}
		~statement()
		{
			statements--;
		}
	private:
		std::string q_;
	};



	extern "C" {
		typedef cppdb::backend::connection *cppdb_backend_connect_function(cppdb::connection_info const &ci);
	}


	class connection : public cppdb::backend::connection {
	public:
		connection(cppdb::connection_info const &info) : cppdb::backend::connection(info) 
		{
			connections++;
		}
		~connection()
		{
			connections--;
		}
		virtual void begin(){}
		virtual void commit(){}
		virtual void rollback(){}
		virtual statement *prepare_statement(std::string const &q) { return new statement(q); }
		virtual statement *create_statement(std::string const &q) { return new statement(q); }
		virtual std::string escape(std::string const &) { throw cppdb::not_supported_by_backend("not supported"); }
		virtual std::string escape(char const *) { throw cppdb::not_supported_by_backend("not supported"); }
		virtual std::string escape(char const *,char const *) { throw cppdb::not_supported_by_backend("not supported"); }
		virtual std::string driver() { return "dummy"; }
		virtual std::string engine() { return "dummy"; }
		
	};


	class loadable_driver : public cppdb::backend::loadable_driver {
	public:
		loadable_driver() 
		{
			drivers++;
		}
		bool in_use()
		{
			return connections > 0;
		}
		connection *open(cppdb::connection_info const &cs)
		{
			return new connection(cs);
		}
		~loadable_driver()
		{
			drivers--;
		}
	};

} // dummy

extern "C" {
	cppdb::backend::connection *dummy_connect_function(cppdb::connection_info const &ci)
	{
		return new dummy::connection(ci);
	}
}