Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query.withParams upgrade #370

Open
vertex-github opened this issue Apr 15, 2024 · 2 comments
Open

Query.withParams upgrade #370

vertex-github opened this issue Apr 15, 2024 · 2 comments

Comments

@vertex-github
Copy link
Contributor

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;
    }
@vertex-github
Copy link
Contributor Author

With the new SequencedCollections this could be improved a little

@aaberg
Copy link
Owner

aaberg commented Apr 15, 2024

Nice. Thanks. I'll take a look 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants