wireservice / csvkit

A suite of utilities for converting to and working with CSV, the king of tabular file formats.
https://csvkit.readthedocs.io
MIT License
5.9k stars 605 forks source link

SQL savepoint issue using csvsql #1249

Closed Jackyto closed 1 month ago

Jackyto commented 1 month ago

Hello,

I tried several times and option combinations to insert my file into my database using csvsql but when I do so, I obtain a

ProgrammingError: (mysql.connector.errors.ProgrammingError) 1305 (42000): SAVEPOINT sa_savepoint_1 does not exist

There is how I intend to use csvsql

csvsql -d ';' --db mysql+mysqlconnector://{username}:{password}@localhost:3306/{my_db} --insert --tables test positpan.csv

I joined my file I used

positpan.csv

My distribution

Distributor ID: Ubuntu Description: Ubuntu 20.04.6 LTS Release: 20.04 Codename: focal

python -v gives Python 3.8.10

I have csvkit 2.0.0 installed

I hope someone has already encountered this issue, I do not really understand what I have done wrong, this is the basic usage of csvsql Thanks in advance for your answers

Regards

Pierre

jpmckinney commented 1 month ago

Can you use pip list to share the version of agate-sql and whichever MySQL Python library is installed?

Jackyto commented 1 month ago

Sure (I think I can see it coming)

agate 1.9.0
agate-dbf 0.2.2
agate-excel 0.4.1
agate-sql 0.7.0 MySQL-python 1.2.5

jpmckinney commented 1 month ago

Aha, yeah, this was fixed in agate-sql 0.7.1. You can upgrade to 0.7.2 with pip install -U agate-sql

Jackyto commented 1 month ago

I did update but I have the following error now TypeError: 'webauthn_callback' is an invalid keyword argument for this function Do I need to open another issue ?

jpmckinney commented 1 month ago

Can you run the command with -v? I don't think anything about that keyword.

Jackyto commented 1 month ago

Sure

Traceback (most recent call last):
  File "/home/jackyto/.local/bin/csvsql", line 8, in <module>
    sys.exit(launch_new_instance())
  File "/home/jackyto/.local/lib/python3.8/site-packages/csvkit/utilities/csvsql.py", line 255, in launch_new_instance
    utility.run()
  File "/home/jackyto/.local/lib/python3.8/site-packages/csvkit/cli.py", line 133, in run
    self.main()
  File "/home/jackyto/.local/lib/python3.8/site-packages/csvkit/utilities/csvsql.py", line 144, in main
    self.connection = engine.connect()
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 3276, in connect
    return self._connection_cls(self)
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 146, in __init__
    self._dbapi_connection = engine.raw_connection()
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 3300, in raw_connection
    return self.pool.connect()
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 449, in connect
    return _ConnectionFairy._checkout(self)
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 1263, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 712, in checkout
    rec = pool._do_get()
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/pool/impl.py", line 180, in _do_get
    self._dec_overflow()
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/pool/impl.py", line 177, in _do_get
    return self._create_connection()
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 390, in _create_connection
    return _ConnectionRecord(self)
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 674, in __init__
    self.__connect()
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 901, in __connect
    pool.logger.debug("Error on connect(): %s", e)
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 146, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 896, in __connect
    self.dbapi_connection = connection = pool._invoke_creator(self)
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/engine/create.py", line 643, in connect
    return dialect.connect(*cargs, **cparams)
  File "/home/jackyto/.local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 620, in connect
    return self.loaded_dbapi.connect(*cargs, **cparams)
  File "/home/jackyto/.local/lib/python3.8/site-packages/mysql/connector/pooling.py", line 322, in connect
    return CMySQLConnection(*args, **kwargs)
  File "/home/jackyto/.local/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 144, in __init__
    self.connect(**kwargs)
  File "/home/jackyto/.local/lib/python3.8/site-packages/mysql/connector/abstracts.py", line 1360, in connect
    self._open_connection()
  File "/home/jackyto/.local/lib/python3.8/site-packages/mysql/connector/connection_cext.py", line 327, in _open_connection
    self._cmysql.connect(**cnx_kwargs)
TypeError: 'webauthn_callback' is an invalid keyword argument for this function

I only have basic knowledge in python, I don't know how to analyze those kind of compilation errors

jpmckinney commented 1 month ago

Okay, and what is the full command you are running?

Jackyto commented 1 month ago

csvsql -d ';' --db mysql+mysqlconnector://username:password@localhost:3306/database --insert --tables test --create-if-not-exists positpan.csv -v

jpmckinney commented 1 month ago

Oh, right, MySQL-python is ancient (last released 2014). You need to install pip install mysql-connector-python instead

jpmckinney commented 1 month ago

And pip uninstall MySQL-python just to be safe.

Jackyto commented 1 month ago

Requirement already satisfied: mysql-connector-python

I removed MySQL-python but I have the same issue.

Nevertheless, I managed to make it work on my production server (those issues are on my machine). I will try to find the issue but I think it is my multiple versions of python which cause that.

Thank you again for the troubleshooting and cheers for your magnificent import tool !

Wish you the best

Pierre

jpmckinney commented 1 month ago

It could be that you need to upgrade pip install -U mysql-connector-python which added webauthn_callback support in 8.2.0