1

I don't know how to correctly insert values into a mysql database.

I think it's a pretty simple fix but I'm new to mysql.

...

sqllist = "INSERT INTO station_fenelon (date, time, outsidetemp, outsidehumidity) VALUES (%s, %s, %f, %f)"

record = [('2019-06-21', '12:12:11', '414.44', '42.4')]

cursor.execute(sqllist, record)
sql.commit()

I get the error: Not all parameters were used in the SQL statement

Chris
  • 15,819
  • 3
  • 24
  • 37
John
  • 43
  • 7

1 Answers1

-1

I would recommend using an ORM (Object Relational Mapper) like SQLAlchemy. If you are writing to your database over a flask application, try using the flask_sqlalchemy extension to support your software. It's quite useful as it can be easily paired with the alembic library for database migrations.

If you use flask_sqlalchemy, then inserting into your database will become as simple as creating a new software object, and then adding it to your database session. Your database session I believe is a representation of your active connection, and adding to it is like writing to the log that is built on top of it. Then you would simply commit your changes to the log, and watch as they propagate into your database.

ekram67
  • 13
  • 4
  • Is there a simple way of just fixing my problem? – John May 29 '19 at 17:39
  • I'm more used to an ORM, so maybe I jumped the gun when trying to answer your question. I notice in your SQL statement, your values have %s and %f placeholders. I looked at the https://www.python.org/dev/peps/pep-0249/ guide, and in the section for 'paramstyle', I saw that the SQL statement can expect ANSI C printf format codes. Judging from this, what other people have said in this same post, and https://stackoverflow.com/questions/20818155/not-all-parameters-were-used-in-the-sql-statement-python-mysql, if you change the %d to %s, that should solve your problem. – ekram67 May 30 '19 at 18:01