Box error: 7 values for 8 columns sqlite3.OperationalError



  • There's a code that put the tape in the OBD system.

    def insertMult(connect,array):
        connect.execute("INSERT INTO Goods (Gtin,Length,Width,Height,Weight,Multuplicator,Gtin2) \
            VALUES ("+array[0]+","+array[1]+","+array[2]+","+array[3]+","+ array[4]+","+array[6]+","+array[7]+")");
        connect.commit()
    

    It was all right, now there's a need for Id auto - increment

    Added the field to the OBD with Id. I'm starting the code and getting the puppet. ♪

    NOT NULL constraint failed: Goods.Id
    

    Changed the code to:

    def insertMult(connect,array):
        connect.execute("INSERT INTO Goods (Id,Gtin,Length,Width,Height,Weight,Multuplicator,Gtin2) \
            VALUES ("+array[0]+","+array[1]+","+array[2]+","+array[3]+","+ array[4]+","+array[6]+","+array[7]+")");
        connect.commit()
    

    Now box 7 values in 8 table points, as Id auto incrementI don't give you the same mistake. Also transmitted 8 values, same error. ♪ ♪
    Help!



  • I'd do it a little different:

    def insertMult(connect,array):
        connect.execute("INSERT INTO Goods (Gtin,Length,Width,Height,Weight,Multuplicator,Gtin2) \
                         VALUES (?,?,?,?,?,?,?)", array)
    

    array - shall contain exactly 7 variables with correct data types - the data types shall be as shown in the table

    1. if id - auto_increment, this field doesn't have to be clearly indicated.
    2. Always try to use prepared statements/bind variables/parameters when working with https://en.wikipedia.org/wiki/Literal_(computer_programming) - it'll keep you safe from SQL injections, and it's likely to work faster, as RDBMS will use the already ready implementation plan (execution plan) and can be saved to review the request, check the syntax and privileges, and build an optimal implementation plan for the request.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2