/sqlite3cc

To get this branch, use:
bzr branch http://bzr.ed.am/sqlite3cc
1 by edam
- initial commit
1
/*
2 by edam
- further initial development
2
 * exception.cc
1 by edam
- initial commit
3
 *
22 by edam
updated email and web addresses
4
 * Copyright (C) 2009 Tim Marston <tim@ed.am>
1 by edam
- initial commit
5
 *
2 by edam
- further initial development
6
 * This file is part of sqlite3cc (hereafter referred to as "this program").
22 by edam
updated email and web addresses
7
 * See http://ed.am/dev/sqlite3cc for more information.
8
 *
9
 * This program is free software: you can redistribute it and/or modify it under
10
 * the terms of the GNU Lesser General Public License as published by the Free
11
 * Software Foundation, either version 3 of the License, or (at your option) any
12
 * later version.
13
 *
14
 * This program is distributed in the hope that it will be useful, but WITHOUT
15
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17
 * details.
1 by edam
- initial commit
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
2 by edam
- further initial development
23
#include <sqlite3cc/exception.h>
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
24
#include <sqlite3cc/connection.h>
1 by edam
- initial commit
25
#include <boost/assign/list_of.hpp>
26
#include <map>
27
#include <string>
28
29
30
sqlite::sqlite_error::sqlite_error(
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
31
	connection &connection,
13 by edam
- made basic_statement::step() protected, for use by query and command only
32
	int code )
33
	:
34
	_code( code ),
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
35
	_message( get_message( code ) + ": " + sqlite3_errmsg( connection._handle ) )
13 by edam
- made basic_statement::step() protected, for use by query and command only
36
{
37
}
38
39
40
sqlite::sqlite_error::sqlite_error(
9 by edam
- added NEWS
41
	int code )
1 by edam
- initial commit
42
	:
9 by edam
- added NEWS
43
	_code( code ),
44
	_message( get_message( code ) )
1 by edam
- initial commit
45
{
46
}
47
48
49
sqlite::sqlite_error::sqlite_error(
50
	const std::string &message,
9 by edam
- added NEWS
51
	int code )
1 by edam
- initial commit
52
	:
9 by edam
- added NEWS
53
	_code( code ),
1 by edam
- initial commit
54
	_message( message )
55
{
56
}
57
58
59
sqlite::sqlite_error::~sqlite_error() throw( )
60
{
61
}
62
63
9 by edam
- added NEWS
64
int sqlite::sqlite_error::get_code() const
1 by edam
- initial commit
65
{
9 by edam
- added NEWS
66
	return _code;
1 by edam
- initial commit
67
}
68
69
70
const char* sqlite::sqlite_error::what() const throw( )
71
{
72
	return _message.c_str();
73
}
74
75
9 by edam
- added NEWS
76
const std::string &sqlite::sqlite_error::get_message(
77
	int code )
1 by edam
- initial commit
78
{
79
	static const std::map< int, std::string > messages =
80
		boost::assign::map_list_of
81
		( SQLITE_OK, "Successful result" )
82
		( SQLITE_ERROR, "SQL error or missing database" )
83
		( SQLITE_INTERNAL, "Internal logic error in SQLite" )
84
		( SQLITE_PERM, "Access permission denied" )
85
		( SQLITE_ABORT, "Callback routine requested an abort" )
86
		( SQLITE_BUSY, "The database file is locked" )
87
		( SQLITE_LOCKED, "A table in the database is locked" )
88
		( SQLITE_NOMEM, "A malloc() failed" )
89
		( SQLITE_READONLY, "Attempt to write a readonly database" )
90
		( SQLITE_INTERRUPT, "Operation terminated by sqlite3_interrupt()" )
91
		( SQLITE_IOERR, "Some kind of disk I/O error occurred" )
92
		( SQLITE_CORRUPT, "The database disk image is malformed" )
93
		( SQLITE_NOTFOUND, "NOT USED. Table or record not found" )
94
		( SQLITE_FULL, "Insertion failed because database is full" )
95
		( SQLITE_CANTOPEN, "Unable to open the database file" )
96
		( SQLITE_PROTOCOL, "NOT USED. Database lock protocol error" )
97
		( SQLITE_EMPTY, "Database is empty" )
98
		( SQLITE_SCHEMA, "The database schema changed" )
99
		( SQLITE_TOOBIG, "String or BLOB exceeds size limit" )
100
		( SQLITE_CONSTRAINT, "Abort due to constraint violation" )
101
		( SQLITE_MISMATCH, "Data type mismatch" )
102
		( SQLITE_MISUSE, "Library used incorrectly" )
103
		( SQLITE_NOLFS, "Uses OS features not supported on host" )
104
		( SQLITE_AUTH, "Authorization denied" )
105
		( SQLITE_FORMAT, "Auxiliary database format error" )
106
		( SQLITE_RANGE, "2nd parameter to sqlite3_bind out of range" )
107
		( SQLITE_NOTADB, "File opened that is not a database file" )
108
		( SQLITE_ROW, "sqlite3_step() has another row ready" )
109
		( SQLITE_DONE, "sqlite3_step() has finished executing" );
110
111
	std::map< int, std::string >::const_iterator i =
9 by edam
- added NEWS
112
		messages.find( code );
1 by edam
- initial commit
113
	if( i == messages.end() )
114
		throw std::range_error( "bad sqlite error code" );
115
	return i->second;
116
}