knop_database documentation clarification

classic Classic list List threaded Threaded
28 messages Options
12
Reply | Threaded
Open this post in threaded view
|

knop_database documentation clarification

stevepiercy
 From the help for knop_database:

     -> settable
     Changes the current table for a database object. Useful to be
     able to create database objects faster by copying an existing
     object and just change the table name. This is a little bit
     faster than creating a new instance from scratch, *but no table
     validation is performed*. Only do this to add database
objects for
     tables within the same database that the original database
     object.
     Parameters:
         -table (required string)

What does the phrase "but no table validation is performed"
mean?  Does it mean that the name of the table is not checked
for existence in the database?

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>


--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

stevepiercy
Follow up question:
How does one use the settable method?  I don't mean syntacticly,
but contextually in a code sample.  In which of the typical Knop
files would it be used, and with which other objects and methods
would it be used?

$d->settable(-table='mytable');

Currently I'm just declaring a bunch of database objects, one
per table, and that seems wasteful.  I couldn't find any
reference to it in the Knop paper or this list archive.  I get
an error:

Attempt to modify a frozen value. The value was "mytable" of
type "string". (=)
at: settable with params: -table='mytable'

--steve


On 11/23/10 at 4:07 AM, [hidden email] (Steve Piercy - Web
Site Builder) pronounced:

>From the help for knop_database:
>
>-> settable
>Changes the current table for a database object. Useful to be
>able to create database objects faster by copying an existing
>object and just change the table name. This is a little bit
>faster than creating a new instance from scratch, *but no table
>validation is performed*. Only do this to add database objects for
>tables within the same database that the original database
>object.
>Parameters:
>-table (required string)
>
>What does the phrase "but no table validation is performed"
>mean?  Does it mean that the name of the table is not checked
>for existence in the database?
>
>--steve
>
>-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
>Steve Piercy               Web Site Builder               Soquel, CA
><[hidden email]>                  <http://www.StevePiercy.com/>
>
>

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>


--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

Johan Solve-2
In reply to this post by stevepiercy
At 04.07 -0800 2010-11-23, Steve Piercy - Web Site Builder wrote:
>What does the phrase "but no table validation is performed" mean?  Does it mean that the name of the table is not checked for existence in the database?

That would be correct yes, but looking at the code it looks like it is validated against table_realname so the documentation seems a bit incorrect.

At 04.20 -0800 2010-11-23, Steve Piercy - Web Site Builder wrote:
>How does one use the settable method?  I don't mean syntacticly, but contextually in a code sample.  In which of the typical Knop files would it be used, and with which other objects and methods would it be used?

It could be used either in cfg__database to make multiple copies of a single db object, or it could be used for specific cases where you need a temporary extra copy of a db object but might want to tie it to another table.

>$d->settable(-table='mytable');
>
>Currently I'm just declaring a bunch of database objects, one per table, and that seems wasteful.  I couldn't find any reference to it in the Knop paper or this list archive.

I'm not sure if I've ever used it, and I had actually forgot about its existence...


>I get an error:
>
>Attempt to modify a frozen value. The value was "mytable" of type "string". (=)
>at: settable with params: -table='mytable'

Another indication that it's seldom used... I suspect there are a couple of references too many.

