Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

Is it possible from within a stored procedure to zip up files ?

asked 14 Feb '13, 18:06

spc's gravatar image

spc
1699918
accept rate: 0%

edited 15 Feb '13, 03:54

Volker%20Barth's gravatar image

Volker Barth
40.2k361550822


There is nothing built into the server to zip up the files, but you can easily call an [external procedure][1] to do it, or use [xp\_cmdshell][2] to run an external process that will zip up the files for you.

[edit 2013-02-15]

Sorry, most of my response above is bogus... I confused compression with encryption :-(

Since SA v10 the compress() and decompress() functions have had a second parameter named 'algorithm' which when set to 'gzip' can be used to compress/decompress data that can be exchanged outside of the database server and decompressed/compressed using gunzip/gzip.

Example:

-- write compressed contents of variable @data to file data.gz
call xp_write_file( 'data.gz', compress( @data, 'gzip' ) );
-- and then decompress it using gunzip
call xp_cmdshell( 'gunzip data.gz' );
permanent link

answered 14 Feb '13, 21:00

Mark%20Culp's gravatar image

Mark Culp
24.9k10141297
accept rate: 41%

edited 15 Feb '13, 15:20

2

It's the tie you're wearing in your photo... restricts the bloodflow :)

(15 Feb '13, 15:25) Breck Carter

What about reading the file with xp_read_file() and using the builtin COMPRESS() function to compress data and write it back to file with xp_write_file()?

Note, I can't tell whether the builtin compression with the "zip" algorithm will be compatible with ordinary zipped files. On Linux, using "gzip" should work that way. - Mark's response may indicate that "zip" itself won't work here as expected...

permanent link

answered 15 Feb '13, 03:54

Volker%20Barth's gravatar image

Volker Barth
40.2k361550822
accept rate: 34%

edited 15 Feb '13, 03:55

Using compress within the engine will compress the data contents but you cannot unzip the result outside of the engine (unless you know what you're doing). The same is true the other way - you cannot use uncompress to unzip contents which have been zipped outside the engine. (Note: this comment applies to SA v12 and below).

[Edit: 2013-02-15 this statement is incorrect - I have corrected my answer to this question]

Also, the question was not clear whether a single file was being zipped or a zip archive (containing multiple files) was wanted.

(15 Feb '13, 07:26) Mark Culp
Replies hidden

Thanks for the clarification - I had a weak impression I had read about that limitation in some FAQ or NNTP thread (therefore my suspicion...) but couldn't find anything relevant.

Now it's well-documented here, at least:)

(15 Feb '13, 08:12) Volker Barth

(Note: this comment applies to SA v12 and below).

Hmmm, have I overseen something in the Nagano docs...?

(15 Feb '13, 08:35) Volker Barth

Now it's well-documented here, at least:)

Hmm, I'm not so sure anymore:)

(16 Feb '13, 05:22) Volker Barth

Okay, when Mark has been refering to encryption instead of compression, then the v16 hint makes sense ("Raw encryption", do you hear me?)...

(16 Feb '13, 05:23) Volker Barth

I ended up downloading 7-Zip, writing a bat file to call 7 Zip, and then calling that bat file with an Event. Worked well.

permanent link

answered 17 Jun '13, 14:01

spc's gravatar image

spc
1699918
accept rate: 0%

edited 28 Jan '14, 19:24

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:

×125
×13

question asked: 14 Feb '13, 18:06

question was seen: 4,781 times

last updated: 28 Jan '14, 19:24