Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spec cleanup, put in some more test cases to clean up coverage
20080519004832-2f820-fea50b9a97a30e145334c525b47bf60680903b95.gz
- Loading branch information
1 parent
f611057
commit ce2bafc
Showing
7 changed files
with
139 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#-- | ||
# Copyright (c) 2008 Jeremy Hinegardner | ||
# All rights reserved. See LICENSE and/or COPYING for details. | ||
#++ | ||
|
||
module Amalgalite | ||
# | ||
# abstrace of the meta informationa about 1 Index | ||
# | ||
class Index | ||
attr_reader :name | ||
attr_reader :sql | ||
attr_accessor :table | ||
|
||
def initialize( name, sql, table ) | ||
@name = name | ||
@sql = sql | ||
@table = table | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#-- | ||
# Copyright (c) 2008 Jeremy Hinegardner | ||
# All rights reserved. See LICENSE and/or COPYING for details. | ||
#++ | ||
|
||
require 'amalgalite/table' | ||
require 'amalgalite/index' | ||
|
||
module Amalgalite | ||
# | ||
# An object view of the schema in the SQLite database. If the schema changes | ||
# after this class is created, it has no knowledge of that. | ||
# | ||
class Schema | ||
|
||
attr_reader :catalog | ||
attr_reader :schema | ||
|
||
def initialize( db, catalog = 'main', schema = 'sqlite') | ||
@db = db | ||
@catalog = catalog | ||
@schema = schema | ||
|
||
load_schema! | ||
end | ||
|
||
# | ||
# load the schema from the database | ||
def load_schema! | ||
load_tables | ||
load_views | ||
end | ||
|
||
## | ||
# load all the tables | ||
# | ||
def load_tables | ||
@tables = {} | ||
@db.execute("SELECT tbl_name, sql FROM sqlite_master WHERE type = 'table'") do |table_info| | ||
table = Amalgalite::Table.new( table_info['name'], table_info['sql'] ) | ||
table.columns = @db.pragma "table_info( #{table.name })" | ||
|
||
@db.execute("SELECT name, sql FROM sqlite_master WHERE type ='index' and tbl_name = @name") do |idx_info| | ||
table.indexes << Amalgalite::Index.new( idx_info['name'], idx_info['sql'], table ) | ||
end | ||
@tables[table.name] = table | ||
end | ||
@tables | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#-- | ||
# Copyright (c) 2008 Jeremy Hinegardner | ||
# All rights reserved. See LICENSE and/or COPYING for details. | ||
#++ | ||
|
||
module Amalgalite | ||
# | ||
# abstrace of the meta informationa bout 1 table | ||
# | ||
class Table | ||
attr_reader :name | ||
attr_reader :sql | ||
attr_accessor :indexes | ||
|
||
def initialize( name, sql ) | ||
@name = name | ||
@sql = sql | ||
@indexes = [] | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'rubygems' | ||
require 'spec' | ||
|
||
$: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib")) | ||
require 'amalgalite' | ||
require 'amalgalite/schema' | ||
|
||
describe Amalgalite::Schema do | ||
before(:each) do | ||
@schema = IO.read( SpecInfo.test_schema_file ) | ||
@iso_db_file = SpecInfo.make_iso_db | ||
@iso_db = Amalgalite::Database.new( SpecInfo.make_iso_db ) | ||
end | ||
|
||
after(:each) do | ||
File.unlink SpecInfo.test_db if File.exist?( SpecInfo.test_db ) | ||
@iso_db.close | ||
File.unlink @iso_db_file if File.exist?( @iso_db_file ) | ||
end | ||
|
||
it "loads the schema of a database" do | ||
schema = @iso_db.schema | ||
schema.tables.size.should == 2 | ||
end | ||
|
||
end |