java/jdbc-loopback-driver/src/info/globalcode/jdbc/loopback/PreparedStatement.java
Tabular formatter: fix problem with CR (carriage return).
Less command or orher programs shows it as ^M (two characters) and it breaks the table layout – so we need to translate it to a single symbol.
3 * Copyright © 2014 František Kučera (frantovo.cz)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package info.globalcode.jdbc.loopback;
20 import java.sql.SQLException;
21 import java.sql.SQLWarning;
22 import java.sql.Types;
23 import java.util.ArrayList;
24 import java.util.HashMap;
25 import java.util.List;
30 * @author Ing. František Kučera (frantovo.cz)
32 public class PreparedStatement extends AbstractPreparedStatement {
34 private final Map<Integer, ObjectParameter> parameters = new HashMap<>();
35 private List<Object[]> table;
36 private final ResultSetMetaData metadata = new ResultSetMetaData();
39 public void setObject(int parameterNumber, Object data, int targetSqlType) throws SQLException {
40 parameters.put(parameterNumber, new ObjectParameter(data, targetSqlType));
44 public boolean execute() throws SQLException {
46 if (parameters.size() < 1) {
47 throw new SQLException("Missing first parameter (column count)");
49 int columnCount = Integer.valueOf(String.valueOf(parameters.get(1).getData()));
51 for (int i = 0; i < columnCount; i++) {
52 String label = parameters.get(1 + i + 1).getData().toString();
53 metadata.addColumn(new ResultSetMetaData.ColumnDescriptor(Types.VARCHAR, "VARCHAR", label, label));
58 table = new ArrayList<>();
59 Object[] currentRow = null;
61 for (int parameterNumber = (1 + columnCount + 1); true; parameterNumber++) {
62 ObjectParameter data = parameters.get(parameterNumber);
66 int columnIndex = cellIndex % columnCount;
68 if (columnIndex == 0) {
69 currentRow = new Object[columnCount];
70 table.add(currentRow);
72 currentRow[columnIndex] = data.getData();
81 public java.sql.ResultSet getResultSet() throws SQLException {
82 return new ResultSet(metadata, table);
86 public int getUpdateCount() throws SQLException {
91 public boolean getMoreResults() throws SQLException {
96 public void close() throws SQLException {
100 public SQLWarning getWarnings() throws SQLException {
105 public void clearWarnings() throws SQLException {