Git Product home page Git Product logo

Comments (9)

moderakh avatar moderakh commented on August 29, 2024

@zhouchong90 for IN (...) clause please try to avoid Parametrizing the query. Please just pass the query string without any parametrization.

from azure-cosmosdb-java.

zhouchong90 avatar zhouchong90 commented on August 29, 2024

Will it be suspect to SQL injections and attacks?

from azure-cosmosdb-java.

moderakh avatar moderakh commented on August 29, 2024

@zhouchong90
You can try something like this:

String query = "SELECT * from c where c.prop IN (@param1, @param2)";
SqlParameterCollection params = new SqlParameterCollection(new SqlParameter("@param1", 98), new SqlParameter("@param2", 99));
SqlQuerySpec sqs = new SqlQuerySpec(query, params);

from azure-cosmosdb-java.

zhouchong90 avatar zhouchong90 commented on August 29, 2024

@moderakh Thanks. Will there be any built-in support to take a list directly? Since I'll have a list of thousands of values and it'll be ugly to write a dynamically generate sql and put the values.

from azure-cosmosdb-java.

mohitgoyal91 avatar mohitgoyal91 commented on August 29, 2024

@zhouchong90 We have a simple library, where you can generate queries more effectively.
https://github.com/mohitgoyal91/azure-cosmosdb-querybuilder-java

For example in your case for query -> "SELECT * from c where c.prop IN (@param1, @Param2)"
Assuming you have a

List<Integer> list = new ArrayList<>();
list.add(98); list.add(99);

Simply call the below function:

new SelectQuery()
.in("prop", list.toArray())
.createQuery();

from azure-cosmosdb-java.

christopheranderson avatar christopheranderson commented on August 29, 2024

Cleaning up older issues.

No plans on support parameterized lists directly any time soon. Following Mohit's pattern makes sense and something we could potentially support ourselves in the future, but not a priority at the moment.

from azure-cosmosdb-java.

kmansel avatar kmansel commented on August 29, 2024

For node SDK based applications, I found that this way works as well.

sqlQuery: SqlQuerySpec = {
        query: 'SELECT * FROM t WHERE ARRAY_CONTAINS(@idList, t.id)',
        parameters: [
            {
                name: '@idList',
                value: ['id1','id2','id3'],
            },
        ],
    };

from azure-cosmosdb-java.

MrBuddyCasino avatar MrBuddyCasino commented on August 29, 2024

Just found this issue, absolutely perplexed that this is just silently not supported. Its not like the client libs are still 1.x early days. Combined with the fact that it is not possible to log the outgoing SQL queries, this just cost me several hours.

from azure-cosmosdb-java.

viswa-optimusprime avatar viswa-optimusprime commented on August 29, 2024

@ALL is this fixed ? What is the solution ? We really need this feature to pass list for in clause.. Can someone tell us the solution ?

from azure-cosmosdb-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.