Query parameter values
Posted: 10.02.2009, 07:18
Hi there,
I need to find a mechanism to define filter criteria for queries. The query SQL will be stored as meta data, together with the filter criteria a user might need to toggle during run-time.
Since we already have parameters that we can use in TDataSet, my first attempt was to use this and simply extract the parameter names. This leaves me with two problems:
1. Identifying the field that the parameter is used for
2. Specifying values for the parameter during run-time
None of this is a problem when we're working with simple operators, such as 'where balance > :minbal' or 'where firstname = :fname'. However, when we start doing things such as 'where length in (:alength)', we run into problems.
The first issue (i.e. specifying the field associated with a parameter) can be solved with a few parsing exercises so I'm not overly concerned with that. However, how do I specify a parameter value for alength (integer) in the example above?. The filter should execute as something like 'where length in (1,3,5)', but how can I implement this? I've tried using the parameter's NativeStr property but don't get any query results. Param.Value and Param.AsString also don't work. I'm testing with Oracle and MySQL, but my solution should be generic across all databases...
Can this be done?
Ben
I need to find a mechanism to define filter criteria for queries. The query SQL will be stored as meta data, together with the filter criteria a user might need to toggle during run-time.
Since we already have parameters that we can use in TDataSet, my first attempt was to use this and simply extract the parameter names. This leaves me with two problems:
1. Identifying the field that the parameter is used for
2. Specifying values for the parameter during run-time
None of this is a problem when we're working with simple operators, such as 'where balance > :minbal' or 'where firstname = :fname'. However, when we start doing things such as 'where length in (:alength)', we run into problems.
The first issue (i.e. specifying the field associated with a parameter) can be solved with a few parsing exercises so I'm not overly concerned with that. However, how do I specify a parameter value for alength (integer) in the example above?. The filter should execute as something like 'where length in (1,3,5)', but how can I implement this? I've tried using the parameter's NativeStr property but don't get any query results. Param.Value and Param.AsString also don't work. I'm testing with Oracle and MySQL, but my solution should be generic across all databases...
Can this be done?
Ben