sql += sql.substring(0, index)
sql = sql.substring(0, index)
    public static EOSQLExpression sqlExpressionForFetchSpecification(EOEditingContext ec, EOFetchSpecification spec, long start, long end) {        EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, spec.entityName());        EOModel model = entity.model();        EODatabaseContext dbc = EOUtilities.databaseContextForModelNamed(ec, model.name());        EOAdaptor adaptor = dbc.adaptorContext().adaptor();        EOSQLExpressionFactory sqlFactory = adaptor.expressionFactory();                NSArray attributes = spec.rawRowKeyPaths();        if (attributes == null || attributes.count() == 0) {            attributes = entity.attributesToFetch();        }                EOQualifier qualifier = spec.qualifier();        if(qualifier != null) {            qualifier = EOQualifierSQLGeneration.Support._schemaBasedQualifierWithRootEntity(qualifier, entity);        }        if(qualifier != spec.qualifier()) {            spec = (EOFetchSpecification)spec.clone();            spec.setQualifier(qualifier);        }        if(spec.fetchLimit() > 0) {            spec = (EOFetchSpecification)spec.clone();            spec.setFetchLimit(0);            spec.setPromptsAfterFetchLimit(false);        }        EOSQLExpression sqlExpr = sqlFactory.selectStatementForAttributes(attributes, false, spec, entity);        String sql = sqlExpr.statement();        if (end >= 0) {            String url = (String) model.connectionDictionary().objectForKey("URL");            if (url != null) {                String lowerCaseURL= url.toLowerCase();                if (lowerCaseURL.indexOf("frontbase") != -1) {                    //add TOP(start, (end - start)) after the SELECT word                    int index = sql.indexOf("select");                    if (index == -1) {                        index = sql.indexOf("SELECT");                    }                    index += 6;                    sql += sql.substring(0, index)                         + " TOP(" + start + ", " + (end-start) + ")"                         + sql.substring(index + 1, sql.length());                } else if (lowerCaseURL.indexOf("openbase") != -1) {                    // Openbase support for limiting result set                    sql += " return results " + start + " to " + end;                } else if (lowerCaseURL.indexOf("mysql") != -1 ) {                    sql += " LIMIT " + start + ", " + (end - start);                } else if (lowerCaseURL.indexOf("postgresql") != -1 ) {                    sql += " LIMIT " + (end - start) + " OFFSET " + start;                }            }            sqlExpr.setStatement(sql);        }        return sqlExpr;    }