sqlite3 1.6.3 → 2.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +615 -1
  3. data/CONTRIBUTING.md +103 -6
  4. data/{faq/faq.md → FAQ.md} +66 -79
  5. data/INSTALLATION.md +267 -0
  6. data/LICENSE +18 -22
  7. data/README.md +87 -124
  8. data/dependencies.yml +10 -11
  9. data/ext/sqlite3/aggregator.c +178 -178
  10. data/ext/sqlite3/aggregator.h +7 -4
  11. data/ext/sqlite3/backup.c +92 -65
  12. data/ext/sqlite3/backup.h +2 -2
  13. data/ext/sqlite3/database.c +964 -477
  14. data/ext/sqlite3/database.h +26 -4
  15. data/ext/sqlite3/exception.c +213 -94
  16. data/ext/sqlite3/exception.h +26 -1
  17. data/ext/sqlite3/extconf.rb +59 -29
  18. data/ext/sqlite3/sqlite3.c +190 -115
  19. data/ext/sqlite3/sqlite3_ruby.h +5 -2
  20. data/ext/sqlite3/statement.c +672 -297
  21. data/ext/sqlite3/statement.h +4 -3
  22. data/ext/sqlite3/timespec.h +29 -0
  23. data/lib/sqlite3/constants.rb +195 -47
  24. data/lib/sqlite3/database.rb +272 -225
  25. data/lib/sqlite3/errors.rb +54 -1
  26. data/lib/sqlite3/fork_safety.rb +66 -0
  27. data/lib/sqlite3/pragmas.rb +194 -141
  28. data/lib/sqlite3/resultset.rb +30 -111
  29. data/lib/sqlite3/statement.rb +105 -25
  30. data/lib/sqlite3/value.rb +17 -20
  31. data/lib/sqlite3/version.rb +2 -21
  32. data/lib/sqlite3/version_info.rb +17 -0
  33. data/lib/sqlite3.rb +8 -4
  34. data/ports/archives/sqlite-autoconf-3540100.tar.gz +0 -0
  35. metadata +16 -48
  36. data/API_CHANGES.md +0 -49
  37. data/ChangeLog.cvs +0 -88
  38. data/Gemfile +0 -11
  39. data/LICENSE-DEPENDENCIES +0 -20
  40. data/faq/faq.rb +0 -145
  41. data/faq/faq.yml +0 -426
  42. data/lib/sqlite3/translator.rb +0 -118
  43. data/ports/archives/sqlite-autoconf-3420000.tar.gz +0 -0
  44. data/test/helper.rb +0 -27
  45. data/test/test_backup.rb +0 -33
  46. data/test/test_collation.rb +0 -82
  47. data/test/test_database.rb +0 -569
  48. data/test/test_database_flags.rb +0 -95
  49. data/test/test_database_readonly.rb +0 -36
  50. data/test/test_database_readwrite.rb +0 -41
  51. data/test/test_deprecated.rb +0 -49
  52. data/test/test_encoding.rb +0 -165
  53. data/test/test_integration.rb +0 -507
  54. data/test/test_integration_aggregate.rb +0 -336
  55. data/test/test_integration_open_close.rb +0 -30
  56. data/test/test_integration_pending.rb +0 -115
  57. data/test/test_integration_resultset.rb +0 -142
  58. data/test/test_integration_statement.rb +0 -194
  59. data/test/test_pragmas.rb +0 -22
  60. data/test/test_result_set.rb +0 -47
  61. data/test/test_sqlite3.rb +0 -30
  62. data/test/test_statement.rb +0 -288
  63. data/test/test_statement_execute.rb +0 -39
