ruby-informix 0.5.1 → 0.6.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.
Files changed (10) hide show
  1. data/Changelog +47 -0
  2. data/README +8 -5
  3. data/extconf.rb +1 -1
  4. data/ifx_assert.h +45 -0
  5. data/ifx_except.c +523 -0
  6. data/ifx_except.ec +467 -0
  7. data/ifx_except.h +82 -0
  8. data/informix.c +555 -541
  9. data/informix.ec +173 -159
  10. metadata +9 -3
@@ -1,4 +1,4 @@
1
- /* $Id: informix.ec,v 1.81.2.2 2007/08/10 17:48:47 santana Exp $ */
1
+ /* $Id: informix.ec,v 1.10 2007/08/23 02:32:56 santana Exp $ */
2
2
  /*
3
3
  * Copyright (c) 2006-2007, Gerardo Santana Gomez Garrido <gerardo.santana@gmail.com>
4
4
  * All rights reserved.
@@ -28,7 +28,10 @@
28
28
  * POSSIBILITY OF SUCH DAMAGE.
29
29
  */
30
30
 
31
+ static const char rcsid[] = "$Id: informix.ec,v 1.10 2007/08/23 02:32:56 santana Exp $";
32
+
31
33
  #include "ruby.h"
34
+ #include "ifx_except.h"
32
35
 
33
36
  #include <sqlstype.h>
34
37
  #include <sqltypes.h>
@@ -55,6 +58,9 @@ static VALUE sym_col_info, sym_sbspace, sym_estbytes, sym_extsz;
55
58
  static VALUE sym_createflags, sym_openflags, sym_maxbytes;
56
59
  static VALUE sym_params;
57
60
 
61
+ /* Symbols from ifx_except module */
62
+ static ifx_except_symbols_t esyms;
63
+
58
64
  #define IDSIZE 30
59
65
 
60
66
  typedef struct {
@@ -82,20 +88,22 @@ typedef struct {
82
88
  ifx_int8_t size;
83
89
  } slobstat_t;
84
90
 
85
- #define NUM2INT8(num, int8addr) do { \
91
+ #define NUM2INT8(num, int8addr) \
92
+ do { \
86
93
  VALUE str = rb_funcall(num, s_to_s, 0); \
87
94
  char *c_str = StringValueCStr(str); \
88
95
  mint ret = ifx_int8cvasc(c_str, strlen(c_str), (int8addr)); \
89
96
  if (ret < 0) \
90
- rb_raise(rb_eRuntimeError, "Could not convert %s to int8", c_str); \
91
- }while(0)
97
+ rb_raise(esyms.eOperationalError, "Could not convert %s to int8", c_str); \
98
+ } while(0)
92
99
 
93
- #define INT82NUM(int8addr, num) do { \
100
+ #define INT82NUM(int8addr, num) \
101
+ do { \
94
102
  char str[21]; \
95
103
  ifx_int8toasc((int8addr), str, sizeof(str) - 1); \
96
104
  str[sizeof(str) - 1] = 0; \
97
105
  num = rb_cstr2inum(str, 10); \
98
- }while(0)
106
+ } while(0)
99
107
 
100
108
  /* class Slob::Stat ------------------------------------------------------ */
101
109
 
@@ -136,18 +144,18 @@ rb_slobstat_initialize(VALUE self, VALUE slob)
136
144
  Data_Get_Struct(self, slobstat_t, stat);
137
145
 
138
146
  if (sb->fd == -1)
139
- rb_raise(rb_eRuntimeError,
147
+ rb_raise(esyms.eProgrammingError,
140
148
  "Open the Slob object before getting its status");
141
149
 
142
150
  did = sb->database_id;
143
151
  EXEC SQL set connection :did;
144
152
  if (SQLCODE < 0)
145
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
153
+ raise_ifx_extended();
146
154
 
147
155
  ret = ifx_lo_stat(sb->fd, &st);
148
156
 
149
157
  if (ret < 0)
150
- rb_raise(rb_eRuntimeError, "Informix Error: %d", ret);
158
+ raise_ifx_extended();
151
159
 
152
160
  stat->atime = ifx_lo_stat_atime(st);
153
161
  stat->ctime = ifx_lo_stat_ctime(st);
@@ -159,7 +167,7 @@ rb_slobstat_initialize(VALUE self, VALUE slob)
159
167
 
160
168
  if (stat->atime == -1 || stat->ctime == -1 || stat->mtime == -1 ||
161
169
  stat->refcnt == -1 || ret == -1) {
162
- rb_raise(rb_eRuntimeError, "Unable to get status");
170
+ rb_raise(esyms.eOperationalError, "Unable to get status");
163
171
  }
164
172
 
165
173
  return self;
@@ -314,27 +322,6 @@ slob_alloc(VALUE klass)
314
322
  return Data_Wrap_Struct(klass, slob_mark, slob_free, slob);
315
323
  }
316
324
 
317
- /*
318
- * call-seq:
319
- * Slob.new(database, type = Slob::CLOB, options = nil) => slob
320
- * Slob.new(database, type = Slob::CLOB, options = nil) {|slob| block } => obj
321
- *
322
- * Creates a Smart Large Object of type <i>type</i> in <i>database</i>.
323
- * Returns a <code>Slob</code> object pointing to it.
324
- *
325
- * <i>type</i> can be Slob::BLOB or Slob::CLOB
326
- *
327
- * <i>options</i> must be a hash with the following possible keys:
328
- *
329
- * :sbspace => Sbspace name
330
- * :estbytes => Estimated size, in bytes
331
- * :extsz => Allocation extent size
332
- * :createflags => Create-time flags
333
- * :openflags => Access mode
334
- * :maxbytes => Maximum size
335
- * :col_info => Get the previous values from the column-level storage
336
- * characteristics for the specified database column
337
- */
338
325
  static VALUE
339
326
  rb_slob_initialize(int argc, VALUE *argv, VALUE self)
