sqlite error?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Salerno

    #1

    sqlite error?

    Am I using the ? placeholder wrong in this example?


    t = ('hi', 'bye')

    self.connection .execute("INSER T INTO Personal (firstName, lastName)
    VALUES ?", t)



    Traceback (most recent call last):
    File "C:\Python25\my scripts\labdb\d bapp.py", line 93, in OnSaveRecord
    self.save_to_da tabase(textfiel d_values)
    File "C:\Python25\my scripts\labdb\d bapp.py", line 97, in save_to_databas e
    self.connection .execute("INSER T INTO Personal (firstName, lastName)
    VALUES ?", t)
    sqlite3.Operati onalError: near "?": syntax error
  • BartlebyScrivener

    #2
    Re: sqlite error?

    >self.connectio n.execute("INSE RT INTO Personal (firstName, lastName)
    VALUES ?", t)

    John,

    I'm no expert, but try

    self.connection .execute("INSER T INTO Personal (firstName, lastName)
    VALUES ?, ?", t)

    Comment

    • thunderfoot@gmail.com

      #3
      Re: sqlite error?


      John Salerno wrote:
      Am I using the ? placeholder wrong in this example?
      >
      >
      t = ('hi', 'bye')
      >
      self.connection .execute("INSER T INTO Personal (firstName, lastName)
      VALUES ?", t)
      >
      >
      >
      Traceback (most recent call last):
      File "C:\Python25\my scripts\labdb\d bapp.py", line 93, in OnSaveRecord
      self.save_to_da tabase(textfiel d_values)
      File "C:\Python25\my scripts\labdb\d bapp.py", line 97, in save_to_databas e
      self.connection .execute("INSER T INTO Personal (firstName, lastName)
      VALUES ?", t)
      sqlite3.Operati onalError: near "?": syntax error
      I believe you're missing the parens around your VALUES to insert. Also,
      you need 1 placeholder per argument inserted, not just one for the
      entire argument list. Try:

      self.connection .execute("INSER T INTO Personal (firstName, lastName)
      VALUES (?, ?)", t)

      HTH

      Comment

      • John Salerno

        #4
        Re: sqlite error?

        thunderfoot@gma il.com wrote:
        John Salerno wrote:
        >Am I using the ? placeholder wrong in this example?
        >>
        >>
        >t = ('hi', 'bye')
        >>
        >self.connectio n.execute("INSE RT INTO Personal (firstName, lastName)
        >VALUES ?", t)
        >>
        >>
        >>
        >Traceback (most recent call last):
        > File "C:\Python25\my scripts\labdb\d bapp.py", line 93, in OnSaveRecord
        > self.save_to_da tabase(textfiel d_values)
        > File "C:\Python25\my scripts\labdb\d bapp.py", line 97, in save_to_databas e
        > self.connection .execute("INSER T INTO Personal (firstName, lastName)
        >VALUES ?", t)
        >sqlite3.Operat ionalError: near "?": syntax error
        >
        I believe you're missing the parens around your VALUES to insert. Also,
        you need 1 placeholder per argument inserted, not just one for the
        entire argument list. Try:
        >
        self.connection .execute("INSER T INTO Personal (firstName, lastName)
        VALUES (?, ?)", t)
        >
        HTH
        >
        Thanks guys. I'll try this. I thought the ? stood for the whole tuple.

        Comment

        • Frank Millman

          #5
          Re: sqlite error?


          John Salerno wrote:
          Am I using the ? placeholder wrong in this example?
          >
          >
          t = ('hi', 'bye')
          >
          self.connection .execute("INSER T INTO Personal (firstName, lastName)
          VALUES ?", t)
          >
          [snip]
          >
          Thanks guys. I'll try this. I thought the ? stood for the whole tuple.
          Definitely not. You could have a sql command like this -

          cur.execute("UP DATE table SET col1 = ?, col2 = ? WHERE col3 = ? AND
          col4 = ?",(1,2,3,4) )

          The parameters could be scattered throughout the command. Therefore the
          substitution is one-for-one from left to right using the values in the
          tuple.

          Frank Millman

          Comment

          • John Salerno

            #6
            Re: sqlite error?

            Frank Millman wrote:
            Definitely not. You could have a sql command like this -
            >
            cur.execute("UP DATE table SET col1 = ?, col2 = ? WHERE col3 = ? AND
            col4 = ?",(1,2,3,4) )
            >
            The parameters could be scattered throughout the command. Therefore the
            substitution is one-for-one from left to right using the values in the
            tuple.
            >
            Thanks! The example I was looking at in the docs didn't use parentheses,
            but I also didn't connect that with the fact that it was only using a
            one-tuple! :)

            Comment

            Working...