Can your programming language do this?
Piotr Szturmaj
bncrbme at jadamspam.pl
Tue Jan 25 08:36:38 PST 2011
Adam Ruppe wrote:
> string name;
> int id;
>
> db_statement.execute();
>
> while(db_statement.next(id, name)) {
> // the variables id and name are now filled in with the row
> }
That's nice too!
> But, a real database has a lot of constraints on top of that -
> field lengths, foreign keys, checks, and so on.
>
> I tried two approaches: one was magic. Add stuff based on the names
> and types, so assume "int id" is a primary key, for example.
>
> Didn't work in practice. What about a table with a primary key
> that spans two columns?
>
> So, then I tried adding a bunch of attributes and templates, but
> that felt like a buggy and incomplete SQL forced into D... didn't
> feel like natural SQL nor D.
>
>
>
> What approach did you take? I wonder if I didn't get anywhere because
> I'm just so set in my old ways!
Please read my messages in "D2 postgresql interface - Phobos2?" thread
(D.learn). There are examples of structs with arrays (postgres supports
them); primary, unique and foreign keys. I've also managed to generate
D's enums using CREATE TYPE in postgres :)
>
>> Maybe we could join our efforts and create kind of hybrid
>> DB library? :)
>
> Indeed. Is your code on the internet somewhere?
Not yet. First, I must clean it from some messed up code :) Then I plan
to publish it on github under Boost license.
More information about the Digitalmars-d
mailing list