![]() |
VOOZH | about |
The CData Cmdlets for IBM Informix are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to IBM Informix.
The Cmdlets are not only a PowerShell interface to IBM Informix, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete IBM Informix data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for IBM Informix. To access IBM Informix data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for IBM Informix.
Once you have acquired the necessary connection properties, accessing IBM Informix data in PowerShell can be enabled in three steps.
Set the following properties to connect to IBM Informix
Install the module:
Install-Module InformixCmdlets
Connect:
$informix = Connect-Informix -Server "$Server" -Port "$Port" -User "$User" -Password "$Password" -Database "$Database"
Search for and retrieve data:
$category = "US" $books = Select-Informix -Connection $informix -Table "Books" -Where "Category = `'$Category`'" $books
You can also use the Invoke-Informix cmdlet to execute SQL commands:
$books = Invoke-Informix -Connection $informix -Query 'SELECT * FROM Books WHERE Category = @Category' -Params @{'@Category'='US'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for IBM Informix\lib\System.Data.CData.Informix.dll")
Connect to IBM Informix:
$conn= New-Object System.Data.CData.Informix.InformixConnection("Server=10.0.1.2;Port=50000;User=admin;Password=admin;Database=test;")
$conn.Open()
Instantiate the InformixDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Id, Price from Books"
$da= New-Object System.Data.CData.Informix.InformixDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.id $_.price
}
Update-Informix -Connection $Informix -Columns @('Id','Price') -Values @('MyId', 'MyPrice') -Table Books -Id "MyId"
$cmd = New-Object System.Data.CData.Informix.InformixCommand("UPDATE Books SET Category='US' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Informix.InformixParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-Informix -Connection $Informix -Table Books -Columns @("Id", "Price") -Values @("MyId", "MyPrice")
$cmd = New-Object System.Data.CData.Informix.InformixCommand("INSERT INTO Books (Category) VALUES (@myCategory)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Informix.InformixParameter("@myCategory","US")))
$cmd.ExecuteNonQuery()
Remove-Informix -Connection $Informix -Table "Books" -Id "MyId"
$cmd = New-Object System.Data.CData.Informix.InformixCommand("DELETE FROM Books WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Informix.InformixParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the IBM Informix Data Provider to get started:
Download NowLearn more:
👁 IBM Informix IconRapidly create and deploy powerful .NET applications that integrate with IBM Informix.