(Down-)Loading a picture (from) into a DB
Hy there! I need some help with the following:
I'm trying to load and download pictures from databases (both embedded
and external data sources like MySQL) using the API with OOoBasic.
I tested it with an embedded HSQL database. I could load the pictures
through the GUI (it was very easy cause the on line help does not give a
clue!). Once I get the connection, I create a statement
oStatement = oConexion.createStatement
sSQL = "SELECT titel, bild FROM bilde"
'bild (=Bild, picture/image) is the LONGVARBINARY field
oResultSet = oStatement .executeQuery(sSQL)
According to the API reference, once we get the stream it returns an
XinputStrean
So I try to do what usually works fine for me when I write and read files:
I give just the example of reading/getting the stream, but setting it
gave me the same problem
Do While NOT IsNull(oResulSelt) AND oResultSet.Next
sTitel = oResultSet.getString(1)
oInputStream = oResultSet.getBinaryStream(2)
'i = oInputStream.available() zero????!!!!!
oFileAccess = createUnoService("com.sun.star.ucb.SimpleFileAccess")
oFile = oFileAccess.openFileWrite("file:///e:/dok/bilde/DATABASE/"
& sTitel & ".png")
oOutputStream = createUnoService("com.sun.star.io.DataOutputStream")
oOutputStream.setOutputStream(oFile)
Dim mData() as Variant
n = -1
While n <> 0
n = oInputStream.readBytes(mData(),
oInputStream.Length)
'if the stream is too long I do not use
Length, but a value xxxx
oOutputStream.writeBytes(mData())
Wend
oOutputStream.flush()
oOutputStream.closeOutput()
oInputStream.closeInput()
ReDim mData() as Variant
Loop
The problem is that getBinaryStream return 0, so there is nothing to read.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]