1

我认为我做错了,我试图使用 ODBC 从 Powershell 2 查询 Postgres DB,如果我使用 PGADMIN(Postgres GUI)查询,DB 会返回这样的字符串:

0/164DAAB0

那是一个十六进制,开头有两个额外的字符。我需要提取十六进制。

当我这样做并将其分配给一个变量并打印该变量时,我什么也没有得到,是空的。我在一台装有 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 | 获取会员回报:

   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;}
4

1 回答 1

0

我没有那种环境,所以很难回答,但无论如何我都会尝试。只是为了澄清,当你执行时:

$MasterUserTableCurr.pg_last_xlog_receive_location 

你返回:0/164DAAB0,你所追求的值应该是:64DAAB0,对吧?

你能粘贴这些命令的结果吗?

$MasterUserTableCurr | Get-Member

$MasterUserTableCurr.pg_last_xlog_receive_location | Get-Member
于 2012-07-28T12:04:07.433 回答