You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-2Lines changed: 22 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,12 +9,14 @@ This one is not.
9
9
10
10
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.
11
11
12
-
The API consists of two classes:
12
+
The API consists of three classes:
13
13
14
14
`Mysql2::Client` - your connection to the database.
15
15
16
16
`Mysql2::Result` - returned from issuing a #query on the connection. It includes Enumerable.
17
17
18
+
`Mysql2::Statement` - returned from issuing a #prepare on the connection. Execute the statement to get a Result.
19
+
18
20
## Installing
19
21
### General Instructions
20
22
```sh
@@ -153,6 +155,20 @@ results.each(:as => :array) do |row|
153
155
end
154
156
```
155
157
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
+
156
172
## Connection options
157
173
158
174
You may set the following connection options in Mysql2::Client.new(...):
@@ -538,4 +554,8 @@ though.
538
554
* Yury Korolev (http://github.com/yury) - for TONS of help testing the Active Record adapter
539
555
* Aaron Patterson (http://github.com/tenderlove) - tons of contributions, suggestions and general badassness
540
556
* 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
561
+
* Tamir Duberstein (http://github.com/tamird) - for help with timeouts and all around updates and cleanups
0 commit comments