Update vendored Sqlite3-ruby to 1.3.0

Also, some tweaks to Maruku.
This commit is contained in:
Jacques Distler 2010-06-10 22:42:33 -05:00
parent 9a80cacc34
commit 4f8759cdf3
55 changed files with 3071 additions and 8028 deletions

View file

@ -31,46 +31,22 @@ module SQLite3
# Create a new ResultSet attached to the given database, using the
# given sql text.
def initialize( db, stmt )
@db = db
@driver = @db.driver
def initialize db, stmt
@db = db
@stmt = stmt
commence
end
# A convenience method for compiling the virtual machine and stepping
# to the first row of the result set.
def commence
result = @driver.step( @stmt.handle )
if result == Constants::ErrorCode::ERROR
@driver.reset( @stmt.handle )
end
check result
@first_row = true
end
private :commence
def check( result )
@eof = ( result == Constants::ErrorCode::DONE )
found = ( result == Constants::ErrorCode::ROW )
Error.check( result, @db ) unless @eof || found
end
private :check
# Reset the cursor, so that a result set which has reached end-of-file
# can be rewound and reiterated.
def reset( *bind_params )
@stmt.must_be_open!
@stmt.reset!(false)
@driver.reset( @stmt.handle )
@stmt.reset!
@stmt.bind_params( *bind_params )
@eof = false
commence
end
# Query whether the cursor has reached the end of the result set or not.
def eof?
@eof
@stmt.done?
end
# Obtain the next row from the cursor. If there are no more rows to be
@ -87,69 +63,39 @@ module SQLite3
# For hashes, the column names are the keys of the hash, and the column
# types are accessible via the +types+ property.
def next
return nil if @eof
row = @stmt.step
return nil if @stmt.done?
@stmt.must_be_open!
unless @first_row
result = @driver.step( @stmt.handle )
check result
if @db.type_translation
row = @stmt.types.zip(row).map do |type, value|
@db.translator.translate( type, value )
end
end
@first_row = false
unless @eof
row = []
@driver.data_count( @stmt.handle ).times do |column|
type = @driver.column_type( @stmt.handle, column )
if type == Constants::ColumnType::TEXT
row << @driver.column_text( @stmt.handle, column )
elsif type == Constants::ColumnType::NULL
row << nil
elsif type == Constants::ColumnType::BLOB
row << @driver.column_blob( @stmt.handle, column )
else
row << @driver.column_text( @stmt.handle, column )
end
end
if @db.type_translation
row = @stmt.types.zip( row ).map do |type, value|
@db.translator.translate( type, value )
end
end
if @db.results_as_hash
new_row = HashWithTypes[ *( @stmt.columns.zip( row ).to_a.flatten ) ]
row.each_with_index { |value,idx|
value.taint
new_row[idx] = value
}
row = new_row
if @db.results_as_hash
new_row = HashWithTypes[*@stmt.columns.zip(row).flatten]
row.each_with_index { |value,idx|
new_row[idx] = value
}
row = new_row
else
if row.respond_to?(:fields)
row = ArrayWithTypes.new(row)
else
if row.respond_to?(:fields)
row = ArrayWithTypes.new(row)
else
row = ArrayWithTypesAndFields.new(row)
end
row.fields = @stmt.columns
row.each { |column| column.taint }
row = ArrayWithTypesAndFields.new(row)
end
row.types = @stmt.types
return row
row.fields = @stmt.columns
end
nil
row.types = @stmt.types
row
end
# Required by the Enumerable mixin. Provides an internal iterator over the
# rows of the result set.
def each
while row=self.next
yield row
def each( &block )
while node = self.next
yield node
end
end