cubrid 0.64 → 0.65

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. checksums.yaml +7 -0
  2. data/README.rdoc +59 -0
  3. data/ext/conn.c +0 -53
  4. data/ext/cubrid.c +2 -40
  5. data/ext/extconf.rb +2 -7
  6. data/ext/stmt.c +6 -61
  7. metadata +15 -26
  8. data/ext/oid.c +0 -727
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ data.tar.gz: 4b541805eb4f6c8f3da595303fcb84a4d929e301
4
+ metadata.gz: 25cddac3b2a33ce57a6321ed4d77a07124e1f48a
5
+ SHA512:
6
+ data.tar.gz: ed02be2895d1e54491c0322fbe64f94f271bbf6e750b16f10d10be09123f5133c53fdac4cf88b73e70d1bf7a2377d41d1eb5c1b64e17fce10ba581475020b6b3
7
+ metadata.gz: 792df3d5319b9b0e94b5e47aaf459bc7d973f299e690318dc500f6f173ecc1c451959ecb5e432417636ebca93fc8c003ab3ba2137f9c36ca319293d234fcf834
@@ -0,0 +1,59 @@
1
+ = cubrid-ruby
2
+
3
+ == Description
4
+
5
+ This is a Ruby Driver and ActiveRecord Adapter for CUBRID Database.
6
+
7
+ == Installation
8
+
9
+ 1. cd ext/
10
+ 2. ruby extconf.rb
11
+ 3. make install # make sure Ruby Development Kit (http://rubyinstaller.org) is installed.
12
+
13
+ === Gem Installation
14
+
15
+ Windows:
16
+ - gem install cubrid
17
+
18
+ Linux:
19
+ - sudo -E gem install cubrid
20
+
21
+ == Features/Problems
22
+
23
+ * Cross-platform.
24
+
25
+ * Compatible with CUBRID 2.2 x86.
26
+
27
+ * Compatible with Ruby 1.8.7.
28
+
29
+ * Ruby 1.9.1 is not supported yet.
30
+
31
+ == Synopsis
32
+
33
+ Use Case:
34
+
35
+ require 'cubrid'
36
+
37
+ #1: @con = Cubrid.connect('dbname')
38
+ #2: @con = Cubrid.connect('dbname', 'host', 'port', 'username', 'password')
39
+ @con = Cubrid.connect('demodb', 'localhost', '30000', 'public', '')
40
+
41
+ puts @con.server_version
42
+
43
+ if @con
44
+ sql = "SELECT * FROM event"
45
+ stmt = @con.prepare(sql)
46
+ stmt.execute
47
+
48
+ while row = stmt.fetch
49
+ puts "Record #{row[0]}: #{row[1]}"
50
+ end
51
+ else
52
+ puts "Connection could not be established"
53
+ end
54
+
55
+ == Copyright
56
+
57
+ Author :: NHN Corp. <cubrid_ruby@nhncorp.com>
58
+ Copyright :: Copyright (c) 2010 Search Solution Corporation
59
+ License :: Ruby's
data/ext/conn.c CHANGED
@@ -36,7 +36,6 @@ extern VALUE cubrid_stmt_new(Connection *con, char *stmt, int option);
36
36
  extern VALUE cubrid_stmt_execute(int argc, VALUE* argv, VALUE self);
37
37
  extern VALUE cubrid_stmt_fetch(VALUE self);
38
38
  extern VALUE cubrid_stmt_close(VALUE self);
39
- extern VALUE cubrid_oid_new(Connection *con, char *oid_str);
40
39
 
41
40
  static void
42
41
  cubrid_conn_free(void *p)
@@ -327,58 +326,6 @@ cubrid_conn_to_s(VALUE self)
327
326
  return rb_str_new2(buf);
328
327
  }
329
328
 
330
- /* call-seq:
331
- * glo_new(classname <, filename>) -> Oid
332
- *
333
- * 새로운 GLO 객체를 생성하고 Oid로 반환합니다.
334
- * CUBRID는 바이너리 데이터를 저장할 수 있도록 GLO를 제공합니다. GLO 객체는 OID로 직접 접근할 수 있습니다.
335
- *
336
- * filename이 주어지면 해당 파일의 데이터를 데이터베이스에 저장합니다. 주어지지 않으면 빈 GLO 객체를 생성합니다.
337
- *
338
- * con = Cubrid.connect('subway')
339
- * con.query('create table attachfile under glo (name string)')
340
- * con.commit
341
- *
342
- * glo = con.glo_new('attachfile', 'pic.jpg')
343
- * glo.glo_size #=> 1234
344
- *
345
- * glo = con.glo_new('attachfile')
346
- * glo.glo_size #=> 0
347
- * glo.glo_save('pic.jpg')
348
- * glo.glo_size #=> 1234
349
- */
350
- VALUE
351
- cubrid_conn_glo_new(VALUE self, VALUE table, VALUE file)
352
- {
353
- char oid_str[MAX_STR_LEN], *table_name, *file_name;
354
- int res;
355
- T_CCI_ERROR error;
356
- Connection *con;
357
-
358
- GET_CONN_STRUCT(self, con);
359
- CHECK_CONNECTION(con, Qnil);
360
-
361
- if (NIL_P(table)) {
362
- rb_raise(rb_eArgError, "class name is required.");
363
- return Qnil;
364
- }
365
- table_name = StringValueCStr(table);
366
-
367
- if (NIL_P(file)) {
368
- file_name = NULL;
369
- } else {
370
- file_name = StringValueCStr(file);
371
- }
372
-
373
- res = cci_glo_new(con->handle, table_name, file_name, oid_str, &error);
374
- if (res < 0) {
375
- cubrid_handle_error(res, &error);
376
- return Qnil;
377
- }
378
-
379
- return cubrid_oid_new(con, oid_str);
380
- }
381
-
382
329
  /* call-seq:
383
330
  * server_version() -> string
384
331
  *
@@ -84,7 +84,6 @@ extern VALUE cubrid_conn_rollback(VALUE self);
84
84
  extern VALUE cubrid_conn_get_auto_commit(VALUE self);
85
85
  extern VALUE cubrid_conn_set_auto_commit(VALUE self, VALUE auto_commit);
86
86
  extern VALUE cubrid_conn_to_s(VALUE self);
87
- extern VALUE cubrid_conn_glo_new(VALUE self, VALUE table, VALUE file);
88
87
  extern VALUE cubrid_conn_server_version(VALUE self);
89
88
 
90
89
  /* from stmt.c */
