![]() |
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) Add Binary Data to a ZIP Using AddBdSee more Zip ExamplesThis example demonstrates how to use the The data is created entirely in memory, added to the ZIP as
-- 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 -- Create a new ZIP archive. DECLARE @zip int EXEC @hr = sp_OACreate 'Chilkat.Zip', @zip OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END EXEC sp_OAMethod @zip, 'NewZip', @success OUT, 'inMemoryData.zip' IF @success = 0 BEGIN EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @zip RETURN END -- Create a BinData object containing binary content. DECLARE @bd int EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT -- Append some bytes as hexadecimal. -- The decoded bytes will become the contents of the ZIP entry. EXEC sp_OAMethod @bd, 'AppendEncoded', @success OUT, '000102030405060708090A0B0C0D0E0F', 'hex' IF @success = 0 BEGIN EXEC sp_OAGetProperty @bd, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @bd RETURN END -- Add the BinData contents as a file entry within the ZIP. -- The file will be stored as "data/binary.dat" inside the ZIP archive. EXEC sp_OAMethod @zip, 'AddBd', @success OUT, 'data/binary.dat', @bd IF @success = 0 BEGIN EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @bd RETURN END -- Write the ZIP archive to disk and close it. EXEC sp_OAMethod @zip, 'WriteZipAndClose', @success OUT IF @success = 0 BEGIN EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @bd RETURN END PRINT 'ZIP archive created successfully.' EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @bd END GO |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.