![]() |
VOOZH | about |
The CData Cmdlets for SingleStore 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 SingleStore.
The Cmdlets are not only a PowerShell interface to SingleStore, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete SingleStore data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for SingleStore. To access SingleStore data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for SingleStore.
Once you have acquired the necessary connection properties, accessing SingleStore data in PowerShell can be enabled in three steps.
The following connection properties are required in order to connect to data.
To authenticate using standard authentication, set the following:
As an alternative to providing the standard username and password, you can set IntegratedSecurity to True to authenticate trusted users to the server via Windows Authentication.
You can leverage SSL authentication to connect to SingleStore data via a secure session. Configure the following connection properties to connect to data:
Using SSH, you can securely login to a remote machine. To access SingleStore data via SSH, configure the following connection properties:
Install the module:
Install-Module SingleStoreCmdlets
Connect:
$singlestore = Connect-SingleStore -User "$User" -Password "$Password" -Database "$Database" -Server "$Server" -Port "$Port"
Search for and retrieve data:
$shipcountry = "USA" $orders = Select-SingleStore -Connection $singlestore -Table "Orders" -Where "ShipCountry = `'$ShipCountry`'" $orders
You can also use the Invoke-SingleStore cmdlet to execute SQL commands:
$orders = Invoke-SingleStore -Connection $singlestore -Query 'SELECT * FROM Orders WHERE ShipCountry = @ShipCountry' -Params @{'@ShipCountry'='USA'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for SingleStore\lib\System.Data.CData.SingleStore.dll")
Connect to SingleStore:
$conn= New-Object System.Data.CData.SingleStore.SingleStoreConnection("User=myUser;Password=myPassword;Database=NorthWind;Server=myServer;Port=3306;")
$conn.Open()
Instantiate the SingleStoreDataAdapter, execute an SQL query, and output the results:
$sql="SELECT ShipName, ShipCity from Orders"
$da= New-Object System.Data.CData.SingleStore.SingleStoreDataAdapter($sql, $conn)
$dt= New-Object System.Data.DataTable
$da.Fill($dt)
$dt.Rows | foreach {
Write-Host $_.shipname $_.shipcity
}
Update-SingleStore -Connection $SingleStore -Columns @('ShipName','ShipCity') -Values @('MyShipName', 'MyShipCity') -Table Orders -Id "MyId"
$cmd = New-Object System.Data.CData.SingleStore.SingleStoreCommand("UPDATE Orders SET ShipCountry='USA' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SingleStore.SingleStoreParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Add-SingleStore -Connection $SingleStore -Table Orders -Columns @("ShipName", "ShipCity") -Values @("MyShipName", "MyShipCity")
$cmd = New-Object System.Data.CData.SingleStore.SingleStoreCommand("INSERT INTO Orders (ShipCountry) VALUES (@myShipCountry)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SingleStore.SingleStoreParameter("@myShipCountry","USA")))
$cmd.ExecuteNonQuery()
Remove-SingleStore -Connection $SingleStore -Table "Orders" -Id "MyId"
$cmd = New-Object System.Data.CData.SingleStore.SingleStoreCommand("DELETE FROM Orders WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SingleStore.SingleStoreParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject
Download a free trial of the SingleStore Data Provider to get started:
Download NowLearn more:
👁 SingleStore IconRapidly create and deploy powerful .NET applications that integrate with SingleStore.