comparison src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java @ 889:485c75b35cc9

An array_size of 0 (so new String[0]) is allowed in java.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 04 Apr 2024 18:47:22 +0200 (13 months ago)
parents 1956d8ba5ad3
children 7621c80b08da
comparison
equal deleted inserted replaced
888:549225b7be85 889:485c75b35cc9
164 size = (int)((MonetConnection.ResultSetResponse)header).tuplecount; 164 size = (int)((MonetConnection.ResultSetResponse)header).tuplecount;
165 165
166 int countParam = 0; 166 int countParam = 0;
167 int firstParamOffset = 0; 167 int firstParamOffset = 0;
168 168
169 // initialise blank finals 169 // initialise metadata arrays. size can be 0.
170 monetdbType = new String[size]; 170 monetdbType = new String[size];
171 javaType = new int[size]; 171 javaType = new int[size];
172 digits = new int[size]; 172 digits = new int[size];
173 scale = new int[size]; 173 scale = new int[size];
174 schema = new String[size]; 174 schema = new String[size];
183 final int digits_colnr = rs.findColumn("digits"); 183 final int digits_colnr = rs.findColumn("digits");
184 final int scale_colnr = rs.findColumn("scale"); 184 final int scale_colnr = rs.findColumn("scale");
185 final int schema_colnr = rs.findColumn("schema"); 185 final int schema_colnr = rs.findColumn("schema");
186 final int table_colnr = rs.findColumn("table"); 186 final int table_colnr = rs.findColumn("table");
187 final int column_colnr = rs.findColumn("column"); 187 final int column_colnr = rs.findColumn("column");
188 for (int i = 0; rs.next(); i++) { 188 for (int i = 0; rs.next() && i < size; i++) {
189 monetdbType[i] = rs.getString(type_colnr); 189 monetdbType[i] = rs.getString(type_colnr);
190 javaType[i] = MonetDriver.getJdbcSQLType(monetdbType[i]); 190 javaType[i] = MonetDriver.getJdbcSQLType(monetdbType[i]);
191 if (javaType[i] == Types.CLOB) { 191 if (javaType[i] == Types.CLOB) {
192 if (connection.mapClobAsVarChar()) 192 if (connection.mapClobAsVarChar())
193 javaType[i] = Types.VARCHAR; 193 javaType[i] = Types.VARCHAR;
355 @Override 355 @Override
356 public ResultSetMetaData getMetaData() throws SQLException { 356 public ResultSetMetaData getMetaData() throws SQLException {
357 if (rsmd == null) { 357 if (rsmd == null) {
358 // first use, construct the arrays with metadata and a 358 // first use, construct the arrays with metadata and a
359 // ResultSetMetaData object once and reuse it for all next calls 359 // ResultSetMetaData object once and reuse it for all next calls
360 final int rescolcount = size - paramCount; 360 final int rescolcount = size - paramCount; // this can be 0
361 int array_size = rescolcount;
362 if (array_size == 0) {
363 // there are no resultset columns for this prepared statement
364 // we can not create arrays of size 0, so use:
365 array_size = 1;
366 }
367 // create arrays for storing only the result columns meta data 361 // create arrays for storing only the result columns meta data
368 final String[] schemas = new String[array_size]; 362 final String[] schemas = new String[rescolcount];
369 final String[] tables = new String[array_size]; 363 final String[] tables = new String[rescolcount];
370 final String[] columns = new String[array_size]; 364 final String[] columns = new String[rescolcount];
371 final String[] types = new String[array_size]; 365 final String[] types = new String[rescolcount];
372 final int[] jdbcTypes = new int[array_size]; 366 final int[] jdbcTypes = new int[rescolcount];
373 final int[] lengths = new int[array_size]; 367 final int[] lengths = new int[rescolcount];
374 final int[] precisions = new int[array_size]; 368 final int[] precisions = new int[rescolcount];
375 final int[] scales = new int[array_size]; 369 final int[] scales = new int[rescolcount];
376 // fill the arrays with the resultset columns metadata 370 // fill the arrays with the resultset columns metadata
377 for (int i = 0; i < rescolcount; i++) { 371 for (int i = 0; i < rescolcount; i++) {
378 schemas[i] = schema[i]; 372 schemas[i] = schema[i];
379 tables[i] = table[i]; 373 tables[i] = table[i];
380 columns[i] = column[i]; 374 columns[i] = column[i];