cubrid 9.3.0 → 10.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ data.tar.gz: 45c8d580728c2b8fd878e6dffc96898ef99e7950
4
+ metadata.gz: 652b2d966b756120b7e8ac3c8e9c2884227f4c32
5
+ SHA512:
6
+ data.tar.gz: 298d7d57f3d33937247d05a2e4fc07f62e5e0ab22487083466fe3958430210a7965baa813ba2919db94ba577efea73b6d71eca4f3f2b168cdc8bf1a45d162740
7
+ metadata.gz: c0aede34b7995c1f2107c8ccb8b528b280466fe7dd491c9a42f14c2c5ac4b811e1da5a187071e322381246a1c4f9c82dcef66e710cd1d6d4cf160387a1217893
@@ -4,7 +4,6 @@
4
4
 
5
5
  This is a Ruby Driver and ActiveRecord Adapter for CUBRID Database.
6
6
 
7
- == Installation
8
7
  == Installation
9
8
 
10
9
  1. cd ext/
@@ -23,9 +22,11 @@ This is a Ruby Driver and ActiveRecord Adapter for CUBRID Database.
23
22
 
24
23
  * Cross-platform.
25
24
 
26
- * Compatible with CUBRID 9.3.0
25
+ * Compatible with CUBRID 10.1.0.
26
+
27
+ * Compatible with Ruby 1.8.7.
27
28
 
28
- * Compatible with Ruby 1.8.x and 1.9.x
29
+ * Ruby 1.9.1 is not supported yet.
29
30
 
30
31
  == Synopsis
31
32
 
@@ -35,7 +36,7 @@ Use Case:
35
36
 
36
37
  #1: @con = Cubrid.connect('dbname')
37
38
  #2: @con = Cubrid.connect('dbname', 'host', 'port', 'username', 'password')
38
- @con = Cubrid.connect('demodb', 'test-db-server', 30000, 'public', '')
39
+ @con = Cubrid.connect('demodb', 'localhost', '30000', 'public', '')
39
40
 
40
41
  puts @con.server_version
41
42
 
@@ -55,4 +56,4 @@ Use Case:
55
56
 
56
57
  Author :: NHN Corp. <cubrid_ruby@nhncorp.com>
57
58
  Copyright :: Copyright (c) 2010 Search Solution Corporation
58
- License :: Ruby's
59
+ License :: Ruby's
data/ext/conn.c CHANGED
@@ -56,12 +56,12 @@ cubrid_conn_new(char *host, int port, char *db, char *user, char *passwd)
56
56
  {
57
57
  VALUE conn;
58
58
  Connection *c;
59
- int handle,res;
60
- T_CCI_ERROR error;
59
+ int handle;
61
60
 
62
- handle = cci_connect_ex(host, port, db, user, passwd,&error);
61
+ handle = cci_connect(host, port, db, user, passwd);
63
62
  if (handle < 0) {
64
- cubrid_handle_error(handle, &error);
63
+ cubrid_handle_error(handle, NULL);
64
+ return Qnil;
65
65
  }
66
66
 
67
67
  conn = Data_Make_Struct(cConnection, Connection, 0, cubrid_conn_free, c);
@@ -71,13 +71,7 @@ cubrid_conn_new(char *host, int port, char *db, char *user, char *passwd)
71
71
  c->port = port;
72
72
  strcpy(c->db, db);
73
73
  strcpy(c->user, user);
74
- c->auto_commit = Qtrue;
75
-
76
- res = cci_set_autocommit(handle,CCI_AUTOCOMMIT_TRUE);
77
- if (res < 0)
78
- {
79
- cubrid_handle_error (res, NULL);
80
- }
74
+ c->auto_commit = Qfalse;
81
75
 
82
76
  return conn;
83
77
  }
@@ -85,6 +79,7 @@ cubrid_conn_new(char *host, int port, char *db, char *user, char *passwd)
85
79
  /* call-seq:
86
80
  * close() -> nil
87
81
  *
82
+ * 데이터베이스와의 연결을 헤제합니다. 이 연결로부터 생성된 Statement도 모두 close됩니다.
88
83
  */
