![]() |
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) Unzip a Text File Entry into a StringBuilder Using ZipEntry.UnzipToSbSee more Zip Examples This example demonstrates how to use the The ZIP entry is uncompressed entirely in memory and appended to the StringBuilder without creating a temporary file on disk. This is useful when:
The
The
Suppose the ZIP archive contains: The example inflates the JSON file directly into 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 DECLARE @zip int EXEC @hr = sp_OACreate 'Chilkat.Zip', @zip OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- Open an existing ZIP archive. EXEC sp_OAMethod @zip, 'OpenZip', @success OUT, 'qa_data/zips/configFiles.zip' IF @success = 0 BEGIN EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @zip RETURN END -- Locate the JSON file entry within the ZIP archive. DECLARE @entry int EXEC @hr = sp_OACreate 'Chilkat.ZipEntry', @entry OUT EXEC sp_OAMethod @zip, 'EntryOf', @success OUT, 'config/settings.json', @entry IF @success = 0 BEGIN PRINT 'ZIP entry not found.' EXEC sp_OAMethod @zip, 'CloseZip', NULL EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @entry RETURN END -- ------------------------------------------------------------ -- Inflate the ZIP entry directly into a StringBuilder. -- -- The uncompressed text is appended to the StringBuilder. -- DECLARE @sb int EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sb OUT -- Leave line endings unchanged. DECLARE @lineEndingBehavior int SELECT @lineEndingBehavior = 0 -- Interpret the uncompressed bytes as UTF-8 text. DECLARE @srcCharset nvarchar(4000) SELECT @srcCharset = 'utf-8' EXEC sp_OAMethod @entry, 'UnzipToSb', @success OUT, @lineEndingBehavior, @srcCharset, @sb IF @success = 0 BEGIN EXEC sp_OAGetProperty @entry, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @entry EXEC @hr = sp_OADestroy @sb RETURN END PRINT 'Uncompressed text:' PRINT '' EXEC sp_OAMethod @sb, 'GetAsString', @sTmp0 OUT PRINT @sTmp0 EXEC sp_OAMethod @zip, 'CloseZip', NULL PRINT 'Done.' EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @entry EXEC @hr = sp_OADestroy @sb END GO |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.