amalgalite 1.9.4-x86-mingw32 → 2.0.0-x86-mingw32

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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +19 -2
  3. data/Manifest.txt +4 -54
  4. data/README.md +1 -1
  5. data/TODO.md +4 -3
  6. data/amalgalite.gemspec +39 -0
  7. data/ext/amalgalite/c/amalgalite.c +0 -1
  8. data/ext/amalgalite/c/amalgalite_constants.c +155 -10
  9. data/ext/amalgalite/c/extconf.rb +5 -2
  10. data/ext/amalgalite/c/gen_constants.rb +32 -1
  11. data/ext/amalgalite/c/sqlite3.c +19308 -9112
  12. data/ext/amalgalite/c/sqlite3.h +909 -296
  13. data/ext/amalgalite/c/sqlite3ext.h +11 -0
  14. data/lib/amalgalite/2.7/amalgalite.so +0 -0
  15. data/lib/amalgalite/3.0/amalgalite.so +0 -0
  16. data/lib/amalgalite/3.1/amalgalite.so +0 -0
  17. data/lib/amalgalite/3.2/amalgalite.so +0 -0
  18. data/lib/amalgalite/3.3/amalgalite.so +0 -0
  19. data/lib/amalgalite/3.4/amalgalite.so +0 -0
  20. data/lib/amalgalite/column.rb +20 -2
  21. data/lib/amalgalite/result/row.rb +83 -0
  22. data/lib/amalgalite/result.rb +15 -0
  23. data/lib/amalgalite/statement.rb +32 -24
  24. data/lib/amalgalite/type_maps/default_map.rb +48 -56
  25. data/lib/amalgalite/version.rb +1 -1
  26. metadata +36 -123
  27. data/Rakefile +0 -27
  28. data/bin/amalgalite-pack +0 -147
  29. data/examples/a.rb +0 -9
  30. data/examples/blob.rb +0 -88
  31. data/examples/bootstrap.rb +0 -36
  32. data/examples/define_aggregate.rb +0 -75
  33. data/examples/define_function.rb +0 -104
  34. data/examples/fts5.rb +0 -152
  35. data/examples/gem-db.rb +0 -94
  36. data/examples/require_me.rb +0 -11
  37. data/examples/requires.rb +0 -42
  38. data/examples/schema-info.rb +0 -34
  39. data/ext/amalgalite/c/amalgalite_requires_bootstrap.c +0 -283
  40. data/lib/amalgalite/2.4/amalgalite.so +0 -0
  41. data/lib/amalgalite/2.5/amalgalite.so +0 -0
  42. data/lib/amalgalite/2.6/amalgalite.so +0 -0
  43. data/lib/amalgalite/core_ext/kernel/require.rb +0 -21
  44. data/lib/amalgalite/packer.rb +0 -231
  45. data/lib/amalgalite/requires.rb +0 -151
  46. data/spec/aggregate_spec.rb +0 -158
  47. data/spec/amalgalite_spec.rb +0 -4
  48. data/spec/blob_spec.rb +0 -78
  49. data/spec/boolean_spec.rb +0 -24
  50. data/spec/busy_handler.rb +0 -157
  51. data/spec/data/iso-3166-country.txt +0 -242
  52. data/spec/data/iso-3166-schema.sql +0 -22
  53. data/spec/data/iso-3166-subcountry.txt +0 -3995
  54. data/spec/data/make-iso-db.sh +0 -12
  55. data/spec/database_spec.rb +0 -505
  56. data/spec/default_map_spec.rb +0 -92
  57. data/spec/function_spec.rb +0 -78
  58. data/spec/integeration_spec.rb +0 -97
  59. data/spec/iso_3166_database.rb +0 -58
  60. data/spec/json_spec.rb +0 -24
  61. data/spec/packer_spec.rb +0 -60
  62. data/spec/paths_spec.rb +0 -28
  63. data/spec/progress_handler_spec.rb +0 -91
  64. data/spec/requires_spec.rb +0 -54
  65. data/spec/rtree_spec.rb +0 -66
  66. data/spec/schema_spec.rb +0 -131
  67. data/spec/spec_helper.rb +0 -48
  68. data/spec/sqlite3/constants_spec.rb +0 -108
  69. data/spec/sqlite3/database_status_spec.rb +0 -36
  70. data/spec/sqlite3/status_spec.rb +0 -22
  71. data/spec/sqlite3/version_spec.rb +0 -28
  72. data/spec/sqlite3_spec.rb +0 -53
  73. data/spec/statement_spec.rb +0 -168
  74. data/spec/storage_map_spec.rb +0 -38
  75. data/spec/tap_spec.rb +0 -57
  76. data/spec/text_map_spec.rb +0 -20
  77. data/spec/type_map_spec.rb +0 -14
  78. data/spec/version_spec.rb +0 -8
  79. data/tasks/custom.rake +0 -101
  80. data/tasks/default.rake +0 -257
  81. data/tasks/extension.rake +0 -28
  82. data/tasks/this.rb +0 -208
  83. /data/{LICENSE → LICENSE.txt} +0 -0