89
84
  VALUE
90
85
  cubrid_conn_close(VALUE self)
@@ -128,6 +123,15 @@ cubrid_conn_prepare_internal(int argc, VALUE* argv, VALUE self)
128
123
  * prepare(sql <, option>) -> Statement
129
124
  * prepare(sql <, option>) { |stmt| block } -> nil
130
125
  *
126
+ * 주어진 SQL을 실행할 준비를 하고 Statement 객체를 반환합니다.
127
+ * SQL은 데이터베이스 서버로 보내져 파싱되어 실행할 수 있도록 준비됩니다.
128
+ *
129
+ * option으로 Cubrid::INCLUDE_OID를 줄 수 있는데, 이것은 SQL 실행 결과에 OID를 포함하도록 합니다.
130
+ * 실행 결과에 포함된 OID는 Statement.get_oid 메쏘드로 얻을 수 있습니다.
131
+ *
132
+ * block 주어지면 생성된 Statement 객체를 인수로 전달하여 block을 실행시킵니다.
133
+ * block의 수행이 끝나면 Statement 객체는 더이상 유효하지 않습니다.
134
+ *
131
135
  * con = Cubrid.connect('demodb')
132
136
  * stmt = con.prepare('SELECT * FROM db_user')
133
137
  * stmt.execute
@@ -165,6 +169,15 @@ cubrid_conn_prepare(int argc, VALUE* argv, VALUE self)
165
169
  * query(sql <, option>) -> Statement
166
170
  * query(sql <, option>) { |row| block } -> nil
167
171
  *
172
+ * 주어진 SQL을 실행할 준비를 하고 실행까지 시킨 후 Statement 객체를 반환합니다.
173
+ * 따라서 Statement.execute를 수행할 필요없이 바로 결과를 받아올 수 있습니다.
174
+ *
175
+ * option으로 Cubrid::INCLUDE_OID를 줄 수 있는데, 이것은 prepare 메쏘드의 그것과 동일합니다.
176
+ *
177
+ * block 주어지면 Statement.fetch를 호출하여 얻어온 결과를 인수로 전달하여 block을 실행시킵니다.
178
+ * block은 SQL 실행 결과로 넘어온 모든 row 대해서 한번씩 호출됩니다.
179
+ * block이 끝나면 Statement 객체는 더 이상 유효하지 않습니다.
180
+ *
168
181
  * con = Cubrid.connect('demodb')
169
182
  * stmt = con.query('SELECT * FROM db_user')
170
183
  * while row = stmt.fetch
@@ -225,6 +238,10 @@ cubrid_conn_end_tran(Connection *con, int type)
225
238
 
226
239
  /* call-seq:
227
240
  * commit() -> nil
241
+ *
242
+ * 트랜잭션을 commit으로 종료합니다.
243
+ * 트랜잭션이 종료되면 이 연결로 부터 생성된 모든 Statement 객체도 모두 close 됩니다.
244
+ *
228
245
  */
229
246
  VALUE
230
247
  cubrid_conn_commit(VALUE self)
@@ -239,6 +256,9 @@ cubrid_conn_commit(VALUE self)
239
256
 
240
257
  /* call-seq:
241
258
  * rollback() -> nil
259
+ *
260
+ * 트랜잭션을 rollback으로 종료합니다.
261
+ * 트랜잭션이 종료되면 이 연결로 부터 생성된 모든 Statement 객체도 모두 close 됩니다.
242
262
  *
243
263
  */
244
264
  VALUE
@@ -251,47 +271,13 @@ cubrid_conn_rollback(VALUE self)
251
271
 
252
272
  return Qnil;
253
273
  }
