In SQLite database how does one define a column default to be the current user?
+2
A:
Are you talking about the default value for the column? The only valid default values for SQLite are as follows:
The DEFAULT constraint specifies a default value to use when doing an INSERT. The value may be NULL, a string constant or a number. The default value may also be one of the special case-independant keywords CURRENT_TIME, CURRENT_DATE or CURRENT_TIMESTAMP.
Kyle Cronin
2009-02-10 02:47:59
actually not *entirely* true; I have a column declared as follows: "timestamp" TEXT DEFAULT (strftime('%Y-%m-%dT%H:%M','now', 'localtime')), which has a function value as default. Maybe this can be categorized as string constant?
polyglot
2009-02-10 04:22:29
+2
A:
SQLite does not have the concept of a user. You don't "log in" with a username/password when you connect to SQLite.
If you need the current operating system user, you should specify this as a string when you insert data from your application.
Bill Karwin
2009-02-10 02:49:14
+1
A:
Simply put: one doesn't. Intending to do so would mean your database has to be aware of the application state, which is kind of backwards.
Aram Verstegen
2009-02-10 02:49:33
I'm not sure of that. In most big businesses their internal audit departments demand extra columns in ever tables with details like last_edited_by, last_edited_at. I always make these columns default to current user and current datetime. Doing it any other way would just be plain hard work.
jussij
2009-02-10 03:27:27