KirbyBase DateTime

H

Horacio Sanson

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
 
J

Jamey Cribbs

Horacio said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top