Beispiel #1
0
/**
 * Get a single value from a table.
 *
 * @param string $sql an SQL statement expected to return a single value.
 * @return mixed the specified value, or false if an error occured.
 */
function get_field_sql($sql)
{
    global $CFG;
    /// Strip potential LIMIT uses arriving here, debugging them (MDL-7173)
    $newsql = preg_replace('/ LIMIT [0-9, ]+$/is', '', $sql);
    if ($newsql != $sql) {
        debugging('Incorrect use of LIMIT clause (not cross-db) in call to get_field_sql(): ' . s($sql), DEBUG_DEVELOPER);
        $sql = $newsql;
    }
    $rs = get_recordset_sql($sql, 0, 1);
    if ($rs && $rs->RecordCount() == 1) {
        /// DIRTY HACK to retrieve all the ' ' (1 space) fields converted back
        /// to '' (empty string) for Oracle. It's the only way to work with
        /// all those NOT NULL DEFAULT '' fields until we definetively delete them
        if ($CFG->dbfamily == 'oracle') {
            $value = reset($rs->fields);
            onespace2empty($value);
            return $value;
        }
        /// End of DIRTY HACK
        return reset($rs->fields);
    } else {
        return false;
    }
}
 /**
  * Get a single value from a table (allowing for the use of LIMIT clauses).
  *
  * @param   string  $sql         an SQL statement expected to return a single value
  *                               (with a limit clause calculated depending on the database type).
  * @param   int     $limitfrom   return a subset of records, starting at this point (optional).
  *
  * @return  mixed                the specified value, or false if an error occured.
  */
 function get_field_sql($sql, $limitfrom = 0)
 {
     global $CFG;
     //use the optional starting point
     $rs = get_recordset_sql($sql, $limitfrom, 1);
     if ($rs && $rs->RecordCount() == 1) {
         /// DIRTY HACK to retrieve all the ' ' (1 space) fields converted back
         /// to '' (empty string) for Oracle. It's the only way to work with
         /// all those NOT NULL DEFAULT '' fields until we definetively delete them
         if ($CFG->dbfamily == 'oracle') {
             $value = reset($rs->fields);
             onespace2empty($value);
             return $value;
         }
         /// End of DIRTY HACK
         return reset($rs->fields);
     } else {
         return false;
     }
 }