amalgalite 0.4.2-x86-mswin32-60

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. data/HISTORY +81 -0
  2. data/LICENSE +29 -0
  3. data/README +40 -0
  4. data/bin/amalgalite-pack-into-db +155 -0
  5. data/examples/a.rb +9 -0
  6. data/examples/blob.rb +105 -0
  7. data/examples/bootstrap.rb +36 -0
  8. data/examples/gem-db.rb +94 -0
  9. data/examples/requires.rb +54 -0
  10. data/examples/schema-info.rb +34 -0
  11. data/ext/amalgalite3.c +201 -0
  12. data/ext/amalgalite3.h +121 -0
  13. data/ext/amalgalite3_blob.c +241 -0
  14. data/ext/amalgalite3_constants.c +221 -0
  15. data/ext/amalgalite3_database.c +550 -0
  16. data/ext/amalgalite3_requires_bootstrap.c +210 -0
  17. data/ext/amalgalite3_statement.c +628 -0
  18. data/ext/extconf.rb +19 -0
  19. data/ext/gen_constants.rb +130 -0
  20. data/ext/rbconfig-mingw.rb +178 -0
  21. data/ext/sqlite3.c +97092 -0
  22. data/ext/sqlite3.h +6364 -0
  23. data/ext/sqlite3_options.h +4 -0
  24. data/ext/sqlite3ext.h +372 -0
  25. data/gemspec.rb +55 -0
  26. data/lib/amalgalite.rb +33 -0
  27. data/lib/amalgalite/blob.rb +186 -0
  28. data/lib/amalgalite/boolean.rb +42 -0
  29. data/lib/amalgalite/column.rb +86 -0
  30. data/lib/amalgalite/core_ext/kernel/require.rb +14 -0
  31. data/lib/amalgalite/database.rb +514 -0
  32. data/lib/amalgalite/index.rb +43 -0
  33. data/lib/amalgalite/paths.rb +70 -0
  34. data/lib/amalgalite/profile_tap.rb +130 -0
  35. data/lib/amalgalite/requires.rb +112 -0
  36. data/lib/amalgalite/schema.rb +115 -0
  37. data/lib/amalgalite/sqlite3.rb +6 -0
  38. data/lib/amalgalite/sqlite3/constants.rb +82 -0
  39. data/lib/amalgalite/sqlite3/database/status.rb +69 -0
  40. data/lib/amalgalite/sqlite3/status.rb +61 -0
  41. data/lib/amalgalite/sqlite3/version.rb +38 -0
  42. data/lib/amalgalite/statement.rb +394 -0
  43. data/lib/amalgalite/table.rb +36 -0
  44. data/lib/amalgalite/taps.rb +2 -0
  45. data/lib/amalgalite/taps/console.rb +27 -0
  46. data/lib/amalgalite/taps/io.rb +71 -0
  47. data/lib/amalgalite/trace_tap.rb +35 -0
  48. data/lib/amalgalite/type_map.rb +63 -0
  49. data/lib/amalgalite/type_maps/default_map.rb +167 -0
  50. data/lib/amalgalite/type_maps/storage_map.rb +41 -0
  51. data/lib/amalgalite/type_maps/text_map.rb +23 -0
  52. data/lib/amalgalite/version.rb +37 -0
  53. data/lib/amalgalite/view.rb +26 -0
  54. data/lib/amalgalite3.so +0 -0
  55. data/spec/amalgalite_spec.rb +4 -0
  56. data/spec/blob_spec.rb +81 -0
  57. data/spec/boolean_spec.rb +23 -0
  58. data/spec/database_spec.rb +238 -0
  59. data/spec/default_map_spec.rb +87 -0
  60. data/spec/integeration_spec.rb +111 -0
  61. data/spec/paths_spec.rb +28 -0
  62. data/spec/schema_spec.rb +60 -0
  63. data/spec/spec_helper.rb +25 -0
  64. data/spec/sqlite3/constants_spec.rb +65 -0
  65. data/spec/sqlite3/database_status_spec.rb +36 -0
  66. data/spec/sqlite3/status_spec.rb +18 -0
  67. data/spec/sqlite3/version_spec.rb +14 -0
  68. data/spec/sqlite3_spec.rb +23 -0
  69. data/spec/statement_spec.rb +134 -0
  70. data/spec/storage_map_spec.rb +41 -0
  71. data/spec/tap_spec.rb +59 -0
  72. data/spec/text_map_spec.rb +23 -0
  73. data/spec/type_map_spec.rb +17 -0
  74. data/spec/version_spec.rb +9 -0
  75. data/tasks/announce.rake +39 -0
  76. data/tasks/config.rb +110 -0
  77. data/tasks/distribution.rake +53 -0
  78. data/tasks/documentation.rake +33 -0
  79. data/tasks/extension.rake +100 -0
  80. data/tasks/rspec.rake +32 -0
  81. data/tasks/rubyforge.rake +59 -0
  82. data/tasks/utils.rb +80 -0
  83. metadata +192 -0
