0

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

Raphael_LK
  • 199
  • 2
  • 13
  • 1
    Is the path to foo.sqlite correct? – Karsten W. Jul 24 '13 at 14:35
  • 1
    I don't believe you that you actually ran that R code. `dbDriver('RSQLite')` will return an error. You meant `dbDriver('SQLite')`. And then `dbConnect` needs to be passed the driver object as well, so even that would throw an error. – joran Jul 24 '13 at 14:51
  • Yes @joran you're right but the code above is not what I wrote in my R interpreter. Otherwise I would have tolf you about the errors. You should have overlooked these mistypings to focus on the real problem – Raphael_LK Jul 24 '13 at 15:02
  • 2
    @Raphael_LK This website is about programming, which is a fairly precise art. Typos are frequently the issue, which is why people here emphasize that you post [reproducible examples](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Thomas Jul 24 '13 at 15:07
  • 3
    @Raphael_LK ha ha ha ha ha ha. Are you serious? You ask us if you are doing something wrong then tell us to ignore what you are doing wrong, to focus on what it is that you are doing wrong. Come on. – Simon O'Hanlon Jul 24 '13 at 15:08

1 Answers1

1

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...

Spacedman
  • 92,590
  • 12
  • 140
  • 224