Esempio n. 1
0
 public function lastInsertId($name = '')
 {
     if ($result = sybase_query('SELECT @@IDENTITY', $this->link)) {
         $row = sybase_fetch_row($result);
         if ($row[0] === null) {
             return -1;
         }
         return $row[0];
     }
     return false;
 }
Esempio n. 2
0
 public function asArray()
 {
     $json = [];
     $i = 0;
     while ($row = sybase_fetch_row($this->result)) {
         foreach ($row as $_v) {
             $json[$i][] = iconv("cp936", "utf-8", $_v);
         }
         $i++;
     }
     return $json;
 }
Esempio n. 3
0
 /**
  * Fetch a row and insert the data into an existing array.
  *
  * Formating of the array and the data therein are configurable.
  * See DB_result::fetchInto() for more information.
  *
  * @param resource $result    query result identifier
  * @param array    $arr       (reference) array where data from the row
  *                            should be placed
  * @param int      $fetchmode how the resulting array should be indexed
  * @param int      $rownum    the row number to fetch
  *
  * @return mixed DB_OK on success, null when end of result set is
  *               reached or on failure
  *
  * @see DB_result::fetchInto()
  * @access private
  */
 function fetchInto($result, &$arr, $fetchmode, $rownum = null)
 {
     if ($rownum !== null) {
         if (!@sybase_data_seek($result, $rownum)) {
             return null;
         }
     }
     if ($fetchmode & DB_FETCHMODE_ASSOC) {
         if (function_exists('sybase_fetch_assoc')) {
             $arr = @sybase_fetch_assoc($result);
         } else {
             if ($arr = @sybase_fetch_array($result)) {
                 foreach ($arr as $key => $value) {
                     if (is_int($key)) {
                         unset($arr[$key]);
                     }
                 }
             }
         }
         if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
             $arr = array_change_key_case($arr, CASE_LOWER);
         }
     } else {
         $arr = @sybase_fetch_row($result);
     }
     if (!$arr) {
         // reported not work as seems that sybase_get_last_message()
         // always return a message here
         //if ($errmsg = @sybase_get_last_message()) {
         //    return $this->sybaseRaiseError($errmsg);
         //} else {
         return null;
         //}
     }
     if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
         $this->_rtrimArrayValues($arr);
     }
     if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
         $this->_convertNullArrayValuesToEmpty($arr);
     }
     return DB_OK;
 }
Esempio n. 4
0
 protected function _fetch_row()
 {
     return sybase_fetch_row($this->_result);
 }
Esempio n. 5
0
function sql_fetch_row(&$res, $nr = 0)
{
    global $dbtype;
    switch ($dbtype) {
        case "MySQL":
            $row = mysql_fetch_row($res);
            return $row;
            break;
        case "mSQL":
            $row = msql_fetch_row($res);
            return $row;
            break;
        case "postgres":
        case "postgres_local":
            if ($res->get_total_rows() > $res->get_fetched_rows()) {
                $row = pg_fetch_row($res->get_result(), $res->get_fetched_rows());
                $res->increment_fetched_rows();
                return $row;
            } else {
                return false;
            }
            break;
        case "ODBC":
        case "ODBC_Adabas":
            $row = array();
            $cols = odbc_fetch_into($res, $nr, $row);
            return $row;
            break;
        case "Interbase":
            $row = ibase_fetch_row($res);
            return $row;
            break;
        case "Sybase":
            $row = sybase_fetch_row($res);
            return $row;
            break;
        default:
            break;
    }
}
Esempio n. 6
0
 function fetchInto($result, &$ar, $fetchmode, $rownum = null)
 {
     if ($rownum !== null) {
         if (!sybase_data_seek($result, $rownum)) {
             return $this->raiseError();
         }
     }
     $ar = $fetchmode & DB_FETCHMODE_ASSOC ? @sybase_fetch_array($result) : @sybase_fetch_row($result);
     if (!$ar) {
         // reported not work as seems that sybase_get_last_message()
         // always return a message here
         //if ($errmsg = sybase_get_last_message()) {
         //    return $this->raiseError($errmsg);
         //} else {
         return null;
         //}
     }
     return DB_OK;
 }
