Reputation: 5972
I used the following command in order to create my own database:
sqlite3 mydb.db
I used the follwing command for making my table:
CREATE TABLE mytable (hostName CHAR(50) PRIMARY KEY, content TEXT);
And this is part of my script:
hostName='mywebsite.com'
cur=con.cursor()
cur.execute('SELECT hostName FROM mytable WHERE hostName="'+hostName+'"')
data=cur.fetchall()
cont=session.get('http://'+hostName).content
cur.execute('INSERT INTO mytable (hostName,content) VALUES (\''+hostName+'\',\''+str(cont)+'\')')
But when I get the website content it doesn't write to the table when the content is not short.
Maybe there is a parameter larger than TEXT
.
Upvotes: 0
Views: 27
Reputation: 42768
Never format contents of a column directly into a SQL-statement. Use placeholders instead:
cur.execute("SELECT hostName FROM mytable WHERE hostName=?", [hostName])
data = cur.fetchall()
cont = session.get('http://%s' % hostName).content
cur.execute("INSERT INTO mytable (hostName,content) VALUES (?,?)", [hostName, cont])
Upvotes: 2