Example #1
0
 private function executeQuery()
 {
     $return = false;
     if ($this->queryType == 'other') {
         if (mssql_query($this->query, $this->link) === true) {
             $return = true;
             $this->error = mssql_get_last_message();
         }
     } else {
         if ($result = mssql_query($this->query, $this->link)) {
             // Conteo de registros
             if ($this->queryType == 'insert' || $this->queryType == 'update' || $this->queryType == 'delete') {
                 $this->numRows = mssql_rows_affected($this->link);
                 $return = true;
             } else {
                 $this->numRows = mssql_num_rows($result);
                 $fetchType = MSSQL_NUM;
                 if ($this->queryReturn == 'assoc') {
                     $fetchType = MSSQL_ASSOC;
                 } elseif ($this->queryReturn == 'both') {
                     $fetchType = MSSQL_BOTH;
                 }
                 $return = array();
                 while ($row = mssql_fetch_array($result, $fetchType)) {
                     array_push($return, $row);
                 }
             }
             $this->error = mssql_get_last_message();
             mssql_free_result($result);
         } else {
             $this->error = mssql_get_last_message();
         }
     }
     return $return;
 }
Example #2
0
 function count_affected()
 {
     if (ANEWT_DATABASE_MSSQL_ROWS_AFFECTED_EXISTS) {
         return mssql_rows_affected($this->rs);
     } else {
         return $this->rowcount;
     }
 }
 protected function _doExec($query)
 {
     if (!mssql_select_db($this->profile['database'], $this->_connection)) {
         throw new jException('jelix~db.error.database.unknown', $this->profile['database']);
     }
     if ($qI = mssql_query($query, $this->_connection)) {
         return mssql_rows_affected($this->_connection);
     } else {
         throw new jException('jelix~db.error.query.bad', mssql_get_last_message());
     }
 }
Example #4
0
 /**
 	Does the mssql-dependent work of the execute method.
 
 	@param	$sQuery			The query to execute.
 	@return	weeSQLiteResult	A result set for SELECT queries.
 */
 protected function doQuery($sQuery)
 {
     // mssql_query triggers a warning when the query could not be executed.
     $m = @mssql_query($sQuery, $this->rLink);
     $m === false and burn('DatabaseException', sprintf(_WT("Failed to execute the query with the following error:\n%s"), mssql_get_last_message()));
     // Get it now since it can be wrong if numAffectedRows is called after getPKId
     $this->iNumAffectedRows = mssql_rows_affected($this->rLink);
     if ($m !== true) {
         return new weeMSSQLResult($m);
     }
 }
Example #5
0
 public function exec(&$statement)
 {
     if ($result = @mssql_query($statement, $this->link)) {
         if (is_resource($result)) {
             mssql_free_result($result);
             return 0;
         }
         return mssql_rows_affected($this->link);
     }
     return false;
 }
Example #6
0
 public function execute($sql, $bindParams = array(), $additionalParameters = array())
 {
     $sql = $this->bind($sql, $bindParams);
     if ($result = mssql_query($sql, $this->connection)) {
         $rows = array();
         if (is_resource($result)) {
             while ($row = mssql_fetch_assoc($result)) {
                 $rows[] = $row;
             }
             mssql_free_result($result);
             $this->affectedRows = 0;
         } else {
             $this->affectedRows = mssql_rows_affected($this->connection);
         }
         return empty($rows) ? null : $rows;
     } else {
         $this->executeError($sql);
     }
 }
Example #7
0
 /**
  * Return the number of affected rows
  * @return int
  */
 protected function affected_rows()
 {
     return @mssql_rows_affected($this->resConnection);
 }
 public function affected_rows($resource = null)
 {
     return mssql_rows_affected(is_resource($resource) ? $resouce : $this->getConnection());
 }
 protected function _affectedRows()
 {
     return mssql_rows_affected($this->connection);
 }
Example #10
0
 /**
  * (non-PHPdoc)
  *
  * @see Core_DB::execute()
  */
 public function execute($str)
 {
     $this->parse_query($str);
     if (!is_resource($this->link)) {
         $this->connect();
     }
     N('db_write', 1);
     G('queryStartTime');
     $result = mssql_query($this->query_str, $this->link);
     $this->debug();
     if (false === $result) {
         $this->error();
         return false;
     } else {
         $this->num_rows = mssql_rows_affected($this->link);
         $this->lastinsid = $this->mssql_insert_id();
         return $this->num_rows;
     }
 }
 /**
  * Return the number of rows affected by the previous operation.
  * @return int
  */
 public function affectedRows()
 {
     if ($this->mssql) {
         return mssql_rows_affected($this->dbConn);
     } else {
         return $this->lastAffectedRows;
     }
 }
