mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
introduce unprepared statements
* rename QueryMethods#prepare to QueryMethods#build * rename Connection#build_statement to Connection#build_prepared_statement * add Connection#build_unprepared_statement * add Connection #prepared and #unprepared dsl methods
This commit is contained in:
parent
73108c169e
commit
fe0ed55ef9
8 changed files with 118 additions and 39 deletions
|
@ -1,15 +1,25 @@
|
|||
require "./spec_helper"
|
||||
|
||||
describe DB::Statement do
|
||||
it "should prepare statements" do
|
||||
it "should build prepared statements" do
|
||||
with_dummy_connection do |cnn|
|
||||
cnn.prepare("the query").should be_a(DB::Statement)
|
||||
prepared = cnn.prepared("the query")
|
||||
prepared.should be_a(DB::Statement)
|
||||
prepared.as(DummyDriver::DummyStatement).prepared?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
it "should build unprepared statements" do
|
||||
with_dummy_connection do |cnn|
|
||||
prepared = cnn.unprepared("the query")
|
||||
prepared.should be_a(DB::Statement)
|
||||
prepared.as(DummyDriver::DummyStatement).prepared?.should be_false
|
||||
end
|
||||
end
|
||||
|
||||
it "should initialize positional params in query" do
|
||||
with_dummy_connection do |cnn|
|
||||
stmt = cnn.prepare("the query").as(DummyDriver::DummyStatement)
|
||||
stmt = cnn.prepared("the query").as(DummyDriver::DummyStatement)
|
||||
stmt.query "a", 1, nil
|
||||
stmt.params[0].should eq("a")
|
||||
stmt.params[1].should eq(1)
|
||||
|
@ -19,7 +29,7 @@ describe DB::Statement do
|
|||
|
||||
it "should initialize positional params in query with array" do
|
||||
with_dummy_connection do |cnn|
|
||||
stmt = cnn.prepare("the query").as(DummyDriver::DummyStatement)
|
||||
stmt = cnn.prepared("the query").as(DummyDriver::DummyStatement)
|
||||
stmt.query ["a", 1, nil]
|
||||
stmt.params[0].should eq("a")
|
||||
stmt.params[1].should eq(1)
|
||||
|
@ -29,7 +39,7 @@ describe DB::Statement do
|
|||
|
||||
it "should initialize positional params in exec" do
|
||||
with_dummy_connection do |cnn|
|
||||
stmt = cnn.prepare("the query").as(DummyDriver::DummyStatement)
|
||||
stmt = cnn.prepared("the query").as(DummyDriver::DummyStatement)
|
||||
stmt.exec "a", 1, nil
|
||||
stmt.params[0].should eq("a")
|
||||
stmt.params[1].should eq(1)
|
||||
|
@ -39,7 +49,7 @@ describe DB::Statement do
|
|||
|
||||
it "should initialize positional params in exec with array" do
|
||||
with_dummy_connection do |cnn|
|
||||
stmt = cnn.prepare("the query").as(DummyDriver::DummyStatement)
|
||||
stmt = cnn.prepared("the query").as(DummyDriver::DummyStatement)
|
||||
stmt.exec ["a", 1, nil]
|
||||
stmt.params[0].should eq("a")
|
||||
stmt.params[1].should eq(1)
|
||||
|
@ -49,7 +59,7 @@ describe DB::Statement do
|
|||
|
||||
it "should initialize positional params in scalar" do
|
||||
with_dummy_connection do |cnn|
|
||||
stmt = cnn.prepare("the query").as(DummyDriver::DummyStatement)
|
||||
stmt = cnn.prepared("the query").as(DummyDriver::DummyStatement)
|
||||
stmt.scalar "a", 1, nil
|
||||
stmt.params[0].should eq("a")
|
||||
stmt.params[1].should eq(1)
|
||||
|
@ -59,7 +69,7 @@ describe DB::Statement do
|
|||
|
||||
it "query with block should not close statement" do
|
||||
with_dummy_connection do |cnn|
|
||||
stmt = cnn.prepare "3,4 1,2"
|
||||
stmt = cnn.prepared "3,4 1,2"
|
||||
stmt.query
|
||||
stmt.closed?.should be_false
|
||||
end
|
||||
|
@ -68,7 +78,7 @@ describe DB::Statement do
|
|||
it "closing connection should close statement" do
|
||||
stmt = uninitialized DB::Statement
|
||||
with_dummy_connection do |cnn|
|
||||
stmt = cnn.prepare "3,4 1,2"
|
||||
stmt = cnn.prepared "3,4 1,2"
|
||||
stmt.query
|
||||
end
|
||||
stmt.closed?.should be_true
|
||||
|
@ -76,7 +86,7 @@ describe DB::Statement do
|
|||
|
||||
it "query with block should not close statement" do
|
||||
with_dummy_connection do |cnn|
|
||||
stmt = cnn.prepare "3,4 1,2"
|
||||
stmt = cnn.prepared "3,4 1,2"
|
||||
stmt.query do |rs|
|
||||
end
|
||||
stmt.closed?.should be_false
|
||||
|
@ -85,7 +95,7 @@ describe DB::Statement do
|
|||
|
||||
it "query should not close statement" do
|
||||
with_dummy_connection do |cnn|
|
||||
stmt = cnn.prepare "3,4 1,2"
|
||||
stmt = cnn.prepared "3,4 1,2"
|
||||
stmt.query do |rs|
|
||||
end
|
||||
stmt.closed?.should be_false
|
||||
|
@ -94,7 +104,7 @@ describe DB::Statement do
|
|||
|
||||
it "scalar should not close statement" do
|
||||
with_dummy_connection do |cnn|
|
||||
stmt = cnn.prepare "3,4 1,2"
|
||||
stmt = cnn.prepared "3,4 1,2"
|
||||
stmt.scalar
|
||||
stmt.closed?.should be_false
|
||||
end
|
||||
|
@ -102,7 +112,7 @@ describe DB::Statement do
|
|||
|
||||
it "exec should not close statement" do
|
||||
with_dummy_connection do |cnn|
|
||||
stmt = cnn.prepare "3,4 1,2"
|
||||
stmt = cnn.prepared "3,4 1,2"
|
||||
stmt.exec
|
||||
stmt.closed?.should be_false
|
||||
end
|
||||
|
@ -110,11 +120,11 @@ describe DB::Statement do
|
|||
|
||||
it "connection should cache statements by query" do
|
||||
with_dummy_connection do |cnn|
|
||||
rs = cnn.query "1, ?", 2
|
||||
rs = cnn.prepared.query "1, ?", 2
|
||||
stmt = rs.statement
|
||||
rs.close
|
||||
|
||||
rs = cnn.query "1, ?", 4
|
||||
rs = cnn.prepared.query "1, ?", 4
|
||||
rs.statement.should be(stmt)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue