amalgalite 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -1,4 +1,12 @@
1
1
  = Changelog
2
+ == Version 0.2.2
3
+
4
+ * Bugfixes
5
+ * Database#pragma should accept a block just like Database#execute does
6
+
7
+ * compatibility fix
8
+ * convert to using extconf.rb instead of mkrf for muster integration
9
+
2
10
  == Version 0.2.1 - 2008-07-05
3
11
 
4
12
  * Bugfixes
data/ext/extconf.rb ADDED
@@ -0,0 +1,13 @@
1
+ require 'mkmf'
2
+ require 'rbconfig'
3
+
4
+ # make available table and column meta data api
5
+ $CFLAGS += " -DSQLITE_ENABLE_COLUMN_METADATA=1"
6
+
7
+ # we compile sqlite the same way that the installation of ruby is compiled.
8
+ if Config::CONFIG['configure_args'].include?( "--enable-pthread" ) then
9
+ $CFLAGS += " -DSQLITE_THREADSAFE=1"
10
+ else
11
+ $CFLAGS += "-DSQLITE_THREADSAFE=0"
12
+ end
13
+ create_makefile('amalgalite3')
data/gemspec.rb CHANGED
@@ -23,7 +23,6 @@ Amalgalite::GEM_SPEC = Gem::Specification.new do |spec|
23
23
  # spec.add_dependency("rake", ">= 0.8.1")
24
24
  spec.add_dependency("configuration", ">= 0.0.5")
25
25
  spec.add_dependency("arrayfields", ">= 4.5.0")
26
- spec.add_dependency("mkrf", ">= 0.2.3")
27
26
 
28
27
 
29
28
  if ext_conf = Configuration.for_if_exist?("extension") then
@@ -78,7 +78,7 @@ module Amalgalite
78
78
  # and +length+. +read+ should have the behavior of IO#read
79
79
  # :db_blob : not normally used by an end user, used to initialize a blob
80
80
  # object that is returned from an SQL query.
81
- # :string : used when a Blob is part of a WHERE clause
81
+ # :string : used when a Blob is part of a WHERE clause or result
82
82
  #
83
83
  # And additional key of :block_size may be used to indicate the maximum size
84
84
  # of a single block of data to move from the source to the destination, this
@@ -96,7 +96,7 @@ module Amalgalite
96
96
  @block_size = params[:block_size] || Blob.default_block_size
97
97
  @column = params[:column]
98
98
 
99
- raise Blob::Error, "A :column parameter is required for a Blob" unless @column
99
+ raise Blob::Error, "A :column parameter is required for a Blob" unless @column or params.has_key?( :string )
100
100
 
101
101
  if params.has_key?( :file ) then
102
102
  @source = File.open( params[:file], "r" )
@@ -147,6 +147,13 @@ module Amalgalite
147
147
  end
148
148
  end
149
149
 
150
+ ##
151
+ # conver the blob to a string
152
+ #
153
+ def to_s
154
+ to_string_io.string
155
+ end
156
+
150
157
  ##
151
158
  # write the Blob contents to a StringIO
152
159
  #
@@ -0,0 +1,14 @@
1
+ module Kernel
2
+ alias :original_require :require
3
+ #
4
+ # hook into the system 'require' to allow for required text or blobs from an
5
+ # amalgalite database.
6
+ #
7
+ def require( filename )
8
+ found = Amalgalite::Requires.require( filename )
9
+ unless found
10
+ found = original_require( filename )
11
+ end
12
+ return found
13
+ end
14
+ end
@@ -437,8 +437,8 @@ module Amalgalite
437
437
  # Run a pragma command against the database
438
438
  #
439
439
  # Returns the result set of the pragma
440
- def pragma( cmd )
441
- execute("PRAGMA #{cmd}")
440
+ def pragma( cmd, &block )
441
+ execute("PRAGMA #{cmd}", &block)
442
442
  end
443
443
 
444
444
  ##
