amalgalite 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,8 @@ module Amalgalite
8
8
  # a class representing the meta information about an SQLite table
9
9
  #
10
10
  class Table
11
+ # the schema object the table is associated with
12
+ attr_accessor :schema
11
13
 
12
14
  # the table name
13
15
  attr_reader :name
@@ -27,7 +29,7 @@ module Amalgalite
27
29
  @name = name
28
30
  @sql = sql
29
31
  @indexes = []
30
- @columns = []
32
+ @columns = {}
31
33
  end
32
34
  end
33
35
  end
@@ -0,0 +1,2 @@
1
+ require 'amalgalite/taps/console'
2
+ require 'amalgalite/taps/io'
@@ -40,7 +40,19 @@ module Amalgalite::TypeMaps
40
40
  sql_types.each { |t| @sql_to_method[t] = method }
41
41
  end
42
42
  end
43
- return @sql_to_method[sql_type]
43
+ return_method = @sql_to_method[sql_type]
44
+
45
+ # the straight lookup didn't work, try iterating through the types and
46
+ # see what is found
47
+ unless return_method
48
+ @sql_to_method.each_pair do |sql, method|
49
+ if sql_type.index(sql) then
50
+ return_method = method
51
+ break
52
+ end
53
+ end
54
+ end
55
+ return return_method
44
56
  end
45
57
  end
46
58
 
@@ -77,6 +89,8 @@ module Amalgalite::TypeMaps
77
89
  return value
78
90
  when NilClass
79
91
  return value
92
+ when Amalgalite::Blob
93
+ return value
80
94
  when String
81
95
  if declared_type then
82
96
  conversion_method = DefaultMap.sql_to_method( declared_type.downcase )
@@ -8,7 +8,7 @@ module Amalgalite
8
8
  module Version
9
9
 
10
10
  MAJOR = 0
11
- MINOR = 1
11
+ MINOR = 2
12
12
  BUILD = 0
13
13
 
14
14
  #
@@ -8,6 +8,8 @@ module Amalgalite
8
8
  # a class representing the meta information about an SQLite view
9
9
  #
10
10
  class View
11
+ # the schame this view is assciated with
12
+ attr_accessor :schema
11
13
 
12
14
  # the table name
13
15
  attr_reader :name
