Reputation: 5745
I have database with tables in WIN1251 encoding. When I read data from tables then all the text that is in Cyrillic are shown as unknown symbols. This is the code I use:
function Get-ODBC-Data {
param([string]$query = $(throw 'query is required.'))
$conn = New-Object System.Data.Odbc.OdbcConnection
$connStr = "Driver=Firebird/Interbase(r) driver;Server=localhost;Port=3050;Database=C:\Users\user\Desktop\B52.GDB;Uid=SYSDBA;Pwd=masterkey;CHARSET=WIN1251"
$conn.ConnectionString = $connStr
$conn.open
$cmd = new-object System.Data.Odbc.OdbcCommand($query, $conn)
$cmd.CommandTimeout = 15
$ds = New-Object system.Data.DataSet
$da = New-Object system.Data.odbc.odbcDataAdapter($cmd)
[void]$da.fill($ds)
$ds.Tables[0]
$conn.close()
}
$query = @"
SELECT name FROM contact;
"@
$result = Get-ODBC-Data -query $query
$customers = @();
foreach ($row in $result) {
if (-not($null -eq $row.name)) {
$customers += $row.name;
}
}
$customers
Upvotes: 2
Views: 1075
Reputation: 108971
You can try specifying the connection character set as UTF8 instead of WIN1251.
This will only work if your database really contains data in WIN1251 and those columns have WIN1251 as their explicit character set, if those columns have character set NONE (or NULL
), then this will only work if the data is actually in UTF8.
The problem is either that your data didn't match your expectation (ie it wasn't WIN1251), or the combination of Powershell and the Firebird ODBC driver doesn't handle strings in a different character set than the console character set properly (if I'm not mistaken, the Powershell character set is utf-8).
Upvotes: 3