blob: 52554bf51f3c355354b860949b3bd1930443044d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
// file : odb/sqlite/error.cxx
// author : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
#include <sqlite3.h>
#include <new> // std::bad_alloc
#include <string>
#include <odb/sqlite/connection.hxx>
#include <odb/sqlite/exceptions.hxx>
using namespace std;
namespace odb
{
namespace sqlite
{
void
translate_error (int e, connection& c)
{
sqlite3* h (c.handle ());
int ee (sqlite3_extended_errcode (h));
string m;
switch (e)
{
case SQLITE_NOMEM:
{
throw bad_alloc ();
}
case SQLITE_MISUSE:
{
// In case of SQLITE_MISUSE, error code/message may or may not
// be set.
//
ee = e;
m = "SQLite API misuse";
break;
}
case SQLITE_LOCKED:
{
if (ee != SQLITE_LOCKED_SHAREDCACHE)
throw deadlock (); // The DROP TABLE special case.
// Getting SQLITE_LOCKED_SHAREDCACHE here means we don't have
// the unlock notify support. Translate this to timeout.
//
throw timeout ();
}
case SQLITE_BUSY:
case SQLITE_IOERR:
{
if (e != SQLITE_IOERR || ee == SQLITE_IOERR_BLOCKED)
throw timeout ();
// Fall throught.
}
default:
{
m = sqlite3_errmsg (h);
break;
}
}
throw database_exception (e, ee, m);
}
}
}
|