本文整理汇总了Python中win32com.client.Dispatch.ActiveConnection方法的典型用法代码示例。如果您正苦于以下问题:Python Dispatch.ActiveConnection方法的具体用法?Python Dispatch.ActiveConnection怎么用?Python Dispatch.ActiveConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32com.client.Dispatch
的用法示例。
在下文中一共展示了Dispatch.ActiveConnection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from win32com.client import Dispatch [as 别名]
# 或者: from win32com.client.Dispatch import ActiveConnection [as 别名]
def __init__(self, databasename):
global connection, command
connection = Dispatch("ADODB.Connection")
command = Dispatch("ADODB.Command")
connection.Open(ADOdb.dsource % databasename)
command.ActiveConnection = connection
示例2: acc2orcl
# 需要导入模块: from win32com.client import Dispatch [as 别名]
# 或者: from win32com.client.Dispatch import ActiveConnection [as 别名]
def acc2orcl(mdb,collectDate):
oConn = Dispatch('ADODB.Connection')
oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+mdb+"SpiderResult.mdb;"
oConn.Open()
conn=cx_Oracle.connect('naiawii/[email protected]')
cur=conn.cursor()
table='NETDATANEW'
td=datetime.date.today()
if oConn.State == adStateOpen:
print "Connected to the database: "+mdb[-4:-1]
oRS = Dispatch('ADODB.RecordSet')
oRS.ActiveConnection = oConn
sql="""select ID,Mid(用户ID,1,200),Mid(城市,1,600),Mid(标题,1,600),出处,主题内容
,Mid(出行天数,1,25),Mid(出发日期,1,10),Mid(目的地,1,600),Mid(发起人,1,200)
,Mid(发起人城市,1,10),Mid(主题发表时间,1,10),Mid(发起人Mail,1,50),Mid(发起人QQ,1,50)
,Mid(发起人联系方式,1,100),PageUrl,采集日期 from content where 采集日期>'"""+collectDate+" 16:00:00'"+\
" and 采集日期<'"+td.isoformat()+" 16:00:00'"
oRS.Open(sql,oConn)
param=[]
while not oRS.EOF:
content=oRS.Fields(5).Value.encode('utf8')
email=oRS.Fields(12).Value.encode('utf8')
qqnum=oRS.Fields(13).Value.encode('utf8')
phone=oRS.Fields(14).Value.encode('utf8')
if str(email)=='' or '@' not in str(email):
email=getRe(content,'gemail')
if str(qqnum)=='':
qqnum=getRe(content,'qqnum')
if str(phone)=='':
phone=getRe(content,'cphone')
if str(email)=='' and str(qqnum)!='':
email=qqnum+'@qq.com'
#print 'email: '+email+',qqnum: '+qqnum+',phone: '+phone
param.append({'id':oRS.Fields(0).Value,'userid':oRS.Fields(1).Value.encode('utf8')\
,'city':oRS.Fields(2).Value.encode('utf8'),'title':oRS.Fields(3).Value.encode('utf8')\
,'souloc':oRS.Fields(4).Value.encode('utf8'),'postcontent':content\
,'days':oRS.Fields(6).Value.encode('utf8'),'departdate':oRS.Fields(7).Value.encode('utf8')\
,'destination':oRS.Fields(8).Value.encode('utf8'),'postman':oRS.Fields(9).Value.encode('utf8')\
,'postcity':oRS.Fields(10).Value.encode('utf8'),'postdate':oRS.Fields(11).Value.encode('utf8')\
,'postemail':email,'qqnum':qqnum,'postcontact':phone,'pageurl':oRS.Fields(15).Value.encode('utf8')\
,'inputdate':oRS.Fields(16).Value.encode('utf8')})
oRS.MoveNext()
print len(param)
cur.setinputsizes(postcontent=cx_Oracle.CLOB)
cur.executemany('insert into netdatanew (id, userid, city,title, souloc,postcontent, days, departdate,destination, postman\
, postcity, postdate, postemail, qqnum, postcontact,pageurl,inputdate) values (:id, :userid, :city,:title\
, :souloc,:postcontent, :days, :departdate,:destination, :postman, :postcity, :postdate, :postemail, :qqnum, :postcontact\
, :pageurl, :inputdate)',param)
cur.close()
conn.commit()
conn.close()
oRS.Close()
oRS=None
else:
print "Failed to connect to the database."
示例3: getCollectDate
# 需要导入模块: from win32com.client import Dispatch [as 别名]
# 或者: from win32com.client.Dispatch import ActiveConnection [as 别名]
def getCollectDate(mdb):
oConn = Dispatch('ADODB.Connection')
oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+mdb+"SpiderResult.mdb;"
oConn.Open()
if oConn.State == adStateOpen:
oRS = Dispatch('ADODB.RecordSet')
oRS.ActiveConnection = oConn
getDate='select top 1 采集日期 from content order by 采集日期 desc'
oRS.Open(getDate,oConn)
while not oRS.EOF:
coll=oRS.Fields(0).Value.encode('utf8')
oRS.MoveNext()
print "采集日期:"+coll
oRS.Close()
oRS=None
return coll[0:11]
else:
return '';
示例4: query
# 需要导入模块: from win32com.client import Dispatch [as 别名]
# 或者: from win32com.client.Dispatch import ActiveConnection [as 别名]
def query (query_string, **command_properties):
"""Auxiliary function to serve as a quick-and-dirty
wrapper round an ADO query
"""
command = Dispatch ("ADODB.Command")
command.ActiveConnection = connection ()
#
# Add any client-specified ADO command properties.
# NB underscores in the keyword are replaced by spaces.
#
# Examples:
# "Cache_results" = False => Don't cache large result sets
# "Page_size" = 500 => Return batches of this size
# "Time Limit" = 30 => How many seconds should the search continue
#
for k, v in command_properties.items ():
command.Properties (k.replace ("_", " ")).Value = v
command.CommandText = query_string
recordset, result = command.Execute ()
while not recordset.EOF:
yield ADO_record (recordset)
recordset.MoveNext ()