You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently we are able to insert Bytes but when reading must specify read(String) not read(Bytes) as there will be an error otherwise. I believe it might be better to support reading a slice for these fields.
DB.open "mysql://root@localhost/test" do |db|
db.exec "drop table if exists contacts"
db.exec "create table contacts (name varchar(30), age int, btest VARBINARY(16))"
db.exec "insert into contacts values (?, ?, ?)", "John Doe", 30, Bytes.new(3, 90_u8)
args = [] of DB::Any
args << "Sarah"
args << 33
args << Bytes.new(3, 90_u8)
db.exec "insert into contacts values (?, ?, ?)", args
puts "max age:"
puts db.scalar "select max(age) from contacts" # => 33
puts "contacts:"
db.query "select name, age, btest from contacts order by age desc" do |rs|
puts "#{rs.column_name(0)} (#{rs.column_name(1)}) (#{rs.column_name(2)})"
# => name (age)
rs.each do
puts "#{rs.read(String)} (#{rs.read(Int32)}) (#{rs.read(Bytes)})"
# => Sarah (33) (ZZZ)
# => John Doe (30) (ZZZ)
end
end
end
max age:
33
contacts:
name (age) (btest)
MySql::ResultSet#read returned a String. A Slice(UInt8) was expected. (Exception)
from lib/db/src/db/result_set.cr:0:9 in 'read'
from src/dbtest.cr:28:57 in '__crystal_main'
from /usr/local/Cellar/crystal-lang/0.24.2_1/src/crystal/main.cr:11:3 in '_crystal_main'
from /usr/local/Cellar/crystal-lang/0.24.2_1/src/crystal/main.cr:112:5 in 'main_user_code'
from /usr/local/Cellar/crystal-lang/0.24.2_1/src/crystal/main.cr:101:7 in 'main'
from /usr/local/Cellar/crystal-lang/0.24.2_1/src/crystal/main.cr:135:3 in 'main'
The text was updated successfully, but these errors were encountered:
crash2burn
added a commit
to crash2burn/crystal-mysql
that referenced
this issue
Jun 12, 2018
Currently we are able to insert
Bytes
but when reading must specifyread(String)
notread(Bytes)
as there will be an error otherwise. I believe it might be better to support reading a slice for these fields.The text was updated successfully, but these errors were encountered: