cubrid 0.65 → 9.2.0
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.rdoc +1 -1
- data/ext/build_cci.sh +19 -0
- data/ext/cci.bz2 +0 -0
- data/ext/conn.c +57 -39
- data/ext/cubrid.c +194 -197
- data/ext/cubrid.h +122 -98
- data/ext/error.c +151 -144
- data/ext/extconf.rb +52 -19
- data/ext/stmt.c +1012 -1019
- metadata +28 -31
- checksums.yaml +0 -7
data/ext/extconf.rb
CHANGED
@@ -31,23 +31,56 @@
|
|
31
31
|
require 'mkmf'
|
32
32
|
require 'rbconfig'
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
34
|
+
|
35
|
+
if RUBY_PLATFORM.include?"linux"
|
36
|
+
|
37
|
+
if RUBY_PLATFORM.include?"64"
|
38
|
+
$os_type="x64"
|
39
|
+
else
|
40
|
+
$os_type="x86"
|
41
|
+
end
|
42
|
+
|
43
|
+
system("chmod +x build_cci.sh")
|
44
|
+
system("./build_cci.sh",$os_type)
|
45
|
+
|
46
|
+
cci_lib_path = "cci-src/cci/.libs/libcascci.a"
|
47
|
+
cci_base_inc_path = "./cci-src/src/base"
|
48
|
+
cci_cci_inc_path = "./cci-src/src/cci"
|
49
|
+
cci_broker_inc_path = "./cci-src/src/broker"
|
50
|
+
|
51
|
+
$INCFLAGS = ($INCFLAGS ? $INCFLAGS : "") + " -I" + cci_base_inc_path \
|
52
|
+
+" -I" + cci_cci_inc_path +" -I" + cci_broker_inc_path
|
53
|
+
|
54
|
+
if !$LIBPATH
|
55
|
+
$LIBPATH = []
|
56
|
+
end
|
57
|
+
|
58
|
+
$LIBPATH.push(cci_lib_path)
|
59
|
+
|
60
|
+
if have_library("supc++") and have_library("stdc++")
|
61
|
+
create_makefile("cubrid")
|
62
|
+
else
|
63
|
+
puts "your system can not support supc++ or stdc++,install failed."
|
64
|
+
end
|
65
|
+
|
66
|
+
else
|
67
|
+
if ENV["CUBRID"]
|
68
|
+
cci_lib_path = ENV["CUBRID"] + "\\lib"
|
69
|
+
cci_inc_path = ENV["CUBRID"] + "\\include"
|
70
|
+
|
71
|
+
$INCFLAGS = ($INCFLAGS ? $INCFLAGS : "") + " -I" + cci_inc_path
|
72
|
+
|
73
|
+
if !$LIBPATH
|
74
|
+
$LIBPATH = []
|
75
|
+
end
|
76
|
+
|
77
|
+
$LIBPATH.push(cci_lib_path)
|
78
|
+
if have_library("cascci", "cci_init")
|
79
|
+
create_makefile("cubrid")
|
80
|
+
else
|
81
|
+
puts "cascci could not be found.\nPlease check if CUBRID database is installed and if the $CUBRID environment variable is correctly set to the location where cubrid is installed."
|
82
|
+
end
|
83
|
+
else
|
84
|
+
puts "$CUBRID environment variable is not defined.\nPlease check that you have installed CUBRID database and if the $CUBRID environment variable is correctly set to the location where cubrid is installed."
|
85
|
+
end
|
53
86
|
end
|
data/ext/stmt.c
CHANGED
@@ -1,1019 +1,1012 @@
|
|
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 cubrid_conn_end_tran(Connection *con, int type);
|
34
|
-
|
35
|
-
extern VALUE cStatement, cOid;
|
36
|
-
|
37
|
-
void
|
38
|
-
cubrid_stmt_free(void *p)
|
39
|
-
{
|
40
|
-
free(p);
|
41
|
-
}
|
42
|
-
|
43
|
-
VALUE
|
44
|
-
cubrid_stmt_new(Connection *con, char *sql, int option)
|
45
|
-
{
|
46
|
-
VALUE cursor;
|
47
|
-
Statement *stmt;
|
48
|
-
int handle, param_cnt;
|
49
|
-
T_CCI_ERROR error;
|
50
|
-
|
51
|
-
/* printf("%s\n", sql); */
|
52
|
-
|
53
|
-
handle = cci_prepare(con->handle, sql, option, &error);
|
54
|
-
if (handle < 0) {
|
55
|
-
cubrid_handle_error(handle, &error);
|
56
|
-
return Qnil;
|
57
|
-
}
|
58
|
-
|
59
|
-
param_cnt = cci_get_bind_num(handle);
|
60
|
-
if (param_cnt < 0) {
|
61
|
-
cubrid_handle_error(param_cnt, NULL);
|
62
|
-
return Qnil;
|
63
|
-
}
|
64
|
-
|
65
|
-
cursor = Data_Make_Struct(cStatement, Statement, 0, cubrid_stmt_free, stmt);
|
66
|
-
stmt->con = con;
|
67
|
-
stmt->handle = handle;
|
68
|
-
stmt->param_cnt = param_cnt;
|
69
|
-
stmt->bound = 0;
|
70
|
-
|
71
|
-
return cursor;
|
72
|
-
}
|
73
|
-
|
74
|
-
/* call-seq:
|
75
|
-
* close() -> nil
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
double
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
T_CCI_BIT
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
char
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
T_CCI_DATE
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
date_ary[i].
|
228
|
-
date_ary[i].
|
229
|
-
date_ary[i].
|
230
|
-
date_ary[i].
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
if (u_type ==
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
date.
|
340
|
-
date.
|
341
|
-
date.
|
342
|
-
date.
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
Oid
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
*
|
393
|
-
*
|
394
|
-
*
|
395
|
-
*
|
396
|
-
*
|
397
|
-
*
|
398
|
-
*
|
399
|
-
*
|
400
|
-
*
|
401
|
-
*
|
402
|
-
*
|
403
|
-
*
|
404
|
-
*
|
405
|
-
*
|
406
|
-
*
|
407
|
-
*
|
408
|
-
*
|
409
|
-
*
|
410
|
-
* con.
|
411
|
-
|
412
|
-
|
413
|
-
*
|
414
|
-
|
415
|
-
*
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
{
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
case
|
451
|
-
case
|
452
|
-
case
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
}
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
*
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
stmt
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
*
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
val =
|
574
|
-
}
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
res =
|
584
|
-
if
|
585
|
-
cubrid_handle_error(res, NULL);
|
586
|
-
return Qnil;
|
587
|
-
}
|
588
|
-
if (ind < 0) {
|
589
|
-
val = Qnil;
|
590
|
-
} else {
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
case
|
597
|
-
case
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
}
|
634
|
-
break;
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
case
|
680
|
-
case
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
val =
|
690
|
-
}
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
case
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
}
|
734
|
-
break;
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
val
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
*
|
823
|
-
*
|
824
|
-
*
|
825
|
-
* *
|
826
|
-
*
|
827
|
-
*
|
828
|
-
*
|
829
|
-
*
|
830
|
-
*
|
831
|
-
*
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
res =
|
852
|
-
if (res
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
*
|
870
|
-
|
871
|
-
*
|
872
|
-
*
|
873
|
-
*
|
874
|
-
*
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
}
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
*
|
906
|
-
*
|
907
|
-
*
|
908
|
-
* con.
|
909
|
-
*
|
910
|
-
* stmt.
|
911
|
-
*
|
912
|
-
*
|
913
|
-
*
|
914
|
-
*
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
*
|
935
|
-
*
|
936
|
-
*
|
937
|
-
*
|
938
|
-
*
|
939
|
-
*
|
940
|
-
*
|
941
|
-
*
|
942
|
-
*
|
943
|
-
*
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
*
|
965
|
-
*
|
966
|
-
*
|
967
|
-
*
|
968
|
-
*
|
969
|
-
*
|
970
|
-
*
|
971
|
-
*
|
972
|
-
*
|
973
|
-
*
|
974
|
-
*
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
rb_ary_push(desc, item);
|
1015
|
-
}
|
1016
|
-
|
1017
|
-
return desc;
|
1018
|
-
}
|
1019
|
-
|
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 cubrid_conn_end_tran(Connection *con, int type);
|
34
|
+
|
35
|
+
extern VALUE cStatement, cOid;
|
36
|
+
|
37
|
+
void
|
38
|
+
cubrid_stmt_free(void *p)
|
39
|
+
{
|
40
|
+
free(p);
|
41
|
+
}
|
42
|
+
|
43
|
+
VALUE
|
44
|
+
cubrid_stmt_new(Connection *con, char *sql, int option)
|
45
|
+
{
|
46
|
+
VALUE cursor;
|
47
|
+
Statement *stmt;
|
48
|
+
int handle, param_cnt;
|
49
|
+
T_CCI_ERROR error;
|
50
|
+
|
51
|
+
/* printf("%s\n", sql); */
|
52
|
+
|
53
|
+
handle = cci_prepare(con->handle, sql, option, &error);
|
54
|
+
if (handle < 0) {
|
55
|
+
cubrid_handle_error(handle, &error);
|
56
|
+
return Qnil;
|
57
|
+
}
|
58
|
+
|
59
|
+
param_cnt = cci_get_bind_num(handle);
|
60
|
+
if (param_cnt < 0) {
|
61
|
+
cubrid_handle_error(param_cnt, NULL);
|
62
|
+
return Qnil;
|
63
|
+
}
|
64
|
+
|
65
|
+
cursor = Data_Make_Struct(cStatement, Statement, 0, cubrid_stmt_free, stmt);
|
66
|
+
stmt->con = con;
|
67
|
+
stmt->handle = handle;
|
68
|
+
stmt->param_cnt = param_cnt;
|
69
|
+
stmt->bound = 0;
|
70
|
+
|
71
|
+
return cursor;
|
72
|
+
}
|
73
|
+
|
74
|
+
/* call-seq:
|
75
|
+
* close() -> nil
|
76
|
+
*/
|
77
|
+
VALUE
|
78
|
+
cubrid_stmt_close(VALUE self)
|
79
|
+
{
|
80
|
+
Statement *stmt;
|
81
|
+
|
82
|
+
GET_STMT_STRUCT(self, stmt);
|
83
|
+
|
84
|
+
if (stmt->handle) {
|
85
|
+
cci_close_req_handle(stmt->handle);
|
86
|
+
stmt->handle = 0;
|
87
|
+
}
|
88
|
+
|
89
|
+
return Qnil;
|
90
|
+
}
|
91
|
+
|
92
|
+
T_CCI_SET
|
93
|
+
cubrid_stmt_make_set(VALUE data, int u_type) /* TODO: check if all item has same type */
|
94
|
+
{
|
95
|
+
int i, arr_size, res;
|
96
|
+
T_CCI_SET set = NULL;
|
97
|
+
void *val = NULL;
|
98
|
+
int *ind;
|
99
|
+
|
100
|
+
arr_size = RARRAY_LEN(data);//RARRAY(data)->len;
|
101
|
+
ind = ALLOCA_N(int, arr_size);
|
102
|
+
if (ind == NULL) {
|
103
|
+
rb_raise(rb_eNoMemError, "Not enough memory");
|
104
|
+
return NULL;
|
105
|
+
}
|
106
|
+
|
107
|
+
switch (TYPE(rb_ary_entry(data, 0))) {
|
108
|
+
case T_FIXNUM:
|
109
|
+
case T_BIGNUM:
|
110
|
+
{
|
111
|
+
int *int_ary = ALLOCA_N(int, arr_size);
|
112
|
+
if (int_ary == NULL) {
|
113
|
+
rb_raise(rb_eNoMemError, "Not enough memory");
|
114
|
+
return NULL;
|
115
|
+
}
|
116
|
+
|
117
|
+
for(i = 0; i < arr_size; i++) {
|
118
|
+
if (NIL_P(rb_ary_entry(data, i))) {
|
119
|
+
ind[i] = 1;
|
120
|
+
}
|
121
|
+
else {
|
122
|
+
int_ary[i] = NUM2INT(rb_ary_entry(data, i));
|
123
|
+
ind[i] = 0;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
if (u_type == CCI_U_TYPE_UNKNOWN) {
|
128
|
+
u_type = CCI_U_TYPE_INT;
|
129
|
+
}
|
130
|
+
val = int_ary;
|
131
|
+
}
|
132
|
+
break;
|
133
|
+
case T_FLOAT:
|
134
|
+
{
|
135
|
+
double *dbl_ary;
|
136
|
+
|
137
|
+
dbl_ary = ALLOCA_N(double, arr_size);
|
138
|
+
if (dbl_ary == NULL) {
|
139
|
+
rb_raise(rb_eNoMemError, "Not enough memory");
|
140
|
+
return NULL;
|
141
|
+
}
|
142
|
+
|
143
|
+
for(i = 0; i < arr_size; i++) {
|
144
|
+
if (NIL_P(rb_ary_entry(data, i))) {
|
145
|
+
ind[i] = 1;
|
146
|
+
}
|
147
|
+
else {
|
148
|
+
dbl_ary[i] = NUM2DBL(rb_ary_entry(data, i));
|
149
|
+
ind[i] = 0;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
if (u_type == CCI_U_TYPE_UNKNOWN) {
|
154
|
+
u_type = CCI_U_TYPE_DOUBLE;
|
155
|
+
}
|
156
|
+
val = dbl_ary;
|
157
|
+
}
|
158
|
+
break;
|
159
|
+
case T_STRING:
|
160
|
+
{
|
161
|
+
if (u_type == CCI_U_TYPE_BIT || u_type == CCI_U_TYPE_VARBIT) {
|
162
|
+
T_CCI_BIT *bit_ary;
|
163
|
+
|
164
|
+
bit_ary = ALLOCA_N(T_CCI_BIT, arr_size);
|
165
|
+
if (bit_ary == NULL) {
|
166
|
+
rb_raise(rb_eNoMemError, "Not enough memory");
|
167
|
+
return NULL;
|
168
|
+
}
|
169
|
+
|
170
|
+
for(i = 0; i < arr_size; i++) {
|
171
|
+
if (NIL_P(rb_ary_entry(data, i))) {
|
172
|
+
ind[i] = 1;
|
173
|
+
}
|
174
|
+
else {
|
175
|
+
bit_ary[i].size =RSTRING_LEN(rb_ary_entry(data, i));//RSTRING(rb_ary_entry(data, i))->len;
|
176
|
+
bit_ary[i].buf =RSTRING_PTR(rb_ary_entry(data, i)); //RSTRING(rb_ary_entry(data, i))->ptr;
|
177
|
+
ind[i] = 0;
|
178
|
+
}
|
179
|
+
}
|
180
|
+
|
181
|
+
val = bit_ary;
|
182
|
+
} else {
|
183
|
+
char **str_ary;
|
184
|
+
|
185
|
+
str_ary = ALLOCA_N(char*, arr_size);
|
186
|
+
if (str_ary == NULL) {
|
187
|
+
rb_raise(rb_eNoMemError, "Not enough memory");
|
188
|
+
return NULL;
|
189
|
+
}
|
190
|
+
|
191
|
+
for(i = 0; i < arr_size; i++) {
|
192
|
+
if (NIL_P(rb_ary_entry(data, i))) {
|
193
|
+
ind[i] = 1;
|
194
|
+
}
|
195
|
+
else {
|
196
|
+
str_ary[i] =RARRAY_PTR(rb_ary_entry(data, i));// RSTRING(rb_ary_entry(data, i))->ptr;
|
197
|
+
ind[i] = 0;
|
198
|
+
}
|
199
|
+
}
|
200
|
+
|
201
|
+
if (u_type == CCI_U_TYPE_UNKNOWN) {
|
202
|
+
u_type = CCI_U_TYPE_STRING;
|
203
|
+
}
|
204
|
+
val = str_ary;
|
205
|
+
}
|
206
|
+
}
|
207
|
+
break;
|
208
|
+
case T_DATA:
|
209
|
+
if (CLASS_OF(rb_ary_entry(data, 0)) == rb_cTime) {
|
210
|
+
VALUE a;
|
211
|
+
T_CCI_DATE *date_ary;
|
212
|
+
|
213
|
+
date_ary = ALLOCA_N(T_CCI_DATE, arr_size);
|
214
|
+
if (date_ary == NULL) {
|
215
|
+
rb_raise(rb_eNoMemError, "Not enough memory");
|
216
|
+
return NULL;
|
217
|
+
}
|
218
|
+
|
219
|
+
for(i = 0; i < arr_size; i++) {
|
220
|
+
if (NIL_P(rb_ary_entry(data, i))) {
|
221
|
+
ind[i] = 1;
|
222
|
+
}
|
223
|
+
else {
|
224
|
+
a = rb_funcall(rb_ary_entry(data, i), rb_intern("to_a"), 0);
|
225
|
+
date_ary[i].ss = FIX2INT(RARRAY_PTR(a)[0]);
|
226
|
+
date_ary[i].mm = FIX2INT(RARRAY_PTR(a)[1]);
|
227
|
+
date_ary[i].hh = FIX2INT(RARRAY_PTR(a)[2]);
|
228
|
+
date_ary[i].day = FIX2INT(RARRAY_PTR(a)[3]);
|
229
|
+
date_ary[i].mon = FIX2INT(RARRAY_PTR(a)[4]);
|
230
|
+
date_ary[i].yr = FIX2INT(RARRAY_PTR(a)[5]);
|
231
|
+
|
232
|
+
ind[i] = 0;
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
if (u_type == CCI_U_TYPE_UNKNOWN) {
|
237
|
+
u_type = CCI_U_TYPE_TIMESTAMP;
|
238
|
+
}
|
239
|
+
val = date_ary;
|
240
|
+
} else if (CLASS_OF(rb_ary_entry(data, 0)) == cOid) {
|
241
|
+
char **str_ary;
|
242
|
+
Oid *oid;
|
243
|
+
|
244
|
+
str_ary = ALLOCA_N(char*, arr_size);
|
245
|
+
if (str_ary == NULL) {
|
246
|
+
rb_raise(rb_eNoMemError, "Not enough memory");
|
247
|
+
return NULL;
|
248
|
+
}
|
249
|
+
|
250
|
+
for(i = 0; i < arr_size; i++) {
|
251
|
+
if (NIL_P(rb_ary_entry(data, i))) {
|
252
|
+
ind[i] = 1;
|
253
|
+
}
|
254
|
+
else {
|
255
|
+
Data_Get_Struct(rb_ary_entry(data, i), Oid, oid);
|
256
|
+
str_ary[i] = oid->oid_str;
|
257
|
+
ind[i] = 0;
|
258
|
+
}
|
259
|
+
}
|
260
|
+
|
261
|
+
if (u_type == CCI_U_TYPE_UNKNOWN) {
|
262
|
+
u_type = CCI_U_TYPE_OBJECT;
|
263
|
+
}
|
264
|
+
val = str_ary;
|
265
|
+
}
|
266
|
+
break;
|
267
|
+
default:
|
268
|
+
rb_raise(rb_eArgError, "Wrong data type");
|
269
|
+
break;
|
270
|
+
}
|
271
|
+
|
272
|
+
res = cci_set_make(&set, u_type, arr_size, val, ind);
|
273
|
+
if (res < 0) {
|
274
|
+
cubrid_handle_error(res, NULL);
|
275
|
+
return NULL;
|
276
|
+
}
|
277
|
+
|
278
|
+
return set;
|
279
|
+
}
|
280
|
+
|
281
|
+
static void
|
282
|
+
cubrid_stmt_bind_internal(Statement *stmt, int index, VALUE data, int u_type, int set_type)
|
283
|
+
{
|
284
|
+
int res, int_val, a_type = CCI_A_TYPE_STR;
|
285
|
+
char *str_val;
|
286
|
+
double dbl_val;
|
287
|
+
void *val = NULL;
|
288
|
+
T_CCI_SET set = NULL;
|
289
|
+
T_CCI_DATE date;
|
290
|
+
T_CCI_BIT bit;
|
291
|
+
|
292
|
+
switch (TYPE(data)) {
|
293
|
+
case T_NIL:
|
294
|
+
a_type = CCI_A_TYPE_STR;
|
295
|
+
val = NULL;
|
296
|
+
u_type = CCI_U_TYPE_NULL;
|
297
|
+
break;
|
298
|
+
|
299
|
+
case T_FIXNUM:
|
300
|
+
case T_BIGNUM:
|
301
|
+
int_val = NUM2INT(data);
|
302
|
+
a_type = CCI_A_TYPE_INT;
|
303
|
+
val = &int_val;
|
304
|
+
if (u_type == CCI_U_TYPE_UNKNOWN) {
|
305
|
+
u_type = CCI_U_TYPE_INT;
|
306
|
+
}
|
307
|
+
break;
|
308
|
+
|
309
|
+
case T_FLOAT:
|
310
|
+
dbl_val = NUM2DBL(data);
|
311
|
+
a_type = CCI_A_TYPE_DOUBLE;
|
312
|
+
val = &dbl_val;
|
313
|
+
if (u_type == CCI_U_TYPE_UNKNOWN) {
|
314
|
+
u_type = CCI_U_TYPE_DOUBLE;
|
315
|
+
}
|
316
|
+
break;
|
317
|
+
|
318
|
+
case T_STRING:
|
319
|
+
str_val = RARRAY_PTR(data);
|
320
|
+
a_type = CCI_A_TYPE_STR;
|
321
|
+
val = str_val;
|
322
|
+
if (u_type == CCI_U_TYPE_UNKNOWN) {
|
323
|
+
u_type = CCI_U_TYPE_STRING;
|
324
|
+
} else if (u_type == CCI_U_TYPE_BIT || u_type == CCI_U_TYPE_VARBIT) {
|
325
|
+
bit.size = RARRAY_LEN(data);
|
326
|
+
bit.buf = str_val;
|
327
|
+
a_type = CCI_A_TYPE_BIT;
|
328
|
+
val = &bit;
|
329
|
+
}
|
330
|
+
break;
|
331
|
+
|
332
|
+
case T_DATA:
|
333
|
+
if (CLASS_OF(data) == rb_cTime) {
|
334
|
+
VALUE a;
|
335
|
+
|
336
|
+
a = rb_funcall(data, rb_intern("to_a"), 0);
|
337
|
+
date.ss = FIX2INT(RARRAY_PTR(a)[0]);
|
338
|
+
date.mm = FIX2INT(RARRAY_PTR(a)[1]);
|
339
|
+
date.hh = FIX2INT(RARRAY_PTR(a)[2]);
|
340
|
+
date.day = FIX2INT(RARRAY_PTR(a)[3]);
|
341
|
+
date.mon = FIX2INT(RARRAY_PTR(a)[4]);
|
342
|
+
date.yr = FIX2INT(RARRAY_PTR(a)[5]);
|
343
|
+
|
344
|
+
a_type = CCI_A_TYPE_DATE;
|
345
|
+
val = &date;
|
346
|
+
if (u_type == CCI_U_TYPE_UNKNOWN) {
|
347
|
+
u_type = CCI_U_TYPE_TIMESTAMP;
|
348
|
+
}
|
349
|
+
} else if (CLASS_OF(data) == cOid) {
|
350
|
+
Oid *oid;
|
351
|
+
|
352
|
+
Data_Get_Struct(data, Oid, oid);
|
353
|
+
a_type = CCI_A_TYPE_STR;
|
354
|
+
val = oid->oid_str;
|
355
|
+
if (u_type == CCI_U_TYPE_UNKNOWN) {
|
356
|
+
u_type = CCI_U_TYPE_OBJECT;
|
357
|
+
}
|
358
|
+
}
|
359
|
+
break;
|
360
|
+
|
361
|
+
case T_ARRAY:
|
362
|
+
set = cubrid_stmt_make_set(data, set_type);
|
363
|
+
a_type = CCI_A_TYPE_SET;
|
364
|
+
val = set;
|
365
|
+
if (u_type == CCI_U_TYPE_UNKNOWN) {
|
366
|
+
u_type = CCI_U_TYPE_SET;
|
367
|
+
}
|
368
|
+
break;
|
369
|
+
|
370
|
+
default:
|
371
|
+
rb_raise(rb_eArgError, "Wrong data type");
|
372
|
+
return;
|
373
|
+
}
|
374
|
+
|
375
|
+
res = cci_bind_param(stmt->handle, index, a_type, val, u_type, 0);
|
376
|
+
|
377
|
+
if (TYPE(data) == T_ARRAY && set) {
|
378
|
+
cci_set_free(set);
|
379
|
+
}
|
380
|
+
|
381
|
+
if (res < 0) {
|
382
|
+
cubrid_handle_error(res, NULL);
|
383
|
+
return;
|
384
|
+
}
|
385
|
+
|
386
|
+
return;
|
387
|
+
}
|
388
|
+
|
389
|
+
/* call-seq:
|
390
|
+
* bind(index, data <, db_type, set_type>) -> nil
|
391
|
+
*
|
392
|
+
* *fixnum, bignum -> integer
|
393
|
+
* *float -> double
|
394
|
+
* *string -> string(varchar)
|
395
|
+
* *Time -> timestamp
|
396
|
+
* *Oid -> object
|
397
|
+
* *array -> collection
|
398
|
+
*
|
399
|
+
*
|
400
|
+
* con = Cubrid.connect('demodb')
|
401
|
+
* con.auto_commit = true
|
402
|
+
* con.query('create table a (a int, b double, c string, d date)')
|
403
|
+
* con.prepare('insert into a values (?, ?, ?, ?)') { |stmt|
|
404
|
+
* stmt.bind(1, 10)
|
405
|
+
* stmt.bind(2, 3.141592)
|
406
|
+
* stmt.bind(3, 'hello')
|
407
|
+
* stmt.bind(4, Time.local(2007, 12, 25, 10, 10, 10), CUBRID::DATE)
|
408
|
+
* stmt.execute
|
409
|
+
* }
|
410
|
+
* con.close
|
411
|
+
*/
|
412
|
+
VALUE
|
413
|
+
cubrid_stmt_bind(int argc, VALUE* argv, VALUE self)
|
414
|
+
{
|
415
|
+
Statement *stmt;
|
416
|
+
VALUE index, u_type, data, set_type;
|
417
|
+
|
418
|
+
GET_STMT_STRUCT(self, stmt);
|
419
|
+
CHECK_HANDLE(stmt, self);
|
420
|
+
|
421
|
+
rb_scan_args(argc, argv, "22", &index, &data, &u_type, &set_type);
|
422
|
+
|
423
|
+
if (NIL_P(u_type)) {
|
424
|
+
u_type = INT2NUM(CCI_U_TYPE_UNKNOWN);
|
425
|
+
}
|
426
|
+
|
427
|
+
if (NIL_P(set_type)) {
|
428
|
+
set_type = INT2NUM(CCI_U_TYPE_UNKNOWN);
|
429
|
+
}
|
430
|
+
|
431
|
+
cubrid_stmt_bind_internal(stmt, NUM2INT(index), data, NUM2INT(u_type), NUM2INT(set_type));
|
432
|
+
stmt->bound = 1;
|
433
|
+
|
434
|
+
return Qnil;
|
435
|
+
}
|
436
|
+
|
437
|
+
static int
|
438
|
+
cubrid_stmt_is_auto_commitable(T_CCI_SQLX_CMD cmd)
|
439
|
+
{
|
440
|
+
switch(cmd) {
|
441
|
+
case SQLX_CMD_SELECT:
|
442
|
+
case SQLX_CMD_CALL:
|
443
|
+
case SQLX_CMD_CALL_SP:
|
444
|
+
case SQLX_CMD_COMMIT_WORK:
|
445
|
+
case SQLX_CMD_ROLLBACK_WORK:
|
446
|
+
case SQLX_CMD_GET_ISO_LVL:
|
447
|
+
case SQLX_CMD_GET_TIMEOUT:
|
448
|
+
case SQLX_CMD_GET_OPT_LVL:
|
449
|
+
case SQLX_CMD_GET_TRIGGER:
|
450
|
+
case SQLX_CMD_SAVEPOINT:
|
451
|
+
case SQLX_CMD_GET_LDB:
|
452
|
+
case SQLX_CMD_GET_STATS:
|
453
|
+
return 0;
|
454
|
+
}
|
455
|
+
|
456
|
+
return 1;
|
457
|
+
}
|
458
|
+
|
459
|
+
/* call-seq:
|
460
|
+
* execute() -> int
|
461
|
+
* execute(...) -> int
|
462
|
+
*
|
463
|
+
* con = Cubrid.connect('demodb')
|
464
|
+
* con.prepare('insert into a values (?, ?, ?, ?)') { |stmt|
|
465
|
+
* stmt.execute (10, 3.141592, 'hello', Time.local(2007, 12, 25))
|
466
|
+
* }
|
467
|
+
* con.close
|
468
|
+
*/
|
469
|
+
VALUE
|
470
|
+
cubrid_stmt_execute(int argc, VALUE* argv, VALUE self)
|
471
|
+
{
|
472
|
+
T_CCI_ERROR error;
|
473
|
+
T_CCI_COL_INFO *res_col_info;
|
474
|
+
T_CCI_SQLX_CMD res_sql_type;
|
475
|
+
int res_col_count, row_count;
|
476
|
+
Statement *stmt;
|
477
|
+
|
478
|
+
GET_STMT_STRUCT(self, stmt);
|
479
|
+
CHECK_HANDLE(stmt, self);
|
480
|
+
|
481
|
+
if (!stmt->bound && stmt->param_cnt != argc) {
|
482
|
+
rb_raise(rb_eStandardError, "execute: param_count(%d) != number of argument(%d)",
|
483
|
+
stmt->param_cnt, argc);
|
484
|
+
return INT2NUM(0);
|
485
|
+
}
|
486
|
+
|
487
|
+
if (argc > 0) {
|
488
|
+
int i;
|
489
|
+
for (i = 0; i < argc; i++) {
|
490
|
+
cubrid_stmt_bind_internal(stmt, i + 1, argv[i], CCI_U_TYPE_UNKNOWN, CCI_U_TYPE_UNKNOWN);
|
491
|
+
}
|
492
|
+
}
|
493
|
+
|
494
|
+
row_count = cci_execute(stmt->handle, 0, 0, &error);
|
495
|
+
if (row_count < 0) {
|
496
|
+
cubrid_handle_error(row_count, &error);
|
497
|
+
return INT2NUM(0);
|
498
|
+
}
|
499
|
+
|
500
|
+
res_col_info = cci_get_result_info(stmt->handle, &res_sql_type, &res_col_count);
|
501
|
+
if (res_sql_type == SQLX_CMD_SELECT && !res_col_info) {
|
502
|
+
cubrid_handle_error(CUBRID_ER_CANNOT_GET_COLUMN_INFO, &error);
|
503
|
+
return INT2NUM(0);
|
504
|
+
}
|
505
|
+
|
506
|
+
stmt->col_info = res_col_info;
|
507
|
+
stmt->sql_type = res_sql_type;
|
508
|
+
stmt->col_count = res_col_count;
|
509
|
+
stmt->affected_rows = row_count;
|
510
|
+
|
511
|
+
if(stmt->con->auto_commit == Qtrue && cubrid_stmt_is_auto_commitable(stmt->sql_type)) {
|
512
|
+
cubrid_stmt_close(self);
|
513
|
+
cubrid_conn_end_tran(stmt->con, CCI_TRAN_COMMIT);
|
514
|
+
}
|
515
|
+
|
516
|
+
stmt->bound = 0;
|
517
|
+
return INT2NUM(row_count);
|
518
|
+
}
|
519
|
+
|
520
|
+
/* call-seq:
|
521
|
+
* affected_rows() -> int
|
522
|
+
*/
|
523
|
+
VALUE
|
524
|
+
cubrid_stmt_affected_rows(VALUE self)
|
525
|
+
{
|
526
|
+
Statement *stmt;
|
527
|
+
|
528
|
+
GET_STMT_STRUCT(self, stmt);
|
529
|
+
CHECK_HANDLE(stmt, self);
|
530
|
+
|
531
|
+
return INT2NUM(stmt->affected_rows);
|
532
|
+
}
|
533
|
+
|
534
|
+
static int ut_str_to_bigint (char *str, CUBRID_LONG_LONG * value)
|
535
|
+
{ char *end_p;
|
536
|
+
CUBRID_LONG_LONG bi_val;
|
537
|
+
bi_val = strtoll (str, &end_p, 10);
|
538
|
+
if (*end_p == 0 || *end_p == '.' || isspace ((int) *end_p))
|
539
|
+
{
|
540
|
+
*value = bi_val;
|
541
|
+
return 0;
|
542
|
+
}
|
543
|
+
|
544
|
+
return (-1);
|
545
|
+
|
546
|
+
}
|
547
|
+
|
548
|
+
|
549
|
+
static VALUE
|
550
|
+
cubrid_stmt_dbval_to_ruby_value(int req_handle, int type, int index, Connection *con)
|
551
|
+
{
|
552
|
+
int res, ind;
|
553
|
+
VALUE val;
|
554
|
+
char *res_buf;
|
555
|
+
int int_val;
|
556
|
+
double double_val;
|
557
|
+
T_CCI_DATE date;
|
558
|
+
T_CCI_BIT bit;
|
559
|
+
CUBRID_LONG_LONG l_val;
|
560
|
+
|
561
|
+
switch (type) {
|
562
|
+
case CCI_U_TYPE_INT:
|
563
|
+
case CCI_U_TYPE_SHORT:
|
564
|
+
res = cci_get_data(req_handle, index, CCI_A_TYPE_INT, &int_val, &ind);
|
565
|
+
if (res < 0) {
|
566
|
+
cubrid_handle_error(res, NULL);
|
567
|
+
return Qnil;
|
568
|
+
}
|
569
|
+
|
570
|
+
if (ind < 0) {
|
571
|
+
val = Qnil;
|
572
|
+
} else {
|
573
|
+
val = INT2NUM(int_val);
|
574
|
+
}
|
575
|
+
break;
|
576
|
+
case CCI_U_TYPE_BIGINT:
|
577
|
+
res = cci_get_data(req_handle, index, CCI_A_TYPE_STR, &res_buf, &ind);
|
578
|
+
if (res < 0) {
|
579
|
+
cubrid_handle_error(res, NULL);
|
580
|
+
return Qnil;
|
581
|
+
}
|
582
|
+
|
583
|
+
res = ut_str_to_bigint(res_buf,&l_val);
|
584
|
+
if(res < 0){
|
585
|
+
cubrid_handle_error(res, NULL);
|
586
|
+
return Qnil;
|
587
|
+
}
|
588
|
+
if (ind < 0) {
|
589
|
+
val = Qnil;
|
590
|
+
} else {
|
591
|
+
val = LL2NUM(l_val);
|
592
|
+
}
|
593
|
+
break;
|
594
|
+
case CCI_U_TYPE_FLOAT:
|
595
|
+
case CCI_U_TYPE_DOUBLE:
|
596
|
+
//case CCI_U_TYPE_NUMERIC:
|
597
|
+
case CCI_U_TYPE_MONETARY:
|
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
|
+
double_val = atof(res_buf);
|
607
|
+
val = rb_float_new(double_val);
|
608
|
+
}
|
609
|
+
break;
|
610
|
+
case CCI_U_TYPE_DATE:
|
611
|
+
case CCI_U_TYPE_TIME:
|
612
|
+
case CCI_U_TYPE_TIMESTAMP:
|
613
|
+
res = cci_get_data(req_handle, index, CCI_A_TYPE_DATE, &date, &ind);
|
614
|
+
if (res < 0) {
|
615
|
+
cubrid_handle_error(res, NULL);
|
616
|
+
return Qnil;
|
617
|
+
}
|
618
|
+
if (ind < 0) {
|
619
|
+
val = Qnil;
|
620
|
+
} else {
|
621
|
+
if (type == CCI_U_TYPE_DATE) {
|
622
|
+
val = rb_funcall(rb_cTime, rb_intern("mktime"), 3,
|
623
|
+
INT2NUM(date.yr), INT2NUM(date.mon), INT2NUM(date.day));
|
624
|
+
} else if (type == CCI_U_TYPE_TIME) {
|
625
|
+
val = rb_funcall(rb_cTime, rb_intern("mktime"), 7,
|
626
|
+
INT2NUM(1970), INT2NUM(1), INT2NUM(1),
|
627
|
+
INT2NUM(date.hh), INT2NUM(date.mm), INT2NUM(date.ss), INT2NUM(0));
|
628
|
+
} else {
|
629
|
+
val = rb_funcall(rb_cTime, rb_intern("mktime"), 7,
|
630
|
+
INT2NUM(date.yr), INT2NUM(date.mon), INT2NUM(date.day),
|
631
|
+
INT2NUM(date.hh), INT2NUM(date.mm), INT2NUM(date.ss), INT2NUM(0));
|
632
|
+
}
|
633
|
+
}
|
634
|
+
break;
|
635
|
+
|
636
|
+
case CCI_U_TYPE_BIT:
|
637
|
+
case CCI_U_TYPE_VARBIT:
|
638
|
+
res = cci_get_data(req_handle, index, CCI_A_TYPE_BIT, &bit, &ind);
|
639
|
+
if (res < 0) {
|
640
|
+
cubrid_handle_error(res, NULL);
|
641
|
+
return Qnil;
|
642
|
+
}
|
643
|
+
if (ind < 0) {
|
644
|
+
val = Qnil;
|
645
|
+
} else {
|
646
|
+
val = rb_tainted_str_new(bit.buf, bit.size);
|
647
|
+
}
|
648
|
+
break;
|
649
|
+
|
650
|
+
default:
|
651
|
+
res = cci_get_data(req_handle, index, CCI_A_TYPE_STR, &res_buf, &ind);
|
652
|
+
if (res < 0) {
|
653
|
+
cubrid_handle_error(res, NULL);
|
654
|
+
return Qnil;
|
655
|
+
}
|
656
|
+
if (ind < 0) {
|
657
|
+
val = Qnil;
|
658
|
+
} else {
|
659
|
+
val = rb_str_new2(res_buf);
|
660
|
+
}
|
661
|
+
break;
|
662
|
+
}
|
663
|
+
|
664
|
+
return val;
|
665
|
+
}
|
666
|
+
|
667
|
+
static VALUE
|
668
|
+
cubrid_stmt_dbval_to_ruby_value_from_set(T_CCI_SET set, int type, int index, Connection *con)
|
669
|
+
{
|
670
|
+
int res, ind;
|
671
|
+
VALUE val;
|
672
|
+
char *res_buf;
|
673
|
+
int int_val;
|
674
|
+
double double_val;
|
675
|
+
T_CCI_DATE date;
|
676
|
+
T_CCI_BIT bit;
|
677
|
+
|
678
|
+
switch (type) {
|
679
|
+
case CCI_U_TYPE_INT:
|
680
|
+
case CCI_U_TYPE_SHORT:
|
681
|
+
res = cci_set_get(set, index, CCI_A_TYPE_INT, &int_val, &ind);
|
682
|
+
if (res < 0) {
|
683
|
+
cubrid_handle_error(res, NULL);
|
684
|
+
return Qnil;
|
685
|
+
}
|
686
|
+
if (ind < 0) {
|
687
|
+
val = Qnil;
|
688
|
+
} else {
|
689
|
+
val = INT2NUM(int_val);
|
690
|
+
}
|
691
|
+
break;
|
692
|
+
|
693
|
+
case CCI_U_TYPE_FLOAT:
|
694
|
+
case CCI_U_TYPE_DOUBLE:
|
695
|
+
case CCI_U_TYPE_NUMERIC:
|
696
|
+
case CCI_U_TYPE_MONETARY:
|
697
|
+
res = cci_set_get(set, index, CCI_A_TYPE_STR, &res_buf, &ind);
|
698
|
+
if (res < 0) {
|
699
|
+
cubrid_handle_error(res, NULL);
|
700
|
+
return Qnil;
|
701
|
+
}
|
702
|
+
if (ind < 0) {
|
703
|
+
val = Qnil;
|
704
|
+
} else {
|
705
|
+
double_val = atof(res_buf);
|
706
|
+
val = rb_float_new(double_val);
|
707
|
+
}
|
708
|
+
break;
|
709
|
+
|
710
|
+
case CCI_U_TYPE_DATE:
|
711
|
+
case CCI_U_TYPE_TIME:
|
712
|
+
case CCI_U_TYPE_TIMESTAMP:
|
713
|
+
res = cci_set_get(set, index, CCI_A_TYPE_DATE, &date, &ind);
|
714
|
+
if (res < 0) {
|
715
|
+
cubrid_handle_error(res, NULL);
|
716
|
+
return Qnil;
|
717
|
+
}
|
718
|
+
if (ind < 0) {
|
719
|
+
val = Qnil;
|
720
|
+
} else {
|
721
|
+
if (type == CCI_U_TYPE_DATE) {
|
722
|
+
val = rb_funcall(rb_cTime, rb_intern("mktime"), 3,
|
723
|
+
INT2NUM(date.yr), INT2NUM(date.mon), INT2NUM(date.day));
|
724
|
+
} else if (type == CCI_U_TYPE_TIME) {
|
725
|
+
val = rb_funcall(rb_cTime, rb_intern("mktime"), 7,
|
726
|
+
INT2NUM(1970), INT2NUM(1), INT2NUM(1),
|
727
|
+
INT2NUM(date.hh), INT2NUM(date.mm), INT2NUM(date.ss), INT2NUM(0));
|
728
|
+
} else {
|
729
|
+
val = rb_funcall(rb_cTime, rb_intern("mktime"), 7,
|
730
|
+
INT2NUM(date.yr), INT2NUM(date.mon), INT2NUM(date.day),
|
731
|
+
INT2NUM(date.hh), INT2NUM(date.mm), INT2NUM(date.ss), INT2NUM(0));
|
732
|
+
}
|
733
|
+
}
|
734
|
+
break;
|
735
|
+
|
736
|
+
case CCI_U_TYPE_BIT:
|
737
|
+
case CCI_U_TYPE_VARBIT:
|
738
|
+
res = cci_set_get(set, index, CCI_A_TYPE_BIT, &bit, &ind);
|
739
|
+
if (res < 0) {
|
740
|
+
cubrid_handle_error(res, NULL);
|
741
|
+
return Qnil;
|
742
|
+
}
|
743
|
+
if (ind < 0) {
|
744
|
+
val = Qnil;
|
745
|
+
} else {
|
746
|
+
val = rb_tainted_str_new(bit.buf, bit.size);
|
747
|
+
}
|
748
|
+
break;
|
749
|
+
|
750
|
+
default:
|
751
|
+
res = cci_set_get(set, index, CCI_A_TYPE_STR, &res_buf, &ind);
|
752
|
+
if (res < 0) {
|
753
|
+
cubrid_handle_error(res, NULL);
|
754
|
+
return Qnil;
|
755
|
+
}
|
756
|
+
if (ind < 0) {
|
757
|
+
val = Qnil;
|
758
|
+
} else {
|
759
|
+
val = rb_str_new2(res_buf);
|
760
|
+
}
|
761
|
+
break;
|
762
|
+
}
|
763
|
+
|
764
|
+
return val;
|
765
|
+
}
|
766
|
+
|
767
|
+
static VALUE
|
768
|
+
cubrid_stmt_dbset_to_ruby_value(int req_handle, int index, Connection *con)
|
769
|
+
{
|
770
|
+
int i, res, ind, e_type;
|
771
|
+
VALUE val, e;
|
772
|
+
T_CCI_SET set = NULL;
|
773
|
+
int set_size;
|
774
|
+
|
775
|
+
res = cci_get_data(req_handle, index, CCI_A_TYPE_SET, &set, &ind);
|
776
|
+
if (res < 0) {
|
777
|
+
cubrid_handle_error(res, NULL);
|
778
|
+
return Qnil;
|
779
|
+
}
|
780
|
+
|
781
|
+
if (set == NULL)
|
782
|
+
return Qnil;
|
783
|
+
|
784
|
+
set_size = cci_set_size(set);
|
785
|
+
val = rb_ary_new2(set_size);
|
786
|
+
|
787
|
+
e_type = cci_set_element_type(set);
|
788
|
+
|
789
|
+
for (i = 0; i < set_size; i++) {
|
790
|
+
e = cubrid_stmt_dbval_to_ruby_value_from_set(set, e_type, i + 1, con);
|
791
|
+
rb_ary_push(val, e);
|
792
|
+
}
|
793
|
+
cci_set_free(set);
|
794
|
+
|
795
|
+
return val;
|
796
|
+
}
|
797
|
+
|
798
|
+
VALUE
|
799
|
+
cubrid_stmt_fetch_one_row(int req_handle, int col_count, T_CCI_COL_INFO *col_info, Connection *con)
|
800
|
+
{
|
801
|
+
int i, type;
|
802
|
+
VALUE row, val;
|
803
|
+
|
804
|
+
row = rb_ary_new();
|
805
|
+
|
806
|
+
for (i = 0; i < col_count; i++) {
|
807
|
+
type = CCI_GET_RESULT_INFO_TYPE(col_info, i + 1);
|
808
|
+
|
809
|
+
if (CCI_IS_COLLECTION_TYPE(type)) {
|
810
|
+
val = cubrid_stmt_dbset_to_ruby_value(req_handle, i + 1, con);
|
811
|
+
} else {
|
812
|
+
val = cubrid_stmt_dbval_to_ruby_value(req_handle, type, i + 1, con);
|
813
|
+
}
|
814
|
+
|
815
|
+
rb_ary_push(row, val);
|
816
|
+
}
|
817
|
+
|
818
|
+
return row;
|
819
|
+
}
|
820
|
+
|
821
|
+
/* call-seq:
|
822
|
+
* fetch() -> array or nil
|
823
|
+
*
|
824
|
+
* con = Cubrid.connect('demodb')
|
825
|
+
* con.prepare('SELECT * FROM db_user') { |stmt|
|
826
|
+
* stmt.execute
|
827
|
+
* r = stmt.fetch
|
828
|
+
* print r[0]
|
829
|
+
* }
|
830
|
+
* con.close
|
831
|
+
*
|
832
|
+
* *int, short -> fixnum, bignum
|
833
|
+
* *float, double, numeric, monetary -> float
|
834
|
+
* *char, varchar, ncahr, varnchar -> string
|
835
|
+
* *bit, varbit -> string
|
836
|
+
* *date, time, timestamp -> Time
|
837
|
+
* *object -> Oid
|
838
|
+
* *collection -> array
|
839
|
+
*
|
840
|
+
*/
|
841
|
+
VALUE
|
842
|
+
cubrid_stmt_fetch(VALUE self)
|
843
|
+
{
|
844
|
+
int res;
|
845
|
+
T_CCI_ERROR error;
|
846
|
+
Statement *stmt;
|
847
|
+
|
848
|
+
GET_STMT_STRUCT(self, stmt);
|
849
|
+
CHECK_HANDLE(stmt, self);
|
850
|
+
|
851
|
+
res = cci_cursor(stmt->handle, 1, CCI_CURSOR_CURRENT, &error);
|
852
|
+
if (res == CCI_ER_NO_MORE_DATA) {
|
853
|
+
return Qnil;
|
854
|
+
} else if (res < 0) {
|
855
|
+
cubrid_handle_error(res, &error);
|
856
|
+
return Qnil;
|
857
|
+
}
|
858
|
+
|
859
|
+
res = cci_fetch(stmt->handle, &error);
|
860
|
+
if (res < 0) {
|
861
|
+
cubrid_handle_error(res, &error);
|
862
|
+
return Qnil;
|
863
|
+
}
|
864
|
+
|
865
|
+
return cubrid_stmt_fetch_one_row(stmt->handle, stmt->col_count, stmt->col_info, stmt->con);
|
866
|
+
}
|
867
|
+
|
868
|
+
/* call-seq:
|
869
|
+
* fetch_hash() -> hash or nil
|
870
|
+
|
871
|
+
* con = Cubrid.connect('demodb')
|
872
|
+
* con.prepare('SELECT * FROM db_user') { |stmt|
|
873
|
+
* stmt.execute
|
874
|
+
* r = stmt.fetch_hash
|
875
|
+
* print r['name']
|
876
|
+
* }
|
877
|
+
* con.close
|
878
|
+
*/
|
879
|
+
VALUE
|
880
|
+
cubrid_stmt_fetch_hash(VALUE self)
|
881
|
+
{
|
882
|
+
VALUE row, col, hash;
|
883
|
+
int i;
|
884
|
+
char colName[128];
|
885
|
+
Statement *stmt;
|
886
|
+
|
887
|
+
GET_STMT_STRUCT(self, stmt);
|
888
|
+
CHECK_HANDLE(stmt, self);
|
889
|
+
|
890
|
+
row = cubrid_stmt_fetch(self);
|
891
|
+
if (NIL_P(row))
|
892
|
+
return Qnil;
|
893
|
+
|
894
|
+
hash = rb_hash_new();
|
895
|
+
for(i = 0; i < stmt->col_count; i++) {
|
896
|
+
col = RARRAY_PTR(row)[i];
|
897
|
+
strcpy(colName, CCI_GET_RESULT_INFO_NAME(stmt->col_info, i+1));
|
898
|
+
rb_hash_aset(hash, rb_str_new2(colName), col);
|
899
|
+
}
|
900
|
+
|
901
|
+
return hash;
|
902
|
+
}
|
903
|
+
|
904
|
+
/* call-seq:
|
905
|
+
* each() { |row| block } -> nil
|
906
|
+
*
|
907
|
+
*
|
908
|
+
* con = Cubrid.connect('demodb')
|
909
|
+
* con.prepare('SELECT * FROM db_user') { |stmt|
|
910
|
+
* stmt.execute
|
911
|
+
* stmt.each { |r|
|
912
|
+
* print r[0]
|
913
|
+
* }
|
914
|
+
* }
|
915
|
+
* con.close
|
916
|
+
*/
|
917
|
+
VALUE
|
918
|
+
cubrid_stmt_each(VALUE self)
|
919
|
+
{
|
920
|
+
VALUE row;
|
921
|
+
|
922
|
+
while(1) {
|
923
|
+
row = cubrid_stmt_fetch(self);
|
924
|
+
if (NIL_P(row)) {
|
925
|
+
break;
|
926
|
+
}
|
927
|
+
rb_yield(row);
|
928
|
+
}
|
929
|
+
|
930
|
+
return Qnil;
|
931
|
+
}
|
932
|
+
|
933
|
+
/* call-seq:
|
934
|
+
* each_hash() { |hash| block } -> nil
|
935
|
+
*
|
936
|
+
* con = Cubrid.connect('demodb')
|
937
|
+
* con.prepare('SELECT * FROM db_user') { |stmt|
|
938
|
+
* stmt.execute
|
939
|
+
* stmt.each_hash { |r|
|
940
|
+
* print r['name']
|
941
|
+
* }
|
942
|
+
* }
|
943
|
+
* con.close
|
944
|
+
*/
|
945
|
+
VALUE
|
946
|
+
cubrid_stmt_each_hash(VALUE self)
|
947
|
+
{
|
948
|
+
VALUE row;
|
949
|
+
|
950
|
+
while(1) {
|
951
|
+
row = cubrid_stmt_fetch_hash(self);
|
952
|
+
if (NIL_P(row)) {
|
953
|
+
break;
|
954
|
+
}
|
955
|
+
rb_yield(row);
|
956
|
+
}
|
957
|
+
|
958
|
+
return Qnil;
|
959
|
+
}
|
960
|
+
|
961
|
+
/* call-seq:
|
962
|
+
* column_info() -> array
|
963
|
+
*
|
964
|
+
* con = Cubrid.connect('demodb')
|
965
|
+
* con.prepare('SELECT * FROM db_user') { |stmt|
|
966
|
+
* stmt.column_info.each { |col|
|
967
|
+
* print col['name']
|
968
|
+
* print col['type_name']
|
969
|
+
* print col['precision']
|
970
|
+
* print col['scale']
|
971
|
+
* print col['nullable']
|
972
|
+
* }
|
973
|
+
* }
|
974
|
+
* con.close
|
975
|
+
*/
|
976
|
+
VALUE
|
977
|
+
cubrid_stmt_column_info(VALUE self)
|
978
|
+
{
|
979
|
+
VALUE desc;
|
980
|
+
int i;
|
981
|
+
char col_name[MAX_STR_LEN];
|
982
|
+
int datatype, precision, scale, nullable;
|
983
|
+
Statement *stmt;
|
984
|
+
|
985
|
+
GET_STMT_STRUCT(self, stmt);
|
986
|
+
CHECK_HANDLE(stmt, self);
|
987
|
+
|
988
|
+
desc = rb_ary_new2(stmt->col_count);
|
989
|
+
|
990
|
+
for (i = 0; i < stmt->col_count; i++) {
|
991
|
+
VALUE item;
|
992
|
+
|
993
|
+
item = rb_hash_new();
|
994
|
+
|
995
|
+
strcpy(col_name, CCI_GET_RESULT_INFO_NAME(stmt->col_info, i+1));
|
996
|
+
precision = CCI_GET_RESULT_INFO_PRECISION(stmt->col_info, i+1);
|
997
|
+
scale = CCI_GET_RESULT_INFO_SCALE(stmt->col_info, i+1);
|
998
|
+
nullable = CCI_GET_RESULT_INFO_IS_NON_NULL(stmt->col_info, i+1);
|
999
|
+
datatype = CCI_GET_RESULT_INFO_TYPE(stmt->col_info, i+1);
|
1000
|
+
|
1001
|
+
rb_hash_aset(item, rb_str_new2("name"), rb_str_new2(col_name));
|
1002
|
+
rb_hash_aset(item, rb_str_new2("type_name"), INT2NUM(datatype));
|
1003
|
+
rb_hash_aset(item, rb_str_new2("precision"), INT2NUM(precision));
|
1004
|
+
rb_hash_aset(item, rb_str_new2("scale"), INT2NUM(scale));
|
1005
|
+
rb_hash_aset(item, rb_str_new2("nullable"), INT2NUM(nullable));
|
1006
|
+
|
1007
|
+
rb_ary_push(desc, item);
|
1008
|
+
}
|
1009
|
+
|
1010
|
+
return desc;
|
1011
|
+
}
|
1012
|
+
|