E
Eric Wilhelm
This is partly an SQL question but I'm also trying to find out if there is
a perl module that has already solved it. Searching CPAN, google, and
reading the DBI/DBD docs seems to indicate that this is just the status
quo.
I am new to SQL, but I'm shocked by the fact that there is no "set the
value of this column in this row" command. I can INSERT or UPDATE, but
first I must SELECT to see if the row already exists (unless I disable
some warnings, do with autocommit and just '$ins->(@vals) or
$upd->(@vals)', but this still requires me to write two SQL statements
which basically express the same desire and then prepare two statement
handles.
At best, it seems to double (or triple) the amount of SQL-related code,
but at worst, it inherently violates the "single point of truth" rule.
REPLACE is not a good solution, since the rest of the row's contents
should be left intact (but if it isn't there, we just want to create it
and get on with our lives.)
It seems like an UPDATE statement could easily enough be translated into
the required INSERT statement (but maybe I haven't thought forward far
enough in this idea.)
If anyone could give me a tip that would allow one "statement of intent"
to create whatever SQL statements are needed, that would be great.
Otherwise, tell me why this is crazy before I go write DBI:WIM
With all of the sql use via Perl and the tendency of Perl to make you
want to be consise, I would think that some kind of "make it so" function
would have been cooked up by now.
Thanks,
Eric
a perl module that has already solved it. Searching CPAN, google, and
reading the DBI/DBD docs seems to indicate that this is just the status
quo.
I am new to SQL, but I'm shocked by the fact that there is no "set the
value of this column in this row" command. I can INSERT or UPDATE, but
first I must SELECT to see if the row already exists (unless I disable
some warnings, do with autocommit and just '$ins->(@vals) or
$upd->(@vals)', but this still requires me to write two SQL statements
which basically express the same desire and then prepare two statement
handles.
At best, it seems to double (or triple) the amount of SQL-related code,
but at worst, it inherently violates the "single point of truth" rule.
REPLACE is not a good solution, since the rest of the row's contents
should be left intact (but if it isn't there, we just want to create it
and get on with our lives.)
It seems like an UPDATE statement could easily enough be translated into
the required INSERT statement (but maybe I haven't thought forward far
enough in this idea.)
If anyone could give me a tip that would allow one "statement of intent"
to create whatever SQL statements are needed, that would be great.
Otherwise, tell me why this is crazy before I go write DBI:WIM
With all of the sql use via Perl and the tendency of Perl to make you
want to be consise, I would think that some kind of "make it so" function
would have been cooked up by now.
Thanks,
Eric