/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
28
29
sqlite::sqlite_error::sqlite_error(
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
30
	connection &connection,
13 by edam
- made basic_statement::step() protected, for use by query and command only
31
	int code )
32
	:
33
	_code( code ),
16 by edam
- renamed database to connection to better identify what it is (would database_connection be better though?)
34
	_message( get_message( code ) + ": " + sqlite3_errmsg( connection._handle ) )
13 by edam
- made basic_statement::step() protected, for use by query and command only
35
{
36
}
37
38
39
sqlite::sqlite_error::sqlite_error(
9 by edam
- added NEWS
40
	int code )
1 by edam
- initial commit
41
	:
9 by edam
- added NEWS
42
	_code( code ),
43
	_message( get_message( code ) )
1 by edam
- initial commit
44
{
45
}
46
47
48
sqlite::sqlite_error::sqlite_error(
49
	const std::string &message,
9 by edam
- added NEWS
50
	int code )
1 by edam
- initial commit
51
	:
9 by edam
- added NEWS
52
	_code( code ),
1 by edam
- initial commit
53
	_message( message )
54
{
55
}
56
57
58
sqlite::sqlite_error::~sqlite_error() throw( )
59
{
60
}
61
62
9 by edam
- added NEWS
63
int sqlite::sqlite_error::get_code() const
1 by edam
- initial commit
64
{
9 by edam
- added NEWS
65
	return _code;
1 by edam
- initial commit
66
}
67
68
69
const char* sqlite::sqlite_error::what() const throw( )
70
{
71
	return _message.c_str();
72
}
73
74
9 by edam
- added NEWS
75
const std::string &sqlite::sqlite_error::get_message(
76
	int code )
1 by edam
- initial commit
77
{
78
	static const std::map< int, std::string > messages =
79
		boost::assign::map_list_of
80
		( SQLITE_OK, "Successful result" )
81
		( SQLITE_ERROR, "SQL error or missing database" )
82
		( SQLITE_INTERNAL, "Internal logic error in SQLite" )
83
		( SQLITE_PERM, "Access permission denied" )
84
		( SQLITE_ABORT, "Callback routine requested an abort" )
85
		( SQLITE_BUSY, "The database file is locked" )
86
		( SQLITE_LOCKED, "A table in the database is locked" )
87
		( SQLITE_NOMEM, "A malloc() failed" )
88
		( SQLITE_READONLY, "Attempt to write a readonly database" )
89
		( SQLITE_INTERRUPT, "Operation terminated by sqlite3_interrupt()" )
90
		( SQLITE_IOERR, "Some kind of disk I/O error occurred" )
91
		( SQLITE_CORRUPT, "The database disk image is malformed" )
92
		( SQLITE_NOTFOUND, "NOT USED. Table or record not found" )
93
		( SQLITE_FULL, "Insertion failed because database is full" )
94
		( SQLITE_CANTOPEN, "Unable to open the database file" )
95
		( SQLITE_PROTOCOL, "NOT USED. Database lock protocol error" )
96
		( SQLITE_EMPTY, "Database is empty" )
97
		( SQLITE_SCHEMA, "The database schema changed" )
98
		( SQLITE_TOOBIG, "String or BLOB exceeds size limit" )
99
		( SQLITE_CONSTRAINT, "Abort due to constraint violation" )
100
		( SQLITE_MISMATCH, "Data type mismatch" )
101
		( SQLITE_MISUSE, "Library used incorrectly" )
102
		( SQLITE_NOLFS, "Uses OS features not supported on host" )
103
		( SQLITE_AUTH, "Authorization denied" )
104
		( SQLITE_FORMAT, "Auxiliary database format error" )
105
		( SQLITE_RANGE, "2nd parameter to sqlite3_bind out of range" )
106
		( SQLITE_NOTADB, "File opened that is not a database file" )
107
		( SQLITE_ROW, "sqlite3_step() has another row ready" )
108
		( SQLITE_DONE, "sqlite3_step() has finished executing" );
109
110
	std::map< int, std::string >::const_iterator i =
9 by edam
- added NEWS
111
		messages.find( code );
1 by edam
- initial commit
112
	if( i == messages.end() )
113
		throw std::range_error( "bad sqlite error code" );
114
	return i->second;
115
}