Write attachments in blob fields

Hi everybody,

I want the following code to create records in an Oracle table, including two blob fields with attachments.

Everything looks like going well until the moment of doing the insert.

I got the error 12546, which according to the help is that some field is not matching with the type of the column in the Oracle table.

Does anyone know what it might be happening? or how could I get the text of the error and know which one is the field that doesn’t match?

Thanks in advance

Dim ses As New NotesSession

Dim bd As NotesDatabase

Dim colec As NotesDocumentCollection

Dim doc As NotesDocument

Dim dtFecha As New NotesDateTime( “01/01/2000” )

Dim dtFecha2 As NotesDateTime

Dim consulta As String

Dim intCont As Long

Dim strCadenaInsert As String

Dim conectado As Variant

Dim anyo As Integer

Dim mes As Integer

Dim dia As Integer

'Definición de conectores

Dim lcora As LCConnection

Dim lcfile As LCConnection

'Definición de las listas de campos de los conectores

Dim fldlistora As LCFieldList

Dim fldlistfile As New LCFieldList( 1, LCFIELDF_TRUNC_PREC )

'Campos de la tabla Oracle

Dim fldid As LCField

Dim fldasunto As LCField

Dim fldcreador As LCField

Dim fldsolicitante As LCField

Dim fldfecha As LCField

Dim fldcuerpo As LCField

Dim fldadjunto1 As LCField

Dim fldadjunto2 As LCField

Dim strTexto As New LCStream

Dim datFecha As LCDatetime

On Error Goto TratarError

ObtenerParametros

conectado = False

'Se crean las conexiones

Set lcora = New LCConnection( “oracle8” )

Set lcfile = New LCConnection( “file” )

'Se crean los campo para las columans de la tabla Oracle

Set fldid = New LCField( LCTYPE_TEXT )

Set fldasunto = New LCField( LCTYPE_TEXT )

Set fldcreador = New LCField( LCTYPE_TEXT )

Set fldsolicitante = New LCField( LCTYPE_TEXT )

Set fldfecha = New LCField( LCTYPE_DATETIME )

Set fldcuerpo = New LCField( LCTYPE_TEXT )

Set fldadjunto1 = New LCField( LCTYPE_BINARY )

Set fldadjunto2 = New LCField( LCTYPE_BINARY )

'fldid.Flags = LCFIELDF_TRUNC_PREC

fldid.Flags = LCFIELDF_KEY

fldasunto.Flags = LCFIELDF_TRUNC_PREC

fldcreador.Flags = LCFIELDF_TRUNC_PREC

fldsolicitante.Flags = LCFIELDF_TRUNC_PREC

fldfecha.Flags = LCFIELDF_TRUNC_PREC

fldcuerpo.Flags = LCFIELDF_TRUNC_PREC

'fldadjunto1.Flags = LCFIELDF_TRUNC_PREC

'fldadjunto2.Flags = LCFIELDF_TRUNC_PREC

'Se crea la lista de campos con los campos definidos antes

Set fldlistora = New LCFieldList( 1, LCFIELDF_TRUNC_PREC )

Call fldlistora.IncludeField( 1, fldid, “ID” )

Call fldlistora.IncludeField( 2, fldasunto, “ASUNTO” )

Call fldlistora.IncludeField( 3, fldcreador, “CREADOR” )

Call fldlistora.IncludeField( 4, fldsolicitante, “SOLICITANTE” )

Call fldlistora.IncludeField( 5, fldfecha, “FECHA” )

Call fldlistora.IncludeField( 6, fldcuerpo, “CUERPO” )

Call fldlistora.IncludeField( 7, fldadjunto1, “ADJUNTO1” )

Call fldlistora.IncludeField( 8, fldadjunto2, “ADJUNTO2” )

'Datos de la conexión al sistema de archivos

lcfile.Database = LOracle( “Ruta” )

lcfile.Binary = True

'Datos de la conexión a Oracle

lcora.MapByName = True

lcora.Server = LOracle( “Servicio” )

lcora.Userid = LOracle( “Usuario” )

lcora.Password = LOracle( “Password” )

lcora.Metadata = LOracle( “Tabla” )

'Realizar la conexión

lcfile.Connect

lcora.Connect

conectado = True

PrintON “Conectado a Oracle”

Set bd = ses.CurrentDatabase

consulta = {Form = “Memo” & !(Procesado = “1”)}

Set colec = bd.Search( consulta, dtFecha, 0 )

For intCont = 1 To colec.Count

Set doc = colec.GetNthDocument( intCont )

TratarDocumento doc

fldid.Text = ValorCampo( doc, “ID” )

fldasunto.Text = ValorCampo( doc, “ASUNTO” )

fldcreador.Text = ValorCampo( doc, “CREADOR” )

fldsolicitante.Text = ValorCampo( doc, “SOLICITANTE” )

fldfecha.Text = ValorCampo( doc, “FECHA” )

fldcuerpo.Text = ValorCampo( doc, “CUERPO” )

Call lcfile.Select( Nothing, 1, fldlistfile )

lcfile.Fetch fldlistfile

Set fldadjunto1 = fldlistfile.Lookup( “Contents” )

lcfile.Fetch fldlistfile

Set fldadjunto2 = fldlistfile.Lookup( “Contents” )

Call lcora.Insert( fldlistora )

EliminarArchivos doc

Next

If conectado Then

lcfile.Disconnect

lcora.Disconnect

End If

Exit Sub

TratarError:

Select Case Err

Case 75

Resume Next

Case Else

Msgbox Cstr( Err ) & ": " & Error$( Err )



If conectado Then

	lcfile.Disconnect

	lcora.Disconnect



End If

Exit Sub

End Select

Subject: Write attachments in blob fields

Carlos,

You can use the MapName method to link the “Contents” field to the “ADJUNTO1” field and then append the other fields to fldlistora:

'Dim variables

.

.

.

.

Set lcora = New LCConnection( “oracle8” )

Set lcfile = New LCConnection( “file” ) ’

'file resource

.

.

.

.

call lcfile.select(Nothing,1,fldlistfile)

call fldlistora.MapName(fldlistfile,“Contents”,“ADJUNTO1”)

call fldlistora.Append(“ID”, LCTYPE_XXX)

'Set values needed

.

.

.

.

call lcfile.fetch(fldlistfile)

call lcora.Insert(fldlistora)

.

.

.