4 ms·
Okay, here's some pseudocode that drives me nuts in every one of these SQL APIs. I have a Group and a list of names of persons. Group myGroup = "Groupia"
by Pxtl 11y ago
Okay, here's some pseudocode that drives me nuts in every one of these SQL APIs.
I have a Group and a list of names of persons.
Group myGroup = "Groupia"
Person[] myPersons = ["Foo", "Bar", "Baz"]
I want to use that to generate the following query:
SELECT *
FROM dbo.Person
WHERE name IN ('Foo', 'Bar', 'Baz')
AND GroupName = 'Groupia'
Every language that tries to do the printf-style approach sucks for this. In many of these cases these are OOP languages. How hard is it to provide an API that gives me concatenation-like semantics?
It would be easy to design an API to allow putting the parameter calculation with concatenation-like semantics but without the problems of concatenation. For example (using Pythonic multi-line strings):
query = new query()
query.Text = """
FROM dbo.Person
WHERE name IN (""" + query.ParamList(myPersons) + """)
AND GroupName = """ + query.Param(MyGroup) + """
"""
resultSet = Query.Execute()
or somesuch nonsense - easier still if you're using a language that has good support for string interpolation. No worrying about lining up your parameters with their placeholders in the string which is functionally illegible in a long query. Good, legible programming involves keeping things that are related close to each other, so good SQL generation would logically involve having parameter's meaning as close as possible to their usage. printf-like syntaxes fail at this.