[pysqlite] Exporting Data to .CSV file

"Nuno Ribeiro" <[email protected]> Fri, 28 Nov 2008 03:38:34 +0000
Newsgroups gmane.comp.python.db.pysqlite.user
Message-ID <[email protected]>
Hello Guys!

I'm new to SQLite and I'm trying to make a small database for contacts. So,
let's say I have a TABLE CONTACTS with 3 rows:
- id integer primary key;
- Name text .... ;
. Phone text ...;

I'm having problems importing Data from sqlite3 from Python. I don't see how
to IMPORT a .csv file (FROM PYTHON), or in the other way, to EXPORT a .csv
(from SQLite).
From a python script, I can query the table. Let's say I have 3 records in
the Table.

1|Adam|444444444
2|Buck|555555555
3|Charles|666666666

from my python script I can view these results using os.system:

a = os.system('sqlite3 /Path/To/Database/contacts.db "select * from
contacts"')

But, I want also to save Data to a file.
I tried to import pysqlite and dump a table in CSV format but it didn't
work!

c.execute ( ''' .output file.csv ''')
c.execute ( ''' .separator , ''' )

I don't know if that is possible, i.e., to execute all SQLite commands using
pysqlite.
I didn't want to used Bash commands. Of course I can do it in a simple way
with cat command...
b = os.system('sqlite3 /Path/To/Database/contacts.db "select * from
contacts" | cat > file.csv')

But, I want to do all work from Python. Is it possible?

Any help please!

Thanks

_______________________________________________
list-pysqlite mailing list
list-pysqlite-FR6EJeJVuqdwc357pe9rcyQmJico6nz3epZhswDD4dQ@public.gmane.org
http://itsystementwicklung.de/cgi-bin/mailman/listinfo/list-pysqlite