data/spec/blob_spec.rb ADDED
@@ -0,0 +1,81 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ $: << File.expand_path(File.join(File.dirname(__FILE__),"..","lib"))
5
+ require 'amalgalite'
6
+
7
+ describe Amalgalite::Blob do
8
+ DATA_FILE = File.expand_path( File.join( File.dirname(__FILE__), "iso-3166-country.txt" ) )
9
+ before(:each) do
10
+ @blob_db_name = File.join(File.dirname( __FILE__ ), "blob.db")
11
+ File.unlink @blob_db_name if File.exist?( @blob_db_name )
12
+ @db = Amalgalite::Database.new( @blob_db_name )
13
+ @schema_sql = <<-SQL
14
+ CREATE TABLE blobs(
15
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
16
+ name VARCHAR(128) NOT NULL UNIQUE,
17
+ data BLOB );
18
+ SQL
19
+ @db.execute( @schema_sql )
20
+ @junk_file = File.join( File.dirname(__FILE__), "test_output")
21
+ end
22
+
23
+ after(:each) do
24
+ @db.close
25
+ File.unlink @blob_db_name if File.exist?( @blob_db_name )
26
+ File.unlink @junk_file if File.exist?( @junk_file )
27
+ end
28
+
29
+ { :file => DATA_FILE,
30
+ :string => IO.read( DATA_FILE ),
31
+ :io => StringIO.new( IO.read( DATA_FILE ) ) }.each_pair do |style, data |
32
+ describe "inserts a blob from a #{style}" do
33
+ before(:each) do
34
+ column = @db.schema.tables['blobs'].columns['data']
35
+ @db.execute("INSERT INTO blobs(name, data) VALUES ($name, $data)",
36
+ { "$name" => DATA_FILE,
37
+ "$data" => Amalgalite::Blob.new( style => data,
38
+ :column => column ) } )
39
+ @db.execute("VACUUM")
40
+ end
41
+
42
+ after(:each) do
43
+ @db.execute("DELETE FROM blobs")
44
+ data.rewind if data.respond_to?( :rewind )
45
+ end
46
+
47
+ it "and retrieves the data as a single value" do
48
+ all_rows = @db.execute("SELECT name,data FROM blobs")
49
+ all_rows.size.should == 1;
50
+ all_rows.first['name'].should == DATA_FILE
51
+ all_rows.first['data'].should_not be_incremental
52
+ all_rows.first['data'].to_string_io.string.should == IO.read( DATA_FILE )
53
+ end
54
+
55
+ it "and retrieves the data using incremental IO" do
56
+ all_rows = @db.execute("SELECT * FROM blobs")
57
+ all_rows.size.should == 1;
58
+ all_rows.first['name'].should == DATA_FILE
59
+ all_rows.first['data'].should be_incremental
60
+ all_rows.first['data'].to_string_io.string.should == IO.read( DATA_FILE )
61
+ end
62
+
63
+ it "writes the data to a file " do
64
+ all_rows = @db.execute("SELECT * FROM blobs")
65
+ all_rows.size.should == 1;
66
+ all_rows.first['name'].should == DATA_FILE
67
+ all_rows.first['data'].should be_incremental
68
+ all_rows.first['data'].write_to_file( @junk_file )
69
+ IO.read( @junk_file).should == IO.read( DATA_FILE )
70
+ end
71
+ end
72
+ end
73
+
74
+
75
+
76
+ it "raises an error if initialized incorrectly" do
77
+ lambda{ Amalgalite::Blob.new( :file => "/dev/null", :string => "foo" ) }.should raise_error( Amalgalite::Blob::Error )
78
+ end
79
+ end
80
+
81
+
@@ -24,7 +24,7 @@ describe Amalgalite::TypeMaps::DefaultMap do
24
24
  end
25
25
 
26
26
  it "::Amalgalite::Blob is bound to DataType::BLOB" do
27
- @map.bind_type_of( ::Amalgalite::Blob.new ).should == ::Amalgalite::SQLite3::Constants::DataType::BLOB
27
+ @map.bind_type_of( ::Amalgalite::Blob.new( :column => true, :string => "just a test" ) ).should == ::Amalgalite::SQLite3::Constants::DataType::BLOB
28
28
  end
29
29
 
30
30
  it "everything else is bound to DataType::TEXT" do
@@ -75,7 +75,8 @@ describe Amalgalite::TypeMaps::DefaultMap do
75
75
  end
76
76
 
77
77
  it "raises and error if an unknown sql type is returned" do
78
- lambda{ @map.result_value_of( "footype", "foo" ) }.should raise_error( ::Amalgalite::Error )
78
+ x = nil
79
+ lambda{ x = @map.result_value_of( "footype", "foo" ) }.should raise_error( ::Amalgalite::Error )
79
80
  end
80
81
 
81
82
  it "raises and error if an ruby class is attempted to be mapped" do
@@ -76,6 +76,24 @@ describe Amalgalite::Statement do
76
76
  end
77
77
  end
78
78
 
79
+ it "can execute the same prepared statement multiple times" do
80
+ @db.execute(" CREATE TABLE t(x,y); ")
81
+ values = {}
82
+ @db.prepare("INSERT INTO t( x, y ) VALUES( $x, $y )" ) do |stmt|
83
+ 20.times do |x|
84
+ y = rand( x )
85
+ stmt.execute( { "$x" => x, "$y" => y } )
86
+ values[x] = y
87
+ end
88
+ end
89
+ c = 0
90
+ @db.execute("SELECT * from t") do |row|
91
+ c += 1
92
+ values[ row['x'] ].should == row['y']
93
+ end
94
+ c.should == 20
95
+ end
96
+
79
97
  it "binds a integer variable correctly" do
