Method: SQLite3::Database#execute_batch
- Defined in:
- lib/sqlite3/database.rb
#execute_batch(sql, bind_vars = [], *args) ⇒ Object
Executes all SQL statements in the given string. By contrast, the other means of executing queries will only execute the first statement in the string, ignoring all subsequent statements. This will execute each one in turn. The same bind parameters, if given, will be applied to each statement.
This always returns nil, making it unsuitable for queries that return rows.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/sqlite3/database.rb', line 195 def execute_batch( sql, bind_vars = [], *args ) # FIXME: remove this stuff later unless [Array, Hash].include?(bind_vars.class) bind_vars = [bind_vars] warn("\#{caller[0]} is calling SQLite3::Database#execute_batch with bind parameters\nthat are not a list of a hash. Please switch to passing bind parameters as an\narray or hash. Support for this behavior will be removed in version 2.0.0.\n eowarn\n end\n\n # FIXME: remove this stuff later\n if bind_vars.nil? || !args.empty?\n if args.empty?\n bind_vars = []\n else\n bind_vars = [nil] + args\n end\n\n warn(<<-eowarn) if $VERBOSE\n\#{caller[0]} is calling SQLite3::Database#execute_batch with nil or multiple bind params\nwithout using an array. Please switch to passing bind parameters as an array.\nSupport for this behavior will be removed in version 2.0.0.\n eowarn\n end\n\n sql = sql.strip\n until sql.empty? do\n prepare( sql ) do |stmt|\n # FIXME: this should probably use sqlite3's api for batch execution\n # This implementation requires stepping over the results.\n if bind_vars.length == stmt.bind_parameter_count\n stmt.bind_params(bind_vars)\n end\n stmt.step\n sql = stmt.remainder.strip\n end\n end\n nil\nend\n") if $VERBOSE |