2012-06-13 79 views
1
import MySQLdb 
import sys 

from libdesklets.controls import Control 
from IDBConnection import IDBConnection 

class DBConnection(Control, IDBConnection): 
    host = 'xxxx' 
    user = 'xxxx' 
    passwd = 'xxxx' 
    db = 'xxxx' 

def __init__(self): 
    Control.__init__(self) 
    pass 

def __get_dbconnection(self): 
    db = MySQLdb.connect(self.host, self.user, self.passwd, self.db) 
    return db 

def __insert(self): 
    db = self.__get_dbconnection() 
    cursor = db.cursor() 
    cursor.execute("INSERT INTO Usernotes (UID, NID, Inhalt) VALUES (3, 1, 'text');") 
    cursor.close() 
    db.close() 

def __select(self): 
    db = self.__get_dbconnection() 
    cursor = db.cursor() 
    cursor.execute("SELECT Inhalt FROM Usernotes WHERE UID = 1 AND NID = 1;") 
    cursor.close() 
    db.close() 

def __update(self): 
    db = self.__get_dbconnection() 
    cursor = db.cursor() 
    cursor.execute("UPDATE Usernotes SET Inhalt = 'inserttest' WHERE UID = 1 AND NID = 2;") 
    cursor.close() 
    db.close() 

insert = property(__insert, doc="insert into database") 
select = property(__select, doc="select from database") 
update = property(__update, doc="update database") 

def get_class(): return DBConnection 

上面的代码是一个控制与一个MySQL-数据库Linux gdesklets(那其中进口和控制进口的IDbConnection是来自)工作。因此,当我们从另一个文件(dbc.insert()/ dbc.select()/ dbc.update())调用属性时,我们得到错误“'NoneType'对象不可调用”。如果我们添加返回类型,我们会得到“'ReturnType'对象不可调用”。函数正在工作,数据库操作已完成,但显示文件(调用函数的位置)在异常后崩溃。Python数据库连接“NoneType”对象不是可调用

希望有人可以帮助我们在这里。

+0

两个提示:首先,当询问关于错误的问题时,复制/粘贴整个错误消息,其中有许多关于发生错误的提示。其次,关于“NoneType”的错误通常意味着一个函数在你没有预期的时候返回'None',开始在那里查找。 –

回答

0

您的查询返回了一个空集,或者列的值为空。

没有一个特定的错误,这是很难说,但我认为你的选择是一个空集。

你插套UID = 3,NID = 1,您的更新正在寻求改变,其中UID = 1,NID 2,但你的选择是寻找UID = 1,NID = 1

我猜测这就是爆炸的地方。

相关问题