![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Compress a File to Gzip with Custom MetadataSee more Gzip ExamplesThis example demonstrates how to use the Before compression, several properties are set:
After setting these properties, the input file is compressed and written to a
-- 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) DECLARE @success int SELECT @success = 0 -- This example demonstrates how to compress a file to Gzip format -- while setting custom metadata such as comment, filename, -- compression level, and last-modified date. DECLARE @gzip int EXEC @hr = sp_OACreate 'Chilkat.Gzip', @gzip OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- Set custom Gzip properties: EXEC sp_OASetProperty @gzip, 'Comment', 'Example Gzip file created with Chilkat' EXEC sp_OASetProperty @gzip, 'Filename', 'custom_name.txt' EXEC sp_OASetProperty @gzip, 'CompressionLevel', 9 EXEC sp_OASetProperty @gzip, 'LastModStr', 'Wed, 1 Apr 2025 12:45:26 -0500' -- The file to be compressed: DECLARE @inputFile nvarchar(4000) SELECT @inputFile = 'example.txt' DECLARE @outputFile nvarchar(4000) SELECT @outputFile = 'example.txt.gz' -- Compress the file: EXEC sp_OAMethod @gzip, 'CompressFile', @success OUT, @inputFile, @outputFile IF @success = 0 BEGIN EXEC sp_OAGetProperty @gzip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @gzip RETURN END PRINT 'Compression successful.' PRINT 'Gzip file created: ' + @outputFile EXEC @hr = sp_OADestroy @gzip END GO |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.