TOPIC: Noob question
#605
Noob question 3 Years, 6 Months ago
I'm trying to learn from the User's Manual, but there's one question that I don't seem to be able to figure out on my own.

I want to write a function that includes a query, and I want one of the query parameters to be passed as a function argument.

I've been writing things like this:

Database("ensure my_file(my_key) key (my_key)")
find_record = function(k)
{
record = QueryFirst("my_file where my_key is k")
Print (record.my_key)
}
find_record("some_key")

and that gives me the error

query: select: nonexistent columns: (k)

What's the right way to do what I want?

Thanks --

-- Fred Goldrich
 
 
#606
Re:Noob question 3 Years, 6 Months ago
Hi Fred,

Welcome! The answer is pretty easy - once you know it :-)

record = QueryFirst("my_file where my_key is " $ Display(k))

Display will add quotes for string values (but not for numbers). '$' is string concatenation. Basically you are building the query string dynamically.

Hope that helps.
 
 
andrew
 
#607
Re:Noob question 3 Years, 6 Months ago
Andrew --

Thanks for your prompt and very helpful response.

It's great to get answers straight from the top!

-- Fred