views:

77

answers:

1

I have a mysql server running and can connect to it from my Django ORM. Can't connect using the rdflib functionality. How can I debug this problem? Thanks.

rdflib 2.4.2, python 2.6, MySQL Community 5.1.42

Trace:

configString = "host=localhost,user=root,password=...,db=..."  
print configString

host=localhost,user=root,password=...,db=...

store = plugin.get('MySQL', Store)('rdfstore')  
print store  

Traceback (most recent call last):
File "D:\GR\Personal\Career\Python\medCE\semantix\foaf_rdf.py", line 26, in print store
File "C:\Program Files\Python26\lib\site-packages\rdflib\store\MySQL.py", line 1029, in __repr__ c=self._db.cursor()
AttributeError: 'NoneType' object has no attribute 'cursor'

rt = store.open(configString,create=False)  

table kb_7b066eca61_relations Doesn't exist
table kb_7b066eca61_relations Doesn't exist

print rt  

0

if rt == 0: store.open(configString,create=True)  

Traceback (most recent call last):
File "", line 3, in
store.open(configString,create=True)
File "C:\Program Files\Python26\lib\site-packages\rdflib\store\MySQL.py", line 602, in open
host=configDict['host'],
File "C:\Program Files\Python26\lib\site-packages\MySQLdb_init_.py", line 74, in Connect
return Connection(*args, **kwargs)
File "C:\Program Files\Python26\lib\site-packages\MySQLdb\connections.py", line 170, in init
super(Connection, self).init(*args, **kwargs2)
OperationalError: (1049, "Unknown database 'test'")

A: 

I commented code in the rdflib/store directory in MySQL.py and now it all works:

test_db = MySQLdb.connect(user=configDict['user'],

passwd=configDict['password'],

db='test',

port=configDict['port'],

host=configDict['host'],

#use_unicode=True,

#read_default_file='/etc/my-client.cnf'

)

c=test_db.cursor()

c.execute("""SET AUTOCOMMIT=0""")

c.execute("""SHOW DATABASES""")

if not (configDict['db'].encode('utf-8'),) in c.fetchall():

print >> sys.stderr, "creating %s (doesn't exist)"%(configDict['db'])

c.execute("""CREATE DATABASE %s"""%(configDict['db'],))

test_db.commit()

c.close()

test_db.close()

I meant I commented out all this code...