placeholder for sql varchar

Asked

Viewed 34 times

0

I’m making a program that reads the output of Arduino and sends to a SQLITE3 database.

You’re making this mistake:

cursor.execute("INSERT INTO reciclagem_data (personID, nome) VALUES (%s,%s)", (pieces[0], pieces[1]))
OperationalError: near "%": syntax error

personID is the UID of an RFID card and the name is simply the name.
I researched and found that the best type of date for UID would be to sweep. I think the mistake has to do with this subject.

What should I do to solve this problem?

  • 1

    Would not be VALUES (?, ?)?

  • @bfavaretto, can you explain why? I’m struggling. I know that %s is for string and %d is for integer.

  • @bfavaretto, you’re making this mistake with your suggestion. Programmingerror: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly Recommended that you Instead just switch your application to Unicode strings.

  • This error seems to be caused by some data, must be one of the names, probably something accentuated. About why use as I said, I saw in documentation.

  • @bfavaretto, you’re making this mistake with your suggestion. Programmingerror: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly Recommended that you Instead just switch your application to Unicode strings

  • 1

    So this is what seems to be caused by a question of encoding/strings with accents. I leave it to someone else to say, I’m not an expert in python or sqlite.

  • 1

    The name he was using contained a cedilla c, ç. Just changed to c.

Show 2 more comments

1 answer

0

In Sql, information is separated by a point and comma. ;

INSERT INTO reciclagem_data (personID, nome) VALUES (%s,%s)
('Valor1','valor3')
('Valor2','valor3')
('Valor3','valor3')

check your shipment if by one of his words was not so:

 ('Va'lor4','val'or4'),

No Sql will not!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.