Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unprepared statements reading strings is broken #36

Closed
benoist opened this issue Jul 13, 2017 · 0 comments
Closed

Unprepared statements reading strings is broken #36

benoist opened this issue Jul 13, 2017 · 0 comments

Comments

@benoist
Copy link
Contributor

benoist commented Jul 13, 2017

I was trying to reduce the amount of prepared statements in order to work around this issue
crystal-lang/crystal-db#60

I ran into bugs with using unprepared statements. I added the following spec and it fails.
If you change db.unprepared.query to db.query it uses a prepared statement and that works fine.

  it "allows unprepared statement queries" do |db|
    db.exec %(create table if not exists a (i int not null, str text not null);)
    db.exec %(insert into a (i, str) values (23, "bai bai");)

    2.times do |i|
      DB.open db.uri do |db|
        begin
          db.unprepared.query("SELECT i, str FROM a WHERE i = 23") do |rs|
            rs.each do
              rs.read(Int32).should eq 23
              rs.read(String).should eq "bai bai"
            end
          end
        rescue e
          fail("Expected no exception, but got \"#{e.message}\"")
        end
      end
    end
  end
Failures:

  1) as a db allows unprepared statement queries
     Failure/Error: fail("Expected no exception, but got \"#{e.message}\"")

       Expected no exception, but got "Expected: "bai bai"
            got: "\u0007b""

     # spec/db_spec.cr:194
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant