KirbyBase DateTime

Discussion in 'Ruby' started by Horacio Sanson, Oct 31, 2005.

  1. Has anyone worked with DateTime fields in a KirbyBase database?? I can insert
    and update values using DateTime data type but when I read the value back
    with a select it returns as and Array not a DateTime object, how can I
    convert it back to DateTime??

    Here is an example

    result = tbl.select:)last_visited) {|r| r.url == "http://www.a-link.org" }
    => [#<struct #<Class:0xb7a3b8d8> last_visited=#<DateTime: -1/2,0,2299161>>]

    result.last_visited => [#<DateTime: -1/2,0,2299161>]

    result.last_visited.class => Array


    regards
    Horacio
     
    Horacio Sanson, Oct 31, 2005
    #1
    1. Advertising

  2. Horacio Sanson

    Jamey Cribbs Guest

    Horacio Sanson wrote:

    >Has anyone worked with DateTime fields in a KirbyBase database?? I can insert
    >and update values using DateTime data type but when I read the value back
    >with a select it returns as and Array not a DateTime object, how can I
    >convert it back to DateTime??
    >
    >Here is an example
    >
    >result = tbl.select:)last_visited) {|r| r.url == "http://www.a-link.org" }
    >=> [#<struct #<Class:0xb7a3b8d8> last_visited=#<DateTime: -1/2,0,2299161>>]
    >
    >result.last_visited => [#<DateTime: -1/2,0,2299161>]
    >
    >result.last_visited.class => Array
    >
    >

    Here's what is happening: When you do a #select, KirbyBase returns a KBResultSet, which is basically an Array that holds a bunch of Struct objects.

    What KirbyBase also does is, inside the KBResultSet, it builds up a "cross-cut" of all of the values in each column of the result set, so that you can do some cool things like get a sum of all values in a column of the result (see the example in the examples\crosstab_test directory of the distribution). Each "cross-cut" is an array that is held in an instance variable of the KBResultSet and the name of this instance variable is the same as the name of the column.

    So, when you did:

    result.last_visited

    You were actually asking for the "cross-cut" or "cross-tab" array of all of the values in the last_visited column of the KBResultSet. That's not what you wanted. :)

    What you want to do is this:

    result[0].last_visited or result.first.last_visited

    Because, remember, the KBResultSet is actually an array of all the records that satisfied the query condition. Notice, in your above example, that the Struct that satisfied your #select condition is *inside* an array.

    Let me know if I didn't explain this well enough.

    This reminds me to add a section to the documentation about "crosstabs" or "crosscuts" (I don't know what to call them). By the way, I'm in the process of doing a pretty comprehensive revision of the manual. It should be ready for the next release.

    Jamey Cribbs



    Confidentiality Notice: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. If you are not the intended recipient(s), you are hereby notified that any dissemination, unauthorized review, use, disclosure or distribution of this email and any materials contained in any attachments is prohibited. If you receive this message in error, or are not the intended recipient(s), please immediately notify the sender by email and destroy all copies of the original message, including attachments.
     
    Jamey Cribbs, Oct 31, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christos TZOTZIOY Georgiou
    Replies:
    3
    Views:
    759
    Christos TZOTZIOY Georgiou
    Sep 13, 2003
  2. Tim Peters
    Replies:
    0
    Views:
    597
    Tim Peters
    Sep 9, 2003
  3. mp
    Replies:
    1
    Views:
    440
    John Machin
    Jul 28, 2006
  4. Martin
    Replies:
    0
    Views:
    376
    Martin
    Dec 27, 2008
  5. Replies:
    2
    Views:
    801
    M.-A. Lemburg
    Jan 6, 2009
Loading...

Share This Page