<script type="text/javascript">
</script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
利用 ODBC 实现 Domino和 关系数据库的 互操作
Lotus Domino是当今办公自动化系统的主流开发平台之一, Domino自带一个非 关系型数据库——文档型数据库,而目前大部分企业的信息都储存在诸如等 关系型数据库中,因此,在开发办公自动化系统过程中势必要涉及 Domino和 关系数据库的数据交换问题。
一、Lotus Domino与 关系数据库的 互操作
在Lotus DominoR5中提供了三个LotusNotes扩展类: ODBCConnection( ODBC连接)、 ODBCQuery( ODBC查询)以及 ODBCResultSet( ODBC结果集)。应用这三个类并辅以LotusScript语言就能 实现与 关系数据库的 互操作问题。
具体解决方法如下:
第1步:在控制面板→32位 ODBC数据源中建立用户数据源Test;
第2步:在 DominoR5中新建一个数据库Try,并建立一个空白表单Con-nection,此表单没有任何内容,然后在表单上创建一个“操作”,起名为“Read”;
第3步:在“Read”操作的窗口中选择编程语言为LotusScript;
第4步:在编程窗口的对象窗口中点击“Option”事件,并写入如下脚本:
Uselsx"lsx ODBC"//使用LotusScript扩展 ODBC类
第5步:选中“Declare”事件,在其中写入:
DimsessionAsNotesSession
DimdbAsNotesDataBase
DimdocAsNotesDocument
DimqryAs ODBCQuery
DimresultAs ODBCResultSet
DimconAs ODBCConnection
第6步:选中“Click”事件,在其中写入:
SubClick(SourceAsButton)
′SetNewValue
Setsession=NewNotesSession
Setcon=New ODBCConnection
Setqry=New ODBCQuery
Setresult=New ODBCResultSet
′GetCurrentDatabase
Setdb=session.CurrentDataBase
Setdoc=NewNotesDocument(db)
doc.form="connection"
Callcon.Disconnect()
Ifcon.ConnectTo("test")Then
Setqry.connection=con
qry.SQL="SELECTFROMTable1"
Setresult.Query=qry
Callresult.Execute()
columns=result.Columns
Do
Callresult.NextRow()
Fori=1Toresult.Numcolumns
field=result.FieldName(i)
value=result.GetValue(field)
IfIsdate(value)Then
Ifvalue=Datevalue("0:00:00")Then
value=""
Else
value=Format(value,"mm-dd-yyyy")
EndIf
EndIf
Setitem=doc.AppendItemValue(field,val-ue)
Next
Calldoc.save(True,True)
Setdb=session.CurrentDataBase
Setdoc=NewNotesDocument(db)
doc.form="test"
LoopUntilresult.IsEndOfData
Callcon.Disconnect()
Else
Messagebox("Couldnotconnecttoserver")
EndIf
EndSub
最后,保存表单并运行,用鼠标点击Read操作后, 关系数据库中的内容就被取到Notes的文档型数据库中了。
二、程序存在的问题及解决
但是使用上面的代码在进行实际数据库内容转换的时候,我们发现Notes通过 ODBC数据源连接 关系数据库时,无法识别中文字段名。如果 关系数据库的字段是中文名字,那么 ODBCResultSet将为空,解决的办法是将 关系数据库中的所有字段都改为英文名字。
在实际数据库的转换过程中同时发现的问题还有:该程序执行完一次后不能把 关系型数据库中的内容全部取出来。通过调试LotusScript脚本并多次单步跟踪脚本的执行情况,发现每次都是执行到同一条数据库记录时, ODBCRe-sultSet就认为数据集已经到头了,下面的记录就都丢了。于是使用 关系数据库打开数据库,并将其中的字段减少若干条后,就可以一次读取出全部记录。至于需要减少多少个字段才能一次读取出全部记录跟原先的 关系型数据库的结构有关,需要具体情况具体实验。共3页 第1页
<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript">
</script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
利用 ODBC 实现 Domino和 关系数据库的 互操作
Lotus Domino是当今办公自动化系统的主流开发平台之一, Domino自带一个非 关系型数据库——文档型数据库,而目前大部分企业的信息都储存在诸如等 关系型数据库中,因此,在开发办公自动化系统过程中势必要涉及 Domino和 关系数据库的数据交换问题。
一、Lotus Domino与 关系数据库的 互操作
在Lotus DominoR5中提供了三个LotusNotes扩展类: ODBCConnection( ODBC连接)、 ODBCQuery( ODBC查询)以及 ODBCResultSet( ODBC结果集)。应用这三个类并辅以LotusScript语言就能 实现与 关系数据库的 互操作问题。
具体解决方法如下:
第1步:在控制面板→32位 ODBC数据源中建立用户数据源Test;
第2步:在 DominoR5中新建一个数据库Try,并建立一个空白表单Con-nection,此表单没有任何内容,然后在表单上创建一个“操作”,起名为“Read”;
第3步:在“Read”操作的窗口中选择编程语言为LotusScript;
第4步:在编程窗口的对象窗口中点击“Option”事件,并写入如下脚本:
Uselsx"lsx ODBC"//使用LotusScript扩展 ODBC类
第5步:选中“Declare”事件,在其中写入:
DimsessionAsNotesSession
DimdbAsNotesDataBase
DimdocAsNotesDocument
DimqryAs ODBCQuery
DimresultAs ODBCResultSet
DimconAs ODBCConnection
第6步:选中“Click”事件,在其中写入:
SubClick(SourceAsButton)
′SetNewValue
Setsession=NewNotesSession
Setcon=New ODBCConnection
Setqry=New ODBCQuery
Setresult=New ODBCResultSet
′GetCurrentDatabase
Setdb=session.CurrentDataBase
Setdoc=NewNotesDocument(db)
doc.form="connection"
Callcon.Disconnect()
Ifcon.ConnectTo("test")Then
Setqry.connection=con
qry.SQL="SELECTFROMTable1"
Setresult.Query=qry
Callresult.Execute()
columns=result.Columns
Do
Callresult.NextRow()
Fori=1Toresult.Numcolumns
field=result.FieldName(i)
value=result.GetValue(field)
IfIsdate(value)Then
Ifvalue=Datevalue("0:00:00")Then
value=""
Else
value=Format(value,"mm-dd-yyyy")
EndIf
EndIf
Setitem=doc.AppendItemValue(field,val-ue)
Next
Calldoc.save(True,True)
Setdb=session.CurrentDataBase
Setdoc=NewNotesDocument(db)
doc.form="test"
LoopUntilresult.IsEndOfData
Callcon.Disconnect()
Else
Messagebox("Couldnotconnecttoserver")
EndIf
EndSub
最后,保存表单并运行,用鼠标点击Read操作后, 关系数据库中的内容就被取到Notes的文档型数据库中了。
二、程序存在的问题及解决
但是使用上面的代码在进行实际数据库内容转换的时候,我们发现Notes通过 ODBC数据源连接 关系数据库时,无法识别中文字段名。如果 关系数据库的字段是中文名字,那么 ODBCResultSet将为空,解决的办法是将 关系数据库中的所有字段都改为英文名字。
在实际数据库的转换过程中同时发现的问题还有:该程序执行完一次后不能把 关系型数据库中的内容全部取出来。通过调试LotusScript脚本并多次单步跟踪脚本的执行情况,发现每次都是执行到同一条数据库记录时, ODBCRe-sultSet就认为数据集已经到头了,下面的记录就都丢了。于是使用 关系数据库打开数据库,并将其中的字段减少若干条后,就可以一次读取出全部记录。至于需要减少多少个字段才能一次读取出全部记录跟原先的 关系型数据库的结构有关,需要具体情况具体实验。共3页 第1页
<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript">
</script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>