340
327
  {
@@ -351,7 +338,7 @@ rb_slob_initialize(int argc, VALUE *argv, VALUE self)
351
338
 
352
339
  EXEC SQL set connection :did;
353
340
  if (SQLCODE < 0)
354
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
341
+ raise_ifx_extended();
355
342
 
356
343
  Data_Get_Struct(self, slob_t, slob);
357
344
  slob->db = db;
@@ -360,7 +347,7 @@ rb_slob_initialize(int argc, VALUE *argv, VALUE self)
360
347
  if (!NIL_P(type)) {
361
348
  int t = FIX2INT(type);
362
349
  if (t != XID_CLOB && t != XID_BLOB)
363
- rb_raise(rb_eRuntimeError, "Invalid type %d for an SLOB", t);
350
+ rb_raise(esyms.eInternalError, "Invalid type %d for an SLOB", t);
364
351
  slob->type = t;
365
352
  }
366
353
 
@@ -379,19 +366,19 @@ rb_slob_initialize(int argc, VALUE *argv, VALUE self)
379
366
 
380
367
  ret = ifx_lo_def_create_spec(&slob->spec);
381
368
  if (ret < 0)
382
- rb_raise(rb_eRuntimeError, "Informix Error: %d", ret);
369
+ raise_ifx_extended();
383
370
 
384
371
  if (!NIL_P(col_info)) {
385
372
  ret = ifx_lo_col_info(StringValueCStr(col_info), slob->spec);
386
373
 
387
374
  if (ret < 0)
388
- rb_raise(rb_eRuntimeError, "Informix Error: %d", ret);
375
+ raise_ifx_extended();
389
376
  }
390
377
  if (!NIL_P(sbspace)) {
391
378
  char *c_sbspace = StringValueCStr(sbspace);
392
379
  ret = ifx_lo_specset_sbspace(slob->spec, c_sbspace);
393
380
  if (ret == -1)
394
- rb_raise(rb_eRuntimeError, "Could not set sbspace name to %s", c_sbspace);
381
+ rb_raise(esyms.eOperationalError, "Could not set sbspace name to %s", c_sbspace);
395
382
  }
396
383
  if (!NIL_P(estbytes)) {
397
384
  ifx_int8_t estbytes8;
@@ -399,17 +386,17 @@ rb_slob_initialize(int argc, VALUE *argv, VALUE self)
399
386
  NUM2INT8(estbytes, &estbytes8);
400
387
  ret = ifx_lo_specset_estbytes(slob->spec, &estbytes8);
401
388
  if (ret == -1)
402
- rb_raise(rb_eRuntimeError, "Could not set estbytes");
389
+ rb_raise(esyms.eOperationalError, "Could not set estbytes");
403
390
  }
404
391
  if (!NIL_P(extsz)) {
405
392
  ret = ifx_lo_specset_extsz(slob->spec, FIX2LONG(extsz));
406
393
  if (ret == -1)
407
- rb_raise(rb_eRuntimeError, "Could not set extsz to %d", FIX2LONG(extsz));
394
+ rb_raise(esyms.eOperationalError, "Could not set extsz to %d", FIX2LONG(extsz));
408
395
  }
409
396
  if (!NIL_P(createflags)) {
410
397
  ret = ifx_lo_specset_flags(slob->spec, FIX2LONG(createflags));
411
398
  if (ret == -1)
412
- rb_raise(rb_eRuntimeError, "Could not set crate-time flags to 0x%X", FIX2LONG(createflags));
399
+ rb_raise(esyms.eOperationalError, "Could not set crate-time flags to 0x%X", FIX2LONG(createflags));
413
400
  }
414
401
  if (!NIL_P(maxbytes)) {
415
402
  ifx_int8_t maxbytes8;
@@ -417,16 +404,17 @@ rb_slob_initialize(int argc, VALUE *argv, VALUE self)
417
404
  NUM2INT8(maxbytes, (&maxbytes8));
418
405
  ret = ifx_lo_specset_maxbytes(slob->spec, &maxbytes8);
419
406
  if (ret == -1)
420
- rb_raise(rb_eRuntimeError, "Could not set maxbytes");
407
+ rb_raise(esyms.eOperationalError, "Could not set maxbytes");
421
408
  }
422
409
 
423
410
  slob->fd = ifx_lo_create(slob->spec, RTEST(openflags)? FIX2LONG(openflags): LO_RDWR, &slob->lo, &error);
424
411
  if (slob->fd == -1)
425
- rb_raise(rb_eRuntimeError, "Informix Error: %d\n", error);
412
+ raise_ifx_extended();
426
413
 
427
414
  return self;
428
415
  }
429
416
 
417
+ static VALUE rb_slob_close(VALUE self);
430
418
  /*
431
419
  * call-seq:
432
420
  * Slob.new(database, type = Slob::CLOB, options = nil) => slob
@@ -448,7 +436,6 @@ rb_slob_initialize(int argc, VALUE *argv, VALUE self)
448
436
  * :col_info => Get the previous values from the column-level storage
449
437
  * characteristics for the specified database column
450
438
  */
451
- static VALUE rb_slob_close(VALUE self);
452
439
  static VALUE
453
440
  rb_slob_s_new(int argc, VALUE *argv, VALUE klass)
454
441
  {
@@ -500,14 +487,14 @@ rb_slob_open(int argc, VALUE *argv, VALUE self)
500
487
  did = slob->database_id;
501
488
  EXEC SQL set connection :did;
502
489
  if (SQLCODE < 0)
503
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
490
+ raise_ifx_extended();
504
491
 
505
492
  rb_scan_args(argc, argv, "01", &access);
506
493
 
507
494
  slob->fd = ifx_lo_open(&slob->lo, NIL_P(access)? LO_RDONLY: FIX2INT(access), &error);
508
495
 
509
496
  if (slob->fd == -1)
510
- rb_raise(rb_eRuntimeError, "Informix Error: %d", error);
497
+ raise_ifx_extended();
511
498
 
512
499
  return self;
513
500
  }
@@ -565,12 +552,12 @@ rb_slob_read(VALUE self, VALUE nbytes)
565
552
  Data_Get_Struct(self, slob_t, slob);
566
553
 
567
554
  if (slob->fd == -1)
568
- rb_raise(rb_eRuntimeError, "Open the Slob object before reading");
555
+ rb_raise(esyms.eProgrammingError, "Open the Slob object before reading");
569
556
 
570
557
  did = slob->database_id;
571
558
  EXEC SQL set connection :did;
572
559
  if (SQLCODE < 0)
573
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
560
+ raise_ifx_extended();
574
561
 
575
562
  c_nbytes = FIX2LONG(nbytes);
576
563
  buffer = ALLOC_N(char, c_nbytes);
@@ -578,7 +565,7 @@ rb_slob_read(VALUE self, VALUE nbytes)
578
565
 
579
566
  if (ret == -1) {
580
567
  xfree(buffer);
581
- rb_raise(rb_eRuntimeError, "Informix Error: %d\n", error);
568
+ raise_ifx_extended();
582
569
  }
583
570
 
584
571
  str = rb_str_new(buffer, ret);
@@ -611,12 +598,12 @@ rb_slob_write(VALUE self, VALUE data)
611
598
  Data_Get_Struct(self, slob_t, slob);
612
599
 
613
600
  if (slob->fd == -1)
614
- rb_raise(rb_eRuntimeError, "Open the Slob object before writing");
601
+ rb_raise(esyms.eProgrammingError, "Open the Slob object before writing");
615
602
 