Esempio n. 7
0
 /**
  * Returns the ID of the latest insert
  *	
  * @return  integer
  * @access  public
  * @author  Adam Greene <*****@*****.**>
  * @since   2004-12-10
  */
 function insert_id($table, $field)
 {
     $sql = "SELECT max({$field}) FROM {$table} ";
     $rs = sybase_query($sql, $this->conn);
     $row = sybase_fetch_row($rs);
     if (isset($row[0]) && $row[0] > 0) {
         return $row[0] + 1;
     }
     return 1;
 }
 function _fetch($ignore_fields = false)
 {
     if ($this->fetchMode == ADODB_FETCH_NUM) {
         $this->fields = @sybase_fetch_row($this->_queryID);
     } else {
         if ($this->fetchMode == ADODB_FETCH_ASSOC) {
             $this->fields = @sybase_fetch_row($this->_queryID);
             $this->fields = $this->GetRowAssoc(ADODB_CASE_ASSOC);
         } else {
             $this->fields = @sybase_fetch_array($this->_queryID);
         }
     }
     return is_array($this->fields);
 }
 function query($query)
 {
     //if flag to convert query from MySql syntax to Sybase syntax is true
     //convert the query
     if ($this->convertMySqlTosybaseQuery == true) {
         $query = $this->ConvertMySqlTosybase($query);
     }
     // Initialise return
     $return_val = 0;
     // Flush cached values..
     $this->flush();
     // For reg expressions
     $query = trim($query);
     // Log how the function was called
     $this->func_call = "\$db->query(\"{$query}\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     // Count how many queries there have been
     $this->num_queries++;
     // Use core file cache function
     if ($cache = $this->get_cache($query)) {
         return $cache;
     }
     // If there is no existing database connection then try to connect
     if (!isset($this->dbh) || !$this->dbh) {
         $this->connect($this->dbuser, $this->dbpassword, $this->dbhost);
         $this->select($this->dbname);
     }
     // Perform the query via std sybase_query function..
     $this->result = @sybase_query($query);
     // If there is an error then take note of it..
     if ($this->result == false) {
         $get_errorcodeSql = "SELECT @@ERROR as errorcode";
         $error_res = @sybase_query($get_errorcodeSql, $this->dbh);
         $errorCode = @sybase_result($error_res, 0, "errorcode");
         $get_errorMessageSql = "SELECT severity as errorSeverity, text as errorText FROM sys.messages  WHERE message_id = " . $errorCode;
         $errormessage_res = @sybase_query($get_errorMessageSql, $this->dbh);
         if ($errormessage_res) {
             $errorMessage_Row = @sybase_fetch_row($errormessage_res);
             $errorSeverity = $errorMessage_Row[0];
             $errorMessage = $errorMessage_Row[1];
         }
         $sqlError = "ErrorCode: " . $errorCode . " ### Error Severity: " . $errorSeverity . " ### Error Message: " . $errorMessage . " ### Query: " . $query;
         $is_insert = true;
         $this->register_error($sqlError);
         $this->show_errors ? trigger_error($sqlError, E_USER_WARNING) : null;
         return false;
     }
     // Query was an insert, delete, update, replace
     $is_insert = false;
     if (preg_match("/^(insert|delete|update|replace)\\s+/i", $query)) {
         $this->rows_affected = @sybase_rows_affected($this->dbh);
         // Take note of the insert_id
         if (preg_match("/^(insert|replace)\\s+/i", $query)) {
             $identityresultset = @sybase_query("select SCOPE_IDENTITY()");
             if ($identityresultset != false) {
                 $identityrow = @sybase_fetch_row($identityresultset);
                 $this->insert_id = $identityrow[0];
             }
         }
         // Return number of rows affected
         $return_val = $this->rows_affected;
     } else {
         // Take note of column info
         $i = 0;
         while ($i < @sybase_num_fields($this->result)) {
             $this->col_info[$i] = @sybase_fetch_field($this->result);
             $i++;
         }
         // Store Query Results
         $num_rows = 0;
         while ($row = @sybase_fetch_object($this->result)) {
             // Store relults as an objects within main array
             $this->last_result[$num_rows] = $row;
             $num_rows++;
         }
         @sybase_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;
     }
     // disk caching of queries
     $this->store_cache($query, $is_insert);
     // If debug ALL queries
     $this->trace || $this->debug_all ? $this->debug() : null;
     return $return_val;
 }
