On Tue, Jun 3, 2008 at 5:09 PM, Alex Katebi <[EMAIL PROTECTED]> wrote:

> It would be nice to be able to revert back to the default value for a
> column. I don't think SQLite support this right now.
> The closest thing I found is "pragma table_info(foo)". If you prepare this
> and then grab the dflt_value for your column.
> On Tue, May 20, 2008 at 2:33 PM, Jeff Hamilton <[EMAIL PROTECTED]> wrote:
>

I've been following this discussion and here's my $0.02: there are three
ways I can imagine going with this.

1.  Extend the API with a "sqlite_bind_default" function, and then modify
the VDBE to inject instructions that are the equivalent of "if
(value==usedefault) value=default" into INSERT statements

2.  Extend the API with a "sqlite_bind_default" function, which somehow does
this 'pragma table-Info(foo)'  and binds *that* value.

3.  Don't support it.  If people want to allow default values they have to
prepare multiple versions of INSERT statements.

#2 wouldn't actually work 100% without being insanely complicated; consider
columns with a default value derived from CURRENT_TIMESTAMP.  This leaves #1
and #3.

#1 is appealing because it enables certain scenarios a *lot* simpler to
maintain, but it also means that *every single application* has to pay the
penalty, in memory and extra CPU cycles, to allow them to specify defaults,
even if they have absolutely no intention of doing so.   There's something
about that on the SQLite site, but I can't find it... it boils down to "If
we implement this feature and document it, DRH has to support it *forever
after*."


I offer you an option #4 that came to me while I was writing this email:

CREATE TABLE Foo(fooName text, fooDate date default(current_timestamp),
fooLevel integer default(42));

INSERT INTO Foo (fooName, fooDate, fooLevel) values (?, ifnull(?,
current_timestamp), ifnull(?, 42));

If you want to get really fancy you can construct the above statement using
Alex's suggested "pragma table_info(Foo)" in order to find out what the
defaults are when you're preparing the query.

-- 
-- Stevie-O
Real programmers use COPY CON PROGRAM.EXE
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to