I wrote a small test on VBS, but you can easily redo this code for your language. For details on working with streams for ADO, see the documentation.
Code on Visual Basic Script
adVarChar=200
adLongVarChar=201
adLongVarBinary=205
adParamInput=1
adCmdText=1
adExecuteNoRecords=128
Set cn=Createobject("ADODB.Connection")
cn.ConnectionString="DRIVER={InterSystems IRIS ODBC35}; SERVER=127.0.0.1; PORT=1972; DATABASE=USER; UID=_system; PWD=SYS;"
cn.openSet cmd = Createobject("ADODB.Command")
with cmd
.ActiveConnection = cn
.CommandText = "CREATE TABLE dc.test(Name VARCHAR(50) NOT NULL,Notes TEXT,Photo IMAGE)"
.Execute ,,adCmdText + adExecuteNoRecords
.CommandText = "insert into dc.test(Name,Notes,Photo)values(?,?,?)"
.Parameters.Append .CreateParameter("pName", adVarChar, adParamInput, 50, "blablabla")
.Parameters.Append .CreateParameter("pNotes", adLongVarChar, adParamInput, 2147483647, ReadTextFile("C:\bigText.txt","Windows-1251"))
.Parameters.Append .CreateParameter("pPhoto", adLongVarBinary, adParamInput, 2147483647, ReadBinaryFile("C:\bigImage.png"))
.Execute ,,adCmdText + adExecuteNoRecords
end with
WScript.Echo "Succesfully!"Function ReadBinaryFile(FileName)
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To get binary data.
BinaryStream.Type = adTypeBinary
'Open the stream
BinaryStream.Open
'Load the file data from disk To stream object
BinaryStream.LoadFromFile FileName
'Open the stream And get binary data from the object
ReadBinaryFile = BinaryStream.Read
End FunctionFunction ReadTextFile(FileName, CharSet)
Const adTypeText = 2
'Create Stream object
Dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To get binary data.
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
If Len(CharSet) > 0 Then
BinaryStream.CharSet = CharSet
End If
'Open the stream
BinaryStream.Open
'Load the file data from disk To stream object
BinaryStream.LoadFromFile FileName
'Open the stream And get binary data from the object
ReadTextFile = BinaryStream.ReadText
End Function
- Log in to post comments