intersys 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,11 +4,11 @@ SHELL = /bin/sh
4
4
  #### Start of system configuration section. ####
5
5
 
6
6
  srcdir = .
7
- topdir = /opt/local/lib/ruby/1.8/powerpc-darwin8.4.0
7
+ topdir = /opt/local/lib/ruby/1.8/i686-darwin8.7.1
8
8
  hdrdir = $(topdir)
9
9
  VPATH = $(srcdir):$(topdir):$(hdrdir)
10
10
  prefix = $(DESTDIR)/opt/local
11
- exec_prefix = $(DESTDIR)/opt/local
11
+ exec_prefix = $(prefix)
12
12
  sitedir = $(prefix)/lib/ruby/site_ruby
13
13
  rubylibdir = $(libdir)/ruby/$(ruby_version)
14
14
  archdir = $(rubylibdir)/$(arch)
@@ -19,7 +19,7 @@ includedir = $(prefix)/include
19
19
  infodir = $(prefix)/info
20
20
  sysconfdir = $(prefix)/etc
21
21
  mandir = $(DESTDIR)/opt/local/share/man
22
- libdir = $(DESTDIR)/opt/local/lib
22
+ libdir = $(exec_prefix)/lib
23
23
  sharedstatedir = $(prefix)/com
24
24
  oldincludedir = $(DESTDIR)/usr/include
25
25
  sitearchdir = $(sitelibdir)/$(sitearch)
@@ -36,19 +36,19 @@ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
36
36
  LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
37
37
  LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
38
38
 
39
- CFLAGS = -fno-common -O -pipe -I/opt/local/include -fno-common -pipe -fno-common -I/Applications/Cache/dev/cpp/include -I/cygdrive/c/Progra~1/Cache/dev/cpp/include -I/cygdrive/c/Cachesys/dev/cpp/include -Wall
40
- CPPFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir) -O -pipe -I/opt/local/include
39
+ CFLAGS = -fno-common -O -pipe -I/opt/local/include -fno-common -pipe -fno-common -I/home/max/cache/dev/cpp/include -I/Applications/Cache/dev/cpp/include -I/cygdrive/c/Progra~1/Cache/dev/cpp/include -I/cygdrive/c/Cachesys/dev/cpp/include -IC:/Cachesys/dev/cpp/include -I./sql_include -Wall
40
+ CPPFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir) -DHAVE_C_API_H -DHAVE_SQL_H -DHAVE_SQLEXT_H -O -pipe -I/opt/local/include
41
41
  CXXFLAGS = $(CFLAGS)
42
- DLDFLAGS = -L/opt/local/lib
42
+ DLDFLAGS = -L/opt/local/lib -L/home/max/cache/dev/cpp/lib -L/Applications/Cache/dev/cpp/lib -L/cygdrive/c/Progra~1/Cache/dev/cpp/lib -L/cygdrive/c/Cachesys/dev/cpp/lib -LC:/Cachesys/dev/cpp/lib -Wall
43
43
  LDSHARED = cc -dynamic -bundle -undefined suppress -flat_namespace
44
44
  AR = ar
45
45
  EXEEXT =
46
46
 
47
47
  RUBY_INSTALL_NAME = ruby
48
48
  RUBY_SO_NAME = ruby
49
- arch = powerpc-darwin8.4.0
50
- sitearch = powerpc-darwin8.4.0
51
- vendorarch = powerpc-darwin8.4.0
49
+ arch = i686-darwin8.7.1
50
+ sitearch = i686-darwin8.7.1
51
+ vendorarch = i686-darwin8.7.1
52
52
  ruby_version = 1.8
53
53
  ruby = /opt/local/bin/ruby
54
54
  RUBY = $(ruby)
@@ -0,0 +1,86 @@
1
+ module Intersys
2
+
3
+ module Callable
4
+ # Returns ClassDefinition object for current class
5
+ def intersys_reflector
6
+ @reflector ||= Intersys::Reflection::ClassDefinition.open(class_name)
7
+ end
8
+
9
+ # returns list of methods for this class
10
+ def intersys_methods
11
+ @methods ||= intersys_reflector._methods
12
+ end
13
+
14
+ # returns list of properties for current class
15
+ def intersys_properties
16
+ @properties ||= intersys_reflector.properties
17
+ end
18
+
19
+ #protected
20
+ # Loads property definition with required name for required object
21
+ # for internal use only
22
+ def intersys_property(name)
23
+ Property.new(database, class_name, name.to_s, self)
24
+ end
25
+
26
+ # Loads method definition with required name for required object
27
+ # for internal use only
28
+ def intersys_method(name)
29
+ Method.new(database, class_name, name.to_s, self)
30
+ end
31
+
32
+ public
33
+ # call class method
34
+ def intersys_call(method_name, *args)
35
+ intersys_method(method_name).call!(args)
36
+ end
37
+ alias :call :intersys_call
38
+
39
+ def intersys_has_property?(property)
40
+ self.intersys_reflector.properties.to_a.include?(property)
41
+ end
42
+
43
+ def intersys_has_method?(method)
44
+ self.intersys_reflector._methods.to_a.include?(method)
45
+ end
46
+
47
+ # Get the specified property
48
+ def intersys_get(property)
49
+ intersys_property(property).get
50
+ end
51
+
52
+ # Set the specified property
53
+ def intersys_set(property, value)
54
+ intersys_property(property).set(value)
55
+ end
56
+
57
+ def method_missing(method, *args)
58
+ method_name = method.to_s.camelize
59
+ if match_data = method_name.match(/intersys_(.*)/)
60
+ # Protection from errors in this method
61
+ return super(method, *args)
62
+ end
63
+ if match_data = method_name.match(/(\w+)=/)
64
+ return intersys_set(match_data.captures.first, args.first)
65
+ end
66
+ return intersys_get(method_name) if intersys_has_property?(method_name) && args.empty?
67
+ begin
68
+ return intersys_call(method_name, *args)
69
+ rescue NoMethodError => e
70
+ end
71
+ begin
72
+ return intersys_call("%"+method_name, *args)
73
+ rescue NoMethodError => e
74
+ end
75
+ super(method, *args)
76
+ end
77
+
78
+ end
79
+
80
+
81
+ class Object
82
+ include Callable
83
+ end
84
+ Intersys::Object.extend(Callable)
85
+
86
+ end
@@ -1,8 +1,15 @@
1
1
  #include "intersys.h"
2
2
 
