import sqlite3
# Get the file name from the user
file_name = input("Enter the file name: ")
# Open the file and read the data
with open(file_name, "r") as file:
lines = file.readlines()
# Process the data and create a list of tuples
data = []
x = 2
xref = 1
yref = 148
l = 6
year = 1991
values = range(12)
date = ""
value = 0
monthNum = 0
for line in lines[6:]:
monthValue = []
line.strip()
year = 1990 + (l-5) % 11.
for i in values:
monthValue.append(line.split())
#monthValue[i] = line.split()
monthNum = i+1
date = "1/" + str(monthNum) + "/" + str(year)
value = monthValue[i]
data.append((xref, yref, date, value))
# Create a connection to the database
conn = sqlite3.connect("data.db")
c = conn.cursor()
# Create the table if it doesn't already exist
c.execute('''CREATE TABLE IF NOT EXISTS data
(Xref REAL, Yref REAL, Date TEXT, Value REAL)''')
# Insert the data into the table
c.executemany('INSERT INTO data VALUES (:xref, :yref, :date, :value)', data)
# Commit the changes and close the connection
conn.commit()
conn.close()
The last line in the above code is flagging up an error "InterfaceError: Error binding parameter 3 - probably unsupported type." parameter 3 is the date string, which consists of multiple mini strings as shown in the top line. Am I doing this incorrectly? why is it flagging this up as an issue?
I have tried replacing the executemany parameters with '?' and '%s' and also tried changing the double quotes around the mini strings into single quotes such as '1/' instead of "1/" on the top line
EDIT: I have added a smaller version of the loop that i am using to demonstrate more accurately how my program works
EDIT 2: monthValue array stores a list of values read in from a line from a file separated by a space. the line in the file looks something like the below
100 250 400 300 100 230 300 405 300 530 510 350
and then each value is assigned to a month from the monthNum variable being i+1
EDIT 3: Just been informed that 'parameter 3' is referring to the 4th paramter as it starts from 0, so this is the value parameter. here is more info about the value parameter to clarify
value parameter is assigned to one of the numbers in the example line in edit 2. for month 1, value stores the first value of that line, for month 2 it stores the second value of that line etc. The associated date for each value is therefore different and each date and value pair are stored in data for the relevant field. Hope this helps
EDIT 4: The code isnt that long so I will just post the whole code to make it simpler. The file being read from has several lines of integer values separated by a space. each value is the data for a specific year and month. the 10 rows are for 10 different years and the 12 columns are for 12 different months. See below for an example
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630
3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630