mal wieder eine newbieFrage: kann mir bitte jemand sagen wie man, den in der MySQL DatenBank gespeicherten File, plotten/zeigen lassen??
hier ist ein kleines beispiel: (interessant ist Zeile 76

Code: Alles auswählen
import wx
import os
import MySQLdb
"""
CREATE TABLE save_blob (
`f_id` int(10) unsigned NOT NULL auto_increment,
`f_blob` blob,
PRIMARY KEY (`f_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"""
#------------------------------------------------------------------------
class MyFrame(wx.Dialog):
def __init__(self, parent, title):
wx.Dialog.__init__(self, parent, -1, title, pos=(150, 150), size=(300, 350))
self.ConnectToDB()
panel = wx.Panel(self, -1)
self.BlobFile = ""
self.result = ""
self.btn_Load = wx.Button(panel, -1, 'Load File')
self.btn_Load.Bind(wx.EVT_BUTTON, self.LoadFile)
self.btn_Save = wx.Button(panel, -1, 'Save File into MySQL-DB')
self.btn_Save.Bind(wx.EVT_BUTTON, self.SaveFile)
self.btn_Read = wx.Button(panel, -1, 'Read File from MySQL-DB')
self.btn_Read.Bind(wx.EVT_BUTTON, self.FetchFile)
btn_sizer = wx.BoxSizer(wx.HORIZONTAL)
btn_sizer.Add(self.btn_Load, -1, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 15)
btn_sizer.Add(self.btn_Save, -1, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 15)
btn_sizer.Add(self.btn_Read, -1, wx.ALL|wx.EXPAND|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 15)
main_sizer = wx.BoxSizer(wx.VERTICAL)
main_sizer.Add(btn_sizer, 0, wx.ALL|wx.ALIGN_CENTER|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 15)
panel.SetSizer(main_sizer)
main_sizer.Fit(self)
self.main_sizer = main_sizer
self.Bind(wx.EVT_CLOSE, self.OnClose)
def LoadFile(self, event):
wildcard = "(*.py) |*.py|"\
"(*.jpg) |*.jpg|"\
"All files (*.*)|*.*"
dlg = wx.FileDialog(self, "Choose a File", os.getcwd(), "", wildcard, wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetFilename()
dirname = dlg.GetDirectory()
OpenFile = open(os.path.join(dirname, filename),'rb')
self.BlobFile = MySQLdb.Binary(OpenFile.read())
OpenFile.close()
dlg.Destroy
if event:
event.Skip()
def SaveFile(self, event):
Cursor = self.Con.cursor()
sql = "INSERT INTO save_blob(f_blob) VALUES (%s)"
Cursor.execute(sql, self.BlobFile)
print "Blob wurde gespeichert!"
self.Con.commit()
def FetchFile(self, event):
Cursor = self.Con.cursor()
sql = "SELECT f_blob FROM save_blob WHERE f_id = 1 "
Cursor.execute(sql)
self.result = Cursor.fetchone()[0]
## wie lasse ich hier mein result zeigen!!
self.Con.commit()
def ConnectToDB(self):
self.Con = MySQLdb.Connect(host = "lokalhost",
user = "user",
passwd = "password",
db = "db")
def OnClose(self, event):
self.Con.close()
self.Destroy()
#------------------------------------------------------------------------
class MyApp(wx.App):
def OnInit(self):
dialog = MyFrame(None, 'BlobFile speichern')
if dialog.ShowModal() == wx.ID_OK:
print dialog.object.GetDate()
return True
app = MyApp(0)
app.MainLoop()
LG,
fanus
