2015-04-28 21 views
0

%Dictionary.ClassDefinitionQuery有一個程序列出了班級摘要;在Java中,我這樣稱呼它:如何在SQL中複製%Dictionary.ClassDefintionQuery的Summary()?

public void readClasses(final Path dir) 
    throws SQLException 
{ 
    final String call 
     = "{ call %Dictionary.ClassDefinitionQuery_Summary() }"; 

    try (
     final CallableStatement statement = connection.prepareCall(call); 
     final ResultSet rs = statement.executeQuery(); 
    ) { 
     String className; 
     int count = 0; 

     while (rs.next()) { 
      // Skip if System is not 0 
      if (rs.getInt(5) != 0) 
       continue; 

      className = rs.getString(1); 

      // Also skip if the name starts with a % 
      if (className.charAt(0) == '%') 
       continue; 

      //System.out.println(className); 
      count++; 
     } 

     System.out.println("read: " + count); 
    } 
} 

在名稱空間SAMPLES中返回491行。

我嘗試用純SQL查詢這樣的複製它:

private void listClasses(final Path dir) 
    throws SQLException 
{ 
    final String query = "select id, super" 
     + " from %Dictionary.ClassDefinition" 
     + " where System = '0' and name not like '\\%%' escape '\\'"; 

    try (
     final PreparedStatement statement 
      = connection.prepareStatement(query); 
     final ResultSet rs = statement.executeQuery(); 
    ) { 
     int count = 0; 

     while (rs.next()) { 
      //System.out.println(rs.getString(1) + ';' + rs.getString(2)); 
      count++; 
     } 

     System.out.println("list: " + count); 
    } 
} 

然而,在運行程序我得到這個時候:

list: 555 
read: 491 

爲何結果不同?

我看過的%Dictionary.ClassDefinitionQuery的代碼,但我不明白爲什麼會給出不同的結果......我只知道,如果我存儲在集的名稱和比較,是:

  • 什麼從讀取的列表中丟失;
  • 大多數(但不是全部)由列表返回的不在讀取的類是CSP頁面。

但就是這樣。

我該如何複製SQL中的彙總過程的行爲?

回答

2

不同的是在一個屬性。 %Dictionary.ClassDefinitionQuery_Summary只顯示部署了<> 2的類。所以,sql必須是這樣的。

select id,super from %Dictionary.ClassDefinition where deployed <> 2 

但有更多的事情是,爲什麼數量可能會有所不同,這樣的SQL請求可compilled臨時類,如「%sqlcq.SAMPLES.cls22」

+0

嗯,這是一個什麼「部署」專欄告訴我們?另外,我不選擇以'%'開頭的類,所以我不會得到任何%sqlcq。我真的是一個新手,儘管有一個完整的安裝,因此所有的文件在手:(: – fge

+0

Aaand ... Spot on。就是這樣!你將成爲我的Intersystems英雄:p – fge

+0

在緩存類,可能沒有任何源代碼,所以,這個標誌會顯示它,因爲它在文檔中告訴它「指示該類是否已部署,即與用於構建它的源分離。」 – DAiMor