From: Stephan Schiffels on 15 Jun 2010 02:28 Dear group, I use DatabaseLink to retrieve binary data from a database. So lets say, I retrieve the data as: Needs["DatabaseLink`"]; conn = OpenSQLConnection["myDB"]; data = SQLSelect[conn, "myTable", "myBinaryField"]; Then the type of data[[1,1]] is an SQLBinary-Object, containing a list of bytes, accessible as the first item of the SQLBinary-Wrapper: data[[1,1.1]] I need to read this binary data as a sequence of double precision floating point numbers, similar to the following command: BinaryRead[stream, "Real64"], where "stream" is a file on the harddisk. I have not figured out how to do this with binary data that is already in memory, rather then in a file. All I can find in the documentation is concerned with File I/O. What I can do is to use a temporary file: BinaryWrite["tmp", data[[1,1,1]]]; Close["tmp"]; num = BinaryRead["tmp", "Real64"]; But there clearly should be a way to avoid the creation of binary files here... I appreciate any help. Thanks, Stephan
From: Stephan Schiffels on 16 Jun 2010 05:39 Well, exactly, but there isn't! The binary data looks something like SQLBinary[{12,14,25,123,144,0,0,12,0,0,12,14,34}], i.e. it is just a sequence of bytes, arranged in a list. I coudn't find a way of reading from this byte-array like a stream. As I said, I can write this data to disk, using BinaryWrite... but reading from it like a stream is not possible. If anyone knows how to use the BinaryRead function with such data, I'd really appreciate it. Stephan Am 15.06.2010 um 20:00 schrieb Christopher Arthur: > There should be a database method for this...also, if not, then a channel/stream doesn't have to be a file on disk, so you could still use binaryWrite like a pipe > > Stephan Schiffels a =E9crit : >> Dear group, >> >> I use DatabaseLink to retrieve binary data from a database. >> So lets say, I retrieve the data as: >> >> Needs["DatabaseLink`"]; >> conn == OpenSQLConnection["myDB"]; >> data == SQLSelect[conn, "myTable", "myBinaryField"]; >> >> Then the type of data[[1,1]] is an SQLBinary-Object, containing a list of bytes, accessible as the first item of the SQLBinary-Wrapper: data[[1,1.1]] >> >> I need to read this binary data as a sequence of double precision floating point numbers, similar to the following command: >> >> BinaryRead[stream, "Real64"], where "stream" is a file on the harddisk. >> >> I have not figured out how to do this with binary data that is already in memory, rather then in a file. All I can find in the documentation is concerned with File I/O. >> >> What I can do is to use a temporary file: >> >> BinaryWrite["tmp", data[[1,1,1]]]; >> Close["tmp"]; >> num == BinaryRead["tmp", "Real64"]; >> >> But there clearly should be a way to avoid the creation of binary files here... >> >> I appreciate any help. >> >> Thanks, >> >> Stephan >> >> >> >> >
From: Hans Michel on 16 Jun 2010 05:41 Try myRealDataString = FromCharacterCode[ data[[1, 1, 1]] ]; myRealDataStream = StringToStream[myRealDataString]; num = BinaryRead[myRealDataStream , "Real64"]; Not sure of above step as I don't have a db with bunary data that can be read as 64-bit IEEE double-precision numbers. Close[myRealDataStream] Hans "Stephan Schiffels" <stephan80(a)mac.com> wrote in message news:hv76ig$k0q$1(a)smc.vnet.net... > Dear group, > > I use DatabaseLink to retrieve binary data from a database. > So lets say, I retrieve the data as: > > Needs["DatabaseLink`"]; > conn = OpenSQLConnection["myDB"]; > data = SQLSelect[conn, "myTable", "myBinaryField"]; > > Then the type of data[[1,1]] is an SQLBinary-Object, containing a list of > bytes, accessible as the first item of the SQLBinary-Wrapper: > data[[1,1.1]] > > I need to read this binary data as a sequence of double precision floating > point numbers, similar to the following command: > > BinaryRead[stream, "Real64"], where "stream" is a file on the harddisk. > > I have not figured out how to do this with binary data that is already in > memory, rather then in a file. All I can find in the documentation is > concerned with File I/O. > > What I can do is to use a temporary file: > > BinaryWrite["tmp", data[[1,1,1]]]; > Close["tmp"]; > num = BinaryRead["tmp", "Real64"]; > > But there clearly should be a way to avoid the creation of binary files > here... > > I appreciate any help. > > Thanks, > > Stephan > >
From: Stephan Schiffels on 16 Jun 2010 05:48 Thank you for you help. I have found a way around this problem, which goes along the line of the solution below, but circumvents the Stream: myRealDataString = FromCharacterCode[data[[1,1,1]]]; reals = ImportString[myRealDataString, "Real64"]; This works. I might even switch my database-column format to pure Text, then I don't even have to use FromCharacterCode. Anyway, I guess the problem is solved, Stephan Am 16.06.2010 um 10:21 schrieb Hans Michel: > Try > > myRealDataString = FromCharacterCode[ data[[1, 1, 1]] ]; > > myRealDataStream = StringToStream[myRealDataString]; > > num = BinaryRead[myRealDataStream , "Real64"]; > > Not sure of above step as I don't have a db with bunary data that can be > > read as 64-bit IEEE double-precision numbers. > > Close[myRealDataStream] > > Hans > > "Stephan Schiffels" <stephan80(a)mac.com> wrote in message > news:hv76ig$k0q$1(a)smc.vnet.net... >> Dear group, >> >> I use DatabaseLink to retrieve binary data from a database. >> So lets say, I retrieve the data as: >> >> Needs["DatabaseLink`"]; >> conn = OpenSQLConnection["myDB"]; >> data = SQLSelect[conn, "myTable", "myBinaryField"]; >> >> Then the type of data[[1,1]] is an SQLBinary-Object, containing a list > of >> bytes, accessible as the first item of the SQLBinary-Wrapper: >> data[[1,1.1]] >> >> I need to read this binary data as a sequence of double precision > floating >> point numbers, similar to the following command: >> >> BinaryRead[stream, "Real64"], where "stream" is a file on the > harddisk. >> >> I have not figured out how to do this with binary data that is already > in >> memory, rather then in a file. All I can find in the documentation is >> concerned with File I/O. >> >> What I can do is to use a temporary file: >> >> BinaryWrite["tmp", data[[1,1,1]]]; >> Close["tmp"]; >> num = BinaryRead["tmp", "Real64"]; >> >> But there clearly should be a way to avoid the creation of binary > files >> here... >> >> I appreciate any help. >> >> Thanks, >> >> Stephan >> >> > >
|
Pages: 1 Prev: DiscretePlot Next: how to scale text to a bounding rectangle? |