254
- /* call-seq:
255
- * last_insert_id? -> last_insert_id
256
- *
257
- */
258
-
259
- VALUE
260
- cubrid_conn_get_last_insert_id(VALUE self)
261
- {
262
- Connection *con;
263
- char *name = NULL;
264
- char ret[1024] = { '\0' };
265
- int res;
266
- T_CCI_ERROR error;
267
-
268
- GET_CONN_STRUCT(self, con);
269
- CHECK_CONNECTION(con, Qnil);
270
-
271
- /* cci_last_id set last_id as allocated string */
272
- res = cci_get_last_insert_id (con->handle, &name, &error);
273
-
274
- if (res < 0)
275
- {
276
- cubrid_handle_error (res, &error);
277
- return Qnil;
278
- }
279
-
280
- if (!name)
281
- {
282
- return Qnil;
283
- }
284
- else
285
- {
286
- strncpy (ret, name, sizeof (ret) - 1);
287
- }
288
-
289
- return rb_cstr2inum(ret, 10);
290
- }
291
-
292
274
 
293
275
  /* call-seq:
294
276
  * auto_commit? -> true or false
277
+ *
278
+ * Connection이 auto commit 모드인지 아닌지를 반환합니다.
279
+ * Connection은 기본적으로 auto commit 모드가 아니며, auto_commit= 메쏘드로 auto commit 여부를 설정할 수 있습니다.
280
+ *
295
281
  */
296
282
  VALUE
297
283
  cubrid_conn_get_auto_commit(VALUE self)
@@ -306,30 +292,19 @@ cubrid_conn_get_auto_commit(VALUE self)
306
292
 
307
293
  /* call-seq:
308
294
  * auto_commit= true or false -> nil
295
+ *
296
+ * Connection의 auto commit 모드를 설정합니다.
297
+ * auto commit이 true로 설정되면 Statement.execute의 실행이 끝난 후 바로 commit이 실행됩니다.
298
+ *
309
299
  */
310
300
  VALUE
311
301
  cubrid_conn_set_auto_commit(VALUE self, VALUE auto_commit)
312
302
  {
313
303
  Connection *con;
314
- int res=0;
315
304
 
316
305
  GET_CONN_STRUCT(self, con);
317
306
  CHECK_CONNECTION(con, self);
318
307
 
319
- if(auto_commit == Qtrue)
320
- {
321
- res = cci_set_autocommit(con->handle,CCI_AUTOCOMMIT_TRUE);
322
- }
323
- else
324
- {
325
- res = cci_set_autocommit(con->handle,CCI_AUTOCOMMIT_FALSE);
326
- }
327
-
328
- if (res < 0)
329
- {
330
- cubrid_handle_error (res, NULL);
331
- return Qnil;
332
- }
333
308
  con->auto_commit = auto_commit;
334
309
  return Qnil;
335
310
  }
@@ -337,6 +312,7 @@ cubrid_conn_set_auto_commit(VALUE self, VALUE auto_commit)
337
312
  /* call-seq:
338
313
  * to_s() -> string
339
314
  *
315
+ * Connection의 현재 연결 정보를 문자열로 반환합니다.
340
316
  */
341
317
  VALUE
342
318
  cubrid_conn_to_s(VALUE self)
@@ -352,6 +328,8 @@ cubrid_conn_to_s(VALUE self)
352
328
 
353
329
  /* call-seq:
354
330
  * server_version() -> string
331
+ *
332
+ * 연결된 서버의 버전을 문자열로 반환합니다.
355
333
  */
356
334
  VALUE
357
335
  cubrid_conn_server_version(VALUE self)