data/faq/faq.yml DELETED
@@ -1,426 +0,0 @@
1
- ---
2
- - "How do I do a database query?":
3
- - "I just want an array of the rows...": >-
4
-
5
- Use the Database#execute method. If you don't give it a block, it will
6
- return an array of all the rows:
7
-
8
-
9
- <pre>
10
- require 'sqlite3'
11
-
12
- db = SQLite3::Database.new( "test.db" )
13
- rows = db.execute( "select * from test" )
14
- </pre>
15
-
16
- - "I'd like to use a block to iterate through the rows...": >-
17
-
18
- Use the Database#execute method. If you give it a block, each row of the
19
- result will be yielded to the block:
20
-
21
-
22
- <pre>
23
- require 'sqlite3'
24
-
25
- db = SQLite3::Database.new( "test.db" )
26
- db.execute( "select * from test" ) do |row|
27
- ...
28
- end
29
- </pre>
30
-
31
- - "I need to get the column names as well as the rows...": >-
32
-
33
- Use the Database#execute2 method. This works just like Database#execute;
34
- if you don't give it a block, it returns an array of rows; otherwise, it
35
- will yield each row to the block. _However_, the first row returned is
36
- always an array of the column names from the query:
37
-
38
-
39
- <pre>
40
- require 'sqlite3'
41
-
42
- db = SQLite3::Database.new( "test.db" )
43
- columns, *rows = db.execute2( "select * from test" )
44
-
45
- # or use a block:
46
-
47
- columns = nil
48
- db.execute2( "select * from test" ) do |row|
49
- if columns.nil?
50
- columns = row
51
- else
52
- # process row
53
- end
54
- end
55
- </pre>
56
-
57
- - "I just want the first row of the result set...": >-
58
-
59
- Easy. Just call Database#get_first_row:
60
-
61
-
62
- <pre>
63
- row = db.get_first_row( "select * from table" )
64
- </pre>
65
-
66
-
67
- This also supports bind variables, just like Database#execute
68
- and friends.
69
-
70
- - "I just want the first value of the first row of the result set...": >-
71
-
72
- Also easy. Just call Database#get_first_value:
73
-
74
-
75
- <pre>
76
- count = db.get_first_value( "select count(*) from table" )
77
- </pre>
78
-
79
-
80
- This also supports bind variables, just like Database#execute
81
- and friends.
82
-
83
- - "How do I prepare a statement for repeated execution?": >-
84
- If the same statement is going to be executed repeatedly, you can speed
85
- things up a bit by _preparing_ the statement. You do this via the
86
- Database#prepare method. It returns a Statement object, and you can
87
- then invoke #execute on that to get the ResultSet:
88
-
89
-
90
- <pre>
91
- stmt = db.prepare( "select * from person" )
92
-
93
- 1000.times do
94
- stmt.execute do |result|
95
- ...
96
- end
97
- end
98
-
99
- stmt.close
100
-
101
- # or, use a block
102
-
103
- db.prepare( "select * from person" ) do |stmt|
104
- 1000.times do
105
- stmt.execute do |result|
106
- ...
107
- end
108
- end
109
- end
110
- </pre>
111
-
112
-
113
- This is made more useful by the ability to bind variables to placeholders
114
- via the Statement#bind_param and Statement#bind_params methods. (See the
115
- next FAQ for details.)
116
-
117
- - "How do I use placeholders in an SQL statement?": >-
118
- Placeholders in an SQL statement take any of the following formats:
119
-
120
-
121
- * @?@
122
-
123
- * @?_nnn_@
124
-
125
- * @:_word_@
126
-
127
-
128
- Where _n_ is an integer, and _word_ is an alpha-numeric identifier (or
129
- number). When the placeholder is associated with a number, that number
130
- identifies the index of the bind variable to replace it with. When it
131
- is an identifier, it identifies the name of the corresponding bind
132
- variable. (In the instance of the first format--a single question
133
- mark--the placeholder is assigned a number one greater than the last
134
- index used, or 1 if it is the first.)
135
-
136
-
137
- For example, here is a query using these placeholder formats:
138
-
139
-
140
- <pre>
141
- select *
142
- from table
143
- where ( c = ?2 or c = ? )
144
- and d = :name
145
- and e = :1
146
- </pre>
147
-
148
-
149
- This defines 5 different placeholders: 1, 2, 3, and "name".
150
-
151
-
152
- You replace these placeholders by _binding_ them to values. This can be
153
- accomplished in a variety of ways.
154
-
155
-
156
- The Database#execute, and Database#execute2 methods all accept additional
157
- arguments following the SQL statement. These arguments are assumed to be
158
- bind parameters, and they are bound (positionally) to their corresponding
159
- placeholders:
160
-
161
-
162
- <pre>
163
- db.execute( "select * from table where a = ? and b = ?",
164
- "hello",
165
- "world" )
166
- </pre>
167
-
168
-
169
- The above would replace the first question mark with 'hello' and the
170
- second with 'world'. If the placeholders have an explicit index given, they
171
- will be replaced with the bind parameter at that index (1-based).
172
-
173
-
174
- If a Hash is given as a bind parameter, then its key/value pairs are bound
175
- to the placeholders. This is how you bind by name:
176
-
177
-
178
- <pre>
179
- db.execute( "select * from table where a = :name and b = :value",
180
- "name" => "bob",
181
- "value" => "priceless" )
182
- </pre>
183
-
184
-
185
- You can also bind explicitly using the Statement object itself. Just pass
186
- additional parameters to the Statement#execute statement:
187
-
188
-
189
- <pre>
190
- db.prepare( "select * from table where a = :name and b = ?" ) do |stmt|
191
- stmt.execute "value", "name" => "bob"
192
- end
193
- </pre>
194
-
195
-
196
- Or do a Database#prepare to get the Statement, and then use either
197
- Statement#bind_param or Statement#bind_params:
198
-
199
-
200
- <pre>
201
- stmt = db.prepare( "select * from table where a = :name and b = ?" )
202
-
203
- stmt.bind_param( "name", "bob" )
204
- stmt.bind_param( 1, "value" )
205
-
206
- # or
207
-
208
- stmt.bind_params( "value", "name" => "bob" )
209
- </pre>
210
-
211
- - "How do I discover metadata about a query?": >-
212
-
213
- If you ever want to know the names or types of the columns in a result
214
- set, you can do it in several ways.
215
-
216
-
217
- The first way is to ask the row object itself. Each row will have a
218
- property "fields" that returns an array of the column names. The row
219
- will also have a property "types" that returns an array of the column
220
- types:
221
-
222
-
223
- <pre>
224
- rows = db.execute( "select * from table" )
225
- p rows[0].fields
226
- p rows[0].types
227
- </pre>
228
-
229
-
230
- Obviously, this approach requires you to execute a statement that actually
231
- returns data. If you don't know if the statement will return any rows, but
232
- you still need the metadata, you can use Database#query and ask the
233
- ResultSet object itself:
234
-
235
-
236
- <pre>
237
- db.query( "select * from table" ) do |result|
238
- p result.columns
239
- p result.types
240
- ...
241
- end
242
- </pre>
243
-
244
-
245
- Lastly, you can use Database#prepare and ask the Statement object what
246
- the metadata are:
247
-
248
-
249
- <pre>
250
- stmt = db.prepare( "select * from table" )
251
- p stmt.columns
252
- p stmt.types
253
- </pre>
254
-
255
- - "I'd like the rows to be indexible by column name.": >-
256
- By default, each row from a query is returned as an Array of values. This
257
- means that you can only obtain values by their index. Sometimes, however,
258
- you would like to obtain values by their column name.
259
-
260
-
261
- The first way to do this is to set the Database property "results_as_hash"
262
- to true. If you do this, then all rows will be returned as Hash objects,
263
- with the column names as the keys. (In this case, the "fields" property
264
- is unavailable on the row, although the "types" property remains.)
265
-
266
-
267
- <pre>
268
- db.results_as_hash = true
269
- db.execute( "select * from table" ) do |row|
270
- p row['column1']
271
- p row['column2']
272
- end
273
- </pre>
274
-
275
-
276
- The other way is to use Ara Howard's
277
- "ArrayFields":http://rubyforge.org/projects/arrayfields
278
- module. Just require "arrayfields", and all of your rows will be indexable
279
- by column name, even though they are still arrays!
280
-
281
-
282
- <pre>
283
- require 'arrayfields'
284
-
285
- ...
286
- db.execute( "select * from table" ) do |row|
287
- p row[0] == row['column1']
288
- p row[1] == row['column2']
289
- end
290
- </pre>
291
-
292
- - "I'd like the values from a query to be the correct types, instead of String.": >-
293
- You can turn on "type translation" by setting Database#type_translation to
294
- true:
295
-
296
-
297
- <pre>
298
- db.type_translation = true
299
- db.execute( "select * from table" ) do |row|
300
- p row
301
- end
302
- </pre>
303
-
304
-
305
- By doing this, each return value for each row will be translated to its
306
- correct type, based on its declared column type.
307
-
308
-
309
- You can even declare your own translation routines, if (for example) you are
310
- using an SQL type that is not handled by default:
311
-
312
-
313
- <pre>
314
- # assume "objects" table has the following schema:
315
- # create table objects (
316
- # name varchar2(20),
317
- # thing object
318
- # )
319
-
320
- db.type_translation = true
321
- db.translator.add_translator( "object" ) do |type, value|
322
- db.decode( value )
323
- end
324
-
325
- h = { :one=>:two, "three"=>"four", 5=>6 }
326
- dump = db.encode( h )
327
-
328
- db.execute( "insert into objects values ( ?, ? )", "bob", dump )
329
-
330
- obj = db.get_first_value( "select thing from objects where name='bob'" )
331
- p obj == h
332
- </pre>
333
-
334
- - "How do I insert binary data into the database?": >-
335
- Use blobs. Blobs are new features of SQLite3. You have to use bind
336
- variables to make it work:
337
-
338
-
339
- <pre>
340
- db.execute( "insert into foo ( ?, ? )",
341
- SQLite3::Blob.new( "\0\1\2\3\4\5" ),
342
- SQLite3::Blob.new( "a\0b\0c\0d ) )
343
- </pre>
344
-
345
-
346
- The blob values must be indicated explicitly by binding each parameter to
347
- a value of type SQLite3::Blob.
348
-
349
- - "How do I do a DDL (insert, update, delete) statement?": >-
350
- You can actually do inserts, updates, and deletes in exactly the same way
351
- as selects, but in general the Database#execute method will be most
352
- convenient:
353
-
354
-
355
- <pre>
356
- db.execute( "insert into table values ( ?, ? )", *bind_vars )
357
- </pre>
358
-
359
- - "How do I execute multiple statements in a single string?": >-
360
- The standard query methods (Database#execute, Database#execute2,
361
- Database#query, and Statement#execute) will only execute the first
362
- statement in the string that is given to them. Thus, if you have a
363
- string with multiple SQL statements, each separated by a string,
364
- you can't use those methods to execute them all at once.
365
-
366
-
367
- Instead, use Database#execute_batch:
368
-
369
-
370
- <pre>
371
- sql = <<SQL
372
- create table the_table (
373
- a varchar2(30),
374
- b varchar2(30)
375
- );
376
-
377
- insert into the_table values ( 'one', 'two' );
378
- insert into the_table values ( 'three', 'four' );
379
- insert into the_table values ( 'five', 'six' );
380
- SQL
381
-
382
- db.execute_batch( sql )
383
- </pre>
384
-
385
-
386
- Unlike the other query methods, Database#execute_batch accepts no
387
- block. It will also only ever return +nil+. Thus, it is really only
388
- suitable for batch processing of DDL statements.
389
-
390
- - "How do I begin/end a transaction?":
391
- Use Database#transaction to start a transaction. If you give it a block,
392
- the block will be automatically committed at the end of the block,
393
- unless an exception was raised, in which case the transaction will be
394
- rolled back. (Never explicitly call Database#commit or Database#rollback
395
- inside of a transaction block--you'll get errors when the block
396
- terminates!)
397
-
398
-
399
- <pre>
400
- database.transaction do |db|
401
- db.execute( "insert into table values ( 'a', 'b', 'c' )" )
402
- ...
403
- end
404
- </pre>
405
-
406
-
407
- Alternatively, if you don't give a block to Database#transaction, the
408
- transaction remains open until you explicitly call Database#commit or
409
- Database#rollback.
410
-
411
-
412
- <pre>
413
- db.transaction
414
- db.execute( "insert into table values ( 'a', 'b', 'c' )" )
415
- db.commit
416
- </pre>
417
-
418
-
419
- Note that SQLite does not allow nested transactions, so you'll get errors
420
- if you try to open a new transaction while one is already active. Use
421
- Database#transaction_active? to determine whether a transaction is
422
- active or not.
423
-
424
- #- "How do I discover metadata about a table/index?":
425
- #
426
- #- "How do I do tweak database settings?":
@@ -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
- # absence 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
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
@@ -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