[std.database] at compile time

foobar foo at bar.com
Fri Oct 14 13:38:06 PDT 2011


Dmitry Olshansky Wrote:

> On 14.10.2011 19:13, foobar wrote:
> > Andrei Alexandrescu Wrote:
> >
> >> On 10/14/11 6:08 AM, Jacob Carlborg wrote:
> >>> On 2011-10-14 12:19, foobar wrote:
> >>>> Has anyone looked at Nemerle's design for this?
> >>>> They have an SQL macro which allows to write SQL such as:
> >>>>
> >>>> var employName = "FooBar"
> >>>> SQL (DBconn, "select * from employees where name = $employName");
> >>>>
> >>>> what that supposed to do is bind the variable(s) and it also validates
> >>>> the sql query with the database. This is all done at compile-time.
> >>>>
> >>>> My understanding is that D's compile-time features are powerful enough
> >>>> to implement this.
> >>>
> >>> You cannot connect to a database in D at compile time. You could some
> >>> form of validation and escape the query without connecting to the database.
> >>
> >> A little SQL interpreter can be written that figures out e.g. the names
> >> of the columns involved.
> >>
> >> Andrei
> >
> > The downsides with writing a separate SQL interpreter are:
> >
> > a) No connection to the DB means no way to validate the schema, e.g. the db might not even have a 'name' column in the employees table.
> 
> The upside is that you can at least rebuild your app when database is 
> down or compile it on a separate machine.
> 
> > b) No way to validate the SQL per the exact version the DB uses. E.g. LIMIT vs. TOP and also DB vendor specific extensions to SQL syntax.
> > c) NIH - implementing your own SQL interpreter when the DB vendor already provides it.
> >
> > oh, well, perhaps it would be possible with D3 once it supports proper macros. In any case, such a macro probably would be built atop the DB API currently being discussed.
> 
> 
> -- 
> Dmitry Olshansky

That's just silly, why would you use a validating SQL macro if you do not want (or don't have the environment set up) to validate the SQL? 


More information about the Digitalmars-d mailing list