@@ -97,24 +96,7 @@ extern VALUE cubrid_stmt_fetch_hash(VALUE self);
97
96
  extern VALUE cubrid_stmt_each(VALUE self);
98
97
  extern VALUE cubrid_stmt_each_hash(VALUE self);
99
98
  extern VALUE cubrid_stmt_column_info(VALUE self);
100
- extern VALUE cubrid_stmt_get_oid(VALUE self);
101
-
102
- /* from oid.c */
103
- extern VALUE cubrid_oid_to_s(VALUE self);
104
- extern VALUE cubrid_oid_table(VALUE self);
105
- extern VALUE cubrid_oid_refresh(VALUE self);
106
- extern VALUE cubrid_oid_get_value(VALUE self, VALUE attr_name);
107
- extern VALUE cubrid_oid_set_value(VALUE self, VALUE attr_name, VALUE val);
108
- extern VALUE cubrid_oid_save(VALUE self);
109
- extern VALUE cubrid_oid_drop(VALUE self);
110
- extern VALUE cubrid_oid_lock(VALUE self);
111
- extern VALUE cubrid_oid_glo_load(VALUE self, VALUE file_name);
112
- extern VALUE cubrid_oid_glo_save(VALUE self, VALUE file_name);
113
- extern VALUE cubrid_oid_glo_drop(VALUE self);
114
- extern VALUE cubrid_oid_glo_size(VALUE self);
115
- extern VALUE cubrid_oid_each(VALUE self);
116
- extern VALUE cubrid_oid_method_missing(int argc, VALUE* argv, VALUE self);
117
- extern VALUE cubrid_oid_to_hash(VALUE self);
99
+
118
100
 
119
101
  /* CUBRID[http://www.cubrid.com] ruby driver
120
102
  *
@@ -174,7 +156,6 @@ void Init_cubrid()
174
156
  rb_define_method(cConnection, "auto_commit?", cubrid_conn_get_auto_commit, 0); /* in conn.c */
175
157
  rb_define_method(cConnection, "auto_commit=", cubrid_conn_set_auto_commit, 1); /* in conn.c */
176
158
  rb_define_method(cConnection, "to_s", cubrid_conn_to_s, 0); /* in conn.c */
177
- rb_define_method(cConnection, "glo_new", cubrid_conn_glo_new, 2); /* in conn.c */
178
159
  rb_define_method(cConnection, "server_version", cubrid_conn_server_version, 0); /* in conn.c */
179
160
 
180
161
  /* statement */
@@ -188,26 +169,7 @@ void Init_cubrid()
188
169
  rb_define_method(cStatement, "each", cubrid_stmt_each, 0); /* in stmt.c */
189
170
  rb_define_method(cStatement, "each_hash", cubrid_stmt_each_hash, 0); /* in stmt.c */
190
171
  rb_define_method(cStatement, "close", cubrid_stmt_close, 0); /* in stmt.c */
191
- rb_define_method(cStatement, "get_oid", cubrid_stmt_get_oid, 0); /* in stmt.c */
192
- /* stmt.to_s */
193
-
194
- /* oid */
195
- cOid = rb_define_class_under(cCubrid, "Oid", rb_cObject);
196
- rb_define_method(cOid, "to_s", cubrid_oid_to_s, 0); /* in oid.c */
197
- rb_define_method(cOid, "table", cubrid_oid_table, 0); /* in oid.c */
198
- rb_define_method(cOid, "[]", cubrid_oid_get_value, 1); /* in oid.c */
199
- rb_define_method(cOid, "[]=", cubrid_oid_set_value, 2); /* in oid.c */
200
- rb_define_method(cOid, "each", cubrid_oid_each, 0); /* in oid.c */
201
- rb_define_method(cOid, "refresh", cubrid_oid_refresh, 0); /* in oid.c */
202
- rb_define_method(cOid, "save", cubrid_oid_save, 0); /* in oid.c */
203
- rb_define_method(cOid, "drop", cubrid_oid_drop, 0); /* in oid.c */
204
- rb_define_method(cOid, "lock", cubrid_oid_lock, 1); /* in oid.c */
205
- rb_define_method(cOid, "to_hash", cubrid_oid_to_hash, 0); /* in oid.c */
206
- rb_define_method(cOid, "glo_load", cubrid_oid_glo_load, 1); /* in oid.c */
207
- rb_define_method(cOid, "glo_save", cubrid_oid_glo_save, 1); /* in oid.c */
208
- rb_define_method(cOid, "glo_drop", cubrid_oid_glo_drop, 0); /* in oid.c */
209
- rb_define_method(cOid, "glo_size", cubrid_oid_glo_size, 0); /* in oid.c */
210
- rb_define_method(cOid, "method_missing", cubrid_oid_method_missing, -1); /* in oid.c */
172
+
211
173
  }
212
174
 
