Skip to main content
gamedev.net
🔒 Locked

[web] using current_user [mysql]

Started by NeoJigglypuff Jul 1, 2008 at 2:08 AM 1 replies 2.4k views
Original Post
NeoJigglypuff
NeoJigglypuff
Is it possible to set the current user as a default value for a table column? Something kind of like this:

create table CATEGORY (
     CATEGORY_ID          tinyint                        not null auto_increment,
     CATEGORY_NAME        char(100)                      null,
     ADDED_ON             timestamp                      null,
     ADDED_BY             char(20)                       null,
     LAST_EDITED_ON       timestamp                      not null default current_timestamp on update current_timestamp,
     LAST_EDITED_BY       char(20)                       not null default current_user,
	 
     constraint PK_CATEGORY primary key (CATEGORY_ID)
);
ruby-lang
ruby-lang
You can't set a function as a default value, the exception being current_timestamp, but you can simulate what you want with a stored procedure. Just remember current_user() returns the user specified in the db connection string, which in a web application probably isn't the same as the logic user.
NeoJigglypuff
NeoJigglypuff
Thanks. I just came from using iSQL, which uses "current_user" in a different way. I'll use a procedure then.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.