[kwlug-disc] Matching strings containing single quotes in Sqlite3 SELECT statement.
John Driezen
jdriezen at sympatico.ca
Wed Sep 19 10:37:09 EDT 2018
How do a I match a string containing single quotes in an Sqlite3 SELECT
statement?
The python code follows. It should output four date and price pairs,
but I am getting empty lists as output.
import sqlite3
import os
DB_FILE = '/home/john/scrap_prices_scraper/scrapmetalprices.db'
# check for existing database file
if os.path.isfile(DB_FILE):
connection = sqlite3.connect(DB_FILE)
cursor = connection.execute ("SELECT * from PRICES WHERE
MATERIAL='Pop Cans/UBC''s'")
prices=[]
dates=[]
for row in cursor:
dates.append(row[4]) # store dates in list
prices.append(row[2]) # store price in list
connection.close
print (dates,prices)
else:
print("Database does not exist.")
raise SystemExit
John Driezen
jdriezen at sympatico.ca
More information about the kwlug-disc
mailing list