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
def t_start= System.currentTimeMillis()
// PostgreSQL// A_Ctx A_PO A_Type A_Event
def postgres= Sql.newInstance('jdbc:postgresql://127.0.0.1/taya1201','adempiere','adempiere','org.postgresql.Driver' )
def metadata = postgres.connection.metaData
String[] tableTypes = ["TABLE"]
ResultSet rs = metadata.getTables(null, "adempiere", "%", tableTypes );
// 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, 'adempiere', tblName, null);
// ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) throws SQLException
while(tblMetadata.next()){
String REMARKS = tblMetadata.getString("REMARKS");
String TABLE_CAT= tblMetadata.getString("TABLE_CAT");
String TABLE_SCHEM= tblMetadata.getString("TABLE_SCHEM");
String TABLE_NAME= tblMetadata.getString("TABLE_NAME");
String COLUMN_NAME= tblMetadata.getString("COLUMN_NAME");
int DATA_TYPE= tblMetadata.getInt("DATA_TYPE");
String TYPE_NAME= tblMetadata.getString("TYPE_NAME");
String COLUMN_SIZE= tblMetadata.getString("COLUMN_SIZE");
String DECIMAL_DIGITS= tblMetadata.getString("DECIMAL_DIGITS");
String NUM_PREC_RADIX= tblMetadata.getString("NUM_PREC_RADIX");
String NULLABLE= tblMetadata.getString("NULLABLE");
def v1 = 0
// sql.rows("select * from PROJECT where name like 'Gra%' ")
if (DATA_TYPE==java.sql.Types.VARCHAR || DATA_TYPE==java.sql.Types.LONGVARCHAR ||
DATA_TYPE==java.sql.Types.NVARCHAR || DATA_TYPE==java.sql.Types.NCHAR )
{
def sqlcount = "SELECT COUNT(*) as v1 FROM "+TABLE_SCHEM+"."+TABLE_NAME+" WHERE "+COLUMN_NAME+" LIKE '%公司' "
postgres.query(sqlcount )
{ ResultSet rscount ->
while(rscount .next())
v1 = rscount .getInt('v1')
}
if (v1 > 0) println sqlcount + " = " + v1 + " " + "\t"
}
} // while(tblMetadata.next())
} // while(rs.next())
def t_end = System.currentTimeMillis()
result="執行完成: " + (t_end - t_start)
沒有留言:
張貼留言