ExpressionFunctionLeft.java :  » Database-DBMS » smallsql » smallsql » database » Java Open Source

Java Open Source » Database DBMS » smallsql 
smallsql » smallsql » database » ExpressionFunctionLeft.java
/* =============================================================
 * SmallSQL : a free Java DBMS library for the Java(tm) platform
 * =============================================================
 *
 * (C) Copyright 2004-2006, by Volker Berlin.
 *
 * Project Info:  http://www.smallsql.de/
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 * USA.  
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 *
 * ---------------
 * ExpressionFunctionLeft.java
 * ---------------
 * Author: Volker Berlin
 * 
 * Created on 17.06.2006
 */
package smallsql.database;


/**
 * @author Volker Berlin
 */
public class ExpressionFunctionLeft extends ExpressionFunctionReturnP1StringAndBinary {

  final int getFunction() {
    return SQLTokenizer.LEFT;
  }


  final boolean isNull() throws Exception {
    return param1.isNull() || param2.isNull();
  }


  final byte[] getBytes() throws Exception{
    if(isNull()) return null;
    byte[] bytes = param1.getBytes();
    int length = param2.getInt();
    if(bytes.length <= length) return bytes;

    byte[] b = new byte[length];
    System.arraycopy(bytes, 0, b, 0, length);
    return b;    
  }
  
  
  final String getString() throws Exception {
    if(isNull()) return null;
    String str = param1.getString();
    int length = param2.getInt();
    length = Math.min( length, str.length() );
    return str.substring(0,length);
  }


}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.