【问题标题】:How do I write string to longvarchar in pervasive larger than 32k?如何以普遍大于 32k 的方式将字符串写入 longvarchar?
【发布时间】:2012-06-13 04:47:53
【问题描述】:

用 VB6 编写的应用程序。 DB 是 Pervasive v9.5。

目前有效:

Public Sub Save()   
    if rs.State = adStateOpen Then
         rs.AddNew
         SetFields rs
         rs.Update
    End If
end sub

Public Sub SetFields(rs as ADODB.Recordset)
    rs!Name = strName
    StrToField strReport rs!Report
    StrToField strResponse rs!Response
end sub

Public Sub StrToField(ByVal str As String, fld As ADODB.Field)
    Dim Data As String
    Dim StrSize As Long, CharsRead As Long

    ' for field of LONVARCHAR type only
    If fld.Type = adLongVarChar Then
        StrSize = Len(str)
        Do While StrSize <> CharsRead
            If StrSize - CharsRead < BLOCK_SIZE_LONGVARCHAR Then
                Data = Mid(str, CharsRead + 1, StrSize - CharsRead)
                CharsRead = StrSize
            Else
                Data = Mid(str, CharsRead + 1, BLOCK_SIZE_LONGVARCHAR)
                CharsRead = CharsRead + BLOCK_SIZE_LONGVARCHAR
            End If
            fld.AppendChunk Data
        Loop
     Else
        ' do something
     End If
 End Sub

Const BLOCK_SIZE_LONGVARCHAR = 4096

在我的报告或响应变量大于 32000 个字符之前,这可以正常工作。调用 rs.update 时我收到此错误消息:

“[Pervasive][ODBC 客户端接口] 字符串长度超过列长度参数 #15。数据被截断。”

谁能指出我正确的方向,或者让我知道我是否遗漏了什么。 Pervasive Longvarchar 最大大小应为 2GB。

谢谢, 格雷厄姆

【问题讨论】:

    标签: vb6 pervasive


    【解决方案1】:

    此代码使用 PSQL v11(我没有 v9.5)对我有效。

    Dim conn As New ADODB.Connection
    Set conn = New ADODB.Connection
    conn.ConnectionString = "demodata"
    conn.Open
    Dim sql As String
    Dim cmd As New ADODB.Command
    cmd.ActiveConnection = conn
    cmd.CommandText = "insert into lvc (f2) values (?)"
    Dim parm As New ADODB.Parameter
    parm.Name = "f2"
    Dim longstring As String
    Open "c:\longdata.txt" For Input As #1
    Do While Not EOF(1)
       Line Input #1, sNextLine
       'do something with it
       'add line numbers to it, in this case!
       sText = sText & sNextLine
    Loop
    longstring = sText
    parm.Value = longstring
    cmd.Parameters.Append cmd.CreateParameter("param1", adLongVarChar, adParamInput, Len(longstring), longstring)
    cmd.Execute
    conn.Close
    MsgBox "done"
    

    基本上,您将使用参数化查询而不是 .AddNew 方法。

    【讨论】:

    • 你是天才米尔泰尔。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多