Search in sources :

Example 6 with SQLItem

use of lucee.runtime.db.SQLItem in project Lucee by lucee.

the class QueryParamConverter method convert.

public static SQL convert(String sql, Array params) throws PageException {
    Iterator<Object> it = params.valueIterator();
    List<SQLItems<NamedSQLItem>> namedItems = new ArrayList<SQLItems<NamedSQLItem>>();
    List<SQLItems<SQLItem>> items = new ArrayList<SQLItems<SQLItem>>();
    Object value, paramValue;
    while (it.hasNext()) {
        value = it.next();
        if (Decision.isStruct(value)) {
            Struct sct = (Struct) value;
            // name (optional)
            String name = null;
            Object oName = sct.get(KeyConstants._name, null);
            if (oName != null)
                name = Caster.toString(oName);
            // value (required)
            paramValue = sct.get(KeyConstants._value);
            if (StringUtil.isEmpty(name)) {
                items.add(new SQLItems<SQLItem>(new SQLItemImpl(paramValue, Types.VARCHAR), sct));
            } else {
                namedItems.add(new SQLItems<NamedSQLItem>(new NamedSQLItem(name, paramValue, Types.VARCHAR), sct));
            }
        } else {
            items.add(new SQLItems<SQLItem>(new SQLItemImpl(value)));
        }
    }
    return convert(sql, items, namedItems);
}
Also used : ArrayList(java.util.ArrayList) SQLItem(lucee.runtime.db.SQLItem) Struct(lucee.runtime.type.Struct) SQLItemImpl(lucee.runtime.db.SQLItemImpl)

Aggregations

SQLItem (lucee.runtime.db.SQLItem)6 PreparedStatement (java.sql.PreparedStatement)2 ArrayList (java.util.ArrayList)2 SQLImpl (lucee.runtime.db.SQLImpl)2 SQLItemImpl (lucee.runtime.db.SQLItemImpl)2 DatabaseException (lucee.runtime.exp.DatabaseException)2 Array (lucee.runtime.type.Array)2 ArrayImpl (lucee.runtime.type.ArrayImpl)2 Struct (lucee.runtime.type.Struct)2 StructImpl (lucee.runtime.type.StructImpl)2 QueryArray (lucee.runtime.type.query.QueryArray)2 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Date (java.util.Date)1 TimeZone (java.util.TimeZone)1 Log (lucee.commons.io.log.Log)1 PageContextImpl (lucee.runtime.PageContextImpl)1 CacheHandler (lucee.runtime.cache.tag.CacheHandler)1 CacheHandlerCollectionImpl (lucee.runtime.cache.tag.CacheHandlerCollectionImpl)1 CacheHandlerPro (lucee.runtime.cache.tag.CacheHandlerPro)1