3
- void intersys_base_free(struct rbDatabase* base) {
3
+
4
+ static void intersys_base_real_close(struct rbDatabase* base) {
5
+ if(base->closed) return;
6
+ base->closed = 1;
4
7
  RUN(cbind_free_db(base->database));
5
8
  RUN(cbind_free_conn(base->connection));
9
+ }
10
+
11
+ void intersys_base_free(struct rbDatabase* base) {
12
+ intersys_base_real_close(base);
6
13
  free(base);
7
14
  }
8
15
 
@@ -32,6 +39,7 @@ VALUE intersys_base_connect(VALUE self, VALUE options) {
32
39
  char conn_str[256];
33
40
  wchar_t w_conn_str[256];
34
41
  int size;
42
+ bool_t is_uni;
35
43
 
36
44
  VALUE host, port, user, password, namespace, timeout;
37
45
 
@@ -58,9 +66,21 @@ VALUE intersys_base_connect(VALUE self, VALUE options) {
58
66
  RUN(cbind_alloc_conn(w_conn_str, WCHARSTR(user), WCHARSTR(password),
59
67
  FIX2INT(timeout), &base->connection));
60
68
  RUN(cbind_alloc_db(base->connection, &base->database));
69
+ RUN(cbind_is_uni_srv(base->database, &is_uni));
70
+ if(!is_uni) {
71
+ rb_warn("Warning! Cache database is not in Unicode mode. Perhaps, everything will fail working. In this case contact max@maxidoors.ru");
72
+ }
61
73
  return self;
62
74
  }
63
75
 
76
+ VALUE intersys_base_close(VALUE self) {
77
+ struct rbDatabase* base;
78
+ Data_Get_Struct(self, struct rbDatabase, base);
79
+ intersys_base_real_close(base);
80
+ return Qtrue;
81
+ }
82
+
83
+
64
84
  VALUE intersys_base_start(VALUE self) {
65
85
  struct rbDatabase* base;
66
86
  Data_Get_Struct(self, struct rbDatabase, base);
@@ -1,9 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "mkmf"
4
- #CONFIG["CPP"] = "g++"
5
- CONFIG["CC"] = "gcc -g"
6
4
 
5
+ CONFIG["CC"] = "gcc -g" unless RUBY_PLATFORM.match /mswin/
6
+
7
+ WIN32 = RUBY_PLATFORM.match(/mswin/)
8
+ MACOS = RUBY_PLATFORM.match(/darwin/)
7
9
 
8
10
  #alias :old_cpp_include :cpp_include
9
11
  #def cpp_include(header)
@@ -13,14 +15,14 @@ CONFIG["CC"] = "gcc -g"
13
15
  #EOF
14
16
  #end
15
17
 
16
- @cache_placements = ["/Applications/Cache", "/cygdrive/c/Progra~1/Cache", "/cygdrive/c/Cachesys"]
18
+ @cache_placements = ["/home/max/cache", "/Applications/Cache", "/cygdrive/c/Progra~1/Cache", "/cygdrive/c/Cachesys", "C:/Cachesys"]
17
19
 
18
20
  def locations(suffix)
19
- @cache_placements.map {|place| place + suffix}
20
- end
21
+ @cache_placements.map {|place| place + suffix}.map{|place| place.split("/").join(WIN32 ? "\\" : "/") }
22
+ end
21
23
 
22
24
  def include_locations
23
- locations("/dev/cpp/include")
25
+ locations("/dev/cpp/include") + ["./sql_include"]
24
26
  end
25
27
 
26
28
  def library_locations
@@ -31,9 +33,31 @@ end
31
33
  def include_flags
32
34
  " "+(include_locations.map { |place| "-I"+place} + ["-Wall"]).join(" ")
33
35
  end
34
- find_header "c_api.h", *include_locations
36
+
37
+ if WIN32
38
+ $CFLAGS << ' -I"C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Vc7\\PlatformSDK\\Include" '
39
+ $CFLAGS << ' -I"C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Vc7\\include" '
40
+ $LDFLAGS << ' -libpath:"C:\\CacheSys\\dev\\cpp\\lib" '
41
+ $LDFLAGS << ' -libpath:"C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Vc7\\lib" '
42
+ $LDFLAGS << ' -libpath:"C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Vc7\PlatformSDK\\Lib" '
43
+ end
44
+
45
+
46
+ def link_flags
47
+ " "+(library_locations.map { |place| "-L"+place} + ["-Wall"]).join(" ")
48
+ end
49
+
35
50
  $CFLAGS << include_flags
36
- #$LDFLAGS << "-Wl,-no-export-libs,cbind.lib"
37
- find_library "cbind", "cbind_alloc_db",*library_locations
51
+ $LDFLAGS << link_flags
52
+
53
+ have_header "c_api.h"
54
+ have_header "sql.h"
55
+ have_header "sqlext.h"
56
+
57
+ unless MACOS
58
+ find_library "cbind", "cbind_alloc_db",*library_locations
59
+ end
60
+
61
+
38
62
  create_makefile 'intersys_cache'
39
63
 
@@ -0,0 +1,66 @@
1
+ #include "intersys.h"
2
+
3
+
4
+ static void intersys_global_mark(struct rbGlobal* global) {
5
+ rb_gc_mark(global->name);
6
+ }
7
+
8
+ VALUE intersys_global_s_allocate(VALUE klass) {
9
+ struct rbGlobal* global = ALLOC(struct rbGlobal);
10
+ global->name = Qnil;
11
+ return Data_Wrap_Struct(klass, intersys_global_mark, 0, global);
12
+ }
13
+
14
+ VALUE intersys_global_initialize(VALUE self, VALUE name) {
15
+ struct rbGlobal* global;
16
+ Data_Get_Struct(self, struct rbGlobal, global);
17
+ global->name = name;
18
+ return self;
19
+ }
20
+
21
+ VALUE intersys_global_set(int argc, VALUE *argv, VALUE self) {
22
+ struct rbGlobal* global;
23
+ int i;
24
+ VALUE value = argv[argc - 1];
25
+ argc--;
26
+ Data_Get_Struct(self, struct rbGlobal, global);
27
+ for(i = 0; i < argc; i++) {
28
+ // marshall dimension
29
+ }
30
+ // perform setting with value
31
+ return Qnil;
32
+ return value;
33
+ }
34
+
35
+
36
+ VALUE intersys_global_get(int argc, VALUE *argv, VALUE self) {
37
+ struct rbGlobal* global;
38
+ int i;
39
+ VALUE value = Qnil;
40
+ Data_Get_Struct(self, struct rbGlobal, global);
41
+ for(i = 0; i < argc; i++) {
42
+ // marshall dimension
43
+ }
44
+ // perform getting with value
45
+ return value;
46
+ }
47
+
48
+ VALUE intersys_global_delete(int argc, VALUE *argv, VALUE self) {
49
+ struct rbGlobal* global;
50
+ int i;
51
+ Data_Get_Struct(self, struct rbGlobal, global);
52
+ for(i = 0; i < argc; i++) {
53
+ // marshall dimension
54
+ }
55
+ // perform getting with value
56
+ return Qnil;
57
+ }
58
+
59
+
60
+ VALUE intersys_global_name(VALUE self) {
61
+ struct rbGlobal* global;
62
+ Data_Get_Struct(self, struct rbGlobal, global);
63
+ return global->name;
64
+ }
65
+
66
+
@@ -1,8 +1,12 @@
1
1
  #include "intersys.h"
2
2
 
3
- VALUE mIntersys, cDatabase, cQuery, cObject, cDefinition, cProperty, cMethod, cArgument;
3
+ VALUE mIntersys, cDatabase, cObject, cDefinition, cProperty, cMethod, cArgument, cGlobal;
4
4
  VALUE cTime, cMarshallError, cUnMarshallError, cObjectNotFound, cIntersysException, cStatus;
5
5
 
6
+ #ifdef HAVE_SQL_H
7
+ VALUE cQuery;
8
+ #endif
9
+
6
10
  void Init_intersys_cache() {
7
11
  rb_define_method(rb_cString, "to_wchar", string_to_wchar, 0);
8
12
  rb_define_method(rb_cString, "from_wchar", string_from_wchar, 0);
@@ -35,15 +39,24 @@ void Init_intersys_cache() {
35
39
  rb_define_method(cDatabase, "rollback_db_transaction", intersys_base_rollback, 0);
36
40
  rb_define_method(cDatabase, "rollback", intersys_base_rollback, 0);
37
41
  rb_define_method(cDatabase, "level", intersys_base_level, 0);
42
+ rb_define_method(cDatabase, "close!", intersys_base_close, 0);
38
43
 
44
+ #ifdef HAVE_SQL_H
39
45
  cQuery = rb_define_class_under(mIntersys, "Query", rb_cObject);
40
46
  rb_define_alloc_func(cQuery, intersys_query_s_allocate);
41
- rb_define_method(cQuery, "native_initialize", intersys_query_initialize, 2);
47
+ rb_define_method(cQuery, "initialize", intersys_query_initialize, 2);
48
+ rb_define_method(cQuery, "bind_params", intersys_query_bind_params, 1);
42
49
  rb_define_method(cQuery, "execute", intersys_query_execute, 0);
43
50
  rb_define_method(cQuery, "fetch", intersys_query_fetch, 0);
51
+ rb_define_method(cQuery, "each", intersys_query_each, 0);
44
52
  rb_define_method(cQuery, "column_name", intersys_query_column_name, 1);
45
53
  rb_define_method(cQuery, "get_data", intersys_query_get_data, 1);
46
54
  rb_define_method(cQuery, "close", intersys_query_close, 0);
55
+ rb_define_method(cQuery, "limit", intersys_query_get_limit, 0);
56
+ rb_define_method(cQuery, "limit=", intersys_query_set_limit, 1);
57
+ rb_define_method(cQuery, "offset", intersys_query_get_offset, 0);
58
+ rb_define_method(cQuery, "offset=", intersys_query_set_offset, 1);
59
+ #endif
47
60
 
48
61
  cObject = rb_define_class_under(mIntersys, "Object", rb_cObject);
49
62
  rb_define_alloc_func(cObject, intersys_object_s_allocate);
@@ -76,6 +89,7 @@ void Init_intersys_cache() {
76
89
  cArgument = rb_define_class_under(mIntersys, "Argument", cDefinition);
77
90
  rb_define_method(cArgument, "initialize", intersys_argument_initialize, 4);
78
91
  rb_define_method(cArgument, "default", intersys_argument_default_value, 0);
92
+ rb_define_method(cArgument, "by_ref?", intersys_argument_is_by_ref, 0);
79
93
  rb_define_method(cArgument, "marshall_dlist_element", intersys_argument_marshall_dlist_elem, 1);
80
94
  rb_define_method(cArgument, "marshall_dlist", intersys_argument_marshall_dlist, 1);
81
95
  /*
@@ -88,6 +102,13 @@ void Init_intersys_cache() {
88
102
  "end\n" \
89
103
  "end");
90
104
  */
91
- rb_define_method(cArgument, "by_ref?", intersys_argument_is_by_ref, 0);
105
+
106
+ cGlobal = rb_define_class_under(mIntersys, "Global", rb_cObject);
107
+ rb_define_alloc_func(cGlobal, intersys_global_s_allocate);
108
+ rb_define_method(cGlobal, "initialize", intersys_global_initialize, 1);
109
+ rb_define_method(cGlobal, "[]=", intersys_global_set, -1);
110
+ rb_define_method(cGlobal, "[]", intersys_global_get, -1);
111
+ rb_define_method(cGlobal, "delete", intersys_global_delete, -1);
112
+ rb_define_method(cGlobal, "name", intersys_global_name, 0);
92
113
  }
93
114
 
@@ -10,14 +10,20 @@
10
10
  struct rbDatabase {
11
11
  h_connection connection;
12
12
  h_database database;
13
+ bool_t closed;
13
14
  };
14
15
 
16
+
17
+ #ifdef HAVE_SQL_H
15
18
  struct rbQuery {
16
19
  h_query query;
17
20
  bool_t empty;
18
21
  bool_t closed;
19
22
  bool_t executed;
23
+ int offset;
24
+ int limit;
20
25
  };
26
+ #endif
21
27
 
22
28
  struct rbObject {
23
29
  h_database database;
@@ -62,6 +68,10 @@ struct rbStatus {
62
68
  VALUE message;
63
69
  };
64
70
 
71
+ struct rbGlobal {
72
+ VALUE name;
73
+ };
74
+
65
75
  enum { D_PROPERTY, D_METHOD, D_ARGUMENT};
66
76
 
67
77
  enum {
@@ -69,7 +79,8 @@ enum {
69
79
  };
70
80
 
71
81
 
72
- extern VALUE mIntersys, cDatabase, cQuery, cObject, cDefinition, cProperty, cMethod, cArgument, cObjectNotFound, cStatus;
82
+ extern VALUE mIntersys, cDatabase, cQuery, cObject, cDefinition, cProperty,
83
+ cMethod, cArgument, cObjectNotFound, cStatus, cGlobal;
73
84
  extern VALUE cTime, cMarshallError, cUnMarshallError;
74
85
 
75
86
 
@@ -92,22 +103,30 @@ VALUE intersys_status_to_s(VALUE self);
92
103
  VALUE intersys_base_s_allocate(VALUE klass);
93
104
  VALUE intersys_base_initialize(VALUE self, VALUE options);
94
105
  VALUE intersys_base_connect(VALUE self, VALUE options);
106
+ VALUE intersys_base_close(VALUE self);
95
107
  VALUE intersys_base_start(VALUE self);
96
108
  VALUE intersys_base_commit(VALUE self);
97
109
  VALUE intersys_base_rollback(VALUE self);
98
110
  VALUE intersys_base_level(VALUE self);
99
111
 
100
112
 
113
+ #ifdef HAVE_SQL_H
101
114
  /******* Query functions *******/
102
115
 
103
116
  VALUE intersys_query_s_allocate(VALUE klass);
104
117
  VALUE intersys_query_initialize(VALUE self, VALUE database, VALUE sql_query);
118
+ VALUE intersys_query_bind_params(VALUE self, VALUE params);
105
119
  VALUE intersys_query_execute(VALUE self);
106
120
  VALUE intersys_query_column_name(VALUE self, VALUE index);
107
121
  VALUE intersys_query_get_data(VALUE self, VALUE index);
108
122
  VALUE intersys_query_fetch(VALUE self);
123
+ VALUE intersys_query_each(VALUE self);
109
124
  VALUE intersys_query_close(VALUE self);
110
-
125
+ VALUE intersys_query_set_limit(VALUE self, VALUE limit);
126
+ VALUE intersys_query_get_limit(VALUE self);
127
+ VALUE intersys_query_set_offset(VALUE self, VALUE limit);
128
+ VALUE intersys_query_get_offset(VALUE self);
129
+ #endif
111
130
 
112
131
 
113
132
  /******* Object functions *******/
@@ -147,7 +166,14 @@ VALUE intersys_argument_set(VALUE self, VALUE obj);
147
166
  VALUE intersys_method_extract_retval(VALUE self);
148
167
 
149
168
 
169
+ /******* Globals *******/
150
170
 
171
+ VALUE intersys_global_s_allocate(VALUE klass);
172
+ VALUE intersys_global_initialize(VALUE self, VALUE name);
173
+ VALUE intersys_global_get(int argc, VALUE* argv, VALUE self);
174
+ VALUE intersys_global_set(int argc, VALUE* argv, VALUE self);
175
+ VALUE intersys_global_delete(int argc, VALUE* argv, VALUE self);
176
+ VALUE intersys_global_name(VALUE self);
151
177
 
152
178
 
153
179
 
@@ -155,6 +181,7 @@ VALUE intersys_method_extract_retval(VALUE self);
155
181
  #define QUERY_RUN(x) {int sql_code = 0; (x); run(sql_code, __FILE__, __LINE__);}
156
182
  #define STR(x) (RSTRING(x)->ptr)
157
183
  #define LEN(x) (RSTRING(x)->len)
184
+ #define CAPA(x) (RSTRING(x)->aux.capa)
158
185
  #define CALL(x, method) (rb_funcall((x), rb_intern(method), 0))
159
186
 
160
187
  #define WCHARSTR(x) ((wchar_t *)STR(x))