title: sqlite3 in python 2.7: Comparing DB values with CSV values
body: <p>I have this code, it reads a csv file for the 2 first columns and appends a list from each row.</p>
  
  <pre><code>            with open(self.selected_file[0], 'rb') as csv_file:
                  itemids = []
                  csv_reader = csv.reader(csv_file, delimiter=',', quotechar="\"")
                  for row in csv_reader:
                      itemids.append([row[0], row[1]])
  </code></pre>
  
  <p>I have a database that already contains 2 tables, each for every item respectively. I wish to check every row of the csv file (which are pairs of strings). If both strings are unique to their respective table (meaning row[0] is unique to the first item table in my db, and row[1] unique to my second item table), then add those values to their respective tables. I tried the following:</p>
  
  <pre><code>        for item in itemids:
              first_itemids = db_cursor.execute('''SELECT itemid FROM items_one''').fetchall()
              second_itemds = db_cursor.execute('''SELECT itemid from items_two''').fetchall()
              try:
                  if not item[0] in first_itemids and not item[1] in second_itemids:
                      db_cursor.execute('''INSERT INTO items_one(itemid) VALUES (?)''', (item[0], ))
                      db_cursor.execute('''INSERT INTO items_two(itemid) VALUES (?)''', (item[1], ))
                      db_conn.commit()
  </code></pre>
  
  <p>However this check <code>if not item[0] in first_itemids and not item[1] in second_itemids</code> always evaluates to true, so duplicate non unique items are being added. I also tried the other way around 
      <code>
      if item[0] in first_itemids or item[1] in second_itemids:
          pass
  </code>
  but that also failed</p>
  
  <p>Note: These aren't my actual variable names, I don't know if same column names in different tables under the same DB can cause problems, but mines don't anyway - I just changed it for the sake of readability.</p>
  
  <p>Edit:</p>
  
  <p>I also tried checking each csv row before appending it to my item list like so:</p>
  
  <pre><code>            with open(self.selected_file[0], 'rb') as csv_file:
                  itemids = []
                  csv_reader = csv.reader(csv_file, delimiter=',', quotechar="\"")
                  first_itemids = db_cursor.execute('''SELECT itemid FROM items_one''').fetchall()
                  second_itemids = db_cursor.execute('''SELECT itemid from items_two''').fetchall()
                  for row in csv_reader:
                      if row[0] not in first_itemds and row[1] not in second_itemids:
                          itemids.append([row[0], row[1]])
  </code></pre>
  
  <p>And then just insert the lists' value to the DB. No good as well     </p>