1 5 package org.h2.value; 6 7 import java.sql.PreparedStatement ; 8 import java.sql.SQLException ; 9 10 import org.h2.util.MathUtils; 11 import org.h2.util.StringUtils; 12 13 abstract class ValueStringBase extends Value { 14 protected String value; 15 16 protected ValueStringBase(String value) { 17 this.value = value; 18 } 19 20 public String getSQL() { 21 return StringUtils.quoteStringSQL(value); 22 } 23 24 public String getString() { 25 return value; 26 } 27 28 public long getPrecision() { 29 return value.length(); 30 } 31 32 public Object getObject() { 33 return value; 34 } 35 36 public void set(PreparedStatement prep, int parameterIndex) throws SQLException { 37 prep.setString(parameterIndex, value); 38 } 39 40 public Value convertPrecision(long precision) { 41 if (precision == 0 || value.length() <= precision) { 42 return this; 43 } 44 int p = MathUtils.convertLongToInt(precision); 45 return ValueString.get(value.substring(0, p)); 46 } 47 48 52 public int getDisplaySize() { 53 return value.length(); 54 } 55 56 protected boolean isEqual(Value v) { 57 return v instanceof ValueString && value.equals(((ValueString)v).value); 58 } 59 60 } 61 | Popular Tags |