Ask a Question related to Ruby, Design and Development.

  1. #1

    Default Ruby DBI Access

    ------=_NextPart_000_001F_01C3AF83.07D67E60
    Content-Type: text/plain;
    charset="iso-8859-1"
    Content-Transfer-Encoding: 7bit

    I am accessing an Oracle Database, and I would like for Ruby to be able to
    get the exact size of the returned columns. How can I do this dynamically
    if the only thing I'm given is an SQL statement?

    Sincerely,

    Brent Harris
    Information Technology
    ABA Programmer


    ------=_NextPart_000_001F_01C3AF83.07D67E60--


    Brent Harris Guest

  2. Similar Questions and Discussions

    1. Internet access at Ruby conference
      Hi, Does anyone know whether there will be (non-dial-up) Internet access available from either the hotel or the conference itself tomorrow? ...
    2. [ba-rb] BA-rb ( Bay Area Ruby Users Group ) - 'Generating Code in Ruby' by Jack Herrington.
      Count me in again, too. -- Jos Backus _/ _/_/_/ Sunnyvale, CA _/ _/ _/ _/ _/_/_/ _/ _/ _/ _/ jos at...
    3. Thread safety: Serializing access to ruby interpreter- again
      I recently asked about this and got answers, but here I go again: How can I efficiently serialize access to the ruby interpreter. I have to make...
    4. [ANN] ruby-freedb, ruby-serialport, ruby-mp3info moved to Rubyforge
      http://ruby-freedb.rubyforge.org/ http://ruby-serialport.rubyforge.org/ http://ruby-mp3info.rubyforge.org/ bye! --...
    5. INI file access from Ruby
      Hi all, if you need to parse/access INI files - what are you using? (whatever your OS/Windows ;-) may be) I tried the one coming with the...
  3. #2

    Default Re: Ruby DBI Access

    "Brent Harris" <bharris@pcci.edu> writes:
    > I am accessing an Oracle Database, and I would like for Ruby to be able to
    > get the exact size of the returned columns. How can I do this dynamically
    > if the only thing I'm given is an SQL statement?
    You can get the data size, if you use one of the following:

    Ruby9i:
    (I havn't use it. I just look at the codes.)

    low-level APIs of oracle module:
    ORAcursor#describe(pos)

    low-level APIs of oci8 module:
    param = OCIStmt#paramGet(pos)
    param.attrGet(OCI_ATTR_DATA_SIZE)
    param.attrGet(OCI_ATTR_SCALE)
    param.attrGet(OCI_ATTR_PRECISION)

    dbd_oracle returns larger size. The others can't do.

    But above three APIs don't return the exact size, but return the
    internal data size. Even though the datatype is 'CHAR', the retrieved
    string may be larger of smaller than the stored string data if the
    charsets of the client and the server are different.

    While looking at Ruby9i source code, I found a bug in it.
    According to the OCI manual, the datatype of OCI_ATTR_DATA_SIZE is
    ub4. But it is ub2 in fact. The original code works on a little-endian
    CPU, but not on a big-endian CPU.

    --- varchar.c.orig 2003-07-07 09:13:18.000000000 +0900
    +++ varchar.c 2003-11-22 11:01:31.000000000 +0900
    @@ -18,7 +18,7 @@
    Data_Get_Struct(self, oci9_define_buf, bp);
    VALUE str;
    oci9_handle *parm_h;
    - ub4 col_size;
    + ub2 col_size;

    if (argc == 1)
    switch (TYPE(argv[0]))
    @@ -32,7 +32,6 @@
    Data_Get_Struct(rb_ary_entry(argv[0], 2), oci9_handle, parm_h);
    if (OCIAttrGet(parm_h->ptr, OCI_DTYPE_PARAM, (dvoid*) &col_size, 0, OCI_ATTR_DATA_SIZE, err_h))
    error_raise("Could not get column size", "varchar_initialize", __FILE__, __LINE__);
    - col_size &= 0x0000ffff; /* XXX high bytes getting corrupted */
    rb_hash_aset(rb_iv_get(self, "@column_info"), rb_str_new2("size"), INT2FIX(col_size));
    /* prepare to receive varchar of length col_size */
    bp->val = ALLOC_N(char, col_size + 1);

    --
    KUBO Takehiro
    [email]kubo@jiubao.org[/email]

    KUBO Takehiro Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 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 138 139