Skip to content

Commit aeb4f70

Browse files
committed
README updates for Prepared Statements
1 parent eaa4027 commit aeb4f70

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ This one is not.
99

1010
It also forces the use of UTF-8 [or binary] for the connection [and all strings in 1.9, unless Encoding.default_internal is set then it'll convert from UTF-8 to that encoding] and uses encoding-aware MySQL API calls where it can.
1111

12-
The API consists of two classes:
12+
The API consists of three classes:
1313

1414
`Mysql2::Client` - your connection to the database.
1515

1616
`Mysql2::Result` - returned from issuing a #query on the connection. It includes Enumerable.
1717

18+
`Mysql2::Statement` - returned from issuing a #prepare on the connection. Execute the statement to get a Result.
19+
1820
## Installing
1921
### General Instructions
2022
``` sh
@@ -153,6 +155,20 @@ results.each(:as => :array) do |row|
153155
end
154156
```
155157

158+
Prepared statements are supported, as well. In a prepared statement, use a `?`
159+
in place of each value and then execute the statement to retrieve a result set.
160+
Pass your arguments to the execute method in the same number and order as the
161+
question marks in the statement.
162+
163+
``` ruby
164+
statement = @client.prepare("SELECT * FROM users WHERE login_count = ?")
165+
result1 = statement.execute(1)
166+
result2 = statement.execute(2)
167+
168+
statement = @client.prepare("SELECT * FROM users WHERE last_login >= ? AND location LIKE ?")
169+
result = statement.execute(1, "CA")
170+
```
171+
156172
## Connection options
157173

158174
You may set the following connection options in Mysql2::Client.new(...):
@@ -538,4 +554,7 @@ though.
538554
* Yury Korolev (http://github.com/yury) - for TONS of help testing the Active Record adapter
539555
* Aaron Patterson (http://github.com/tenderlove) - tons of contributions, suggestions and general badassness
540556
* Mike Perham (http://github.com/mperham) - Async Active Record adapter (uses Fibers and EventMachine)
541-
* Aaron Stone (http://github.com/sodabrew) - additional client settings, local files, microsecond time, maintenance support.
557+
* Aaron Stone (http://github.com/sodabrew) - additional client settings, local files, microsecond time, maintenance support
558+
* Kouhei Ueno (https://github.com/nyaxt) - for the original work on Prepared Statements way back in 2012
559+
* John Cant (http://github.com/johncant) - polishing and updating Prepared Statements support
560+
* Justin Case (http://github.com/justincase) - polishing and updating Prepared Statements support and getting it merged

0 commit comments

Comments
 (0)