Sha256: ab59bee842cd686c52ab24bda61da56a9c8bea5535a605d1b6b0a76881da9c4b

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require "#{File.dirname(__FILE__)}/../spec_helper"

describe SQLTree::Node::InsertQuery do
  
  it "should parse an insert query without field list correctly" do
    insert = SQLTree::Node::InsertQuery["INSERT INTO table VALUES (1, 'two', 3+4, MD5('$ecret'))"]
    insert.table.should == SQLTree::Node::TableReference.new('table')
    insert.fields.should be_nil
    insert.values.should have(4).items
    insert.values[0].should == SQLTree::Node::Expression::Value.new(1)
    insert.values[1].should == SQLTree::Node::Expression::Value.new('two')
    insert.values[2].should be_kind_of(SQLTree::Node::Expression::BinaryOperator)
    insert.values[3].should be_kind_of(SQLTree::Node::Expression::FunctionCall)
  end
  
  it "should parse an insert query with field list" do
    insert = SQLTree::Node::InsertQuery['INSERT INTO table ("field1", "field2") VALUES (1, 2)']
    insert.table.should == SQLTree::Node::TableReference.new('table')
    insert.fields.should have(2).items
    insert.values.should have(2).items
    insert.fields[0].should == SQLTree::Node::Expression::Field.new('field1')
    insert.fields[1].should == SQLTree::Node::Expression::Field.new('field2')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sql_tree-0.1.1 spec/unit/insert_query_spec.rb