original_string: public function generatePK()
      {
          $format = $this->pkFormat;
          $pk     = $this->_properties['primary_key'];
          if (isset($pk[1]))
              throw new Exception(sprintf(self::E_Composit, get_called_class(), __FUNCTION__), 1);
  
          $pk     = array_shift($pk);
          if (!$pk)
              throw new Exception(sprintf(self::E_PrimaryKey, get_called_class()), 1);
  
          $last = (int) $this
              ->select(($format['serial']?
                  'right('.$pk.', '.$format['serial'].')':
                  $pk).' as last')
              ->order($pk.' desc')
              ->read(1)
              ->last;
  
          // compile prefix format
          if (preg_match('/\{(?<date>.+)\}/', $format['prefix'], $match))
              $newPK = preg_replace('/\{.+\}/', date($match['date']), $format['prefix']);
          else
              $newPK = $format['prefix'];
  
          $newPK .= trim(str_pad($last+1, $format['serial'], $format['prefix']?'0':' ', STR_PAD_LEFT));
  
          return $newPK;
      }
code: public function generatePK()
      {
          $format = $this->pkFormat;
          $pk     = $this->_properties['primary_key'];
          if (isset($pk[1]))
              throw new Exception(sprintf(self::E_Composit, get_called_class(), __FUNCTION__), 1);
  
          $pk     = array_shift($pk);
          if (!$pk)
              throw new Exception(sprintf(self::E_PrimaryKey, get_called_class()), 1);
  
          $last = (int) $this
              ->select(($format['serial']?
                  'right('.$pk.', '.$format['serial'].')':
                  $pk).' as last')
              ->order($pk.' desc')
              ->read(1)
              ->last;
  
          // compile prefix format
          if (preg_match('/\{(?<date>.+)\}/', $format['prefix'], $match))
              $newPK = preg_replace('/\{.+\}/', date($match['date']), $format['prefix']);
          else
              $newPK = $format['prefix'];
  
          $newPK .= trim(str_pad($last+1, $format['serial'], $format['prefix']?'0':' ', STR_PAD_LEFT));
  
          return $newPK;
      }
code_tokens: public function generatePK ( ) { $ format = $ this -> pkFormat ; $ pk = $ this -> _properties [ 'primary_key' ] ; if ( isset ( $ pk [ 1 ] ) ) throw new Exception ( sprintf ( self :: E_Composit , get_called_class ( ) , __FUNCTION__ ) , 1 ) ; $ pk = array_shift ( $ pk ) ; if ( ! $ pk ) throw new Exception ( sprintf ( self :: E_PrimaryKey , get_called_class ( ) ) , 1 ) ; $ last = ( int ) $ this -> select ( ( $ format [ 'serial' ] ? 'right(' . $ pk . ', ' . $ format [ 'serial' ] . ')' : $ pk ) . ' as last' ) -> order ( $ pk . ' desc' ) -> read ( 1 ) -> last ; // compile prefix format if ( preg_match ( '/\{(?<date>.+)\}/' , $ format [ 'prefix' ] , $ match ) ) $ newPK = preg_replace ( '/\{.+\}/' , date ( $ match [ 'date' ] ) , $ format [ 'prefix' ] ) ; else $ newPK = $ format [ 'prefix' ] ; $ newPK .= trim ( str_pad ( $ last + 1 , $ format [ 'serial' ] , $ format [ 'prefix' ] ? '0' : ' ' , STR_PAD_LEFT ) ) ; return $ newPK ; }
docstring: Generate PK only if pk count = 1
  @return string Next PK
docstring_tokens: Generate PK only if pk count = 1