does rails activerecord have any support for prepared statements? best I can tell -no.
When you use prepared statement(i.e pre-compiled statement), As soon as DB gets this statement, it compiles it and caches it so that it can use the last compiled statement for successive call of same statement. So it becomes pre-compiled for successive calls.
Query result obtained by SELECT type prepared statement is stored in query cache on a universal basis independent of the source type of query and can be reused both by another execution of this or another prepared statement and by direct query when its text is identical to the SQL text of the first prepared statement.
Prepared statements offer two major benefits: The query only needs to be parsed (or prepared) once, but can be executed multiple times with the same or different parameters. When the query is prepared, the database will analyze, compile and optimize its plan for executing the query.
A prepared statement is a parameterized and reusable SQL query which forces the developer to write the SQL command and the user-provided data separately. The SQL command is executed safely, preventing SQL Injection vulnerabilities.
Since Rails 3.1 prepared statements in active_record are in place. See this presentation http://www.youtube.com/watch?v=kWOAHIpmLAI by Aaron Patterson.
There are recent patches available to do this for mysql:
https://rails.lighthouseapp.com/projects/8994/tickets/3151-mysql-adapter-update-to-enable-use-of-stored-procedures
For Oracle, there are 2 related projects that seem like they do the trick:
plsql support http://github.com/rsim/ruby-plsql
more goodies when using Oracle and AR, with use of ruby-plsql gem for stored procs http://wiki.github.com/rsim/oracle-enhanced/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With