By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 2,031 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

Pysqlite text data importing problem

P: 14
hey 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 same working directory, i don't know the exact syntax for doing that.

Also can someone help to rename the file name to current date and time rather than user specified name.

Thanks in advance

Expand|Select|Wrap|Line Numbers
  1. #Connecting to Database
  2. import os
  3. import sqlite3
  4. from pysqlite2 import dbapi2 as sqlite
  5. connection = sqlite.connect('Photos.db')
  6. memoryConnection = sqlite.connect(':memory:')
  7. cursor = connection.cursor()
  8.  
  9. #Writing  Data to Database
  10. #Getting data from Text File
  11.  
  12. TXT_FILE = os.getcwd() + "\\Photos.txt"
  13. cursor.execute('CREATE TABLE photos (Name VARCHAR(100) PRIMARY KEY, Date INTEGER, Make VARCHAR(50), Tag VARCHAR(100))') 
  14. cursor.execute('SEPARATOR "|"')
  15. cursor.execute('IMPORT Photos.txt Photos')
  16. connection.commit()
Nov 26 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.