amalgalite 0.4.2-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +81 -0
- data/LICENSE +29 -0
- data/README +40 -0
- data/bin/amalgalite-pack-into-db +155 -0
- data/examples/a.rb +9 -0
- data/examples/blob.rb +105 -0
- data/examples/bootstrap.rb +36 -0
- data/examples/gem-db.rb +94 -0
- data/examples/requires.rb +54 -0
- data/examples/schema-info.rb +34 -0
- data/ext/amalgalite3.c +201 -0
- data/ext/amalgalite3.h +121 -0
- data/ext/amalgalite3_blob.c +241 -0
- data/ext/amalgalite3_constants.c +221 -0
- data/ext/amalgalite3_database.c +550 -0
- data/ext/amalgalite3_requires_bootstrap.c +210 -0
- data/ext/amalgalite3_statement.c +628 -0
- data/ext/extconf.rb +19 -0
- data/ext/gen_constants.rb +130 -0
- data/ext/rbconfig-mingw.rb +178 -0
- data/ext/sqlite3.c +97092 -0
- data/ext/sqlite3.h +6364 -0
- data/ext/sqlite3_options.h +4 -0
- data/ext/sqlite3ext.h +372 -0
- data/gemspec.rb +55 -0
- data/lib/amalgalite.rb +33 -0
- data/lib/amalgalite/blob.rb +186 -0
- data/lib/amalgalite/boolean.rb +42 -0
- data/lib/amalgalite/column.rb +86 -0
- data/lib/amalgalite/core_ext/kernel/require.rb +14 -0
- data/lib/amalgalite/database.rb +514 -0
- data/lib/amalgalite/index.rb +43 -0
- data/lib/amalgalite/paths.rb +70 -0
- data/lib/amalgalite/profile_tap.rb +130 -0
- data/lib/amalgalite/requires.rb +112 -0
- data/lib/amalgalite/schema.rb +115 -0
- data/lib/amalgalite/sqlite3.rb +6 -0
- data/lib/amalgalite/sqlite3/constants.rb +82 -0
- data/lib/amalgalite/sqlite3/database/status.rb +69 -0
- data/lib/amalgalite/sqlite3/status.rb +61 -0
- data/lib/amalgalite/sqlite3/version.rb +38 -0
- data/lib/amalgalite/statement.rb +394 -0
- data/lib/amalgalite/table.rb +36 -0
- data/lib/amalgalite/taps.rb +2 -0
- data/lib/amalgalite/taps/console.rb +27 -0
- data/lib/amalgalite/taps/io.rb +71 -0
- data/lib/amalgalite/trace_tap.rb +35 -0
- data/lib/amalgalite/type_map.rb +63 -0
- data/lib/amalgalite/type_maps/default_map.rb +167 -0
- data/lib/amalgalite/type_maps/storage_map.rb +41 -0
- data/lib/amalgalite/type_maps/text_map.rb +23 -0
- data/lib/amalgalite/version.rb +37 -0
- data/lib/amalgalite/view.rb +26 -0
- data/lib/amalgalite3.so +0 -0
- data/spec/amalgalite_spec.rb +4 -0
- data/spec/blob_spec.rb +81 -0
- data/spec/boolean_spec.rb +23 -0
- data/spec/database_spec.rb +238 -0
- data/spec/default_map_spec.rb +87 -0
- data/spec/integeration_spec.rb +111 -0
- data/spec/paths_spec.rb +28 -0
- data/spec/schema_spec.rb +60 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/sqlite3/constants_spec.rb +65 -0
- data/spec/sqlite3/database_status_spec.rb +36 -0
- data/spec/sqlite3/status_spec.rb +18 -0
- data/spec/sqlite3/version_spec.rb +14 -0
- data/spec/sqlite3_spec.rb +23 -0
- data/spec/statement_spec.rb +134 -0
- data/spec/storage_map_spec.rb +41 -0
- data/spec/tap_spec.rb +59 -0
- data/spec/text_map_spec.rb +23 -0
- data/spec/type_map_spec.rb +17 -0
- data/spec/version_spec.rb +9 -0
- data/tasks/announce.rake +39 -0
- data/tasks/config.rb +110 -0
- data/tasks/distribution.rake +53 -0
- data/tasks/documentation.rake +33 -0
- data/tasks/extension.rake +100 -0
- data/tasks/rspec.rake +32 -0
- data/tasks/rubyforge.rake +59 -0
- data/tasks/utils.rb +80 -0
- metadata +192 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2008 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
|
6
|
+
module Amalgalite
|
7
|
+
#
|
8
|
+
# a class representing the meta information about an SQLite table
|
9
|
+
#
|
10
|
+
class Table
|
11
|
+
# the schema object the table is associated with
|
12
|
+
attr_accessor :schema
|
13
|
+
|
14
|
+
# the table name
|
15
|
+
attr_reader :name
|
16
|
+
|
17
|
+
# the original sql that was used to create this table
|
18
|
+
attr_reader :sql
|
19
|
+
|
20
|
+
# hash of Index objects holding the meta informationa about the indexes
|
21
|
+
# on this table. The keys of the indexes variable is the index name
|
22
|
+
attr_accessor :indexes
|
23
|
+
|
24
|
+
# a hash of Column objects holding the meta information about the columns
|
25
|
+
# in this table. keys are the column names
|
26
|
+
attr_accessor :columns
|
27
|
+
|
28
|
+
def initialize( name, sql )
|
29
|
+
@name = name
|
30
|
+
@sql = sql
|
31
|
+
@indexes = {}
|
32
|
+
@columns = {}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2008 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
|
6
|
+
require 'amalgalite/taps/io'
|
7
|
+
|
8
|
+
module Amalgalite::Taps
|
9
|
+
#
|
10
|
+
# Class provide an IO tap that can write to $stdout
|
11
|
+
#
|
12
|
+
class Stdout < ::Amalgalite::Taps::IO
|
13
|
+
def initialize
|
14
|
+
super( $stdout )
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# This class provide an IO tap that can write to $stderr
|
20
|
+
#
|
21
|
+
class Stderr < ::Amalgalite::Taps::IO
|
22
|
+
def initialize
|
23
|
+
super( $stderr )
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2008 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
|
6
|
+
require 'amalgalite/profile_tap'
|
7
|
+
require 'stringio'
|
8
|
+
|
9
|
+
module Amalgalite
|
10
|
+
module Taps
|
11
|
+
#
|
12
|
+
# An IOTap is an easy way to send all top information to andy IO based
|
13
|
+
# object. Both profile and trace tap information can be captured
|
14
|
+
# This means you can send the events to STDOUT with:
|
15
|
+
#
|
16
|
+
# db.profile_tap = db.trace_tap = Amalgalite::Taps::Stdout.new
|
17
|
+
#
|
18
|
+
#
|
19
|
+
class IO
|
20
|
+
|
21
|
+
attr_reader :profile_tap
|
22
|
+
attr_reader :io
|
23
|
+
|
24
|
+
def initialize( io )
|
25
|
+
@io = io
|
26
|
+
@profile_tap = ProfileTap.new( self, 'output_profile_event' )
|
27
|
+
end
|
28
|
+
|
29
|
+
def trace( msg )
|
30
|
+
io.puts msg
|
31
|
+
end
|
32
|
+
|
33
|
+
# need a profile method, it routes through the profile tap which calls back
|
34
|
+
# to output_profile_event
|
35
|
+
def profile( msg, time )
|
36
|
+
@profile_tap.profile(msg, time)
|
37
|
+
end
|
38
|
+
|
39
|
+
def output_profile_event( msg, time )
|
40
|
+
io.puts "#{time} : #{msg}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def dump_profile
|
44
|
+
samplers.each do |s|
|
45
|
+
io.puts s.to_s
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def samplers
|
50
|
+
profile_tap.samplers
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# This class provides an IO tap that writes to a StringIO. The result is
|
56
|
+
# available via .to_s or .string.
|
57
|
+
#
|
58
|
+
class StringIO < ::Amalgalite::Taps::IO
|
59
|
+
def initialize
|
60
|
+
@stringio = ::StringIO.new
|
61
|
+
super( @stringio )
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_s
|
65
|
+
@stringio.string
|
66
|
+
end
|
67
|
+
alias :string :to_s
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2008 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
|
6
|
+
module Amalgalite
|
7
|
+
#
|
8
|
+
# A TraceTap receives tracing information from SQLite3. It receives the SQL
|
9
|
+
# statement being executed as a +msg+ just before the statement first begins
|
10
|
+
# executing.
|
11
|
+
#
|
12
|
+
# A TraceTap is a wrapper around another object and a method. The Tap object
|
13
|
+
# will receive the call to +trace+ and redirect that call to another object
|
14
|
+
# and method.
|
15
|
+
#
|
16
|
+
class TraceTap
|
17
|
+
|
18
|
+
attr_reader :delegate_obj
|
19
|
+
attr_reader :delegate_method
|
20
|
+
|
21
|
+
def initialize( wrapped_obj, send_to = 'trace' )
|
22
|
+
unless wrapped_obj.respond_to?( send_to )
|
23
|
+
raise Amalgalite::Error, "#{wrapped_obj.class.name} does not respond to #{send_to.to_s} "
|
24
|
+
end
|
25
|
+
|
26
|
+
@delegate_obj = wrapped_obj
|
27
|
+
@delegate_method = send_to
|
28
|
+
end
|
29
|
+
|
30
|
+
def trace( msg )
|
31
|
+
delegate_obj.send( delegate_method, msg )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2008 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
module Amalgalite
|
6
|
+
##
|
7
|
+
# TypeMap defines the protocol used between Ruby and SQLite for mapping
|
8
|
+
# binding types, used in prepared statements; and result types, used in
|
9
|
+
# returning objects from a query.
|
10
|
+
#
|
11
|
+
#
|
12
|
+
class TypeMap
|
13
|
+
##
|
14
|
+
# :call-seq:
|
15
|
+
# map.bind_type_of( obj ) -> DataType constant
|
16
|
+
#
|
17
|
+
# bind_type_of is called during the Statement#bind process to convert the
|
18
|
+
# bind parameter to the appropriate SQLite types. This method MUST return
|
19
|
+
# one of the valid constants in the namespace
|
20
|
+
# Amalgalite::SQLite::Constants::DataType
|
21
|
+
#
|
22
|
+
def bind_type_of( obj )
|
23
|
+
raise NotImplementedError, "bind_type_of has not been implemented"
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# :call-seq:
|
28
|
+
# map.result_value_of( declared_type, value ) -> String
|
29
|
+
#
|
30
|
+
# result_value_of is called during the result processing of column values
|
31
|
+
# to convert an SQLite database value into the appropriate Ruby class.
|
32
|
+
#
|
33
|
+
# +declared_type+ is the string from the original CREATE TABLE statment
|
34
|
+
# from which the column value originates. It may also be nil if the origin
|
35
|
+
# column cannot be determined.
|
36
|
+
#
|
37
|
+
# +value+ is the SQLite value from the column as either a Ruby String,
|
38
|
+
# Integer, Float or Amalgalite::Blob.
|
39
|
+
#
|
40
|
+
# result_value should return the value that is to be put into the result set
|
41
|
+
# for the query. It may do nothing, or it may do massive amounts of
|
42
|
+
# conversion.
|
43
|
+
def result_value_of( delcared_type, value )
|
44
|
+
raise NotImplementedError, "result_value_of has not been implemented"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# The TypeMaps module holds all typemaps that ship with Amagalite. They
|
50
|
+
# currently are:
|
51
|
+
#
|
52
|
+
# DefaultMap:: does a 'best-guess' mapping to convert as many types as
|
53
|
+
# possible to known ruby classes from known SQL types.
|
54
|
+
# StorageMap:: converts to a limited set of classes directly based
|
55
|
+
# upon the SQLite storage types
|
56
|
+
# TextMap:: Everything is Text ... everything everything everything
|
57
|
+
#
|
58
|
+
module TypeMaps
|
59
|
+
end
|
60
|
+
end
|
61
|
+
require 'amalgalite/type_maps/default_map'
|
62
|
+
require 'amalgalite/type_maps/storage_map'
|
63
|
+
require 'amalgalite/type_maps/text_map'
|
@@ -0,0 +1,167 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2008 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
|
6
|
+
require 'amalgalite/type_map'
|
7
|
+
require 'amalgalite3'
|
8
|
+
require 'time'
|
9
|
+
require 'date'
|
10
|
+
|
11
|
+
module Amalgalite::TypeMaps
|
12
|
+
##
|
13
|
+
# An Amalgalite::TypeMap that does its best to convert between Ruby classes
|
14
|
+
# and known SQL data types.
|
15
|
+
#
|
16
|
+
# Upon instantiation, DefaultMap generates a conversion map to try to figure
|
17
|
+
# out the best way to convert between populate SQL 'types' and ruby classes
|
18
|
+
#
|
19
|
+
class DefaultMap
|
20
|
+
class << self
|
21
|
+
def methods_handling_sql_types # :nodoc:
|
22
|
+
@methods_handling_sql_types ||= {
|
23
|
+
'date' => %w[ date ],
|
24
|
+
'datetime' => %w[ datetime ],
|
25
|
+
'time' => %w[ timestamp ],
|
26
|
+
'float' => %w[ double real numeric decimal ],
|
27
|
+
'integer' => %w[ integer tinyint smallint int int2 int4 int8 bigint serial bigserial ],
|
28
|
+
'string' => %w[ text char varchar character ],
|
29
|
+
'boolean' => %w[ bool boolean ],
|
30
|
+
'blob' => %w[ binary blob ],
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
# say what method to call to convert an sql type to a ruby type
|
35
|
+
#
|
36
|
+
def sql_to_method( sql_type ) # :nodoc:
|
37
|
+
unless @sql_to_method
|
38
|
+
@sql_to_method = {}
|
39
|
+
methods_handling_sql_types.each_pair do |method, sql_types|
|
40
|
+
sql_types.each { |t| @sql_to_method[t] = method }
|
41
|
+
end
|
42
|
+
end
|
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
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def initialize
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# A straight logical mapping (for me at least) of basic Ruby classes to SQLite types, if
|
64
|
+
# nothing can be found then default to TEXT.
|
65
|
+
#
|
66
|
+
def bind_type_of( obj )
|
67
|
+
case obj
|
68
|
+
when Float
|
69
|
+
::Amalgalite::SQLite3::Constants::DataType::FLOAT
|
70
|
+
when Fixnum
|
71
|
+
::Amalgalite::SQLite3::Constants::DataType::INTEGER
|
72
|
+
when NilClass
|
73
|
+
::Amalgalite::SQLite3::Constants::DataType::NULL
|
74
|
+
when ::Amalgalite::Blob
|
75
|
+
::Amalgalite::SQLite3::Constants::DataType::BLOB
|
76
|
+
else
|
77
|
+
::Amalgalite::SQLite3::Constants::DataType::TEXT
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
##
|
82
|
+
# Map the incoming value to an outgoing value. For some incoming values,
|
83
|
+
# there will be no change, but for some (i.e. Dates and Times) there is some
|
84
|
+
# conversion
|
85
|
+
#
|
86
|
+
def result_value_of( declared_type, value )
|
87
|
+
case value
|
88
|
+
when Numeric
|
89
|
+
return value
|
90
|
+
when NilClass
|
91
|
+
return value
|
92
|
+
when Amalgalite::Blob
|
93
|
+
return value
|
94
|
+
when String
|
95
|
+
if declared_type then
|
96
|
+
conversion_method = DefaultMap.sql_to_method( declared_type.downcase )
|
97
|
+
if conversion_method then
|
98
|
+
return send(conversion_method, value)
|
99
|
+
else
|
100
|
+
raise ::Amalgalite::Error, "Unable to convert SQL type of #{declared_type} to a Ruby class"
|
101
|
+
end
|
102
|
+
else
|
103
|
+
# unable to do any other conversion, just return what we have.
|
104
|
+
return value
|
105
|
+
end
|
106
|
+
else
|
107
|
+
raise ::Amalgalite::Error, "Unable to convert a class #{value.class.name} with value #{value.inspect}"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# convert a string to a date
|
113
|
+
#
|
114
|
+
def date( str )
|
115
|
+
Date.parse( str )
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# convert a string to a datetime
|
120
|
+
#
|
121
|
+
def datetime( str )
|
122
|
+
DateTime.parse( str )
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# convert a string to a Time
|
127
|
+
#
|
128
|
+
def time( str )
|
129
|
+
Time.parse( str )
|
130
|
+
end
|
131
|
+
|
132
|
+
##
|
133
|
+
# convert a string to a Float
|
134
|
+
#
|
135
|
+
def float( str )
|
136
|
+
Float( str )
|
137
|
+
end
|
138
|
+
|
139
|
+
##
|
140
|
+
# convert an string to an Integer
|
141
|
+
#
|
142
|
+
def integer( str )
|
143
|
+
Float( str ).to_i
|
144
|
+
end
|
145
|
+
|
146
|
+
##
|
147
|
+
# convert a string to a String, yes redundant I know.
|
148
|
+
#
|
149
|
+
def string( str )
|
150
|
+
str
|
151
|
+
end
|
152
|
+
|
153
|
+
##
|
154
|
+
# convert a string to true of false
|
155
|
+
#
|
156
|
+
def boolean( str )
|
157
|
+
::Amalgalite::Boolean.to_bool( str )
|
158
|
+
end
|
159
|
+
|
160
|
+
##
|
161
|
+
# convert a string to a blob
|
162
|
+
#
|
163
|
+
def blob( str )
|
164
|
+
::Amalgalite::Blob.new( :string => str )
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2008 Jeremy Hinegardner
|
3
|
+
# All rights reserved. See LICENSE and/or COPYING for details.
|
4
|
+
#++
|
5
|
+
|
6
|
+
require 'amalgalite/type_map'
|
7
|
+
require 'amalgalite3'
|
8
|
+
|
9
|
+
module Amalgalite::TypeMaps
|
10
|
+
##
|
11
|
+
# An Amalagliate TypeMap that has a one-to-one conversion between SQLite types
|
12
|
+
# and Ruby classes
|
13
|
+
#
|
14
|
+
class StorageMap < ::Amalgalite::TypeMap
|
15
|
+
##
|
16
|
+
# A straight logical mapping (for me at least) of basic Ruby classes to SQLite types, if
|
17
|
+
# nothing can be found then default to TEXT.
|
18
|
+
#
|
19
|
+
def bind_type_of( obj )
|
20
|
+
case obj
|
21
|
+
when Float
|
22
|
+
::Amalgalite::SQLite3::Constants::DataType::FLOAT
|
23
|
+
when Fixnum
|
24
|
+
::Amalgalite::SQLite3::Constants::DataType::INTEGER
|
25
|
+
when NilClass
|
26
|
+
::Amalgalite::SQLite3::Constants::DataType::NULL
|
27
|
+
when ::Amalgalite::Blob
|
28
|
+
::Amalgalite::SQLite3::Constants::DataType::BLOB
|
29
|
+
else
|
30
|
+
::Amalgalite::SQLite3::Constants::DataType::TEXT
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Do no mapping, just return the value as it was retrieved from SQLite.
|
36
|
+
#
|
37
|
+
def result_value_of( delcared_type, value )
|
38
|
+
return value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|