data/HISTORY ADDED
@@ -0,0 +1,81 @@
1
+ = Changelog
2
+ == Version 0.4.2 - 2008-10-12
3
+
4
+ === Minor Enhancements
5
+
6
+ * release of windows gem
7
+
8
+ == Version 0.4.1 - 2008-09-28
9
+
10
+ === Minor Enhancement
11
+
12
+ * update to SQLite3 version 3.6.3
13
+ * change rdoc template to darkfish
14
+
15
+ == Version 0.4.0 - 2008-09-14
16
+
17
+ === Major Enhancements
18
+ * update to SQLite3 version 3.6.2 and enable the RTree option by default
19
+ * Amalgalite::Requires module allowing ruby code to be 'required' from columns in an SQLite database
20
+ * Amagalite::Requires::Bootstrap extension module enabling low level boot
21
+ strapping of the pure ruby Amalgalite code from an sqlite database
22
+
23
+ === Minor Enhancements
24
+
25
+ * more indepth information about indexes is available via the Index class
26
+ * add support for sqlite3_status and sqlite3_db_status information
27
+
28
+ === Bugfixes
29
+
30
+ * fix nil exception when using a declared_data_type on primary key column that
31
+ has no declared_data_type
32
+ * when Database#transaction is passed a block, the return value is the return
33
+ value of the block
34
+ * nested transactions are 'faked'. Calling Database#transaction while
35
+ Databased#in_transaction? is true does not result in an exception, but
36
+ continues on in the current transaction.
37
+ * raise LoadError if required in the same program as sqlite3-ruby. These
38
+ libraries conflict with each other.
39
+
40
+ == Version 0.2.4 - 2008-07-13
41
+
42
+ === Bugfixes
43
+ * fix compilation when ruby is compiled without pthreads using
44
+
45
+ == Version 0.2.3 - 2008-07-12
46
+
47
+ === Bugfixes
48
+ * make sure file permissions are all read before shipping gem
49
+
50
+ == Version 0.2.2 - 2008-07-12
51
+
52
+ === Bugfixes
53
+ * Database#pragma should accept a block just like Database#execute does
54
+ * convert to using extconf.rb instead of mkrf to enable compilation as a
55
+ direct ruby extension in the ruby source tree
56
+
57
+ == Version 0.2.1 - 2008-07-05
58
+
59
+ === Bugfixes
60
+ * make sure that the pthread support in sqlite3 matches that of ruby
61
+ * fix schema reloading in the example scripts
62
+
63
+ == Version 0.2.0 - 2008-07-04
64
+
65
+ === Major Enhancements
66
+ * blob support, both incremental access and normal access
67
+
68
+ === Minor Enhancements
69
+ * added examples/gem_db.rb script demonstrating taps and prepared statements
70
+ * added examples/schema-info.rb script demonstrating meta information
71
+ * added examples/blob.rb demonstrating incremental blob IO
72
+ * added access to the SQLite3 errcode and errmsg api
73
+
74
+ === Bugfixes
75
+ * added taps.rb for requiring
76
+ * fixed prepared statement reset
77
+ * caught an error in executing prepared statements earlier in the process so the correct error is reported
78
+
79
+ == Version 0.1.0 - 2008-06-21
80
+
81
+ * Initial public release
data/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ Copyright (c) 2008, Jeremy Hinegardner
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice,
9
+ this list of conditions and the following disclaimer.
10
+
11
+ * Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ * Neither the name of Jeremy Hinegardner nor the names of its contributors
16
+ may be used to endorse or promote products derived from this software without
17
+ specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
22
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
23
+ OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README ADDED
@@ -0,0 +1,40 @@
1
+ == Amalgalite
2
+
3
+ * Homepage[http://copiousfreetime.rubyforge.org/amalgalite]
4
+ * {Rubyforge Project}[http://rubyforge.org/projects/copiousfreetime/]
5
+ * email jeremy at copiousfreetime dot org
6
+ * git clone url git://github.com/copiousfreetime/amalgalite.git
7
+
8
+ == INSTALL
9
+
10
+ * gem install amalgalite
11
+
12
+ == DESCRIPTION
13
+
14
+ Amalgalite embeds the SQLite database engine in a ruby extension. There is no
15
+ need to install SQLite separately.
16
+
17
+ Look in the examples/ directory to see
18
+
19
+ * general usage
20
+ * blob io
21
+ * schema information
22
+
23
+ Also Scroll through Amalgalite::Database for a quick example, and a general
24
+ overview of the API.
25
+
26
+ == CREDITS
27
+
28
+ * Jamis Buck for the first {ruby sqlite implementation}[http://www.rubyforge.org/projects/sqlite-ruby]
29
+
30
+ == CHANGES
31
+
32
+ Read the HISTORY file.
33
+
34
+ == LICENSE
35
+
36
+ Copyright (c) 2008 Jeremy Hinegardner
37
+
38
+ All rights reserved.
39
+
40
+ See LICENSE and/or COPYING for details.
@@ -0,0 +1,155 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ #
6
+ # A commandline utility to pack all of amalgalite into a database so that it can
7
+ # be loaded with the C extension only.
8
+ #
9
+
10
+ #
11
+ # given a file, see if it can be found in the ruby load path, if so, return that
12
+ # full path
13
+ #
14
+ def full_path_of( rb_file )
15
+ $:.each do |load_path|
16
+ guess = File.join( load_path, rb_file )
17
+ return guess if File.exist?( guess )
18
+ end
19
+ return nil
20
+ end
21
+
22
+ OPTIONS = { :force => false }
23
+
24
+ parser = OptionParser.new do |op|
25
+ op.banner = "Usage: #{op.program_name} [options] <dbfile>"
26
+ op.separator ""
27
+
28
+ op.on("-f", "--force", "Force overwriting of an existing database") do |f|
29
+ OPTIONS[:force]= true
30
+ end
31
+
32
+ end
33
+
34
+ begin
35
+ parser.parse!
36
+ rescue OptionParser::ParseError => pe
37
+ STDERR.puts "ERROR : #{pe}"
38
+ STDERR.puts parser
39
+ exit 1
40
+ end
41
+
42
+ #
43
+ # capture before and after snapshots of the loaded features to see what changed
44
+ # when we required amalgalite
45
+ #
46
+ require 'rubygems'
47
+ $: << "lib"
48
+ $: << "ext"
49
+ loaded_features_before = $".dup
50
+ require 'amalgalite/requires'
51
+ loaded_features_after = $".dup
52
+
53
+ #
54
+ # reorder the items that should be required, putting the system level .rb files
55
+ # first in the list
56
+ #
57
+ amalgalite_needs = loaded_features_after - loaded_features_before
58
+ core_libs = (amalgalite_needs - Amalgalite::Requires.require_order).delete_if { |l| l.index(".rb").nil? }
59
+
60
+ #
61
+ # check and make sure nothing is missed
62
+ #
63
+ core_libs.each do |l|
64
+ if l.index("malgalite") then
65
+ STDERR.puts "ERROR! require_order needs an update #{l}"
66
+ STDERR.puts "run rake test:check_requries and fix"
67
+ exit 2
68
+ end
69
+ end
70
+ amalgalite_needs = core_libs.concat( Amalgalite::Requires.require_order )
71
+
72
+
73
+ # width value for tidy output
74
+ max_width = amalgalite_needs.sort_by { |l| l.length }.last.length
75
+
76
+ #
77
+ # Get the filename, and do not overwrite if the file already exists, unless of
78
+ # course, --force is used
79
+ #
80
+ dbfile = ARGV.shift || Amalgalite::Requires::Bootstrap::DEFAULT_DB
81
+ if OPTIONS[:force] then
82
+ File.unlink( dbfile ) if File.exist?( dbfile )
83
+ end
84
+
85
+ if File.exist?( dbfile ) then
86
+ STDERR.puts "ERROR: #{dbfile} already exists, erase manually or use '--force' option"
87
+ STDERR.puts parser
88
+ exit 1
89
+ end
90
+
91
+
92
+ #
93
+ # Create the datbase
94
+ #
95
+ puts "Creating database #{dbfile}"
96
+ db = Amalgalite::Database.new( dbfile )
97
+ table_name = Amalgalite::Requires::Bootstrap::DEFAULT_TABLE
98
+ rowid_col = Amalgalite::Requires::Bootstrap::DEFAULT_ROWID_COLUMN
99
+ filename_col = Amalgalite::Requires::Bootstrap::DEFAULT_FILENAME_COLUMN
100
+ contents_col = Amalgalite::Requires::Bootstrap::DEFAULT_CONTENTS_COLUMN
101
+ db.execute(<<-create)
102
+ CREATE TABLE #{table_name} (
103
+ #{rowid_col} INTEGER PRIMARY KEY AUTOINCREMENT,
104
+ #{filename_col} TEXT UNIQUE,
105
+ #{contents_col} BLOB
106
+ )
107
+ create
108
+ db.reload_schema!
109
+
110
+ #
111
+ # for every file in the list, insert it into the database
112
+ #
113
+ db.transaction do |dbt|
114
+ db.prepare( "INSERT INTO #{table_name}(#{filename_col}, #{contents_col}) VALUES ( $filename, $contents )" ) do |stmt|
115
+ amalgalite_needs.each do |am_requires|
116
+
117
+ msg = " skipped, probably a binary extension"
118
+
119
+ if File.extname( am_requires ) == ".rb" then
120
+ full_path = File.expand_path( full_path_of( am_requires ) )
121
+
122
+ if full_path and File.readable?( full_path ) then
123
+ contents = IO.readlines( full_path )
124
+ contents.each { |l| l.gsub!( /^(\s*require .*)$/m, "# commented out by #{parser.program_name} \\1") }
125
+ # strip off the .rb
126
+ rq = am_requires[ /\A(.*)\.rb\Z/, 1]
127
+ stmt.execute( { "$filename" => rq,
128
+ "$contents" => Amalgalite::Blob.new( :string => contents.join,
129
+ :column => dbt.schema.tables[table_name].columns[contents_col] ) } )
130
+ msg = "stored #{full_path}"
131
+ end
132
+
133
+ puts " -> #{am_requires.ljust( max_width )} : #{msg}"
134
+ else
135
+ STDERR.puts "ERROR : #{am_requires} is an invalid file to pack"
136
+ end
137
+ end
138
+ end
139
+ end
140
+ db.close
141
+
142
+ puts <<-text
143
+
144
+ Packing complete. To utilize the bootstrapping in #{dbfile} you must do
145
+ one of the following:
146
+
147
+ * statically compile the amalgalite C extension into your application
148
+ * require 'amalgalite3'
149
+
150
+ Once one of those is working you can boostrap the Amalgalite library with
151
+ this line in your code:
152
+
153
+ Amalgalite::Requries::Boostrap.lift( 'dbfile' => '#{dbfile}' )
154
+
155
+ text
data/examples/a.rb ADDED
@@ -0,0 +1,9 @@
1
+ class A
2
+ def initialize
3
+ puts "Initialized A"
4
+ end
5
+
6
+ def a
7
+ puts "called a"
8
+ end
9
+ end
data/examples/blob.rb ADDED
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # An Amalgalite example showing how Blob's can be utilized
5
+ #
6
+ # We'll make a database with one table, that we store files in. We'll use the
7
+ # Blob incremental IO to store the files and retrieve them from the database
8
+ #
9
+ # This little program will store 1 or more files in the sqlite3 database when
10
+ # the 'store' action is given, and cat a file to stdout on 'retrieve'
11
+ #
12
+ # e.g.
13
+ #
14
+ # ruby blob.rb store a.rb b.rb c.rb # => stores a.rb b.rb and c.rb in the db
15
+ #
16
+ # ruby blob.rb retrieve a.rb # => dumps a.rb to stdout
17
+ #
18
+
19
+ require 'rubygems'
20
+ require 'amalgalite'
21
+ VALID_ACTIONS = %w[ list retrieve store ]
22
+ def usage
23
+ STDERR.puts "Usage: #{File.basename($0)} ( #{VALID_ACTIONS.join(' | ')} ) file(s)"
24
+ exit 1
25
+ end
26
+
27
+ #
28
+ # This does the basic command line parsing
29
+ #
30
+ usage if ARGV.size < 1
31
+ action = ARGV.shift
32
+ usage unless VALID_ACTIONS.include? action
33
+ file_list = ARGV
34
+
35
+ #
36
+ # create the database if it doesn't exist
37
+ #
38
+ db = Amalgalite::Database.new( "filestore.db" )
39
+ unless db.schema.tables['files']
40
+ STDERR.puts "Creating files table"
41
+ db.execute(<<-create)
42
+ CREATE TABLE files(
43
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
44
+ path VARCHAR UNIQUE,
45
+ data BLOB
46
+ )
47
+ create
48
+ db.reload_schema!
49
+ end
50
+
51
+
52
+ case action
53
+ #
54
+ # list all the files that are stored in the database
55
+ #
56
+ when 'list'
57
+ db.execute("SELECT path FROM files") do |row|
58
+ puts row['path']
59
+ end
60
+
61
+ #
62
+ # if we are doing the store action, then loop over the files and store them in
63
+ # the database. This will use incremental IO to store the files directly from
64
+ # the file names.
65
+ #
66
+ # It is slightly strange in that you have to tell the Blob object what column
67
+ # it is going to, but that is necessary at this point to be able to hook
68
+ # automatically into the lower level incremental blob IO api.
69
+ #
70
+ # This also shows using the $var syntax for binding name sql values in a
71
+ # prepared statement.
72
+ #
73
+ when 'store'
74
+ usage if file_list.empty?
75
+ db.transaction do |db_in_trans|
76
+ db_in_trans.prepare("INSERT INTO files(path, data) VALUES( $path, $data )") do |stmt|
77
+ file_list.each do |file_path|
78
+ begin
79
+ if File.exist?( file_path ) then
80
+ stmt.execute( "$path" => file_path,
81
+ "$data" => Amalgalite::Blob.new( :file => file_path, :column => db_in_trans.schema.tables['files'].columns['data'] ) )
82
+ STDERR.puts "inserted #{file_path} with id #{db.last_insert_rowid}"
83
+ else
84
+ STDERR.puts "#{file_path} does not exist"
85
+ end
86
+ rescue => e
87
+ STDERR.puts e
88
+ end
89
+ end
90
+ end
91
+ end
92
+ STDERR.puts "inserted a total of #{db.total_changes} changes"
93
+
94
+ #
95
+ # dump the file that matches the right path to stdout. This also shows
96
+ # positional sql varible binding using the '?' syntax.
97
+ #
98
+ when 'retrieve'
99
+ usage if file_list.empty?
100
+ db.execute("SELECT id, path, data FROM files WHERE path = ?", file_list.first) do |row|
101
+ STDERR.puts "Dumping #{row['path']} to stdout"
102
+ row['data'].write_to_io( STDOUT )
103
+ end
104
+ end
105
+ db.close
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # An example of requiring all the files in a table via the Bootstrap::lift
4
+ # method.
5
+ #
6
+ # First use the blob.rb example in this same directory to load the a.rb file
7
+ # into an example database:
8
+ #
9
+ # ruby blob.rb store a.rb
10
+ #
11
+ # Then run this example.
12
+ #
13
+
14
+ # Require "ONLY" then binary extension, do not +require+ the ruby based code
15
+ $: << "../ext"
16
+ require 'amalgalite3'
17
+
18
+ # See what the load path is, notice that it is very small
19
+ puts "Before $\" : #{$".inspect}"
20
+
21
+ # tell the binary extension to "require" every file in the filestore.db in the
22
+ # table 'files' orderd by column 'id'. The 'path' column is added to $" and the
23
+ # code in 'data' is evaled.
24
+ Amalgalite::Requires::Bootstrap.lift( "dbfile" => "filestore.db",
25
+ "table_name" => "files",
26
+ "rowid_column" => "id",
27
+ "filename_column" => "path",
28
+ "contents_column" => "data" )
29
+
30
+ # Notice that a.rb is in the list of files that has been required
31
+ puts "After $\" : #{$".inspect}"
32
+
33
+ # and look we prove that the code was eval'd appropriately
34
+ a = A.new
35
+ a.a
36
+