471,593 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,593 software developers and data experts.

Pysqlite text data importing problem

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()
  9. #Writing  Data to Database
  10. #Getting data from Text File
  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
0 1253

Post your reply

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

Similar topics

6 posts views Thread by Rob Cowie | last post: by
8 posts views Thread by rdrink | last post: by
14 posts views Thread by Nader Emami | last post: by
5 posts views Thread by =?ISO-8859-1?Q?Gerhard_H=E4ring?= | last post: by
4 posts views Thread by Tilman Kispersky | last post: by
4 posts views Thread by Astley Le Jasper | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.