ruby-informix 0.7.0 → 0.7.1

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 (4) hide show
  1. data/Changelog +11 -0
  2. data/ext/informixc.c +498 -483
  3. data/ext/informixc.ec +93 -65
  4. metadata +2 -2
data/ext/informixc.ec CHANGED
@@ -1,6 +1,6 @@
1
- /* $Id: informixc.ec,v 1.26 2008/04/01 05:30:21 santana Exp $ */
1
+ /* $Id: informixc.ec,v 1.29 2008/04/03 00:50:20 santana Exp $ */
2
2
  /*
3
- * Copyright (c) 2006-2008, Gerardo Santana Gomez Garrido <gerardo.santana@gmail.com>
3
+ * Copyright (c) 2006-2008, Gerardo Santana Gomez Garrido <gerardo.santana@gmail.com>
4
4
  * All rights reserved.
5
5
  *
6
6
  * Redistribution and use in source and binary forms, with or without
@@ -28,7 +28,7 @@
28
28
  * POSSIBILITY OF SUCH DAMAGE.
29
29
  */
30
30
 
31
- static const char rcsid[] = "$Id: informixc.ec,v 1.26 2008/04/01 05:30:21 santana Exp $";
31
+ static const char rcsid[] = "$Id: informixc.ec,v 1.29 2008/04/03 00:50:20 santana Exp $";
32
32
 
33
33
  #include "ruby.h"
34
34
 
@@ -69,6 +69,13 @@ static VALUE sym_params;
69
69
 
70
70
  #define IDSIZE 30
71
71
 