Example #12
0
 function _post_query($query, $dbh)
 {
     ++$this->num_queries;
     // If there is an error then take note of it..
     if ($this->result == FALSE && ($this->last_error = mssql_get_last_message())) {
         $this->log_query($this->last_error);
         //var_dump($query);
         //var_dump($this->translation_changes);
         $this->print_error();
         return false;
     }
     if (defined('SAVEQUERIES') && SAVEQUERIES) {
         $this->queries[] = array($query, $this->timer_stop(), $this->get_caller());
     }
     if (preg_match("/^\\s*(insert|delete|update|replace) /i", $query)) {
         $this->rows_affected = mssql_rows_affected($dbh);
         // Take note of the insert_id
         if (preg_match("/^\\s*(insert|replace) /i", $query)) {
             $result = @mssql_fetch_object(@mssql_query("SELECT SCOPE_IDENTITY() AS ID"));
             $this->insert_id = $result->ID;
         }
         $return_val = $this->rows_affected;
     } else {
         $i = 0;
         while ($i < @mssql_num_fields($this->result)) {
             $field = @mssql_fetch_field($this->result, $i);
             $new_field = new stdClass();
             $new_field->name = $field->name;
             $new_field->table = $field->column_source;
             $new_field->def = null;
             $new_field->max_length = $field->max_length;
             $new_field->not_null = true;
             $new_field->primary_key = null;
             $new_field->unique_key = null;
             $new_field->multiple_key = null;
             $new_field->numeric = $field->numeric;
             $new_field->blob = null;
             $new_field->type = $field->type;
             if (isset($field->unsigned)) {
                 $new_field->unsigned = $field->unsigned;
             } else {
                 $new_field->unsigned = null;
             }
             $new_field->zerofill = null;
             $this->col_info[$i] = $new_field;
             $i++;
         }
         $num_rows = 0;
         while ($row = @mssql_fetch_object($this->result)) {
             $this->last_result[$num_rows] = $row;
             $num_rows++;
         }
         $this->last_result = $this->fix_results($this->last_result);
         // perform limit
         if (!empty($this->limit)) {
             $this->last_result = array_slice($this->last_result, $this->limit['from'], $this->limit['to']);
             $num_rows = count($this->last_result);
         }
         @mssql_free_result($this->result);
         // Log number of rows the query returned
         $this->num_rows = $num_rows;
         // Return number of rows selected
         $return_val = $this->num_rows;
     }
     $this->log_query();
     return $return_val;
 }
Example #13
0
 /**
  * 更新数据
  * @param string $table 表名
  * @param mixed $condition 要更新的where条件或者字符下标的条件数组
  * @param array $data 要更新的数据,字符下标的数组形式
  * @param array $pam 数字下标的数组,数组项依次替换$condition中的"?"参数
  * @return integer 成功返回受影响的行数,更新失败返回null
  */
 function update_entity($table, $condition = null, $data = array(), $pam = null)
 {
     $ssql = "update [{$table}] set ";
     $vars = array();
     $vals = array();
     $columns = $this->list_fields($table);
     foreach ($data as $k => $val) {
         if (in_array($k, $columns)) {
             $vars[] = "[{$k}]=@yYUc_SqL@ ";
             $vals[] = $val === null ? self::raw('null') : $val;
         }
     }
     $ssql .= implode(",", $vars);
     if (!empty($condition)) {
         if (is_string($condition)) {
             $condition = str_replace('?', '@yYUc_SqL@', $condition);
         }
         $whereres = $this->con_sql($condition, $pam);
         $ssql .= trim($whereres[0]);
         $pam = $whereres[1];
         if ($pam !== null) {
             $vals = array_merge($vals, $pam);
         }
     }
     if ($this->execute($ssql, $vals)) {
         return mssql_rows_affected($this->conn);
     }
     return null;
 }
Example #14
0
 public function affectedRows()
 {
     return mssql_rows_affected($this->linkID);
 }
 function getAffectedRowCount()
 {
     return mssql_rows_affected($this->connection->getConnectionId());
 }
Example #16
0
 /**
  * Returns the number of rows affected
  *
  * @param resource $result
  * @param resource $connection
  * @return mixed MDB2 Error Object or the number of rows affected
  * @access private
  */
 function _affectedRows($connection, $result = null)
 {
     if (is_null($connection)) {
         $connection = $this->getConnection();
         if (PEAR::isError($connection)) {
             return $connection;
         }
     }
     return @mssql_rows_affected($connection);
 }
Example #17
0
 private function myfetchAll($result)
 {
     if (mssql_rows_affected($this->myconnection) == -1) {
         return false;
     }
     if (!is_resource($result)) {
         return false;
     } else {
         while ($rows[] = mssql_fetch_array($result, MYSQL_ASSOC)) {
         }
         array_pop($rows);
         return $rows;
     }
 }
 function DbAffectedRows()
 {
     return @mssql_rows_affected($this->ConnectionID);
 }
