# pull the info we need from the URL early. Even though URL
# is immutable, we don't want any in-place changes to the URL
# to affect things
- passphrase = url.password or ""
- url_query = dict(url.query)
+ ip = self.identifier_preparer
+ passphrase = ip.quote_identifier(url.password or "")
+ query_pragmas = {
+ prag: ip.quote_identifier(url.query[prag])
+ for prag in self.pragmas
+ if url.query.get(prag) is not None
+ }
def on_connect(conn):
cursor = conn.cursor()
- cursor.execute('pragma key="%s"' % passphrase)
- for prag in self.pragmas:
- value = url_query.get(prag, None)
- if value is not None:
- cursor.execute('pragma %s="%s"' % (prag, value))
+ cursor.execute(f"pragma key={passphrase}")
+ for prag, value in query_pragmas.items():
+ cursor.execute(f"pragma {prag}={value}")
+ print(query_pragmas)
cursor.close()
if super_on_connect:
"""SQLite-specific tests."""
import os
+from tempfile import mkstemp
from sqlalchemy import and_
from sqlalchemy import Column
@testing.only_on("sqlite+pysqlcipher")
def test_pysqlcipher_connects(self):
"""test #6586"""
- str_url = str(testing.db.url)
+ f, name = mkstemp()
+ str_url = str(testing.db.url.set(database=name))
e = create_engine(str_url)
with e.connect() as conn:
eq_(conn.scalar(text("select 1")), 1)
+ e.dispose()
+ os.close(f)
+ os.unlink(name)
+
+ @testing.only_on("sqlite+pysqlcipher")
+ def test_pysqlcipher_escaped(self):
+ """test #6586"""
+ f, name = mkstemp()
+ new_url = testing.db.url.set(
+ password='tes"ting',
+ database=name,
+ query={"cipher": 'aes-"select 1', "kdf_iter": "64000"},
+ )
+ e = create_engine(new_url)
+
+ with e.connect() as conn:
+ eq_(conn.scalar(text("select 1")), 1)
+
+ e.dispose()
+ os.close(f)
+ os.unlink(name)
+
@testing.provide_metadata
def test_extra_reserved_words(self, connection):
"""Tests reserved words in identifiers.