Using array for knop_database objects not working

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

Using array for knop_database objects not working

Jolle Carlestam-2
I wanted to be smart and save some code rows by first creating an  
array and then use that when creating knop_database objects but that  
failed.

This works:
var: 'db_jina_webpage' = (knop_database:
        -database = 'jina_test',
        -username = adminUser,
        -password = adminUserpw,
        -keyfield = 'rcrdNo',
        -lockfield = 'rcrdLock',
        -table='jina_webpage');

This doesn't
var: 'jina_dbCommon' = (:
        -database = 'jina_test',
        -username = jn_adminUser,
        -password = jn_adminUserpw,
        -keyfield = 'rcrdNo',
        -lockfield = 'rcrdLock');
var: 'db_jina_webpgprtlink' = (knop_database: $jina_dbCommon, -
table='jina_webpgprtlink');
var: 'db_jina_websnippet' = (knop_database: $jina_dbCommon, -
table='jina_websnippet');

Error Message:
The specified database was not found.
at: oncreate with params: array: (pair: (-database)=(jina_test)),  
(pair: (-username)=(*****)), (pair: (-password)=(*****)), (pair: (-
keyfield)=(rcrdNo)), (pair: (-lockfield)=(rcrdLock)), -
table='jina_webpgprtlink'
at: /_config/cfg__global.inc on line: 29 at position: 32

The idea was that since I'm creating several knop_database objects  
all using the same info except for table this would be easier. Is  
this a limitation easy to work around or something to do with how a  
ctype expects params?

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://lists.montania.se/Lists/knop/
(log in with your email and ConfirmationID as password, send message to
<[hidden email]> to get that ID)
Project homepage http://montania.se/projects/knop/
AIM chatroom knop aim:gochat?roomname=knop


Reply | Threaded
Open this post in threaded view
|

Re: Using array for knop_database objects not working

Johan Solve-2
At 18.44 +0100 2007-03-08, [hidden email] wrote:
>The idea was that since I'm creating several knop_database objects all using the same info except for table this would be easier. Is this a limitation easy to work around or something to do with how a ctype expects params?

Ctags (or ctype member tags) don't automatically recognize an array as a prebuilt set of parameters.
The way inlines allow this is a special case (extremely convenient - in fact much of Knop relies on that feature).

I've been thinking briefly about if this would be easy to implement, and maybe it isn't so hard.

I'm thinking to have the ctag iterate through the params, and if it comes across an array as unnamed parameter, it would merge it with the params, to "flatten" the array into the params so to speak.
It would probably also need to create locals for any named params in the array since the autocreation would not happen. Would those locals be copies or references? I don't think there's a way to figure out from the tag definition if a parameter of a custom tag has the -copy flag set or not.
Now, how to handle this in the most efficient manner? I don't think it would be wise to merge with the params while iterating it, it would probably be to pull the rug you're standing on, so maybe by working on a copy of the params array and after iterating and merging, copy the modified params copy back over the original params.
Another problem would be how to handle assignment of locals that have already been autoassigned by a normal named param (an override situation). Those would need to be de-referenced before assigned to the new value to not attempt to alter the referenced value from the original param...

Hmm, an interesting challenge...

Has anyone played with this?


-- Just chatted a bit with Kyle about this and in his view this is no easy thing, but I'll play with it anyway and see what I come up with.

--
     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://lists.montania.se/Lists/knop/
(log in with your email and ConfirmationID as password, send message to
<[hidden email]> to get that ID)
Project homepage http://montania.se/projects/knop/
AIM chatroom knop aim:gochat?roomname=knop

Reply | Threaded
Open this post in threaded view
|

Re: Using array for knop_database objects not working

Johan Solve-2
In reply to this post by Jolle Carlestam-2
At 22.35 +0100 2007-03-08, Johan Solve wrote:
>Hmm, an interesting challenge...

Here's a proof of concept. Not perfect, but seems to work.

define_tag: 'testtag';
        local: 'param', 'element';
        // loop until we reach the last param element (the params array will possibly grow while looping)
        while: loop_count < (params -> size);
                #param = @(params -> (get: loop_count));
                if: #param -> type =='array';
                        // we want to merge the array with the rest of the params
                        // but first we want to auto-assign locals for the keywords in the array. We will not override any existing locals.
                        iterate: #param, #element;
                                if: #element -> (isa: 'pair') && #element -> name -> (beginswith: '-') && !(local_defined: (#element->name - '-'));
                                        // there is no point in creating references here since they will be copied when the array is merged later
                                        local: (#element->name - '-') = (#element->value);
                                /if;
                        /iterate;
                        // merge the array into the params at the right position (this will kill any reference)
                        params -> (merge: #param, loop_count);
                        // replace the array with null so we know we can delete it later
                        #param=null;
                /if;
        /while;
        // remove all ex arrays that we have merged into the params array
        params -> (removeall: null);
        // show what params we saw
        return: @(params -> (join: '<br>'));
/define_tag;

testtag: -name='Nisse Hult',
        (array: -address='home', -phone='124'),
        -more='even more',
        (array: -page=1, -table='test'),
        -mode='sql';


--
     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://lists.montania.se/Lists/knop/
(log in with your email and ConfirmationID as password, send message to
<[hidden email]> to get that ID)
Project homepage http://montania.se/projects/knop/
AIM chatroom knop aim:gochat?roomname=knop