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

Sqlalchemy MonetDb dialet question #49

Open
yyx100 opened this issue Mar 28, 2022 · 7 comments
Open

Sqlalchemy MonetDb dialet question #49

yyx100 opened this issue Mar 28, 2022 · 7 comments

Comments

@yyx100
Copy link

yyx100 commented Mar 28, 2022

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

@yyx100
Copy link
Author

yyx100 commented Mar 28, 2022

I temporarily changed the code to:

` def has_table(self, connection, table_name, schema=None):
# seems like case gets folded in pg_class...
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())`

@MitchellWeg
Copy link
Member

MitchellWeg commented Mar 30, 2022

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.

@thevoiddancer
Copy link

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.

@MitchellWeg
Copy link
Member

We currently have different priorities, but we try to maintain the project. PR's are always welcome!

@njnes
Copy link

njnes commented Jul 24, 2023

also work on the sql alchemy 2.0 driver/dialect is underway.

@thevoiddancer
Copy link

@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.

@thevoiddancer
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants