Python论坛  - 讨论区

标题:[python-chinese] 回复: 回复: pywin32中如何存取二進制大對象

2007年07月30日 星期一 15:28

汪文进 wjawon在yahoo.com.cn
星期一 七月 30 15:28:21 HKT 2007

ÔÚgoogleµÄcomp.lang.pythonÕÒµ½ÁËһЩ¾€Ë÷,»ù±¾M×ãÎÒµÄÒªÇó.´ú´aÈçÏÂ:

01.  import win32com.client
02.  
03.  
04.  def AppendChunk(field, fileName):
05.      try:
06.          file = open(fileName, 'rb').read()
07.          binaryBuffer = buffer(file)
08.          
09.          mstream = win32com.client.Dispatch(r'ADODB.Stream')
10.          mstream.Type = adTypeBinary
11.          mstream.Open()
12.          mstream.Write(binaryBuffer)
13.          mstream.Position = 0
14.          
15.          objRS.AddNew()
16.          objRS.Fields.Item(field).Value = mstream.Read()
17.          objRS.Fields.Update()
18.      except:
19.          print 'error'
20.      
21.  
22.  def GetChunk1(field, fileName):
23.      try:
24.          val = objRS.Fields.Item(field).Value
25.          
26.          mstream = win32com.client.Dispatch(r'ADODB.Stream')
27.          mstream.Type = adTypeBinary
28.          mstream.Open()
29.          mstream.Write(buffer(val))
30.          mstream.Position = 0
31.          mstream.SaveToFile(fileName)
32.      except:
33.          print 'error'
34.          
35.          
36.  def GetChunk2(field, fileName):
37.      try:
38.          fl = open(fileName, 'wb+')
39.          val = objRS.Fields.Item(field).Value
40.          if val:
41.              fl.write(val)
42.      except:
43.          print 'error'
44.      finally:
45.          fl.close()

Èç¹ûÄúÓиüºÃµÄ·½·¨,ՈÙn½Ì!



----- ԭʼÓʼþ ----
·¢¼þÈË£º ÍôÎĽø <wjawon在yahoo.com.cn>
ÊÕ¼þÈË£º python-chinese在lists.python.cn
ÒÑ·¢ËÍ£º 2007/7/17(Öܶþ), ÉÏÎç10:25:44
Ö÷Ì⣺ [python-chinese] »Ø¸´£º pywin32ÖÐÈçºÎ´æÈ¡¶þßMÖÆ´óŒ¦Ïó


ÕÒµ½ÁËGetChunkºÍAppendChunk,߀ÊDz»ÖªµÀÔõôÓÃ!
ÕlÄÜÖ¸½Ì?
 
01.  import pythoncom
02.  import win32com.client
03.  
04.  try:
05.      objConn = win32com.client.Dispatch(r'ADODB.Connection')
06.      objConn.Open(r"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:/db1.mdb")
07.  
08.      objRS = win32com.client.Dispatch(r'ADODB.Recordset')
09.      objRS.Open('SELECT id,photo FROM [user]',objConn,1,3)
10.      objRS.MoveFirst()
11.  
12.      sz = objRS.Fields.Item('photo').ActualSize
13.      objRS.Fields.Item('photo').GetChunk(sz)    
14.      #????????????
15.  except pythoncom.com_error, (hr, msg, exc, n):
16.      print 'com error'



----- ԭʼÓʼþ ----
·¢¼þÈË£º ÍôÎĽø <wjawon在yahoo.com.cn>
ÊÕ¼þÈË£º python-chinese在lists.python.cn
ÒÑ·¢ËÍ£º 2007/7/16(ÖÜÒ»), ÏÂÎç4:06:10
Ö÷Ì⣺ [python-chinese] pywin32ÖÐÈçºÎ´æÈ¡¶þßMÖÆ´óŒ¦Ïó


Ո½Ì¸÷λ,ÔÚpywin32ÖÐÈçºÎ´æÈ¡¶þßMÖÆ´óŒ¦Ïó(ADO)?
 
ÒÔÇ°ÔÚCÖÐÓÃFieldŒ¦ÏóµÄGetChunkºÍAppendChunk·½·¨,ÔÚpywin32ÖÐÓЛ]ÓÐîËƵķ½·¨?
¬FÔÚÎÒÒªŒ¢AutoCADÎļþ(»ò„eµÄÎļþ)´æÈë/×x³ö”µ“þŽì,
ÄÄλÓпÕÄܽoÎÒÒ»‚€Ô´´aíÕfÃ÷,±ÈÈç:
 
def AppendChunk(FieldName,FileName):
    ...
 
def Getchunk(FieldName):
    ...
 
ÖxÖx!
(win2k + python2.5 + pywin32-210)



ÑÅ»¢Ãâ·ÑÓÊÏä3.5GÈÝÁ¿£¬20M¸½¼þ£¡ 
_______________________________________________
python-chinese
Post: send python-chinese在lists.python.cn
Subscribe: send subscribe to python-chinese-request在lists.python.cn
Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
Detail Info: http://python.cn/mailman/listinfo/python-chinese





ÇÀ×¢ÑÅ»¢Ãâ·ÑÓÊÏä3.5GÈÝÁ¿£¬20M¸½¼þ£¡


      ___________________________________________________________ 
ÇÀ×¢ÑÅ»¢Ãâ·ÑÓÊÏä3.5GÈÝÁ¿£¬20M¸½¼þ£¡ 
http://cn.mail.yahoo.com
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070730/9aa168cf/attachment-0001.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号