[CDBI] sql function as column
oj at defuturo.co.uk
Wed Feb 14 09:16:13 GMT 2007
Jason Bodnar wrote:
> I have a table with just two columns - id int auto_increment and name
> varchar(255). I'd like to have a third "virtual" column called code. The SQL
> for retrieving all three columns would be:
> select id, name, conv(id,10,36) as code from table where name = ?
> conv is a (possibly mysql-only) function that converts the first argument from
> the base second arg to base third arg. (In this case it converts the id from
> base 10 to base 36).
> Is there a way to do this with CDBI?
The first thing that comes to mind, is to do this with perl instead of
SQL, simply because I can think how that would be achieved with CDBI.
CDBI lets you have temporary columns (aren't stored; don't relate to an
SQL column). You could then use a select trigger to populate this column
whenever you retrieve a row from the database.
Alternativly, could you setup a view in MySQL, and have your CDBI class
use the view as its table.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 252 bytes
Desc: OpenPGP digital signature
Url : http://lists.digitalcraftsmen.net/pipermail/classdbi/attachments/20070214/0e90e0db/signature.pgp
More information about the ClassDBI