@@ -0,0 +1,75 @@
1
+ module Amalgalite
2
+ #
3
+ # Requires encapsulates requiring itesm from the database
4
+ class Requires
5
+ class << self
6
+ def load_path_db_connections
7
+ @load_path_db_connections ||= {}
8
+ end
9
+ def load_path
10
+ @load_path ||= []
11
+ end
12
+
13
+ def db_connection_to( dbfile_name )
14
+ unless connection = load_path_db_connections[ dbfile_name ]
15
+ puts "loading file #{dbfile_name}"
16
+ connection = ::Amalgalite::Database.new( dbfile_name )
17
+ load_path_db_connections[dbfile_name] = connection
18
+ end
19
+ return connection
20
+ end
21
+
22
+ def require( filename )
23
+ load_path.each { |lp| lp.require( filename ) }
24
+ end
25
+ end
26
+
27
+ attr_reader :dbfile_name
28
+ attr_reader :table_name
29
+ attr_reader :filename_column
30
+ attr_reader :contents_column
31
+ attr_reader :db_connection
32
+
33
+ def initialize( opts = {} )
34
+ @dbfile_name = opts[:dbfile_name] || "lib.db"
35
+ @table_name = opts[:table_name] || "rubylibs"
36
+ @filename_column = opts[:filename_column] || "filename"
37
+ @contents_column = opts[:contents_column] || "contents"
38
+ @db_connection = Requires.db_connection_to( dbfile_name )
39
+ Requires.load_path << self
40
+ end
41
+
42
+ #
43
+ # return the sql to find the file contents for a file in this requires
44
+ #
45
+ def sql
46
+ @sql ||= "SELECT #{filename_column}, #{contents_column} FROM #{table_name} WHERE #{filename_column} = ?"
47
+ end
48
+
49
+ #
50
+ # require a file in this database table. This will check and see if the
51
+ # file is already required. If it isn't it will select the contents
52
+ # associated with the row identified by the filename and eval those contents
53
+ # within the context of TOPLEVEL_BINDING. The filename is then appended to
54
+ # $".
55
+ #
56
+ # if the file was required then true is returned, otherwise false
57
+ #
58
+ def require( filename )
59
+ if $".include?( filename ) then
60
+ return false
61
+ else
62
+ begin
63
+ rows = db_connection.execute(sql, filename)
64
+ row = rows.first
65
+ eval( row[contents_column].to_s, TOPLEVEL_BINDING)
66
+ $" << row[filename_column]
67
+ rescue => e
68
+ raise LoadError, "Failure loading #{filename} from #{dbfile_name} : #{e}"
69
+ end
70
+ end
71
+ return true
72
+ end
73
+ end
74
+ end
75
+ require 'amalgalite/core_ext/kernel/require'
@@ -158,10 +158,10 @@ module Amalgalite::TypeMaps
158
158
  end
159
159
 
160
160
  ##
161
- # convert a string to a blog
161
+ # convert a string to a blob
162
162
  #
163
163
  def blob( str )
164
- raise NotImplementedError, "Blob type conversion is not implemented"
164
+ ::Amalgalite::Blob.new( :string => str )
165
165
  end
166
166
  end
167
167
  end
@@ -9,7 +9,7 @@ module Amalgalite
9
9
 
10
10
  MAJOR = 0
11
11
  MINOR = 2
12
- BUILD = 1
12
+ BUILD = 2
13
13
 
14
14
  #
15
15
  # return the Version as an array of MAJOR, MINOR, BUILD
@@ -159,6 +159,14 @@ describe Amalgalite::Database do
159
159
  count.should == 10
160
160
  end
161
161
 
162
+ it "#pragma yields each row when called with a block" do
163
+ count = 0
164
+ @iso_db.pragma( "index_info( subcountry_country )" ) do |row|
165
+ count += 1
166
+ end
167
+ count.should == 1
168
+ end
169
+
162
170
  it "can use something that responds to 'write' as a tap" do
163
171
  db = Amalgalite::Database.new( SpecInfo.test_db )
164
172
  s2 = db.trace_tap = StringIO.new
@@ -70,8 +70,9 @@ describe Amalgalite::TypeMaps::DefaultMap do
70
70
  @map.result_value_of( "bool", "True" ).should == true
71
71
  end
72
72
 
73
- it "raises NotImplemeted for blob conversion" do
74
- lambda{ @map.result_value_of( "Blob", "some blob" ) }.should raise_error( NotImplementedError )
73
+ it "Blob is returned for declated types of 'blob'" do
74
+ blob = @map.result_value_of( "blob", "stuff")
75
+ blob.to_s.should == "stuff"
75
76
  end
76
77
 
77
78
  it "raises and error if an unknown sql type is returned" do
