@@ -32,6 +32,12 @@ public ResultSetMetaDataImpl(List<ClickHouseColumn> columns, String schema, Stri
3232 this .typeClassMap = typeClassMap ;
3333 }
3434
35+ private void checkColumnIndex (int column ) throws SQLException {
36+ if (column < 1 || column > columns .size ()) {
37+ throw new SQLException ("Column index out of range: " + column , ExceptionUtils .SQL_STATE_CLIENT_ERROR );
38+ }
39+ }
40+
3541 private ClickHouseColumn getColumn (int column ) throws SQLException {
3642 try {
3743 return columns .get (column - 1 );
@@ -47,68 +53,52 @@ public int getColumnCount() throws SQLException {
4753
4854 @ Override
4955 public boolean isAutoIncrement (int column ) throws SQLException {
56+ checkColumnIndex (column );
5057 return false ; // no auto-incremental types
5158 }
5259
5360 @ Override
5461 public boolean isCaseSensitive (int column ) throws SQLException {
55- try {
56- // TODO: should be in sync with DatabaseMetadata
57- return getColumn (column ).getDataType ().isCaseSensitive ();
58- } catch (Exception e ) {
59- throw ExceptionUtils .toSqlState (e );
60- }
62+ // TODO: should be in sync with DatabaseMetadata
63+ return getColumn (column ).getDataType ().isCaseSensitive ();
6164 }
6265
6366 @ Override
6467 public boolean isSearchable (int column ) throws SQLException {
68+ checkColumnIndex (column );
6569 return true ; // all columns are considered as searchable
6670 }
6771
6872 @ Override
6973 public boolean isCurrency (int column ) throws SQLException {
74+ checkColumnIndex (column );
7075 return false ;
7176 }
7277
7378 @ Override
7479 public int isNullable (int column ) throws SQLException {
75- try {
76- return getColumn (column ).isNullable () ? columnNullable : columnNoNulls ;
77- } catch (Exception e ) {
78- throw ExceptionUtils .toSqlState (e );
79- }
80+ return getColumn (column ).isNullable () ? columnNullable : columnNoNulls ;
8081 }
8182
8283 @ Override
8384 public boolean isSigned (int column ) throws SQLException {
84- try {
85- return getColumn (column ).getDataType ().isSigned ();
86- } catch (Exception e ) {
87- throw ExceptionUtils .toSqlState (e );
88- }
85+ return getColumn (column ).getDataType ().isSigned ();
8986 }
9087
9188 @ Override
9289 public int getColumnDisplaySize (int column ) throws SQLException {
90+ checkColumnIndex (column );
9391 return 80 ;
9492 }
9593
9694 @ Override
9795 public String getColumnLabel (int column ) throws SQLException {
98- try {
99- return getColumn (column ).getColumnName ();
100- } catch (Exception e ) {
101- throw ExceptionUtils .toSqlState (e );
102- }
96+ return getColumn (column ).getColumnName ();
10397 }
10498
10599 @ Override
106100 public String getColumnName (int column ) throws SQLException {
107- try {
108- return getColumn (column ).getColumnName ();
109- } catch (Exception e ) {
110- throw ExceptionUtils .toSqlState (e );
111- }
101+ return getColumn (column ).getColumnName ();
112102 }
113103
114104 @ Override
@@ -118,62 +108,51 @@ public String getSchemaName(int column) throws SQLException {
118108
119109 @ Override
120110 public int getPrecision (int column ) throws SQLException {
121- try {
122- return getColumn (column ).getPrecision ();
123- } catch (Exception e ) {
124- throw ExceptionUtils .toSqlState (e );
125- }
111+ return getColumn (column ).getPrecision ();
126112 }
127113
128114 @ Override
129115 public int getScale (int column ) throws SQLException {
130- try {
131- return getColumn (column ).getScale ();
132- } catch (Exception e ) {
133- throw ExceptionUtils .toSqlState (e );
134- }
116+ return getColumn (column ).getScale ();
135117 }
136118
137119 @ Override
138120 public String getTableName (int column ) throws SQLException {
121+ checkColumnIndex (column );
139122 return tableName ;
140123 }
141124
142125 @ Override
143126 public String getCatalogName (int column ) throws SQLException {
127+ checkColumnIndex (column );
144128 return catalog ;
145129 }
146130
147131 @ Override
148132 public int getColumnType (int column ) throws SQLException {
149- try {
150- return JdbcUtils .convertToSqlType (getColumn (column ).getDataType ()).getVendorTypeNumber ();
151- } catch (Exception e ) {
152- throw ExceptionUtils .toSqlState (e );
153- }
133+ return JdbcUtils .convertToSqlType (getColumn (column ).getDataType ()).getVendorTypeNumber ();
154134 }
155135
156136 @ Override
157137 public String getColumnTypeName (int column ) throws SQLException {
158- try {
159- return getColumn (column ).getOriginalTypeName ();
160- } catch (Exception e ) {
161- throw ExceptionUtils .toSqlState (e );
162- }
138+ return getColumn (column ).getOriginalTypeName ();
163139 }
164140
165141 @ Override
166142 public boolean isReadOnly (int column ) throws SQLException {
143+ checkColumnIndex (column );
167144 return true ;
168145 }
169146
170147 @ Override
171148 public boolean isWritable (int column ) throws SQLException {
149+ checkColumnIndex (column );
172150 return false ;
173151 }
174152
175153 @ Override
176154 public boolean isDefinitelyWritable (int column ) throws SQLException {
155+ checkColumnIndex (column );
177156 return false ;
178157 }
179158
0 commit comments