4
* Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
6
* This file is part of sqlitepp (hereafter referred to as "this program").
7
* See http://www.waxworlds.org/edam/software/sqlitepp for more information.
9
* This program is free software: you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published
11
* by the Free Software Foundation, either version 3 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Lesser General Public License for more details.
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/>.
23
#include <sqlitepp/exception.hpp>
24
#include <boost/assign/list_of.hpp>
29
sqlite::sqlite_error::sqlite_error(
32
_error_code( error_code ),
33
_message( get_error_message( error_code ) )
38
sqlite::sqlite_error::sqlite_error(
39
const std::string &message,
42
_error_code( error_code ),
48
sqlite::sqlite_error::~sqlite_error() throw( )
53
int sqlite::sqlite_error::get_error_code() const
59
const char* sqlite::sqlite_error::what() const throw( )
61
return _message.c_str();
65
const std::string &sqlite::sqlite_error::get_error_message(
68
static const std::map< int, std::string > messages =
69
boost::assign::map_list_of
70
( SQLITE_OK, "Successful result" )
71
( SQLITE_ERROR, "SQL error or missing database" )
72
( SQLITE_INTERNAL, "Internal logic error in SQLite" )
73
( SQLITE_PERM, "Access permission denied" )
74
( SQLITE_ABORT, "Callback routine requested an abort" )
75
( SQLITE_BUSY, "The database file is locked" )
76
( SQLITE_LOCKED, "A table in the database is locked" )
77
( SQLITE_NOMEM, "A malloc() failed" )
78
( SQLITE_READONLY, "Attempt to write a readonly database" )
79
( SQLITE_INTERRUPT, "Operation terminated by sqlite3_interrupt()" )
80
( SQLITE_IOERR, "Some kind of disk I/O error occurred" )
81
( SQLITE_CORRUPT, "The database disk image is malformed" )
82
( SQLITE_NOTFOUND, "NOT USED. Table or record not found" )
83
( SQLITE_FULL, "Insertion failed because database is full" )
84
( SQLITE_CANTOPEN, "Unable to open the database file" )
85
( SQLITE_PROTOCOL, "NOT USED. Database lock protocol error" )
86
( SQLITE_EMPTY, "Database is empty" )
87
( SQLITE_SCHEMA, "The database schema changed" )
88
( SQLITE_TOOBIG, "String or BLOB exceeds size limit" )
89
( SQLITE_CONSTRAINT, "Abort due to constraint violation" )
90
( SQLITE_MISMATCH, "Data type mismatch" )
91
( SQLITE_MISUSE, "Library used incorrectly" )
92
( SQLITE_NOLFS, "Uses OS features not supported on host" )
93
( SQLITE_AUTH, "Authorization denied" )
94
( SQLITE_FORMAT, "Auxiliary database format error" )
95
( SQLITE_RANGE, "2nd parameter to sqlite3_bind out of range" )
96
( SQLITE_NOTADB, "File opened that is not a database file" )
97
( SQLITE_ROW, "sqlite3_step() has another row ready" )
98
( SQLITE_DONE, "sqlite3_step() has finished executing" );
100
std::map< int, std::string >::const_iterator i =
101
messages.find( error_code );
102
if( i == messages.end() )
103
throw std::range_error( "bad sqlite error code" );