FileDocCategorySizeDatePackage
CharIndexFunction.javaAPI DocHibernate 3.2.51266Wed Oct 26 17:12:28 BST 2005org.hibernate.dialect.function

CharIndexFunction

public class CharIndexFunction extends Object implements SQLFunction
Emulation of locate() on Sybase
author
Nathan Moon

Fields Summary
Constructors Summary
Methods Summary
public org.hibernate.type.TypegetReturnType(org.hibernate.type.Type columnType, org.hibernate.engine.Mapping mapping)

		return Hibernate.INTEGER;
	
public booleanhasArguments()

		return true;
	
public booleanhasParenthesesIfNoArguments()

		return true;
	
public java.lang.Stringrender(java.util.List args, org.hibernate.engine.SessionFactoryImplementor factory)

		boolean threeArgs = args.size() > 2;
		Object pattern = args.get(0);
		Object string = args.get(1);
		Object start = threeArgs ? args.get(2) : null;

		StringBuffer buf = new StringBuffer();
		buf.append("charindex(").append( pattern ).append(", ");
		if (threeArgs) buf.append( "right(");
		buf.append( string );
		if (threeArgs) buf.append( ", char_length(" ).append( string ).append(")-(").append( start ).append("-1))");
		buf.append(')");
		return buf.toString();