mockley_crew 1.1.9 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mockley_crew/version.rb +1 -1
- data/lib/mockley_crew.rb +2 -1
- metadata +1 -67
- data/vendor/gems/sqlite3/cache/sqlite3-1.3.13.gem +0 -0
- data/vendor/gems/sqlite3/extensions/x86_64-linux/2.5.0/sqlite3-1.3.13/gem.build_complete +0 -0
- data/vendor/gems/sqlite3/extensions/x86_64-linux/2.5.0/sqlite3-1.3.13/gem_make.out +0 -33
- data/vendor/gems/sqlite3/extensions/x86_64-linux/2.5.0/sqlite3-1.3.13/mkmf.log +0 -592
- data/vendor/gems/sqlite3/extensions/x86_64-linux/2.5.0/sqlite3-1.3.13/sqlite3/sqlite3_native.so +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/API_CHANGES.rdoc +0 -50
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/CHANGELOG.rdoc +0 -292
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ChangeLog.cvs +0 -88
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/Gemfile +0 -15
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/LICENSE +0 -27
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/Manifest.txt +0 -52
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/README.rdoc +0 -118
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/Rakefile +0 -10
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/Makefile +0 -263
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/backup.c +0 -168
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/backup.h +0 -15
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/backup.o +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/database.c +0 -888
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/database.h +0 -15
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/database.o +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/exception.c +0 -94
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/exception.h +0 -8
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/exception.o +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/extconf.rb +0 -71
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/sqlite3.c +0 -152
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/sqlite3.o +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/sqlite3_native.so +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/sqlite3_ruby.h +0 -52
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/statement.c +0 -447
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/statement.h +0 -16
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/ext/sqlite3/statement.o +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/faq/faq.rb +0 -145
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/faq/faq.yml +0 -426
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/constants.rb +0 -49
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/database.rb +0 -591
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/errors.rb +0 -44
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/pragmas.rb +0 -588
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/resultset.rb +0 -195
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/sqlite3_native.so +0 -0
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/statement.rb +0 -144
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/translator.rb +0 -118
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/value.rb +0 -57
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3/version.rb +0 -25
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/lib/sqlite3.rb +0 -15
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/setup.rb +0 -1333
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/tasks/faq.rake +0 -9
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/tasks/gem.rake +0 -38
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/tasks/native.rake +0 -52
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/tasks/vendor_sqlite3.rake +0 -97
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/helper.rb +0 -18
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_backup.rb +0 -33
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_collation.rb +0 -82
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_database.rb +0 -430
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_database_readonly.rb +0 -36
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_deprecated.rb +0 -44
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_encoding.rb +0 -155
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration.rb +0 -576
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration_open_close.rb +0 -30
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration_pending.rb +0 -115
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration_resultset.rb +0 -159
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_integration_statement.rb +0 -194
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_result_set.rb +0 -37
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_sqlite3.rb +0 -21
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_statement.rb +0 -260
- data/vendor/gems/sqlite3/gems/sqlite3-1.3.13/test/test_statement_execute.rb +0 -35
- data/vendor/gems/sqlite3/specifications/sqlite3-1.3.13.gemspec +0 -56
@@ -1,195 +0,0 @@
|
|
1
|
-
require 'sqlite3/constants'
|
2
|
-
require 'sqlite3/errors'
|
3
|
-
|
4
|
-
module SQLite3
|
5
|
-
|
6
|
-
# The ResultSet object encapsulates the enumerability of a query's output.
|
7
|
-
# It is a simple cursor over the data that the query returns. It will
|
8
|
-
# very rarely (if ever) be instantiated directly. Instead, clients should
|
9
|
-
# obtain a ResultSet instance via Statement#execute.
|
10
|
-
class ResultSet
|
11
|
-
include Enumerable
|
12
|
-
|
13
|
-
class ArrayWithTypes < Array # :nodoc:
|
14
|
-
attr_accessor :types
|
15
|
-
end
|
16
|
-
|
17
|
-
class ArrayWithTypesAndFields < Array # :nodoc:
|
18
|
-
attr_writer :types
|
19
|
-
attr_writer :fields
|
20
|
-
|
21
|
-
def types
|
22
|
-
warn(<<-eowarn) if $VERBOSE
|
23
|
-
#{caller[0]} is calling #{self.class}#types. This method will be removed in
|
24
|
-
sqlite3 version 2.0.0, please call the `types` method on the SQLite3::ResultSet
|
25
|
-
object that created this object
|
26
|
-
eowarn
|
27
|
-
@types
|
28
|
-
end
|
29
|
-
|
30
|
-
def fields
|
31
|
-
warn(<<-eowarn) if $VERBOSE
|
32
|
-
#{caller[0]} is calling #{self.class}#fields. This method will be removed in
|
33
|
-
sqlite3 version 2.0.0, please call the `columns` method on the SQLite3::ResultSet
|
34
|
-
object that created this object
|
35
|
-
eowarn
|
36
|
-
@fields
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# The class of which we return an object in case we want a Hash as
|
41
|
-
# result.
|
42
|
-
class HashWithTypesAndFields < Hash # :nodoc:
|
43
|
-
attr_writer :types
|
44
|
-
attr_writer :fields
|
45
|
-
|
46
|
-
def types
|
47
|
-
warn(<<-eowarn) if $VERBOSE
|
48
|
-
#{caller[0]} is calling #{self.class}#types. This method will be removed in
|
49
|
-
sqlite3 version 2.0.0, please call the `types` method on the SQLite3::ResultSet
|
50
|
-
object that created this object
|
51
|
-
eowarn
|
52
|
-
@types
|
53
|
-
end
|
54
|
-
|
55
|
-
def fields
|
56
|
-
warn(<<-eowarn) if $VERBOSE
|
57
|
-
#{caller[0]} is calling #{self.class}#fields. This method will be removed in
|
58
|
-
sqlite3 version 2.0.0, please call the `columns` method on the SQLite3::ResultSet
|
59
|
-
object that created this object
|
60
|
-
eowarn
|
61
|
-
@fields
|
62
|
-
end
|
63
|
-
|
64
|
-
def [] key
|
65
|
-
key = fields[key] if key.is_a? Numeric
|
66
|
-
super key
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# Create a new ResultSet attached to the given database, using the
|
71
|
-
# given sql text.
|
72
|
-
def initialize db, stmt
|
73
|
-
@db = db
|
74
|
-
@stmt = stmt
|
75
|
-
end
|
76
|
-
|
77
|
-
# Reset the cursor, so that a result set which has reached end-of-file
|
78
|
-
# can be rewound and reiterated.
|
79
|
-
def reset( *bind_params )
|
80
|
-
@stmt.reset!
|
81
|
-
@stmt.bind_params( *bind_params )
|
82
|
-
@eof = false
|
83
|
-
end
|
84
|
-
|
85
|
-
# Query whether the cursor has reached the end of the result set or not.
|
86
|
-
def eof?
|
87
|
-
@stmt.done?
|
88
|
-
end
|
89
|
-
|
90
|
-
# Obtain the next row from the cursor. If there are no more rows to be
|
91
|
-
# had, this will return +nil+. If type translation is active on the
|
92
|
-
# corresponding database, the values in the row will be translated
|
93
|
-
# according to their types.
|
94
|
-
#
|
95
|
-
# The returned value will be an array, unless Database#results_as_hash has
|
96
|
-
# been set to +true+, in which case the returned value will be a hash.
|
97
|
-
#
|
98
|
-
# For arrays, the column names are accessible via the +fields+ property,
|
99
|
-
# and the column types are accessible via the +types+ property.
|
100
|
-
#
|
101
|
-
# For hashes, the column names are the keys of the hash, and the column
|
102
|
-
# types are accessible via the +types+ property.
|
103
|
-
def next
|
104
|
-
if @db.results_as_hash
|
105
|
-
return next_hash
|
106
|
-
end
|
107
|
-
|
108
|
-
row = @stmt.step
|
109
|
-
return nil if @stmt.done?
|
110
|
-
|
111
|
-
if @db.type_translation
|
112
|
-
row = @stmt.types.zip(row).map do |type, value|
|
113
|
-
@db.translator.translate( type, value )
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
if row.respond_to?(:fields)
|
118
|
-
# FIXME: this can only happen if the translator returns something
|
119
|
-
# that responds to `fields`. Since we're removing the translator
|
120
|
-
# in 2.0, we can remove this branch in 2.0.
|
121
|
-
row = ArrayWithTypes.new(row)
|
122
|
-
else
|
123
|
-
# FIXME: the `fields` and `types` methods are deprecated on this
|
124
|
-
# object for version 2.0, so we can safely remove this branch
|
125
|
-
# as well.
|
126
|
-
row = ArrayWithTypesAndFields.new(row)
|
127
|
-
end
|
128
|
-
|
129
|
-
row.fields = @stmt.columns
|
130
|
-
row.types = @stmt.types
|
131
|
-
row
|
132
|
-
end
|
133
|
-
|
134
|
-
# Required by the Enumerable mixin. Provides an internal iterator over the
|
135
|
-
# rows of the result set.
|
136
|
-
def each
|
137
|
-
while node = self.next
|
138
|
-
yield node
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
# Provides an internal iterator over the rows of the result set where
|
143
|
-
# each row is yielded as a hash.
|
144
|
-
def each_hash
|
145
|
-
while node = next_hash
|
146
|
-
yield node
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
# Closes the statement that spawned this result set.
|
151
|
-
# <em>Use with caution!</em> Closing a result set will automatically
|
152
|
-
# close any other result sets that were spawned from the same statement.
|
153
|
-
def close
|
154
|
-
@stmt.close
|
155
|
-
end
|
156
|
-
|
157
|
-
# Queries whether the underlying statement has been closed or not.
|
158
|
-
def closed?
|
159
|
-
@stmt.closed?
|
160
|
-
end
|
161
|
-
|
162
|
-
# Returns the types of the columns returned by this result set.
|
163
|
-
def types
|
164
|
-
@stmt.types
|
165
|
-
end
|
166
|
-
|
167
|
-
# Returns the names of the columns returned by this result set.
|
168
|
-
def columns
|
169
|
-
@stmt.columns
|
170
|
-
end
|
171
|
-
|
172
|
-
# Return the next row as a hash
|
173
|
-
def next_hash
|
174
|
-
row = @stmt.step
|
175
|
-
return nil if @stmt.done?
|
176
|
-
|
177
|
-
# FIXME: type translation is deprecated, so this can be removed
|
178
|
-
# in 2.0
|
179
|
-
if @db.type_translation
|
180
|
-
row = @stmt.types.zip(row).map do |type, value|
|
181
|
-
@db.translator.translate( type, value )
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
# FIXME: this can be switched to a regular hash in 2.0
|
186
|
-
row = HashWithTypesAndFields[*@stmt.columns.zip(row).flatten]
|
187
|
-
|
188
|
-
# FIXME: these methods are deprecated for version 2.0, so we can remove
|
189
|
-
# this code in 2.0
|
190
|
-
row.fields = @stmt.columns
|
191
|
-
row.types = @stmt.types
|
192
|
-
row
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
Binary file
|
@@ -1,144 +0,0 @@
|
|
1
|
-
require 'sqlite3/errors'
|
2
|
-
require 'sqlite3/resultset'
|
3
|
-
|
4
|
-
class String
|
5
|
-
def to_blob
|
6
|
-
SQLite3::Blob.new( self )
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
module SQLite3
|
11
|
-
# A statement represents a prepared-but-unexecuted SQL query. It will rarely
|
12
|
-
# (if ever) be instantiated directly by a client, and is most often obtained
|
13
|
-
# via the Database#prepare method.
|
14
|
-
class Statement
|
15
|
-
include Enumerable
|
16
|
-
|
17
|
-
# This is any text that followed the first valid SQL statement in the text
|
18
|
-
# with which the statement was initialized. If there was no trailing text,
|
19
|
-
# this will be the empty string.
|
20
|
-
attr_reader :remainder
|
21
|
-
|
22
|
-
# Binds the given variables to the corresponding placeholders in the SQL
|
23
|
-
# text.
|
24
|
-
#
|
25
|
-
# See Database#execute for a description of the valid placeholder
|
26
|
-
# syntaxes.
|
27
|
-
#
|
28
|
-
# Example:
|
29
|
-
#
|
30
|
-
# stmt = db.prepare( "select * from table where a=? and b=?" )
|
31
|
-
# stmt.bind_params( 15, "hello" )
|
32
|
-
#
|
33
|
-
# See also #execute, #bind_param, Statement#bind_param, and
|
34
|
-
# Statement#bind_params.
|
35
|
-
def bind_params( *bind_vars )
|
36
|
-
index = 1
|
37
|
-
bind_vars.flatten.each do |var|
|
38
|
-
if Hash === var
|
39
|
-
var.each { |key, val| bind_param key, val }
|
40
|
-
else
|
41
|
-
bind_param index, var
|
42
|
-
index += 1
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# Execute the statement. This creates a new ResultSet object for the
|
48
|
-
# statement's virtual machine. If a block was given, the new ResultSet will
|
49
|
-
# be yielded to it; otherwise, the ResultSet will be returned.
|
50
|
-
#
|
51
|
-
# Any parameters will be bound to the statement using #bind_params.
|
52
|
-
#
|
53
|
-
# Example:
|
54
|
-
#
|
55
|
-
# stmt = db.prepare( "select * from table" )
|
56
|
-
# stmt.execute do |result|
|
57
|
-
# ...
|
58
|
-
# end
|
59
|
-
#
|
60
|
-
# See also #bind_params, #execute!.
|
61
|
-
def execute( *bind_vars )
|
62
|
-
reset! if active? || done?
|
63
|
-
|
64
|
-
bind_params(*bind_vars) unless bind_vars.empty?
|
65
|
-
@results = ResultSet.new(@connection, self)
|
66
|
-
|
67
|
-
step if 0 == column_count
|
68
|
-
|
69
|
-
yield @results if block_given?
|
70
|
-
@results
|
71
|
-
end
|
72
|
-
|
73
|
-
# Execute the statement. If no block was given, this returns an array of
|
74
|
-
# rows returned by executing the statement. Otherwise, each row will be
|
75
|
-
# yielded to the block.
|
76
|
-
#
|
77
|
-
# Any parameters will be bound to the statement using #bind_params.
|
78
|
-
#
|
79
|
-
# Example:
|
80
|
-
#
|
81
|
-
# stmt = db.prepare( "select * from table" )
|
82
|
-
# stmt.execute! do |row|
|
83
|
-
# ...
|
84
|
-
# end
|
85
|
-
#
|
86
|
-
# See also #bind_params, #execute.
|
87
|
-
def execute!( *bind_vars, &block )
|
88
|
-
execute(*bind_vars)
|
89
|
-
block_given? ? each(&block) : to_a
|
90
|
-
end
|
91
|
-
|
92
|
-
# Returns true if the statement is currently active, meaning it has an
|
93
|
-
# open result set.
|
94
|
-
def active?
|
95
|
-
!done?
|
96
|
-
end
|
97
|
-
|
98
|
-
# Return an array of the column names for this statement. Note that this
|
99
|
-
# may execute the statement in order to obtain the metadata; this makes it
|
100
|
-
# a (potentially) expensive operation.
|
101
|
-
def columns
|
102
|
-
get_metadata unless @columns
|
103
|
-
return @columns
|
104
|
-
end
|
105
|
-
|
106
|
-
def each
|
107
|
-
loop do
|
108
|
-
val = step
|
109
|
-
break self if done?
|
110
|
-
yield val
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
# Return an array of the data types for each column in this statement. Note
|
115
|
-
# that this may execute the statement in order to obtain the metadata; this
|
116
|
-
# makes it a (potentially) expensive operation.
|
117
|
-
def types
|
118
|
-
must_be_open!
|
119
|
-
get_metadata unless @types
|
120
|
-
@types
|
121
|
-
end
|
122
|
-
|
123
|
-
# Performs a sanity check to ensure that the statement is not
|
124
|
-
# closed. If it is, an exception is raised.
|
125
|
-
def must_be_open! # :nodoc:
|
126
|
-
if closed?
|
127
|
-
raise SQLite3::Exception, "cannot use a closed statement"
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
private
|
132
|
-
# A convenience method for obtaining the metadata about the query. Note
|
133
|
-
# that this will actually execute the SQL, which means it can be a
|
134
|
-
# (potentially) expensive operation.
|
135
|
-
def get_metadata
|
136
|
-
@columns = Array.new(column_count) do |column|
|
137
|
-
column_name column
|
138
|
-
end
|
139
|
-
@types = Array.new(column_count) do |column|
|
140
|
-
column_decltype column
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
@@ -1,118 +0,0 @@
|
|
1
|
-
require 'time'
|
2
|
-
require 'date'
|
3
|
-
|
4
|
-
module SQLite3
|
5
|
-
|
6
|
-
# The Translator class encapsulates the logic and callbacks necessary for
|
7
|
-
# converting string data to a value of some specified type. Every Database
|
8
|
-
# instance may have a Translator instance, in order to assist in type
|
9
|
-
# translation (Database#type_translation).
|
10
|
-
#
|
11
|
-
# Further, applications may define their own custom type translation logic
|
12
|
-
# by registering translator blocks with the corresponding database's
|
13
|
-
# translator instance (Database#translator).
|
14
|
-
class Translator
|
15
|
-
|
16
|
-
# Create a new Translator instance. It will be preinitialized with default
|
17
|
-
# translators for most SQL data types.
|
18
|
-
def initialize
|
19
|
-
@translators = Hash.new( proc { |type,value| value } )
|
20
|
-
@type_name_cache = {}
|
21
|
-
register_default_translators
|
22
|
-
end
|
23
|
-
|
24
|
-
# Add a new translator block, which will be invoked to process type
|
25
|
-
# translations to the given type. The type should be an SQL datatype, and
|
26
|
-
# may include parentheses (i.e., "VARCHAR(30)"). However, any parenthetical
|
27
|
-
# information is stripped off and discarded, so type translation decisions
|
28
|
-
# are made solely on the "base" type name.
|
29
|
-
#
|
30
|
-
# The translator block itself should accept two parameters, "type" and
|
31
|
-
# "value". In this case, the "type" is the full type name (including
|
32
|
-
# parentheses), so the block itself may include logic for changing how a
|
33
|
-
# type is translated based on the additional data. The "value" parameter
|
34
|
-
# is the (string) data to convert.
|
35
|
-
#
|
36
|
-
# The block should return the translated value.
|
37
|
-
def add_translator( type, &block ) # :yields: type, value
|
38
|
-
warn(<<-eowarn) if $VERBOSE
|
39
|
-
#{caller[0]} is calling `add_translator`.
|
40
|
-
Built in translators are deprecated and will be removed in version 2.0.0
|
41
|
-
eowarn
|
42
|
-
@translators[ type_name( type ) ] = block
|
43
|
-
end
|
44
|
-
|
45
|
-
# Translate the given string value to a value of the given type. In the
|
46
|
-
# absense of an installed translator block for the given type, the value
|
47
|
-
# itself is always returned. Further, +nil+ values are never translated,
|
48
|
-
# and are always passed straight through regardless of the type parameter.
|
49
|
-
def translate( type, value )
|
50
|
-
unless value.nil?
|
51
|
-
# FIXME: this is a hack to support Sequel
|
52
|
-
if type && %w{ datetime timestamp }.include?(type.downcase)
|
53
|
-
@translators[ type_name( type ) ].call( type, value.to_s )
|
54
|
-
else
|
55
|
-
@translators[ type_name( type ) ].call( type, value )
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# A convenience method for working with type names. This returns the "base"
|
61
|
-
# type name, without any parenthetical data.
|
62
|
-
def type_name( type )
|
63
|
-
@type_name_cache[type] ||= begin
|
64
|
-
type = "" if type.nil?
|
65
|
-
type = $1 if type =~ /^(.*?)\(/
|
66
|
-
type.upcase
|
67
|
-
end
|
68
|
-
end
|
69
|
-
private :type_name
|
70
|
-
|
71
|
-
# Register the default translators for the current Translator instance.
|
72
|
-
# This includes translators for most major SQL data types.
|
73
|
-
def register_default_translators
|
74
|
-
[ "time",
|
75
|
-
"timestamp" ].each { |type| add_translator( type ) { |t, v| Time.parse( v ) } }
|
76
|
-
|
77
|
-
add_translator( "date" ) { |t,v| Date.parse(v) }
|
78
|
-
add_translator( "datetime" ) { |t,v| DateTime.parse(v) }
|
79
|
-
|
80
|
-
[ "decimal",
|
81
|
-
"float",
|
82
|
-
"numeric",
|
83
|
-
"double",
|
84
|
-
"real",
|
85
|
-
"dec",
|
86
|
-
"fixed" ].each { |type| add_translator( type ) { |t,v| v.to_f } }
|
87
|
-
|
88
|
-
[ "integer",
|
89
|
-
"smallint",
|
90
|
-
"mediumint",
|
91
|
-
"int",
|
92
|
-
"bigint" ].each { |type| add_translator( type ) { |t,v| v.to_i } }
|
93
|
-
|
94
|
-
[ "bit",
|
95
|
-
"bool",
|
96
|
-
"boolean" ].each do |type|
|
97
|
-
add_translator( type ) do |t,v|
|
98
|
-
!( v.strip.gsub(/00+/,"0") == "0" ||
|
99
|
-
v.downcase == "false" ||
|
100
|
-
v.downcase == "f" ||
|
101
|
-
v.downcase == "no" ||
|
102
|
-
v.downcase == "n" )
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
add_translator( "tinyint" ) do |type, value|
|
107
|
-
if type =~ /\(\s*1\s*\)/
|
108
|
-
value.to_i == 1
|
109
|
-
else
|
110
|
-
value.to_i
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
private :register_default_translators
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'sqlite3/constants'
|
2
|
-
|
3
|
-
module SQLite3
|
4
|
-
|
5
|
-
class Value
|
6
|
-
attr_reader :handle
|
7
|
-
|
8
|
-
def initialize( db, handle )
|
9
|
-
@driver = db.driver
|
10
|
-
@handle = handle
|
11
|
-
end
|
12
|
-
|
13
|
-
def null?
|
14
|
-
type == :null
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_blob
|
18
|
-
@driver.value_blob( @handle )
|
19
|
-
end
|
20
|
-
|
21
|
-
def length( utf16=false )
|
22
|
-
if utf16
|
23
|
-
@driver.value_bytes16( @handle )
|
24
|
-
else
|
25
|
-
@driver.value_bytes( @handle )
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_f
|
30
|
-
@driver.value_double( @handle )
|
31
|
-
end
|
32
|
-
|
33
|
-
def to_i
|
34
|
-
@driver.value_int( @handle )
|
35
|
-
end
|
36
|
-
|
37
|
-
def to_int64
|
38
|
-
@driver.value_int64( @handle )
|
39
|
-
end
|
40
|
-
|
41
|
-
def to_s( utf16=false )
|
42
|
-
@driver.value_text( @handle, utf16 )
|
43
|
-
end
|
44
|
-
|
45
|
-
def type
|
46
|
-
case @driver.value_type( @handle )
|
47
|
-
when Constants::ColumnType::INTEGER then :int
|
48
|
-
when Constants::ColumnType::FLOAT then :float
|
49
|
-
when Constants::ColumnType::TEXT then :text
|
50
|
-
when Constants::ColumnType::BLOB then :blob
|
51
|
-
when Constants::ColumnType::NULL then :null
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module SQLite3
|
2
|
-
|
3
|
-
VERSION = '1.3.13'
|
4
|
-
|
5
|
-
module VersionProxy
|
6
|
-
|
7
|
-
MAJOR = 1
|
8
|
-
MINOR = 3
|
9
|
-
TINY = 13
|
10
|
-
BUILD = nil
|
11
|
-
|
12
|
-
STRING = [ MAJOR, MINOR, TINY, BUILD ].compact.join( "." )
|
13
|
-
#:beta-tag:
|
14
|
-
|
15
|
-
VERSION = ::SQLite3::VERSION
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.const_missing(name)
|
19
|
-
return super unless name == :Version
|
20
|
-
warn(<<-eowarn) if $VERBOSE
|
21
|
-
#{caller[0]}: SQLite::Version will be removed in sqlite3-ruby version 2.0.0
|
22
|
-
eowarn
|
23
|
-
VersionProxy
|
24
|
-
end
|
25
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
# support multiple ruby version (fat binaries under windows)
|
2
|
-
begin
|
3
|
-
RUBY_VERSION =~ /(\d+\.\d+)/
|
4
|
-
require "sqlite3/#{$1}/sqlite3_native"
|
5
|
-
rescue LoadError
|
6
|
-
require 'sqlite3/sqlite3_native'
|
7
|
-
end
|
8
|
-
|
9
|
-
require 'sqlite3/database'
|
10
|
-
require 'sqlite3/version'
|
11
|
-
|
12
|
-
module SQLite3
|
13
|
-
# Was sqlite3 compiled with thread safety on?
|
14
|
-
def self.threadsafe?; threadsafe > 0; end
|
15
|
-
end
|