Grüße Euch, wie schreibt an SQL z.B. eine .JPG Imagedatei in ein IMAGE Feld?

VG Franz

asked 24 Jan, 09:19

Franz_Stf's gravatar image

Franz_Stf
157101115
accept rate: 0%

edited 24 Jan, 10:56

Volker%20Barth's gravatar image

Volker Barth
39.7k357545814


You can use xp_read_file() to load the file's contents, and then just use the return value as value within an INSERT and/or UPDATE statement, such as

UPDATE MyTable
SET MyImage = xp_read_file('c:\\Gallery\\MyTest.jpg')
WHERE ID = 1;

Column MyTable should be of LONG BINARY (or IMAGE) data type. This should work for any kind of BLOBs (binary large objects).

permanent link

answered 24 Jan, 10:54

Volker%20Barth's gravatar image

Volker Barth
39.7k357545814
accept rate: 34%

edited 24 Jan, 10:56

Danke, hat geklappt! Wie funktioniert der umgekehrte Fall, also das BLOB auslesen...? VG Franz

(25 Jan, 06:54) Franz_Stf
Replies hidden

Similarly you can use xp_write_file() to store a BLOB's contents in a OS file, such as

SELECT xp_write_file('c:\\Gallery\\MyTestKopie.jpg', MyImage)
FROM MyTable
WHERE ID = 1;

Of course, you can also use local variables within SQL to handle BLOBs, such as

begin
   declare myVar long binary;
   set myVar = xp_read_file('c:\\Gallery\\MyTest.jpg');
   xp_write_file(myBlob, ('c:\\Gallery\\MyTestKopie.jpg', myVar);
end;

Both file functions are server-based and use path specifications that must be accessible for the database engine. For client-side access, you can use READ_CLIENT_FILE() resp. WRITE_CLIENT_FILE().

(25 Jan, 08:44) Volker Barth

Danke, hat auch geklappt. Aber mit den Proportionen der Bilder hab ich meine Probleme, aber das ist ein Anzeigeproblem. Vielen Dank nochmal!

(25 Jan, 10:30) Franz_Stf

... noch eine Frage: Kann man VOR xp_write_file feststellen, welche Extention das Bild Hat? VG Franz

(30 Jan, 04:44) Franz_Stf
Replies hidden

The type of file stored in a BLOB has nothing to do with SQL Anywhere...

AFAIK, most picture formats will have identifying values in the first bytes of the contents - but it sure would be waaayyyy easier to store the file name and/or MIME type when storing the file contents, so it is already available when you want to export the file. :)

(30 Jan, 05:55) Volker Barth

... so habe ich es auch schon gemacht. Vielen Dank!

(30 Jan, 08:43) Franz_Stf
showing 4 of 6 show all flat view
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×11

question asked: 24 Jan, 09:19

question was seen: 711 times

last updated: 30 Jan, 08:43