Open yyx100 opened 2 years ago
I temporarily changed the code to:
` def has_table(self, connection, table_name, schema=None):
if schema is None:
cursor = connection.execute(
sql.text(
# "select name "
# "from sys.tables "
# "where system = false "
# "and type = 0 "
# "and name=:name",
# bindparams=[
# sql.bindparam('name', util.text_type(table_name),
# type_=sqltypes.Unicode)]
"""
select name
from sys.tables
where system = false
and type = 0
and name='{name}'
""".format(name=table_name)
)
)
else:
cursor = connection.execute(
sql.text(
"""
SELECT tables.name
FROM sys.tables, sys.schemas
WHERE tables.system = FALSE
AND tables.schema_id = schemas.id
AND type = 0
AND tables.name = '{name}'
AND schemas.name = '{schema}'
""".format(name=table_name, schema=schema)
#"SELECT tables.name"
#"FROM sys.tables, sys.schemas"
#"WHERE tables.system = FALSE"
#" AND tables.schema_id = schemas.id"
#" AND type = 0"
#"AND tables.name = :name "
#"AND schemas.name = :schema" ,
#bindparams=[
# sql.bindparam('name',
# util.text_type(table_name),
# type_=sqltypes.Unicode),
# sql.bindparam('schema',
# util.text_type(schema),
# type_=sqltypes.Unicode)]
)
)
return bool(cursor.first())`
Did you clone the repo or did you install it from Pypi? this should be fixed in the newer versions. These aren't on Pypi however.
Hi @MitchellWeg , got a question here. I've just encountered the same problem when I tried running metadata.create_all
on a declarative base. I've looked into dialect.py as well as sqlalchemy documentation and it seems that the text object is created incorrectly.
This is the current implementation:
sql.text(
"SELECT tables.name "
"FROM sys.tables, sys.schemas "
"WHERE tables.system = FALSE "
"AND tables.schema_id = schemas.id "
"AND type = 0 "
"AND tables.name = :name "
"AND schemas.name = :schema",
bindparams=[
sql.bindparam('name',
util.text_type(table_name),
type_=sqltypes.Unicode),
sql.bindparam('schema',
util.text_type(schema),
type_=sqltypes.Unicode)]
)
but this code executes correctly:
sql.text(
"SELECT tables.name "
"FROM sys.tables, sys.schemas "
"WHERE tables.system = FALSE "
"AND tables.schema_id = schemas.id "
"AND type = 0 "
"AND tables.name = :name "
"AND schemas.name = :schema"
).bindparams(
sql.bindparam(
'name', util.text_type(table_name), type_=sqltypes.Unicode
),
sql.bindparam(
'schema', util.text_type(schema), type_=sqltypes.Unicode
),
)
So it looks like bindparams need to be moved from a keyword to a method.
So the question is - is the project still being maintained and can do a PR for this? Latest version was from 2017 and there's mention that this is fixed but it's definitely not fixed on pypi and it looks like it's not fixed here either.
We currently have different priorities, but we try to maintain the project. PR's are always welcome!
also work on the sql alchemy 2.0 driver/dialect is underway.
@MitchellWeg I'd like to fix this, as the solution is already ready, but I seem to be having problems setting up the dev environment. If I understand correctly, to set up the dev env I should do: make venv/ make setup or should I do something else?
Thanks.
Alternatively, in the meantime. For anyone encountering the same error. A workaround is something like this:
for table in MonetDBModel.metadata.tables.values():
table.create(MDBengine)
I got following error: TypeError("text() got an unexpected keyword argument 'bindparams'"). I found that: dialet .py "has_table" method is using sql.text(...., bindparams...). I changed the SQL text to be static without parameter marking to get it working. I'm new to MonetDb. Is this related to my SqlAchemy version (1.4) or some incompatible driver?
pip3 list SQLAlchemy 1.4.23 sqlalchemy-monetdb 1.0.0 pymonetdb 1.5.1