SQLAlchemy 2.0 (released 2023-01-26) requires that raw SQL queries be wrapped by sqlalchemy.text.
The general solution for this error message is to pass the query text to sqlalchemy.text()
from sqlalchemy import text
...
query = text("SELECT * FROM some_table WHERE column1 > 1")
However in this case the OP is using pandasql, which expects a string. There does not seem to be a straightforward way to make pandasql compatible with SQLAlchemy >= 2.0, and the package seems to be unmaintained, so the only solutions are to find a fork that has fixed the problem (there are some), fork the project yourself and fix it, or downgrade your SQLAlchemy installation using your Python package manager. For example, if you use pip:
python3 -m pip install --upgrade 'sqlalchemy<2.0'
Answer from snakecharmerb on Stack OverflowSQLAlchemy 2.0 (released 2023-01-26) requires that raw SQL queries be wrapped by sqlalchemy.text.
The general solution for this error message is to pass the query text to sqlalchemy.text()
from sqlalchemy import text
...
query = text("SELECT * FROM some_table WHERE column1 > 1")
However in this case the OP is using pandasql, which expects a string. There does not seem to be a straightforward way to make pandasql compatible with SQLAlchemy >= 2.0, and the package seems to be unmaintained, so the only solutions are to find a fork that has fixed the problem (there are some), fork the project yourself and fix it, or downgrade your SQLAlchemy installation using your Python package manager. For example, if you use pip:
python3 -m pip install --upgrade 'sqlalchemy<2.0'
I had same problem with ciavam, and following the comments from snakecharmerb, the problem was solved after wrapped the query string with text():
import pandas as pd
import sqlalchemy as sa
connection = engine.connect()
result = connection.execute("select * from myTables;")
This code returned an error:
AttributeError: 'str' object has no attribute '_execute_on_connection'
So, I wrapped the query as:
connection = engine.connect()
query = sa.text("select * from myTables;")
result = connection.execute(query)
With this correction, I was able to use the result as a dataframe:
my_table = pd.read_sql(query, con=engine)
There is something wrong with this function. It shows no errors, but when I try to run it, It says AttributeError: 'str' object has no attribute 'current'. (BTW, i am trying to run it as a flet on spyder)
def leapyears(e):
days_in_month = {1: 31, 3: 31, 4: 30, 5:31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31 }
month = int(EnterMonth_text.value)
year = int(EnterYear_text.value)
if year % 100 == 0:
if year % 400 == 0:
leap_year = True
elif year % 4 == 0:
leap_year = True
else:
leap_year = False
if month == 2 :
if leap_year:
days_in_month[2] = 29
else:
days_in_month[2]= 28
output_textfield.value= days_in_month[month]
page.update()
db.perform_query fails when called with a string: sqlalchemy not an executable object/no attribute '_execute_on_connection'
AttributeError: 'Engine' object has no attribute 'execute'
sqlite - python - 'str' object has no attribute 'execute' - Stack Overflow
AttributeError: 'str' object has no attribute 'get'
I don't know what's wrong, but at the very least:
db.connect
should be
db.connect()
e.g. call the function.
OK. S.Lott had the answer, I just found an other bug :)
Do Not Do This.
class SqliteDB:
connection = ''
curser = ''
It doesn't "declare" any variables. This isn't C++ or Java.
Do this.
class SqliteDB:
def __init__( self ):
self.connection = None
self.cursor= None
Just replace:
key = Key(mybucket)
with:
mybucket = "foo"
bucketobj = conn.get_bucket(mybucket)
mykey = Key(bucketobj)
Expanding on sth's comment, you can't pass a string, it needs to be a bucket object.
Key expects a bucket object as its first parameter (possibly created by conn.create_bucket()).
It looks like mybucket isn't a bucket, but a string, so the call fails.