Skip to content

Query.withParams upgrade #370

@vertex-github

Description

@vertex-github

We also had this mod to Query.withParams to allow Lists and arrays to be passed in:

	/**
	 * Construct a Query with the provided variable number of parameters.  Accepts all object types, List, and arrays as parameters.
	 * @param paramValues
	 * @return
	 */
    public Query withParams(Object... paramValues){
        int i=0;
        for (Object paramValue : paramValues) {
	        if( paramValue == null ) { // null values are valid for inserting in to a DB . We need to check for these first.
		        addParameter( "p" + (++i), paramValue );
	        }
	        else if( paramValue instanceof Collection ) {
				if( paramValue instanceof List ) {
					List list = (List) paramValue;
					for( Object val : list ) {
						addParameter( "p" + (++i), val );
					}
				}
				else {
					throw new Sql2oException( "I can only handle ordered Collections - i.e. a List" );
				}
	        }
	        else if( paramValue.getClass().isArray() ) {
		        int len = java.lang.reflect.Array.getLength( paramValue );
		        for( int j = 0; j < len; j++ )
		        {
			        Object arrVal = java.lang.reflect.Array.get( paramValue, j );
			        addParameter( "p" + (++i), arrVal );
		        }
	        }
            else {
		        addParameter( "p" + (++i), paramValue );
	        }
        }
        return this;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions