rubyfb 0.5.8 → 0.5.9
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.
- data/Manifest +3 -0
- data/Rakefile +1 -1
- data/ext/Blob.c +14 -7
- data/ext/Blob.h +4 -2
- data/ext/TypeMap.c +14 -37
- data/ext/rfbstr.c +28 -0
- data/ext/rfbstr.h +12 -0
- data/lib/rubyfb_lib.so +0 -0
- data/rubyfb.gemspec +9 -10
- data/test/BlobTest.rb +26 -0
- data/test/FieldCharacterSetTest.rb +48 -0
- data/test/StatementTest.rb +24 -0
- metadata +9 -8
data/Manifest
CHANGED
@@ -45,6 +45,8 @@ ext/TypeMap.h
|
|
45
45
|
ext/extconf.rb
|
46
46
|
ext/rfbint.h
|
47
47
|
ext/rfbsleep.h
|
48
|
+
ext/rfbstr.c
|
49
|
+
ext/rfbstr.h
|
48
50
|
ext/uncrustify.cfg
|
49
51
|
lib/Connection.rb
|
50
52
|
lib/ProcedureCall.rb
|
@@ -69,6 +71,7 @@ test/CharacterSetTest.rb
|
|
69
71
|
test/ConnectionTest.rb
|
70
72
|
test/DDLTest.rb
|
71
73
|
test/DatabaseTest.rb
|
74
|
+
test/FieldCharacterSetTest.rb
|
72
75
|
test/GeneratorTest.rb
|
73
76
|
test/KeyTest.rb
|
74
77
|
test/ResultSetTest.rb
|
data/Rakefile
CHANGED
data/ext/Blob.c
CHANGED
@@ -27,6 +27,7 @@
|
|
27
27
|
#include "Blob.h"
|
28
28
|
#include <limits.h>
|
29
29
|
#include "Common.h"
|
30
|
+
#include "rfbstr.h"
|
30
31
|
|
31
32
|
/* Function prototypes. */
|
32
33
|
static VALUE allocateBlob(VALUE);
|
@@ -67,12 +68,14 @@ static VALUE allocateBlob(VALUE klass) {
|
|
67
68
|
/**
|
68
69
|
* This function provides the initialize method for the Blob class.
|
69
70
|
*
|
70
|
-
* @param self
|
71
|
+
* @param self A reference to the Blob object to be initialized.
|
72
|
+
* @param connection A reference to the Connection object owning the blob.
|
71
73
|
*
|
72
74
|
* @return A reference to the newly initialized Blob object.
|
73
75
|
*
|
74
76
|
*/
|
75
|
-
VALUE initializeBlob(VALUE self) {
|
77
|
+
VALUE initializeBlob(VALUE self, VALUE connection) {
|
78
|
+
rb_iv_set(self, "@connection", connection);
|
76
79
|
rb_iv_set(self, "@data", Qnil);
|
77
80
|
return(self);
|
78
81
|
}
|
@@ -89,6 +92,7 @@ VALUE initializeBlob(VALUE self) {
|
|
89
92
|
*/
|
90
93
|
static VALUE getBlobData(VALUE self) {
|
91
94
|
VALUE data = rb_iv_get(self, "@data");
|
95
|
+
VALUE connection = rb_iv_get(self, "@connection");
|
92
96
|
|
93
97
|
if(data == Qnil) {
|
94
98
|
BlobHandle *blob = NULL;
|
@@ -98,7 +102,7 @@ static VALUE getBlobData(VALUE self) {
|
|
98
102
|
char *buffer = loadBlobData(blob);
|
99
103
|
|
100
104
|
if(buffer != NULL) {
|
101
|
-
data =
|
105
|
+
data = rfbstr(connection, blob->charset, buffer, blob->size);
|
102
106
|
}
|
103
107
|
free(buffer);
|
104
108
|
}
|
@@ -154,6 +158,7 @@ static VALUE eachBlobSegment(VALUE self) {
|
|
154
158
|
VALUE result = Qnil;
|
155
159
|
|
156
160
|
if(rb_block_given_p()) {
|
161
|
+
VALUE connection = rb_iv_get(self, "@connection");
|
157
162
|
BlobHandle *blob = NULL;
|
158
163
|
char *segment = NULL;
|
159
164
|
unsigned short size = 0;
|
@@ -161,7 +166,7 @@ static VALUE eachBlobSegment(VALUE self) {
|
|
161
166
|
Data_Get_Struct(self, BlobHandle, blob);
|
162
167
|
segment = loadBlobSegment(blob, &size);
|
163
168
|
while(segment != NULL) {
|
164
|
-
result = rb_yield(
|
169
|
+
result = rb_yield(rfbstr(connection, blob->charset, segment, size));
|
165
170
|
free(segment);
|
166
171
|
segment = loadBlobSegment(blob, &size);
|
167
172
|
}
|
@@ -175,7 +180,7 @@ static VALUE eachBlobSegment(VALUE self) {
|
|
175
180
|
* This function allocates a BlobHandle structure and opens the structure for
|
176
181
|
* use.
|
177
182
|
*
|
178
|
-
* @param
|
183
|
+
* @param blobEntry The blob SQLVAR data.
|
179
184
|
* @param table The name of the table containing the blob being opened.
|
180
185
|
* @param column The name of the column in the table that contains the
|
181
186
|
* blob.
|
@@ -185,7 +190,7 @@ static VALUE eachBlobSegment(VALUE self) {
|
|
185
190
|
* @return A pointer to an allocated and opened BlobHandle structure.
|
186
191
|
*
|
187
192
|
*/
|
188
|
-
BlobHandle *openBlob(
|
193
|
+
BlobHandle *openBlob(XSQLVAR *blobEntry,
|
189
194
|
char *table,
|
190
195
|
char *column,
|
191
196
|
VALUE connection,
|
@@ -194,6 +199,7 @@ BlobHandle *openBlob(ISC_QUAD blobId,
|
|
194
199
|
TransactionHandle *tHandle = NULL;
|
195
200
|
Data_Get_Struct(connection, ConnectionHandle, cHandle);
|
196
201
|
Data_Get_Struct(transaction, TransactionHandle, tHandle);
|
202
|
+
ISC_QUAD blobId = *(ISC_QUAD *)blobEntry->sqldata;
|
197
203
|
|
198
204
|
BlobHandle *blob = ALLOC(BlobHandle);
|
199
205
|
|
@@ -202,6 +208,7 @@ BlobHandle *openBlob(ISC_QUAD blobId,
|
|
202
208
|
|
203
209
|
/* Extract the blob details and open it. */
|
204
210
|
blob->handle = 0;
|
211
|
+
blob->charset = blobEntry->sqlscale;
|
205
212
|
isc_blob_default_desc(&blob->description,
|
206
213
|
(unsigned char *)table,
|
207
214
|
(unsigned char *)column);
|
@@ -365,7 +372,7 @@ void blobFree(void *blob) {
|
|
365
372
|
void Init_Blob(VALUE module) {
|
366
373
|
cBlob = rb_define_class_under(module, "Blob", rb_cObject);
|
367
374
|
rb_define_alloc_func(cBlob, allocateBlob);
|
368
|
-
rb_define_method(cBlob, "initialize", initializeBlob,
|
375
|
+
rb_define_method(cBlob, "initialize", initializeBlob, 1);
|
369
376
|
rb_define_method(cBlob, "initialize_copy", forbidObjectCopy, 1);
|
370
377
|
rb_define_method(cBlob, "to_s", getBlobData, 0);
|
371
378
|
rb_define_method(cBlob, "close", closeBlob, 0);
|
data/ext/Blob.h
CHANGED
@@ -42,25 +42,27 @@
|
|
42
42
|
#include "Connection.h"
|
43
43
|
#include "Transaction.h"
|
44
44
|
|
45
|
+
#include "rfbint.h"
|
45
46
|
/* Type definitions. */
|
46
47
|
typedef struct {
|
47
48
|
ISC_BLOB_DESC description;
|
48
49
|
ISC_LONG segments,
|
49
50
|
size;
|
50
51
|
isc_blob_handle handle;
|
52
|
+
short charset;
|
51
53
|
} BlobHandle;
|
52
54
|
|
53
55
|
/* Data elements. */
|
54
56
|
extern VALUE cBlob;
|
55
57
|
|
56
58
|
/* Function prototypes. */
|
57
|
-
BlobHandle *openBlob(
|
59
|
+
BlobHandle *openBlob(XSQLVAR *,
|
58
60
|
char *,
|
59
61
|
char *,
|
60
62
|
VALUE,
|
61
63
|
VALUE);
|
62
64
|
void Init_Blob(VALUE);
|
63
65
|
void blobFree(void *);
|
64
|
-
VALUE initializeBlob(VALUE);
|
66
|
+
VALUE initializeBlob(VALUE, VALUE);
|
65
67
|
|
66
68
|
#endif /* FIRERUBY_BLOB_H */
|
data/ext/TypeMap.c
CHANGED
@@ -35,6 +35,7 @@
|
|
35
35
|
#include "Statement.h"
|
36
36
|
#include "FireRuby.h"
|
37
37
|
#include "rfbint.h"
|
38
|
+
#include "rfbstr.h"
|
38
39
|
|
39
40
|
/* Function prototypes. */
|
40
41
|
VALUE createDate(const struct tm *);
|
@@ -56,32 +57,6 @@ void populateDateField(VALUE, XSQLVAR *);
|
|
56
57
|
void populateTimeField(VALUE, XSQLVAR *);
|
57
58
|
void populateTimestampField(VALUE, XSQLVAR *);
|
58
59
|
|
59
|
-
|
60
|
-
/**
|
61
|
-
* This function converts a sql data into ruby string
|
62
|
-
* respecting data encoding
|
63
|
-
*
|
64
|
-
* @param connection The connection object relating to the data
|
65
|
-
* @param sqlsubtype SQL subtype of the field (fot character types - used to hold encoding information)
|
66
|
-
* @param data A pointer to the sql data
|
67
|
-
* @param length Length of the sql data
|
68
|
-
*
|
69
|
-
* @return A Ruby String object with correct encoding
|
70
|
-
*
|
71
|
-
*/
|
72
|
-
VALUE createString(VALUE connection, short sqlsubtype, const char *data, short length) {
|
73
|
-
VALUE value = Qnil;
|
74
|
-
if (length >= 0) {
|
75
|
-
char *array = ALLOC_N(char, length + 1);
|
76
|
-
memcpy(array, data, length);
|
77
|
-
array[length] = 0;
|
78
|
-
value = rb_str_new2(array);
|
79
|
-
free(array);
|
80
|
-
value = rb_funcall(connection, rb_intern("force_encoding"), 2, value, INT2FIX(sqlsubtype));
|
81
|
-
}
|
82
|
-
return value;
|
83
|
-
}
|
84
|
-
|
85
60
|
/**
|
86
61
|
* This function converts a single XSQLVAR entry to a Ruby VALUE type.
|
87
62
|
*
|
@@ -122,10 +97,10 @@ VALUE toValue(XSQLVAR *entry,
|
|
122
97
|
memset(table, 0, 256);
|
123
98
|
memcpy(column, entry->sqlname, entry->sqlname_length);
|
124
99
|
memcpy(table, entry->relname, entry->relname_length);
|
125
|
-
blob = openBlob(
|
100
|
+
blob = openBlob(entry, column, table, connection,
|
126
101
|
transaction);
|
127
102
|
working = Data_Wrap_Struct(cBlob, NULL, blobFree, blob);
|
128
|
-
rb_ary_push(value, initializeBlob(working));
|
103
|
+
rb_ary_push(value, initializeBlob(working, connection));
|
129
104
|
rb_ary_push(value, getColumnType(entry));
|
130
105
|
break;
|
131
106
|
|
@@ -190,7 +165,7 @@ VALUE toValue(XSQLVAR *entry,
|
|
190
165
|
break;
|
191
166
|
|
192
167
|
case SQL_TEXT: /* Type: CHAR */
|
193
|
-
rb_ary_push(value,
|
168
|
+
rb_ary_push(value, rfbstr(connection, entry->sqlsubtype, entry->sqldata, entry->sqllen));
|
194
169
|
rb_ary_push(value, getColumnType(entry));
|
195
170
|
break;
|
196
171
|
|
@@ -211,7 +186,7 @@ VALUE toValue(XSQLVAR *entry,
|
|
211
186
|
|
212
187
|
case SQL_VARYING:
|
213
188
|
memcpy(&length, entry->sqldata, 2);
|
214
|
-
rb_ary_push(value,
|
189
|
+
rb_ary_push(value, rfbstr(connection, entry->sqlsubtype, &entry->sqldata[2], length));
|
215
190
|
rb_ary_push(value, getColumnType(entry));
|
216
191
|
break;
|
217
192
|
|
@@ -731,21 +706,23 @@ void storeBlob(VALUE info,
|
|
731
706
|
ISC_STATUS status[ISC_STATUS_LENGTH];
|
732
707
|
isc_blob_handle handle = 0;
|
733
708
|
ISC_QUAD *blobId = (ISC_QUAD *)field->sqldata;
|
709
|
+
char *data = StringValuePtr(info);
|
734
710
|
VALUE number = rb_funcall(info, rb_intern("length"), 0);
|
735
|
-
long
|
736
|
-
|
737
|
-
|
738
|
-
length = TYPE(number) == T_FIXNUM ? FIX2INT(number) : NUM2INT(number);
|
711
|
+
long charLength = TYPE(number) == T_FIXNUM ? FIX2INT(number) : NUM2INT(number);
|
712
|
+
long byteLength = strlen(data);
|
713
|
+
short charSize = byteLength/charLength;
|
739
714
|
field->sqltype = SQL_BLOB;
|
715
|
+
|
740
716
|
if(isc_create_blob(status, &connection->handle, &transaction->handle,
|
741
717
|
&handle, blobId) == 0) {
|
742
718
|
long offset = 0;
|
743
719
|
unsigned short size = 0;
|
744
720
|
|
745
|
-
while(offset <
|
721
|
+
while(offset < byteLength) {
|
746
722
|
char *buffer = &data[offset];
|
747
723
|
|
748
|
-
size = (
|
724
|
+
size = (byteLength - offset) > USHRT_MAX ? USHRT_MAX : byteLength - offset;
|
725
|
+
size = (size/charSize)*charSize; // align
|
749
726
|
if(isc_put_segment(status, &handle, size, buffer) != 0) {
|
750
727
|
ISC_STATUS other[20];
|
751
728
|
|
@@ -991,7 +968,7 @@ void populateTextField(VALUE value, XSQLVAR *field) {
|
|
991
968
|
char *text = NULL;
|
992
969
|
short length = 0;
|
993
970
|
|
994
|
-
if(TYPE(value)
|
971
|
+
if(TYPE(value) == T_STRING) {
|
995
972
|
actual = value;
|
996
973
|
} else {
|
997
974
|
actual = rb_funcall(value, rb_intern("to_s"), 0);
|
data/ext/rfbstr.c
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
/*------------------------------------------------------------------------------
|
2
|
+
* rfbstr.c
|
3
|
+
*----------------------------------------------------------------------------*/
|
4
|
+
|
5
|
+
/* Includes. */
|
6
|
+
#include "rfbstr.h"
|
7
|
+
|
8
|
+
/**
|
9
|
+
* This function converts a sql data into ruby string
|
10
|
+
* respecting data encoding
|
11
|
+
*
|
12
|
+
* @param connection The connection object relating to the data
|
13
|
+
* @param sqlsubtype SQL subtype of the field (fot character types - used to hold encoding information)
|
14
|
+
* @param data A pointer to the sql data
|
15
|
+
* @param length Length of the sql data
|
16
|
+
*
|
17
|
+
* @return A Ruby String object with correct encoding
|
18
|
+
*
|
19
|
+
*/
|
20
|
+
VALUE rfbstr(VALUE connection, short sqlsubtype, const char *data, short length) {
|
21
|
+
VALUE value = Qnil;
|
22
|
+
if (length >= 0) {
|
23
|
+
value = rb_str_new(data, length);
|
24
|
+
value = rb_funcall(connection, rb_intern("force_encoding"), 2, value, INT2FIX(sqlsubtype));
|
25
|
+
}
|
26
|
+
return value;
|
27
|
+
}
|
28
|
+
|
data/ext/rfbstr.h
ADDED
data/lib/rubyfb_lib.so
CHANGED
Binary file
|
data/rubyfb.gemspec
CHANGED
@@ -2,25 +2,24 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{rubyfb}
|
5
|
-
s.version = "0.5.
|
5
|
+
s.version = "0.5.9"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = [
|
9
|
-
s.date = %q{2011-
|
8
|
+
s.authors = [%q{George Georgiev}]
|
9
|
+
s.date = %q{2011-06-06}
|
10
10
|
s.description = %q{Firebird SQL access library}
|
11
11
|
s.email = %q{georgiev@heatbs.com}
|
12
|
-
s.extensions = [
|
13
|
-
s.extra_rdoc_files = [
|
14
|
-
s.files = [
|
12
|
+
s.extensions = [%q{ext/extconf.rb}]
|
13
|
+
s.extra_rdoc_files = [%q{CHANGELOG}, %q{LICENSE}, %q{README}, %q{examples/example01.rb}, %q{ext/extconf.rb}, %q{lib/Connection.rb}, %q{lib/ProcedureCall.rb}, %q{lib/SQLType.rb}, %q{lib/rubyfb.rb}, %q{lib/rubyfb_options.rb}, %q{lib/src.rb}]
|
14
|
+
s.files = [%q{CHANGELOG}, %q{LICENSE}, %q{Manifest}, %q{README}, %q{Rakefile}, %q{examples/example01.rb}, %q{ext/AddUser.c}, %q{ext/AddUser.h}, %q{ext/Backup.c}, %q{ext/Backup.h}, %q{ext/Blob.c}, %q{ext/Blob.h}, %q{ext/Common.c}, %q{ext/Common.h}, %q{ext/Connection.c}, %q{ext/Connection.h}, %q{ext/DataArea.c}, %q{ext/DataArea.h}, %q{ext/Database.c}, %q{ext/Database.h}, %q{ext/FireRuby.c}, %q{ext/FireRuby.h}, %q{ext/FireRubyException.c}, %q{ext/FireRubyException.h}, %q{ext/Generator.c}, %q{ext/Generator.h}, %q{ext/RemoveUser.c}, %q{ext/RemoveUser.h}, %q{ext/Restore.c}, %q{ext/Restore.h}, %q{ext/ResultSet.c}, %q{ext/ResultSet.h}, %q{ext/Row.c}, %q{ext/Row.h}, %q{ext/ServiceManager.c}, %q{ext/ServiceManager.h}, %q{ext/Services.c}, %q{ext/Services.h}, %q{ext/Statement.c}, %q{ext/Statement.h}, %q{ext/Transaction.c}, %q{ext/Transaction.h}, %q{ext/TypeMap.c}, %q{ext/TypeMap.h}, %q{ext/extconf.rb}, %q{ext/rfbint.h}, %q{ext/rfbsleep.h}, %q{ext/rfbstr.c}, %q{ext/rfbstr.h}, %q{ext/uncrustify.cfg}, %q{lib/Connection.rb}, %q{lib/ProcedureCall.rb}, %q{lib/SQLType.rb}, %q{lib/active_record/connection_adapters/rubyfb_adapter.rb}, %q{lib/arel/visitors/rubyfb.rb}, %q{lib/arel/visitors/rubyfb_15compat.rb}, %q{lib/mkdoc}, %q{lib/rubyfb.rb}, %q{lib/rubyfb_lib.so}, %q{lib/rubyfb_options.rb}, %q{lib/src.rb}, %q{mswin32fb/fbclient_mingw.def}, %q{mswin32fb/fbclient_mingw.lib}, %q{mswin32fb/fbclient_ms.lib}, %q{mswin32fb/ibase.h}, %q{mswin32fb/iberror.h}, %q{test/AddRemoveUserTest.rb}, %q{test/BackupRestoreTest.rb}, %q{test/BlobTest.rb}, %q{test/CharacterSetTest.rb}, %q{test/ConnectionTest.rb}, %q{test/DDLTest.rb}, %q{test/DatabaseTest.rb}, %q{test/FieldCharacterSetTest.rb}, %q{test/GeneratorTest.rb}, %q{test/KeyTest.rb}, %q{test/ResultSetTest.rb}, %q{test/RoleTest.rb}, %q{test/RowCountTest.rb}, %q{test/RowTest.rb}, %q{test/SQLTest.rb}, %q{test/SQLTypeTest.rb}, %q{test/ServiceManagerTest.rb}, %q{test/StatementTest.rb}, %q{test/TestSetup.rb}, %q{test/TransactionTest.rb}, %q{test/TypeTest.rb}, %q{rubyfb.gemspec}]
|
15
15
|
s.homepage = %q{http://rubyforge.org/projects/rubyfb}
|
16
|
-
s.rdoc_options = [
|
17
|
-
s.require_paths = [
|
16
|
+
s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Rubyfb}, %q{--main}, %q{README}]
|
17
|
+
s.require_paths = [%q{lib}, %q{ext}]
|
18
18
|
s.rubyforge_project = %q{rubyfb}
|
19
|
-
s.rubygems_version = %q{1.
|
19
|
+
s.rubygems_version = %q{1.8.5}
|
20
20
|
s.summary = %q{Firebird SQL access library}
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
23
|
s.specification_version = 3
|
25
24
|
|
26
25
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
data/test/BlobTest.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
2
3
|
|
3
4
|
require './TestSetup'
|
4
5
|
require 'test/unit'
|
@@ -11,6 +12,7 @@ class BlobTest < Test::Unit::TestCase
|
|
11
12
|
DB_FILE = File.join(DB_DIR, "blob_unit_test.fdb")
|
12
13
|
TXT_FILE = File.join(DB_DIR, "data.txt")
|
13
14
|
DATA = "aasdfjakhdsfljkashdfslfhaslhasyhfawyufalwuhlhsdlkfhasljlkshflalksjhasjhalsjhdf\nasdflkajshdfjkahsdfjajdfalsdfasdf\nasdfasdfasdkljfhajdfhkjasdfagdsflalkjfgagsdflasdf\nasdfasdfasdf"
|
15
|
+
UTF_DATA = "ред с utf кирилица"
|
14
16
|
|
15
17
|
def setup
|
16
18
|
puts "#{self.class.name} started." if TEST_LOGGING
|
@@ -53,4 +55,28 @@ class BlobTest < Test::Unit::TestCase
|
|
53
55
|
cxn.execute_immediate('DROP TABLE BLOB_TEST')
|
54
56
|
end
|
55
57
|
end
|
58
|
+
|
59
|
+
def test02
|
60
|
+
d = nil
|
61
|
+
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
62
|
+
cxn.execute_immediate('create table blob_test (data blob sub_type 1 segment size 10 CHARACTER SET UTF8)')
|
63
|
+
cxn.start_transaction do |tx|
|
64
|
+
|
65
|
+
s = Statement.new(cxn, tx, 'INSERT INTO BLOB_TEST VALUES(?)', 3)
|
66
|
+
s.execute_for([UTF_DATA])
|
67
|
+
|
68
|
+
# Perform a select of the value inserted.
|
69
|
+
r = cxn.execute('SELECT * FROM BLOB_TEST', tx)
|
70
|
+
d = r.fetch
|
71
|
+
|
72
|
+
assert_equal(d[0].to_s, UTF_DATA)
|
73
|
+
|
74
|
+
# Clean up.
|
75
|
+
s.close
|
76
|
+
r.close
|
77
|
+
end
|
78
|
+
cxn.execute_immediate('DROP TABLE BLOB_TEST')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
56
82
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require './TestSetup'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'rubygems'
|
7
|
+
require 'rubyfb'
|
8
|
+
|
9
|
+
include Rubyfb
|
10
|
+
|
11
|
+
class FieldCharacterSetTest < Test::Unit::TestCase
|
12
|
+
DB_FILE = File.join(DB_DIR, "cxnarset_unit_test.fdb")
|
13
|
+
DB_CHAR_SET = 'NONE'
|
14
|
+
|
15
|
+
def setup
|
16
|
+
puts "#{self.class.name} started." if TEST_LOGGING
|
17
|
+
if File::exist?(DB_FILE)
|
18
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
19
|
+
end
|
20
|
+
@database = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD, 1024, DB_CHAR_SET)
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
if File::exist?(DB_FILE)
|
25
|
+
Database.new(DB_FILE).drop(DB_USER_NAME, DB_PASSWORD)
|
26
|
+
end
|
27
|
+
puts "#{self.class.name} finished." if TEST_LOGGING
|
28
|
+
end
|
29
|
+
|
30
|
+
def test01
|
31
|
+
db = Database.new(DB_FILE, DB_CHAR_SET)
|
32
|
+
utf8_str = "Малко utf8 кирилица"
|
33
|
+
db.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
34
|
+
cxn.start_transaction do |tr|
|
35
|
+
cxn.execute("CREATE TABLE SAMPLE_TABLE(SAMPLE_FIELD VARCHAR(100) CHARACTER SET UTF8)", tr)
|
36
|
+
end
|
37
|
+
cxn.start_transaction do |tr|
|
38
|
+
cxn.execute("INSERT INTO SAMPLE_TABLE VALUES ('#{utf8_str}')", tr)
|
39
|
+
row_count = 0
|
40
|
+
cxn.execute("SELECT * FROM SAMPLE_TABLE WHERE SAMPLE_FIELD = '#{utf8_str}'", tr) do |row|
|
41
|
+
assert(row['SAMPLE_FIELD'] == utf8_str, "Field encoding failed")
|
42
|
+
row_count += 1
|
43
|
+
end
|
44
|
+
assert(1==row_count)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/test/StatementTest.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
2
3
|
|
3
4
|
require './TestSetup'
|
4
5
|
require 'test/unit'
|
@@ -131,4 +132,27 @@ class StatementTest < Test::Unit::TestCase
|
|
131
132
|
cxn.execute_immediate('DROP TABLE STRING_TEST')
|
132
133
|
end
|
133
134
|
end
|
135
|
+
|
136
|
+
def test04
|
137
|
+
d = nil
|
138
|
+
@database.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
139
|
+
utf_str = 'utf кирилица';
|
140
|
+
cxn.execute_immediate('CREATE TABLE STRING_TEST(TEXT VARCHAR(100) CHARACTER SET UTF8)')
|
141
|
+
cxn.start_transaction do |tx|
|
142
|
+
# Perform an truncated insert.
|
143
|
+
s = Statement.new(cxn, tx, 'INSERT INTO STRING_TEST VALUES(?)', 3)
|
144
|
+
s.execute_for([utf_str])
|
145
|
+
|
146
|
+
# Perform a select of the value inserted.
|
147
|
+
r = cxn.execute('SELECT * FROM STRING_TEST', tx)
|
148
|
+
d = r.fetch
|
149
|
+
|
150
|
+
# Clean up.
|
151
|
+
s.close
|
152
|
+
r.close
|
153
|
+
end
|
154
|
+
assert(d[0] == utf_str)
|
155
|
+
cxn.execute_immediate('DROP TABLE STRING_TEST')
|
156
|
+
end
|
157
|
+
end
|
134
158
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyfb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 0.5.
|
9
|
+
- 9
|
10
|
+
version: 0.5.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- George Georgiev
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-06-06 00:00:00 Z
|
20
19
|
dependencies: []
|
21
20
|
|
22
21
|
description: Firebird SQL access library
|
@@ -85,6 +84,8 @@ files:
|
|
85
84
|
- ext/extconf.rb
|
86
85
|
- ext/rfbint.h
|
87
86
|
- ext/rfbsleep.h
|
87
|
+
- ext/rfbstr.c
|
88
|
+
- ext/rfbstr.h
|
88
89
|
- ext/uncrustify.cfg
|
89
90
|
- lib/Connection.rb
|
90
91
|
- lib/ProcedureCall.rb
|
@@ -109,6 +110,7 @@ files:
|
|
109
110
|
- test/ConnectionTest.rb
|
110
111
|
- test/DDLTest.rb
|
111
112
|
- test/DatabaseTest.rb
|
113
|
+
- test/FieldCharacterSetTest.rb
|
112
114
|
- test/GeneratorTest.rb
|
113
115
|
- test/KeyTest.rb
|
114
116
|
- test/ResultSetTest.rb
|
@@ -123,7 +125,6 @@ files:
|
|
123
125
|
- test/TransactionTest.rb
|
124
126
|
- test/TypeTest.rb
|
125
127
|
- rubyfb.gemspec
|
126
|
-
has_rdoc: true
|
127
128
|
homepage: http://rubyforge.org/projects/rubyfb
|
128
129
|
licenses: []
|
129
130
|
|
@@ -160,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
161
|
requirements: []
|
161
162
|
|
162
163
|
rubyforge_project: rubyfb
|
163
|
-
rubygems_version: 1.
|
164
|
+
rubygems_version: 1.8.5
|
164
165
|
signing_key:
|
165
166
|
specification_version: 3
|
166
167
|
summary: Firebird SQL access library
|