Esempio n. 10
0
 /**
  * Fetch the current row as enumerated array
  * @return array
  */
 protected function fetch_row()
 {
     return @sybase_fetch_row($this->resResult);
 }
Esempio n. 11
0
 /**
  * Gets the DBMS' native error code produced by the last query
  *
  * @return int  the DBMS' error code
  */
 function errorNative()
 {
     $res = @mssql_query('select @@ERROR as ErrorCode', $this->connection);
     if (!$res) {
         return DB_ERROR;
     }
     $row = @sybase_fetch_row($res);
     return $row[0];
 }
Esempio n. 12
0
 /**
  * Get Patron Fines
  *
  * This is responsible for retrieving all fines by a specific patron.
  *
  * @param array $patron The patron array from patronLogin
  *
  * @throws \VuFind\Exception\Date
  * @throws ILSException
  * @return mixed        Array of the patron's fines on success.
  */
 public function getMyFines($patron)
 {
     $aid = $patron['address_id_nr'];
     $iln = $patron['iln'];
     //$lang = $patron['lang'];
     $sql = "select o.ppn" . ", r.costs_code" . ", r.costs" . ", rtrim(convert(char(20),r.date_of_issue,104))" . ", rtrim(convert(char(20),r.date_of_creation,104))" . ", 'Overdue' as fines" . ", o.shorttitle" . " from requisition r, ous_copy_cache o, volume v" . " where r.address_id_nr=" . $aid . "" . " and r.iln=" . $iln . " and r.id_number=v.volume_number" . " and v.epn=o.epn" . " and r.iln=o.iln" . " and r.costs_code in (1, 2, 3, 4, 8)" . " union select id_number" . ", r.costs_code" . ", r.costs" . ", rtrim(convert(char(20),r.date_of_issue,104))" . ", rtrim(convert(char(20),r.date_of_creation,104))" . ", r.extra_information" . ", '' as zero" . " from requisition r" . " where r.address_id_nr=" . $aid . "" . " and r.costs_code not in (1, 2, 3, 4, 8)" . "";
     try {
         $result = [];
         $sqlStmt = sybase_query($sql);
         while ($row = sybase_fetch_row($sqlStmt)) {
             //$fine = $this->translate(('3'==$row[1])?'Overdue':'Dues');
             $fine = $this->picaRecode($row[5]);
             $amount = null == $row[2] ? 0 : $row[2] * 100;
             //$balance = (null==$row[3])?0:$row[3]*100;
             $checkout = substr($row[3], 0, 12);
             $duedate = substr($row[4], 0, 12);
             $title = $this->picaRecode(substr($row[6], 0, 12));
             $result[] = ['id' => $this->prfz($row[0]), 'amount' => $amount, 'balance' => $amount, 'checkout' => $checkout, 'duedate' => $duedate, 'fine' => $fine, 'title' => $title];
         }
         return $result;
     } catch (\Exception $e) {
         throw new ILSException($e->getMessage());
     }
     return [];
 }
 function FetchAllRows()
 {
     $retVal = array();
     $i = 0;
     // bump up if just ran query
     if ($this->cur == -1) {
         $this->cur = 0;
     }
     while ($a = @sybase_fetch_row($this->res)) {
         $this->cur++;
         $retVal[$i++] = $a;
     }
     return $retVal;
 }
