示例#1
0
 public function getAllFields($tablename)
 {
     $cur = sqlrcur_alloc($this->_conn);
     $success = sqlrcur_sendQuery($cur, SQLHelper::createSafeSQL("select * from :table", array(":table" => $tablename)));
     sqlrcon_endSession($cur);
     if (!$success) {
         throw new DatasetException(sqlrcur_errorMessage($cur));
     }
     $fields = [];
     $colCount = sqlrcur_colCount($cur);
     for ($col = 0; $col < $colCount; $col++) {
         $fields[] = strtolower(sqlrcur_getColumnName($cur, $col));
     }
     sqlrcur_free($cur);
     return $fields;
 }
示例#2
0
 /**
  * @return bool
  */
 public function hasNext()
 {
     if (count($this->_rowBuffer) >= SQLRelayIterator::RECORD_BUFFER) {
         return true;
     } else {
         if (is_null($this->_cursor)) {
             return count($this->_rowBuffer) > 0;
         } else {
             if ($this->_currentRow < $this->count()) {
                 $sr = new SingleRow();
                 $colCount = sqlrcur_colCount($this->_cursor);
                 for ($col = 0; $col < $colCount; $col++) {
                     $fieldName = strtolower(sqlrcur_getColumnName($this->_cursor, $col));
                     $value = sqlrcur_getField($this->_cursor, $this->_currentRow, $col);
                     if (is_null($value)) {
                         $sr->addField($fieldName, "");
                     } elseif (is_object($value)) {
                         $sr->addField($fieldName, "[OBJECT]");
                     } else {
                         $value = AnyDataset::fixUTF8($value);
                         $sr->addField($fieldName, $value);
                     }
                 }
                 $this->_currentRow++;
                 // Enfileira o registo
                 array_push($this->_rowBuffer, $sr);
                 // Traz novos até encher o Buffer
                 if (count($this->_rowBuffer) < DBIterator::RECORD_BUFFER) {
                     $this->hasNext();
                 }
                 return true;
             } else {
                 sqlrcur_free($this->_cursor);
                 $this->_cursor = null;
                 return count($this->_rowBuffer) > 0;
             }
         }
     }
 }
示例#3
0
/**
 * Perform a DB Layer SQL query.
 *
 * This function returns values dependin on the input parameters and the result of the query.
 * It can return:
 *   false if there was an error,
 *   true if the query succeeded but did not generate any rows
 *   array of field values if it returned a single row and $single is true
 *   array of array of field values if it returned row(s) [stacked array]
 *
 * @access public
 * @param   string      SQL query to execute
 * @param   boolean     Toggle whether the expected result is a single row (TRUE) or multiple rows (FALSE). This affects whether the returned array is 1 or 2 dimensional!
 * @param   string      Result type of the array indexing. Can be one of "assoc" (associative), "num" (numerical), "both" (numerical and associative, default)
 * @param   boolean     If true, errors will be reported. If false, errors will be ignored.
 * @param   string      A possible array key name, so that you can control the multi-dimensional mapping of an array by the key column
 * @param   string      A possible array field name, so that you can control the multi-dimensional mapping of an array by the key column and the field value.
 * @param   boolean     If true, the executed SQL error is known to fail, and should be disregarded (errors can be ignroed on DUPLICATE INDEX queries and the likes)
 * @return  mixed       Returns the result of the SQL query, depending on the input parameters
 */
function generate_resultset($cursor, $result_type = 'sqlr_BOTH')
{
    $return_row = array();
    for ($r_row = 0, $max_r = sqlrcur_rowCount($cursor); $r_row < $max_r; $r_row++) {
        for ($r_col = 0, $max_rc = sqlrcur_colCount($cursor); $r_col < $max_rc; $r_col++) {
            if ($result_type == 'sqlr_ASSOC') {
                $return_row[sqlrcur_getColumnName($cursor, $r_col)] = sqlrcur_getField($cursor, $r_row, $r_col);
            } else {
                $return_row[$r_row][$r_col] = sqlrcur_getField($cursor, $r_row, $r_col);
                $return_row[$r_row][sqlrcur_getColumnName($cursor, $r_col)] = $return_row[$r_row][$r_col];
            }
        }
    }
    return $return_row;
}
function da_sql_field_name($fields, $num, $config)
{
    return sqlrcur_getColumnName($fields, $num);
}
 /**
  * Returns the name of the specified column
  *
  * @access public
  * @param  integer $iColumn
  * @return string
  */
 function showColumn($iColumn = 0)
 {
     return sqlrcur_getColumnName($this->curs_id, $iColumn);
 }