@@ -1,194 +1,197 @@
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
- char *cci_client_name = "CCI"; /* for lower than 7.0 */
34
- VALUE cCubrid, cConnection, cStatement, cOid,eCubrid,cCubrid;
35
- extern VALUE cubrid_conn_new(char *host, int port, char *db, char *user, char *passwd);
36
-
37
- VALUE GeteCubrid()
38
- {
39
- return eCubrid;
40
- }
41
-
42
- /* call-seq:
43
- * connect(db, host, port, user, password) -> Connection
44
- *
45
- *
46
- * con = Cubrid.connect('demodb', '192.168.1.1', '33000', 'foo','bar')
47
- * con.to_s #=> host: 192.168.1.1, port: 33000, db: demodb, user: foo
48
- *
49
- * con = Cubrid.connect('subway')
50
- * con.to_s #=> host: localhost, port: 30000, db: subway, user: PUBLIC
51
- *
52
- * con = Cubrid.connect('subway', '192.168.1.2')
53
- * con.to_s #=> host: 192.168.1.2, port: 33000, db: subway, user: PUBLIC
54
- */
55
- VALUE cubrid_connect(int argc, VALUE* argv, VALUE self)
56
- {
57
- VALUE host, port, db, user, passwd;
58
-
59
- rb_scan_args(argc, argv, "14", &db, &host, &port, &user, &passwd);
60
-
61
- if (NIL_P(db))
62
- rb_raise(rb_eStandardError, "DB name is required.");
63
-
64
- if (NIL_P(host))
65
- host = rb_str_new2("localhost");
66
-
67
- if (NIL_P(port))
68
- port = INT2NUM(30000);
69
-
70
- if (NIL_P(user))
71
- user = rb_str_new2("PUBLIC");
72
-
73
- if (NIL_P(passwd))
74
- passwd = rb_str_new2("");
75
-
76
- return cubrid_conn_new(StringValueCStr(host), NUM2INT(port),
77
- StringValueCStr(db), StringValueCStr(user), StringValueCStr(passwd));
78
- }
79
-
80
- /* from conn.c */
81
- extern VALUE cubrid_conn_close(VALUE self);
82
- extern VALUE cubrid_conn_prepare(int argc, VALUE* argv, VALUE self);
83
- extern VALUE cubrid_conn_query(int argc, VALUE* argv, VALUE self);
84
- extern VALUE cubrid_conn_commit(VALUE self);
85
- extern VALUE cubrid_conn_rollback(VALUE self);
86
- extern VALUE cubrid_conn_get_auto_commit(VALUE self);
87
- extern VALUE cubrid_conn_get_last_insert_id(VALUE self);
88
- extern VALUE cubrid_conn_set_auto_commit(VALUE self, VALUE auto_commit);
89
- extern VALUE cubrid_conn_to_s(VALUE self);
90
- extern VALUE cubrid_conn_server_version(VALUE self);
91
-
92
- /* from stmt.c */
93
- extern VALUE cubrid_stmt_close(VALUE self);
94
- extern VALUE cubrid_stmt_bind(int argc, VALUE* argv, VALUE self);
95
- extern VALUE cubrid_stmt_execute(int argc, VALUE* argv, VALUE self);
96
- extern VALUE cubrid_stmt_affected_rows(VALUE self);
97
- extern VALUE cubrid_stmt_fetch(VALUE self);
98
- extern VALUE cubrid_stmt_fetch_hash(VALUE self);
99
- extern VALUE cubrid_stmt_each(VALUE self);
100
- extern VALUE cubrid_stmt_each_hash(VALUE self);
101
- extern VALUE cubrid_stmt_column_info(VALUE self);
102
-
103
-
104
- /* CUBRID[http://www.cubrid.com] ruby driver
105
- *
106
- *
107
- * * Connection
108
- * * Statement
109
- * * Oid
110
- *
111
- * con = Cubrid.connect('demodb', '192.168.1.1', '33000', 'foo','bar')
112
- * stmt = con.prepare('SELECT * FROM db_user')
113
- * stmt.execute
114
- * stmt.each { |row|
115
- * print row
116
- * }
117
- * stmt.close
118
- * con.close
119
- *
120
- */
121
- void Init_cubrid()
122
- {
123
- cCubrid = rb_define_module("Cubrid");
124
- rb_define_module_function(cCubrid, "connect", cubrid_connect, -1);
125
-
126
- rb_define_const(cCubrid, "CHAR", INT2NUM(CCI_U_TYPE_CHAR));
127
- rb_define_const(cCubrid, "VARCHAR", INT2NUM(CCI_U_TYPE_STRING));
128
- rb_define_const(cCubrid, "STRING", INT2NUM(CCI_U_TYPE_STRING));
129
- rb_define_const(cCubrid, "NCHAR", INT2NUM(CCI_U_TYPE_NCHAR));
130
- rb_define_const(cCubrid, "VARNCHAR", INT2NUM(CCI_U_TYPE_VARNCHAR));
131
- rb_define_const(cCubrid, "BIT", INT2NUM(CCI_U_TYPE_BIT));
132
- rb_define_const(cCubrid, "VARBIT", INT2NUM(CCI_U_TYPE_VARBIT));
133
- rb_define_const(cCubrid, "NUMERIC", INT2NUM(CCI_U_TYPE_NUMERIC));
134
- rb_define_const(cCubrid, "INT", INT2NUM(CCI_U_TYPE_INT));
135
- rb_define_const(cCubrid, "BIGINT", INT2NUM(CCI_U_TYPE_BIGINT));
136
- rb_define_const(cCubrid, "SHORT", INT2NUM(CCI_U_TYPE_SHORT));
137
- rb_define_const(cCubrid, "MONETARY", INT2NUM(CCI_U_TYPE_MONETARY));
138
- rb_define_const(cCubrid, "FLOAT", INT2NUM(CCI_U_TYPE_FLOAT));
139
- rb_define_const(cCubrid, "DOUBLE", INT2NUM(CCI_U_TYPE_DOUBLE));
140
- rb_define_const(cCubrid, "DATE", INT2NUM(CCI_U_TYPE_DATE));
141
- rb_define_const(cCubrid, "TIME", INT2NUM(CCI_U_TYPE_TIME));
142
- rb_define_const(cCubrid, "TIMESTAMP", INT2NUM(CCI_U_TYPE_TIMESTAMP));
143
- rb_define_const(cCubrid, "SET", INT2NUM(CCI_U_TYPE_SET));
144
- rb_define_const(cCubrid, "MULTISET", INT2NUM(CCI_U_TYPE_MULTISET));
145
- rb_define_const(cCubrid, "SEQUENCE", INT2NUM(CCI_U_TYPE_SEQUENCE));
146
- rb_define_const(cCubrid, "OBJECT", INT2NUM(CCI_U_TYPE_OBJECT));
147
-
148
- rb_define_const(cCubrid, "INCLUDE_OID", INT2NUM(CCI_PREPARE_INCLUDE_OID));
149
- rb_define_const(cCubrid, "READ_LOCK", INT2NUM(CCI_OID_LOCK_READ));
150
- rb_define_const(cCubrid, "WRITE_LOCK", INT2NUM(CCI_OID_LOCK_WRITE));
151
-
152
- /* connection */
153
- cConnection = rb_define_class_under(cCubrid, "Connection", rb_cObject);
154
- rb_define_method(cConnection, "close", cubrid_conn_close, 0); /* in conn.c */
155
- rb_define_method(cConnection, "commit", cubrid_conn_commit, 0); /* in conn.c */
156
- rb_define_method(cConnection, "rollback", cubrid_conn_rollback, 0); /* in conn.c */
157
- rb_define_method(cConnection, "prepare", cubrid_conn_prepare, -1); /* in conn.c */
158
- rb_define_method(cConnection, "query", cubrid_conn_query, -1); /* in conn.c */
159
- rb_define_method(cConnection, "auto_commit?", cubrid_conn_get_auto_commit, 0); /* in conn.c */
160
- rb_define_method(cConnection, "last_insert_id", cubrid_conn_get_last_insert_id, 0); /* in conn.c */
161
- rb_define_method(cConnection, "auto_commit=", cubrid_conn_set_auto_commit, 1); /* in conn.c */
162
- rb_define_method(cConnection, "to_s", cubrid_conn_to_s, 0); /* in conn.c */
163
- rb_define_method(cConnection, "server_version", cubrid_conn_server_version, 0); /* in conn.c */
164
-
165
- /* statement */
166
- cStatement = rb_define_class_under(cCubrid, "Statement", rb_cObject);
167
- rb_define_method(cStatement, "bind", cubrid_stmt_bind, -1); /* in stmt.c */
168
- rb_define_method(cStatement, "execute", cubrid_stmt_execute, -1); /* in stmt.c */
169
- rb_define_method(cStatement, "affected_rows", cubrid_stmt_affected_rows, 0); /* in stmt.c */
170
- rb_define_method(cStatement, "column_info", cubrid_stmt_column_info, 0); /* in stmt.c */
171
- rb_define_method(cStatement, "fetch", cubrid_stmt_fetch, 0); /* in stmt.c */
172
- rb_define_method(cStatement, "fetch_hash", cubrid_stmt_fetch_hash, 0); /* in stmt.c */
173
- rb_define_method(cStatement, "each", cubrid_stmt_each, 0); /* in stmt.c */
174
- rb_define_method(cStatement, "each_hash", cubrid_stmt_each_hash, 0); /* in stmt.c */
175
- rb_define_method(cStatement, "close", cubrid_stmt_close, 0); /* in stmt.c */
176
-
177
- //error
178
- //cCubrid = rb_define_class("CUBRID", rb_cObject);
179
- eCubrid = rb_define_class_under(cCubrid, "Error", rb_eStandardError);
180
-
181
- }
182
-
183
- /* Document-class: Cubrid::Oid
184
- *
185
- */
186
-
187
- /* TODO:
188
- bind method & stored procedure
189
- save point
190
- db parameter : isolation level, max result count, lock time out, ..
191
- glo : load to buffer, save from buffer, performance task
192
- schema infomation
193
- */
194
-
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
+ char *cci_client_name = "CCI"; /* for lower than 7.0 */
34
+ VALUE cCubrid, cConnection, cStatement, cOid;
35
+ extern VALUE cubrid_conn_new(char *host, int port, char *db, char *user, char *passwd);
36
+
37
+ /* call-seq:
38
+ * connect(db, host, port, user, password) -> Connection
39
+ *
40
+ * 데이터베이스 서버에 연결하고 Connection 객체를 반환합니다.
41
+ * db는 반드시 주어져야 하고, host, port, user, password는 옵션입니다.
42
+ * 이들의 디폴트 값은 각각 'localhost', 30000, 'PUBLIC', '' 입니다.
43
+ *
44
+ * con = Cubrid.connect('demodb', '192.168.1.1', '33000', 'foo','bar')
45
+ * con.to_s #=> host: 192.168.1.1, port: 33000, db: demodb, user: foo
46
+ *
47
+ * con = Cubrid.connect('subway')
48
+ * con.to_s #=> host: localhost, port: 30000, db: subway, user: PUBLIC
49
+ *
50
+ * con = Cubrid.connect('subway', '192.168.1.2')
51
+ * con.to_s #=> host: 192.168.1.2, port: 33000, db: subway, user: PUBLIC
52
+ */
53
+ VALUE cubrid_connect(int argc, VALUE* argv, VALUE self)
54
+ {
55
+ VALUE host, port, db, user, passwd;
56
+
57
+ rb_scan_args(argc, argv, "14", &db, &host, &port, &user, &passwd);
58
+
59
+ if (NIL_P(db))
60
+ rb_raise(rb_eStandardError, "DB name is required.");
61
+
62
+ if (NIL_P(host))
63
+ host = rb_str_new2("localhost");
64
+
65
+ if (NIL_P(port))
66
+ port = INT2NUM(30000);
67
+
68
+ if (NIL_P(user))
69
+ user = rb_str_new2("PUBLIC");
70
+
71
+ if (NIL_P(passwd))
72
+ passwd = rb_str_new2("");
73
+
74
+ return cubrid_conn_new(StringValueCStr(host), NUM2INT(port),
75
+ StringValueCStr(db), StringValueCStr(user), StringValueCStr(passwd));
76
+ }
77
+
78
+ /* from conn.c */
79
+ extern VALUE cubrid_conn_close(VALUE self);
80
+ extern VALUE cubrid_conn_prepare(int argc, VALUE* argv, VALUE self);
81
+ extern VALUE cubrid_conn_query(int argc, VALUE* argv, VALUE self);
82
+ extern VALUE cubrid_conn_commit(VALUE self);
83
+ extern VALUE cubrid_conn_rollback(VALUE self);
84
+ extern VALUE cubrid_conn_get_auto_commit(VALUE self);
85
+ extern VALUE cubrid_conn_set_auto_commit(VALUE self, VALUE auto_commit);
86
+ extern VALUE cubrid_conn_to_s(VALUE self);
87
+ extern VALUE cubrid_conn_server_version(VALUE self);
88
+
89
+ /* from stmt.c */
90
+ extern VALUE cubrid_stmt_close(VALUE self);
91
+ extern VALUE cubrid_stmt_bind(int argc, VALUE* argv, VALUE self);
92
+ extern VALUE cubrid_stmt_execute(int argc, VALUE* argv, VALUE self);
93
+ extern VALUE cubrid_stmt_affected_rows(VALUE self);
94
+ extern VALUE cubrid_stmt_fetch(VALUE self);
95
+ extern VALUE cubrid_stmt_fetch_hash(VALUE self);
96
+ extern VALUE cubrid_stmt_each(VALUE self);
97
+ extern VALUE cubrid_stmt_each_hash(VALUE self);
98
+ extern VALUE cubrid_stmt_column_info(VALUE self);
99
+
100
+
101
+ /* CUBRID[http://www.cubrid.com] ruby driver
102
+ *
103
+ * CUBRID ruby driver는 ruby에서 CUBRID 데이터베이스 서버에 접속하여 질의를 할 수 있도록 해주는 모듈입니다.
104
+ *
105
+ * * Connection
106
+ * * Statement
107
+ * * Oid
108
+ *
109
+ * con = Cubrid.connect('demodb', '192.168.1.1', '33000', 'foo','bar')
110
+ * stmt = con.prepare('SELECT * FROM db_user')
111
+ * stmt.execute
112
+ * stmt.each { |row|
113
+ * print row
114
+ * }
115
+ * stmt.close
116
+ * con.close
117
+ *
118
+ */
119
+ void Init_cubrid()
120
+ {
121
+ cCubrid = rb_define_module("Cubrid");
122
+ rb_define_module_function(cCubrid, "connect", cubrid_connect, -1);
123
+
124
+ rb_define_const(cCubrid, "CHAR", INT2NUM(CCI_U_TYPE_CHAR));
125
+ rb_define_const(cCubrid, "VARCHAR", INT2NUM(CCI_U_TYPE_STRING));
126
+ rb_define_const(cCubrid, "STRING", INT2NUM(CCI_U_TYPE_STRING));
127
+ rb_define_const(cCubrid, "NCHAR", INT2NUM(CCI_U_TYPE_NCHAR));
128
+ rb_define_const(cCubrid, "VARNCHAR", INT2NUM(CCI_U_TYPE_VARNCHAR));
129
+ rb_define_const(cCubrid, "BIT", INT2NUM(CCI_U_TYPE_BIT));
130
+ rb_define_const(cCubrid, "VARBIT", INT2NUM(CCI_U_TYPE_VARBIT));
131
+ rb_define_const(cCubrid, "NUMERIC", INT2NUM(CCI_U_TYPE_NUMERIC));
132
+ rb_define_const(cCubrid, "INT", INT2NUM(CCI_U_TYPE_INT));
133
+ rb_define_const(cCubrid, "SHORT", INT2NUM(CCI_U_TYPE_SHORT));
134
+ rb_define_const(cCubrid, "MONETARY", INT2NUM(CCI_U_TYPE_MONETARY));
135
+ rb_define_const(cCubrid, "FLOAT", INT2NUM(CCI_U_TYPE_FLOAT));
136
+ rb_define_const(cCubrid, "DOUBLE", INT2NUM(CCI_U_TYPE_DOUBLE));
137
+ rb_define_const(cCubrid, "DATE", INT2NUM(CCI_U_TYPE_DATE));
138
+ rb_define_const(cCubrid, "TIME", INT2NUM(CCI_U_TYPE_TIME));
139
+ rb_define_const(cCubrid, "TIMESTAMP", INT2NUM(CCI_U_TYPE_TIMESTAMP));
140
+ rb_define_const(cCubrid, "SET", INT2NUM(CCI_U_TYPE_SET));
141
+ rb_define_const(cCubrid, "MULTISET", INT2NUM(CCI_U_TYPE_MULTISET));
142
+ rb_define_const(cCubrid, "SEQUENCE", INT2NUM(CCI_U_TYPE_SEQUENCE));
143
+ rb_define_const(cCubrid, "OBJECT", INT2NUM(CCI_U_TYPE_OBJECT));
144
+
145
+ rb_define_const(cCubrid, "INCLUDE_OID", INT2NUM(CCI_PREPARE_INCLUDE_OID));
146
+ rb_define_const(cCubrid, "READ_LOCK", INT2NUM(CCI_OID_LOCK_READ));
147
+ rb_define_const(cCubrid, "WRITE_LOCK", INT2NUM(CCI_OID_LOCK_WRITE));
148
+
149
+ /* connection */
150
+ cConnection = rb_define_class_under(cCubrid, "Connection", rb_cObject);
151
+ rb_define_method(cConnection, "close", cubrid_conn_close, 0); /* in conn.c */
152
+ rb_define_method(cConnection, "commit", cubrid_conn_commit, 0); /* in conn.c */
153
+ rb_define_method(cConnection, "rollback", cubrid_conn_rollback, 0); /* in conn.c */
154
+ rb_define_method(cConnection, "prepare", cubrid_conn_prepare, -1); /* in conn.c */
155
+ rb_define_method(cConnection, "query", cubrid_conn_query, -1); /* in conn.c */
156
+ rb_define_method(cConnection, "auto_commit?", cubrid_conn_get_auto_commit, 0); /* in conn.c */
157
+ rb_define_method(cConnection, "auto_commit=", cubrid_conn_set_auto_commit, 1); /* in conn.c */
158
+ rb_define_method(cConnection, "to_s", cubrid_conn_to_s, 0); /* in conn.c */
159
+ rb_define_method(cConnection, "server_version", cubrid_conn_server_version, 0); /* in conn.c */
160
+
161
+ /* statement */
162
+ cStatement = rb_define_class_under(cCubrid, "Statement", rb_cObject);
163
+ rb_define_method(cStatement, "bind", cubrid_stmt_bind, -1); /* in stmt.c */
164
+ rb_define_method(cStatement, "execute", cubrid_stmt_execute, -1); /* in stmt.c */
165
+ rb_define_method(cStatement, "affected_rows", cubrid_stmt_affected_rows, 0); /* in stmt.c */
166
+ rb_define_method(cStatement, "column_info", cubrid_stmt_column_info, 0); /* in stmt.c */
167
+ rb_define_method(cStatement, "fetch", cubrid_stmt_fetch, 0); /* in stmt.c */
168
+ rb_define_method(cStatement, "fetch_hash", cubrid_stmt_fetch_hash, 0); /* in stmt.c */
169
+ rb_define_method(cStatement, "each", cubrid_stmt_each, 0); /* in stmt.c */
170
+ rb_define_method(cStatement, "each_hash", cubrid_stmt_each_hash, 0); /* in stmt.c */
171
+ rb_define_method(cStatement, "close", cubrid_stmt_close, 0); /* in stmt.c */
172
+
173
+ }
174
+
175
+ /* Document-class: Cubrid::Connection
176
+ * Connection 클래스는 데이터베이스 서버에 대한 연결을 유지하고 트랜잭션을 연산을 수행합니다.
177
+ */
178
+
179
+ /* Document-class: Cubrid::Statement
180
+ * Statement 클래스는 질의문을 수행하고 그 결과를 반환합니다.
181
+ */
182
+
183
+ /* Document-class: Cubrid::Oid
184
+ * Oid 클래스는 CUBRID instance에 대하여 직접 연산을 수행할 수 있도록 합니다.
185
+ * CUBRID는 저장되어 있는 instance들의 고유한 식별자를 OID라는 이름으로 제공합니다.
186
+ * OID를 통해서 직접 해당하는 instance에 접근하여 read/write/update/delete 연산을 할 수 있습니다.
187
+ *
188
+ */
189
+
190
+ /* TODO:
191
+ bind method & stored procedure
192
+ save point
193
+ db parameter : isolation level, max result count, lock time out, ..
194
+ glo : load to buffer, save from buffer, performance task
195
+ schema infomation
196
+ */
197
+