616
603
  did = slob->database_id;
617
604
  EXEC SQL set connection :did;
618
605
  if (SQLCODE < 0)
619
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
606
+ raise_ifx_extended();
620
607
 
621
608
  str = rb_obj_as_string(data);
622
609
  buffer = RSTRING(str)->ptr;
@@ -625,7 +612,7 @@ rb_slob_write(VALUE self, VALUE data)
625
612
  ret = ifx_lo_write(slob->fd, buffer, nbytes, &error);
626
613
 
627
614
  if (ret == -1)
628
- rb_raise(rb_eRuntimeError, "Informix Error: %d", error);
615
+ raise_ifx_extended();
629
616
 
630
617
  return LONG2NUM(ret);
631
618
  }
@@ -679,17 +666,17 @@ rb_slob_seek(VALUE self, VALUE offset, VALUE whence)
679
666
  Data_Get_Struct(self, slob_t, slob);
680
667
 
681
668
  if (slob->fd == -1)
682
- rb_raise(rb_eRuntimeError, "Open the Slob object first");
669
+ rb_raise(esyms.eProgrammingError, "Open the Slob object first");
683
670
 
684
671
  did = slob->database_id;
685
672
  EXEC SQL set connection :did;
686
673
  if (SQLCODE < 0)
687
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
674
+ raise_ifx_extended();
688
675
 
689
676
  NUM2INT8(offset, &offset8);
690
677
  ret = ifx_lo_seek(slob->fd, &offset8, FIX2INT(whence), &seek_pos8);
691
678
  if (ret < 0)
692
- rb_raise(rb_eRuntimeError, "Informix Error: %d", ret);
679
+ raise_ifx_extended();
693
680
 
694
681
  INT82NUM(&seek_pos8, seek_pos);
695
682
 
@@ -741,16 +728,16 @@ rb_slob_tell(VALUE self)
741
728
  Data_Get_Struct(self, slob_t, slob);
742
729
 
743
730
  if (slob->fd == -1)
744
- rb_raise(rb_eRuntimeError, "Open the Slob object first");
731
+ rb_raise(esyms.eProgrammingError, "Open the Slob object first");
745
732
 
746
733
  did = slob->database_id;
747
734
  EXEC SQL set connection :did;
748
735
  if (SQLCODE < 0)
749
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
736
+ raise_ifx_extended();
750
737
 
751
738
  ret = ifx_lo_tell(slob->fd, &seek_pos8);
752
739
  if (ret < 0)
753
- rb_raise(rb_eRuntimeError, "Informix Error: %d", ret);
740
+ raise_ifx_extended();
754
741
 
755
742
  INT82NUM(&seek_pos8, seek_pos);
756
743
 
@@ -778,17 +765,17 @@ rb_slob_truncate(VALUE self, VALUE offset)
778
765
  Data_Get_Struct(self, slob_t, slob);
779
766
 
780
767
  if (slob->fd == -1)
781
- rb_raise(rb_eRuntimeError, "Open the Slob object first");
768
+ rb_raise(esyms.eProgrammingError, "Open the Slob object first");
782
769
 
783
770
  did = slob->database_id;
784
771
  EXEC SQL set connection :did;
785
772
  if (SQLCODE < 0)
786
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
773
+ raise_ifx_extended();
787
774
 
788
775
  NUM2INT8(offset, &offset8);
789
776
  ret = ifx_lo_truncate(slob->fd, &offset8);
790
777
  if (ret < 0)
791
- rb_raise(rb_eRuntimeError, "Informix Error: %d", ret);
778
+ raise_ifx_extended();
792
779
 
793
780
  return self;
794
781
  }
@@ -834,18 +821,18 @@ rb_slob_lock(VALUE self, VALUE offset, VALUE whence, VALUE range, VALUE mode)
834
821
  Data_Get_Struct(self, slob_t, slob);
835
822
 
836
823
  if (slob->fd == -1)
837
- rb_raise(rb_eRuntimeError, "Open the Slob object first");
824
+ rb_raise(esyms.eProgrammingError, "Open the Slob object first");
838
825
 
839
826
  did = slob->database_id;
840
827
  EXEC SQL set connection :did;
841
828
  if (SQLCODE < 0)
842
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
829
+ raise_ifx_extended();
843
830
 
844
831
  NUM2INT8(offset, &offset8);
845
832
  NUM2INT8(range, &range8);
846
833
  ret = ifx_lo_lock(slob->fd, &offset8, FIX2INT(whence), &range8, FIX2INT(mode));
847
834
  if (ret < 0)
848
- rb_raise(rb_eRuntimeError, "Informix Error: %d", ret);
835
+ raise_ifx_extended();
849
836
 
850
837
  return self;
851
838
  }
@@ -878,18 +865,18 @@ rb_slob_unlock(VALUE self, VALUE offset, VALUE whence, VALUE range)
878
865
  Data_Get_Struct(self, slob_t, slob);
879
866
 
880
867
  if (slob->fd == -1)
881
- rb_raise(rb_eRuntimeError, "Open the Slob object first");
868
+ rb_raise(esyms.eProgrammingError, "Open the Slob object first");
882
869
 
883
870
  did = slob->database_id;
884
871
  EXEC SQL set connection :did;
885
872
  if (SQLCODE < 0)
886
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
873
+ raise_ifx_extended();
887
874
 
888
875
  NUM2INT8(offset, &offset8);
889
876
  NUM2INT8(range, &range8);
890
877
  ret = ifx_lo_unlock(slob->fd, &offset8, FIX2INT(whence), &range8);
891
878
  if (ret < 0)
892
- rb_raise(rb_eRuntimeError, "Informix Error: %d", ret);
879
+ raise_ifx_extended();
893
880
 
894
881
  return self;
895
882
  }
@@ -919,21 +906,21 @@ slob_specget(VALUE self, slob_option_t option)
919
906
  Data_Get_Struct(self, slob_t, slob);
920
907
 
921
908
  if (slob->fd == -1)
922
- rb_raise(rb_eRuntimeError, "Open the Slob object first");
909
+ rb_raise(esyms.eProgrammingError, "Open the Slob object first");
923
910
 
924
911
  did = slob->database_id;
925
912
  EXEC SQL set connection :did;
926
913
  if (SQLCODE < 0)
927
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
914
+ raise_ifx_extended();
928
915
 
929
916
  ret = ifx_lo_stat(slob->fd, &stat);
930
917
  if (ret < 0)
931
- rb_raise(rb_eRuntimeError, "Informix Error: %d", ret);
918
+ raise_ifx_extended();
932
919
 
933
920
  spec = ifx_lo_stat_cspec(stat);
