当前位置: 首页>>代码示例>>PHP>>正文


PHP DB_DataObject::_is_null方法代码示例

本文整理汇总了PHP中DB_DataObject::_is_null方法的典型用法代码示例。如果您正苦于以下问题:PHP DB_DataObject::_is_null方法的具体用法?PHP DB_DataObject::_is_null怎么用?PHP DB_DataObject::_is_null使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DB_DataObject的用法示例。


在下文中一共展示了DB_DataObject::_is_null方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fromValue

 /**
  * standard set* implementation.
  *
  * takes data and uses it to set dates/strings etc.
  * normally called from __call..  
  *
  * Current supports
  *   date      = using (standard time format, or unixtimestamp).... so you could create a method :
  *               function setLastread($string) { $this->fromValue('lastread',strtotime($string)); }
  *
  *   time      = using strtotime 
  *   datetime  = using  same as date - accepts iso standard or unixtimestamp.
  *   string    = typecast only..
  * 
  * TODO: add formater:: eg. d/m/Y for date! ???
  *
  * @param   string       column of database
  * @param   mixed        value to assign
  *
  * @return   true| false     (False on error)
  * @access   public 
  * @see      DB_DataObject::_call
  */
 function fromValue($col, $value)
 {
     global $_DB_DATAOBJECT;
     $options = $_DB_DATAOBJECT['CONFIG'];
     $cols = $this->table();
     // dont know anything about this col..
     if (!isset($cols[$col])) {
         $this->{$col} = $value;
         return true;
     }
     //echo "FROM VALUE $col, {$cols[$col]}, $value\n";
     switch (true) {
         // set to null and column is can be null...
         case !($cols[$col] & DB_DATAOBJECT_NOTNULL) && DB_DataObject::_is_null($value, false):
         case is_object($value) && is_a($value, 'DB_DataObject_Cast'):
             $this->{$col} = $value;
             return true;
             // fail on setting null on a not null field..
         // fail on setting null on a not null field..
         case $cols[$col] & DB_DATAOBJECT_NOTNULL && DB_DataObject::_is_null($value, false):
             return false;
         case $cols[$col] & DB_DATAOBJECT_DATE && $cols[$col] & DB_DATAOBJECT_TIME:
             // empty values get set to '' (which is inserted/updated as NULl
             if (!$value) {
                 $this->{$col} = '';
             }
             if (is_numeric($value)) {
                 $this->{$col} = date('Y-m-d H:i:s', $value);
                 return true;
             }
             // eak... - no way to validate date time otherwise...
             $this->{$col} = (string) $value;
             return true;
         case $cols[$col] & DB_DATAOBJECT_DATE:
             // empty values get set to '' (which is inserted/updated as NULl
             if (!$value) {
                 $this->{$col} = '';
                 return true;
             }
             if (is_numeric($value)) {
                 $this->{$col} = date('Y-m-d', $value);
                 return true;
             }
             // try date!!!!
             require_once 'Date.php';
             $x = new Date($value);
             $this->{$col} = $x->format("%Y-%m-%d");
             return true;
         case $cols[$col] & DB_DATAOBJECT_TIME:
             // empty values get set to '' (which is inserted/updated as NULl
             if (!$value) {
                 $this->{$col} = '';
             }
             $guess = strtotime($value);
             if ($guess != -1) {
                 $this->{$col} = date('H:i:s', $guess);
                 return $return = true;
             }
             // otherwise an error in type...
             return false;
         case $cols[$col] & DB_DATAOBJECT_STR:
             $this->{$col} = (string) $value;
             return true;
             // todo : floats numerics and ints...
         // todo : floats numerics and ints...
         default:
             $this->{$col} = $value;
             return true;
     }
 }
开发者ID:bigpussy,项目名称:statusnet,代码行数:93,代码来源:DataObject.php

示例2: _update

 /**
  * Updates  current objects variables into the database
  * DB_DataObject fix to allow update of objects that were fetched from a join query.
  *
  */
 function _update($dataObject = false)
 {
     global $_DB_DATAOBJECT;
     // connect will load the config!
     $this->_connect();
     $original_query = $this->_query;
     $items = isset($_DB_DATAOBJECT['INI'][$this->_database][$this->__table]) ? $_DB_DATAOBJECT['INI'][$this->_database][$this->__table] : $this->table();
     // only apply update against sequence key if it is set?????
     $seq = $this->sequenceKey();
     if ($seq[0] !== false) {
         $keys = array($seq[0]);
         if (!isset($this->{$keys[0]}) && $dataObject !== true) {
             $this->raiseError("update: trying to perform an update without\n                        the key set, and argument to update is not\n                        DB_DATAOBJECT_WHEREADD_ONLY\n                    ", DB_DATAOBJECT_ERROR_INVALIDARGS);
             return false;
         }
     } else {
         $keys = $this->keys();
     }
     $pkName = $keys[0];
     $pkVal = $this->{$keys[0]};
     if (!$items) {
         $this->raiseError("update:No table definition for {$this->__table}", DB_DATAOBJECT_ERROR_INVALIDCONFIG);
         return false;
     }
     $datasaved = 1;
     $settings = '';
     $this->_connect();
     $DB =& $_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5];
     $dbtype = $DB->dsn["phptype"];
     $quoteIdentifiers = !empty($_DB_DATAOBJECT['CONFIG']['quote_identifiers']);
     $options = $_DB_DATAOBJECT['CONFIG'];
     $ignore_null = !isset($options['disable_null_strings']) || !is_string($options['disable_null_strings']) || strtolower($options['disable_null_strings']) !== 'full';
     foreach ($items as $k => $v) {
         if (!isset($this->{$k}) && $ignore_null) {
             continue;
         }
         // ignore stuff thats
         // dont write things that havent changed..
         if ($dataObject !== false && isset($dataObject->{$k}) && $dataObject->{$k} === $this->{$k}) {
             continue;
         }
         // - dont write keys to left.!!!
         if (in_array($k, $keys)) {
             continue;
         }
         // dont insert data into mysql timestamps
         // use query() if you really want to do this!!!!
         if ($v & DB_DATAOBJECT_MYSQLTIMESTAMP) {
             continue;
         }
         if ($settings) {
             $settings .= ', ';
         }
         $kSql = $quoteIdentifiers ? $DB->quoteIdentifier($k) : $k;
         if (is_a($this->{$k}, 'DB_DataObject_Cast')) {
             $value = $this->{$k}->toString($v, $DB);
             if (PEAR::isError($value)) {
                 $this->raiseError($value->getMessage(), DB_DATAOBJECT_ERROR_INVALIDARG);
                 return false;
             }
             $settings .= "{$kSql} = {$value} ";
             continue;
         }
         // special values ... at least null is handled...
         if (!($v & DB_DATAOBJECT_NOTNULL) && DB_DataObject::_is_null($this, $k)) {
             $settings .= "{$kSql} = NULL ";
             continue;
         }
         // DATE is empty... on a col. that can be null..
         // note: this may be usefull for time as well..
         if (!$this->{$k} && ($v & DB_DATAOBJECT_DATE || $v & DB_DATAOBJECT_TIME) && !($v & DB_DATAOBJECT_NOTNULL)) {
             $settings .= "{$kSql} = NULL ";
             continue;
         }
         if ($v & DB_DATAOBJECT_STR) {
             $settings .= "{$kSql} = " . $this->_quote((string) ($v & DB_DATAOBJECT_BOOL ? $this->{$k} === 'f' ? 0 : (int) (bool) $this->{$k} : $this->{$k})) . ' ';
             continue;
         }
         if (is_numeric($this->{$k})) {
             $settings .= "{$kSql} = {$this->{$k}} ";
             continue;
         }
         // at present we only cast to integers
         // - V2 may store additional data about float/int
         $settings .= "{$kSql} = " . intval($this->{$k}) . ' ';
     }
     if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
         $this->debug("got keys as " . serialize($keys), 3);
     }
     if ($dataObject !== true) {
         $this->_build_condition($items, $keys);
     } else {
         // prevent wiping out of data!
         if (empty($this->_query['condition'])) {
             $this->raiseError("update: global table update not available\n                        do \$do->whereAdd('1=1'); if you really want to do that.\n                    ", DB_DATAOBJECT_ERROR_INVALIDARGS);
//.........这里部分代码省略.........
开发者ID:demental,项目名称:m,代码行数:101,代码来源:Pluggable.php


注:本文中的DB_DataObject::_is_null方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。