如何通过LSXODBC从数据库中删除记录

时间:2014-08-29 20:53:36

标签: lotus-notes lotusscript

我已经运行了一个代理程序,它将数据从Notes数据库推送到Postgres数据库。我现在需要构建一个从表中删除记录或进行截断的函数。该文档并不是那么好,所以我发现它有点难以弄清楚。任何提示都表示赞赏。

感谢 CLEM

1 个答案:

答案 0 :(得分:0)

假设有一个简单的表“Employees”,其中包含以下列:

Code (longint)
FullName (text)
Title (text)
Position (text)
Retired (boolean)

table before

让我们执行代理脚本,删除已退休员工的行。

Option Public
Option Declare
UseLSX "*LSXODBC"

Sub Initialize
    Const DSN = "TestODBCConnection"

    Dim con As New ODBCConnection
    Dim qry As New ODBCQuery
    Dim result As New ODBCResultSet
    Dim msg As String

    Call con.ConnectTo(DSN)

    If Not con.IsConnected Then
        MessageBox "Could not connect to " + DSN,,"No connection"
        Exit Sub
    End If

    Set qry.Connection = con
    Set result.Query = qry

    qry.SQL = "Delete From Employees WHERE Retired = TRUE;"
    result.Execute

    If Not result.Execute Then
          MessageBox result.GetExtendedErrorMessage,, result.GetErrorMessage
     Else
          MsgBox "Ok"
     End If

    result.Close(DB_CLOSE)
    con.Disconnect
End Sub

我们的表“员工”现在看起来像这样:

table after