934
921
  if (spec == NULL) {
935
922
  ifx_lo_stat_free(stat);
936
- rb_raise(rb_eRuntimeError, "Unable to get storage characteristics");
923
+ rb_raise(esyms.eOperationalError, "Unable to get storage characteristics");
937
924
  }
938
925
 
939
926
  switch(option) {
@@ -955,7 +942,7 @@ slob_specget(VALUE self, slob_option_t option)
955
942
 
956
943
  ifx_lo_stat_free(stat);
957
944
  if (ret == -1)
958
- rb_raise(rb_eRuntimeError, "Unable to get information for %s", str_slob_options[option]);
945
+ rb_raise(esyms.eOperationalError, "Unable to get information for %s", str_slob_options[option]);
959
946
 
960
947
  switch(option) {
961
948
  case slob_estbytes:
@@ -989,21 +976,21 @@ slob_specset(VALUE self, slob_option_t option, VALUE value)
989
976
  Data_Get_Struct(self, slob_t, slob);
990
977
 
991
978
  if (slob->fd == -1)
992
- rb_raise(rb_eRuntimeError, "Open the Slob object first");
979
+ rb_raise(esyms.eProgrammingError, "Open the Slob object first");
993
980
 
994
981
  did = slob->database_id;
995
982
  EXEC SQL set connection :did;
996
983
  if (SQLCODE < 0)
997
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
984
+ raise_ifx_extended();
998
985
 
999
986
  ret = ifx_lo_stat(slob->fd, &stat);
1000
987
  if (ret < 0)
1001
- rb_raise(rb_eRuntimeError, "Informix Error: %d", ret);
988
+ raise_ifx_extended();
1002
989
 
1003
990
  spec = ifx_lo_stat_cspec(stat);
1004
991
  if (spec == NULL) {
1005
992
  ifx_lo_stat_free(stat);
1006
- rb_raise(rb_eRuntimeError, "Unable to get storage characteristics");
993
+ rb_raise(esyms.eOperationalError, "Unable to get storage characteristics");
1007
994
  }
1008
995
 
1009
996
  switch(option) {
@@ -1019,7 +1006,7 @@ slob_specset(VALUE self, slob_option_t option, VALUE value)
1019
1006
 
1020
1007
  ifx_lo_stat_free(stat);
1021
1008
  if (ret == -1)
1022
- rb_raise(rb_eRuntimeError, "Unable to set information for %s", str_slob_options[option]);
1009
+ rb_raise(esyms.eOperationalError, "Unable to set information for %s", str_slob_options[option]);
1023
1010
 
1024
1011
  return value;
1025
1012
  }
@@ -1131,18 +1118,18 @@ slob_stat(VALUE self, slob_stat_t stat)
1131
1118
  Data_Get_Struct(self, slob_t, slob);
1132
1119
 
1133
1120
  if (slob->fd == -1)
1134
- rb_raise(rb_eRuntimeError,
1121
+ rb_raise(esyms.eProgrammingError,
1135
1122
  "Open the Slob object before getting its status");
1136
1123
 
1137
1124
  did = slob->database_id;
1138
1125
  EXEC SQL set connection :did;
1139
1126
  if (SQLCODE < 0)
1140
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
1127
+ raise_ifx_extended();
1141
1128
 
1142
1129
  ret = ifx_lo_stat(slob->fd, &st);
1143
1130
 
1144
1131
  if (ret < 0)
1145
- rb_raise(rb_eRuntimeError, "Informix Error: %d", ret);
1132
+ raise_ifx_extended();
1146
1133
 
1147
1134
  switch(stat) {
1148
1135
  case slob_atime:
@@ -1164,7 +1151,7 @@ slob_stat(VALUE self, slob_stat_t stat)
1164
1151
  ifx_lo_stat_free(st);
1165
1152
 
1166
1153
  if (ret == -1)
1167
- rb_raise(rb_eRuntimeError, "Unable to get value of %s", str_slob_stats[stat]);
1154
+ rb_raise(esyms.eOperationalError, "Unable to get value of %s", str_slob_stats[stat]);
1168
1155
 
1169
1156
  switch(stat) {
1170
1157
  case slob_atime:
@@ -1700,7 +1687,7 @@ make_result(cursor_t *c, VALUE record)
1700
1687
  ret = dectoasc((dec_t *)var->sqldata, buffer,
1701
1688
  sizeof(buffer) - 1, -1);
1702
1689
  if (ret)
1703
- rb_raise(rb_eRuntimeError,
1690
+ rb_raise(esyms.eOperationalError,
1704
1691
  "Unable to convert DECIMAL to BigDecimal");
1705
1692
 
1706
1693
  buffer[sizeof(buffer) - 1] = 0;
@@ -1759,6 +1746,7 @@ make_result(cursor_t *c, VALUE record)
1759
1746
 
1760
1747
  /* module Informix -------------------------------------------------------- */
1761
1748
 
1749
+ static VALUE rb_database_s_open(int argc, VALUE *argv, VALUE klass);
1762
1750
  /*
1763
1751
  * call-seq:
1764
1752
  * Informix.connect(dbname, user=nil, password=nil) => database
@@ -1772,13 +1760,29 @@ make_result(cursor_t *c, VALUE record)
1772
1760
  * closes the connection when the block terminates, returning the value of
1773
1761
  * the block.
1774
1762
  */
1775
- static VALUE rb_database_s_open(int argc, VALUE *argv, VALUE klass);
1776
1763
  static VALUE
1777
- informix_connect(int argc, VALUE *argv, VALUE self)
1764
+ rb_informix_connect(int argc, VALUE *argv, VALUE self)
1778
1765
  {
1779
1766
  return rb_database_s_open(argc, argv, rb_cDatabase);
1780
1767
  }
1781
1768
 
1769
+ /*
1770
+ * call-seq:
1771
+ * Informix.version => string
1772
+ *
1773
+ * Returns the version of this Ruby/Informix driver.
1774
+ * Note that this is NOT the Informix database version.
1775
+ */
1776
+ static VALUE rb_informix_version(void)
1777
+ {
1778
+ static const char * const ver = "0.6.0";
1779
+ static VALUE driver_version;
1780
+
1781
+ if (driver_version == 0)
1782
+ driver_version = rb_str_freeze(rb_str_new2(ver));
1783
+
1784
+ return driver_version;
1785
+ }
1782
1786
 
1783
1787
  /* class Database --------------------------------------------------------- */
1784
1788
 
@@ -1816,7 +1820,7 @@ rb_database_initialize(int argc, VALUE *argv, VALUE self)
1816
1820
  rb_scan_args(argc, argv, "12", &arg[0], &arg[1], &arg[2]);
1817
1821
 
1818
1822
  if (NIL_P(arg[0]))
1819
- rb_raise(rb_eRuntimeError, "A database name must be specified");
1823
+ rb_raise(esyms.eProgrammingError, "A database name must be specified");
1820
1824
 
1821
1825
  Data_Get_Struct(self, char, did);
1822
1826
 
@@ -1836,7 +1840,7 @@ rb_database_initialize(int argc, VALUE *argv, VALUE self)
1836
1840
  EXEC SQL connect to :dbname as :did with concurrent transaction;
1837
1841
 
1838
1842
  if (SQLCODE < 0)
1839
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
1843
+ raise_ifx_extended();
1840
1844
 
1841
1845
  return self;
1842
1846
  }
@@ -1896,6 +1900,7 @@ rb_database_close(VALUE self)
1896
1900
  /*
1897
1901
  * call-seq:
1898
1902
  * db.immediate(query) => fixnum
1903
+ * db.execute(query) => fixnum
1899
1904
  *
1900
1905
  * Executes <i>query</i> and returns the number of rows affected.
1901
1906
  * <i>query</i> must not return rows. Executes efficiently any
@@ -1913,12 +1918,12 @@ rb_database_immediate(VALUE self, VALUE arg)
1913
1918
 
1914
1919
  EXEC SQL set connection :did;
1915
1920
  if (SQLCODE < 0)
1916
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
1921
+ raise_ifx_extended();
1917
1922
 
1918
1923
  query = StringValueCStr(arg);
1919
1924
  EXEC SQL execute immediate :query;
1920
1925
  if (SQLCODE < 0)
1921
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
1926
+ raise_ifx_extended();
1922
1927
 
1923
1928
  return INT2FIX(sqlca.sqlerrd[2]);
1924
1929
  }
@@ -1940,7 +1945,7 @@ rb_database_rollback(VALUE self)
1940
1945
 
1941
1946
  EXEC SQL set connection :did;
1942
1947
  if (SQLCODE < 0)
1943
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
1948
+ raise_ifx_extended();
1944
1949
 
1945
1950
  EXEC SQL rollback;
1946
1951
  return self;
@@ -1963,7 +1968,7 @@ rb_database_commit(VALUE self)
1963
1968
 
1964
1969
  EXEC SQL set connection :did;
1965
1970
  if (SQLCODE < 0)
1966
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
1971
+ raise_ifx_extended();
1967
1972
 
1968
1973
  EXEC SQL commit;
1969
1974
  return self;
@@ -1998,18 +2003,19 @@ rb_database_transaction(VALUE self)
1998
2003
 
1999
2004
  EXEC SQL set connection :did;
2000
2005
  if (SQLCODE < 0)
2001
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2006
+ raise_ifx_extended();
2002
2007
 
2003
2008
  EXEC SQL commit;
2004
2009
 
2005
2010
  EXEC SQL begin work;
2006
2011
  ret = rb_rescue(rb_yield, self, database_transfail, self);
2007
2012
  if (ret == Qundef)
2008
- rb_raise(rb_eRuntimeError, "Transaction rolled back");
2013
+ rb_raise(esyms.eOperationalError, "Transaction rolled back");
2009
2014
  EXEC SQL commit;
2010
2015
  return self;
2011
2016
  }
2012
2017
 
2018
+ static VALUE statement_s_new(int, VALUE *, VALUE);
2013
2019
  /*
2014
2020
  * call-seq:
2015
2021
  * db.prepare(query) => statement
@@ -2025,7 +2031,6 @@ rb_database_transaction(VALUE self)
2025
2031
  * it must not be a query returning more than one row
2026
2032
  * (use <code>Database#cursor</code> instead.)
2027
2033
  */
2028
- static VALUE statement_s_new(int, VALUE *, VALUE);
2029
2034
  static VALUE
2030
2035
  rb_database_prepare(VALUE self, VALUE query)
2031
2036
  {
@@ -2035,6 +2040,7 @@ rb_database_prepare(VALUE self, VALUE query)
2035
2040
  return statement_s_new(2, argv, rb_cStatement);
2036
2041
  }
2037
2042
 
2043
+ static VALUE rb_cursor_s_new(int argc, VALUE *argv, VALUE klass);
2038
2044
  /*
2039
2045
  * call-seq:
2040
2046
  * db.cursor(query, options = nil) => cursor
@@ -2055,7 +2061,7 @@ rb_database_cursor(int argc, VALUE *argv, VALUE self)
2055
2061
 
2056
2062
  arg[0] = self;
2057
2063
  rb_scan_args(argc, argv, "11", &arg[1], &arg[2]);
2058
- return rb_class_new_instance(3, arg, rb_cCursor);
2064
+ return rb_cursor_s_new(3, arg, rb_cCursor);
2059
2065
  }
2060
2066
 
2061
2067
  /*
@@ -2126,14 +2132,14 @@ rb_database_columns(VALUE self, VALUE tablename)
2126
2132
 
2127
2133
  EXEC SQL set connection :did;
2128
2134
  if (SQLCODE < 0)
2129
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2135
+ raise_ifx_extended();
2130
2136
 
2131
2137
  tabname = StringValueCStr(tablename);
2132
2138
 
2133
2139
  EXEC SQL select tabid into :tabid from systables where tabname = :tabname;
2134
2140
 
2135
2141
  if (SQLCODE == SQLNOTFOUND)
2136
- rb_raise(rb_eRuntimeError, "Table '%s' doesn't exist", tabname);
2142
+ rb_raise(esyms.eProgrammingError, "Table '%s' doesn't exist", tabname);
2137
2143
 
2138
2144
  result = rb_ary_new();
2139
2145
 
@@ -2149,19 +2155,19 @@ rb_database_columns(VALUE self, VALUE tablename)
2149
2155
  order by c.colno;
2150
2156
  if (SQLCODE < 0) {
2151
2157
  cid[0] = 0;
2152
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2158
+ raise_ifx_extended();
2153
2159
  }
2154
2160
  }
2155
2161
 
2156
2162
  EXEC SQL open :cid;
2157
2163
  if (SQLCODE < 0)
2158
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2164
+ raise_ifx_extended();
2159
2165
 
2160
2166
  for(;;) {
2161
2167
  EXEC SQL fetch :cid into :colname, :coltype, :collength, :xid,
2162
2168
  :deftype, :defvalue;
2163
2169
  if (SQLCODE < 0)
2164
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2170
+ raise_ifx_extended();
2165
2171
 
2166
2172
  if (SQLCODE == SQLNOTFOUND)
2167
2173
  break;
@@ -2302,22 +2308,6 @@ statement_alloc(VALUE klass)
2302
2308
  return Data_Wrap_Struct(klass, statement_mark, statement_free, c);
2303
2309
  }
2304
2310
 
2305
- /*
2306
- * call-seq:
2307
- * Statement.new(database, query) => statement
2308
- * Statement.new(database, query) {|stmt| block } => obj
2309
- *
2310
- * Creates a <code>Statement</code> object based on <i>query</i> in the
2311
- * context of <i>database</i>.
2312
- * In the first form the <code>Statement</code> object is returned.
2313
- * In the second form the Statement object is passed to the block and when it
2314
- * terminates, the Statement object is dropped, returning the value of the
2315
- * block.
2316
- *
2317
- * <i>query</i> may contain '?' placeholders for input parameters;
2318
- * it must not be a query returning more than one row
2319
- * (use <code>Cursor</code> instead.)
2320
- */
2321
2311
  static VALUE
2322
2312
  statement_initialize(VALUE self, VALUE db, VALUE query)
2323
2313
  {
@@ -2330,7 +2320,7 @@ statement_initialize(VALUE self, VALUE db, VALUE query)
2330
2320
  Data_Get_Struct(db, char, did);
2331
2321
  EXEC SQL set connection :did;
2332
2322
  if (SQLCODE < 0)
2333
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2323
+ raise_ifx_extended();
2334
2324
 
2335
2325
  Data_Get_Struct(self, cursor_t, c);
2336
2326
  c->db = db;
@@ -2342,7 +2332,7 @@ statement_initialize(VALUE self, VALUE db, VALUE query)
2342
2332
 
2343
2333
  EXEC SQL prepare :sid from :c_query;
2344
2334
  if (SQLCODE < 0)
2345
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2335
+ raise_ifx_extended();
2346
2336
 
2347
2337
  alloc_input_slots(c, c_query);
2348
2338
  EXEC SQL describe :sid into output;
@@ -2360,6 +2350,7 @@ statement_initialize(VALUE self, VALUE db, VALUE query)
2360
2350
  return self;
2361
2351
  }
2362
2352
 
2353
+ static VALUE statement_drop(VALUE);
2363
2354
  /*
2364
2355
  * call-seq:
2365
2356
  * Statement.new(database, query) => statement
@@ -2376,7 +2367,6 @@ statement_initialize(VALUE self, VALUE db, VALUE query)
2376
2367
  * it must not be a query returning more than one row
2377
2368
  * (use <code>Cursor</code> instead.)
2378
2369
  */
2379
- static VALUE statement_drop(VALUE);
2380
2370
  static VALUE
2381
2371
  statement_s_new(int argc, VALUE *argv, VALUE klass)
2382
2372
  {
@@ -2414,7 +2404,7 @@ statement_call(int argc, VALUE *argv, VALUE self)
2414
2404
  did = c->database_id;
2415
2405
  EXEC SQL set connection :did;
2416
2406
  if (SQLCODE < 0)
2417
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2407
+ raise_ifx_extended();
2418
2408
 
2419
2409
  output = c->daOutput;
2420
2410
  input = &c->daInput;
@@ -2435,7 +2425,7 @@ statement_call(int argc, VALUE *argv, VALUE self)
2435
2425
  EXEC SQL execute :sid into descriptor output;
2436
2426
 
2437
2427
  if (SQLCODE < 0)
2438
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2428
+ raise_ifx_extended();
2439
2429
 
2440
2430
  if (SQLCODE == SQLNOTFOUND)
2441
2431
  return Qnil;
@@ -2451,7 +2441,7 @@ statement_call(int argc, VALUE *argv, VALUE self)
2451
2441
  EXEC SQL execute :sid;
2452
2442
  }
2453
2443
  if (SQLCODE < 0)
2454
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2444
+ raise_ifx_extended();
2455
2445
 
2456
2446
  return INT2FIX(sqlca.sqlerrd[2]);
2457
2447
  }
@@ -2489,7 +2479,8 @@ statement_drop(VALUE self)
2489
2479
  /* Decides whether to use an Array or a Hash, and instantiate a new
2490
2480
  * object or reuse an existing one.
2491
2481
  */
2492
- #define RECORD(c, type, bang, record) do {\
2482
+ #define RECORD(c, type, bang, record) \
2483
+ do {\
2493
2484
  if (type == T_ARRAY) {\
2494
2485
  if (bang) {\
2495
2486
  if (!c->array)\
@@ -2525,19 +2516,19 @@ fetch(VALUE self, VALUE type, int bang)
2525
2516
 
2526
2517
  Data_Get_Struct(self, cursor_t, c);
2527
2518
  if (!c->is_open)
2528
- rb_raise(rb_eRuntimeError, "Open the cursor object first");
2519
+ rb_raise(esyms.eProgrammingError, "Open the cursor object first");
2529
2520
 
2530
2521
  did = c->database_id;
2531
2522
  EXEC SQL set connection :did;
2532
2523
  if (SQLCODE < 0)
2533
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2524
+ raise_ifx_extended();
2534
2525
 
2535
2526
  output = c->daOutput;
2536
2527
  cid = c->cursor_id;
2537
2528
 
2538
2529
  EXEC SQL fetch :cid using descriptor output;
2539
2530
  if (SQLCODE < 0)
2540
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2531
+ raise_ifx_extended();
2541
2532
 
2542
2533
  if (SQLCODE == SQLNOTFOUND)
2543
2534
  return Qnil;
@@ -2625,12 +2616,12 @@ fetch_many(VALUE self, VALUE n, VALUE type)
2625
2616
 
2626
2617
  Data_Get_Struct(self, cursor_t, c);
2627
2618
  if (!c->is_open)
2628
- rb_raise(rb_eRuntimeError, "Open the cursor object first");
2619
+ rb_raise(esyms.eProgrammingError, "Open the cursor object first");
2629
2620
 
2630
2621
  did = c->database_id;
2631
2622
  EXEC SQL set connection :did;
2632
2623
  if (SQLCODE < 0)
2633
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2624
+ raise_ifx_extended();
2634
2625
 
2635
2626
  output = c->daOutput;
2636
2627
  cid = c->cursor_id;
@@ -2646,7 +2637,7 @@ fetch_many(VALUE self, VALUE n, VALUE type)
2646
2637
  for(i = 0; all || i < max; i++) {
2647
2638
  EXEC SQL fetch :cid using descriptor output;
2648
2639
  if (SQLCODE < 0)
2649
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2640
+ raise_ifx_extended();
2650
2641
 
2651
2642
  if (SQLCODE == SQLNOTFOUND)
2652
2643
  break;
@@ -2727,12 +2718,12 @@ each(VALUE self, VALUE type, int bang)
2727
2718
 
2728
2719
  Data_Get_Struct(self, cursor_t, c);
2729
2720
  if (!c->is_open)
2730
- rb_raise(rb_eRuntimeError, "Open the cursor object first");
2721
+ rb_raise(esyms.eProgrammingError, "Open the cursor object first");
2731
2722
 
2732
2723
  did = c->database_id;
2733
2724
  EXEC SQL set connection :did;
2734
2725
  if (SQLCODE < 0)
2735
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2726
+ raise_ifx_extended();
2736
2727
 
2737
2728
  output = c->daOutput;
2738
2729
  cid = c->cursor_id;
@@ -2740,7 +2731,7 @@ each(VALUE self, VALUE type, int bang)
2740
2731
  for(;;) {
2741
2732
  EXEC SQL fetch :cid using descriptor output;
2742
2733
  if (SQLCODE < 0)
2743
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2734
+ raise_ifx_extended();
2744
2735
 
2745
2736
  if (SQLCODE == SQLNOTFOUND)
2746
2737
  return self;
@@ -2879,12 +2870,12 @@ inscur_put(int argc, VALUE *argv, VALUE self)
2879
2870
 
2880
2871
  Data_Get_Struct(self, cursor_t, c);
2881
2872
  if (!c->is_open)
2882
- rb_raise(rb_eRuntimeError, "Open the cursor object first");
2873
+ rb_raise(esyms.eProgrammingError, "Open the cursor object first");
2883
2874
 
2884
2875
  did = c->database_id;
2885
2876
  EXEC SQL set connection :did;
2886
2877
  if (SQLCODE < 0)
2887
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2878
+ raise_ifx_extended();
2888
2879
 
2889
2880
  input = &c->daInput;
2890
2881
  cid = c->cursor_id;
@@ -2897,7 +2888,7 @@ inscur_put(int argc, VALUE *argv, VALUE self)
2897
2888
  EXEC SQL put :cid using descriptor input;
2898
2889
  clean_input_slots(c);
2899
2890
  if (SQLCODE < 0)
2900
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2891
+ raise_ifx_extended();
2901
2892
 
2902
2893
  /* XXX 2-448, Guide to SQL: Sytax*/
2903
2894
  return INT2FIX(sqlca.sqlerrd[2]);
@@ -2921,12 +2912,12 @@ inscur_flush(VALUE self)
2921
2912
 
2922
2913
  Data_Get_Struct(self, cursor_t, c);
2923
2914
  if (!c->is_open)
2924
- rb_raise(rb_eRuntimeError, "Open the cursor object first");
2915
+ rb_raise(esyms.eProgrammingError, "Open the cursor object first");
2925
2916
 
2926
2917
  did = c->database_id;
2927
2918
  EXEC SQL set connection :did;
2928
2919
  if (SQLCODE < 0)
2929
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2920
+ raise_ifx_extended();
2930
2921
 
2931
2922
  cid = c->cursor_id;
2932
2923
  EXEC SQL flush :cid;
@@ -2952,7 +2943,7 @@ scrollcur_entry(VALUE self, VALUE index, VALUE type, int bang)
2952
2943
 
2953
2944
  Data_Get_Struct(self, cursor_t, c);
2954
2945
  if (!c->is_open)
2955
- rb_raise(rb_eRuntimeError, "Open the cursor object first");
2946
+ rb_raise(esyms.eProgrammingError, "Open the cursor object first");
2956
2947
 
2957
2948
  did = c->database_id;
2958
2949
  EXEC SQL set connection :did;
@@ -2975,7 +2966,7 @@ scrollcur_entry(VALUE self, VALUE index, VALUE type, int bang)
2975
2966
  return Qnil;
2976
2967
 
2977
2968
  if (SQLCODE < 0)
2978
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
2969
+ raise_ifx_extended();
2979
2970
 
2980
2971
  RECORD(c, type, bang, record);
2981
2972
  return make_result(c, record);
@@ -3126,7 +3117,7 @@ scrollcur_rel(int argc, VALUE *argv, VALUE self, int dir, VALUE type, int bang)
3126
3117
 
3127
3118
  Data_Get_Struct(self, cursor_t, c);
3128
3119
  if (!c->is_open)
3129
- rb_raise(rb_eRuntimeError, "Open the cursor object first");
3120
+ rb_raise(esyms.eProgrammingError, "Open the cursor object first");
3130
3121
 
3131
3122
  did = c->database_id;
3132
3123
  EXEC SQL set connection :did;
@@ -3144,7 +3135,7 @@ scrollcur_rel(int argc, VALUE *argv, VALUE self, int dir, VALUE type, int bang)
3144
3135
  return Qnil;
3145
3136
 
3146
3137
  if (SQLCODE < 0)
3147
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
3138
+ raise_ifx_extended();
3148
3139
 
3149
3140
  RECORD(c, type, bang, record);
3150
3141
  return make_result(c, record);
@@ -3492,18 +3483,6 @@ cursor_alloc(VALUE klass)
3492
3483
  return Data_Wrap_Struct(klass, cursor_mark, cursor_free, c);
3493
3484
  }
3494
3485
 
3495
- /*
3496
- * call-seq:
3497
- * Cursor.new(database, query, options = nil) => cursor
3498
- *
3499
- * Prepares <i>query</i> in the context of <i>database</i> with <i>options</i>
3500
- * and returns a <code>Cursor</code> object.
3501
- *
3502
- * <i>options</i> can be nil or a Hash object with the following possible keys:
3503
- *
3504
- * :scroll => true or false
3505
- * :hold => true or false
3506
- */
3507
3486
  static VALUE
3508
3487
  cursor_initialize(int argc, VALUE *argv, VALUE self)
3509
3488
  {
@@ -3521,7 +3500,7 @@ cursor_initialize(int argc, VALUE *argv, VALUE self)
3521
3500
 
3522
3501
  EXEC SQL set connection :did;
3523
3502
  if (SQLCODE < 0)
3524
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
3503
+ raise_ifx_extended();
3525
3504
 
3526
3505
  Data_Get_Struct(self, cursor_t, c);
3527
3506
  c->db = db;
@@ -3540,7 +3519,7 @@ cursor_initialize(int argc, VALUE *argv, VALUE self)
3540
3519
 
3541
3520
  EXEC SQL prepare :sid from :c_query;
3542
3521
  if (SQLCODE < 0)
3543
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
3522
+ raise_ifx_extended();
3544
3523
 
3545
3524
  if (RTEST(scroll) && RTEST(hold))
3546
3525
  EXEC SQL declare :cid scroll cursor with hold for :sid;
@@ -3552,7 +3531,7 @@ cursor_initialize(int argc, VALUE *argv, VALUE self)
3552
3531
  EXEC SQL declare :cid cursor for :sid;
3553
3532
 
3554
3533
  if (SQLCODE < 0)
3555
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
3534
+ raise_ifx_extended();
3556
3535
 
3557
3536
  alloc_input_slots(c, c_query);
3558
3537
  EXEC SQL describe :sid into output;
@@ -3574,6 +3553,37 @@ cursor_initialize(int argc, VALUE *argv, VALUE self)
3574
3553
  return self;
3575
3554
  }
3576
3555
 
3556
+ static VALUE cursor_drop(VALUE self);
3557
+ /*
3558
+ * call-seq:
3559
+ * Cursor.new(database, query, options) => cursor
3560
+ * Cursor.new(database, query, options) {|cursor| block } => obj
3561
+ *
3562
+ * Creates a Cursor object based on <i>query</i> using <i>options</i>
3563
+ * in the context of <i>database</i> but does not open it.
3564
+ * In the first form the Cursor object is returned.
3565
+ * In the second form the Cursor object is passed to the block and when it
3566
+ * terminates, the Cursor object is dropped, returning the value of the block.
3567
+ *
3568
+ * <i>options</i> can be nil or a Hash object with the following possible keys:
3569
+ *
3570
+ * :scroll => true or false
3571
+ * :hold => true or false
3572
+ */
3573
+ static VALUE
3574
+ rb_cursor_s_new(int argc, VALUE *argv, VALUE klass)
3575
+ {
3576
+ VALUE cursor;
3577
+
3578
+ cursor = rb_class_new_instance(argc, argv, klass);
3579
+
3580
+ if (rb_block_given_p())
3581
+ return rb_ensure(rb_yield, cursor, cursor_drop, cursor);
3582
+
3583
+ return cursor;
3584
+ }
3585
+
3586
+ static VALUE cursor_open(int argc, VALUE *argv, VALUE self);
3577
3587
  /*
3578
3588
  * call-seq:
3579
3589
  * Cursor.open(database, query, options) => cursor
@@ -3591,8 +3601,6 @@ cursor_initialize(int argc, VALUE *argv, VALUE self)
3591
3601
  * :hold => true or false
3592
3602
  * :params => input parameters as an Array or nil
3593
3603
  */
3594
- static VALUE cursor_open(int argc, VALUE *argv, VALUE self);
3595
- static VALUE cursor_drop(VALUE self);
3596
3604
  static VALUE
3597
3605
  cursor_s_open(int argc, VALUE *argv, VALUE klass)
3598
3606
  {
@@ -3609,7 +3617,7 @@ cursor_s_open(int argc, VALUE *argv, VALUE klass)
3609
3617
  if (TYPE(params) == T_ARRAY)
3610
3618
  open_argc = RARRAY(params)->len;
3611
3619
  else if (params != Qnil)
3612
- rb_raise(rb_eRuntimeError, "Parameters must be supplied as an Array");
3620
+ rb_raise(rb_eArgError, "Parameters must be supplied as an Array");
3613
3621
  }
3614
3622
 
3615
3623
  cursor = rb_class_new_instance(argc, argv, klass);
@@ -3662,7 +3670,7 @@ cursor_open(int argc, VALUE *argv, VALUE self)
3662
3670
  did = c->database_id;
3663
3671
  EXEC SQL set connection :did;
3664
3672
  if (SQLCODE < 0)
3665
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
3673
+ raise_ifx_extended();
3666
3674
 
3667
3675
  input = &c->daInput;
3668
3676
  cid = c->cursor_id;
@@ -3685,7 +3693,7 @@ cursor_open(int argc, VALUE *argv, VALUE self)
3685
3693
  EXEC SQL open :cid;
3686
3694
 
3687
3695
  if (SQLCODE < 0)
3688
- rb_raise(rb_eRuntimeError, "Informix Error: %d", SQLCODE);
3696
+ raise_ifx_extended();
3689
3697
 
3690
3698
  c->is_open = 1;
3691
3699
  return self;
@@ -3733,7 +3741,8 @@ void Init_informix(void)
3733
3741
  rb_mInformix = rb_define_module("Informix");
3734
3742
  rb_mScrollCursor = rb_define_module_under(rb_mInformix, "ScrollCursor");
3735
3743
  rb_mInsertCursor = rb_define_module_under(rb_mInformix, "InsertCursor");
3736
- rb_define_module_function(rb_mInformix, "connect", informix_connect, -1);
3744
+ rb_define_module_function(rb_mInformix, "connect", rb_informix_connect, -1);
3745
+ rb_define_module_function(rb_mInformix, "version", rb_informix_version, 0);
3737
3746
 
3738
3747
  /* class Slob --------------------------------------------------------- */
3739
3748
  rb_cSlob = rb_define_class_under(rb_mInformix, "Slob", rb_cObject);
@@ -3828,6 +3837,7 @@ void Init_informix(void)
3828
3837
  rb_define_alias(rb_cDatabase, "disconnect", "close");
3829
3838
  rb_define_method(rb_cDatabase, "immediate", rb_database_immediate, 1);
3830
3839
  rb_define_alias(rb_cDatabase, "do", "immediate");
3840
+ rb_define_alias(rb_cDatabase, "execute", "immediate");
3831
3841
  rb_define_method(rb_cDatabase, "rollback", rb_database_rollback, 0);
3832
3842
  rb_define_method(rb_cDatabase, "commit", rb_database_commit, 0);
3833
3843
  rb_define_method(rb_cDatabase, "transaction", rb_database_transaction, 0);
@@ -3898,6 +3908,7 @@ void Init_informix(void)
3898
3908
  rb_cCursor = rb_define_class_under(rb_mInformix, "Cursor", rb_cObject);
3899
3909
  rb_define_alloc_func(rb_cCursor, cursor_alloc);
3900
3910
  rb_define_method(rb_cCursor, "initialize", cursor_initialize, -1);
3911
+ rb_define_singleton_method(rb_cCursor, "new", rb_cursor_s_new, -1);
3901
3912
  rb_define_singleton_method(rb_cCursor, "open", cursor_s_open, -1);
3902
3913
  rb_define_method(rb_cCursor, "id", cursor_id, 0);
3903
3914
  rb_define_method(rb_cCursor, "open", cursor_open, -1);
@@ -3939,4 +3950,7 @@ void Init_informix(void)
3939
3950
  sym_maxbytes = ID2SYM(rb_intern("maxbytes"));
3940
3951
 
3941
3952
  sym_params = ID2SYM(rb_intern("params"));
3953
+
3954
+ /* Initialize ifx_except module */
3955
+ rbifx_except_init(rb_mInformix, &esyms);
3942
3956
  }