Esempio n. 14
0
 /**
  * Fetches the next row from the current result set
  *
  * @return unknown
  */
 function fetchResult()
 {
     if ($row = sybase_fetch_row($this->results)) {
         $resultRow = array();
         $i = 0;
         foreach ($row as $index => $field) {
             list($table, $column) = $this->map[$index];
             $resultRow[$table][$column] = $row[$index];
             $i++;
         }
         return $resultRow;
     } else {
         return false;
     }
 }
 /**
  * Execute any statement
  *
  * @param   string sql
  * @param   bool buffered default TRUE
  * @return  rdbms.sybase.SybaseResultSet or TRUE if no resultset was created
  * @throws  rdbms.SQLException
  */
 protected function query0($sql, $buffered = TRUE)
 {
     if (!is_resource($this->handle)) {
         if (!($this->flags & DB_AUTOCONNECT)) {
             throw new SQLStateException('Not connected');
         }
         $c = $this->connect();
         // Check for subsequent connection errors
         if (FALSE === $c) {
             throw new SQLStateException('Previously failed to connect');
         }
     }
     if (!$buffered) {
         $result = @sybase_unbuffered_query($sql, $this->handle, FALSE);
     } else {
         if ($this->flags & DB_UNBUFFERED) {
             $result = @sybase_unbuffered_query($sql, $this->handle, $this->flags & DB_STORE_RESULT);
         } else {
             $result = @sybase_query($sql, $this->handle);
         }
     }
     if (FALSE === $result) {
         $message = 'Statement failed: ' . trim(sybase_get_last_message()) . ' @ ' . $this->dsn->getHost();
         if (!is_resource($error = sybase_query('select @@error', $this->handle))) {
             // The only case selecting @@error should fail is if we receive a
             // disconnect. We could also check on the warnings stack if we can
             // find the following:
             //
             // Sybase:  Client message:  Read from SQL server failed. (severity 78)
             //
             // but that seems a bit errorprone.
             throw new SQLConnectionClosedException($message, $sql);
         }
         $code = current(sybase_fetch_row($error));
         switch ($code) {
             case 1205:
                 // Deadlock
                 throw new SQLDeadlockException($message, $sql, $code);
             default:
                 // Other error
                 throw new SQLStatementFailedException($message, $sql, $code);
         }
     }
     return TRUE === $result ? $result : new SybaseResultSet($result, $this->tz);
 }
 function _fetch($ignore_fields = false)
 {
     if ($this->fetchMode == ADODB_FETCH_NUM) {
         $this->fields = @sybase_fetch_row($this->_queryID);
     } else {
         if ($this->fetchMode == ADODB_FETCH_ASSOC) {
             $this->fields = @sybase_fetch_assoc($this->_queryID);
             if (is_array($this->fields)) {
                 $this->fields = $this->GetRowAssoc();
                 return true;
             }
             return false;
         } else {
             $this->fields = @sybase_fetch_array($this->_queryID);
         }
     }
     if (is_array($this->fields)) {
         return true;
     }
     return false;
 }
