/sqlite3cc

To get this branch, use:
bzr branch http://bzr.ed.am/sqlite3cc

« back to all changes in this revision

Viewing changes to src/exception.cpp

  • Committer: edam
  • Date: 2009-11-25 20:32:34 UTC
  • Revision ID: edam@waxworlds.org-20091125203234-24i7mzd60c7o46py
- initial commit
- basic support for: database, statements, commands, transactions, exceptions
- initial test app
- initial liscence and readme

Show diffs side-by-side

added added

removed removed

1
1
/*
2
 
 * exception.cc
 
2
 * exception.cpp
3
3
 *
4
4
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
5
5
 *
6
 
 * This file is part of sqlite3cc (hereafter referred to as "this program").
7
 
 * See http://www.waxworlds.org/edam/software/sqlite3cc for more information.
 
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.
8
8
 *
9
9
 * This program is free software: you can redistribute it and/or modify
10
10
 * it under the terms of the GNU Lesser General Public License as published
20
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
21
 */
22
22
 
23
 
#include <sqlite3cc/exception.h>
 
23
#include <sqlitepp/exception.hpp>
24
24
#include <boost/assign/list_of.hpp>
25
25
#include <map>
26
26
#include <string>
27
27
 
28
28
 
29
29
sqlite::sqlite_error::sqlite_error(
30
 
        int code )
 
30
        int error_code )
31
31
        :
32
 
        _code( code ),
33
 
        _message( get_message( code ) )
 
32
        _error_code( error_code ),
 
33
        _message( get_error_message( error_code ) )
34
34
{
35
35
}
36
36
 
37
37
 
38
38
sqlite::sqlite_error::sqlite_error(
39
39
        const std::string &message,
40
 
        int code )
 
40
        int error_code )
41
41
        :
42
 
        _code( code ),
 
42
        _error_code( error_code ),
43
43
        _message( message )
44
44
{
45
45
}
50
50
}
51
51
 
52
52
 
53
 
int sqlite::sqlite_error::get_code() const
 
53
int sqlite::sqlite_error::get_error_code() const
54
54
{
55
 
        return _code;
 
55
        return _error_code;
56
56
}
57
57
 
58
58
 
62
62
}
63
63
 
64
64
 
65
 
const std::string &sqlite::sqlite_error::get_message(
66
 
        int code )
 
65
const std::string &sqlite::sqlite_error::get_error_message(
 
66
        int error_code )
67
67
{
68
68
        static const std::map< int, std::string > messages =
69
69
                boost::assign::map_list_of
98
98
                ( SQLITE_DONE, "sqlite3_step() has finished executing" );
99
99
 
100
100
        std::map< int, std::string >::const_iterator i =
101
 
                messages.find( code );
 
101
                messages.find( error_code );
102
102
        if( i == messages.end() )
103
103
                throw std::range_error( "bad sqlite error code" );
104
104
        return i->second;