Skip to content

Commit

Permalink
Tweaked log output to include parameters, removed log files from repo…
Browse files Browse the repository at this point in the history
…sitory, and added spec for in-clause based queries.
  • Loading branch information
sam committed Mar 27, 2008
1 parent d4fc4b9 commit 5ee7e06
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
*.log
log/*
doc
cov
pkg
Expand Down
7 changes: 6 additions & 1 deletion environment.rb
Expand Up @@ -16,7 +16,12 @@

# Determine log path.
ENV['_'] =~ /(\w+)/
DataMapper::Logger.new(__DIR__ + "log/#{$1}.log", 0)
log_path = __DIR__ + "log/#{$1 == 'opt' ? 'spec' : $1}.log"

FileUtils::mkdir_p(File.dirname(log_path))
FileUtils::rm(log_path) if File.exists?(log_path)

DataMapper::Logger.new(log_path, 0)
at_exit { DataMapper.logger.close }

Pathname.glob(__DIR__ + 'spec/models/*.rb').sort.each { |path| load path }
Expand Down
5 changes: 3 additions & 2 deletions lib/data_mapper/adapters/data_objects_adapter.rb
Expand Up @@ -165,13 +165,14 @@ def read_set(repository, query)
set = LoadedSet.new(repository, query.resource, properties_with_indexes)

sql = query_read_statement(query)
DataMapper.logger.debug { sql }
parameters = query.parameters
DataMapper.logger.debug { "QUERY: '#{sql}' PARAMETERS: #{parameters.inspect}" }

begin
connection = create_connection
command = connection.create_command(sql)
command.set_types(properties.map { |property| property.type })
reader = command.execute_reader(*query.parameters)
reader = command.execute_reader(*parameters)

while(reader.next!)
set.materialize!(reader.values, query.reload?)
Expand Down
2 changes: 0 additions & 2 deletions log/spec.log

This file was deleted.

34 changes: 23 additions & 11 deletions spec/integration/sqlite3_adapter_spec.rb
Expand Up @@ -213,16 +213,15 @@ class BankCustomer

describe "query" do



before do

@adapter = repository(:sqlite3).adapter
@adapter.execute(<<-EOS.compress_lines) rescue nil
CREATE TABLE "sail_boats" (
"id" INTEGER PRIMARY KEY,
"name" VARCHAR(50),
"port" VARCHAR(50)
"port" VARCHAR(50),
"notes" VARCHAR(50)
)
EOS

Expand All @@ -231,13 +230,15 @@ class SailBoat
property :id, Fixnum, :serial => true
property :name, String
property :port, String
property :notes, String, :lazy => true

class << self
def property_by_name(name)
properties(repository.name).detect do |property|
property.name == name
end
end
end
end
end

repository(:sqlite3).save(SailBoat.new(:id => 1, :name => "A", :port => "C"))
Expand Down Expand Up @@ -266,17 +267,20 @@ def property_by_name(name)
result = repository(:sqlite3).all(SailBoat,{:order => [
SailBoat.property_by_name(:name),
DataMapper::Query::Direction.new(SailBoat.property_by_name(:port), :asc)
]})
]})
result[0].id.should == 1
end

end

it "should lazy load" do
result = repository(:sqlite3).all(SailBoat,{})
result[0].id.should == 1
puts result[0].id
puts result[0].notes
end

after do
@adapter.execute('DROP TABLE "sail_boats"')
end




end

Expand Down Expand Up @@ -328,7 +332,15 @@ class SerialFinderSpec
sfs.instance_variables.should_not include('@sample')
sfs.sample.should_not be_nil
end


it "should translate an Array to an IN clause" do
ids = repository(:sqlite3).all(SerialFinderSpec, { :limit => 100 }).map(&:id)
results = repository(:sqlite3).all(SerialFinderSpec, { :id => ids })

results.size.should == 100
results.map(&:ids).should == ids
end

after do
@adapter.execute('DROP TABLE "serial_finder_specs"')
end
Expand Down

0 comments on commit 5ee7e06

Please sign in to comment.