Git Product home page Git Product logo

Comments (8)

ttddyy avatar ttddyy commented on May 28, 2024

Hi @shahamit

Is this about detecting query execution between java.sql.Statement vs java.sql.PreparedStatement?
If so, now(v1.3) ExecutionInfo contains statementType which indicates whether it was an invocation of statement, prepared statement, or callable statement.
I think that can be used to update your statistics based on type.
If you use the query count statistics, the QueryCount also contains number of queries by type(statement, prepared, callable).

Or, is it something specific to database(oracle)? Retrievable from JDBC API or driver(db vender) specific API?

Regards,

from datasource-proxy.

shahamit avatar shahamit commented on May 28, 2024

No, it won't be a check between between java.sql.Statement vs java.sql.PreparedStatement. In the example that I mentioned earlier

select emp_name from employee where emp_id = 24 and emp_type = ?

This would be a PreparedStatement but the emp_id parameter is hard coded. So its not a PreparedStatement practically.

from datasource-proxy.

ttddyy avatar ttddyy commented on May 28, 2024

I’m not sure about the definition of the static statement.
So, when there is a hardcoded parameter(“key=value”) in where clause, it is a static statement regardless of executed as PreparedStatement??

sample1:

Statement stat = conn.createStatement();
stat.execute("SELECT * FROM employee WHERE id = 100”);
  • static statement since it’s Statement

sample2:

PreparedStatement ps = conn.prepareStatement("SELECT * FROM employee WHERE id = 100 and type=’sales'”);
ps.execute();
  • static statement because there is no parameters even though it is PreparedStatement ??

sample3:

PreparedStatement ps = conn.prepareStatement("SELECT * FROM employee WHERE id = 100 and type=?”);
ps.setString(1, “sales”);
ps.execute();
  • static statement because there is “id=100” even though PreparedStatement and type=? ??

sample4:

PreparedStatement ps = conn.prepareStatement("SELECT * FROM employee WHERE id = ? and type=?”);
ps.setInt(1, 100);
ps.setString(1, “sales”);
ps.execute();
  • not static statement

Is my assumption correct??

from datasource-proxy.

shahamit avatar shahamit commented on May 28, 2024

Yes, your assumption is right. Is it possible to distinguish between these static and prepared statements in the code?

from datasource-proxy.

ttddyy avatar ttddyy commented on May 28, 2024

It's kinda workaround check but how about this?

private boolean isStaticStatement(ExecutionInfo execInfo, String query) {
    StatementType statType = execInfo.getStatementType();
    if (StatementType.STATEMENT.equals(statType)) {
        return true;
    } else if (StatementType.PREPARED.equals(statType) && !query.contains("?")) {
        return true;
    }
    return false;
}

from datasource-proxy.

shahamit avatar shahamit commented on May 28, 2024

This wouldn't catch "sample 3" from your initial reply which is the main problem. It would mark sample 3 as a Prepared Statement when it is not completely a Prepared Statement

from datasource-proxy.

ttddyy avatar ttddyy commented on May 28, 2024

ah, you're right.
hmm, then i think it needs to parse the query to find hardcoded "key=value" unless oracle jdbc driver has a way to say it's a static query or not...

from datasource-proxy.

ttddyy avatar ttddyy commented on May 28, 2024

Since the detection of static statement requires analyzing the query, datasource-proxy can be a starting point to trigger such logic, but is not planning to have the logic itself in datasource-proxy.

Thanks for raising the issue, now I'm closing this.

from datasource-proxy.

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.