Multiple query params w/ queryExecute()

83 views
Skip to first unread message

Nando Breiter

unread,
Feb 13, 2015, 10:51:16 AM2/13/15
to lu...@googlegroups.com
I'm trying to get the following to work:

public void function createSubscriber( struct subscriber ) {
var q = {};
q.subscriber = queryExecute( '
insert into subscriber ( 
subscriberId,
name,
email,
dateSubscribed,
isConfirmed,
isSubscribed
) values ( 
:subscriberId,
:name,
:email,
:dateSubscribed,
:isConfirmed,
:isSubscribed
)
' ,
{ subscriberId = { value='#createUUID()#', cfsqltype='cf_sql_varchar' } } ,
{ name = { value='#subscriber.name#', cfsqltype='cf_sql_varchar' } } ,
{ email = { value='#subscriber.email#', cfsqltype='cf_sql_varchar' } } ,
{ dateSubscribed = { value='#CreateODBCDate( Now() )#', cfsqltype='cf_sql_date' } } ,
{ isConfirmed = { value='0', cfsqltype='cf_sql_tinyint' } } ,
{ isSubscribed = { value='0', cfsqltype='cf_sql_tinyint' } } 
);
}

And am getting the error "no param with name [name] found", with the stack trace pointing to the param block.

I suspect I have the syntax wrong for multiple query params, but haven't found an example. Can someone point me in the right direction?

Thanks,

Nando


Aria Media Sagl
Via Rompada 40
6987 Caslano
Switzerland

+41 (0)91 600 9601
+41 (0)76 303 4477 cell
skype: ariamedia

Igal @ Lucee.org

unread,
Feb 13, 2015, 11:10:09 AM2/13/15
to lu...@googlegroups.com
there is a bug in the params parser, I don't remeber it off the top of my head but I think it has to do with the punctuation (comma) immediately after the param name (if you identify the bug please open a ticket for it).

try to put a space between the param names and the commas.

also, in script you don't have to use the quotes and pound signs everywhere, so


  { subscriberId = { value='#createUUID()#', cfsqltype='cf_sql_varchar' } } ,

can be turned into

  { subscriberId = { value=createUUID(), cfsqltype='cf_sql_varchar' } } ,

which will like give you a slightly better performance as well.

Igal Sapir
Lucee Core Developer
Lucee.org

--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/CAGHrs%3D8aGQjkQ2%3D2%3DNR4R21KN_xYF6OQD46p2XS1431j-O6cfQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Nando Breiter

unread,
Feb 13, 2015, 11:18:12 AM2/13/15
to lu...@googlegroups.com
Thanks Igal. I've made those changes ... and now I have it working:

  subscriberId = { value=createUUID(), cfsqltype='cf_sql_varchar' }  ,
  name = { value=subscriber.name, cfsqltype='cf_sql_varchar' } ,
  email = { value=subscriber.email, cfsqltype='cf_sql_varchar' } ,
  dateSubscribed = { value=CreateODBCDate( Now() ), cfsqltype='cf_sql_date' } ,
  isConfirmed = { value='0', cfsqltype='cf_sql_tinyint' } ,
  isSubscribed = { value='0', cfsqltype='cf_sql_tinyint' } 

I had too many curly braces, trying to create a list of structs, when it should be a nested struct.



Aria Media Sagl
Via Rompada 40
6987 Caslano
Switzerland

+41 (0)91 600 9601
+41 (0)76 303 4477 cell
skype: ariamedia

Nando Breiter

unread,
Feb 13, 2015, 11:23:47 AM2/13/15
to lu...@googlegroups.com
And this also works:

  subscriberId : { value:createUUID(), cfsqltype:'cf_sql_varchar' }  ,
  name : { value:subscriber.name, cfsqltype:'cf_sql_varchar' } ,
  email : { value:subscriber.email, cfsqltype:'cf_sql_varchar' } ,
  dateSubscribed : { value:CreateODBCDate( Now() ), cfsqltype:'cf_sql_date' } ,
  isConfirmed : { value:'0', cfsqltype:'cf_sql_tinyint' } ,
  isSubscribed : { value:'0', cfsqltype:'cf_sql_tinyint' } 

which I find cleaner somehow. :-)



Aria Media Sagl
Via Rompada 40
6987 Caslano
Switzerland

+41 (0)91 600 9601
+41 (0)76 303 4477 cell
skype: ariamedia

Igal @ Lucee.org

unread,
Feb 13, 2015, 11:42:01 AM2/13/15
to lu...@googlegroups.com
yes, I prefer the colon separator in Structs too.  didn't point it out cause I figured that's your coding style and I didn't want to be "picky".

you can remove the single quotes from the '0' values as well.


Igal Sapir
Lucee Core Developer
Lucee.org

Reply all
Reply to author
Forward
0 new messages