sqlite-ruby 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,115 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # * Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # * Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # * The names of its contributors may not be used to endorse or promote
17
+ # products derived from this software without specific prior written
18
+ # permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
24
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # =============================================================================
31
+ #++
32
+
33
+ $:.unshift "lib"
34
+
35
+ require 'base64'
36
+ require 'sqlite/translator'
37
+ require 'test/unit'
38
+
39
+ class TC_Translator < Test::Unit::TestCase
40
+
41
+ def setup
42
+ @translator = SQLite::Translator.new
43
+ end
44
+
45
+ def test_date_time
46
+ value = "2004-09-08 14:09:39"
47
+ expect = Time.mktime( 2004, 9, 8, 14, 9, 39 )
48
+
49
+ assert_equal expect, @translator.translate( "date", value )
50
+ assert_equal expect, @translator.translate( "datetime", value )
51
+ assert_equal expect, @translator.translate( "time", value )
52
+ end
53
+
54
+ def test_real
55
+ value = "3.1415"
56
+ expect = 3.1415
57
+
58
+ assert_equal expect, @translator.translate( "decimal", value )
59
+ assert_equal expect, @translator.translate( "float", value )
60
+ assert_equal expect, @translator.translate( "numeric", value )
61
+ assert_equal expect, @translator.translate( "double", value )
62
+ assert_equal expect, @translator.translate( "real", value )
63
+ assert_equal expect, @translator.translate( "dec", value )
64
+ assert_equal expect, @translator.translate( "fixed", value )
65
+ end
66
+
67
+ def test_integer
68
+ value = "128"
69
+ expect = 128
70
+
71
+ assert_equal expect, @translator.translate( "integer", value )
72
+ assert_equal expect, @translator.translate( "smallint", value )
73
+ assert_equal expect, @translator.translate( "mediumint", value )
74
+ assert_equal expect, @translator.translate( "int", value )
75
+ assert_equal expect, @translator.translate( "bigint", value )
76
+ end
77
+
78
+ def test_boolean
79
+ assert_equal true, @translator.translate( "bit", "1" )
80
+ assert_equal false, @translator.translate( "bit", "0" )
81
+ assert_equal false, @translator.translate( "bool", "0" )
82
+ assert_equal false, @translator.translate( "bool", "false" )
83
+ assert_equal false, @translator.translate( "bool", "f" )
84
+ assert_equal false, @translator.translate( "bool", "no" )
85
+ assert_equal false, @translator.translate( "bool", "n" )
86
+ assert_equal false, @translator.translate( "boolean", "0" )
87
+ assert_equal false, @translator.translate( "boolean", "false" )
88
+ assert_equal false, @translator.translate( "boolean", "f" )
89
+ assert_equal false, @translator.translate( "boolean", "no" )
90
+ assert_equal false, @translator.translate( "boolean", "n" )
91
+ assert_equal true, @translator.translate( "bool", "heck ya!" )
92
+ assert_equal true, @translator.translate( "boolean", "heck ya!" )
93
+ end
94
+
95
+ def test_timestamp
96
+ time = Time.mktime( 2004, 9, 8, 14, 9, 39 )
97
+ assert_equal time, @translator.translate( "timestamp", time.to_i.to_s )
98
+ end
99
+
100
+ def test_tinyint
101
+ assert_equal true, @translator.translate( "tinyint(1)", "1" )
102
+ assert_equal false, @translator.translate( "tinyint(1)", "0" )
103
+ assert_equal 16, @translator.translate( "tinyint", "16" )
104
+ end
105
+
106
+ def test_custom
107
+ @translator.add_translator( "object" ) { |t,v| Marshal.load( Base64.decode64( v ) ) }
108
+
109
+ value = { :one => "hello", :four => "blah" }
110
+ dump = Base64.encode64( Marshal.dump( value ) ).strip
111
+
112
+ assert_equal value, @translator.translate( "object", dump )
113
+ end
114
+
115
+ end
@@ -0,0 +1,55 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # * Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # * Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # * The names of its contributors may not be used to endorse or promote
17
+ # products derived from this software without specific prior written
18
+ # permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
24
+ # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ # =============================================================================
31
+ #++
32
+
33
+ $:.unshift "lib"
34
+
35
+ require 'sqlite'
36
+ require 'test/unit'
37
+
38
+ class TC_TypeTranslation < Test::Unit::TestCase
39
+
40
+ def setup
41
+ @db = SQLite::Database.open( "db/fixtures.db" )
42
+ @db.type_translation = true
43
+ end
44
+
45
+ def teardown
46
+ @db.close
47
+ end
48
+
49
+ def test_execute_no_block
50
+ rows = @db.execute( "select * from A order by name limit 2" )
51
+
52
+ assert_equal [ [nil, 6], ["Amber", 5] ], rows
53
+ end
54
+
55
+ end
data/test/tests.rb ADDED
@@ -0,0 +1,133 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # * Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # * Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # * The names of its contributors may not be used to endorse or promote
17
+ # products derived from this software without specific prior written
18
+ # permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ # POSSIBILITY OF SUCH DAMAGE.
31
+ # =============================================================================
32
+ #++
33
+
34
+ $:.unshift "lib"
35
+
36
+ require 'test/unit/testsuite'
37
+ require 'fileutils'
38
+ require 'rbconfig'
39
+
40
+ Dir.chdir( File.dirname( __FILE__ ) )
41
+
42
+ # =============================================================================
43
+ # ENSURE THAT THE EXTENSION LIBRARY IS AVAILABLE AND UP-TO-DATE
44
+ # =============================================================================
45
+
46
+ FileUtils.mkdir_p "lib"
47
+
48
+ ext_lib = "lib/sqlite_api.#{Config::CONFIG['DLEXT']}"
49
+ ext_src = %w{ ../ext/sqlite-api.c ../ext/extconf.rb }
50
+ unless FileUtils.uptodate?( ext_lib, ext_src )
51
+ FileUtils.mkdir_p "build", :verbose=>true
52
+ FileUtils.cp ext_src, "build"
53
+ FileUtils.cd( "build" ) do
54
+ puts "Building extension library"
55
+ system "ruby extconf.rb > /dev/null" or
56
+ fail "could not configure SQLite/Ruby module"
57
+ system "make > /dev/null" or
58
+ fail "could not build SQLite/Ruby module"
59
+ end
60
+ FileUtils.cp "build/sqlite_api.#{Config::CONFIG['DLEXT']}", "lib",
61
+ :verbose=>true
62
+ FileUtils.rm_rf "build"
63
+ end
64
+
65
+ Dir["../lib/**/*.rb"].map { |i| i[3..-1] }.each do |file|
66
+ unless FileUtils.uptodate?( file, "../#{file}" )
67
+ dir = File.dirname( file )
68
+ FileUtils.mkdir_p dir, :verbose=>true unless File.exist?( dir )
69
+ FileUtils.cp "../#{file}", file, :verbose=>true
70
+ end
71
+ end
72
+
73
+ # =============================================================================
74
+ # LOAD THE TEST CASES
75
+ # =============================================================================
76
+
77
+ Dir["**/tc_*.rb"].each { |file| load file }
78
+
79
+ class TS_AllTests
80
+ def self.suite
81
+ suite = Test::Unit::TestSuite.new( "All SQLite/Ruby Unit Tests" )
82
+
83
+ ObjectSpace.each_object( Class ) do |unit_test|
84
+ next unless unit_test.name =~ /^T[CS]_/ &&
85
+ unit_test.superclass == Test::Unit::TestCase
86
+ suite << unit_test.suite
87
+ end
88
+
89
+ return suite
90
+ end
91
+ end
92
+
93
+ require 'test/unit/ui/console/testrunner'
94
+ test_runner = Test::Unit::UI::Console::TestRunner
95
+
96
+ case ARGV[0]
97
+ when "GTK"
98
+ require 'test/unit/ui/gtk/testrunner'
99
+ test_runner = Test::Unit::UI::GTK::TestRunner
100
+ when "GTK2"
101
+ require 'test/unit/ui/gtk2/testrunner'
102
+ test_runner = Test::Unit::UI::GTK2::TestRunner
103
+ when "Fox"
104
+ require 'test/unit/ui/fox/testrunner'
105
+ test_runner = Test::Unit::UI::Fox::TestRunner
106
+ when "Tk"
107
+ require 'test/unit/ui/tk/testrunner'
108
+ test_runner = Test::Unit::Tk::Fox::TestRunner
109
+ end
110
+
111
+ use_reporter = ARGV.find { |arg| arg.downcase == "report" }
112
+
113
+ if use_reporter
114
+ begin
115
+ require 'test/unit/util/reporter'
116
+ rescue LoadError => l
117
+ use_reporter = false
118
+ end
119
+ end
120
+
121
+ FileUtils.rm_f "db/fixtures.db"
122
+ system "sqlite db/fixtures.db < db/fixtures.sql"
123
+
124
+ if use_reporter
125
+ path = File.join( File.dirname( __FILE__ ), "..", "report" )
126
+ FileUtils.mkdir_p path
127
+ Test::Unit::Util::Reporter.run( test_runner, TS_AllTests.suite, path, :html )
128
+ puts "An HTML report of these unit tests has been written to #{path}"
129
+ else
130
+ test_runner.run( TS_AllTests )
131
+ end
132
+
133
+ FileUtils.rm_f "db/fixtures.db"
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.1
3
+ specification_version: 1
4
+ name: sqlite-ruby
5
+ version: !ruby/object:Gem::Version
6
+ version: 2.0.3
7
+ date: 2004-09-20
8
+ summary: "SQLite/Ruby is a module to allow Ruby scripts to interface with a SQLite database. VERSIONS >=2.0.0 ARE BETA RELEASES. THEY ARE INTENDED FOR TESTING ONLY, AND SHOULD NOT BE CONSIDERED PRODUCTION-WORTHY YET."
9
+ require_paths:
10
+ - lib
11
+ author: Jamis Buck
12
+ email: jgb3@email.byu.edu
13
+ homepage: http://sqlite-ruby.rubyforge.org
14
+ rubyforge_project:
15
+ description:
16
+ autorequire: sqlite
17
+ default_executable:
18
+ bindir: bin
19
+ has_rdoc: true
20
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
21
+ requirements:
22
+ -
23
+ - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 1.8.0
26
+ version:
27
+ platform: ruby
28
+ files:
29
+ - doc/faq
30
+ - doc/faq/faq.html
31
+ - doc/faq/faq.yml
32
+ - doc/faq/faq.rb
33
+ - ext/extconf.rb
34
+ - ext/sqlite-api.c
35
+ - lib/sqlite.rb
36
+ - lib/sqlite
37
+ - lib/sqlite/statement.rb
38
+ - lib/sqlite/database.rb
39
+ - lib/sqlite/parsed_statement.rb
40
+ - lib/sqlite/translator.rb
41
+ - lib/sqlite/resultset.rb
42
+ - lib/sqlite/version.rb
43
+ - lib/sqlite/pragmas.rb
44
+ - test/db
45
+ - test/tc_parsed_statement.rb
46
+ - test/tc_api_core.rb
47
+ - test/tests.rb
48
+ - test/tc_pragmas.rb
49
+ - test/tc_arrayfields.rb
50
+ - test/tc_translator.rb
51
+ - test/tc_type_translation.rb
52
+ - test/tc_database.rb
53
+ - test/db/fixtures.sql
54
+ - README
55
+ test_files:
56
+ - test/tests.rb
57
+ rdoc_options:
58
+ - "--main"
59
+ - README
60
+ extra_rdoc_files:
61
+ - README
62
+ - ext/sqlite-api.c
63
+ executables: []
64
+ extensions:
65
+ - ext/extconf.rb
66
+ requirements: []
67
+ dependencies: []