0

用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。

谢谢,格雷厄姆

4

1 回答 1

0

此代码使用 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 方法。

于 2012-06-12T20:47:53.770 回答