joeferner / node-oracle

node.js driver to connect with an oracle database.
MIT License
270 stars 99 forks source link

Benefits of prepared statements? #177

Open ThomasR opened 10 years ago

ThomasR commented 10 years ago

I understand how prepared statements work, but I fail to see why I should use them. The code gets more verbose compared to simply running connection.execute() on a string with placeholders.

Is there considerable performance benefit? If so: How is this possible? That should probably be mentioned in the readme.

7imbrook commented 10 years ago

When a query is executed it has to prepare a statement to send to the database. It takes the SQL statement and complies it down to the actual query. Every time you use execute it does this. If you prepare the statement first, then you can inject your "wildcard" values into the statement which is a much faster operation then re-compiling the statement each time.

The places you'll get performance benefits are where you need to perform the operation over and over again say inside a tight loop or recursive call.