using sql2o (https://github.com/aaberg/sql2o)
when selecting a VARCHAR column that has trailing spaces (for example "some value ") the return value is "some value"
when selecting from mysql cli the result contains the trailing spaces
cant find any documentation how to prevent this from happening
- table:
CREATE TABLE names
(
name VARCHAR(100),
PRIMARY KEY (experiment_key, metric_name)
);
- code example:
Sql2o sql2o;
String name = "some name with trailing space ";
try (Connection con = sql2o.open()) {
con.createQuery("INSERT INTO names (name) VALUES(:name)")
.addParameter("name", name)
.executeUpdate();
}
String nameFromDB;
try (Connection con = sql2o.open()) {
nameFromDB = con.createQuery("select name from names")
.executeAndFetchFirst(String.class);
}
if (!nameFromDB.equals(name)){
throw new RuntimeException("where did the trailing spaces go ??? :( ");
}