Class: Cassandra::Statements::Prepared
- Inherits:
-
Object
- Object
- Cassandra::Statements::Prepared
- Includes:
- Cassandra::Statement
- Defined in:
- lib/cassandra/statements/prepared.rb
Overview
A prepared statement is created by calling Cassandra::Session#prepare or Cassandra::Session#prepare_async.
Instance Attribute Summary collapse
-
#cql ⇒ String
readonly
Original cql used to prepare this statement.
Instance Method Summary collapse
-
#bind(args = nil) ⇒ Cassandra::Statements::Bound
Creates a statement bound with specific arguments.
-
#execution_info ⇒ Cassandra::Execution::Info
Execution info for PREPARE request.
-
#inspect ⇒ String
A CLI-friendly prepared statement representation.
Methods included from Cassandra::Statement
Instance Attribute Details
#cql ⇒ String (readonly)
Returns original cql used to prepare this statement.
27 28 29 |
# File 'lib/cassandra/statements/prepared.rb', line 27 def cql @cql end |
Instance Method Details
#bind(args = nil) ⇒ Cassandra::Statements::Bound
Creates a statement bound with specific arguments
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/cassandra/statements/prepared.rb', line 78 def bind(args = nil) if args Util.assert_instance_of_one_of([::Array, ::Hash], args) do "args must be an Array or a Hash, #{args.inspect} given" end else args = EMPTY_LIST end params = [] param_types = [] if args.is_a?(::Hash) .each do |(_, _, name, type)| name = name.to_sym unless args.key?(name) value = args.fetch(name, NOT_SET) if NOT_SET.eql?(value) if .protocol_version < 4 raise ::ArgumentError, "argument #{name.inspect} it not present in #{args.inspect}" end else Util.assert_type(type, value) do "argument for #{name.inspect} must be #{type}, #{value} given" end end params << value param_types << type end else Util.assert_equal(.size, args.size) do "expecting exactly #{@params_metadata.size} bind parameters, " \ "#{args.size} given" end .zip(args) do |(_, _, name, type), value| if NOT_SET.eql?(value) if .protocol_version < 4 raise ::ArgumentError, "argument #{name.inspect} it not present in #{args.inspect}" end else Util.assert_type(type, value) do "argument for #{name.inspect} must be #{type}, #{value} given" end end params << value param_types << type end end # params_metadata is an array of column-specs; each column-spec is an array # of keyspace, tablename, other stuff. We only care about the keyspace name. # See read_prepared_metadata_v4 in coder.rb for more details. keyspace_name = .first.first unless .empty? partition_key = create_partition_key(params) Bound.new(@id, @cql, param_types, , params, keyspace_name, partition_key, @idempotent) end |
#execution_info ⇒ Cassandra::Execution::Info
Returns execution info for PREPARE request.
149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/cassandra/statements/prepared.rb', line 149 def execution_info @info ||= Execution::Info.new(@payload, @warnings, @keyspace, @statement, , @hosts, @consistency, @retries, @trace_id ? Execution::Trace.new(@trace_id, @client, .load_balancing_policy) : nil) end |
#inspect ⇒ String
Returns a CLI-friendly prepared statement representation.
169 170 171 |
# File 'lib/cassandra/statements/prepared.rb', line 169 def inspect "#<#{self.class.name}:0x#{object_id.to_s(16)} @cql=#{@cql.inspect}>" end |