(SQL Server) GZip Decompress File
Demonstrates how to uncompress a .gz compressed file to get the uncompressed original file.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @gzip int
-- Use "Chilkat_9_5_0.Gzip" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.Gzip', @gzip OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
EXEC sp_OAMethod @gzip, 'UncompressFile', @success OUT, 'qa_data/gzip/something.csv.gz', 'qa_output/something.csv'
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @gzip, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @gzip
RETURN
END
PRINT 'File successfully uncompressed and extracted from the Gzip compressed format.'
EXEC @hr = sp_OADestroy @gzip
END
GO
|