Skip to content

Instantly share code, notes, and snippets.

@TiloGit
Last active January 23, 2025 23:40
Show Gist options
  • Save TiloGit/eed089c56aa1aa07d060d46294b0cbdc to your computer and use it in GitHub Desktop.
Save TiloGit/eed089c56aa1aa07d060d46294b0cbdc to your computer and use it in GitHub Desktop.
Read IBM FileNet GCD from Database as XML script
$SQLServer = "mysqlserver1232.westus2.cloudapp.azure.com"
$SQLDBName = "ABC_FNGCD"
$uid ="sa"
$pwd = "my-db-pass123"
##modify below query if you want specific GCD version
$SqlQuery = "select gcd_blob FROM FNGCD WHERE epoch_id = (select last_epoch_id from FNGCD where epoch_id = 0);"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; User ID = $uid; Password = $pwd;"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$DataSet.Tables
$instream = [System.IO.MemoryStream]::new($DataSet.Tables.gcd_blob)
$zlib = [System.IO.Compression.ZLibStream]::new(
$instream,
[System.IO.Compression.CompressionMode]::Decompress)
$outstream = [System.IO.MemoryStream]::new()
$zlib.CopyTo($outstream)
$zlib.Dispose()
# Choose encoding here
$enc = [System.Text.Encoding]::UTF8
##out to console
$enc.GetString($outstream.ToArray())
##out to XML file
$enc.GetString($outstream.ToArray()) | out-file my-gcd.xml -encoding utf8
@TiloGit
Copy link
Author

TiloGit commented Jan 20, 2025

IBM FileNet GCD (XML) is compressed with zlib stored in DB Blob/binary/bytea column these days it seems. If you have the GCDUtil from IBM support you still better of using that one.

If you have Java use java.util.zip.InflaterOutputStream (zlib)

Here a little PS script (needs 7.x or newer PS) to read the zlib compressed GCD and output as XML.

if you get

MethodInvocationException: Exception calling "CopyTo" with "1" argument(s): "The archive entry was compressed using an unsupported compression method."

your GCD is not compressed and you can just use plain MS SQL CMD

--read if uncompressed stored blob
SELECT CAST(cast(gcd_blob AS VARBINARY(MAX)) AS XML) AS MyXml
FROM FNGCD WHERE epoch_id = (select last_epoch_id from [ABC_FNGCD].[dbo].[FNGCD] where epoch_id = 0)

if I get around will do a bash script/other DBs

see here for other info about the GCD: https://bpmadmin.blogspot.com/2013/09/how-to-open-filenet-global_25.html

@TiloGit
Copy link
Author

TiloGit commented Jan 23, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment