intersys 0.0.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.
- data/README +0 -0
- data/lib/common.c +61 -0
- data/lib/database.c +90 -0
- data/lib/definition.c +575 -0
- data/lib/extconf.rb +20 -0
- data/lib/intersys.c +83 -0
- data/lib/intersys.h +154 -0
- data/lib/intersys.rb +419 -0
- data/lib/object.c +69 -0
- data/lib/query.c +153 -0
- data/test/object.rb +17 -0
- data/test/query.rb +12 -0
- data/test/reflection.rb +65 -0
- data/test/strings.rb +14 -0
- metadata +69 -0
data/lib/object.c
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#include "intersys.h"
|
2
|
+
|
3
|
+
|
4
|
+
static void intersys_object_free(struct rbObject* object) {
|
5
|
+
// printf("Releasing object %d\n", object->oref);
|
6
|
+
if (object->oref) {
|
7
|
+
RUN(cbind_object_release(object->database, object->oref));
|
8
|
+
}
|
9
|
+
free(object);
|
10
|
+
}
|
11
|
+
|
12
|
+
static void intersys_object_mark(struct rbObject* object) {
|
13
|
+
rb_gc_mark(object->class_name);
|
14
|
+
}
|
15
|
+
|
16
|
+
|
17
|
+
VALUE intersys_object_s_allocate(VALUE klass) {
|
18
|
+
struct rbObject* object = ALLOC(struct rbObject);
|
19
|
+
bzero(object, sizeof(struct rbObject));
|
20
|
+
return Data_Wrap_Struct(klass, intersys_object_mark, intersys_object_free, object);
|
21
|
+
}
|
22
|
+
|
23
|
+
VALUE intersys_object_initialize(VALUE self) {
|
24
|
+
struct rbObject* object;
|
25
|
+
struct rbDatabase* base;
|
26
|
+
VALUE klass = rb_funcall(self, rb_intern("class"), 0);
|
27
|
+
VALUE database = rb_funcall(klass, rb_intern("database"), 0);
|
28
|
+
Data_Get_Struct(self, struct rbObject, object);
|
29
|
+
Data_Get_Struct(database, struct rbDatabase, base);
|
30
|
+
object->database = base->database;
|
31
|
+
object->class_name = TOWCHAR(rb_funcall(klass, rb_intern("class_name"), 0));
|
32
|
+
return self;
|
33
|
+
}
|
34
|
+
|
35
|
+
VALUE intersys_object_open_by_id(VALUE self, VALUE oid) {
|
36
|
+
int concurrency = rb_funcall(self, rb_intern("concurrency"), 0);
|
37
|
+
int timeout = rb_funcall(self, rb_intern("timeout"), 0);
|
38
|
+
int error;
|
39
|
+
struct rbObject* object;
|
40
|
+
VALUE r_object = rb_funcall(self, rb_intern("new"), 0);
|
41
|
+
Data_Get_Struct(r_object, struct rbObject, object);
|
42
|
+
|
43
|
+
error = cbind_openid(object->database, CLASS_NAME(object), WCHARSTR(oid), concurrency, timeout, &object->oref);
|
44
|
+
switch(error) {
|
45
|
+
case 0:
|
46
|
+
return r_object;
|
47
|
+
case -9:
|
48
|
+
rb_raise(cObjectNotFound, "Object with id %s not found", PRINTABLE(oid));
|
49
|
+
return Qnil;
|
50
|
+
default:
|
51
|
+
RUN(error);
|
52
|
+
return Qnil;
|
53
|
+
}
|
54
|
+
return r_object;
|
55
|
+
}
|
56
|
+
|
57
|
+
VALUE intersys_object_create(VALUE self) {
|
58
|
+
wchar_t *init_val = NULL;
|
59
|
+
struct rbObject *object;
|
60
|
+
VALUE r_object = rb_funcall(self, rb_intern("new"), 0);
|
61
|
+
|
62
|
+
Data_Get_Struct(r_object, struct rbObject, object);
|
63
|
+
|
64
|
+
RUN(cbind_create_new(object->database, CLASS_NAME(object), init_val,&object->oref));
|
65
|
+
return r_object;
|
66
|
+
}
|
67
|
+
|
68
|
+
|
69
|
+
|
data/lib/query.c
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
#include "intersys.h"
|
2
|
+
#include <sql.h>
|
3
|
+
#include <sqlext.h>
|
4
|
+
#include <sqlucode.h>
|
5
|
+
|
6
|
+
void intersys_query_free(struct rbQuery* query) {
|
7
|
+
RUN(cbind_free_query(query->query));
|
8
|
+
free(query);
|
9
|
+
}
|
10
|
+
|
11
|
+
VALUE intersys_query_s_allocate(VALUE klass) {
|
12
|
+
struct rbQuery* query = ALLOC(struct rbQuery);
|
13
|
+
bzero(query, sizeof(struct rbQuery));
|
14
|
+
return Data_Wrap_Struct(klass, 0, intersys_query_free, query);
|
15
|
+
}
|
16
|
+
|
17
|
+
VALUE intersys_query_initialize(VALUE self, VALUE database, VALUE sql_query) {
|
18
|
+
struct rbQuery* query;
|
19
|
+
struct rbDatabase* base;
|
20
|
+
int sql_code;
|
21
|
+
Data_Get_Struct(self, struct rbQuery, query);
|
22
|
+
Data_Get_Struct(database, struct rbDatabase, base);
|
23
|
+
RUN(cbind_alloc_query(base->database, &query->query));
|
24
|
+
RUN(cbind_prepare_gen_query(query->query, WCHARSTR(sql_query), &sql_code));
|
25
|
+
return self;
|
26
|
+
}
|
27
|
+
|
28
|
+
VALUE intersys_query_execute(VALUE self) {
|
29
|
+
struct rbQuery* query;
|
30
|
+
int sql_code;
|
31
|
+
int res;
|
32
|
+
Data_Get_Struct(self, struct rbQuery, query);
|
33
|
+
RUN(cbind_query_execute(query->query, &sql_code));
|
34
|
+
RUN(cbind_query_get_num_pars(query->query, &res));
|
35
|
+
return self;
|
36
|
+
}
|
37
|
+
|
38
|
+
VALUE intersys_query_get_data(VALUE self, VALUE index) {
|
39
|
+
struct rbQuery* query;
|
40
|
+
int type = 0;
|
41
|
+
VALUE ret = Qnil;
|
42
|
+
bool_t is_null;
|
43
|
+
Data_Get_Struct(self, struct rbQuery, query);
|
44
|
+
|
45
|
+
RUN(cbind_query_get_col_sql_type(query->query, FIX2INT(index), &type));
|
46
|
+
switch(type) {
|
47
|
+
case SQL_WCHAR:
|
48
|
+
case SQL_WVARCHAR:
|
49
|
+
case SQL_WLONGVARCHAR:
|
50
|
+
case SQL_CHAR:
|
51
|
+
case SQL_VARCHAR:
|
52
|
+
case SQL_LONGVARCHAR:
|
53
|
+
{
|
54
|
+
wchar_t buf[32767];
|
55
|
+
int size;
|
56
|
+
RUN(cbind_query_get_uni_str_data(query->query, buf, sizeof(buf), &size, &is_null));
|
57
|
+
if (is_null) {
|
58
|
+
return Qnil;
|
59
|
+
}
|
60
|
+
return FROMWCSTR(buf);
|
61
|
+
}
|
62
|
+
case SQL_BINARY:
|
63
|
+
case SQL_LONGVARBINARY:
|
64
|
+
case SQL_VARBINARY:
|
65
|
+
{
|
66
|
+
char buf[32767];
|
67
|
+
int size;
|
68
|
+
|
69
|
+
RUN(cbind_query_get_bin_data(query->query, buf, sizeof(buf), &size, &is_null));
|
70
|
+
if (is_null) {
|
71
|
+
return Qnil;
|
72
|
+
}
|
73
|
+
return rb_str_new(buf, size);
|
74
|
+
}
|
75
|
+
case SQL_TINYINT:
|
76
|
+
case SQL_SMALLINT:
|
77
|
+
case SQL_INTEGER:
|
78
|
+
case SQL_BIGINT:
|
79
|
+
case SQL_BIT:
|
80
|
+
{
|
81
|
+
int res;
|
82
|
+
RUN(cbind_query_get_int_data(query->query, &res, &is_null));
|
83
|
+
if (is_null) {
|
84
|
+
return Qnil;
|
85
|
+
}
|
86
|
+
return INT2NUM(res);
|
87
|
+
}
|
88
|
+
case SQL_FLOAT:
|
89
|
+
case SQL_DOUBLE:
|
90
|
+
case SQL_REAL:
|
91
|
+
case SQL_NUMERIC:
|
92
|
+
case SQL_DECIMAL:
|
93
|
+
{
|
94
|
+
double res;
|
95
|
+
RUN(cbind_query_get_double_data(query->query, &res, &is_null));
|
96
|
+
if (is_null) {
|
97
|
+
return Qnil;
|
98
|
+
}
|
99
|
+
return rb_float_new(res);
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
}
|
105
|
+
return ret;
|
106
|
+
}
|
107
|
+
|
108
|
+
VALUE intersys_query_column_name(VALUE self, VALUE i) {
|
109
|
+
struct rbQuery* query;
|
110
|
+
Data_Get_Struct(self, struct rbQuery, query);
|
111
|
+
int len;
|
112
|
+
const wchar_t *res;
|
113
|
+
RUN(cbind_query_get_col_name_len(query->query, FIX2INT(i), &len));
|
114
|
+
RUN(cbind_query_get_col_name(query->query, FIX2INT(i), &res));
|
115
|
+
return FROMWCSTR(res);
|
116
|
+
}
|
117
|
+
|
118
|
+
VALUE intersys_query_fetch(VALUE self) {
|
119
|
+
struct rbQuery* query;
|
120
|
+
VALUE data;
|
121
|
+
Data_Get_Struct(self, struct rbQuery, query);
|
122
|
+
int num_cols = 0;
|
123
|
+
int i = 0;
|
124
|
+
int sql_code;
|
125
|
+
|
126
|
+
RUN(cbind_query_fetch(query->query, &sql_code));
|
127
|
+
|
128
|
+
data = rb_ary_new();
|
129
|
+
|
130
|
+
if(sql_code == 100) {
|
131
|
+
query->query = 1;
|
132
|
+
rb_funcall(self, rb_intern("close"), 0);
|
133
|
+
return data;
|
134
|
+
}
|
135
|
+
if(sql_code) {
|
136
|
+
return data;
|
137
|
+
// rb_raise(rb_eStandardError, "Error in SQL: %d", sql_code);
|
138
|
+
}
|
139
|
+
|
140
|
+
RUN(cbind_query_get_num_cols(query->query, &num_cols));
|
141
|
+
for(i = 0; i < num_cols; i++) {
|
142
|
+
rb_ary_push(data, rb_funcall(self, rb_intern("get_data"), 1, INT2FIX(i+1)));
|
143
|
+
}
|
144
|
+
rb_funcall(self, rb_intern("close"), 0);
|
145
|
+
return data;
|
146
|
+
}
|
147
|
+
|
148
|
+
VALUE intersys_query_close(VALUE self) {
|
149
|
+
struct rbQuery* query;
|
150
|
+
Data_Get_Struct(self, struct rbQuery, query);
|
151
|
+
RUN(cbind_query_close(query->query));
|
152
|
+
return self;
|
153
|
+
}
|
data/test/object.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/intersys'
|
3
|
+
|
4
|
+
|
5
|
+
class Person < Intersys::Object
|
6
|
+
end
|
7
|
+
|
8
|
+
class QueryTest < Test::Unit::TestCase
|
9
|
+
def test_open_and_save
|
10
|
+
@p = Person.open(21)
|
11
|
+
@name = "Anni Fyo"
|
12
|
+
@p.name = @name
|
13
|
+
@p.save
|
14
|
+
@p = Article.open(21)
|
15
|
+
assert_equal @name, @p.name
|
16
|
+
end
|
17
|
+
end
|
data/test/query.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/intersys'
|
3
|
+
|
4
|
+
|
5
|
+
class QueryTest < Test::Unit::TestCase
|
6
|
+
def test_query1
|
7
|
+
@db = Intersys::Database.new({})
|
8
|
+
|
9
|
+
@data = @db.query("select * from sample.person")
|
10
|
+
assert @data.size > 0
|
11
|
+
end
|
12
|
+
end
|
data/test/reflection.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/intersys'
|
3
|
+
|
4
|
+
|
5
|
+
class Article < Intersys::Object
|
6
|
+
prefix "Sample"
|
7
|
+
end
|
8
|
+
class Person < Intersys::Object
|
9
|
+
end
|
10
|
+
|
11
|
+
class ReflectionTest < Test::Unit::TestCase
|
12
|
+
def test_methods
|
13
|
+
@cdef = Intersys::Reflection::ClassDefinition.open("%Dictionary.ClassDefinition")
|
14
|
+
assert_equal "%Dictionary.ClassDefinition", @cdef.name
|
15
|
+
assert_equal "persistent", @cdef.class_type
|
16
|
+
assert_equal "%Persistent,%Dictionary.ClassDefinitionQuery", @cdef.super
|
17
|
+
assert_equal 58, @cdef.properties.size
|
18
|
+
assert_equal 19, @cdef._methods.size
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_class_names
|
22
|
+
assert_equal Article, Article.lookup("Sample.Article")
|
23
|
+
assert_equal Person, Article.lookup("User.Person")
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_class_create
|
27
|
+
@cdef = Intersys::Reflection::ClassDefinition.call("%New", "User.Person")
|
28
|
+
@cdef.class_type = "persistent"
|
29
|
+
@cdef.super = "%Persistent,%Populate,%XML.Adaptor"
|
30
|
+
@props = @cdef.properties
|
31
|
+
|
32
|
+
@prop = Intersys::Reflection::PropertyDefinition.intersys_call("%New", "Person:Name")
|
33
|
+
assert @props << @prop
|
34
|
+
@prop.type = "%String"
|
35
|
+
|
36
|
+
@prop = Intersys::Reflection::PropertyDefinition.intersys_call("%New", "Person:SSN")
|
37
|
+
assert @props << @prop
|
38
|
+
@prop.type = "%String"
|
39
|
+
|
40
|
+
@prop = Intersys::Reflection::PropertyDefinition.intersys_call("%New", "Person:Title")
|
41
|
+
assert @props << @prop
|
42
|
+
@prop.type = "%String"
|
43
|
+
|
44
|
+
@prop = Intersys::Reflection::PropertyDefinition.intersys_call("%New", "Person:DOB")
|
45
|
+
assert @props << @prop
|
46
|
+
@prop.type = "%String"
|
47
|
+
|
48
|
+
@prop = Intersys::Reflection::PropertyDefinition.intersys_call("%New", "Person:Home")
|
49
|
+
assert @props << @prop
|
50
|
+
@prop.type = "Sample.Address"
|
51
|
+
|
52
|
+
@prop = Intersys::Reflection::PropertyDefinition.intersys_call("%New", "Person:Business")
|
53
|
+
assert @props << @prop
|
54
|
+
@prop.type = "Sample.Address"
|
55
|
+
|
56
|
+
assert_equal "User.Person", @cdef.name
|
57
|
+
assert_equal 6, @cdef.properties.size
|
58
|
+
#@cdef.save
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_populate
|
62
|
+
assert Person.intersys_call("Populate", 1000)
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
data/test/strings.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.dirname(__FILE__) + '/../lib/intersys'
|
3
|
+
|
4
|
+
class StringTest < Test::Unit::TestCase
|
5
|
+
@@wide_string = "\000\000\000a\000\000\000b\000\000\000c\000\000\000\000"
|
6
|
+
@@simple_string = "abc"
|
7
|
+
def test_from_wchar
|
8
|
+
assert_equal @@simple_string, @@wide_string.from_wchar
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_to_wchar
|
12
|
+
assert_equal @@wide_string, @@simple_string.to_wchar
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: intersys
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.2
|
7
|
+
date: 2006-09-02 00:00:00 +04:00
|
8
|
+
summary: Intersystems Cache ruby driver
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: max@maxidoors.ru
|
12
|
+
homepage: http://maxidoors.ru/
|
13
|
+
rubyforge_project: intersys
|
14
|
+
description:
|
15
|
+
autorequire: intersys
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
authors:
|
29
|
+
- Max Lapshin
|
30
|
+
files:
|
31
|
+
- test/object.rb
|
32
|
+
- test/query.rb
|
33
|
+
- test/reflection.rb
|
34
|
+
- test/strings.rb
|
35
|
+
- lib/common.c
|
36
|
+
- lib/database.c
|
37
|
+
- lib/definition.c
|
38
|
+
- lib/extconf.rb
|
39
|
+
- lib/intersys.c
|
40
|
+
- lib/intersys.h
|
41
|
+
- lib/intersys.rb
|
42
|
+
- lib/object.c
|
43
|
+
- lib/query.c
|
44
|
+
- README
|
45
|
+
test_files: []
|
46
|
+
|
47
|
+
rdoc_options:
|
48
|
+
- --main=README
|
49
|
+
- --line-numbers
|
50
|
+
- --charset=utf-8
|
51
|
+
- --promiscuous
|
52
|
+
extra_rdoc_files:
|
53
|
+
- README
|
54
|
+
executables: []
|
55
|
+
|
56
|
+
extensions:
|
57
|
+
- lib/extconf.rb
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
dependencies:
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: activesupport
|
63
|
+
version_requirement:
|
64
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "1.0"
|
69
|
+
version:
|