I have set out to create prepared statement support for active record. So far it is looking good. I am looking at different ways to manage the statements. The biggest pain will be supporting the syntax of different databases. I will start out with statements in Postgres.
Using prepared statements in your applications is like giving a tug on your spice weasel!
I am not going to talk about why prepare statements are important. That information can be found at google, or from years of doing database work. This is how I am going add support for them in to active record.
The syntax is not complete yet but it will go down something like this...
ActiveRecord::Base.create_ps({:key=>'Pstatemnet1', :sql=>'select * from cost_to_cost where id=$1;})
</code
<br> <br><br>Notice the use of very helpful names. Also, notice the ps and not prepared_statement the less I have to type the more I will use it, and it will just be an ailis anyway. So, key is going to be the name that is associated with the statement. As I currently understand it postgres allows you to set this and oracle slaps you in the face. The the sql statement will be more like active record and use ? for the value locations. The syntax for this statement comes from postgres. <br><br> Yah we made a statement.. but can we use it?<BR><br><br>
<code>
SpaceGhost.find(:ps,:key=>"Pstatement1",:conditions=>[100]) <br>
SpaceGhost.find_by_ps(:key=>"Pstatement1",:conditions=>[15])<br>
I think its simple and sweet. We are also working on "auto_magic" mode for people who do not know sql. This will high jack active records processes of creating the sql, and create statements, manage them and run them instead of the normal sql statements. I just want to make sure no one can say I discriminate against people who do not know sql. Also, I have yet to test what happens if you call the a statement with the wrong model. Currently we do not have the concept of this model owns this statement. We need a better handling of errors and more testing with Oracle. But as Nick always says "Its piratically done"