Hi I am storing a file in the DB and I had some problems with it but then was able to do it with some help. Now this is becoming strange as I try to retreive the file back and store it in a directory. [CODE] aFileNameAsString:= 'install.log'. " Or Car.jpg" fileExt := aFileNameAsString copyFrom: (aFileNameAsString size-3) to: (aFileNameAsString size). fileWildCard:= aFileNameAsString copyFrom:1 to:(aFileNameAsString size-4). connection := Database.MS_SQLServerConnection new. connection username: 'user'; password: 'paswd'. connection environment: 'Driver={SQL Native Client};Server=Myserver;Database=Mydev;Uid=user;Pwd=paswd;'. connection connect. session := connection getSession. session prepare: 'SELECT FILEDATA FROM TBFile WHERE (FILENAME LIKE ''%' , fileWildCard , '%'')'. session execute. something :=session answer . something := something upToEnd. someData := something at:1. someMoreData := someData at:1. " I need the first value" session disconnect. connection disconnect. [/CODE] It does not matter what filename I give a txt file or a jpeg the output is coming the same alternatively: The first time I would inspect someData it will give me this as a ByteArray #[88 228 206 0 0 0 2 0 2 0 2 0 126 1 12 0 240 201 52 0 0 0 2 0 2 0 2 0 112 1 12 0 232 203 52 0 0 0 2 0 2 0 2 0 114 1 15 0 40 192...etc...] Or the enxt time I inspect it, it gives me this as a ByteArray: #[16 202 52 0 0 0 2 0 2 0 2 0 149 1 8 1 64 255 52 0 0 0 0 0 2 0 2 0 151 1 12 1 72 192 206 0 0 0 2 0 9 0 2 0 137 1 12 1 224 1...etc...] (this doesn't make sense to me, what am I doing wrong here) I used the Ad Hoc SQL in VW and the FILEDATA actually stores something totally different, #[255 216 255 224 0 16 74 70 73 70 0 1 1 1 0 96 0 96 0 0 255 225 0 110 69 120 105 102 0 0 73 73 42 0 8 0 0 0 1 0 105 135 4 0 1 0 0 0 26 0...etc...] Car.jpg #[255 216 255 224 0 16 74 70 73 70 0 1 1 1 0 96 0 96 0 0 255 225 0 22 69 120 105 102 0 0 73 73 42 0 8 0 0 0 0 0 0 0 0 0 255 219 0 67 0 8...etc...]Yatch.jpg #[255 216 255 224 0 16 74 70 73 70 0 1 1 1 0 96 0 96 0 0 255 225 0 22 69 120 105 102 0 0 73 73 42 0 8 0 0 0 0 0 0 0 0 0 255 219 0 67 0 8...etc...]House.jpg #[255 216 255 224 0 16 74 70 73 70 0 1 1 1 0 96 0 96 0 0 255 225 0 110 69 120 105 102 0 0 73 73 42 0 8 0 0 0 1 0 105 135 4 0 1 0 0 0 26 0...etc...]Car.jpg again this is exactly what I need hen I am retreieving back, storing the file is correct as this data can be streamed back into the directory, but when I retreieve it from the database, the same data comes totally different. Any help would be appreciated. Thanks. Regards, Syed Mahdi Software Engineer _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
If you want to store and retrieve binary files from your database you
should create your byteArray as follows: stream := 'somefilename' asFilename readStream. stream binary. myByteArray := stream contents. to write back something like: newFile := myBinFile fileName asFilename. stream := newFile writeStream binary. stream nextPutAll: myByteArray. stream close. PS You will most likely run into some other problems related to the size of your Blobs. @+Maarten, Syed Mahdi a écrit : > > Hi > I am storing a file in the DB and I had some problems with it but then was able to do it with some help. Now this is becoming > strange as I try to retreive the file back and store it in a directory. > > [CODE] > aFileNameAsString:= 'install.log'. " Or Car.jpg" > fileExt := aFileNameAsString copyFrom: (aFileNameAsString size-3) to: (aFileNameAsString size). > fileWildCard:= aFileNameAsString copyFrom:1 to:(aFileNameAsString size-4). > > connection := Database.MS_SQLServerConnection new. > connection > username: 'user'; > password: 'paswd'. > connection environment: > 'Driver={SQL Native Client};Server=Myserver;Database=Mydev;Uid=user;Pwd=paswd;'. > connection connect. > session := connection getSession. > session > prepare: > 'SELECT FILEDATA FROM TBFile WHERE (FILENAME LIKE ''%' , fileWildCard > , '%'')'. > session execute. > something :=session answer . > something := something upToEnd. > someData := something at:1. > someMoreData := someData at:1. " I need the first value" > session disconnect. > connection disconnect. > > [/CODE] > > It does not matter what filename I give a txt file or a jpeg the output is coming the same alternatively: > > The first time I would inspect someData it will give me this as a ByteArray > #[88 228 206 0 0 0 2 0 2 0 2 0 126 1 12 0 240 201 52 0 0 0 2 0 2 0 2 0 112 1 12 0 232 203 52 0 0 0 2 0 2 0 2 0 114 1 15 0 40 > 192...etc...] > Or the enxt time I inspect it, it gives me this as a ByteArray: > #[16 202 52 0 0 0 2 0 2 0 2 0 149 1 8 1 64 255 52 0 0 0 0 0 2 0 2 0 151 1 12 1 72 192 206 0 0 0 2 0 9 0 2 0 137 1 12 1 224 > 1...etc...] > (this doesn't make sense to me, what am I doing wrong here) > > I used the Ad Hoc SQL in VW and the FILEDATA actually stores something totally different, #[255 216 255 224 0 16 74 70 73 70 0 1 1 1 > 0 96 0 96 0 0 255 225 0 110 69 120 105 102 0 0 73 73 42 0 8 0 0 0 1 0 105 135 4 0 1 0 0 0 26 0...etc...] Car.jpg > #[255 216 255 224 0 16 74 70 73 70 0 1 1 1 0 96 0 96 0 0 255 225 0 22 69 120 105 102 0 0 73 73 42 0 8 0 0 0 0 0 0 0 0 0 255 219 0 67 > 0 8...etc...]Yatch.jpg > #[255 216 255 224 0 16 74 70 73 70 0 1 1 1 0 96 0 96 0 0 255 225 0 22 69 120 105 102 0 0 73 73 42 0 8 0 0 0 0 0 0 0 0 0 255 219 0 67 > 0 8...etc...]House.jpg > #[255 216 255 224 0 16 74 70 73 70 0 1 1 1 0 96 0 96 0 0 255 225 0 110 69 120 105 102 0 0 73 73 42 0 8 0 0 0 1 0 105 135 4 0 1 0 0 0 > 26 0...etc...]Car.jpg again > > this is exactly what I need hen I am retreieving back, storing the file is correct as this data can be streamed back into the > directory, but when I retreieve it from the database, the same data comes totally different. > > Any help would be appreciated. > > > > Thanks. > Regards, > Syed Mahdi > Software Engineer > > > _______________________________________________ > vwnc mailing list > [hidden email] > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > > > _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Hi I can write store the file correctly, and also write the binary data to a file in a directory correctly as well, its only the data that is coming from the DB is wrong/different from what is stored in the DB table. Even the file binary data stored in the table is correct its just the ByetArray that comes back from the DB table through the SQL query is different. Thanks for your help though. Thanks. Regards, Syed Mahdi Software Engineer Omnitec International,P.O. Box 500229, Dubai Internet City, U.A.E. Tel.: +971-4-3616798 Fax: +971-4-3908521 E-Mail: [hidden email] -----Original Message----- From: Maarten Mostert [mailto:[hidden email]] Sent: Thursday, September 04, 2008 12:44 AM To: Syed Mahdi Cc: [hidden email] Subject: Re: [vwnc] retreiving Binary data from DB If you want to store and retrieve binary files from your database you should create your byteArray as follows: stream := 'somefilename' asFilename readStream. stream binary. myByteArray := stream contents. to write back something like: newFile := myBinFile fileName asFilename. stream := newFile writeStream binary. stream nextPutAll: myByteArray. stream close. PS You will most likely run into some other problems related to the size of your Blobs. @+Maarten, Syed Mahdi a écrit : > > Hi > I am storing a file in the DB and I had some problems with it but then was able to do it with some help. Now this is becoming > strange as I try to retreive the file back and store it in a directory. > > [CODE] > aFileNameAsString:= 'install.log'. " Or Car.jpg" > fileExt := aFileNameAsString copyFrom: (aFileNameAsString size-3) to: (aFileNameAsString size). > fileWildCard:= aFileNameAsString copyFrom:1 to:(aFileNameAsString size-4). > > connection := Database.MS_SQLServerConnection new. > connection > username: 'user'; > password: 'paswd'. > connection environment: > 'Driver={SQL Native Client};Server=Myserver;Database=Mydev;Uid=user;Pwd=paswd;'. > connection connect. > session := connection getSession. > session > prepare: > 'SELECT FILEDATA FROM TBFile WHERE (FILENAME LIKE ''%' , fileWildCard > , '%'')'. > session execute. > something :=session answer . > something := something upToEnd. > someData := something at:1. > someMoreData := someData at:1. " I need the first value" > session disconnect. > connection disconnect. > > [/CODE] > > It does not matter what filename I give a txt file or a jpeg the output is coming the same alternatively: > > The first time I would inspect someData it will give me this as a ByteArray > #[88 228 206 0 0 0 2 0 2 0 2 0 126 1 12 0 240 201 52 0 0 0 2 0 2 0 2 0 112 1 12 0 232 203 52 0 0 0 2 0 2 0 2 0 114 1 15 0 40 > 192...etc...] > Or the enxt time I inspect it, it gives me this as a ByteArray: > #[16 202 52 0 0 0 2 0 2 0 2 0 149 1 8 1 64 255 52 0 0 0 0 0 2 0 2 0 151 1 12 1 72 192 206 0 0 0 2 0 9 0 2 0 137 1 12 1 224 > 1...etc...] > (this doesn't make sense to me, what am I doing wrong here) > > I used the Ad Hoc SQL in VW and the FILEDATA actually stores something totally different, #[255 216 255 224 0 16 74 70 73 70 0 1 1 > 0 96 0 96 0 0 255 225 0 110 69 120 105 102 0 0 73 73 42 0 8 0 0 0 1 0 105 135 4 0 1 0 0 0 26 0...etc...] Car.jpg > #[255 216 255 224 0 16 74 70 73 70 0 1 1 1 0 96 0 96 0 0 255 225 0 22 69 120 105 102 0 0 73 73 42 0 8 0 0 0 0 0 0 0 0 0 255 219 0 67 > 0 8...etc...]Yatch.jpg > #[255 216 255 224 0 16 74 70 73 70 0 1 1 1 0 96 0 96 0 0 255 225 0 22 69 120 105 102 0 0 73 73 42 0 8 0 0 0 0 0 0 0 0 0 255 219 0 67 > 0 8...etc...]House.jpg > #[255 216 255 224 0 16 74 70 73 70 0 1 1 1 0 96 0 96 0 0 255 225 0 110 69 120 105 102 0 0 73 73 42 0 8 0 0 0 1 0 105 135 4 0 1 0 0 0 > 26 0...etc...]Car.jpg again > > this is exactly what I need hen I am retreieving back, storing the file is correct as this data can be streamed back into the > directory, but when I retreieve it from the database, the same data comes totally different. > > Any help would be appreciated. > > > > Thanks. > Regards, > Syed Mahdi > Software Engineer > > > _______________________________________________ > vwnc mailing list > [hidden email] > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > > > _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Free forum by Nabble | Edit this page |