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

5
  • 1
    Is the path to foo.sqlite correct? Commented Jul 24, 2013 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. Commented Jul 24, 2013 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 Commented Jul 24, 2013 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. Commented Jul 24, 2013 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. Commented Jul 24, 2013 at 15:08

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.