Re: Writing BLOBS to pgsql via ODBC using VB - Mailing list pgsql-odbc

From Hiroshi Inoue
Subject Re: Writing BLOBS to pgsql via ODBC using VB
Date
Msg-id 3BD65A42.FB57EB12@tpf.co.jp
Whole thread Raw
In response to Re: Writing BLOBS to pgsql via ODBC using VB  (Denis Gasparin <denis@edinet.it>)
Responses Re: Writing BLOBS to pgsql via ODBC using VB  (Denis Gasparin <denis@edinet.it>)
List pgsql-odbc
How about the following ?

Denis Gasparin wrote:
>
>  > Are you setting the CursorLocation memeber as adUseClient ?
>  >
>  >regards,
>  >Hiroshi Inoue
>
> Ok, it worked. I think that it would be great to insert that tip in the faq
> at the odbc.postgresql.org.
>
> Now another question:
> is there possible to use lo with parameterized queries (ADO command object)?
> I have tried but i receive a query error. It seems like the odbc driver
> doesn't use the lo interface but tryies to insert the record into the db as
> if the field was of bytea type (Sorry for the poor English...I hope it is
> clear what i'm saying...)
>
> At the end of the mail there is the code and the log of the odbc pgsql driver.
> The table is the same of the other mail: two fields, main (of type integer)
> and object (of type lo)
>
> Thank for your help,
>
> Denis
>
> --- DEBUG INFORMATIONS ---
> At the end of the mail there is the pgsql odbc driver log. Here instead
> there is the code:
>
> Dim cn As New ADODB.Connection
> Dim rs As ADODB.Recordset
> Dim cmd As ADODB.Command
> Dim chunk() As Byte
> Dim fd As Integer
> Dim flen As Long
> Dim chunks As Integer
> Dim fragment As Integer
> Dim main As ADODB.Parameter
> Dim object As ADODB.Parameter
> Dim i As Long
>
> With cn
>      .ConnectionString = "dsn=pgsql_test_blob;"
>      .Open
>      .CursorLocation = adUseClient
> End With
>
> Set cmd = New ADODB.Command
> With cmd
>      .CommandText = "delete from myt1"
>      .ActiveConnection = cn
>      .Execute
> End With
>
> Set cmd = Nothing
>
> Set cmd = New ADODB.Command
> cmd.ActiveConnection = cn
> cmd.CommandText = "insert into myt1(main,object) values(?,?)"
> cmd.CommandType = adCmdText
>
> ' Set the main parameter
> Set main = cmd.CreateParameter("main", adInteger, adParamInput)
> main.Value = 1234
' add the following
  cmd.Parameters.Append main

>
> Set object = cmd.CreateParameter("object", adLongVarBinary,
adParamInput)

' change as follows(100000 should be large enough)
Set object = cmd.CreateParameter("object", adLongVarBinary,
adParamInput, 100000)
' add the following
cmd.Parameters.Append object

> fd = FreeFile
> Open "mydocument" For Binary Access Read As fd
> flen = LOF(fd)
> If flen = 0 Then
>      Close
>      MsgBox "Error while opening the file"
>      End
> End If
> ReDim chunk(flen)
> Get fd, , chunk()
> ' Now insert into the parameter
> object.AppendChunk chunk()
>
> ' Execute the insert command
> Set rs = cmd.Execute(, Array(main, object))

' Change as follows
Set rs = cmd.Execute

> cn.Close
> Close
>

pgsql-odbc by date:

Previous
From: Denis Gasparin
Date:
Subject: Re: Writing BLOBS to pgsql via ODBC using VB
Next
From: Denis Gasparin
Date:
Subject: Re: Writing BLOBS to pgsql via ODBC using VB