2012-07-28 5 views
1

내가 잘못 생각한 것 같습니다. Im, ODBC를 사용하여 Powershell 2에서 Postgres DB를 쿼리하려고했는데, PGADMIN을 사용하여 쿼리하면 DB가이 문자열을 반환합니다. (포스트 그레스의 GUI) :Powershell V2에서 반환 된 값을 변수로 반환 NULL

0/164DAAB0

은 처음 두 개의 추가 문자와 HEX 그게 전부. 16 진수를 추출해야합니다.

변수에 할당하고 변수를 인쇄하면 아무 것도없고 비어 있습니다. 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) 

Additiional 정보 :

명령 $의 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;} 

답변

0

는 그 환경이 없어하지만 난 어쨌든 노력하겠습니다. 당신이 실행할 때 그냥 명확히 : 0/164DAAB0, 값 당신은 '; 후 재해야한다 :

$MasterUserTableCurr.pg_last_xlog_receive_location 

을 당신은 돌아가 64DAAB0, 맞죠?

이 명령의 결과를 붙여 넣을 수 있습니까?

$MasterUserTableCurr | Get-Member 

그리고

$MasterUserTableCurr.pg_last_xlog_receive_location | Get-Member 
+0

정확 하 ,,, 내가) (쿼리 SELECT pg_last_xlog_receive_location를 실행하는 경우; 내 GUI를 사용하면 다음과 같은 결과를 얻을 수 있습니다 : 0/164DAAB0 ,, Powershell에서 동일한 작업을 수행하려고하는 Im이 변수 안에 값이 필요하므로 '나중에'처음 두 문자를 제거하고 16 진수를 가져옵니다. 질문에서 반환 된 값을 변수에 할당하는 데 문제가 있습니다. Im을 입력해야합니다. $ MasterStringValueCurr; 및 문자열을 가져옵니다 : 0/164DAAB0하지만 아무것도 (빈, 빈), 그리고 아무런 오류. – Dotty

+0

원래 게시물에 요청한 추가 정보를 추가했습니다. 마지막 명령이 반환되었습니다. Get-Member : get-member cmdlet에 지정된 개체가 없습니다. – Dotty

+0

이 값을 얻을 수 있습니까? $ MasterDBResultCurr = $ MasterDBCmdCurr.ExecuteReader(); while ($ MasterDBResultCurr.Read()) {$ MasterDBResultCurr [ "pg_last_xlog_receive_location"]} –