Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap raw SQL query string with sqlalchemy.text() #78

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/tools/troubleshoot_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import uuid

import sqlcipher3
from sqlalchemy import exc, create_engine
from sqlalchemy import exc, create_engine, text

from ..models.base import get_session, drop_sessions, get_db_key
from ..views.menu import get_input
Expand Down Expand Up @@ -48,7 +48,7 @@ def get_pragma_key():
def query_vault_db():
""" Attempt a query against the database """
try:
get_session(True).execute('SELECT * FROM sqlite_master')
get_session(True).execute(text('SELECT * FROM sqlite_master'))
return True
except exc.DatabaseError as e:
# print('Database Error: %s' % e)
Expand All @@ -75,9 +75,9 @@ def attempt_dummy_encrypted_db(db_path):
module=sqlcipher3)
# engine = create_engine('sqlite:///' + db_path)
connection = engine.connect()
connection.execute('CREATE TABLE foo (a int)')
connection.execute('INSERT INTO foo (a) VALUES (123)')
result_proxy = connection.execute('SELECT * FROM foo')
connection.execute(text('CREATE TABLE foo (a int)'))
connection.execute(text('INSERT INTO foo (a) VALUES (123)'))
result_proxy = connection.execute(text('SELECT * FROM foo'))
return True if result_proxy.fetchall() == [(123,)] else False


Expand All @@ -87,7 +87,7 @@ def verify_if_dummy_db_is_encrypted(db_path):
engine = create_engine('sqlite:///' + db_path)
connection = engine.connect()
try:
connection.execute('SELECT * FROM sqlite_master')
connection.execute(text('SELECT * FROM sqlite_master'))

# If query is successful, then the database is not encrypted
return False
Expand Down
4 changes: 2 additions & 2 deletions src/unittest/tools/test_troubleshoot_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from tempfile import NamedTemporaryFile

import sqlcipher3
from sqlalchemy import create_engine
from sqlalchemy import create_engine, text
from sqlalchemy.orm import Session

from ..base import BaseTest
Expand Down Expand Up @@ -75,7 +75,7 @@ def test_query_vault_db(self):
engine = create_engine(
'sqlite+pysqlcipher://:abcd@//' + f.name, module=sqlcipher3)
connection = engine.connect()
connection.execute('CREATE TABLE foo (a int)')
connection.execute(text('CREATE TABLE foo (a int)'))

global_scope['db_file'] = f.name

Expand Down