<p>下面是一个更完整的示例:</p>
<pre><code>def example (self):
#retrieve info from first textview
buf = self.builder.get_object('textbuffer1')
format = buf.register_serialize_tagset()
data = buf.serialize(buf, format, buf.get_start_iter(), buf.get_end_iter())
#run db update to prove it can be inserted into a database
db = psycopg2.connect(database= 'silrep_restore3', host='192.168.0.101',
user='postgres', password = 'true',
port = '5432')
c = db.cursor()
c.execute("UPDATE products SET byt = %s WHERE id = 1", (psycopg2.Binary(data),))
#append info to second treeview as a proof of concept
c.execute("SELECT byt FROM products WHERE id = 1")
data = c.fetchone()[0]
buf = self.builder.get_object('textbuffer2')
format = buf.register_deserialize_tagset()
buf.deserialize(buf, format, buf.get_end_iter(), data)
</code></pre>
<p>既然您使用的是MySQL,我建议您阅读这篇<a href="https://stackoverflow.com/questions/5241031/">article</a>关于像您这样插入和检索数据的文章。你知道吗</p>
<p>以我为例,我用了一个“茶边”专栏。在MySQL中,这可能是BLOB或二进制类型。你知道吗</p>
<p>另外,很抱歉我的回答中没有完整的MySQL示例。我本来会发表评论的,但是评论的格式太差了。你知道吗</p>