2017-02-17 4 views
0

바이트 객체를 데이터베이스에 어떻게 삽입합니까? 내가 이것을 시도 할 때마다 나는 빈 문자열 (NULL이 아닌)이 삽입되게된다.pyqt5가 바이트를 삽입하지 못함

with open(filepath, 'rb') as f: 
    filehash = hashlib.md5(f.read()).hexdigest() 
img_pkl = pickle.dumps(img, protocol=4) 

record = self.tablemodel.record() 
record.setValue('originfile_path', filepath) 
record.setValue('originfile_hash', filehash) 
record.setValue('image', img_pkl) 
record.setValue('area', area) 
self.tablemodel.insertRecord(-1, record) 

문제는 메일 링리스트에 기록되었지만 해결되지 않았습니다. https://www.riverbankcomputing.com/pipermail/pyqt/2016-April/037260.html 그것은 또한 당신이 대신 준비된 명령문의 수 (그는 또한 exec_ 대 간부()에 대한 PyQt는 버그를 언급 할 때 테이블 모델을 사용하는 것이 더 의미가 밝혀(). 당신은 명시 적으로 변환해야합니다

답변

0

. QByteArray

record.setValue('image', QtCore.QByteArray(img_pkl)) 

참고 : 또한 부동 소수점을 사용하여 numpy.float64 개체를 변환해야합니다()

관련 문제