Content-Length: 4352 | pFad | http://github.com/RustPython/RustPython/pull/5996.patch
thub.com
From 3403b9b8bae9a9f95edb5cc89679009561123648 Mon Sep 17 00:00:00 2001
From: Jiseok CHOI
Date: Thu, 17 Jul 2025 17:38:11 +0900
Subject: [PATCH] Align SQL comment parsing with CPython
---
Lib/test/test_sqlite3/test_dbapi.py | 6 ----
stdlib/src/sqlite.rs | 50 +++++++++++++++++++----------
2 files changed, 33 insertions(+), 23 deletions(-)
diff --git a/Lib/test/test_sqlite3/test_dbapi.py b/Lib/test/test_sqlite3/test_dbapi.py
index 56cd8f8a68..3ef18111bc 100644
--- a/Lib/test/test_sqlite3/test_dbapi.py
+++ b/Lib/test/test_sqlite3/test_dbapi.py
@@ -769,8 +769,6 @@ def test_execute_illegal_sql(self):
with self.assertRaises(sqlite.OperationalError):
self.cu.execute("select asdf")
- # TODO: RUSTPYTHON
- @unittest.expectedFailure
def test_execute_multiple_statements(self):
msg = "You can only execute one statement at a time"
dataset = (
@@ -793,8 +791,6 @@ def test_execute_multiple_statements(self):
with self.assertRaisesRegex(sqlite.ProgrammingError, msg):
self.cu.execute(query)
- # TODO: RUSTPYTHON
- @unittest.expectedFailure
def test_execute_with_appended_comments(self):
dataset = (
"select 1; -- foo bar",
@@ -963,8 +959,6 @@ def test_rowcount_update_returning(self):
self.assertEqual(self.cu.fetchone()[0], 1)
self.assertEqual(self.cu.rowcount, 1)
- # TODO: RUSTPYTHON
- @unittest.expectedFailure
def test_rowcount_prefixed_with_comment(self):
# gh-79579: rowcount is updated even if query is prefixed with comments
self.cu.execute("""
diff --git a/stdlib/src/sqlite.rs b/stdlib/src/sqlite.rs
index 744da0cf6e..1edbfddb70 100644
--- a/stdlib/src/sqlite.rs
+++ b/stdlib/src/sqlite.rs
@@ -3068,36 +3068,52 @@ mod _sqlite {
}
fn lstrip_sql(sql: &[u8]) -> Option<&[u8]> {
- let mut pos = sql;
- loop {
- match pos.first()? {
+ let mut pos = 0;
+
+ // This loop is borrowed from the SQLite source code.
+ while let Some(t_char) = sql.get(pos) {
+ match t_char {
b' ' | b'\t' | b'\x0c' | b'\n' | b'\r' => {
- pos = &pos[1..];
+ // Skip whitespace.
+ pos += 1;
}
b'-' => {
- if *pos.get(1)? == b'-' {
- // line comments
- pos = &pos[2..];
- while *pos.first()? != b'\n' {
- pos = &pos[1..];
+ // Skip line comments.
+ if sql.get(pos + 1) == Some(&b'-') {
+ pos += 2;
+ while let Some(&ch) = sql.get(pos) {
+ if ch == b'\n' {
+ break;
+ }
+ pos += 1;
}
+ let _ = sql.get(pos)?;
} else {
- return Some(pos);
+ return Some(&sql[pos..]);
}
}
b'/' => {
- if *pos.get(1)? == b'*' {
- // c style comments
- pos = &pos[2..];
- while *pos.first()? != b'*' || *pos.get(1)? != b'/' {
- pos = &pos[1..];
+ // Skip C style comments.
+ if sql.get(pos + 1) == Some(&b'*') {
+ pos += 2;
+ while let Some(&ch) = sql.get(pos) {
+ if ch == b'*' && sql.get(pos + 1) == Some(&b'/') {
+ break;
+ }
+ pos += 1;
}
+ let _ = sql.get(pos)?;
+ pos += 2;
} else {
- return Some(pos);
+ return Some(&sql[pos..]);
}
}
- _ => return Some(pos),
+ _ => {
+ return Some(&sql[pos..]);
+ }
}
}
+
+ None
}
}
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/RustPython/RustPython/pull/5996.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy