All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
  Print view

new attribute: agxUUIDAttribute (for MySQL)
Author Message
PostPosted: Thu Jul 25, 2013 10:24 pm 
Regular
User avatar
Offline

Joined: Tue Oct 30, 2012 9:07 am
Posts: 128
Location: Italy
This attribute uses Mysql UUID for primary key instead of numeric auto increments.

I'm starting my own framework, so i've decided to release my unpublished ATK source code
under GPL2 license.

To contact me please visit http://www.badpenguin.org/follow-me


Code:
<?
/*
* @2010 by Antonio Gallo "AGX" - http://www.badpenguin.org/
* License: GPL
* Version: 1
*/

class agxUUIDAttribute extends atkAttribute
{
   private $uuid = NULL;

    public function __construct($name, $flags=0)
    {
      $flags = $flags | AF_READONLY;
        parent::__construct($name, $flags);
      $this->setForceInsert(true);
      $this->setForceUpdate(true);
      //only in badpenguin?
      $this->cache_uuid();
    }
   
   function cache_uuid() {      
      if ($this->uuid==NULL) {
         $db = &atkGetDb();
         $this->uuid = $db->getValue('SELECT UUID();');
         atkdebug('cache new UUID='. $this->uuid);
         $this->setInitialValue($this->uuid);
         return $this->uuid;
      }
      atkdebug('cache old UUID='. $this->uuid);
      return $this->uuid;
   }
   
    function initialValue()
    {
     atkdebug('UUID initiaValue() calling cache_uuid()' );
      return $this->cache_uuid();
    }

    function needsInsert($rec)
    {
      return true;
    }   
   
    function needsUpdate($rec)
    {
      return false;
    }   

   function dbFieldType()
    {
      return 'text';
    }
   
}


_________________
My best regards,

Antonio Gallo
Linux, PHP, Perl/Webmin Consultant
http://badpenguin.org
Join the ATK's Linkedin Group https://www.linkedin.com/groups/ATK-Framework-7446956


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group