data/tasks/config.rb CHANGED
@@ -92,7 +92,8 @@ Configuration.for('rdoc') {
92
92
  # Extensions
93
93
  #-----------------------------------------------------------------------
94
94
  Configuration.for('extension') {
95
- configs Configuration.for('packaging').files.ext.find_all { |x| %w[ mkrf_conf.rb extconf.rb ].include?(File.basename(x)) }
95
+ #configs Configuration.for('packaging').files.ext.find_all { |x| %w[ mkrf_conf.rb extconf.rb ].include?(File.basename(x)) }
96
+ configs Configuration.for('packaging').files.ext.find_all { |x| %w[ extconf.rb ].include?(File.basename(x)) }
96
97
  }
97
98
 
98
99
  #-----------------------------------------------------------------------
data/tasks/extension.rake CHANGED
@@ -15,7 +15,8 @@ if ext_config = Configuration.for_if_exist?('extension') then
15
15
  conf = parts.last
16
16
  Dir.chdir(path.dirname) do |d|
17
17
  ruby conf.to_s
18
- sh "rake default"
18
+ #sh "rake default"
19
+ sh "make"
19
20
  end
20
21
  end
21
22
  end
@@ -26,7 +27,8 @@ if ext_config = Configuration.for_if_exist?('extension') then
26
27
  parts = path.split
27
28
  conf = parts.last
28
29
  Dir.chdir(path.dirname) do |d|
29
- sh "rake clean"
30
+ #sh "rake clean"
31
+ sh "make clean"
30
32
  end
31
33
  end
32
34
  end
@@ -37,7 +39,8 @@ if ext_config = Configuration.for_if_exist?('extension') then
37
39
  parts = path.split
38
40
  conf = parts.last
39
41
  Dir.chdir(path.dirname) do |d|
40
- sh "rake clobber"
42
+ #sh "rake clobber"
43
+ sh "make distclean"
41
44
  end
42
45
  end
43
46
  end
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.2.1
4
+ version: 0.2.2
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-07-05 00:00:00 -06:00
12
+ date: 2008-07-12 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,26 +30,26 @@ dependencies:
30
30
  - !ruby/object:Gem::Version
31
31
  version: 4.5.0
32
32
  version:
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
33
  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.
43
34
  email: jeremy@hinegardner.org
44
35
  executables: []
45
36
 
46
37
  extensions:
47
- - ext/mkrf_conf.rb
38
+ - ext/extconf.rb
48
39
  extra_rdoc_files:
49
40
  - README
50
41
  - HISTORY
51
42
  - LICENSE
43
+ - lib/amalgalite/sqlite3/constants.rb
44
+ - lib/amalgalite/sqlite3/version.rb
45
+ - lib/amalgalite/taps/console.rb
46
+ - lib/amalgalite/taps/io.rb
47
+ - lib/amalgalite/type_maps/default_map.rb
48
+ - lib/amalgalite/type_maps/storage_map.rb
49
+ - lib/amalgalite/type_maps/text_map.rb
50
+ - lib/amalgalite/statement.rb
52
51
  - lib/amalgalite/blob.rb
52
+ - lib/amalgalite/version.rb
53
53
  - lib/amalgalite/boolean.rb
54
54
  - lib/amalgalite/column.rb
55
55
  - lib/amalgalite/database.rb
@@ -57,30 +57,23 @@ extra_rdoc_files:
57
57
  - lib/amalgalite/paths.rb
58
58
  - lib/amalgalite/profile_tap.rb
59
59
  - lib/amalgalite/schema.rb
60
- - lib/amalgalite/sqlite3/constants.rb
61
- - lib/amalgalite/sqlite3/version.rb
62
60
  - lib/amalgalite/sqlite3.rb
63
- - lib/amalgalite/statement.rb
61
+ - lib/amalgalite/core_ext/kernel/require.rb
62
+ - lib/amalgalite/requires.rb
64
63
  - lib/amalgalite/table.rb
65
- - lib/amalgalite/taps/console.rb
66
- - lib/amalgalite/taps/io.rb
67
64
  - lib/amalgalite/taps.rb
68
65
  - lib/amalgalite/trace_tap.rb
69
66
  - lib/amalgalite/type_map.rb
70
- - lib/amalgalite/type_maps/default_map.rb
71
- - lib/amalgalite/type_maps/storage_map.rb
72
- - lib/amalgalite/type_maps/text_map.rb
73
- - lib/amalgalite/version.rb
74
67
  - lib/amalgalite/view.rb
75
68
  - lib/amalgalite.rb
76
- - ext/amalgalite3.c
77
69
  - ext/amalgalite3_blob.c
70
+ - ext/amalgalite3.c
78
71
  - ext/amalgalite3_constants.c
79
72
  - ext/amalgalite3_database.c
80
73
  - ext/amalgalite3_statement.c
81
74
  files:
82
- - ext/amalgalite3.c
83
75
  - ext/amalgalite3_blob.c
76
+ - ext/amalgalite3.c
84
77
  - ext/amalgalite3_constants.c
85
78
  - ext/amalgalite3_database.c
86
79
  - ext/amalgalite3_statement.c
@@ -89,9 +82,18 @@ files:
89
82
  - ext/sqlite3.h
90
83
  - ext/sqlite3_options.h
91
84
  - ext/sqlite3ext.h
85
+ - ext/extconf.rb
92
86
  - ext/gen_constants.rb
93
- - ext/mkrf_conf.rb
87
+ - lib/amalgalite/sqlite3/constants.rb
88
+ - lib/amalgalite/sqlite3/version.rb
89
+ - lib/amalgalite/taps/console.rb
90
+ - lib/amalgalite/taps/io.rb
91
+ - lib/amalgalite/type_maps/default_map.rb
92
+ - lib/amalgalite/type_maps/storage_map.rb
93
+ - lib/amalgalite/type_maps/text_map.rb
94
+ - lib/amalgalite/statement.rb
94
95
  - lib/amalgalite/blob.rb
96
+ - lib/amalgalite/version.rb
95
97
  - lib/amalgalite/boolean.rb
96
98
  - lib/amalgalite/column.rb
97
99
  - lib/amalgalite/database.rb
@@ -99,34 +101,27 @@ files:
99
101
  - lib/amalgalite/paths.rb
100
102
  - lib/amalgalite/profile_tap.rb
101
103
  - lib/amalgalite/schema.rb
102
- - lib/amalgalite/sqlite3/constants.rb
103
- - lib/amalgalite/sqlite3/version.rb
104
104
  - lib/amalgalite/sqlite3.rb
105
- - lib/amalgalite/statement.rb
105
+ - lib/amalgalite/core_ext/kernel/require.rb
106
+ - lib/amalgalite/requires.rb
106
107
  - lib/amalgalite/table.rb
107
- - lib/amalgalite/taps/console.rb
108
- - lib/amalgalite/taps/io.rb
109
108
  - lib/amalgalite/taps.rb
110
109
  - lib/amalgalite/trace_tap.rb
111
110
  - lib/amalgalite/type_map.rb
112
- - lib/amalgalite/type_maps/default_map.rb
113
- - lib/amalgalite/type_maps/storage_map.rb
114
- - lib/amalgalite/type_maps/text_map.rb
115
- - lib/amalgalite/version.rb
116
111
  - lib/amalgalite/view.rb
117
112
  - lib/amalgalite.rb
113
+ - spec/sqlite3/constants_spec.rb
114
+ - spec/sqlite3/version_spec.rb
115
+ - spec/integeration_spec.rb
118
116
  - spec/amalgalite_spec.rb
119
117
  - spec/blob_spec.rb
118
+ - spec/sqlite3_spec.rb
120
119
  - spec/boolean_spec.rb
121
120
  - spec/database_spec.rb
122
121
  - spec/default_map_spec.rb
123
- - spec/integeration_spec.rb
124
122
  - spec/paths_spec.rb
125
123
  - spec/schema_spec.rb
126
124
  - spec/spec_helper.rb
127
- - spec/sqlite3/constants_spec.rb
128
- - spec/sqlite3/version_spec.rb
129
- - spec/sqlite3_spec.rb
130
125
  - spec/statement_spec.rb
131
126
  - spec/storage_map_spec.rb
132
127
  - spec/tap_spec.rb
@@ -136,10 +131,10 @@ files:
136
131
  - README
137
132
  - HISTORY
138
133
  - LICENSE
139
- - tasks/announce.rake
140
134
  - tasks/distribution.rake
141
- - tasks/documentation.rake
135
+ - tasks/announce.rake
142
136
  - tasks/extension.rake
137
+ - tasks/documentation.rake
143
138
  - tasks/rspec.rake
144
139
  - tasks/rubyforge.rake
145
140
  - tasks/config.rb
@@ -171,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
166
  requirements: []
172
167
 
173
168
  rubyforge_project: copiousfreetime
174
- rubygems_version: 1.1.1
169
+ rubygems_version: 1.0.1
175
170
  signing_key:
176
171
  specification_version: 2
177
172
  summary: Amalgalite embeds the SQLite database engine in a ruby extension
data/ext/mkrf_conf.rb DELETED
@@ -1,14 +0,0 @@
1
- require 'rubygems'
2
- require 'mkrf'
3
- require 'rbconfig'
4
- Mkrf::Generator.new('amalgalite3') do |g|
5
- # turn on some compilation options
6
- g.cflags << " -DSQLITE_ENABLE_COLUMN_METADATA=1" # make available table and column meta data api
7
-
8
- # we compile sqlite the same way that the installation of ruby is compiled.
9
- if Config::CONFIG['configure_args'].include?( "--enable-pthread" ) then
10
- g.cflags << " -DSQLITE_THREADSAFE=1"
11
- else
12
- g.cflags << " -DSQLITE_THREADSAFE=0"
13
- end
14
- end