@@ -1,75 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- $: << "../lib"
5
- $: << "../ext"
6
- require 'amalgalite'
7
-
8
- #--
9
- # Create a database and a table to put some results from the functions in
10
- #--
11
- db = Amalgalite::Database.new( ":memory:" )
12
- db.execute( "CREATE TABLE atest( words )" )
13
-
14
- #------------------------------------------------------------------------------
15
- # Create unique word count aggregate
16
- #------------------------------------------------------------------------------
17
- class UniqueWordCount < ::Amalgalite::Aggregate
18
- attr_accessor :words
19
-
20
- def initialize
21
- @name = 'unique_word_count'
22
- @arity = 1
23
- @words = Hash.new { |h,k| h[k] = 0 }
24
- end
25
-
26
- def step( str )
27
- str.split(/\W+/).each do |word|
28
- words[ word.downcase ] += 1
29
- end
30
- return nil
31
- end
32
-
33
- def finalize
34
- return words.size
35
- end
36
- end
37
-
38
- db.define_aggregate( 'unique_word_count', UniqueWordCount )
39
-
40
- #------------------------------------------------------------------------------
41
- # Now we have a new aggregate function, lets insert some rows into the database
42
- # and see what we can find.
43
- #------------------------------------------------------------------------------
44
- sql = "INSERT INTO atest( words ) VALUES( ? )"
45
- verify = {}
46
- db.prepare( sql ) do |stmt|
47
- DATA.each do |words|
48
- words.strip!
49
- puts "Inserting #{words}"
50
- stmt.execute( words )
51
- words.split(/\W+/).each { |w| verify[w] = true }
52
- end
53
- end
54
-
55
- #------------------------------------------------------------------------------
56
- # And show the results
57
- #------------------------------------------------------------------------------
58
- puts
59
- puts "Getting results..."
60
- puts
61
- all_rows = db.execute("SELECT unique_word_count( words ) AS uwc FROM atest")
62
- puts "#{all_rows.first['uwc']} unique words found"
63
- puts "#{verify.size} unique words to verify"
64
-
65
- __END__
66
- some random
67
- words with
68
- which
69
- to play
70
- and there should
71
- be a couple of different
72
- words that appear
73
- more than once and
74
- some that appear only
75
- once
@@ -1,104 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- $: << "../lib"
5
- $: << "../ext"
6
- require 'amalgalite'
7
-
8
- #--
9
- # Create a database and a table to put some results from the functions in
10
- #--
11
- db = Amalgalite::Database.new( ":memory:" )
12
- db.execute( "CREATE TABLE ftest( data, md5, sha1, sha2_bits, sha2)" )
13
-
14
- #------------------------------------------------------------------------------
15
- # Create an MD5 method using the block format of defining an sql fuction
16
- #------------------------------------------------------------------------------
17
- require 'digest/md5'
18
- db.define_function( 'md5' ) do |x|
19
- Digest::MD5.hexdigest( x.to_s )
20
- end
21
-
22
- #------------------------------------------------------------------------------
23
- # Create a SHA1 method using the lambda format of defining an sql function
24
- #------------------------------------------------------------------------------
25
- require 'digest/sha1'
26
- sha1 = lambda do |y|
27
- Digest::SHA1.hexdigest( y.to_s )
28
- end
29
- db.define_function( "sha1", sha1 )
30
-
31
- #------------------------------------------------------------------------------
32
- # Create a SHA2 method using the class format for defining an sql function
33
- # In this one we will allow any number of parameters, but we will only use the
34
- # first two.
35
- #------------------------------------------------------------------------------
36
- require 'digest/sha2'
37
- class SQLSha2
38
- # track the number of invocations
39
- attr_reader :call_count
40
-
41
- def initialize
42
- @call_count = 0
43
- end
44
-
45
- # the protocol that is used for sql function definition
46
- def to_proc() self ; end
47
-
48
- # say we take any number of parameters
49
- def arity
50
- -1
51
- end
52
-
53
- # The method that is called by SQLite, must be named 'call'
54
- def call( *args )
55
- text = args.shift.to_s
56
- bitlength = (args.shift || 256).to_i
57
- Digest::SHA2.new( bitlength ).hexdigest( text )
58
- end
59
- end
60
- db.define_function('sha2', SQLSha2.new)
61
-
62
-
63
- #------------------------------------------------------------------------------
64
- # Now we have 3 new sql functions, each defined in one of the available methods
65
- # to define sql functions in amalgalite. Lets insert some rows and look at the
66
- # results
67
- #------------------------------------------------------------------------------
68
- possible_bits = [ 256, 384, 512 ]
69
- sql = "INSERT INTO ftest( data, md5, sha1, sha2_bits, sha2 ) VALUES( @word , md5( @word ), sha1( @word ), @bits, sha2(@word,@bits) )"
70
- db.prepare( sql ) do |stmt|
71
- DATA.each do |word|
72
- word.strip!
73
- bits = possible_bits[ rand(3) ]
74
- puts "Inserting #{word}, #{bits}"
75
- stmt.execute( { '@word' => word, '@bits' => bits } )
76
- end
77
- end
78
-
79
- #------------------------------------------------------------------------------
80
- # And show the results
81
- #------------------------------------------------------------------------------
82
- puts
83
- puts "Getting results..."
84
- puts
85
- columns = db.schema.tables['ftest'].columns.keys.sort
86
- i = 0
87
- db.execute("SELECT #{columns.join(',')} FROM ftest") do |row|
88
- i += 1
89
- puts "-----[ row #{i} ]-" + "-" * 42
90
- columns.each do |col|
91
- puts "#{col.ljust(10)} : #{row[col]}"
92
- end
93
- puts
94
- end
95
-
96
-
97
- __END__
98
- some
99
- random
100
- words
101
- with
102
- which
103
- to
104
- play
data/examples/fts5.rb DELETED
@@ -1,152 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'rubygems'
3
- require 'amalgalite'
4
- require 'benchmark'
5
- require 'pathname'
6
-
7
- begin
8
- require 'json'
9
- rescue LoadError
10
- abort "'gem install json' to run this example"
11
- end
12
-
13
-
14
- README = <<_
15
- This example program assumes that you have available the 'fortune' BSD command dataset.
16
-
17
- execute `fortune -f` to see if you have this command available.
18
- _
19
-
20
- fortune_dir = %x[ fortune -f 2>&1 ].split("\n").first.split.last
21
- abort README unless fortune_dir and File.directory?( fortune_dir )
22
-
23
- fortune_path = Pathname.new(fortune_dir)
24
-
25
- #
26
- # Lets create a database that utilizes FTS5 http://www.sqlite.org/fts5.html
27
- #
28
- #
29
-
30
- #
31
- # Create a database, this will create the DB if it doesn't exist
32
- #
33
- puts "Opening database (version #{Amalgalite::VERSION})"
34
- db = Amalgalite::Database.new("fts5.db")
35
-
36
- #
37
- # Create the schema unless it already exists in the table. The meta information
38
- # about the database schema is available as the result of the db.schema method
39
- #
40
- schema = db.schema
41
- unless schema.tables['search']
42
- puts "Create schema"
43
- db.execute_batch <<-SQL
44
- CREATE VIRTUAL TABLE search USING fts5(
45
- filename,
46
- content
47
- );
48
-
49
- CREATE TABLE plain (
50
- filename VARCHAR(128),
51
- content TEXT
52
- );
53
- SQL
54
- db.reload_schema!
55
- end
56
-
57
- def each_fortune(path,&block)
58
- fortune = []
59
- path.each_line do |line|
60
- line.strip!
61
- if line == "%" then
62
- yield fortune.join("\n")
63
- fortune.clear
64
- else
65
- fortune << line
66
- end
67
- end
68
- end
69
-
70
- #
71
- # Only load the data if the db is empty
72
- #
73
- if db.first_value_from( "SELECT count(*) from search" ) == 0 then
74
- before = Time.now
75
- idx = 0
76
-
77
- # Inserting bulk rows as a transaction is good practice with SQLite, it is
78
- # MUCH faster.
79
- db.transaction do |db_in_transaction|
80
- # Iterate over the files in the fortunes dir and split on the fortunes, then
81
-
82
- fortune_path.each_child do |fortune_file|
83
- next if fortune_file.directory?
84
- next if fortune_file.extname == ".dat"
85
- $stdout.puts "Loading #{fortune_file}"
86
-
87
- each_fortune(fortune_file) do |fortune|
88
- insert_data = {
89
- ':fname' => fortune_file.to_s,
90
- ':content' => fortune
91
- }
92
-
93
- # insert into the FTS5 table
94
- db_in_transaction.prepare("INSERT INTO search( filename, content ) VALUES( :fname, :content );") do |stmt|
95
- stmt.execute( insert_data )
96
- end
97
-
98
- # insert into the normal table for comparison
99
- db_in_transaction.prepare("INSERT INTO plain( filename, content ) VALUES( :fname, :content );") do |stmt|
100
- stmt.execute( insert_data )
101
- end
102
-
103
- idx += 1
104
- print "Processed #{idx}\r"
105
- $stdout.flush
106
- end
107
- puts "\nFinalizing..."
108
- end
109
- end
110
- puts "Took #{Time.now - before} seconds to insert #{idx} fortunes"
111
- puts "Done Inserting"
112
- end
113
-
114
- doc_count = db.first_value_from( "SELECT count(*) from search" )
115
-
116
- #
117
- # Now lets do some searching for some various words
118
- #
119
-
120
- %w[ president salmon thanks ].each do |word|
121
-
122
- count = 100
123
- puts
124
- puts "Searching for '#{word}' #{count} times across #{doc_count} fortunes"
125
- puts "=" * 60
126
-
127
- Benchmark.bm( 15 ) do |x|
128
-
129
- #
130
- # search using the fts search to get the cont of tweets with the given word
131
- #
132
- x.report('fts5: ') do
133
- db.prepare( "SELECT count(filename) FROM search WHERE search MATCH 'content:#{word}'" ) do |stmt|
134
- count.times do
135
- stmt.execute
136
- end
137
- end
138
- end
139
-
140
- #
141
- # search using basic string matching in sqlite.
142
- #
143
- x.report('plain: ') do
144
- db.prepare( "SELECT count(filename) FROM plain WHERE content LIKE '% #{word} %'" ) do |stmt|
145
- count.times do
146
- stmt.execute
147
- end
148
- end
149
- end
150
- end
151
- end
152
-
data/examples/gem-db.rb DELETED
@@ -1,94 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #
4
- # Basic amalgalite example creating a table, inserting rows and doing various
5
- # selects and prepared statements
6
- #
7
- require 'rubygems'
8
- require 'amalgalite'
9
-
10
- #
11
- # Create a database, this will create the DB if it doesn't exist
12
- #
13
- puts "Opening database (version #{Amalgalite::Version})"
14
- db = Amalgalite::Database.new("gems.db")
15
-
16
- #
17
- # Setup taps into profile and trace information of sqlite, the profile tap will
18
- # goto the profile_tap.log file and the trace information will go to the
19
- # trace_tap.log file
20
- #
21
- puts "Establishing taps"
22
- db.trace_tap = Amalgalite::Taps::IO.new( trace_tap_file = File.open("trace_tap.log", "w+") )
23
- db.profile_tap = Amalgalite::Taps::IO.new( profile_tap_file = File.open("profile_tap.log", "w+") )
24
-
25
- #
26
- # Create the schema unless it already exists in the table. The meta information
27
- # about the database schema is available as the result of the db.schema method
28
- #
29
- schema = db.schema
30
- unless schema.tables['gems']
31
- puts "Create schema"
32
- db.execute <<-SQL
33
- CREATE TABLE gems (
34
- id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
35
- name VARCHAR(128),
36
- version VARCHAR(32),
37
- author VARCHAR(128)
38
- );
39
- SQL
40
- db.reload_schema!
41
- end
42
-
43
- #
44
- # Get some data from the system to insert into the database. Since everyone
45
- # probably has gems installed, that's a ready known piece of information. We'll
46
- # just pull in the latest version of each installed gem and dump some meta
47
- # information into a db for testing.
48
- #
49
- latest_specs = Gem.source_index.latest_specs
50
-
51
- puts "Inserting #{latest_specs.size} rows of gem information..."
52
- before = Time.now
53
-
54
- # Inserting bulk rows as a transaction is good practice with SQLite, it is
55
- # MUCH faster.
56
- db.transaction do |db_in_transaction|
57
- db_in_transaction.prepare("INSERT INTO gems(name, version, author) VALUES( :name, :version, :author );") do |stmt|
58
- latest_specs.each do |spec|
59
- insert_data = {}
60
- insert_data[':name'] = spec.name.to_s
61
- insert_data[':version'] = spec.version.to_s
62
- insert_data[':author'] = spec.authors.join(' ')
63
- #puts "Inserting #{insert_data.inspect}"
64
- stmt.execute( insert_data )
65
- end
66
- end
67
- end
68
- puts "Took #{Time.now - before} seconds"
69
- puts "Done Inserting"
70
-
71
- authors_by_number = db.execute("SELECT author, count( name ) as num_gems FROM gems GROUP BY author ORDER BY num_gems DESC")
72
- favorite_author = authors_by_number.first
73
- puts "Your favorite gem author is <#{favorite_author['author']}>, with #{favorite_author['num_gems']} gems installed."
74
-
75
- #
76
- # Now we'll look at the profile sampler and see what information it traced about
77
- # our behavoir.
78
- #
79
- db.profile_tap.samplers.each do |stat_name, stat_values|
80
- puts "-" * 20
81
- puts stat_values.to_s
82
- end
83
-
84
- #
85
- # Clear out the taps (not really necessary, just cleaning up)
86
- #
87
- db.trace_tap = profile_tap = nil
88
-
89
- #
90
- # close things down
91
- #
92
- db.close
93
- trace_tap_file.close
94
- profile_tap_file.close
@@ -1,11 +0,0 @@
1
- CONSTANT = "bad"
2
- class RequireMe
3
- def initialize( msg )
4
- @msg = msg
5
- puts "RequireMe initialized"
6
- end
7
-
8
- def foo
9
- puts @msg
10
- end
11
- end
data/examples/requires.rb DELETED
@@ -1,42 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- #
4
- # An Amalgalite example showing how to 'require' data in an amalgalite database
5
- #
6
- # We'll make a database with one table, that we store file contents in.
7
- #
8
-
9
- $: << "../lib"
10
- $: << "../ext"
11
- require 'rubygems'
12
- require 'amalgalite'
13
-
14
- style = ARGV.shift || "normal"
15
-
16
- #
17
- # create the database
18
- #
19
- dbfile = Amalgalite::Requires::Bootstrap::DEFAULT_DB
20
- File.unlink( dbfile ) if File.exist?( dbfile )
21
- require 'amalgalite/packer'
22
- options = { :verbose => true }
23
- if style == "compressed" then
24
- options[:compressed] = true
25
- end
26
- p = Amalgalite::Packer.new( options )
27
- p.pack( [ "require_me.rb" ] )
28
-
29
- require 'amalgalite/requires'
30
- begin
31
- Amalgalite::Requires.new( :dbfile_name => p.dbfile )
32
- FileUtils.mv 'require_me.rb', 'rm.rb', :verbose => true
33
- require 'require_me'
34
- e = RequireMe.new( "#{style} require style works!" )
35
- e.foo
36
- require 'require_me'
37
- puts
38
-
39
- ensure
40
- FileUtils.mv 'rm.rb', 'require_me.rb', :verbose => true
41
- File.unlink( dbfile ) if File.exist?( dbfile )
42
- end
@@ -1,34 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'amalgalite'
5
-
6
- db_name = ARGV.shift
7
- unless db_name
8
- puts "Usage: #{File.basename($0)} dbname"
9
- exit 1
10
- end
11
- db = Amalgalite::Database.new( db_name )
12
- col_info = %w[ default_value declared_data_type collation_sequence_name not_null_constraint primary_key auto_increment ]
13
- max_width = col_info.collect { |c| c.length }.sort.last
14
-
15
- db.schema.tables.keys.sort.each do |table_name|
16
- puts "Table: #{table_name}"
17
- puts "=" * 42
18
- db.schema.tables[table_name].columns.each_pair do |col_name, col|
19
- puts " Column : #{col.name}"
20
- col_info.each do |ci|
21
- puts " |#{ci.rjust( max_width, "." )} : #{col.send( ci )}"
22
- end
23
- puts
24
- end
25
-
26
- db.schema.tables[table_name].indexes.each_pair do |idx_name, index|
27
- puts " Index : #{index.name}"
28
- puts " |#{"sequence_number".rjust( max_width, "." )} : #{index.sequence_number}"
29
- puts " |#{"is unique?".rjust( max_width, ".")} : #{index.unique?}"
30
- puts " |#{"columns".rjust( max_width, ".")} : #{index.columns.collect { |c| c.name }.join(',') }"
31
- puts
32
- end
33
- end
34
-