forked from pyodide/pyodide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable building sqlite3 into cpython (pyodide#352)
* Enable building sqlite3 into cpython
- Loading branch information
Showing
8 changed files
with
199 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
diff --git a/Modules/_sqlite/Modules/_sqlite/cache.c b/Modules/_sqlite/cache.c | ||
index 72b1f2c..2190bd4 100644 | ||
--- a/Modules/_sqlite/cache.c | ||
+++ b/Modules/_sqlite/cache.c | ||
@@ -24,6 +24,10 @@ | ||
#include "cache.h" | ||
#include <limits.h> | ||
|
||
+#ifndef MODULE_NAME | ||
+#define MODULE_NAME "sqlite" | ||
+#endif | ||
+ | ||
/* only used internally */ | ||
pysqlite_Node* pysqlite_new_node(PyObject* key, PyObject* data) | ||
{ | ||
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c | ||
index 6e05761..2d1ad34 100644 | ||
--- a/Modules/_sqlite/connection.c | ||
+++ b/Modules/_sqlite/connection.c | ||
@@ -45,6 +45,10 @@ | ||
#define HAVE_BACKUP_API | ||
#endif | ||
|
||
+#ifndef MODULE_NAME | ||
+#define MODULE_NAME "sqlite" | ||
+#endif | ||
+ | ||
_Py_IDENTIFIER(cursor); | ||
|
||
static const char * const begin_statements[] = { | ||
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c | ||
index 4ecb5b4..24b03c1 100644 | ||
--- a/Modules/_sqlite/cursor.c | ||
+++ b/Modules/_sqlite/cursor.c | ||
@@ -25,6 +25,10 @@ | ||
#include "module.h" | ||
#include "util.h" | ||
|
||
+#ifndef MODULE_NAME | ||
+#define MODULE_NAME "sqlite" | ||
+#endif | ||
+ | ||
PyObject* pysqlite_cursor_iternext(pysqlite_Cursor* self); | ||
|
||
static const char errmsg_fetch_across_rollback[] = "Cursor needed to be reset because of commit/rollback and can no longer be fetched from."; | ||
diff --git a/Modules/_sqlite/microprotocols.c b/Modules/_sqlite/microprotocols.c | ||
index 3d01872..7f98c2f 100644 | ||
--- a/Modules/_sqlite/microprotocols.c | ||
+++ b/Modules/_sqlite/microprotocols.c | ||
@@ -30,6 +30,10 @@ | ||
#include "microprotocols.h" | ||
#include "prepare_protocol.h" | ||
|
||
+#ifndef MODULE_NAME | ||
+#define MODULE_NAME "sqlite" | ||
+#endif | ||
+ | ||
|
||
/** the adapters registry **/ | ||
|
||
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c | ||
index 6befa07..4611574 100644 | ||
--- a/Modules/_sqlite/module.c | ||
+++ b/Modules/_sqlite/module.c | ||
@@ -33,6 +33,10 @@ | ||
#define HAVE_SHARED_CACHE | ||
#endif | ||
|
||
+#ifndef MODULE_NAME | ||
+#define MODULE_NAME "sqlite" | ||
+#endif | ||
+ | ||
/* static objects at module-level */ | ||
|
||
PyObject *pysqlite_Error = NULL; | ||
diff --git a/Modules/_sqlite/prepare_protocol.c b/Modules/_sqlite/prepare_protocol.c | ||
index f2c85f9..14969bb 100644 | ||
--- a/Modules/_sqlite/prepare_protocol.c | ||
+++ b/Modules/_sqlite/prepare_protocol.c | ||
@@ -23,6 +23,10 @@ | ||
|
||
#include "prepare_protocol.h" | ||
|
||
+#ifndef MODULE_NAME | ||
+#define MODULE_NAME "sqlite" | ||
+#endif | ||
+ | ||
int pysqlite_prepare_protocol_init(pysqlite_PrepareProtocol* self, PyObject* args, PyObject* kwargs) | ||
{ | ||
return 0; | ||
diff --git a/Modules/_sqlite/row.c b/Modules/_sqlite/row.c | ||
index ec2c788..ce65e62 100644 | ||
--- a/Modules/_sqlite/row.c | ||
+++ b/Modules/_sqlite/row.c | ||
@@ -24,6 +24,10 @@ | ||
#include "row.h" | ||
#include "cursor.h" | ||
|
||
+#ifndef MODULE_NAME | ||
+#define MODULE_NAME "sqlite" | ||
+#endif | ||
+ | ||
void pysqlite_row_dealloc(pysqlite_Row* self) | ||
{ | ||
Py_XDECREF(self->data); | ||
diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c | ||
index 3869088..6d16049 100644 | ||
--- a/Modules/_sqlite/statement.c | ||
+++ b/Modules/_sqlite/statement.c | ||
@@ -28,6 +28,10 @@ | ||
#include "prepare_protocol.h" | ||
#include "util.h" | ||
|
||
+#ifndef MODULE_NAME | ||
+#define MODULE_NAME "sqlite" | ||
+#endif | ||
+ | ||
/* prototypes */ | ||
static int pysqlite_check_remaining_sql(const char* tail); | ||
|
||
diff --git a/Modules/_sqlite/util.c b/Modules/_sqlite/util.c | ||
index 3fa671d..bd12f51 100644 | ||
--- a/Modules/_sqlite/util.c | ||
+++ b/Modules/_sqlite/util.c | ||
@@ -24,6 +24,10 @@ | ||
#include "module.h" | ||
#include "connection.h" | ||
|
||
+#ifndef MODULE_NAME | ||
+#define MODULE_NAME "sqlite" | ||
+#endif | ||
+ | ||
int pysqlite_step(sqlite3_stmt* statement, pysqlite_Connection* connection) | ||
{ | ||
int rc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ ensurepip | |
idlelib | ||
lib2to3 | ||
multiprocessing | ||
sqlite3 | ||
tkinter | ||
turtle.py | ||
turtledemo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
def test_sqlite3(selenium): | ||
content = selenium.run(""" | ||
import sqlite3 | ||
with sqlite3.connect(':memory:') as conn: | ||
c = conn.cursor() | ||
c.execute(''' | ||
CREATE TABLE people ( | ||
first_name VARCHAR, | ||
last_name VARCHAR | ||
) | ||
''') | ||
c.execute("INSERT INTO people VALUES ('John', 'Doe')") | ||
c.execute("INSERT INTO people VALUES ('Jane', 'Smith')") | ||
c.execute("INSERT INTO people VALUES ('Michael', 'Jordan')") | ||
c.execute("SELECT * FROM people") | ||
""") | ||
content = selenium.run("c.fetchall()") | ||
assert len(content) == 3 | ||
assert content[0][0] == 'John' | ||
assert content[1][0] == 'Jane' | ||
assert content[2][0] == 'Michael' |