213
175
  /* Document-class: Cubrid::Connection
@@ -32,12 +32,7 @@ require 'mkmf'
32
32
  require 'rbconfig'
33
33
 
34
34
  if ENV["CUBRID"]
35
- if Config::CONFIG["arch"] =~ /64/
36
- cci_lib_path = ENV["CUBRID"] + "/lib64"
37
- else
38
- cci_lib_path = ENV["CUBRID"] + "/lib"
39
- end
40
-
35
+ cci_lib_path = ENV["CUBRID"] + "/lib"
41
36
  cci_inc_path = ENV["CUBRID"] + "/include"
42
37
 
43
38
  $INCFLAGS = ($INCFLAGS ? $INCFLAGS : "") + " -I" + cci_inc_path
@@ -55,4 +50,4 @@ if ENV["CUBRID"]
55
50
  end
56
51
  else
57
52
  puts "$CUBRID_BROKER is not defined. Possibly you have not installed CUBRID Database yet."
58
- end
53
+ end
data/ext/stmt.c CHANGED
@@ -31,7 +31,6 @@
31
31
  #include "cubrid.h"
32
32
 
33
33
  extern VALUE cubrid_conn_end_tran(Connection *con, int type);
34
- extern VALUE cubrid_oid_new(Connection *con, char *oid_str);
35
34
 
36
35
  extern VALUE cStatement, cOid;
37
36
 
@@ -49,7 +48,7 @@ cubrid_stmt_new(Connection *con, char *sql, int option)
49
48
  int handle, param_cnt;
50
49
  T_CCI_ERROR error;
51
50
 
52
- printf("%s\n", sql);
51
+ /* printf("%s\n", sql); */
53
52
 
54
53
  handle = cci_prepare(con->handle, sql, option, &error);
