Kuzu::

PreparedStatement class

A parameterized query which can avoid planning the same query for repeated execution

Public Instance Methods

bind( **variable_map )

Bind the variables in the specified variable_map to the statement.

# File lib/kuzu/prepared_statement.rb, line 35
def    bind( **variable_map )
        variable_map.each do |name, value|
                self.bind_variable( name, value )
        end
end
bind_variable( name, value )

Binds the given value to the given parameter name in the prepared statement

static VALUE
rkuzu_prepared_statement_bind_variable( VALUE self, VALUE name, VALUE value )
{
        rkuzu_prepared_statement *stmt = CHECK_PREPARED_STATEMENT( self );
        VALUE name_string = rb_funcall( name, rb_intern("to_s"), 0 );
        const char *name_s = StringValueCStr( name_string );
        kuzu_value *null_value;

        switch (TYPE(value)) {
                case T_TRUE:
                case T_FALSE:
                        kuzu_prepared_statement_bind_bool( &stmt->statement, name_s, RTEST(value) );
                        break;

                // fallthrough
                case T_FLOAT:
                        kuzu_prepared_statement_bind_float( &stmt->statement, name_s, NUM2DBL(value) );
                        break;

                case T_BIGNUM:
                        kuzu_prepared_statement_bind_int64( &stmt->statement, name_s, NUM2LL(value) );
                        break;

                case T_FIXNUM:
                        kuzu_prepared_statement_bind_int32( &stmt->statement, name_s, NUM2INT(value) );
                        break;

                case T_SYMBOL:
                        rb_notimplement();
                        break; // not reached

                case T_NIL:
                        null_value = kuzu_value_create_null();
                        kuzu_prepared_statement_bind_value( &stmt->statement, name_s, null_value );
                        kuzu_value_destroy( null_value );
                        break;

                case T_OBJECT:
                case T_CLASS:
                case T_MODULE:
                case T_REGEXP:
                case T_ARRAY:
                case T_HASH:
                case T_STRUCT:
                case T_COMPLEX:
                case T_RATIONAL:
                case T_FILE:
                case T_DATA:
                case T_STRING:
                default:
                        rkuzu_bind_string( stmt, name_s, value );
                        break;

                        // kuzu_prepared_statement_bind_int8
                        // kuzu_prepared_statement_bind_int16
                        // kuzu_prepared_statement_bind_uint64
                        // kuzu_prepared_statement_bind_uint32
                        // kuzu_prepared_statement_bind_uint16
                        // kuzu_prepared_statement_bind_uint8

                        // kuzu_prepared_statement_bind_double
                        // kuzu_prepared_statement_bind_date
                        // kuzu_prepared_statement_bind_timestamp_ns
                        // kuzu_prepared_statement_bind_timestamp_sec
                        // kuzu_prepared_statement_bind_timestamp_tz
                        // kuzu_prepared_statement_bind_timestamp_ms
                        // kuzu_prepared_statement_bind_timestamp
                        // kuzu_prepared_statement_bind_interval
                        // kuzu_prepared_statement_bind_value
        }

        return Qtrue;
}
connection → conn

Return the Kuzu::Connection used to run this statement.

static VALUE
rkuzu_prepared_statement_connection( VALUE self )
{
        rkuzu_prepared_statement *statement_s = rkuzu_get_prepared_statement( self );
        return statement_s->connection;
}
execute( **bound_variables, &block )

Execute the statement against its connection and return a Kuzu::Result. If a block is supplied, the result will be passed to it instead, then finished automatically, and the return value of the block returned instead.

# File lib/kuzu/prepared_statement.rb, line 19
def execute( **bound_variables, &block )
        self.bind( **bound_variables )
        result = self._execute
        return Kuzu::Result.wrap_block_result( result, &block )
end
execute!( **bound_variables )

Execute the statement against its connection and return true if it succeeded.

# File lib/kuzu/prepared_statement.rb, line 28
def execute!( **bound_variables )
        self.bind( **bound_variables )
        return self._execute!
end
query → string

Return the query string used to build this statement.

static VALUE
rkuzu_prepared_statement_query( VALUE self )
{
        rkuzu_prepared_statement *statement_s = rkuzu_get_prepared_statement( self );
        return statement_s->query;
}
success? → true or false

Returns true if the query was prepared successfully.

static VALUE
rkuzu_prepared_statement_success_p( VALUE self )
{
        rkuzu_prepared_statement *stmt = CHECK_PREPARED_STATEMENT( self );

        if ( kuzu_prepared_statement_is_success(&stmt->statement) ) {
                return Qtrue;
        } else {
                return Qfalse;
        }
}