X-Git-Url: http://jaekl.net/gitweb/?p=squelch.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fjaekl%2Fsquelch%2Fstmt%2FTabularColumnInfo.java;fp=src%2Fmain%2Fjava%2Fnet%2Fjaekl%2Fsquelch%2Fstmt%2FTabularColumnInfo.java;h=ff9fc62f0dba399e55dc0885e3e87643ee22a9ca;hp=0000000000000000000000000000000000000000;hb=5c97ab69edb44c0f1a7dc416ffaf1b934f7a3d7d;hpb=dde7f6828b7e2fc479d2285754e4a150be7958a5 diff --git a/src/main/java/net/jaekl/squelch/stmt/TabularColumnInfo.java b/src/main/java/net/jaekl/squelch/stmt/TabularColumnInfo.java new file mode 100644 index 0000000..ff9fc62 --- /dev/null +++ b/src/main/java/net/jaekl/squelch/stmt/TabularColumnInfo.java @@ -0,0 +1,78 @@ +package net.jaekl.squelch.stmt; + +import java.sql.ResultSet; +import java.sql.SQLException; + +import net.jaekl.squelch.sql.Column; +import net.jaekl.squelch.sql.Row; + +public class TabularColumnInfo extends Tabular { + private static final Column[] COLUMNS = { + new Column("Column", String.class, 32), + new Column("Type", String.class, 16), + new Column("Modifiers", String.class, 16) + }; + private ResultSet m_rs; + + public TabularColumnInfo(ResultSet rs) { + m_rs = rs; + } + + @Override + Column[] getCols() throws SQLException { + return COLUMNS; + } + + @Override + Row getNext() throws SQLException { + if (!m_rs.next()) { + return null; + } + + Row row = new Row(COLUMNS.length); + + String columnName = m_rs.getString(4); + + String typeName = m_rs.getString(6); + int columnSize = m_rs.getInt(7); + if (columnSize > 0) { + int decimalDigits = m_rs.getInt(8); // digits after the decimal point + if (decimalDigits > 0) { + typeName += "(" + columnSize + "." + decimalDigits + ")"; + } + else { + typeName += "(" + columnSize + ")"; + } + } + + String remarks = m_rs.getString(12); + String isNullable = m_rs.getString(18); + String isAutoIncrement = m_rs.getString(23); + String notes = ""; + if ("YES".equals(isNullable)) { + notes += "NULL"; + } + else if ("NO".equals(isNullable)) { + notes += "NOT NULL"; + } + if ("YES".equals(isAutoIncrement)) { + if (notes.length() > 0) { + notes += " "; + } + notes += "AUTOINCREMENT"; + } + if ((null != remarks) && (remarks.length() > 0)) { + if (notes.length() > 0) { + notes += " "; + } + notes += "(" + remarks + ")"; + } + + row.setValue(1, columnName); + row.setValue(2, typeName); + row.setValue(3, notes); + + return row; + } + +}