1 // Copyright 2011 Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "utils/sqlite/exceptions.hpp"
35 #include "utils/format/macros.hpp"
36 #include "utils/sqlite/c_gate.hpp"
38 namespace sqlite
= utils::sqlite
;
41 /// Constructs a new error with a plain-text message.
43 /// \param message The plain-text error message.
44 sqlite::error::error(const std::string
& message
) :
45 std::runtime_error(message
)
50 /// Destructor for the error.
51 sqlite::error::~error(void) throw()
56 /// Constructs a new error.
58 /// \param api_function_ The name of the API function that caused the error.
59 /// \param message_ The plain-text error message provided by SQLite.
60 sqlite::api_error::api_error(const std::string
& api_function_
,
61 const std::string
& message_
) :
63 _api_function(api_function_
)
68 /// Destructor for the error.
69 sqlite::api_error::~api_error(void) throw()
74 /// Constructs a new api_error with the message in the SQLite database.
76 /// \param database_ The SQLite database.
77 /// \param api_function_ The name of the SQLite C API function that caused the
80 /// \return A new api_error with the retrieved message.
82 sqlite::api_error::from_database(database
& database_
,
83 const std::string
& api_function_
)
85 ::sqlite3
* c_db
= database_c_gate(database_
).c_database();
86 return api_error(api_function_
, ::sqlite3_errmsg(c_db
));
90 /// Gets the name of the SQlite C API function that caused this error.
92 /// \return The name of the function.
94 sqlite::api_error::api_function(void) const
100 /// Constructs a new error.
102 /// \param name_ The name of the unknown column.
103 sqlite::invalid_column_error::invalid_column_error(const std::string
& name_
) :
104 error(F("Unknown column '%s'") % name_
),
110 /// Destructor for the error.
111 sqlite::invalid_column_error::~invalid_column_error(void) throw()
116 /// Gets the name of the column that could not be found.
118 /// \return The name of the column requested by the user.
120 sqlite::invalid_column_error::column_name(void) const