Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Firebird Open Source J2ee connector - jdbc driver
   * Distributable under LGPL license.
   * You may obtain a copy of the License at
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * LGPL License for more details.
  * This file was created by members of the firebird development team.
  * All individual contributions remain the Copyright (C) of those
  * individuals.  Contributors to this file are either listed here or
  * can be obtained from a CVS history command.
  * All rights reserved.
 package org.firebirdsql.jdbc.field;
 import java.sql.Types;
Class implementing workaround for "operation was cancelled" bug in server. When we send some string data exceeding maximum length of the corresponding field causes "operation was cancelled" in remote module of the server instead of "arithmetic exception..." error. This makes code debugging harder, since error message is not very informative.

However we cannot simply check length locally. Maximum allowed length in bytes is connected with the character set of the field as defined lengh * maximum number of bytes per character in that encoding. However this does not work for system tables which have defined length 31, character set UNICODE_FSS and maximum allowed length of 31 (instead of 31 * 3 = 63).

Until this bug is fixed in the engine we will simply check if field belongs to the system table and do not throw data truncation error locally.

Roman Rokytskyy
 public class FBWorkaroundStringField extends FBStringField {
     private boolean trimString;
Create instance of this class for the specified field and result set.

field instance of org.firebirdsql.gds.XSQLVAR containing field value.
dataProvider data provider for this field
requiredType required type.
java.sql.SQLException if something went wrong.
     public FBWorkaroundStringField(XSQLVAR fieldFieldDataProvider dataProvider,
             int requiredTypethrows SQLException 
     public void setTrimString(boolean trimString) {
         this. = trimString;
     public void setString(String valuethrows SQLException {
         byte[] data = setStringForced(value);
         if (value == )
         if (data.length > . && !isSystemTable(.)) {
             // special handling for the LIKE ? queries with CHAR(1) fields
             if (!(value.length() <= . + 2 && (value.charAt(0) == '%' || value.charAt(value.length() - 1) == '%'))) 
                 throw new DataTruncation(-1, truefalsedata.length.);
Set string value without any check of its length. This is a workaround for the problem described above.

value value to set.
java.sql.SQLException if something went wrong.
     public byte[] setStringForced(String valuethrows SQLException {
         if (value == ) {
             return null;
         byte[] data = .encodeString(value,);
         return data;
Get string value of this field.

string value of this filed or null if the value is NULL.
    public String getString() throws SQLException {
        String result = super.getString();
        if (result == )
            return ;
        if (isType(.))
            return result;
        // fix incorrect padding done by the database for multibyte charsets
        if ((. % ) == 0 && result.length() > )
            result = result.substring(0, );
        if ()
            result = result.trim();
        return result;
List of system tables from Firebird 1.5
    private static final String[] SYSTEM_TABLES = new String[] {
Check if specified table is system table. This method simply traverses hardcoded list of system tables and compares table names.

tableName name of the table to check.
true if specified table is system, otherwise false
    private boolean isSystemTable(String tableName) {
        boolean result = false;
        for (int i = 0; i < .i++) {
            if ([i].equals(tableName)) {
                result = true;
        return result;
New to GrepCode? Check out our FAQ X