55
54
  if (handle < 0) {
@@ -594,19 +593,6 @@ cubrid_stmt_dbval_to_ruby_value(int req_handle, int type, int index, Connection
594
593
  }
595
594
  break;
596
595
 
597
- case CCI_U_TYPE_OBJECT:
598
- res = cci_get_data(req_handle, index, CCI_A_TYPE_STR, &res_buf, &ind);
599
- if (res < 0) {
600
- cubrid_handle_error(res, NULL);
601
- return Qnil;
602
- }
603
- if (ind < 0) {
604
- val = Qnil;
605
- } else {
606
- val = cubrid_oid_new(con, res_buf);
607
- }
608
- break;
609
-
610
596
  case CCI_U_TYPE_DATE:
611
597
  case CCI_U_TYPE_TIME:
612
598
  case CCI_U_TYPE_TIMESTAMP:
@@ -707,19 +693,6 @@ cubrid_stmt_dbval_to_ruby_value_from_set(T_CCI_SET set, int type, int index, Con
707
693
  }
708
694
  break;
709
695
 
710
- case CCI_U_TYPE_OBJECT:
711
- res = cci_set_get(set, index, CCI_A_TYPE_STR, &res_buf, &ind);
712
- if (res < 0) {
713
- cubrid_handle_error(res, NULL);
714
- return Qnil;
715
- }
716
- if (ind < 0) {
717
- val = Qnil;
718
- } else {
719
- val = cubrid_oid_new(con, res_buf);
720
- }
721
- break;
722
-
723
696
  case CCI_U_TYPE_DATE:
724
697
  case CCI_U_TYPE_TIME:
725
698
  case CCI_U_TYPE_TIMESTAMP:
@@ -947,9 +920,9 @@ cubrid_stmt_each(VALUE self)
947
920
 
948
921
  while(1) {
949
922
  row = cubrid_stmt_fetch(self);
950
- if (NIL_P(row)) {
923
+ if (NIL_P(row)) {
951
924
  break;
952
- }
925
+ }
953
926
  rb_yield(row);
954
927
  }
955
928
 
@@ -978,9 +951,9 @@ cubrid_stmt_each_hash(VALUE self)
978
951
 
979
952
  while(1) {
980
953
  row = cubrid_stmt_fetch_hash(self);
981
- if (NIL_P(row)) {
954
+ if (NIL_P(row)) {
982
955
  break;
983
- }
956
+ }
984
957
  rb_yield(row);
985
958
  }
986
959
 
@@ -1010,7 +983,7 @@ cubrid_stmt_each_hash(VALUE self)
1010
983
  VALUE
1011
984
  cubrid_stmt_column_info(VALUE self)
1012
985
  {
1013
- VALUE desc;
986
+ VALUE desc;
1014
987
  int i;
1015
988
  char col_name[MAX_STR_LEN];
1016
989
  int datatype, precision, scale, nullable;
@@ -1044,31 +1017,3 @@ cubrid_stmt_column_info(VALUE self)
1044
1017
  return desc;
1045
1018
  }
1046
1019
 
1047
- /* call-seq:
1048
- * get_oid() -> Oid
1049
- *
1050
- * Cubrid::INCLUDE_OID 옵션으로 prepare된 Statement인 경우 실행 결과에 OID가 포함되어 있습니다.
1051
- * get_oid()는 이 OID를 다룰 수 있도록 Oid 객체를 생성하여 반환합니다.
1052
- *
1053
- * con = Cubrid.connect('demodb')
1054
- * con.prepare('SELECT * FROM db_user', CUBRID::INCLUDE_OID) { |stmt|
1055
- * stmt.execute
1056
- * stmt.fetch
1057
- * oid = stmt.get_oid
1058
- * print oid.table
1059
- * }
1060
- * con.close
1061
- */
1062
- VALUE
1063
- cubrid_stmt_get_oid(VALUE self)
1064
- {
1065
- Statement *stmt;
1066
- char oid_str[MAX_STR_LEN];
1067
-
1068
- GET_STMT_STRUCT(self, stmt);
1069
- CHECK_HANDLE(stmt, self);
1070
-
1071
- cci_get_cur_oid(stmt->handle, oid_str);
1072
- return cubrid_oid_new(stmt->con, oid_str);
1073
- }
1074
-
metadata CHANGED
@@ -1,12 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cubrid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 139
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 64
9
- version: "0.64"
4
+ version: "0.65"
10
5
  platform: ruby
11
6
  authors:
12
7
  - NHN
@@ -14,8 +9,7 @@ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
11
 
17
- date: 2010-08-09 00:00:00 +09:00
18
- default_executable:
12
+ date: 2013-03-11 00:00:00 Z
19
13
  dependencies: []
20
14
 
21
15
  description: This extension is a Ruby connector for CUBRID Database.
@@ -24,51 +18,46 @@ executables: []
24
18
 
25
19
  extensions:
26
20
  - ext/extconf.rb
27
- extra_rdoc_files: []
28
-
21
+ extra_rdoc_files:
22
+ - README.rdoc
29
23
  files:
24
+ - README.rdoc
30
25
  - ext/extconf.rb
31
26
  - ext/cubrid.c
32
27
  - ext/cubrid.h
33
28
  - ext/conn.c
34
29
  - ext/stmt.c
35
- - ext/oid.c
36
30
  - ext/error.c
37
- has_rdoc: true
38
31
  homepage: http://www.cubrid.org/cubrid_ruby_programming
39
32
  licenses: []
40
33
 
41
- post_install_message:
42
- rdoc_options: []
34
+ metadata: {}
43
35
 
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --title
39
+ - cubrid-ruby documentation
40
+ - --line-numbers
41
+ - --main
42
+ - README
44
43
  require_paths:
45
44
  - .
46
45
  required_ruby_version: !ruby/object:Gem::Requirement
47
- none: false
48
46
  requirements:
49
47
  - - ~>
50
48
  - !ruby/object:Gem::Version
51
- hash: 55
52
- segments:
53
- - 1
54
- - 8
55
- - 0
56
49
  version: 1.8.0
57
50
  required_rubygems_version: !ruby/object:Gem::Requirement
58
- none: false
59
51
  requirements:
60
52
  - - ">="
61
53
  - !ruby/object:Gem::Version
62
- hash: 3
63
- segments:
64
- - 0
65
54
  version: "0"
66
55
  requirements: []
67
56
 
68
57
  rubyforge_project: cubrid
69
- rubygems_version: 1.3.7
58
+ rubygems_version: 2.0.2
70
59
  signing_key:
71
- specification_version: 3
60
+ specification_version: 4
72
61
  summary: CUBRID Database API Module for Ruby
73
62
  test_files: []
74
63
 
data/ext/oid.c DELETED
@@ -1,727 +0,0 @@
1
- /*
2
- * Copyright (C) 2008 Search Solution Corporation. All rights reserved by Search Solution.
3
- *
4
- * Redistribution and use in source and binary forms, with or without modification,
5
- * are permitted provided that the following conditions are met:
6
- *
7
- * - Redistributions of source code must retain the above copyright notice,
8
- * this list of conditions and the following disclaimer.
9
- *
10
- * - Redistributions in binary form must reproduce the above copyright notice,
11
- * this list of conditions and the following disclaimer in the documentation
12
- * and/or other materials provided with the distribution.
13
- *
14
- * - Neither the name of the <ORGANIZATION> nor the names of its contributors
15
- * may be used to endorse or promote products derived from this software without
16
- * specific prior written permission.
17
- *
18
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
- * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24
- * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27
- * OF SUCH DAMAGE.
28
- *
29
- */
30
-
31
- #include "cubrid.h"
32
-
33
- extern VALUE cOid;
34
- extern VALUE cubrid_stmt_fetch_one_row(int req_handle, int col_count, T_CCI_COL_INFO *col_info, Connection *con);
35
- extern T_CCI_SET cubrid_stmt_make_set(VALUE data, int u_type);
36
-
37
- void
38
- cubrid_oid_free(void *p)
39
- {
40
- free(p);
41
- }
42
-
43
- VALUE
44
- cubrid_oid_new(Connection *con, char *oid_str)
45
- {
46
- VALUE oid;
47
- Oid *o;
48
-
49
- oid = Data_Make_Struct(cOid, Oid, 0, cubrid_oid_free, o);
50
-
51
- o->con = con;
52
- strcpy(o->oid_str, oid_str);
53
-
54
- return oid;
55
- }
56
-
57
- /* call-seq:
58
- * to_s() -> string
59
- *
60
- * OID string을 반환합니다.
61
- */
62
- VALUE
63
- cubrid_oid_to_s(VALUE self)
64
- {
65
- Oid *oid;
66
-
67
- Data_Get_Struct(self, Oid, oid);
68
- return rb_str_new2(oid->oid_str);
69
- }
70
-
71
- /* call-seq:
72
- * table() -> string
73
- *
74
- * OID의 table 이름을 반환합니다.
75
- */
76
- VALUE
77
- cubrid_oid_table(VALUE self)
78
- {
79
- Oid *oid;
80
- char table_name[MAX_STR_LEN];
81
- T_CCI_ERROR error;
82
-
83
- Data_Get_Struct(self, Oid, oid);
84
- CHECK_CONNECTION(oid->con, Qnil);
85
-
86
- cci_oid_get_class_name(oid->con->handle, oid->oid_str, table_name, MAX_STR_LEN, &error);
87
-
88
- return rb_str_new2(table_name);
89
- }
90
-
91
- /* call-seq:
92
- * refresh() -> self
93
- *
94
- * 데이터베이스 서버로 부터 OID의 데이터를 읽어옵니다.
95
- * OID의 컬럼 데이터는 데이터베이스 서버와 자동으로 동기화되지 않습니다.
96
- * Oid 객체가 생성된 후에 시간이 많이 경과하여 데이터베이스가 갱신되었을 가능성이 있다면
97
- * 이 메쏘드를 호출하여 데이터베이스 서버로 부터 최신의 데이터를 읽어올 수 있습니다.
98
- *
99
- * con = Cubrid.connect('demodb')
100
- * stmt = con.prepare('SELECT * FROM db_user', CUBRID::INCLUDE_OID)
101
- * stmt.execute
102
- * stmt.fetch
103
- * oid = stmt.get_oid
104
- * print oid['name']
105
- * #after some time
106
- * oid.refresh
107
- * print oid['name']
108
- * stmt.close
109
- * con.close
110
- *
111
- */
112
- VALUE
113
- cubrid_oid_refresh(VALUE self)
114
- {
115
- Oid *oid;
116
- int req_handle;
117
- T_CCI_ERROR error;
118
- T_CCI_COL_INFO *col_info;
119
- T_CCI_SQLX_CMD sql_type;
120
- int col_count, i, res;
121
- VALUE row, col;
122
- char *attr_name;
123
-
124
- Data_Get_Struct(self, Oid, oid);
125
- CHECK_CONNECTION(oid->con, self);
126
-
127
- req_handle = cci_oid_get(oid->con->handle, oid->oid_str, NULL, &error);
128
- if (req_handle < 0) {
129
- cubrid_handle_error(req_handle, &error);
130
- return self;
131
- }
132
-
133
- col_info = cci_get_result_info(req_handle, &sql_type, &col_count);
134
- if (!col_info) {
135
- cubrid_handle_error(CUBRID_ER_CANNOT_GET_COLUMN_INFO, &error);
136
- return self;
137
- }
138
-
139
- res = cci_cursor(req_handle, 1, CCI_CURSOR_CURRENT, &error);
140
- if (res < 0) {
141
- cubrid_handle_error(res, &error);
142
- return self;
143
- }
144
-
145
- res = cci_fetch(req_handle, &error);
146
- if (res < 0) {
147
- cubrid_handle_error(res, &error);
148
- return self;
149
- }
150
-
151
- row = cubrid_stmt_fetch_one_row(req_handle, col_count, col_info, oid->con);
152
-
153
- if (NIL_P(row)) { /* TODO */
154
- return self;
155
- }
156
-
157
- oid->hash = rb_hash_new();
158
- oid->col_type = rb_hash_new();
159
- oid->col_count = col_count;
160
-
161
- for(i = 0; i < col_count; i++) {
162
- col = RARRAY(row)->ptr[i];
163
- attr_name = CCI_GET_RESULT_INFO_NAME(col_info, i+1);
164
- rb_hash_aset(oid->hash, rb_str_new2(attr_name), col);
165
- rb_hash_aset(oid->col_type, rb_str_new2(attr_name), INT2NUM(CCI_GET_RESULT_INFO_TYPE(col_info, i+1)));
166
- }
167
-
168
- cci_close_req_handle(req_handle);
169
-
170
- return self;
171
- }
172
-
173
- /* call-seq:
174
- * [](col_name) -> obj
175
- *
176
- * OID의 컬럼 데이터를 반환합니다.
177
- *
178
- * con = Cubrid.connect('demodb')
179
- * stmt = con.prepare('SELECT * FROM db_user', CUBRID::INCLUDE_OID)
180
- * stmt.execute
181
- * stmt.fetch
182
- * oid = stmt.get_oid
183
- * print oid['name']
184
- * print oid.name
185
- * stmt.close
186
- * con.close
187
- *
188
- * 컬럼의 데이터에 접근하는 또다른 방법으로 컬럼의 이름을 메쏘드처럼 사용할 수 있습니다.
189
- *
190
- * oid = stmt.get_oid
191
- * print oid.name
192
- */
193
- VALUE
194
- cubrid_oid_get_value(VALUE self, VALUE attr_name)
195
- {
196
- Oid *oid;
197
- VALUE has_key;
198
-
199
- Data_Get_Struct(self, Oid, oid);
200
-
201
- if (oid->hash == Qfalse) {
202
- cubrid_oid_refresh(self);
203
- }
204
-
205
- has_key = rb_funcall(oid->hash, rb_intern("has_key?"), 1, attr_name);
206
- if (has_key == Qfalse) {
207
- rb_raise(rb_eArgError, "Invalid column name");
208
- return Qnil;
209
- }
210
-
211
- return rb_hash_aref(oid->hash, attr_name);
212
- }
213
-
214
- /* call-seq:
215
- * []=(col_name, obj) -> nil
216
- *
217
- * OID의 컬럼에 데이터를 저장합니다.
218
- * 저장된 데이터를 데이터베이스 서버에 반영하기 위해서는 save 메쏘드를 호출하여야 합니다.
219
- *
220
- * con = Cubrid.connect('demodb')
221
- * stmt = con.prepare('SELECT * FROM db_user', CUBRID::INCLUDE_OID)
222
- * stmt.execute
223
- * stmt.fetch
224
- * oid = stmt.get_oid
225
- * oid['name'] = 'foo'
226
- * oid.save
227
- * stmt.close
228
- * con.close
229
- *
230
- * 컬럼의 이름을 메쏘드처럼 사용하여 데이터를 저장할 수 도 있습니다.
231
- *
232
- * oid = stmt.get_oid
233
- * oid.name = 'foo'
234
- * oid.save
235
- */
236
- VALUE
237
- cubrid_oid_set_value(VALUE self, VALUE attr_name, VALUE val)
238
- {
239
- Oid *oid;
240
- VALUE has_key;
241
-
242
- Data_Get_Struct(self, Oid, oid);
243
-
244
- if (oid->hash == Qfalse) {
245
- cubrid_oid_refresh(self);
246
- }
247
-
248
- has_key = rb_funcall(oid->hash, rb_intern("has_key?"), 1, attr_name);
249
- if (has_key == Qfalse) {
250
- rb_raise(rb_eArgError, "Invalid column name");
251
- return Qnil;
252
- }
253
-
254
- return rb_hash_aset(oid->hash, attr_name, val);
255
- }
256
-
257
- /* call-seq:
258
- * save() -> self
259
- *
260
- * OID의 데이터를 데이터베이스 서버에 반영합니다.
261
- */
262
- VALUE
263
- cubrid_oid_save(VALUE self)
264
- {
265
- Oid *oid;
266
- int res, i, u_type;
267
- T_CCI_ERROR error;
268
- char **attr_names;
269
- void **vals;
270
- int *types;
271
- VALUE val, keys, key, col_type;
272
- int *int_val;
273
- double *dbl_val;
274
- T_CCI_SET set = NULL;
275
- T_CCI_DATE *date;
276
- T_CCI_BIT *bit;
277
-
278
- Data_Get_Struct(self, Oid, oid);
279
- CHECK_CONNECTION(oid->con, Qnil);
280
-
281
- if (oid->hash == Qfalse) {
282
- return self;
283
- }
284
-
285
- attr_names = (char **) ALLOCA_N(char *, oid->col_count + 1);
286
- if (attr_names == NULL) {
287
- rb_raise(rb_eNoMemError, "Not enough memory");
288
- return self;
289
- }
290
-
291
- attr_names[oid->col_count] = NULL;
292
-
293
- vals = (void **) ALLOCA_N(void *, oid->col_count);
294
- if (vals == NULL) {
295
- rb_raise(rb_eNoMemError, "Not enough memory");
296
- return self;
297
- }
298
-
299
- types = (int *) ALLOCA_N(int, oid->col_count);
300
- if (types == NULL) {
301
- rb_raise(rb_eNoMemError, "Not enough memory");
302
- return self;
303
- }
304
-
305
- keys = rb_funcall(oid->hash, rb_intern("keys"), 0);
306
-
307
- for(i = 0; i < oid->col_count; i++) {
308
- key = rb_ary_entry(keys, i);
309
- attr_names[i] = StringValueCStr(key);
310
- val = rb_hash_aref(oid->hash, key);
311
-
312
- switch (TYPE(val)) {
313
- case T_NIL:
314
- vals[i] = NULL;
315
- types[i] = CCI_A_TYPE_STR;
316
- break;
317
-
318
- case T_FIXNUM:
319
- case T_BIGNUM:
320
- int_val = (int *) ALLOCA_N(int, 1);
321
- if (int_val == NULL) {
322
- rb_raise(rb_eNoMemError, "Not enough memory");
323
- return self;
324
- }
325
-
326
- *int_val = NUM2INT(val);
327
- vals[i] = int_val;
328
- types[i] = CCI_A_TYPE_INT;
329
- break;
330
-
331
- case T_FLOAT:
332
- dbl_val = (double *) ALLOCA_N(double, 1);
333
- if (dbl_val == NULL) {
334
- rb_raise(rb_eNoMemError, "Not enough memory");
335
- return self;
336
- }
337
-
338
- *dbl_val = NUM2DBL(val);
339
- vals[i] = dbl_val;
340
- types[i] = CCI_A_TYPE_DOUBLE;
341
- break;
342
-
343
- case T_STRING:
344
- col_type = rb_hash_aref(oid->col_type, key);
345
- u_type = FIX2INT(col_type);
346
-
347
- if (u_type == CCI_U_TYPE_BIT || u_type == CCI_U_TYPE_VARBIT) {
348
- bit = (T_CCI_BIT *) ALLOCA_N(T_CCI_BIT, 1);
349
- if (bit == NULL) {
350
- rb_raise(rb_eNoMemError, "Not enough memory");
351
- return self;
352
- }
353
-
354
- bit->size = RSTRING(val)->len;
355
- bit->buf = RSTRING(val)->ptr;
356
- vals[i] = bit;
357
- types[i] = CCI_A_TYPE_BIT;
358
- } else {
359
- vals[i] = RSTRING(val)->ptr;
360
- types[i] = CCI_A_TYPE_STR;
361
- }
362
- break;
363
-
364
- case T_DATA:
365
- if (CLASS_OF(val) == rb_cTime) {
366
- VALUE a;
367
-
368
- a = rb_funcall(val, rb_intern("to_a"), 0);
369
-
370
- date = (T_CCI_DATE *) ALLOCA_N(T_CCI_DATE, 1);
371
- if (date == NULL) {
372
- rb_raise(rb_eNoMemError, "Not enough memory");
373
- return self;
374
- }
375
-
376
- date->ss = FIX2INT(RARRAY(a)->ptr[0]);
377
- date->mm = FIX2INT(RARRAY(a)->ptr[1]);
378
- date->hh = FIX2INT(RARRAY(a)->ptr[2]);
379
- date->day = FIX2INT(RARRAY(a)->ptr[3]);
380
- date->mon = FIX2INT(RARRAY(a)->ptr[4]);
381
- date->yr = FIX2INT(RARRAY(a)->ptr[5]);
382
-
383
- vals[i] = date;
384
- types[i] = CCI_A_TYPE_DATE;
385
- } else if (CLASS_OF(val) == cOid) {
386
- Oid *oid;
387
-
388
- Data_Get_Struct(val, Oid, oid);
389
- vals[i] = oid->oid_str;
390
- types[i] = CCI_A_TYPE_STR;
391
- }
392
- break;
393
-
394
- case T_ARRAY:
395
- set = cubrid_stmt_make_set(val, CCI_U_TYPE_UNKNOWN);
396
- vals[i] = set;
397
- types[i] = CCI_A_TYPE_SET;
398
- break;
399
-
400
- default:
401
- rb_raise(rb_eArgError, "Wrong data type");
402
- return self; /* TODO: avoid leak */
403
- }
404
- }
405
-
406
- res = cci_oid_put2(oid->con->handle, oid->oid_str, attr_names, vals, types, &error);
407
-
408
- for(i = 0; i < oid->col_count; i++) {
409
- if (types[i] == CCI_A_TYPE_SET) {
410
- cci_set_free(vals[i]);
411
- }
412
- }
413
-
414
- if (res < 0) {
415
- cubrid_handle_error(res, &error);
416
- return INT2NUM(0);
417
- }
418
-
419
- return self;
420
- }
421
-
422
- static VALUE
423
- cubrid_oid_cmd(VALUE self, T_CCI_OID_CMD cmd)
424
- {
425
- Oid *oid;
426
- int res;
427
- T_CCI_ERROR error;
428
-
429
- Data_Get_Struct(self, Oid, oid);
430
- CHECK_CONNECTION(oid->con, Qnil);
431
-
432
- res = cci_oid(oid->con->handle, cmd, oid->oid_str, &error);
433
-
434
- if (res < 0) {
435
- cubrid_handle_error(res, &error);
436
- return INT2NUM(0);
437
- }
438
-
439
- return Qnil;
440
- }
441
-
442
- /* call-seq:
443
- * drop() -> self
444
- *
445
- * OID를 데이터베이스 서버에서 삭제합니다.
446
- */
447
- VALUE
448
- cubrid_oid_drop(VALUE self)
449
- {
450
- return cubrid_oid_cmd(self, CCI_OID_DROP);
451
- }
452
-
453
- /* call-seq:
454
- * lock(lockmode) -> self
455
- *
456
- * OID에 Cubrid::READ_LOCK 또는 Cubrid::WRITE_LOCK 잠금을 설정합니다.
457
- * 설정된 잠금은 트랜잭션이 종료될 때 헤제됩니다.
458
- *
459
- */
460
- VALUE
461
- cubrid_oid_lock(VALUE self, VALUE lock)
462
- {
463
- return cubrid_oid_cmd(self, NUM2INT(lock));
464
- }
465
-
466
- /*
467
- stopdoc:
468
- static VALUE
469
- cubrid_oid_column_info(VALUE self)
470
- {
471
- VALUE desc;
472
- int req_handle;
473
- T_CCI_ERROR error;
474
- T_CCI_COL_INFO *col_info;
475
- T_CCI_SQLX_CMD sql_type;
476
- int col_count, i;
477
- char *col_name;
478
- int datatype, precision, scale, nullable;
479
- Oid *oid;
480
-
481
- Data_Get_Struct(self, Oid, oid);
482
- CHECK_CONNECTION(oid->con, self);
483
-
484
- req_handle = cci_oid_get(oid->con->handle, oid->oid_str, NULL, &error);
485
- if (req_handle < 0) {
486
- cubrid_handle_error(req_handle, &error);
487
- return Qnil;
488
- }
489
-
490
- col_info = cci_get_result_info(req_handle, &sql_type, &col_count);
491
- if (!col_info) {
492
- cubrid_handle_error(CUBRID_ER_CANNOT_GET_COLUMN_INFO, &error);
493
- return Qnil;
494
- }
495
-
496
- desc = rb_ary_new2(col_count);
497
-
498
- for (i = 0; i < col_count; i++) {
499
- VALUE item;
500
-
501
- item = rb_hash_new();
502
-
503
- col_name = CCI_GET_RESULT_INFO_NAME(col_info, i+1);
504
- precision = CCI_GET_RESULT_INFO_PRECISION(col_info, i+1);
505
- scale = CCI_GET_RESULT_INFO_SCALE(col_info, i+1);
506
- nullable = CCI_GET_RESULT_INFO_IS_NON_NULL(col_info, i+1);
507
- datatype = CCI_GET_RESULT_INFO_TYPE(col_info, i+1);
508
-
509
- rb_hash_aset(item, rb_str_new2("name"), rb_str_new2(col_name));
510
- rb_hash_aset(item, rb_str_new2("type_name"), INT2NUM(datatype));
511
- rb_hash_aset(item, rb_str_new2("precision"), INT2NUM(precision));
512
- rb_hash_aset(item, rb_str_new2("scale"), INT2NUM(scale));
513
- rb_hash_aset(item, rb_str_new2("nullable"), INT2NUM(nullable));
514
-
515
- rb_ary_push(desc, item);
516
- }
517
-
518
- cci_close_req_handle(req_handle);
519
-
520
- return desc;
521
- }
522
- startdoc:
523
- */
524
-
525
- /* call-seq:
526
- * glo_load(filename) -> File
527
- *
528
- * 데이터베이스에 저장되어 있는 GLO 데이터를 File로 저장합니다.
529
- *
530
- * con = Cubrid.connect('subway')
531
- * con.query('create table attachfile under glo (name string)')
532
- * con.commit
533
- *
534
- * glo = con.glo_new('attachfile', 'pic.jpg')
535
- * newfile = glo.glo_load('pic_copy.jpg')
536
- */
537
- VALUE
538
- cubrid_oid_glo_load(VALUE self, VALUE file_name)
539
- {
540
- Oid *oid;
541
- int res;
542
- T_CCI_ERROR error;
543
- VALUE file, fd;
544
-
545
- Data_Get_Struct(self, Oid, oid);
546
- CHECK_CONNECTION(oid->con, Qnil);
547
-
548
- file = rb_file_open(StringValueCStr(file_name), "w");
549
- fd = rb_funcall(file, rb_intern("fileno"), 0);
550
-
551
- res = cci_glo_load(oid->con->handle, oid->oid_str, FIX2INT(fd), &error);
552
- if (res < 0) {
553
- cubrid_handle_error(res, &error);
554
- return Qnil;
555
- }
556
-
557
- return file;
558
- }
559
-
560
- /* call-seq:
561
- * glo_save(filename) -> self
562
- *
563
- * 주어진 파일의 데이터를 데이터베이스 서버의 GLO로 저장합니다.
564
- *
565
- * con = Cubrid.connect('subway')
566
- * con.query('create table attachfile under glo (name string)')
567
- * con.commit
568
- *
569
- * glo = con.glo_new('attachfile')
570
- * glo.glo_save('pic.jpg')
571
- */
572
- VALUE
573
- cubrid_oid_glo_save(VALUE self, VALUE file_name)
574
- {
575
- Oid *oid;
576
- int res;
577
- T_CCI_ERROR error;
578
-
579
- Data_Get_Struct(self, Oid, oid);
580
- CHECK_CONNECTION(oid->con, self);
581
-
582
- if (NIL_P(file_name)) {
583
- rb_raise(rb_eArgError, "file name is required.");
584
- return self;
585
- }
586
-
587
- res = cci_glo_save(oid->con->handle, oid->oid_str, StringValueCStr(file_name), &error);
588
- if (res < 0) {
589
- cubrid_handle_error(res, &error);
590
- return self;
591
- }
592
-
593
- return self;
594
- }
595
-
596
- /* call-seq:
597
- * glo_size() -> int
598
- *
599
- * GLO에 저장된 데이터의 크기를 반환합니다.
600
- */
601
- VALUE
602
- cubrid_oid_glo_size(VALUE self)
603
- {
604
- Oid *oid;
605
- int size;
606
- T_CCI_ERROR error;
607
-
608
- Data_Get_Struct(self, Oid, oid);
609
- CHECK_CONNECTION(oid->con, INT2NUM(0));
610
-
611
- size = cci_glo_data_size(oid->con->handle, oid->oid_str, &error);
612
- if (size < 0) {
613
- cubrid_handle_error(size, &error);
614
- return INT2NUM(0);
615
- }
616
-
617
- return INT2NUM(size);
618
- }
619
-
620
- /* call-seq:
621
- * glo_drop() -> self
622
- *
623
- * 데이터베이스 서버에서 GLO를 삭제합니다.
624
- *
625
- * con = Cubrid.connect('demodb')
626
- * stmt = con.prepare("SELECT * FROM attachfile WHERE name = 'pig.jpg'", CUBRID::INCLUDE_OID)
627
- * stmt.execute
628
- * stmt.fetch
629
- * oid = stmt.get_oid
630
- * oid.drop
631
- */
632
- VALUE
633
- cubrid_oid_glo_drop(VALUE self)
634
- {
635
- Oid *oid;
636
- int res;
637
- T_CCI_ERROR error;
638
-
639
- Data_Get_Struct(self, Oid, oid);
640
- CHECK_CONNECTION(oid->con, self);
641
-
642
- res = cci_glo_destroy_data(oid->con->handle, oid->oid_str, &error);
643
- if (res < 0) {
644
- cubrid_handle_error(res, &error);
645
- return self;
646
- }
647
-
648
- return self;
649
- }
650
-
651
- /* call-seq:
652
- * each() { |name, val| block } -> nil
653
- *
654
- * OID의 컬럼 이름과 데이터를 넘겨 주어진 block을 실행합니다.
655
- *
656
- * con = Cubrid.connect('demodb')
657
- * stmt = con.prepare('SELECT * FROM db_user', CUBRID::INCLUDE_OID)
658
- * stmt.execute
659
- * stmt.fetch
660
- * oid = stmt.get_oid
661
- * oid.each { |name, val|
662
- * print name
663
- * print val
664
- * }
665
- */
666
- VALUE
667
- cubrid_oid_each(VALUE self)
668
- {
669
- Oid *oid;
670
-
671
- Data_Get_Struct(self, Oid, oid);
672
-
673
- if (oid->hash == Qfalse) {
674
- cubrid_oid_refresh(self);
675
- }
676
-
677
- rb_iterate(rb_each, oid->hash, rb_yield, Qnil);
678
-
679
- return Qnil;
680
- }
681
-
682
- /* call-seq:
683
- * to_hash() -> Hash
684
- *
685
- * OID의 데이터를 hash로 반환합니다. key는 컬럼의 이름이며, value는 컬럼의 데이터입니다.
686
- */
687
- VALUE
688
- cubrid_oid_to_hash(VALUE self)
689
- {
690
- Oid *oid;
691
-
692
- Data_Get_Struct(self, Oid, oid);
693
-
694
- if (oid->hash == Qfalse) {
695
- cubrid_oid_refresh(self);
696
- }
697
-
698
- return oid->hash;
699
- }
700
-
701
- VALUE
702
- cubrid_oid_method_missing(int argc, VALUE* argv, VALUE self)
703
- {
704
- Oid *oid;
705
- VALUE method, attr_name;
706
- char *attr_name_str;
707
- int size, is_set_method = 0;
708
-
709
- Data_Get_Struct(self, Oid, oid);
710
-
711
- method = rb_funcall(argv[0], rb_intern("id2name"), 0);
712
- attr_name_str = StringValueCStr(method);
713
- size = strlen(attr_name_str);
714
-
715
- if (attr_name_str[size - 1] == '=') {
716
- is_set_method = 1;
717
- attr_name_str[size - 1] = '\0';
718
- }
719
-
720
- attr_name = rb_str_new2(attr_name_str);
721
-
722
- if (is_set_method) {
723
- return cubrid_oid_set_value(self, attr_name, argv[1]);
724
- }
725
- return cubrid_oid_get_value(self, attr_name);
726
- }
727
-