2014年6月28日 星期六

iDempiere Read HIS Informix


import groovy.sql.Sql
import java.sql.Timestamp
import java.sql.PreparedStatement
import java.sql.ResultSet
import java.sql.Types
import org.compiere.util.Env
import org.compiere.util.DB
int client=Env.getContextAsInt(A_Ctx, "AD_Client_ID");
int org=Env.getContextAsInt(A_Ctx, "AD_Org_ID");
int uid=Env.getContextAsInt(A_Ctx, "#AD_User_ID");
def t_start= System.currentTimeMillis()
String ss= DB.getSQLValueString(null,"select value from h_search where h_search_id = ?", A_Record_ID );
// DB.executeUpdateEx( "delete from h_searchline where h_search_id="+A_Record_ID+ " " , A_TrxName);
postSql = Sql.newInstance('jdbc:postgresql://127.0.0.1/taya1201','adempiere','adempiere','org.postgresql.Driver' )
ptable= postSql.dataSet("h_searchline")   //上傳
inforSql = Sql.newInstance( 'jdbc:informix-sqli://192.168.170.211:1534/hisipddb:informixserver=hisipdsrv;CLIENT_LOCALE=zh_tw.big5;','informix','db@w94u6', 'com.informix.jdbc.IfxDriver' );
metadata = inforSql.connection.metaData
String[] tableTypes = ["TABLE"]
ResultSet rs = metadata.getTables(null, null, null, tableTypes );  //"userlist"
// getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)
// "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
String tblName = null;


while(rs.next()){
   tblName = rs.getString('TABLE_NAME');
   println ">>>>>> "+tblName
   ResultSet tblMetadata = metadata.getColumns(null, '%', tblName, null);
// ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern)  throws SQLException
   while(tblMetadata.next()){
      String TABLE_SCHEM = tblMetadata.getString("TABLE_SCHEM");
      String TABLE_NAME    = tblMetadata.getString("TABLE_NAME");
      String COLUMN_NAME= tblMetadata.getString("COLUMN_NAME");
      String TYPE_NAME      = tblMetadata.getString("TYPE_NAME");
      String COLUMN_SIZE  = ""+tblMetadata.getInt("COLUMN_SIZE");
      String DECIMAL_DIGITS= ""+tblMetadata.getInt("DECIMAL_DIGITS");
      String NULLABLE          = tblMetadata.getString("NULLABLE");
      String s1 = TABLE_SCHEM +"."+TABLE_NAME+"."+COLUMN_NAME+ "  " + TYPE_NAME;
      if (TYPE_NAME.equals("datetime")  || TYPE_NAME.equals("date")   || TYPE_NAME.equals("text")   || TYPE_NAME.equals("byte")   || TYPE_NAME.equals("int") ) s1 = s1+",";
      else if (TYPE_NAME.equals("char") || TYPE_NAME.equals("varchar")  || TYPE_NAME.equals("smallint")) s1 = s1 +"("+ COLUMN_SIZE+"),";
      else if (TYPE_NAME.equals("decimal") || TYPE_NAME.equals("float"))   s1 = s1 + "("+ COLUMN_SIZE+","+ DECIMAL_DIGITS   +"),";
     
      else println  s1 + "("+ COLUMN_SIZE+","+ DECIMAL_DIGITS   +"),------------------";
   //   println s1
// TABLE_SCHEM +"."+TABLE_NAME+"."+COLUMN_NAME+ "  " + TYPE_NAME + "("+ COLUMN_SIZE+","+ DECIMAL_DIGITS   +")   "
    // +NULLABLE;
   } // while(tblMetadata.next())
} // while(rs.next())

/*
ResultSet rs1 = metadata.getTypeInfo();
while (rs1.next()) {
      String typeName = rs1.getString("TYPE_NAME");
      short dataType = rs1.getShort("DATA_TYPE");
      println "TYPE_NAME:: "+typeName +" ,DATA_TYPE="+dataType;
}*/
return ""

沒有留言:

張貼留言