Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   KirbyBase DateTime (http://www.velocityreviews.com/forums/t825657-kirbybase-datetime.html)

Horacio Sanson 10-31-2005 02:25 AM

KirbyBase DateTime
 
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



Jamey Cribbs 10-31-2005 02:51 PM

Re: KirbyBase DateTime
 
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.




All times are GMT. The time now is 02:42 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.