I don't know why it's unable to add this value, even though i've defined it as a string: Here's my code:
import gspread
import sqlite3
import oauth2client
from oauth2client.service_account import ServiceAccountCredentials
import time
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name("secret key.json",scope)
gc = gspread.authorize(credentials)
wks = gc.open('File').sheet1
arr = wks.col_values(8)
class Tables():
def __init__(self,id_number=0,NationalGridReference = ""):
self.id_number = id_number
self.NationalGridReference = NationalGridReference
self.connection = sqlite3.connect("Conversion")
self.cursor = self.connection.cursor()
self.cursor.execute('''CREATE TABLE IF NOT EXISTS {} (
id INTEGER PRIMARY KEY,
{} TEXT
);'''.format(name,arr[0]))
def load_info(self,id_number):
self.cursor.execute('''
SELECT * FROM {}
WHERE id = {}
'''.format(name,id_number))
results = self.cursor.fetchall()
self.id_number = id_number
self.NationalGridReference = results
print("From ",name,"value",self.id_number,"is",self.NationalGridReference)
def add_info(self,id_number,value):
self.cursor.execute('''
INSERT INTO {} VALUES(
{},{})'''.format(name,id_number,value))
self.connection.commit()
self.cursor.execute('''
SELECT * FROM {}
WHERE id = {}
'''.format(name,id_number))
global name
name = "Converting"
tbl1 = Tables()
tbl2 = Tables()
#tbl1.add_info(1,'Armaan','Khaitan',17)
#tbl1.add_info(2,'Vikas','Khaitan',47)
#tbl1.add_info(3,'Nandini','Chatterjee',47)
#tbl1.connection.commit()
#for i in range(1,4):
# tbl1.load_info(i)
print(arr[0])
print(arr[2])
tbl1.add_info(2,arr[2])
#url = f'https://uk.images.search.yahoo.com/search/images;_ylt=AwrIfln4XytkPt4DqAAM34lQ;_ylu=Y29sbwNpcjIEcG9zAzEEdnRpZAMEc2VjA3BpdnM-?p=aesthetic+#{insert}+gym+diagram+instructions&fr2=piv-web&type=E210GB91082G0&fr=mcafee'#
#page = requests.get(url)
#soup = BeautifulSoup(page.content,'html.parser')
#holder = soup.find('img')
#if holder['alt'] == "":
# holder['alt'] = "Something"
#for i in range(1,865):
# tbl1.add_info(i,arr[i])
tbl1.load_info(1)
tbl1.connection.close()
returns:
sqlite3.OperationalError: near 10074: syntax error
using a table of values that have values like this:
SU 10020 31197
SU 10074 31063
SU 16110 27173
SU 17136 26567