Hi folks
i am facing this problem in my following codes where i am trying to create a database using pysqlite and load data from text file where data is arranged in this form "Birthday2|12/5/2008|HTC|this is my birthday"
but i could connect to the database, create it into my current working directory but i can't load the data from my text file in the same working directory into sqlite database created. please any idea or tips
thanks in advance
i am facing this problem in my following codes where i am trying to create a database using pysqlite and load data from text file where data is arranged in this form "Birthday2|12/5/2008|HTC|this is my birthday"
but i could connect to the database, create it into my current working directory but i can't load the data from my text file in the same working directory into sqlite database created. please any idea or tips
thanks in advance
Code:
Codes
import os
import sqlite3
from pysqlite2 import dbapi2 as sqlite3
#Connecting to Database
connection = sqlite3.connect('Photos.db')
memoryConnection = sqlite3.connect(':memory:')
cursor = connection.cursor()
cursor.execute('CREATE TABLE photos (Name VARCHAR(100) PRIMARY KEY, Date INTEGER, Make VARCHAR(50), Tag VARCHAR(100))')
#reading text file
text_file = open("/home/waseem/Project2/photos.txt", "r")
whole_thing = text_file.read()
print whole_thing
#writing text data into database
for row in text_file:
cursor.execute('INSERT INTO photos VALUES(Name,Date,Make,Tag)', row)
#cursor.commit()
text_file.close()