Sha256: 4ec8eb2019e1f6cafc92d57db2f49b254880e0cc94cfbc3ba462f81560f8eea0
Contents?: true
Size: 1.57 KB
Versions: 7
Compression:
Stored size: 1.57 KB
Contents
require 'date' module DuckDB # The DuckDB::PreparedStatement encapsulates connection with DuckDB prepared # statement. # # require 'duckdb' # db = DuckDB::Database.open('duckdb_database') # con = db.connect # sql ='SELECT name, email FROM users WHERE email = ?' # stmt = PreparedStatement.new(con, sql) # stmt.bind(1, 'email@example.com') # stmt.execute class PreparedStatement # binds i-th parameter with SQL prepared statement. # The first argument is index of parameter. The index of first parameter is # 1 not 0. # The second argument value is the value of prepared statement parameter. # # require 'duckdb' # db = DuckDB::Database.open('duckdb_database') # con = db.connect # sql ='SELECT name, email FROM users WHERE email = ?' # stmt = PreparedStatement.new(con, sql) # stmt.bind(1, 'email@example.com') def bind(i, value) case value when NilClass respond_to?(:bind_null) ? bind_null(i) : rb_raise(DuckDB::Error, 'This bind method does not support nil value. Re-compile ruby-duckdb with DuckDB version >= 0.1.1') when Float bind_double(i, value) when Integer bind_int64(i, value) when String bind_varchar(i, value) when TrueClass, FalseClass bind_boolean(i, value) when Time bind_varchar(i, value.strftime('%Y-%m-%d %H:%M:%S.%N')) when Date bind_varchar(i, value.strftime('%Y-%m-%d')) else rb_raise(DuckDB::Error, "not supported type #{value} (value.class)") end end end end
Version data entries
7 entries across 7 versions & 1 rubygems