PGADMIN (Postgres GUI) を使用してクエリを実行すると、DB は次のような文字列を返します。
0/164DAAB0
これは、先頭に 2 つの文字が追加された HEX です。HEXを抽出する必要があります。
それを変数に代入して変数を出力すると、何も得られず、空になります。Powershell V3 を搭載したコンピューターで試してみましたが、問題なく動作しますが、PS2 で動作させる必要があります。誰かが私の問題を見つけてくれることを願っています。これを行うには別の/より良い方法があると思いますので、私の変数はクエリによって返される文字列を取得します。
コードは次のとおりです。
$MasterDBIP = "172.16.50.20";
$MasterDBPort = "5432";
$MasterDB = "database1";
$MasterUid = "postgres";
$MasterPassword = "postgres";
$MasterMasterDBConnectionString = "Driver={PostgreSQL Unicode(x64)};Server=$MasterDBIP;Port=$MasterDBPort;Database=$MasterDB;Uid=$MasterUid;Pwd=$MasterPassword;"
$MasterDBConn = New-Object System.Data.Odbc.OdbcConnection
$MasterDBConn.ConnectionString = $MasterMasterDBConnectionString;
$MasterDBConn.Open();
$MasterDBCmdCurr = $MasterDBConn.CreateCommand();
$MasterDBCmdCurr.CommandText = "SELECT pg_last_xlog_receive_location();";
$MasterDBResultCurr = $MasterDBCmdCurr.ExecuteReader();
$MasterUserTableCurr=New-Object system.data.datatable
$MasterUserTableCurr.load($MasterDBResultCurr)
[string]$MasterStringValueCurr = $MasterUserTableCurr.pg_last_xlog_receive_location;
$MasterDBConn.Close();
$MasterStringValueCurr;
exit (0)
追加情報:
コマンド $MasterUserTableCurr | Get-Member の戻り値:
TypeName: System.Data.DataRow
Name MemberType Definition
---- ---------- ----------
AcceptChanges Method System.Void AcceptChanges()
BeginEdit Method System.Void BeginEdit()
CancelEdit Method System.Void CancelEdit()
ClearErrors Method System.Void ClearErrors()
Delete Method System.Void Delete()
EndEdit Method System.Void EndEdit()
Equals Method bool Equals(System.Object obj)
GetChildRows Method System.Data.DataRow[] GetChildRows(string relationName), System.Data.DataRow[] GetChildRows(string relat...
GetColumnError Method string GetColumnError(int columnIndex), string GetColumnError(string columnName), string GetColumnError(...
GetColumnsInError Method System.Data.DataColumn[] GetColumnsInError()
GetHashCode Method int GetHashCode()
GetParentRow Method System.Data.DataRow GetParentRow(string relationName), System.Data.DataRow GetParentRow(string relationN...
GetParentRows Method System.Data.DataRow[] GetParentRows(string relationName), System.Data.DataRow[] GetParentRows(string rel...
GetType Method type GetType()
HasVersion Method bool HasVersion(System.Data.DataRowVersion version)
IsNull Method bool IsNull(int columnIndex), bool IsNull(string columnName), bool IsNull(System.Data.DataColumn column)...
RejectChanges Method System.Void RejectChanges()
SetAdded Method System.Void SetAdded()
SetColumnError Method System.Void SetColumnError(int columnIndex, string error), System.Void SetColumnError(string columnName,...
SetModified Method System.Void SetModified()
SetParentRow Method System.Void SetParentRow(System.Data.DataRow parentRow), System.Void SetParentRow(System.Data.DataRow pa...
ToString Method string ToString()
Item ParameterizedProperty System.Object Item(int columnIndex) {get;set;}, System.Object Item(string columnName) {get;set;}, System...
pg_last_xlog_receive_location Property System.String pg_last_xlog_receive_location {get;}