2009-01-06 15:51:01 +00:00
|
|
|
# Copyright (C) 2008-2009 10gen Inc.
|
2008-11-22 01:00:51 +00:00
|
|
|
#
|
2009-02-15 13:24:14 +00:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
2008-11-22 01:00:51 +00:00
|
|
|
#
|
2009-02-15 13:24:14 +00:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2008-11-22 01:00:51 +00:00
|
|
|
#
|
2009-02-15 13:24:14 +00:00
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2008-11-22 01:00:51 +00:00
|
|
|
|
|
|
|
require 'mongo/util/byte_buffer'
|
|
|
|
require 'mongo/util/bson'
|
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
module Mongo
|
2008-11-22 01:00:51 +00:00
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
# A cursor over query results. Returned objects are hashes.
|
|
|
|
class Cursor
|
2009-10-20 19:44:46 +00:00
|
|
|
include Mongo::Conversions
|
2009-08-20 14:50:48 +00:00
|
|
|
include Enumerable
|
2008-11-22 01:00:51 +00:00
|
|
|
|
2009-10-22 18:10:12 +00:00
|
|
|
attr_reader :collection, :selector, :admin, :fields,
|
|
|
|
:order, :hint, :snapshot, :timeout,
|
|
|
|
:full_collection_name
|
2009-01-13 19:02:16 +00:00
|
|
|
|
2009-08-21 15:21:33 +00:00
|
|
|
# Create a new cursor.
|
|
|
|
#
|
|
|
|
# Should not be called directly by application developers.
|
2009-10-22 18:10:12 +00:00
|
|
|
def initialize(collection, options={})
|
|
|
|
@db = collection.db
|
|
|
|
@collection = collection
|
2009-11-23 20:20:05 +00:00
|
|
|
@connection = @db.connection
|
2009-10-22 18:10:12 +00:00
|
|
|
|
|
|
|
@selector = convert_selector_for_query(options[:selector])
|
|
|
|
@fields = convert_fields_for_query(options[:fields])
|
|
|
|
@admin = options[:admin] || false
|
|
|
|
@skip = options[:skip] || 0
|
|
|
|
@limit = options[:limit] || 0
|
|
|
|
@order = options[:order]
|
|
|
|
@hint = options[:hint]
|
|
|
|
@snapshot = options[:snapshot]
|
|
|
|
@timeout = options[:timeout] || false
|
|
|
|
@explain = options[:explain]
|
2009-11-23 20:20:05 +00:00
|
|
|
@socket = options[:socket]
|
2009-10-22 18:10:12 +00:00
|
|
|
|
2009-11-23 20:20:05 +00:00
|
|
|
@full_collection_name = "#{@collection.db.name}.#{@collection.name}"
|
2009-08-20 14:50:48 +00:00
|
|
|
@cache = []
|
|
|
|
@closed = false
|
|
|
|
@query_run = false
|
|
|
|
end
|
2009-01-13 19:02:16 +00:00
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
# Return the next object or nil if there are no more. Raises an error
|
|
|
|
# if necessary.
|
|
|
|
def next_object
|
|
|
|
refill_via_get_more if num_remaining == 0
|
|
|
|
o = @cache.shift
|
2009-01-23 16:47:22 +00:00
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
if o && o['$err']
|
|
|
|
err = o['$err']
|
2009-01-23 16:47:22 +00:00
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
# If the server has stopped being the master (e.g., it's one of a
|
|
|
|
# pair but it has died or something like that) then we close that
|
|
|
|
# connection. If the db has auto connect option and a pair of
|
|
|
|
# servers, next request will re-open on master server.
|
2009-11-23 18:13:14 +00:00
|
|
|
if err == "not master"
|
|
|
|
raise ConnectionFailure, err
|
2009-11-23 23:09:13 +00:00
|
|
|
@connection.close
|
2009-11-23 18:13:14 +00:00
|
|
|
end
|
2009-01-23 16:47:22 +00:00
|
|
|
|
2009-11-23 18:13:14 +00:00
|
|
|
raise OperationFailure, err
|
2009-08-20 14:50:48 +00:00
|
|
|
end
|
2008-11-22 01:00:51 +00:00
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
o
|
|
|
|
end
|
2009-08-18 15:26:58 +00:00
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
# Get the size of the results set for this query.
|
|
|
|
#
|
|
|
|
# Returns the number of objects in the results set for this query. Does
|
|
|
|
# not take limit and skip into account. Raises OperationFailure on a
|
|
|
|
# database error.
|
|
|
|
def count
|
2009-10-22 18:10:12 +00:00
|
|
|
command = OrderedHash["count", @collection.name,
|
|
|
|
"query", @selector,
|
|
|
|
"fields", @fields]
|
2009-11-23 20:20:05 +00:00
|
|
|
response = @db.command(command)
|
2009-08-20 14:50:48 +00:00
|
|
|
return response['n'].to_i if response['ok'] == 1
|
|
|
|
return 0 if response['errmsg'] == "ns missing"
|
|
|
|
raise OperationFailure, "Count failed: #{response['errmsg']}"
|
|
|
|
end
|
2009-09-17 18:54:30 +00:00
|
|
|
|
|
|
|
# Sort this cursor's result
|
|
|
|
#
|
2009-10-08 14:02:54 +00:00
|
|
|
# Takes either a single key and a direction, or an array of [key,
|
|
|
|
# direction] pairs. Directions should be specified as Mongo::ASCENDING
|
|
|
|
# or Mongo::DESCENDING (or :ascending or :descending) (or :asc or :desc).
|
2009-09-17 18:54:30 +00:00
|
|
|
#
|
2009-10-08 14:02:54 +00:00
|
|
|
# Raises InvalidOperation if this cursor has already been used. Raises
|
|
|
|
# InvalidSortValueError if specified order is invalid.
|
2009-09-04 23:04:11 +00:00
|
|
|
#
|
2009-09-17 18:54:30 +00:00
|
|
|
# This method overrides any sort order specified in the Collection#find
|
|
|
|
# method, and only the last sort applied has an effect
|
2009-10-08 14:02:54 +00:00
|
|
|
def sort(key_or_list, direction=nil)
|
2009-09-17 19:07:18 +00:00
|
|
|
check_modifiable
|
2009-10-08 14:02:54 +00:00
|
|
|
|
|
|
|
if !direction.nil?
|
|
|
|
order = [[key_or_list, direction]]
|
|
|
|
else
|
|
|
|
order = key_or_list
|
|
|
|
end
|
|
|
|
|
2009-10-22 18:10:12 +00:00
|
|
|
@order = order
|
2009-09-04 23:04:11 +00:00
|
|
|
self
|
|
|
|
end
|
2009-01-07 19:07:17 +00:00
|
|
|
|
2009-09-16 21:52:41 +00:00
|
|
|
# Limits the number of results to be returned by this cursor.
|
2009-10-22 18:10:12 +00:00
|
|
|
# Returns the current number_to_return if no parameter is given.
|
2009-09-05 18:25:49 +00:00
|
|
|
#
|
2009-09-17 18:54:30 +00:00
|
|
|
# Raises InvalidOperation if this cursor has already been used.
|
|
|
|
#
|
|
|
|
# This method overrides any limit specified in the Collection#find method,
|
|
|
|
# and only the last limit applied has an effect.
|
2009-10-22 18:10:12 +00:00
|
|
|
def limit(number_to_return=nil)
|
|
|
|
return @limit unless number_to_return
|
2009-09-05 18:25:49 +00:00
|
|
|
check_modifiable
|
|
|
|
raise ArgumentError, "limit requires an integer" unless number_to_return.is_a? Integer
|
|
|
|
|
2009-10-22 18:10:12 +00:00
|
|
|
@limit = number_to_return
|
2009-09-17 19:07:18 +00:00
|
|
|
self
|
2009-09-05 18:25:49 +00:00
|
|
|
end
|
2009-09-16 21:52:41 +00:00
|
|
|
|
|
|
|
# Skips the first +number_to_skip+ results of this cursor.
|
2009-10-22 18:10:12 +00:00
|
|
|
# Returns the current number_to_skip if no parameter is given.
|
|
|
|
#
|
2009-09-17 18:54:30 +00:00
|
|
|
# Raises InvalidOperation if this cursor has already been used.
|
|
|
|
#
|
2009-09-17 20:45:03 +00:00
|
|
|
# This method overrides any skip specified in the Collection#find method,
|
2009-09-17 18:54:30 +00:00
|
|
|
# and only the last skip applied has an effect.
|
2009-10-22 18:10:12 +00:00
|
|
|
def skip(number_to_skip=nil)
|
|
|
|
return @skip unless number_to_skip
|
2009-09-05 18:25:49 +00:00
|
|
|
check_modifiable
|
2009-09-16 21:52:41 +00:00
|
|
|
raise ArgumentError, "skip requires an integer" unless number_to_skip.is_a? Integer
|
2009-09-05 18:25:49 +00:00
|
|
|
|
2009-10-22 18:10:12 +00:00
|
|
|
@skip = number_to_skip
|
2009-09-17 19:07:18 +00:00
|
|
|
self
|
2009-09-05 18:25:49 +00:00
|
|
|
end
|
|
|
|
|
2009-08-21 18:11:59 +00:00
|
|
|
# Iterate over each document in this cursor, yielding it to the given
|
|
|
|
# block.
|
2009-08-20 14:50:48 +00:00
|
|
|
#
|
2009-08-21 18:11:59 +00:00
|
|
|
# Iterating over an entire cursor will close it.
|
2009-08-20 14:50:48 +00:00
|
|
|
def each
|
2009-08-21 18:11:59 +00:00
|
|
|
num_returned = 0
|
2009-10-22 18:10:12 +00:00
|
|
|
while more? && (@limit <= 0 || num_returned < @limit)
|
2009-08-21 18:11:59 +00:00
|
|
|
yield next_object()
|
|
|
|
num_returned += 1
|
2009-08-20 14:50:48 +00:00
|
|
|
end
|
|
|
|
end
|
2008-11-22 01:00:51 +00:00
|
|
|
|
2009-08-21 18:11:59 +00:00
|
|
|
# Return all of the documents in this cursor as an array of hashes.
|
2009-08-20 14:50:48 +00:00
|
|
|
#
|
2009-08-21 18:11:59 +00:00
|
|
|
# Raises InvalidOperation if this cursor has already been used (including
|
|
|
|
# any previous calls to this method).
|
2009-08-20 14:50:48 +00:00
|
|
|
#
|
2009-08-21 18:11:59 +00:00
|
|
|
# Use of this method is discouraged - iterating over a cursor is much
|
|
|
|
# more efficient in most cases.
|
2009-08-20 14:50:48 +00:00
|
|
|
def to_a
|
2009-08-21 18:11:59 +00:00
|
|
|
raise InvalidOperation, "can't call Cursor#to_a on a used cursor" if @query_run
|
|
|
|
rows = []
|
2009-08-20 14:50:48 +00:00
|
|
|
num_returned = 0
|
2009-10-22 18:10:12 +00:00
|
|
|
while more? && (@limit <= 0 || num_returned < @limit)
|
2009-08-21 18:11:59 +00:00
|
|
|
rows << next_object()
|
2009-08-20 14:50:48 +00:00
|
|
|
num_returned += 1
|
|
|
|
end
|
2009-08-21 18:11:59 +00:00
|
|
|
rows
|
2009-08-20 14:50:48 +00:00
|
|
|
end
|
2009-01-14 15:42:56 +00:00
|
|
|
|
2009-08-21 15:21:33 +00:00
|
|
|
# Returns an explain plan record for this cursor.
|
2009-08-20 14:50:48 +00:00
|
|
|
def explain
|
2009-10-22 18:10:12 +00:00
|
|
|
c = Cursor.new(@collection, query_options_hash.merge(:limit => -@limit.abs, :explain => true))
|
2009-08-20 14:50:48 +00:00
|
|
|
explanation = c.next_object
|
|
|
|
c.close
|
2009-01-13 19:02:16 +00:00
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
explanation
|
|
|
|
end
|
2008-11-22 01:00:51 +00:00
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
# Close the cursor.
|
|
|
|
#
|
2009-10-21 14:11:33 +00:00
|
|
|
# Note: if a cursor is read until exhausted (read until Mongo::Constants::OP_QUERY or
|
|
|
|
# Mongo::Constants::OP_GETMORE returns zero for the cursor id), there is no need to
|
2009-08-20 14:50:48 +00:00
|
|
|
# close it by calling this method.
|
2009-08-21 15:21:33 +00:00
|
|
|
#
|
|
|
|
# Collection#find takes an optional block argument which can be used to
|
|
|
|
# ensure that your cursors get closed. See the documentation for
|
|
|
|
# Collection#find for details.
|
2009-08-20 14:50:48 +00:00
|
|
|
def close
|
2009-10-21 14:11:33 +00:00
|
|
|
if @cursor_id
|
|
|
|
message = ByteBuffer.new
|
|
|
|
message.put_int(0)
|
|
|
|
message.put_int(1)
|
|
|
|
message.put_long(@cursor_id)
|
2009-11-23 20:20:05 +00:00
|
|
|
@connection.send_message_with_operation(Mongo::Constants::OP_KILL_CURSORS, message, "cursor.close()")
|
2009-10-21 14:11:33 +00:00
|
|
|
end
|
2009-08-20 14:50:48 +00:00
|
|
|
@cursor_id = 0
|
2009-10-21 14:11:33 +00:00
|
|
|
@closed = true
|
2009-08-20 14:50:48 +00:00
|
|
|
end
|
2008-11-22 01:00:51 +00:00
|
|
|
|
2009-08-21 15:21:33 +00:00
|
|
|
# Returns true if this cursor is closed, false otherwise.
|
|
|
|
def closed?; @closed; end
|
|
|
|
|
2009-10-22 18:10:12 +00:00
|
|
|
# Returns an integer indicating which query options have been selected.
|
|
|
|
# See http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-Mongo::Constants::OPQUERY
|
|
|
|
def query_opts
|
|
|
|
timeout = @timeout ? 0 : Mongo::Constants::OP_QUERY_NO_CURSOR_TIMEOUT
|
2009-11-23 20:20:05 +00:00
|
|
|
slave_ok = @connection.slave_ok? ? Mongo::Constants::OP_QUERY_SLAVE_OK : 0
|
2009-10-22 18:10:12 +00:00
|
|
|
slave_ok + timeout
|
|
|
|
end
|
|
|
|
|
|
|
|
# Returns the query options set on this Cursor.
|
|
|
|
def query_options_hash
|
|
|
|
{ :selector => @selector,
|
|
|
|
:fields => @fields,
|
|
|
|
:admin => @admin,
|
|
|
|
:skip => @skip_num,
|
|
|
|
:limit => @limit_num,
|
|
|
|
:order => @order,
|
|
|
|
:hint => @hint,
|
|
|
|
:snapshot => @snapshot,
|
|
|
|
:timeout => @timeout }
|
|
|
|
end
|
|
|
|
|
2009-08-21 15:03:56 +00:00
|
|
|
private
|
2008-11-22 01:00:51 +00:00
|
|
|
|
2009-10-22 18:10:12 +00:00
|
|
|
# Converts the +:fields+ parameter from a single field name or an array
|
|
|
|
# of fields names to a hash, with the field names for keys and '1' for each
|
|
|
|
# value.
|
|
|
|
def convert_fields_for_query(fields)
|
|
|
|
case fields
|
|
|
|
when String, Symbol
|
|
|
|
{fields => 1}
|
|
|
|
when Array
|
|
|
|
return nil if fields.length.zero?
|
|
|
|
returning({}) do |hash|
|
|
|
|
fields.each { |field| hash[field] = 1 }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Set query selector hash. If the selector is a Code or String object,
|
|
|
|
# the selector will be used in a $where clause.
|
|
|
|
# See http://www.mongodb.org/display/DOCS/Server-side+Code+Execution
|
|
|
|
def convert_selector_for_query(selector)
|
2009-11-04 22:46:15 +00:00
|
|
|
case selector
|
|
|
|
when Hash
|
|
|
|
selector
|
|
|
|
when nil
|
|
|
|
{}
|
|
|
|
when String
|
2009-10-22 18:10:12 +00:00
|
|
|
{"$where" => Code.new(selector)}
|
2009-11-04 22:46:15 +00:00
|
|
|
when Code
|
2009-10-22 18:10:12 +00:00
|
|
|
{"$where" => selector}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Returns true if the query contains order, explain, hint, or snapshot.
|
|
|
|
def query_contains_special_fields?
|
|
|
|
@order || @explain || @hint || @snapshot
|
|
|
|
end
|
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
def num_remaining
|
|
|
|
refill_via_get_more if @cache.length == 0
|
|
|
|
@cache.length
|
|
|
|
end
|
2008-11-22 01:00:51 +00:00
|
|
|
|
2009-08-21 15:03:56 +00:00
|
|
|
# Internal method, not for general use. Return +true+ if there are
|
2009-10-22 18:10:12 +00:00
|
|
|
# more records to retrieve. This methods does not check @limit;
|
2009-09-16 21:52:41 +00:00
|
|
|
# #each is responsible for doing that.
|
2009-08-21 15:03:56 +00:00
|
|
|
def more?
|
|
|
|
num_remaining > 0
|
|
|
|
end
|
2008-11-22 01:00:51 +00:00
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
def refill_via_get_more
|
2009-10-20 19:44:46 +00:00
|
|
|
return if send_query_if_needed || @cursor_id.zero?
|
2009-11-04 22:46:15 +00:00
|
|
|
message = ByteBuffer.new
|
|
|
|
# Reserved.
|
|
|
|
message.put_int(0)
|
2009-10-20 19:44:46 +00:00
|
|
|
|
2009-11-04 22:46:15 +00:00
|
|
|
# DB name.
|
|
|
|
db_name = @admin ? 'admin' : @db.name
|
|
|
|
BSON.serialize_cstr(message, "#{db_name}.#{@collection.name}")
|
2009-10-20 19:44:46 +00:00
|
|
|
|
2009-11-04 22:46:15 +00:00
|
|
|
# Number of results to return; db decides for now.
|
|
|
|
message.put_int(0)
|
2009-10-20 19:44:46 +00:00
|
|
|
|
2009-11-04 22:46:15 +00:00
|
|
|
# Cursor id.
|
|
|
|
message.put_long(@cursor_id)
|
2009-11-23 20:20:05 +00:00
|
|
|
results, @n_received, @cursor_id = @connection.receive_message_with_operation(Mongo::Constants::OP_GET_MORE, message, "cursor.get_more()", @socket)
|
2009-11-04 22:46:15 +00:00
|
|
|
@cache += results
|
2009-10-21 14:11:33 +00:00
|
|
|
close_cursor_if_query_complete
|
2009-08-20 14:50:48 +00:00
|
|
|
end
|
2008-11-22 01:00:51 +00:00
|
|
|
|
2009-11-23 23:09:13 +00:00
|
|
|
# Run query the first time we request an object from the wire
|
2009-08-20 14:50:48 +00:00
|
|
|
def send_query_if_needed
|
|
|
|
if @query_run
|
|
|
|
false
|
|
|
|
else
|
2009-11-02 20:04:06 +00:00
|
|
|
message = construct_query_message
|
2009-11-23 20:20:05 +00:00
|
|
|
results, @n_received, @cursor_id = @connection.receive_message_with_operation(Mongo::Constants::OP_QUERY, message,
|
|
|
|
(query_log_message if @connection.logger), @socket)
|
2009-11-04 22:46:15 +00:00
|
|
|
@cache += results
|
|
|
|
@query_run = true
|
2009-10-21 14:11:33 +00:00
|
|
|
close_cursor_if_query_complete
|
2009-08-20 14:50:48 +00:00
|
|
|
true
|
2008-11-22 01:00:51 +00:00
|
|
|
end
|
|
|
|
end
|
2009-08-20 14:50:48 +00:00
|
|
|
|
2009-11-02 20:04:06 +00:00
|
|
|
def construct_query_message
|
2009-10-20 19:44:46 +00:00
|
|
|
message = ByteBuffer.new
|
2009-10-22 18:10:12 +00:00
|
|
|
message.put_int(query_opts)
|
2009-10-20 19:44:46 +00:00
|
|
|
db_name = @admin ? 'admin' : @db.name
|
|
|
|
BSON.serialize_cstr(message, "#{db_name}.#{@collection.name}")
|
2009-10-22 18:10:12 +00:00
|
|
|
message.put_int(@skip)
|
|
|
|
message.put_int(@limit)
|
|
|
|
selector = @selector
|
|
|
|
if query_contains_special_fields?
|
|
|
|
selector = selector_with_special_query_fields
|
2009-10-20 19:44:46 +00:00
|
|
|
end
|
2009-11-12 19:48:49 +00:00
|
|
|
message.put_array(BSON_SERIALIZER.serialize(selector, false).unpack("C*"))
|
|
|
|
message.put_array(BSON_SERIALIZER.serialize(@fields, false).unpack("C*")) if @fields
|
2009-10-20 19:44:46 +00:00
|
|
|
message
|
|
|
|
end
|
|
|
|
|
2009-11-02 20:04:06 +00:00
|
|
|
def query_log_message
|
2009-11-02 20:50:16 +00:00
|
|
|
"#{@admin ? 'admin' : @db.name}.#{@collection.name}.find(#{@selector.inspect}, #{@fields ? @fields.inspect : '{}'})" +
|
2009-11-02 20:04:06 +00:00
|
|
|
"#{@skip != 0 ? ('.skip(' + @skip.to_s + ')') : ''}#{@limit != 0 ? ('.limit(' + @limit.to_s + ')') : ''}"
|
|
|
|
end
|
|
|
|
|
2009-10-22 18:10:12 +00:00
|
|
|
def selector_with_special_query_fields
|
2009-10-20 19:44:46 +00:00
|
|
|
sel = OrderedHash.new
|
2009-10-22 18:10:12 +00:00
|
|
|
sel['query'] = @selector
|
|
|
|
sel['orderby'] = formatted_order_clause if @order
|
|
|
|
sel['$hint'] = @hint if @hint && @hint.length > 0
|
|
|
|
sel['$explain'] = true if @explain
|
|
|
|
sel['$snapshot'] = true if @snapshot
|
2009-10-20 19:44:46 +00:00
|
|
|
sel
|
|
|
|
end
|
|
|
|
|
2009-10-22 18:10:12 +00:00
|
|
|
def formatted_order_clause
|
|
|
|
case @order
|
2009-11-23 23:09:13 +00:00
|
|
|
when String, Symbol then string_as_sort_parameters(@order)
|
|
|
|
when Array then array_as_sort_parameters(@order)
|
2009-10-20 19:44:46 +00:00
|
|
|
else
|
2009-11-23 23:09:13 +00:00
|
|
|
raise InvalidSortValueError, "Illegal sort clause, '#{@order.class.name}'; must be of the form " +
|
|
|
|
"[['field1', '(ascending|descending)'], ['field2', '(ascending|descending)']]"
|
2009-10-20 19:44:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-20 14:50:48 +00:00
|
|
|
def to_s
|
2009-09-30 14:49:08 +00:00
|
|
|
"DBResponse(flags=#@result_flags, cursor_id=#@cursor_id, start=#@starting_from)"
|
2009-08-20 14:50:48 +00:00
|
|
|
end
|
2009-09-05 18:25:49 +00:00
|
|
|
|
2009-10-21 14:11:33 +00:00
|
|
|
def close_cursor_if_query_complete
|
2009-10-22 18:10:12 +00:00
|
|
|
close if @limit > 0 && @n_received >= @limit
|
2009-10-21 14:11:33 +00:00
|
|
|
end
|
|
|
|
|
2009-09-05 18:25:49 +00:00
|
|
|
def check_modifiable
|
|
|
|
if @query_run || @closed
|
|
|
|
raise InvalidOperation, "Cannot modify the query once it has been run or closed."
|
|
|
|
end
|
|
|
|
end
|
2008-11-22 01:00:51 +00:00
|
|
|
end
|
|
|
|
end
|