72
+ typedef struct {
73
+ char database_id[IDSIZE];
74
+ char cursor_id[IDSIZE];
75
+ char stmt_id[IDSIZE];
76
+ long idcount;
77
+ } database_t;
78
+
72
79
  typedef struct {
73
80
  short is_select, is_open;
74
81
  struct sqlda daInput, *daOutput;
@@ -1926,23 +1933,26 @@ make_result(cursor_t *c, VALUE record)
1926
1933
  static void
1927
1934
  database_free(void *p)
1928
1935
  {
1936
+ database_t *dbt;
1929
1937
  EXEC SQL begin declare section;
1930
- char *did;
1938
+ char *id;
1931
1939
  EXEC SQL end declare section;
1932
1940
 
1933
- did = p;
1934
- EXEC SQL disconnect :did;
1941
+ dbt = p;
1942
+ id = dbt->database_id;
1943
+ EXEC SQL disconnect :id;
1935
1944
  xfree(p);
1936
1945
  }
1937
1946
 
1938
1947
  static VALUE
1939
1948
  database_alloc(VALUE klass)
1940
1949
  {
1941
- char *did;
1950
+ database_t *dbt;
1942
1951
 
1943
- did = ALLOC_N(char, IDSIZE<<1);
1944
- did[0] = did[IDSIZE] = 0;
1945
- return Data_Wrap_Struct(klass, 0, database_free, did);
1952
+ dbt = ALLOC(database_t);
1953
+ dbt->database_id[0] = dbt->cursor_id[0] = dbt->stmt_id[0] = 0;
1954
+ dbt->idcount = 0;
1955
+ return Data_Wrap_Struct(klass, 0, database_free, dbt);
1946
1956
  }
1947
1957
 
1948
1958
  /* :nodoc: */
@@ -1951,9 +1961,11 @@ rb_database_initialize(int argc, VALUE *argv, VALUE self)
1951
1961
  {
1952
1962
  VALUE arg[3], version;
1953
1963
  VALUE server_type, major, minor, os, level, full;
1964
+ database_t *dbt;
1954
1965
 
1955
1966
  EXEC SQL begin declare section;
1956
- char *dbname, *user = NULL, *pass = NULL, *did;
1967
+ char *dbname, *user = NULL, *pass = NULL;
1968
+ char *did, *cid, *sid;
1957
1969
  struct version_t {
1958
1970
  varchar server_type[41], major[3], minor[3], os[3], level[3];
1959
1971
  varchar full[61];
@@ -1965,10 +1977,14 @@ rb_database_initialize(int argc, VALUE *argv, VALUE self)
1965
1977
  if (NIL_P(arg[0]))
1966
1978
  rb_raise(rb_eProgrammingError, "A database name must be specified");
1967
1979
 
1968
- Data_Get_Struct(self, char, did);
1980
+ Data_Get_Struct(self, database_t, dbt);
1969
1981
 
1970
1982
  dbname = StringValueCStr(arg[0]);
1971
- snprintf(did, IDSIZE, "DB%lX", self);
1983
+ snprintf(dbt->database_id, IDSIZE, "DB%lX", self);
1984
+ snprintf(dbt->cursor_id, IDSIZE, "CUR%lX", dbt->idcount);
1985
+ snprintf(dbt->stmt_id, IDSIZE, "STMT%lX", dbt->idcount);
1986
+ ++dbt->idcount;
1987
+ did = dbt->database_id;
1972
1988
 
1973
1989
  if (!NIL_P(arg[1]))
1974
1990
  user = StringValueCStr(arg[1]);
@@ -1982,6 +1998,24 @@ rb_database_initialize(int argc, VALUE *argv, VALUE self)
1982
1998
  else
1983
1999
  EXEC SQL connect to :dbname as :did with concurrent transaction;
1984
2000
 
2001
+ if (SQLCODE < 0)
2002
+ raise_ifx_extended();
2003
+
2004
+ cid = dbt->cursor_id;
2005
+ sid = dbt->stmt_id;
2006
+
2007
+ EXEC SQL prepare :sid from
2008
+ 'select colname, coltype, collength, extended_id,
2009
+ type, default, c.colno
2010
+ from syscolumns c, outer sysdefaults d
2011
+ where c.tabid = ? and c.tabid = d.tabid and c.colno = d.colno
2012
+ order by c.colno';
2013
+
2014
+ if (SQLCODE < 0)
2015
+ raise_ifx_extended();
2016
+
2017
+ EXEC SQL declare :cid cursor for :sid;
2018
+
1985
2019
  if (SQLCODE < 0)
1986
2020
  raise_ifx_extended();
1987
2021
 
@@ -2013,29 +2047,26 @@ rb_database_initialize(int argc, VALUE *argv, VALUE self)
2013
2047
  * call-seq:
2014
2048
  * db.close => db
2015
2049
  *
2016
- * Disconnects <i>db</i> and returns __self__
2050
+ * Disconnects <i>db</i> and returns nil.
2017
2051
  */
2018
2052
  static VALUE
2019
2053
  rb_database_close(VALUE self)
2020
2054
  {
2055
+ database_t *dbt;
2021
2056
  EXEC SQL begin declare section;
2022
- char *did;
2057
+ char *id;
2023
2058
  EXEC SQL end declare section;
2024
2059
 
2025
- Data_Get_Struct(self, char, did);
2026
- did += IDSIZE;
2027
- if (*did)
2028
- EXEC SQL free :did;
2029
- did -= IDSIZE;
2030
- EXEC SQL disconnect :did;
2060
+ Data_Get_Struct(self, database_t, dbt);
2061
+ id = dbt->database_id;
2062
+ EXEC SQL disconnect :id;
2031
2063
 
2032
- return self;
2064
+ return Qnil;
2033
2065
  }
2034
2066
 
2035
2067
  /*
2036
2068
  * call-seq:
2037
2069
  * db.immediate(query) => fixnum
2038
- * db.execute(query) => fixnum
2039
2070
  *
2040
2071
  * Executes <i>query</i> and returns the number of rows affected.
2041
2072
  * <i>query</i> must not return rows. Executes efficiently any
@@ -2055,13 +2086,15 @@ rb_database_close(VALUE self)
2055
2086
  static VALUE
2056
2087
  rb_database_immediate(VALUE self, VALUE arg)
2057
2088
  {
2089
+ database_t *dbt;
2058
2090
  EXEC SQL begin declare section;
2059
2091
  char *query, *did;
2060
2092
  EXEC SQL end declare section;
2061
2093
 
2062
- Data_Get_Struct(self, char, did);
2063
-
2094
+ Data_Get_Struct(self, database_t, dbt);
2095
+ did = dbt->database_id;
2064
2096
  EXEC SQL set connection :did;
2097
+
2065
2098
  if (SQLCODE < 0)
2066
2099
  raise_ifx_extended();
2067
2100
 
@@ -2082,17 +2115,20 @@ rb_database_immediate(VALUE self, VALUE arg)
2082
2115
  static VALUE
2083
2116
  rb_database_rollback(VALUE self)
2084
2117
  {
2118
+ database_t *dbt;
2085
2119
  EXEC SQL begin declare section;
2086
2120
  char *did;
2087
2121
  EXEC SQL end declare section;
2088
2122
 
2089
- Data_Get_Struct(self, char, did);
2090
-
2123
+ Data_Get_Struct(self, database_t, dbt);
2124
+ did = dbt->database_id;
2091
2125
  EXEC SQL set connection :did;
2126
+
2092
2127
  if (SQLCODE < 0)
2093
2128
  raise_ifx_extended();
2094
2129
 
2095
2130
  EXEC SQL rollback;
2131
+
2096
2132
  return self;
2097
2133
  }
2098
2134
 
@@ -2105,17 +2141,20 @@ rb_database_rollback(VALUE self)
2105
2141
  static VALUE
2106
2142
  rb_database_commit(VALUE self)
2107
2143
  {
2144
+ database_t *dbt;
2108
2145
  EXEC SQL begin declare section;
2109
2146
  char *did;
2110
2147
  EXEC SQL end declare section;
2111
2148
 
2112
- Data_Get_Struct(self, char, did);
2113
-
2149
+ Data_Get_Struct(self, database_t, dbt);
2150
+ did = dbt->database_id;
2114
2151
  EXEC SQL set connection :did;
2152
+
2115
2153
  if (SQLCODE < 0)
2116
2154
  raise_ifx_extended();
2117
2155
 
2118
2156
  EXEC SQL commit;
2157
+
2119
2158
  return self;
2120
2159
  }
2121
2160
 
@@ -2154,23 +2193,27 @@ static VALUE
2154
2193
  rb_database_transaction(VALUE self)
2155
2194
  {
2156
2195
  VALUE ret;
2196
+ database_t *dbt;
2157
2197
  EXEC SQL begin declare section;
2158
2198
  char *did;
2159
2199
  EXEC SQL end declare section;
2160
2200
 
2161
- Data_Get_Struct(self, char, did);
2162
-
2201
+ Data_Get_Struct(self, database_t, dbt);
2202
+ did = dbt->database_id;
2163
2203
  EXEC SQL set connection :did;
2204
+
2164
2205
  if (SQLCODE < 0)
2165
2206
  raise_ifx_extended();
2166
2207
 
2167
2208
  EXEC SQL commit;
2168
-
2169
2209
  EXEC SQL begin work;
2170
2210
  ret = rb_rescue(rb_yield, self, database_transfail, self);
2211
+
2171
2212
  if (ret == Qundef)
2172
2213
  rb_raise(rb_eOperationalError, "Transaction rolled back");
2214
+
2173
2215
  EXEC SQL commit;
2216
+
2174
2217
  return self;
2175
2218
  }
2176
2219
 
@@ -2197,6 +2240,7 @@ rb_database_columns(VALUE self, VALUE tablename)
2197
2240
  "YEAR", "MONTH", "DAY", "HOUR", "MINUTE", "SECOND"
2198
2241
  };
2199
2242
 
2243
+ database_t *dbt;
2200
2244
  EXEC SQL begin declare section;
2201
2245
  char *did, *cid;
2202
2246
  char *tabname;
@@ -2207,9 +2251,10 @@ rb_database_columns(VALUE self, VALUE tablename)
2207
2251
  varchar defvalue[257];
2208
2252
  EXEC SQL end declare section;
2209
2253
 
2210
- Data_Get_Struct(self, char, did);
2211
-
2254
+ Data_Get_Struct(self, database_t, dbt);
2255
+ did = dbt->database_id;
2212
2256
  EXEC SQL set connection :did;
2257
+
2213
2258
  if (SQLCODE < 0)
2214
2259
  raise_ifx_extended();
2215
2260
 
@@ -2221,32 +2266,9 @@ rb_database_columns(VALUE self, VALUE tablename)
2221
2266
  rb_raise(rb_eProgrammingError, "Table '%s' doesn't exist", tabname);
2222
2267
 
2223
2268
  result = rb_ary_new();
2224
-
2225
- cid = did + IDSIZE;
2226
-
2227
- if (!*cid) {
2228
- EXEC SQL begin declare section;
2229
- char sid[IDSIZE];
2230
- EXEC SQL end declare section;
2231
-
2232
- snprintf(sid, IDSIZE, "COLS%lX", self);
2233
- snprintf(cid, IDSIZE, "COLC%lX", self);
2234
-
2235
- EXEC SQL prepare :sid from
2236
- 'select colname, coltype, collength, extended_id,
2237
- type, default, c.colno
2238
- from syscolumns c, outer sysdefaults d
2239
- where c.tabid = ? and c.tabid = d.tabid
2240
- and c.colno = d.colno
2241
- order by c.colno';
2242
- EXEC SQL declare :cid cursor for :sid;
2243
- if (SQLCODE < 0) {
2244
- cid[0] = 0;
2245
- raise_ifx_extended();
2246
- }
2247
- }
2248
-
2269
+ cid = dbt->cursor_id;
2249
2270
  EXEC SQL open :cid using :tabid;
2271
+
2250
2272
  if (SQLCODE < 0)
2251
2273
  raise_ifx_extended();
2252
2274
 
@@ -2407,11 +2429,13 @@ rb_statement_initialize(VALUE self, VALUE db, VALUE query)
2407
2429
  {
2408
2430
  struct sqlda *output;
2409
2431
  cursor_t *c;
2432
+ database_t *dbt;
2410
2433
  EXEC SQL begin declare section;
2411
2434
  char *c_query, *sid, *did;
2412
2435
  EXEC SQL end declare section;
2413
2436
 
2414
- Data_Get_Struct(db, char, did);
2437
+ Data_Get_Struct(db, database_t, dbt);
2438
+ did = dbt->database_id;
2415
2439
  EXEC SQL set connection :did;
2416
2440
  if (SQLCODE < 0)
2417
2441
  raise_ifx_extended();
@@ -2420,7 +2444,7 @@ rb_statement_initialize(VALUE self, VALUE db, VALUE query)
2420
2444
  c->db = db;
2421
2445
  c->database_id = did;
2422
2446
  output = c->daOutput;
2423
- snprintf(c->stmt_id, sizeof(c->stmt_id), "STMT%lX", self);
2447
+ snprintf(c->stmt_id, sizeof(c->stmt_id), "STMT%lX", dbt->idcount++);
2424
2448
  sid = c->stmt_id;
2425
2449
  c_query = StringValueCStr(query);
2426
2450
 
@@ -3073,6 +3097,8 @@ rb_cursor_s_new0(int argc, VALUE *argv, VALUE self)
3073
3097
  VALUE scroll, hold;
3074
3098
  struct sqlda *output;
3075
3099
  cursor_t c, *cur;
3100
+ database_t *dbt;
3101
+ long id;
3076
3102
  EXEC SQL begin declare section;
3077
3103
  char *c_query;
3078
3104
  char *cid, *sid, *did;
@@ -3080,17 +3106,19 @@ rb_cursor_s_new0(int argc, VALUE *argv, VALUE self)
3080
3106
 
3081
3107
  memset(&c, 0, sizeof(c));
3082
3108
  rb_scan_args(argc, argv, "21", &db, &query, &options);
3083
- Data_Get_Struct(db, char, did);
3084
-
3109
+ Data_Get_Struct(db, database_t, dbt);
3110
+ did = dbt->database_id;
3085
3111
  EXEC SQL set connection :did;
3112
+
3086
3113
  if (SQLCODE < 0)
3087
3114
  raise_ifx_extended();
3088
3115
 
3089
3116
  c.db = db;
3090
3117
  c.database_id = did;
3091
3118
  scroll = hold = Qfalse;
3092
- snprintf(c.cursor_id, sizeof(c.cursor_id), "CUR%lX", self);
3093
- snprintf(c.stmt_id, sizeof(c.stmt_id), "STMT%lX", self);
3119
+ id = dbt->idcount++;
3120
+ snprintf(c.cursor_id, sizeof(c.cursor_id), "CUR%lX", id);
3121
+ snprintf(c.stmt_id, sizeof(c.stmt_id), "STMT%lX", id);
3094
3122
  cid = c.cursor_id; sid = c.stmt_id;
3095
3123
  c_query = StringValueCStr(query);
3096
3124
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: ruby-informix
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.7.0
7
- date: 2008-03-31 00:00:00 -06:00
6
+ version: 0.7.1
7
+ date: 2008-04-02 00:00:00 -06:00
8
8
  summary: Ruby library for IBM Informix
9
9
  require_paths:
10
10
  - lib