80
98
  @iso_db.prepare("SELECT * FROM country WHERE id = ? ORDER BY name ") do |stmt|
81
99
  all_rows = stmt.execute( 891 )
@@ -24,7 +24,7 @@ describe Amalgalite::TypeMaps::StorageMap do
24
24
  end
25
25
 
26
26
  it "::Amalgalite::Blob is bound to DataType::BLOB" do
27
- @map.bind_type_of( ::Amalgalite::Blob.new ).should == ::Amalgalite::SQLite3::Constants::DataType::BLOB
27
+ @map.bind_type_of( ::Amalgalite::Blob.new( :string => "testing mapping", :column => true ) ).should == ::Amalgalite::SQLite3::Constants::DataType::BLOB
28
28
  end
29
29
 
30
30
  it "everything else is bound to DataType::TEXT" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amalgalite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Hinegardner
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-20 00:00:00 -06:00
12
+ date: 2008-07-04 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,7 +30,16 @@ dependencies:
30
30
  - !ruby/object:Gem::Version
31
31
  version: 4.5.0
32
32
  version:
33
- description: Amalgalite embeds the SQLite database engine in a ruby extension. Scroll through Amalgalite::Database for a quick example, and a general overview of the API.
33
+ - !ruby/object:Gem::Dependency
34
+ name: mkrf
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.3
41
+ version:
42
+ description: Amalgalite embeds the SQLite database engine in a ruby extension. There is no need to install SQLite separately. Look in the examples/ directory to see * general usage * blob io * schema information Also Scroll through Amalgalite::Database for a quick example, and a general overview of the API.
34
43
  email: jeremy@hinegardner.org
35
44
  executables: []
36
45
 
@@ -55,6 +64,7 @@ extra_rdoc_files:
55
64
  - lib/amalgalite/table.rb
56
65
  - lib/amalgalite/taps/console.rb
57
66
  - lib/amalgalite/taps/io.rb
67
+ - lib/amalgalite/taps.rb
58
68
  - lib/amalgalite/trace_tap.rb
59
69
  - lib/amalgalite/type_map.rb
60
70
  - lib/amalgalite/type_maps/default_map.rb
@@ -64,11 +74,13 @@ extra_rdoc_files:
64
74
  - lib/amalgalite/view.rb
65
75
  - lib/amalgalite.rb
66
76
  - ext/amalgalite3.c
77
+ - ext/amalgalite3_blob.c
67
78
  - ext/amalgalite3_constants.c
68
79
  - ext/amalgalite3_database.c
69
80
  - ext/amalgalite3_statement.c
70
81
  files:
71
82
  - ext/amalgalite3.c
83
+ - ext/amalgalite3_blob.c
72
84
  - ext/amalgalite3_constants.c
73
85
  - ext/amalgalite3_database.c
74
86
  - ext/amalgalite3_statement.c
@@ -94,6 +106,7 @@ files:
94
106
  - lib/amalgalite/table.rb
95
107
  - lib/amalgalite/taps/console.rb
96
108
  - lib/amalgalite/taps/io.rb
109
+ - lib/amalgalite/taps.rb
97
110
  - lib/amalgalite/trace_tap.rb
98
111
  - lib/amalgalite/type_map.rb
99
112
  - lib/amalgalite/type_maps/default_map.rb
@@ -103,6 +116,7 @@ files:
103
116
  - lib/amalgalite/view.rb
104
117
  - lib/amalgalite.rb
105
118
  - spec/amalgalite_spec.rb
119
+ - spec/blob_spec.rb
106
120
  - spec/boolean_spec.rb
107
121
  - spec/database_spec.rb
108
122
  - spec/default_map_spec.rb