Example #19
0
 /**
  * @see Connection::executeUpdate()
  */
 function executeUpdate($sql)
 {
     $this->lastQuery = $sql;
     if (!mssql_select_db($this->database, $this->dblink)) {
         throw new SQLException('No database selected');
     }
     $result = @mssql_query($sql, $this->dblink);
     if (!$result) {
         throw new SQLException('Could not execute update', mssql_get_last_message(), $sql);
     }
     return (int) mssql_rows_affected($this->dblink);
     // return $this->getUpdateCount();
 }
Example #20
0
 /**
  * @param unknown $query
  * @param unknown $connection
  * @return boolean|number
  */
 public function NonQuery($query)
 {
     $result = null;
     try {
         switch ($this->type) {
             case TSP_Settings::$database_mysql:
             case TSP_Settings::$database_mysqli:
                 mysqli_query(self::$connection, $query);
                 $result = mysqli_affected_rows(self::$connection);
                 break;
             case TSP_Settings::$database_mssql:
                 mssql_query($query, self::$connection);
                 $result = mssql_rows_affected(self::$connection);
                 break;
             default:
                 break;
         }
         if ($result == -1) {
             return false;
         }
         return $result;
     } catch (Exception $e) {
         throw new Exception("Error Occurred in " . __FUNCTION__ . ": " . $e->getMessage() . PHP_EOL);
     }
 }
Example #21
0
 public function countAffected()
 {
     return mssql_rows_affected($this->link);
 }
Example #22
0
 function affected_rows()
 {
     if (!$this->link_identifier) {
         return 0;
     }
     $num = mssql_rows_affected($this->link_identifier);
     // not sure what it returns one fail, test maybe ?
     return !$num || $num == -1 ? 0 : $num;
 }
Example #23
0
 /**
  * Return number of affected rows
  */
 function sql_affectedrows()
 {
     return $this->db_connect_id ? @mssql_rows_affected($this->db_connect_id) : false;
 }
Example #24
0
 /**
  * Tell the number of rows the last run query affected
  * 
  * @return integer
  */
 public function affected()
 {
     return mssql_rows_affected($this->_conn);
 }
Example #25
0
 /**
  * Returns number of affected rows in previous database operation. If no previous operation exists,
  * this returns false.
  *
  * @return integer Number of affected rows
  */
 function lastAffected()
 {
     if ($this->_result) {
         return mssql_rows_affected($this->connection);
     }
     return null;
 }
Example #26
0
File: mssql.php Project: vlki/dibi
 /**
  * Gets the number of affected rows by the last INSERT, UPDATE or DELETE query.
  * @return int|FALSE  number of rows or FALSE on error
  */
 public function getAffectedRows()
 {
     return mssql_rows_affected($this->connection);
 }
Example #27
0
 /**
  * 执行语句
  * @access public
  * @param string $str  sql指令
  * @return integer
  */
 public function execute($str)
 {
     $this->initConnect(true);
     if (!$this->_linkID) {
         return false;
     }
     $this->queryStr = $str;
     //释放前次的查询结果
     if ($this->queryID) {
         $this->free();
     }
     N('db_write', 1);
     // 记录开始执行时间
     G('queryStartTime');
     $result = mssql_query($str, $this->_linkID);
     $this->debug();
     if (false === $result) {
         $this->error();
         return false;
     } else {
         $this->numRows = mssql_rows_affected($this->_linkID);
         $this->lastInsID = $this->mssql_insert_id();
         return $this->numRows;
     }
 }
Example #28
0
 /**
  * Get the number of rows affected by the last write query
  */
 function affectedRows()
 {
     return mssql_rows_affected($this->mConn);
 }
Example #29
0
 /**
  * Affected Rows
  *
  * @access	public
  * @return	integer
  */
 function affected_rows()
 {
     return @mssql_rows_affected($this->conn_id);
 }
Example #30
0
 /**
  * Sets up the result variables.
  *
  * @param  resource  query result
  * @param  resource  database link
  * @param  boolean   return objects or arrays
  * @param  string    SQL query that was run
  */
 public function __construct($result, $link, $object = TRUE, $sql)
 {
     $this->result = $result;
     // If the query is a resource, it was a SELECT, SHOW, DESCRIBE, EXPLAIN query
     if (is_resource($result)) {
         $this->current_row = 0;
         $this->total_rows = mssql_num_rows($this->result);
         $this->fetch_type = $object === TRUE ? 'mssql_fetch_object' : 'mssql_fetch_array';
     } elseif (is_bool($result)) {
         if ($result == FALSE) {
             // SQL error
             throw new Kohana_Database_Exception('database.error', mssql_get_last_message($link) . ' - ' . $sql);
         } else {
             // Its an DELETE, INSERT, REPLACE, or UPDATE querys
             $last_id = mssql_query('SELECT @@IDENTITY AS last_id', $link);
             $result = mssql_fetch_assoc($last_id);
             $this->insert_id = $result['last_id'];
             $this->total_rows = mssql_rows_affected($link);
         }
     }
     // Set result type
     $this->result($object);
     // Store the SQL
     $this->sql = $sql;
 }