Raphael_LK
Raphael_LK

Reputation: 309

How to read a database created with python with R

I've created a database with the python package sqlite3.

import sqlite3
conn=sqlite3.connect('foo.sqlite')
c=conn.cursor()
c.execute('CREATE TABLE foo (bar1 int, bar2 int)')
conn.commit()
conn.close

Then for statistical purposes I try to read this database with R (I use the R package RSQLite)

library('RSQLite')
drv=dbDriver('SQLite')
foo=dbConnect(drv,'foo.sqlite')

If I want to list the table I've just created with Python

dbListTables(foo)

R says that the database is empty :

character(0)

Am I doing something wrong or does R cannot read a Python database ?

Thanks for your help

Upvotes: 0

Views: 244

Answers (1)

Spacedman
Spacedman

Reputation: 94202

Try closing your database connection in python, rather than just instantiating the close method:

conn.close()

Spot the difference? Then it all works for me.

> dbListTables(foo)
[1] "foo"

although it all works for me even if I don't close the connection, and even if I've not quit python after the commit. So, umm...

Upvotes: 1

Related Questions