Current code:
                (self -> 'table_realname') = @#table;
                (self -> 'db_connect') -> removeall(#table);
                (self -> 'db_connect') -> (insert: '-table' = @#table);

Try changing to:
                (self -> 'table_realname') = #table;
                (self -> 'db_connect') -> removeall(#table);
                (self -> 'db_connect') -> (insert: '-table' = #table);


--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[hidden email]
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

stevepiercy
On 11/23/10 at 1:51 PM, [hidden email] (Johan Solve) pronounced:

>It could be used either in cfg__database to make multiple
>copies of a single db object, or it could be used for specific
>cases where you need a temporary extra copy of a db object but
>might want to tie it to another table.

cfg__database.inc?  Do you mean cfg__global.inc?

My earlier attempt was in the specific page's cfg file.  When I
put it in cfg__global.inc, I get the same error message.

>>Attempt to modify a frozen value. The value was "mytable" of type "string". (=)
>>at: settable with params: -table='mytable'
>
>Another indication that it's seldom used... I suspect there are
>a couple of references too many.
>
>Current code:
>(self -> 'table_realname') = @#table;
>(self -> 'db_connect') -> removeall(#table);
>(self -> 'db_connect') -> (insert: '-table' = @#table);
>
>Try changing to:
>(self -> 'table_realname') = #table;
>(self -> 'db_connect') -> removeall(#table);
>(self -> 'db_connect') -> (insert: '-table' = #table);

Got another error.

The tag 'oncreate' expected a parameter 'database', but the
provided value was of the wrong type. Wanted type 'database' but
received type 'null'.
at: /_mod_forms_assignment_availability/cfg.inc on line: 221 at
position: 10

Code causing error:

     var('f')=knop_form(
             -database=$db_av,

and in my cfg__global.inc:

     var('db_av')=$db_gr->settable(-table='availability');

If I set var('db_av') to a normal knop_database instance, then
it works fine.

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>


--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

Johan Solve-2
At 05.47 -0800 2010-11-23, Steve Piercy - Web Site Builder wrote:
>cfg__database.inc?  Do you mean cfg__global.inc?

Well, wherever you define your dbs. We usually do it in cfg__database.inc. That's just a matter of taste.


>Code causing error:
>
>    var('f')=knop_form(
>            -database=$db_av,
>
>and in my cfg__global.inc:
>
>    var('db_av')=$db_gr->settable(-table='availability');

Copy first, then set.
    var('db_av')=$db_gr;
        $db_gr->settable(-table='availability');



--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[hidden email]
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

stevepiercy
On 11/23/10 at 4:04 PM, [hidden email] (Johan Solve) pronounced:

>>and in my cfg__global.inc:
>>
>>var('db_av')=$db_gr->settable(-table='availability');
>
>Copy first, then set.
>var('db_av')=$db_gr;
>$db_gr->settable(-table='availability');

That fixed it without modifying knop.lasso.

What is going on behind the scenes that would cause the former
code sample to fail, but the latter to work?  There is some
subtle distinction that is lost on me.

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>


--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

jasonhuck
Unless I'm missing something, you are setting the variable to the
output of a function that does not output anything.

It's akin to doing this:

var('foo') = array(1,2,3)->reverse;
$foo;

-> null


I suppose you could try using the retarget operator to see if you get
a copy of the object, e.g.:

var('db_av') = $db_gr->settable( -table='availability')&;



I don't know if it works automatically on custom types the way it does
on the built-in ones. I've never actually tried it.

- jason



On Tue, Nov 23, 2010 at 3:03 PM, Steve Piercy - Web Site Builder
<[hidden email]> wrote:

> On 11/23/10 at 4:04 PM, [hidden email] (Johan Solve) pronounced:
>
>>> and in my cfg__global.inc:
>>>
>>> var('db_av')=$db_gr->settable(-table='availability');
>>
>> Copy first, then set.
>> var('db_av')=$db_gr;
>> $db_gr->settable(-table='availability');
>
> That fixed it without modifying knop.lasso.
>
> What is going on behind the scenes that would cause the former code sample
> to fail, but the latter to work?  There is some subtle distinction that is
> lost on me.
>
> --steve
>
> -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
> Steve Piercy               Web Site Builder               Soquel, CA
> <[hidden email]>                  <http://www.StevePiercy.com/>
>
>
> --
> #############################################################
> This message is sent to you because you are subscribed to
> the mailing list <[hidden email]>.
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>
> List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
> Project homepage http://montania.se/projects/knop/
> Google Code has the latest downloads at http://code.google.com/p/knop/
>

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

stevepiercy
In reply to this post by stevepiercy
On 11/23/10 at 12:03 PM, [hidden email] (Steve Piercy - Web
Site Builder) pronounced:

>On 11/23/10 at 4:04 PM, [hidden email] (Johan Solve) pronounced:
>
>>>and in my cfg__global.inc:
>>>
>>>var('db_av')=$db_gr->settable(-table='availability');
>>
>>Copy first, then set.
>>var('db_av')=$db_gr;
>>$db_gr->settable(-table='availability');
>
>That fixed it without modifying knop.lasso.

Oops.  It does not after all.  It should be this:

     var('db_av')=$db_gr;
     $db_av->settable(-table='availability');

And removing the references is required after all:

         (self -> 'table_realname') = #table;
         (self -> 'db_connect') -> removeall(#table);
         (self -> 'db_connect') -> (insert: '-table' = #table);

Anyway, I'm still not clear about why it is necessary to copy
first, then set.  I mean, if you copy something, why would its
values not be frozen as well?

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>


--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

stevepiercy
In reply to this post by jasonhuck
On 11/23/10 at 3:10 PM, [hidden email] (Jason Huck) pronounced:

>Unless I'm missing something, you are setting the variable to the
>output of a function that does not output anything.
>
>It's akin to doing this:
>
>var('foo') = array(1,2,3)->reverse;
>$foo;
>
>-> null

OK, so the right-hand side returns nothing, so the left-hand
side is set to NULL, right?

Assuming that is true, and since NULL does not have a ->settable
method, the value for the -table parameter is frozen, even
though it does not exist in the NULL type.  Does that sound right?

I never fully grokked that "frozen" error message.  I wrapped my
variables in a blanket to see if that would help.

>I suppose you could try using the retarget operator to see if you get
>a copy of the object, e.g.:
>
>var('db_av') = $db_gr->settable( -table='availability')&;
>
>I don't know if it works automatically on custom types the way it does
>on the built-in ones. I've never actually tried it.

Yup, that works, too.

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>


--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

jasonhuck
On Tue, Nov 23, 2010 at 3:38 PM, Steve Piercy - Web Site Builder
<[hidden email]> wrote:

> On 11/23/10 at 3:10 PM, [hidden email] (Jason Huck) pronounced:
>
>> Unless I'm missing something, you are setting the variable to the
>> output of a function that does not output anything.
>>
>> It's akin to doing this:
>>
>> var('foo') = array(1,2,3)->reverse;
>> $foo;
>>
>> -> null
>
> OK, so the right-hand side returns nothing, so the left-hand side is set to
> NULL, right?

Yes.


> Assuming that is true, and since NULL does not have a ->settable method, the
> value for the -table parameter is frozen, even though it does not exist in
> the NULL type.  Does that sound right?

Not really. ->settable is operating on the original object, not NULL.
It's just that ->settable itself doesn't return anything for the left
hand side to use for the assignment.


> I never fully grokked that "frozen" error message.  I wrapped my variables
> in a blanket to see if that would help.

I missed that part of the thread, I guess.


>> I suppose you could try using the retarget operator to see if you get
>> a copy of the object, e.g.:
>>
>> var('db_av') = $db_gr->settable( -table='availability')&;
>>
>> I don't know if it works automatically on custom types the way it does
>> on the built-in ones. I've never actually tried it.
>
> Yup, that works, too.

Cool. I thought it probably would.


- jason

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

list
In reply to this post by Johan Solve-2
23 nov 2010 kl. 22.51 skrev Johan Solve:

> At 04.07 -0800 2010-11-23, Steve Piercy - Web Site Builder wrote:
>> What does the phrase "but no table validation is performed" mean?  Does it mean that the name of the table is not checked for existence in the database?
>
> That would be correct yes, but looking at the code it looks like it is validated against table_realname so the documentation seems a bit incorrect.
>
> At 04.20 -0800 2010-11-23, Steve Piercy - Web Site Builder wrote:
>> How does one use the settable method?  I don't mean syntacticly, but contextually in a code sample.  In which of the typical Knop files would it be used, and with which other objects and methods would it be used?
>
> It could be used either in cfg__database to make multiple copies of a single db object, or it could be used for specific cases where you need a temporary extra copy of a db object but might want to tie it to another table.
>
>> $d->settable(-table='mytable');
>>
>> Currently I'm just declaring a bunch of database objects, one per table, and that seems wasteful.  I couldn't find any reference to it in the Knop paper or this list archive.
>
> I'm not sure if I've ever used it, and I had actually forgot about its existence...

I am using settable regularly so please don't touch it! :-)

Here're a couple of examples from live code:

var('dDoc' = $dBase);
$dDoc -> settable('document');

---

$dBase -> settable('department_business_unit');

Works like a charm. Due to speed issues I try not to create database objects until they're actually needed. And as few as possible. So no central database page declaring a bunch of unused database objects. And since the documentation claims that copying a database object is faster than creating a new one that's what I do if I need more than one in parallel. If I can reuse the database object, that is don't need it for the original table any more, I just change the table.

HDB
Jolle

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

Johan Solve-2
In reply to this post by stevepiercy
At 12.10 -0800 2010-11-23, Steve Piercy - Web Site Builder wrote:

>On 11/23/10 at 12:03 PM, [hidden email] (Steve Piercy - Web Site Builder) pronounced:
>
>>On 11/23/10 at 4:04 PM, [hidden email] (Johan Solve) pronounced:
>>
>>>>and in my cfg__global.inc:
>>>>
>>>>var('db_av')=$db_gr->settable(-table='availability');
>>>
>>>Copy first, then set.
>>>var('db_av')=$db_gr;
>>>$db_gr->settable(-table='availability');
>>
>>That fixed it without modifying knop.lasso.
>
>Oops.  It does not after all.  It should be this:
>    var('db_av')=$db_gr;
>    $db_av->settable(-table='availability');

Sorry, my bad...


>And removing the references is required after all:
>
>        (self -> 'table_realname') = #table;
>        (self -> 'db_connect') -> removeall(#table);
>        (self -> 'db_connect') -> (insert: '-table' = #table);
>
>Anyway, I'm still not clear about why it is necessary to copy first, then set.  I mean, if you copy something, why would its values not be frozen as well?

The "frozen" error refers to the string that you pass in the -table parameter. Since a reference to the parameter value is stored internally, trying to modify it is the same as trying to modify a string, which you can't. A string is frozen by definition.

Original code snippet:
        define_tag: 'settable', -description='...',
                -required='table', -type='string';
...
                (self -> 'table_realname') = @#table;
                (self -> 'db_connect') -> removeall(#table);
                (self -> 'db_connect') -> (insert: '-table' = @#table);
                (self -> 'table_realname') = (table_realname: self -> 'database', #table);

With this call:
    $db_av->settable(-table='availability');

you're essentially trying to do this:
'availability'=(table_realname: self -> 'database', 'availability')

And I hope you now see where the "frozen" error is coming from.

--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[hidden email]
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

Johan Solve-2
In reply to this post by stevepiercy
At 12.10 -0800 2010-11-23, Steve Piercy - Web Site Builder wrote:
>    var('db_av')=$db_gr;
>    $db_av->settable(-table='availability');

>Anyway, I'm still not clear about why it is necessary to copy first, then set.  I mean, if you copy something, why would its values not be frozen as well?

You don't want to change the table of $db_gr, do you?

I think your intention is to clone the $db_gr object and set another table for it. Hence copy first, then set.

The code you tried with changes the table for $db_gr and then creates an empty variable $db_av.
var('db_av')=$db_gr->settable(-table='availability');

Adding a retarget & operator doesn't help much, you're still modifying your original $db_gr object even if you make it output a copy of it. At least that's what I think will happen.


--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[hidden email]
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

stevepiercy
In reply to this post by list
On 11/24/10 at 7:14 AM, [hidden email] pronounced:

>I am using settable regularly so please don't touch it! :-)
>
>Here're a couple of examples from live code:
>
>var('dDoc' = $dBase);
>$dDoc -> settable('document');
>
>---
>
>$dBase -> settable('department_business_unit');

Wait a minute!  Where is the named '-table' parameter?  Since
that is the first (and only) parameter for this method, does it
implicitly use its index instead of a named parameter?

I've done testing, and I found knop_database->settable *does*
need some touch-up.  Here are the testing parameters I used:

Explicit -table parameter in settable
-------------------------------------
     var('db_av')=$db_gr;
     $db_av->settable(-table='availability');


Implicit -table parameter in settable
-------------------------------------
     var('db_av')=$db_gr;
     $db_av->settable('availability');


Original knop_database->settable
-------------------------------------
         (self -> 'table_realname') = @#table;
         (self -> 'db_connect') -> removeall(#table);
         (self -> 'db_connect') -> (insert: '-table' = @#table);


Corrected knop_database->settable
-------------------------------------
         (self -> 'table_realname') = #table;
         (self -> 'db_connect') -> removeall(#table);
         (self -> 'db_connect') -> (insert: '-table' = #table);

Explicit/Original permutation returns an error:

     Attempt to modify a frozen value. The value was
"availability" of type "string". (=)
     at: settable with params: -table='availability'

Implicit/Original works.
Explicit/Corrected works.
Implicit/Corrected works.

>Works like a charm. Due to speed issues I try not to create
>database objects until they're actually needed. And as few as
>possible. So no central database page declaring a bunch of
>unused database objects.

So how do you instantiate a db object?  In the page cfg file?

If so, why would you need to use settable?  I suppose it might
be needed if you use many tables for a module, or if you store
the db object in a user session and need to modify it.

I can see that creating db objects only when needed is good for
execution time.

>And since the documentation claims that copying a database object is
>faster than creating a new one that's what I do if I need more than
>one in parallel. If I can reuse the database object, that is don't
>need it for the original table any more, I just change the table.

I haven't done any speed testing.  But looking at the source
code, there is some code duplication between ->settable and
->oncreate.  The duplication requires a connection to the
datasource, so you won't save any time on this point.  The
unique code in ->oncreate appears to be triggered only with
optional flags.  I would assume that any time savings is negligible.

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>


--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

Johan Solve-2
At 04.09 -0800 2010-11-24, Steve Piercy - Web Site Builder wrote:
>I can see that creating db objects only when needed is good for execution time.

Instead of creating db objects on demand, we create them all at once and then cache them using the knop_cache tag. That way they won't be instantiated again for any new page loads for as long as the cache is valid. Instead they are restored (copied) from cache which is much more efficient than creating new objects.

As usual there are always more ways to skin a cat.

--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[hidden email]
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

stevepiercy
In reply to this post by Johan Solve-2
On 11/23/10 at 10:57 PM, [hidden email] (Johan Solve) pronounced:

>At 12.10 -0800 2010-11-23, Steve Piercy - Web Site Builder wrote:

>>And removing the references is required after all:
>>
>>(self -> 'table_realname') = #table;
>>(self -> 'db_connect') -> removeall(#table);
>>(self -> 'db_connect') -> (insert: '-table' = #table);
>>
>>Anyway, I'm still not clear about why it is necessary to copy
>>first, then set.  I mean, if you copy something, why would its
>>values not be frozen as well?
>
>The "frozen" error refers to the string that you pass in the
>-table parameter. Since a reference to the parameter value is
>stored internally, trying to modify it is the same as trying to
>modify a string, which you can't. A string is frozen by definition.
>
>Original code snippet:
>define_tag: 'settable', -description='...',
>-required='table', -type='string';
>...
>(self -> 'table_realname') = @#table;
>(self -> 'db_connect') -> removeall(#table);
>(self -> 'db_connect') -> (insert: '-table' = @#table);
>(self -> 'table_realname') = (table_realname: self -> 'database', #table);
>
>With this call:
>$db_av->settable(-table='availability');
>
>you're essentially trying to do this:
>'availability'=(table_realname: self -> 'database', 'availability')
>
>And I hope you now see where the "frozen" error is coming from.

Yes, that helps me understand most of it, but I'm missing a
piece.  I understand your explanation of why this fails:

         (self -> 'table_realname') = @#table;

But I don't understand why this works:

         (self -> 'table_realname') = #table;

I mean, if you cannot store a reference to a local (@#table),
then why can you store the local itself (#table)?

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>


--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

stevepiercy
In reply to this post by Johan Solve-2
On 11/24/10 at 1:57 PM, [hidden email] (Johan Solve) pronounced:

>At 04.09 -0800 2010-11-24, Steve Piercy - Web Site Builder wrote:
>>I can see that creating db objects only when needed is good for execution time.
>
>Instead of creating db objects on demand, we create them all at
>once and then cache them using the knop_cache tag. That way
>they won't be instantiated again for any new page loads for as
>long as the cache is valid. Instead they are restored (copied)
>from cache which is much more efficient than creating new objects.

I confess, I haven't taken the time to understand Knop's caching
mechanism.  So I did a little reading, and came up with a couple
of questions.

(1)  For database objects, would these code samples be correct?

// database used by public facing content management system
if(!knop_cachefetch(-type='knop_database',-name='site1_dcms'));
     var('dcms')=knop_database(
         -database='d',
         -table='cms',
         -username'u',
         -password='p',
         -keyfield='keyfield',
         -lockfield='lockfield');
     knop_cachestore(-type='knop_database', -name='site1_dcms');
/if;

// database used by a single authenticated user
if(!knop_cachefetch(-type='knop_database',-name=$sitename_username));
     var('duser')=knop_database(
         -database='d',
         -table='user',
         -username'u',
         -password='p',
         -keyfield='keyfield',
         -lockfield='lockfield');
     knop_cachestore(-type='knop_database',
-name=$sitename_username, -expires=$session_expires, -session=$session_name);
/if;

(2)  Are there any gotchas with knop's caching?

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>


--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

Johan Solve-2
In reply to this post by stevepiercy
At 05.37 -0800 2010-11-24, Steve Piercy - Web Site Builder wrote:
>But I don't understand why this works:
>
>        (self -> 'table_realname') = #table;
>
>I mean, if you cannot store a reference to a local (@#table), then why can you store the local itself (#table)?

(self -> 'table_realname') will contain a copy of the value in #table, instead of a reference to #table.



--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[hidden email]
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

Johan Solve-2
In reply to this post by stevepiercy
At 06.30 -0800 2010-11-24, Steve Piercy - Web Site Builder wrote:

>On 11/24/10 at 1:57 PM, [hidden email] (Johan Solve) pronounced:
>
>>At 04.09 -0800 2010-11-24, Steve Piercy - Web Site Builder wrote:
>>>I can see that creating db objects only when needed is good for execution time.
>>
>>Instead of creating db objects on demand, we create them all at once and then cache them using the knop_cache tag. That way they won't be instantiated again for any new page loads for as long as the cache is valid. Instead they are restored (copied) from cache which is much more efficient than creating new objects.
>
>I confess, I haven't taken the time to understand Knop's caching mechanism.  So I did a little reading, and came up with a couple of questions.
>
>(1)  For database objects, would these code samples be correct?
>
>// database used by public facing content management system
>if(!knop_cachefetch(-type='knop_database',-name='site1_dcms'));
>    var('dcms')=knop_database(
>        -database='d',
>        -table='cms',
>        -username'u',
>        -password='p',
>        -keyfield='keyfield',
>        -lockfield='lockfield');
>    knop_cachestore(-type='knop_database', -name='site1_dcms');
>/if;


Yes that looks right.


>// database used by a single authenticated user
>if(!knop_cachefetch(-type='knop_database',-name=$sitename_username));
>    var('duser')=knop_database(
>        -database='d',
>        -table='user',
>        -username'u',
>        -password='p',
>        -keyfield='keyfield',
>        -lockfield='lockfield');
>    knop_cachestore(-type='knop_database', -name=$sitename_username, -expires=$session_expires, -session=$session_name);
>/if;
>
>(2)  Are there any gotchas with knop's caching?

Storing objects in the session as in the second case can cause a bit of overhead and caching might hurt more than it helps. Avoid session storage of cache. Use a more unique cachename instead.


Caching is good. Burn once, serve many.
But it can be tricky to avoid stale data. I add a switch to the cache condition so I can easily reload cache data.
if($cache_refresh || !knop_cachefetch(-type='knop_database',-name='site1_dcms'));

Also consider taking advantage of the -maxage parameter for cache_fetch. It lets you set a cutoff timestamp (date type) for example last modification datetime of a table. Can be very useful in relevant cases.



--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[hidden email]
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: knop_database documentation clarification

list
In reply to this post by stevepiercy
24 nov 2010 kl. 22.09 skrev Steve Piercy - Web Site Builder:

>> $dBase -> settable('department_business_unit');
>
> Wait a minute!  Where is the named '-table' parameter?  Since that is the first (and only) parameter for this method, does it implicitly use its index instead of a named parameter?

Common knowledge, Steve. :-)

Here's an example:

define_tag('steve',
        -required = 'value'
        );

        return('Steve is a ' + #value);

/define_tag;

steve('nice guy');
'<br>';
steve(-value = 'guy that uses Lasso');

->
Steve is a nice guy
Steve is a guy that uses Lasso

HDB
Jolle

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
12