title: Sqlite insert not working with python
body: <p>I'm working with sqlite3 on python 2.7 and I am facing a problem with a many-to-many relationship. I have a table from which I am fetching its primary key like this</p>
  
  <pre><code>current.execute("SELECT ExtensionID FROM tblExtensionLookup where ExtensionName = ?",[ext])
  </code></pre>
  
  <p>and then i am fetching another primary key from another table</p>
  
  <pre><code>current.execute("SELECT HostID FROM tblHostLookup where HostName = ?",[host])
  </code></pre>
  
  <p>now what i am doing is i have a third table with these two keys as foreign keys and i inserted them like this</p>
  
  <pre><code>current.execute("INSERT INTO tblExtensionHistory VALUES(?,?)",[Hid,Eid])
  </code></pre>
  
  <p>The problem is i don't know why but the last insertion is not working it keeps giving errors. Now what i have tried is:</p>
  
  <p>First I thought it was because I have an autoincrement primary id for the last mapping table which I didn't provide, but isn't it supposed to consider itself as it's auto incremented? However I went ahead and tried adding Null,None,0 but nothing works. </p>
  
  <p>Secondly I thought maybe because i'm not getting the values from tables above so I tried printing it out and it shows so it works.</p>
  
  <p>Any suggestions what I am doing wrong here?</p>
  
  <p><strong>EDIT :</strong>
  When i don't provide primary key i get error as</p>
  
  <pre><code>The table has three columns but you provided only two values
  </code></pre>
  
  <p>and when i do provide them as None,Null or 0 it says </p>
  
  <pre><code>Parameter 0 is not supported probably because of unsupported type
  </code></pre>
  
  <p>I tried implementing the @abarnet way but still keeps saying parameter 0 not supported</p>
  
  <pre><code>connection = sqlite3.connect('WebInfrastructureScan.db')
      with connection:
          current = connection.cursor()
          current.execute("SELECT ExtensionID FROM tblExtensionLookup where ExtensionName = ?",[ext])
          Eid = current.fetchone()
          print Eid
          current.execute("SELECT HostID FROM tblHostLookup where HostName = ?",[host])
          Hid = current.fetchone()
          print Hid
  
          current.execute("INSERT INTO tblExtensionHistory(HostID,ExtensionID) VALUES(?,?)",[Hid,Eid])
  </code></pre>
  
  <p><strong>EDIT 2 :</strong></p>
  
  <p>The database schema is :</p>
  
  <p>table 1:</p>
  
  <pre><code>CREATE TABLE tblHostLookup ( 
  HostID INTEGER PRIMARY KEY AUTOINCREMENT, 
  HostName TEXT);
  </code></pre>
  
  <p>table2:  </p>
  
  <pre><code> CREATE TABLE tblExtensionLookup ( 
   ExtensionID INTEGER PRIMARY KEY AUTOINCREMENT, 
   ExtensionName TEXT);
  </code></pre>
  
  <p>table3:</p>
  
  <pre><code>CREATE TABLE tblExtensionHistory (
  ExtensionHistoryID INTEGER PRIMARY KEY AUTOINCREMENT,
  HostID INTEGER,
  FOREIGN KEY(HostID) REFERENCES tblHostLookup(HostID),
  ExtensionID INTEGER,
  FOREIGN KEY(ExtensionID) REFERENCES tblExtensionLookup(ExtensionID));
  </code></pre>