Comments (8)
I'm going to implement the option 2. for SOCI 3.2.0
from soci.
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.
@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.
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.
@vnaydionov I didn't know about this feature. Nice one.
from soci.
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.
@vadz good idea, I'll add a note about this usage, as part of #85
from soci.
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)
- fsanitize=undefined in parent project causes to link due to missing rtti infos in soci.so HOT 3
- Getting multiple recordsets from a stored procedure
- SOCI doesn't compile when using the `UNICODE` flag on Windows HOT 4
- Next release
- vcpkg soci crashes on session::close() HOT 1
- Streamline cmake usage HOT 14
- How to read DATETIME(3) type in database? HOT 2
- Missing backend includes HOT 2
- failed to connect to mysql database after I upgrade the mariadbclient library inside the msys2 HOT 2
- MSVC: number of sections exceeded object file format limit
- Issue with Boost 1.84 HOT 6
- Incorrect query result with `use` and `into` into vector, at least for sqlite3. HOT 1
- Incorrect query result with `use` and `into` into vector, at least for sqlite3. HOT 2
- SOCI with MySQL on Linux (Ubuntu) - impossible to link static HOT 12
- Dates before year 1900 stored in Oracle as one hundred years earlier. HOT 1
- Win10, sqlite3 , MultiThread , Can not use into and use . HOT 2
- Getting Invalid Cursor State on mssql - complex queries - Urgent help needed HOT 2
- BLOB does not work in Oracle HOT 11
- Cant use sqlstate(). Undefined reference HOT 2
- Using `row::move_as` while iterating `rowset` yields segmentation fault HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from soci.