sqlite3 1.7.3-x64-mingw-ucrt → 2.0.0-x64-mingw-ucrt
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +152 -0
- data/CONTRIBUTING.md +23 -1
- data/FAQ.md +0 -43
- data/INSTALLATION.md +13 -5
- data/LICENSE +18 -22
- data/README.md +75 -4
- data/dependencies.yml +10 -11
- data/ext/sqlite3/aggregator.c +142 -145
- data/ext/sqlite3/aggregator.h +2 -4
- data/ext/sqlite3/backup.c +74 -65
- data/ext/sqlite3/backup.h +2 -2
- data/ext/sqlite3/database.c +535 -482
- data/ext/sqlite3/database.h +7 -4
- data/ext/sqlite3/exception.c +111 -92
- data/ext/sqlite3/exception.h +3 -1
- data/ext/sqlite3/extconf.rb +21 -22
- data/ext/sqlite3/sqlite3.c +159 -115
- data/ext/sqlite3/sqlite3_ruby.h +2 -2
- data/ext/sqlite3/statement.c +516 -300
- data/ext/sqlite3/statement.h +3 -3
- data/ext/sqlite3/timespec.h +20 -0
- data/lib/sqlite3/3.1/sqlite3_native.so +0 -0
- data/lib/sqlite3/3.2/sqlite3_native.so +0 -0
- data/lib/sqlite3/3.3/sqlite3_native.so +0 -0
- data/lib/sqlite3/constants.rb +171 -47
- data/lib/sqlite3/database.rb +105 -165
- data/lib/sqlite3/errors.rb +26 -1
- data/lib/sqlite3/pragmas.rb +126 -136
- data/lib/sqlite3/resultset.rb +14 -97
- data/lib/sqlite3/statement.rb +58 -13
- data/lib/sqlite3/value.rb +17 -20
- data/lib/sqlite3/version.rb +1 -21
- data/lib/sqlite3.rb +6 -4
- metadata +3 -28
- data/API_CHANGES.md +0 -49
- data/ChangeLog.cvs +0 -88
- data/Gemfile +0 -10
- data/LICENSE-DEPENDENCIES +0 -20
- data/lib/sqlite3/translator.rb +0 -117
- data/test/helper.rb +0 -27
- data/test/test_backup.rb +0 -33
- data/test/test_collation.rb +0 -82
- data/test/test_database.rb +0 -668
- data/test/test_database_flags.rb +0 -95
- data/test/test_database_readonly.rb +0 -36
- data/test/test_database_readwrite.rb +0 -41
- data/test/test_deprecated.rb +0 -49
- data/test/test_encoding.rb +0 -165
- data/test/test_integration.rb +0 -507
- data/test/test_integration_aggregate.rb +0 -336
- data/test/test_integration_open_close.rb +0 -30
- data/test/test_integration_pending.rb +0 -115
- data/test/test_integration_resultset.rb +0 -142
- data/test/test_integration_statement.rb +0 -194
- data/test/test_pragmas.rb +0 -22
- data/test/test_result_set.rb +0 -47
- data/test/test_sqlite3.rb +0 -30
- data/test/test_statement.rb +0 -290
- data/test/test_statement_execute.rb +0 -39
data/lib/sqlite3/translator.rb
DELETED
@@ -1,117 +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 `SQLite3::Translator#add_translator`. Built-in translators are deprecated and will be removed in version 2.0.0.
|
40
|
-
eowarn
|
41
|
-
@translators[ type_name( type ) ] = block
|
42
|
-
end
|
43
|
-
|
44
|
-
# Translate the given string value to a value of the given type. In the
|
45
|
-
# absence of an installed translator block for the given type, the value
|
46
|
-
# itself is always returned. Further, +nil+ values are never translated,
|
47
|
-
# and are always passed straight through regardless of the type parameter.
|
48
|
-
def translate( type, value )
|
49
|
-
unless value.nil?
|
50
|
-
# FIXME: this is a hack to support Sequel
|
51
|
-
if type && %w{ datetime timestamp }.include?(type.downcase)
|
52
|
-
@translators[ type_name( type ) ].call( type, value.to_s )
|
53
|
-
else
|
54
|
-
@translators[ type_name( type ) ].call( type, value )
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# A convenience method for working with type names. This returns the "base"
|
60
|
-
# type name, without any parenthetical data.
|
61
|
-
def type_name( type )
|
62
|
-
@type_name_cache[type] ||= begin
|
63
|
-
type = "" if type.nil?
|
64
|
-
type = $1 if type =~ /^(.*?)\(/
|
65
|
-
type.upcase
|
66
|
-
end
|
67
|
-
end
|
68
|
-
private :type_name
|
69
|
-
|
70
|
-
# Register the default translators for the current Translator instance.
|
71
|
-
# This includes translators for most major SQL data types.
|
72
|
-
def register_default_translators
|
73
|
-
[ "time",
|
74
|
-
"timestamp" ].each { |type| add_translator( type ) { |t, v| Time.parse( v ) } }
|
75
|
-
|
76
|
-
add_translator( "date" ) { |t,v| Date.parse(v) }
|
77
|
-
add_translator( "datetime" ) { |t,v| DateTime.parse(v) }
|
78
|
-
|
79
|
-
[ "decimal",
|
80
|
-
"float",
|
81
|
-
"numeric",
|
82
|
-
"double",
|
83
|
-
"real",
|
84
|
-
"dec",
|
85
|
-
"fixed" ].each { |type| add_translator( type ) { |t,v| v.to_f } }
|
86
|
-
|
87
|
-
[ "integer",
|
88
|
-
"smallint",
|
89
|
-
"mediumint",
|
90
|
-
"int",
|
91
|
-
"bigint" ].each { |type| add_translator( type ) { |t,v| v.to_i } }
|
92
|
-
|
93
|
-
[ "bit",
|
94
|
-
"bool",
|
95
|
-
"boolean" ].each do |type|
|
96
|
-
add_translator( type ) do |t,v|
|
97
|
-
!( v.strip.gsub(/00+/,"0") == "0" ||
|
98
|
-
v.downcase == "false" ||
|
99
|
-
v.downcase == "f" ||
|
100
|
-
v.downcase == "no" ||
|
101
|
-
v.downcase == "n" )
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
add_translator( "tinyint" ) do |type, value|
|
106
|
-
if type =~ /\(\s*1\s*\)/
|
107
|
-
value.to_i == 1
|
108
|
-
else
|
109
|
-
value.to_i
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
private :register_default_translators
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
data/test/helper.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'sqlite3'
|
2
|
-
require 'minitest/autorun'
|
3
|
-
|
4
|
-
if ENV['GITHUB_ACTIONS'] == 'true' || ENV['CI']
|
5
|
-
$VERBOSE = nil
|
6
|
-
end
|
7
|
-
|
8
|
-
puts "info: sqlite3-ruby version: #{SQLite3::VERSION}/#{SQLite3::VersionProxy::STRING}"
|
9
|
-
puts "info: sqlite3 version: #{SQLite3::SQLITE_VERSION}/#{SQLite3::SQLITE_LOADED_VERSION}"
|
10
|
-
puts "info: sqlcipher?: #{SQLite3.sqlcipher?}"
|
11
|
-
puts "info: threadsafe?: #{SQLite3.threadsafe?}"
|
12
|
-
|
13
|
-
unless RUBY_VERSION >= "1.9"
|
14
|
-
require 'iconv'
|
15
|
-
end
|
16
|
-
|
17
|
-
module SQLite3
|
18
|
-
class TestCase < Minitest::Test
|
19
|
-
alias :assert_not_equal :refute_equal
|
20
|
-
alias :assert_not_nil :refute_nil
|
21
|
-
alias :assert_raise :assert_raises
|
22
|
-
|
23
|
-
def assert_nothing_raised
|
24
|
-
yield
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/test/test_backup.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
module SQLite3
|
4
|
-
class TestBackup < SQLite3::TestCase
|
5
|
-
def setup
|
6
|
-
@sdb = SQLite3::Database.new(':memory:')
|
7
|
-
@ddb = SQLite3::Database.new(':memory:')
|
8
|
-
@sdb.execute('CREATE TABLE foo (idx, val);');
|
9
|
-
@data = ('A'..'Z').map{|x|x * 40}
|
10
|
-
@data.each_with_index do |v, i|
|
11
|
-
@sdb.execute('INSERT INTO foo (idx, val) VALUES (?, ?);', [i, v])
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_backup_step
|
16
|
-
b = SQLite3::Backup.new(@ddb, 'main', @sdb, 'main')
|
17
|
-
while b.step(1) == SQLite3::Constants::ErrorCode::OK
|
18
|
-
assert_not_equal(0, b.remaining)
|
19
|
-
end
|
20
|
-
assert_equal(0, b.remaining)
|
21
|
-
b.finish
|
22
|
-
assert_equal(@data.length, @ddb.execute('SELECT * FROM foo;').length)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_backup_all
|
26
|
-
b = SQLite3::Backup.new(@ddb, 'main', @sdb, 'main')
|
27
|
-
assert_equal(SQLite3::Constants::ErrorCode::DONE, b.step(-1))
|
28
|
-
assert_equal(0, b.remaining)
|
29
|
-
b.finish
|
30
|
-
assert_equal(@data.length, @ddb.execute('SELECT * FROM foo;').length)
|
31
|
-
end
|
32
|
-
end if defined?(SQLite3::Backup)
|
33
|
-
end
|
data/test/test_collation.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
module SQLite3
|
6
|
-
class TestCollation < SQLite3::TestCase
|
7
|
-
class Comparator
|
8
|
-
attr_reader :calls
|
9
|
-
def initialize
|
10
|
-
@calls = []
|
11
|
-
end
|
12
|
-
|
13
|
-
def compare left, right
|
14
|
-
@calls << [left, right]
|
15
|
-
left <=> right
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def setup
|
20
|
-
@db = SQLite3::Database.new(':memory:')
|
21
|
-
@create = "create table ex(id int, data string)"
|
22
|
-
@db.execute(@create);
|
23
|
-
[ [1, 'hello'], [2, 'world'] ].each do |vals|
|
24
|
-
@db.execute('insert into ex (id, data) VALUES (?, ?)', vals)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_custom_collation
|
29
|
-
comparator = Comparator.new
|
30
|
-
|
31
|
-
@db.collation 'foo', comparator
|
32
|
-
|
33
|
-
assert_equal comparator, @db.collations['foo']
|
34
|
-
@db.execute('select data from ex order by 1 collate foo')
|
35
|
-
assert_equal 1, comparator.calls.length
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_remove_collation
|
39
|
-
comparator = Comparator.new
|
40
|
-
|
41
|
-
@db.collation 'foo', comparator
|
42
|
-
@db.collation 'foo', nil
|
43
|
-
|
44
|
-
assert_nil @db.collations['foo']
|
45
|
-
assert_raises(SQLite3::SQLException) do
|
46
|
-
@db.execute('select data from ex order by 1 collate foo')
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
if RUBY_VERSION >= '1.9.1'
|
51
|
-
def test_encoding
|
52
|
-
comparator = Comparator.new
|
53
|
-
@db.collation 'foo', comparator
|
54
|
-
@db.execute('select data from ex order by 1 collate foo')
|
55
|
-
|
56
|
-
a, b = *comparator.calls.first
|
57
|
-
|
58
|
-
assert_equal Encoding.find('UTF-8'), a.encoding
|
59
|
-
assert_equal Encoding.find('UTF-8'), b.encoding
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_encoding_default_internal
|
63
|
-
warn_before = $-w
|
64
|
-
$-w = false
|
65
|
-
before_enc = Encoding.default_internal
|
66
|
-
|
67
|
-
Encoding.default_internal = 'EUC-JP'
|
68
|
-
comparator = Comparator.new
|
69
|
-
@db.collation 'foo', comparator
|
70
|
-
@db.execute('select data from ex order by 1 collate foo')
|
71
|
-
|
72
|
-
a, b = *comparator.calls.first
|
73
|
-
|
74
|
-
assert_equal Encoding.find('EUC-JP'), a.encoding
|
75
|
-
assert_equal Encoding.find('EUC-JP'), b.encoding
|
76
|
-
ensure
|
77
|
-
Encoding.default_internal = before_enc
|
78
|
-
$-w = warn_before
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|