sqlite3-full 1.3.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gemtest +0 -0
  3. data/API_CHANGES.rdoc +50 -0
  4. data/CHANGELOG.rdoc +278 -0
  5. data/ChangeLog.cvs +88 -0
  6. data/Gemfile +15 -0
  7. data/LICENSE +34 -0
  8. data/Manifest.txt +52 -0
  9. data/README.rdoc +90 -0
  10. data/Rakefile +10 -0
  11. data/ext/sqlite3/backup.c +168 -0
  12. data/ext/sqlite3/backup.h +15 -0
  13. data/ext/sqlite3/database.c +825 -0
  14. data/ext/sqlite3/database.h +15 -0
  15. data/ext/sqlite3/exception.c +94 -0
  16. data/ext/sqlite3/exception.h +8 -0
  17. data/ext/sqlite3/extconf.rb +86 -0
  18. data/ext/sqlite3/sqlite3.c +97 -0
  19. data/ext/sqlite3/sqlite3_ruby.h +52 -0
  20. data/ext/sqlite3/sqlite3amalgamation.c +153367 -0
  21. data/ext/sqlite3/statement.c +447 -0
  22. data/ext/sqlite3/statement.h +16 -0
  23. data/faq/faq.rb +145 -0
  24. data/faq/faq.yml +426 -0
  25. data/lib/sqlite3/constants.rb +49 -0
  26. data/lib/sqlite3/database.rb +590 -0
  27. data/lib/sqlite3/errors.rb +44 -0
  28. data/lib/sqlite3/pragmas.rb +280 -0
  29. data/lib/sqlite3/resultset.rb +195 -0
  30. data/lib/sqlite3/statement.rb +144 -0
  31. data/lib/sqlite3/translator.rb +118 -0
  32. data/lib/sqlite3/value.rb +57 -0
  33. data/lib/sqlite3/version.rb +25 -0
  34. data/lib/sqlite3.rb +10 -0
  35. data/setup.rb +1333 -0
  36. data/tasks/faq.rake +9 -0
  37. data/tasks/gem.rake +38 -0
  38. data/tasks/native.rake +52 -0
  39. data/tasks/vendor_sqlite3.rake +91 -0
  40. data/test/helper.rb +18 -0
  41. data/test/test_backup.rb +33 -0
  42. data/test/test_collation.rb +82 -0
  43. data/test/test_database.rb +367 -0
  44. data/test/test_database_readonly.rb +29 -0
  45. data/test/test_deprecated.rb +44 -0
  46. data/test/test_encoding.rb +153 -0
  47. data/test/test_integration.rb +572 -0
  48. data/test/test_integration_open_close.rb +30 -0
  49. data/test/test_integration_pending.rb +115 -0
  50. data/test/test_integration_resultset.rb +159 -0
  51. data/test/test_integration_statement.rb +194 -0
  52. data/test/test_result_set.rb +37 -0
  53. data/test/test_sqlite3.rb +9 -0
  54. data/test/test_statement.rb +260 -0
  55. data/test/test_statement_execute.rb +35 -0
  56. metadata +205 -0
@@ -0,0 +1,118 @@
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
@@ -0,0 +1,57 @@
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
@@ -0,0 +1,25 @@
1
+ module SQLite3
2
+
3
+ VERSION = '1.3.9.1'
4
+
5
+ module VersionProxy
6
+
7
+ MAJOR = 1
8
+ MINOR = 3
9
+ TINY = 9
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
data/lib/sqlite3.rb ADDED
@@ -0,0 +1,10 @@
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'