History

add hg and python

cinap_lenrek committed 15 years ago

Commit 4bb9e221 parent 987265c3706 files · +1228772 −-233Browse files

Showing the changes to sys/src/cmd/python/Modules/_sqlite/util.c (1 of 3706 files). Show all

Unified · Split

sys/src/cmd/python/Modules/_sqlite/util.c+96−0
@@ -0,0 +1,96 @@
1+/* util.c - various utility functions
2+ *
3+ * Copyright (C) 2005-2006 Gerhard H�ring <gh@ghaering.de>
4+ *
5+ * This file is part of pysqlite.
6+ *
7+ * This software is provided 'as-is', without any express or implied
8+ * warranty. In no event will the authors be held liable for any damages
9+ * arising from the use of this software.
10+ *
11+ * Permission is granted to anyone to use this software for any purpose,
12+ * including commercial applications, and to alter it and redistribute it
13+ * freely, subject to the following restrictions:
14+ *
15+ * 1. The origin of this software must not be misrepresented; you must not
16+ * claim that you wrote the original software. If you use this software
17+ * in a product, an acknowledgment in the product documentation would be
18+ * appreciated but is not required.
19+ * 2. Altered source versions must be plainly marked as such, and must not be
20+ * misrepresented as being the original software.
21+ * 3. This notice may not be removed or altered from any source distribution.
22+ */
23+
24+#include "module.h"
25+#include "connection.h"
26+
27+int _sqlite_step_with_busyhandler(sqlite3_stmt* statement, Connection* connection
28+)
29+{
30+ int rc;
31+
32+ Py_BEGIN_ALLOW_THREADS
33+ rc = sqlite3_step(statement);
34+ Py_END_ALLOW_THREADS
35+
36+ return rc;
37+}
38+
39+/**
40+ * Checks the SQLite error code and sets the appropriate DB-API exception.
41+ * Returns the error code (0 means no error occurred).
42+ */
43+int _seterror(sqlite3* db)
44+{
45+ int errorcode;
46+
47+ errorcode = sqlite3_errcode(db);
48+
49+ switch (errorcode)
50+ {
51+ case SQLITE_OK:
52+ PyErr_Clear();
53+ break;
54+ case SQLITE_INTERNAL:
55+ case SQLITE_NOTFOUND:
56+ PyErr_SetString(InternalError, sqlite3_errmsg(db));
57+ break;
58+ case SQLITE_NOMEM:
59+ (void)PyErr_NoMemory();
60+ break;
61+ case SQLITE_ERROR:
62+ case SQLITE_PERM:
63+ case SQLITE_ABORT:
64+ case SQLITE_BUSY:
65+ case SQLITE_LOCKED:
66+ case SQLITE_READONLY:
67+ case SQLITE_INTERRUPT:
68+ case SQLITE_IOERR:
69+ case SQLITE_FULL:
70+ case SQLITE_CANTOPEN:
71+ case SQLITE_PROTOCOL:
72+ case SQLITE_EMPTY:
73+ case SQLITE_SCHEMA:
74+ PyErr_SetString(OperationalError, sqlite3_errmsg(db));
75+ break;
76+ case SQLITE_CORRUPT:
77+ PyErr_SetString(DatabaseError, sqlite3_errmsg(db));
78+ break;
79+ case SQLITE_TOOBIG:
80+ PyErr_SetString(DataError, sqlite3_errmsg(db));
81+ break;
82+ case SQLITE_CONSTRAINT:
83+ case SQLITE_MISMATCH:
84+ PyErr_SetString(IntegrityError, sqlite3_errmsg(db));
85+ break;
86+ case SQLITE_MISUSE:
87+ PyErr_SetString(ProgrammingError, sqlite3_errmsg(db));
88+ break;
89+ default:
90+ PyErr_SetString(DatabaseError, sqlite3_errmsg(db));
91+ break;
92+ }
93+
94+ return errorcode;
95+}
96+

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t