Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Parametrized queries using cached prepared statements

Jesse Gumm edited this pageJul 3, 2019 ·4 revisions

A parametrized query is implemented using prepared statements. This is a parametrized query:

1>mysql:query(Pid,"SELECT * FROM foo WHERE id=?", [Id]).{ok,[<<"id">>,<<"bar">>],[[1,<<"baz">>],[2,<<"bah">>]]}

In SQL, you need to call "CREATE STATEMENT" to create the prepared statement before you can execute it using "EXECUTE" and passing values for the? place holders. This is two calls. When you are done, the prepared statement should be deleted using "DROP STATEMENT" to free resources, thus three calls in total.

The MySQL/OTP connection process is saving the prepared statement so when the same query is used again within a certain time (the cache TTL) the same prepared statement can be used. The query itself is used as a cache key. Thus, if the same code is run frequently, the prepared statement will already exist and there will be only one call to the server.

Use the{query_cache_time, Timeout} option tomysql:start_link/1 to set the cache time in milleseconds or'infinity'.

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp