利用ODBC实现Domino和关系的互操作

<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="SELECTFROMTable1"

  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>
以下是俺学习参考别人有关NOTES与关系数据库互相操作的文档后更新的LOTUSSCRIPT程序代码 Set con=New ODBCConnection Set qry=New ODBCQuery Set rs=New ODBCResultSet Set qry.Connection = con Set rs.Query=qry Set ws=New notesuiworkspace Set uidoc=ws.currentdocument Dim s As New NotesSession Dim db As NotesDatabase Dim tempdoc As NotesDocument Dim StudentView As NotesView Dim j As Integer Set db=s.CurrentDatabase Set StudentView = db.GetView("($studentid)") Call con.ConnectTo("arice","","") qry.SQL="Select * From people" rs.execute rs.LastRow rs.CurrentRow = currentrow If Cstr(uidoc.fieldgettext("Saveoptions"))="0" Then '如果是新建表单 Set tempdoc=StudentView.GetDocumentByKey(Trim(uidoc.fieldgettext("Student_ID")),True)'判断是否在视图存在此学生id的表单 If Not tempdoc Is Nothing Then'如果存在 Messagebox "系统已经存在,请不要重复录入",,"警告" continue=False Exit Sub Else j = 0 For i = 1 To rs.NumRows rs.CurrentRow = i If Cstr(rs.GetValue("Cname")) = Cstr(uidoc.FieldGetText("Student_ID")) Then j = j + 1 End If Next '==============更新操作================================================== If j > 0 Then Call rs.SetValue("Student_id",Cstr(uidoc.FieldGetText("Student_ID"))) 'Messagebox "执行第一条语句" Call rs.SetValue("CName", Cstr(uidoc.fieldgettext("CName"))) 'Messagebox "执行第二条语句" Call rs.SetValue("EName", Cstr(uidoc.fieldgettext("EName"))) Call rs.SetValue("Address",Cstr(uidoc.fieldgettext("Address"))) Call rs.SetValue("Tel",Cstr(uidoc.fieldgettext("Tel"))) 'Messagebox "执行第五条语句" If rs.UpdateRow Then Messagebox "提交SQL数据库成功" 'Call uidoc.fieldsettext("Saveoptions","1") Call uidoc.Save(False,False) Else Messagebox "保存SQL数据库失败" Exit Sub End If Else Messagebox "是新增的文档,待定新增代码处理!" '====================新增保存代码========================= rs.AddRow Call rs.SetValue("Student_id",Cstr(uidoc.FieldGetText("Student_ID"))) Call rs.SetValue("CName", Cstr(uidoc.fieldgettext("CName"))) Call rs.SetValue("EName", Cstr(uidoc.fieldgettext("EName"))) Call rs.SetValue("Address",Cstr(uidoc.fieldgettext("Address"))) Call rs.SetValue("Tel",Cstr(uidoc.fieldgettext("Tel"))) If rs.UpdateRow Then Call uidoc.fieldsettext("Saveoptions","1") Call uidoc.Save(True,False) Messagebox "提交SQL数据库成功" Else Messagebox "保存SQL数据库失败" Exit Sub End If End If End If 'Messagebox "执行update条语句" Else Call rs.SetValue("Student_id",Cstr(uidoc.FieldGetText("Student_ID"))) 'Messagebox "执行第一条语句" Call rs.SetValue("CName", Cstr(uidoc.fieldgettext("CName"))) 'Messagebox "执行第二条语句" Call rs.SetValue("EName", Cstr(uidoc.fieldgettext("EName"))) Call rs.SetValue("Address",Cstr(uidoc.fieldgettext("Address"))) Call rs.SetValue("Tel",Cstr(uidoc.fieldgettext("Tel"))) 'Messagebox "执行第五条语句" If rs.UpdateRow Then Messagebox "提交SQL数据库成功" 'Call uidoc.fieldsettext("Saveoptions","1") Call uidoc.Save(True,False) Else Messagebox "保存SQL数据库失败" Exit Sub End If End If rs.Close(DB_CLOSE) con.Disconnect
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值