Esempio n. 17
0
 protected function convertResource($resource)
 {
     $resourceType = get_resource_type($resource);
     switch ($resourceType) {
         #case 'dbm':
         #case 'dba':
         #case 'dbase':
         #case 'domxml attribute':
         #case 'domxml document':
         #case 'domxml node':
         case 'fbsql result':
             $rows = array();
             $indexType = $this->dbResultIndexType == 'ASSOC' ? FBSQL_ASSOC : FBSQL_NUM;
             while ($row = fbsql_fetch_array($resource, $indexType)) {
                 array_push($rows, $row);
             }
             return $rows;
             #case 'gd': #return base64
         #case 'gd': #return base64
         case 'msql query':
             $rows = array();
             $indexType = $this->dbResultIndexType == 'ASSOC' ? MSQL_ASSOC : MSQL_NUM;
             while ($row = msql_fetch_array($resource, $indexType)) {
                 array_push($rows, $row);
             }
             return $rows;
         case 'mssql result':
             $rows = array();
             $indexType = $this->dbResultIndexType == 'ASSOC' ? MSSQL_ASSOC : MSSQL_NUM;
             while ($row = mssql_fetch_array($resource, $indexType)) {
                 array_push($rows, $row);
             }
             return $rows;
         case 'mysql result':
             $rows = array();
             $indexType = $this->dbResultIndexType == 'ASSOC' ? MYSQL_ASSOC : MYSQL_NUM;
             while ($row = mysql_fetch_array($resource, $indexType)) {
                 array_push($rows, $row);
             }
             return $rows;
         case 'odbc result':
             $rows = array();
             if ($this->dbResultIndexType == 'ASSOC') {
                 while ($row = odbc_fetch_array($resource)) {
                     array_push($rows, $row);
                 }
             } else {
                 while ($row = odbc_fetch_row($resource)) {
                     array_push($rows, $row);
                 }
             }
             return $rows;
             #case 'pdf document':
         #case 'pdf document':
         case 'pgsql result':
             $rows = array();
             $indexType = $this->dbResultIndexType == 'ASSOC' ? PGSQL_ASSOC : PGSQL_NUM;
             while ($row = pg_fetch_array($resource, $indexType)) {
                 array_push($rows, $row);
             }
             return $rows;
         case 'stream':
             return stream_get_contents($resource);
         case 'sybase-db result':
         case 'sybase-ct result':
             $rows = array();
             if ($this->dbResultIndexType == 'ASSOC') {
                 while ($row = sybase_fetch_assoc($resource)) {
                     array_push($rows, $row);
                 }
             } else {
                 while ($row = sybase_fetch_row($resource)) {
                     array_push($rows, $row);
                 }
             }
             return $rows;
             #case 'xml':
         #case 'xml':
         default:
             trigger_error("Unable to return resource type '{$resourceType}'.");
     }
 }
 /**
  * Places a row from the result set into the given array
  *
  * Formating of the array and the data therein are configurable.
  * See DB_result::fetchInto() for more information.
  *
  * This method is not meant to be called directly.  Use
  * DB_result::fetchInto() instead.  It can't be declared "protected"
  * because DB_result is a separate object.
  *
  * @param resource $result    the query result resource
  * @param array    $arr       the referenced array to put the data in
  * @param int      $fetchmode how the resulting array should be indexed
  * @param int      $rownum    the row number to fetch (0 = first row)
  *
  * @return mixed  DB_OK on success, NULL when the end of a result set is
  *                 reached or on failure
  *
  * @see DB_result::fetchInto()
  */
 function fetchInto($result, &$arr, $fetchmode, $rownum = null)
 {
     if ($rownum !== null) {
         if (!@sybase_data_seek($result, $rownum)) {
             return null;
         }
     }
     if ($fetchmode & DB_FETCHMODE_ASSOC) {
         if (function_exists('sybase_fetch_assoc')) {
             $arr = @sybase_fetch_assoc($result);
         } else {
             if ($arr = @sybase_fetch_array($result)) {
                 foreach ($arr as $key => $value) {
                     if (is_int($key)) {
                         unset($arr[$key]);
                     }
                 }
             }
         }
         if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
             $arr = array_change_key_case($arr, CASE_LOWER);
         }
     } else {
         $arr = @sybase_fetch_row($result);
     }
     if (!$arr) {
         return null;
     }
     if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
         $this->_rtrimArrayValues($arr);
     }
     if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
         $this->_convertNullArrayValuesToEmpty($arr);
     }
     return DB_OK;
 }
Esempio n. 19
0
 public function fetchRow()
 {
     if (!empty($this->query)) {
         return sybase_fetch_row($this->query);
     } else {
         return 0;
     }
 }