Wednesday, March 17, 2010

VBscript to retrieve BLOB data type



BLOB data type: 


A BLOB (binary large object) is a varying-length binary string that can be up to 2,147,483,647 characters long. Like other binary types, BLOB strings are not associated with a code page. In addition, BLOB strings do not hold character data.

You can use a BLOB data type to store any data that a program can generate: graphic images, satellite images, video clips, audio clips, or formatted documents saved by any word processor or spreadsheet. The database server permits any kind of data of any length in a BLOB column. 

Like CLOB objects, BLOB objects are stored in whole disk pages in separate disk areas from normal row data.

The advantage of the BLOB data type, as opposed to CLOB, is that it accepts any data. Otherwise, the advantages and disadvantages of the BLOB data type are the same as for the CLOB data type.

 

VBscript to read BLOB:
'Create the connection, recordset & stream objects
set oCon = CreateObject("ADODB.Connection")
Set oRs = CreateObject("ADODB.Recordset")
set mstream = CreateObject("ADODB.Stream")
mstream.Type = 1 'adTypeBinary
'Open SQL connection
oCon.Open pstr
oRs.CursorType = 0 'adOpenForwardOnly
sql="select Data_Value from <Table_Name> where <Variable>"
'Run the Query
oRs.open sql,oCon
'oRs.MoveFirst
Do While Not oRs.EOF
If oRs.Status = adRecModified Then
mstream.Open
mstream.Write oRs("Data_Value")
mstream.SaveToFile <FileName>, 2 'adSaveCreateOveWrite , also tried
mstream.close
End If
oRs.MoveNext
Loop
oRs.close
oCon.Close
Set oRs = Nothing
Set oCon = Nothing
set mstream=Nothing




Blogger Labels: VBscript,BLOB,data,length,addition,satellite,processor,database,server,column,CLOB,disk,areas,advantage,Otherwise,advantages,disadvantages,Create,connection,CreateObject,ADODB,Recordset,Stream,Type,Open,CursorType,Data_Value,Table_Name,Variable,Query,MoveFirst,Status,Write,SaveToFile,FileName,MoveNext,Loop,Close,oCon,mstream