Giter Site home page Giter Site logo

Comments (8)

mloskot avatar mloskot commented on May 12, 2024

I'm going to implement the option 2. for SOCI 3.2.0

from soci.

vadz avatar vadz commented on May 12, 2024

It's not really an objection but I have a feeling that working with SQL at string level is not really the right thing to do. One thing that bothers me is that the examples above break down for the queries which already include a WHERE clause. Another one is that "transformation" can be anything at all (including absence of changes, the mechanism for which I'd consider using this would be for logging all SQL queries executed in my code).

So if we just want to allow defining extra WHERE clauses for the queries which don't necessarily include them, it'd be IMO better to provide some soci::session::set_projection() which could, at least in principle, be implemented correctly even for the queries which already have WHERE clauses and which is also more clear.

But maybe I just don't see the intended use case for this feature. For me the idea looks dangerous (my first thought was: "spooky action at a distance", this is going to be fun to debug) rather than interesting...

from soci.

mloskot avatar mloskot commented on May 12, 2024

@vadz The idea is not to simply allow extra WHERE (or any other SQL clause), but to enable users to perform some action on query string just before it's executed. In fact, it may be used as part of security measures, a sanitisation checking for any unverified input (SQL injection comes to mind). My examples are just poor and don't back up the idea well.

Certainly, this kind of "working with SQL at string level" is an advanced feature.

from soci.

vnaydionov avatar vnaydionov commented on May 12, 2024

I can imagine why it might be useful.
For example, in Oracle one can insert specially formatted comment just after SELECT keyword to force certain behaviour for the query optimizer.
In particular, the following directive enforces using rule-based optimizer rather than cost-based one.
SELECT /+RULE/ A, B FROM C

Also, here is an example of more specialized interface, allowing for altering queries
http://docs.sqlalchemy.org/en/rel_0_7/core/expression_api.html#sqlalchemy.sql.expression.Select.prefix_with

from soci.

mloskot avatar mloskot commented on May 12, 2024

@vnaydionov I didn't know about this feature. Nice one.

from soci.

vadz avatar vadz commented on May 12, 2024

On Sun, 24 Feb 2013 11:21:48 -0800 Viacheslav Naydenov [email protected] wrote:

VN> I can imagine why it might be useful.
VN> For example, in Oracle one can insert specially formatted comment just after SELECT keyword to force certain behaviour for the query optimizer.
VN> In particular, the following directive enforces using rule-based optimizer rather than cost-based one.
VN> SELECT /+RULE/ A, B FROM C
VN>
VN> Also, here is an example of more specialized interface, allowing for altering queries
VN> http://docs.sqlalchemy.org/en/rel_0_7/core/expression_api.html#sqlalchemy.sql.expression.Select.prefix_with

Interesting, I didn't know about either of these uses. Perhaps a mention
of them could be added to the documentation for this feature to make it
more clear what kind of things can be done with it.

VZ

from soci.

mloskot avatar mloskot commented on May 12, 2024

@vadz good idea, I'll add a note about this usage, as part of #85

from soci.

dstocking-ext avatar dstocking-ext commented on May 12, 2024

Is there any way that this could be changed so that it gives the actual sql statement object? If I want to add more to a where clause or what have you I cannot use a soci::use(). Idk if a soci::use sanatizes the input, but still would like it all in one spot.

from soci.

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.