mirror of
https://gitea.invidious.io/iv-org/shard-crystal-sqlite3.git
synced 2024-08-15 00:53:26 +00:00
Fix timestamp reading issue
Also adds a couple of basic tests for ResultSet Should fix #63
This commit is contained in:
parent
55b8399d7e
commit
6eb1002c24
3 changed files with 55 additions and 2 deletions
53
spec/result_set_spec.cr
Normal file
53
spec/result_set_spec.cr
Normal file
|
@ -0,0 +1,53 @@
|
|||
require "./spec_helper"
|
||||
|
||||
describe SQLite3::ResultSet do
|
||||
it "reads integer data types" do
|
||||
with_db do |db|
|
||||
db.exec "CREATE TABLE test_table(test_int integer);"
|
||||
db.exec "INSERT INTO test_table(test_int) values(?);", 42
|
||||
db.query("SELECT test_int FROM test_table") do |rs|
|
||||
rs.each do
|
||||
rs.read.should be_a(Int64)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "reads string data types" do
|
||||
with_db do |db|
|
||||
db.exec "CREATE TABLE test_table(test_text text);"
|
||||
db.exec "INSERT INTO test_table(test_text) VALUES (?), (?)", "abc", "123"
|
||||
db.query("SELECT test_text FROM test_table") do |rs|
|
||||
rs.each do
|
||||
r = rs.read
|
||||
r.should be_a(String)
|
||||
r.should match(/abc|123/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "reads time data types" do
|
||||
with_db do |db|
|
||||
db.exec "CREATE TABLE test_table(test_date datetime);"
|
||||
db.exec "INSERT INTO test_table(test_date) values(current_timestamp);"
|
||||
db.query("SELECT test_date FROM test_table") do |rs|
|
||||
rs.each do
|
||||
rs.read(Time).should be_a(Time)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "reads time stored in text fields, too" do
|
||||
with_db do |db|
|
||||
db.exec "CREATE TABLE test_table(test_date text);"
|
||||
db.exec "INSERT INTO test_table(test_date) values(current_timestamp);"
|
||||
db.query("SELECT test_date FROM test_table") do |rs|
|
||||
rs.each do
|
||||
rs.read(Time).should be_a(Time)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,7 +2,7 @@ require "db"
|
|||
require "./sqlite3/**"
|
||||
|
||||
module SQLite3
|
||||
DATE_FORMAT = "%F %H:%M:%S.%L"
|
||||
DATE_FORMAT = "%F %H:%M:%S"
|
||||
|
||||
# :nodoc:
|
||||
TIME_ZONE = Time::Location::UTC
|
||||
|
|
|
@ -70,7 +70,7 @@ class SQLite3::Statement < DB::Statement
|
|||
end
|
||||
|
||||
private def bind_arg(index, value : Time)
|
||||
bind_arg(index, value.in(SQLite3::TIME_ZONE).to_s(SQLite3::DATE_FORMAT))
|
||||
bind_arg(index, value.in(SQLite3::TIME_ZONE).to_s(SQLite3::DATE_FORMAT + ".%L"))
|
||||
end
|
||||
|
||||
private def bind_arg(index, value)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue