示例#1
0
文件: Field.php 项目: jasny/Q
 /**
  * Return the name of a field.
  *
  * @param int $flags  A DB::FIELDNAME_% constant and DB::WITH_ALIAS and DB::QUOTE_% options as binary set 
  * @return string
  */
 public function getName($flags = DB::FIELDNAME_FULL)
 {
     switch ($flags & 0xf) {
         case DB::FIELDNAME_NAME:
             return $flags & QUOTE_LOOSE || $flags & QUOTE_STRICT ? $this->parent->getConnection()->quoteIdentifier($this['name'], $flags) : $this['name'];
         case DB::FIELDNAME_FULL:
             return $flags & QUOTE_LOOSE || $flags & QUOTE_STRICT ? $this->parent->getConnection()->makeIdentifier($this['table'], $this['name'], $flags) : (isset($this['table']) ? $this['table'] . '.' . $this['name'] : $this['name']);
         case DB::FIELDNAME_COLUMN:
             return $this->parent->getConnection()->makeIdentifier($this['table'], $this['name_db'], $flags & DB::WITH_ALIAS && $this['name'] != $this['name_db'] ? $this['name'] : null, $flags);
         case DB::FIELDNAME_DB:
             return $this->parent->getConnection()->makeIdentifier($this['table_db'], $this['name_db'], $flags & DB::WITH_ALIAS && $this['name'] != $this['name_db'] ? $this['name'] : null);
     }
 }
示例#2
0
 /**
  * Run a query
  *
  * @param resource $connection DB Connection
  * @param string $sql
  * @throws Exception MySQL error
  */
 public function __construct($sql, $connection)
 {
     parent::__construct($sql);
     $this->connection = $connection;
     $resource = mysql_query($sql, $this->connection);
     if (false === $resource) {
         $this->throwError();
     } elseif (!is_bool($resource)) {
         $this->resource = $resource;
         $this->setNumberOfRows(mysql_num_rows($resource));
         $this->columns = $this->getColumnTypes();
     } else {
         $this->rowsAffected = mysql_affected_rows($this->connection);
         $this->lastId = mysql_insert_id($this->connection);
     }
 }
示例#3
0
 /**
  * Run a query
  *
  * @param string $sql
  * @param resource $connection DB Connection
  * @throws Exception MySQL error
  */
 public function __construct($sql, $connection)
 {
     parent::__construct($sql);
     $this->connection = $connection;
     $errorMessage = '';
     // Overwritten by sqlite_query
     $resource = sqlite_query($this->connection, $sql, SQLITE_ASSOC, $errorMessage);
     if (false === $resource) {
         throw new Exception('SQLite Error: ' . $errorMessage);
     } else {
         $this->resource = $resource;
         $this->setNumberOfRows(sqlite_num_rows($resource));
         $this->columns = $this->getColumnTypes();
         $this->rowsAffected = sqlite_changes($this->connection);
         $this->lastId = sqlite_last_insert_rowid($this->connection);
     }
 }
 /**
  *  Format the result of DB query into array
  *	
  *	(@see get_attribute)
  *	
  *	@private
  *	@param	DB_Result	$res		result of DB query
  *	@param	string		$origin		
  *	@return mixed				see above
  */
 function get_attrib_format_output(&$res, $origin)
 {
     if ($res->numRows() > 1) {
         $out = array('value' => array(), 'origin' => $origin);
         while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
             $out['value'][] = $row['value'];
         }
         return $out;
     }
     if ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
         return array('value' => $row['value'], 'origin' => $origin);
     }
     return null;
 }
示例#5
0
文件: Result.php 项目: jasny/Q
 /**
  * Class constructor
  *
  * @param Q\DB|Q\DB_Table $source
  * @param mysqli_result   $native     The native result object or resource
  * @param string          $statement  The query statement which created this result
  */
 function __construct($source, \mysqli_result $native, $statement)
 {
     parent::__construct($source, $native, $statement);
 }