node-oracle icon indicating copy to clipboard operation
node-oracle copied to clipboard

Benefits of prepared statements?

Open ThomasR opened this issue 10 years ago • 1 comments

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.

ThomasR avatar May 07 '14 04:05 ThomasR

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.

7imbrook avatar Sep 11 '14 16:09 7imbrook