1 package org.paneris.jal.model;
2
3 import java.sql.Connection;
4 import java.sql.ResultSet;
5 import java.sql.ResultSetMetaData;
6 import java.sql.SQLException;
7 import java.sql.Statement;
8
9
10
11
12
13 public class SQLMetaData extends Object {
14
15 private DBConnectionManager connMgr = DBConnectionManager.getInstance();
16
17
18
19
20 boolean AutoIncrement;
21
22
23
24
25 boolean CaseSensitive;
26
27
28
29
30 boolean Searchable;
31
32
33
34
35 boolean Currency;
36
37
38
39
40 int Nullable;
41
42
43
44
45 boolean Signed;
46
47
48
49
50 int ColumnDisplaySize;
51
52
53
54
55
56 String ColumnLabel;
57
58
59
60
61 String ColumnName;
62
63
64
65
66 String SchemaName;
67
68
69
70
71 int Precision;
72
73
74
75
76 int Scale;
77
78
79
80
81
82 public int ColumnType;
83
84
85
86
87 public String ColumnTypeName;
88
89
90
91
92 boolean ReadOnly;
93
94
95
96
97 boolean Writable;
98
99
100
101
102 boolean DefinitelyWritable;
103
104
105
106
107 public SQLMetaData(String db, Integer fn) {
108 Connection conn = connMgr.getConnection("SQLMetaData",db);
109 String sqlString = "";
110 try {
111 Statement s = conn.createStatement();
112 sqlString = "SELECT datadictionary.fieldname, datadictionarytables.tablename FROM datadictionary, datadictionarytables WHERE datadictionary.tablename = datadictionarytables.id and datadictionary.id = " + fn;
113 ResultSet rs = s.executeQuery(sqlString);
114 rs.next();
115 try {
116 String fieldname = rs.getString(1);
117 String tablename = rs.getString(2);
118 try {
119 sqlString = "SELECT " + fieldname + " FROM " + tablename + " WHERE id=0";
120 rs = s.executeQuery(sqlString);
121 ResultSetMetaData md = rs.getMetaData();
122 try {
123 AutoIncrement = md.isAutoIncrement(1);
124 CaseSensitive = md.isCaseSensitive(1);
125 Searchable = md.isSearchable(1);
126 Currency = md.isCurrency(1);
127 Nullable = md.isNullable(1);
128 Signed = md.isSigned(1);
129 ColumnDisplaySize = md.getColumnDisplaySize(1);
130 ColumnLabel = md.getColumnLabel(1);
131 ColumnName = md.getColumnName(1);
132 SchemaName = md.getSchemaName(1);
133 try {
134 Precision = md.getPrecision(1);
135 } catch (SQLException e) {
136 Precision = 0;
137 }
138 try {
139 Scale = md.getScale(1);
140 } catch (SQLException e) {
141 Scale = 0;
142 }
143 ColumnType = md.getColumnType(1);
144 ColumnTypeName = md.getColumnTypeName(1);
145 ReadOnly = md.isReadOnly(1);
146 Writable = md.isWritable(1);
147 DefinitelyWritable = md.isDefinitelyWritable(1);
148 } catch (Exception e) {
149 System.err.println(e.toString());
150 }
151 } catch (Exception e) {
152 System.err.println("failed get resultsetmetadata, sqlString: " + sqlString + " Error: " + e.toString());
153 }
154 } catch (Exception e) {
155 System.err.println("failed get fieldname / tablename, sqlString: " + sqlString + " Error: " + e.toString());
156 }
157 } catch (Exception e) {
158 System.err.println("failed to create results set, sqlString: " + sqlString + " Error: " + e.toString());
159 }
160 connMgr.freeConnection(db, conn);
161 }
162 }
163