Ejemplo n.º 1
0
 function &loadCurrent($columns = null, $loadText = true, $loadBlobs = false, $loadPasswords = false)
 {
     $app =& Dataface_Application::getInstance();
     $false = false;
     // boolean placeholders for values needing to be returned by reference
     $true = true;
     if ($this->_currentRecord === null) {
         //require_once 'Dataface/IO.php';
         //$io = new Dataface_IO($this->_table->tablename);
         //$query = array_merge( $this->_query, array('-skip'=>$this->_data['cursor'], '-limit'=>1) );
         $this->_currentRecord = new Dataface_Record($this->_table->tablename, array());
         //$io->read($query, $this->_currentRecord);
     }
     //return $this->_currentRecord;
     $unloaded = array();
     $fields =& $this->_table->fields(false, true);
     if ($columns === null) {
         $names = array_keys($fields);
     } else {
         $names = $columns;
     }
     foreach ($names as $name) {
         if (!$this->_currentRecord->isLoaded($name)) {
             if (!$loadText and $this->_table->isText($name)) {
                 continue;
             }
             if (!$loadBlobs and $this->_table->isBlob($name)) {
                 continue;
             }
             if (!$loadPasswords and $this->_table->isPassword($name)) {
                 continue;
             }
             $unloaded[] = $name;
         }
     }
     if (sizeof($unloaded) > 0) {
         $query = array_merge($this->_query, array('-skip' => $this->_data['cursor'], '-limit' => 1));
         $builder = new Dataface_QueryBuilder($this->_tablename, $query);
         $builder->selectMetaData = true;
         $builder->_omitBlobs = false;
         $sql = $builder->select($unloaded);
         //echo $sql;
         if (PEAR::isError($sql)) {
             throw new Exception($sql->toString(), E_USER_ERROR);
         }
         //echo $sql;
         $res = $this->dbObj->query($sql, $this->_db, null, true);
         if (!$res and !is_array($res)) {
             $app->refreshSchemas($this->_table->tablename);
             $res = $this->dbObj->query($sql, $this->_db, null, true);
             if (!$res and !is_array($res)) {
                 error_log(df_translate('scripts.Dataface.QueryTool.loadCurrent.ERROR_COULD_NOT_LOAD_CURRENT_RECORD', "Error: Could not load current record: ") . xf_db_error($this->_db) . "\n{$sql}");
                 throw new Exception("Failed to load current record due to an SQL error");
             }
         }
         if (count($res) <= 0) {
             return $false;
         }
         $row = $res[0];
         //xf_db_fetch_assoc($res);
         //@xf_db_free_result($row);
         if (!isset($this->_currentRecord)) {
             $this->_currentRecord = new Dataface_Record($this->_table->tablename, $row);
         } else {
             $this->_currentRecord->setValues($row);
         }
         //$this->_table->setValues($row);
         //$this->_table->setSnapshot();
         //$this->_table->deserialize();
     }
     return $this->_currentRecord;
 }
Ejemplo n.º 2
0
 /**
  * Returns an array of history ids of history records that match the 
  * given query.
  */
 function findMatchingSnapshots($record, $query, $idsOnly = true)
 {
     $app =& Dataface_Application::getInstance();
     $htablename = $record->_table->tablename . '__history';
     if (!Dataface_Table::tableExists($htablename)) {
         return array();
     }
     $keys = $record->strvals(array_keys($record->_table->keys()));
     foreach ($keys as $key => $val) {
         $query[$key] = '=' . $val;
     }
     if ($idsOnly) {
         $qbuilder = new Dataface_QueryBuilder($htablename, $query);
         $sql = $qbuilder->select(array('history__id'), $query);
         $res = xf_db_query($sql, df_db());
         $ids = array();
         while ($row = xf_db_fetch_row($res)) {
             $ids[] = $row[0];
         }
         @xf_db_free_result($res);
         return $ids;
     } else {
         return df_get_records_array($htablename, $query);
     }
 }
Ejemplo n.º 3
0
 function test_query_builder_select_with_meta_data()
 {
     $builder = new Dataface_QueryBuilder('Profiles');
     $builder->selectMetaData = true;
     $this->assertEquals('SELECT length(`Profiles`.`id`) as `__id_length`,`Profiles`.`id`,length(`Profiles`.`fname`) as `__fname_length`,`Profiles`.`fname`,length(`Profiles`.`lname`) as `__lname_length`,`Profiles`.`lname`,length(`Profiles`.`title`) as `__title_length`,`Profiles`.`title`,length(`Profiles`.`description`) as `__description_length`,`Profiles`.`description`,length(`Profiles`.`dob`) as `__dob_length`,`Profiles`.`dob`,length(`Profiles`.`phone1`) as `__phone1_length`,`Profiles`.`phone1`,length(`Profiles`.`phone2`) as `__phone2_length`,`Profiles`.`phone2`,length(`Profiles`.`fax`) as `__fax_length`,`Profiles`.`fax`,length(`Profiles`.`email`) as `__email_length`,`Profiles`.`email`,length(`Profiles`.`datecreated`) as `__datecreated_length`,`Profiles`.`datecreated`,length(`Profiles`.`lastmodified`) as `__lastmodified_length`,`Profiles`.`lastmodified`,length(`Profiles`.`favtime`) as `__favtime_length`,`Profiles`.`favtime`,length(`Profiles`.`lastlogin`) as `__lastlogin_length`,`Profiles`.`lastlogin`,length(`Profiles`.`photo`) as `__photo_length`,length(`Profiles`.`thumbnail`) as `__thumbnail_length`,length(`Profiles`.`photo_mimetype`) as `__photo_mimetype_length`,`Profiles`.`photo_mimetype`,length(`Profiles`.`tablefield`) as `__tablefield_length`,`Profiles`.`tablefield` FROM `Profiles`', $builder->select());
 }
Ejemplo n.º 4
0
Archivo: IO.php Proyecto: promoso/HVAC
 /**
  * Reads result of query into the table.
  *
  * @param mixed $query Either an array of query parameters or a record id string
  *			identifying a record to load.
  *
  * @param &$record The record object into which to load our results.
  *
  * @param string $tablename An optional table name from which the record could be read.
  *				For example, a record may be read form an import table rather than
  *				the real table. (or a deleted table).
  *
  */
 function read($query = '', &$record, $tablename = null)
 {
     $app =& Dataface_Application::getInstance();
     if (!is_a($record, "Dataface_Record")) {
         trigger_error(df_translate('scripts.Dataface.IO.read.ERROR_PARAMETER_2', "Dataface_IO::read() requires second parameter to be of type 'Dataface_Record' but received '" . get_class($record) . "\n<br>", array('class' => get_class($record))) . Dataface_Error::printStackTrace(), E_USER_ERROR);
     }
     if (is_string($query) and !empty($query)) {
         // If the query is actually a record id string, then we convert it
         // to a normal query.
         $query = $this->recordid2query($query);
     }
     if ($tablename === null and $this->_altTablename !== null) {
         $tablename = $this->_altTablename;
     }
     $qb = new Dataface_QueryBuilder($this->_table->tablename);
     $qb->selectMetaData = true;
     $query['-limit'] = 1;
     if (@$query['-cursor'] > 0) {
         $query['-skip'] = $query['-cursor'];
     }
     $sql = $qb->select('', $query, false, $this->tablename($tablename));
     $res = $this->dbObj->query($sql, $this->_table->db, $this->lang, true);
     if ((!is_array($res) and !$res) || PEAR::isError($res)) {
         $app->refreshSchemas($this->_table->tablename);
         $res = $this->dbObj->query($sql, $this->_table->db, $this->lang, true);
         if ((!is_array($res) and !$res) || PEAR::isError($res)) {
             if (PEAR::isError($res)) {
                 return $res;
             }
             return PEAR::raiseError(Dataface_LanguageTool::translate("Error reading record", "Error reading table '" . $this->_table->tablename . "' from the database: " . mysql_error($this->_table->db) . " on line " . __LINE__ . " of file " . __FILE__ . ". \nSQL used was '{$sql}'.", array('table' => $this->_table->tablename, 'mysql_error' => mysql_error(), 'line' => __LINE__, 'file' => __FILE__, 'sql' => $sql)), DATAFACE_E_READ_FAILED);
         }
     }
     //if ( mysql_num_rows($res) == 0 ){
     if (count($res) == 0) {
         return PEAR::raiseError(Dataface_LanguageTool::translate("No records found", "Record for table '" . $this->_table->tablename . "' could not be found.", array('table' => $this->_table->tablename, 'sql' => $sql)), DATAFACE_E_READ_FAILED);
     }
     //$row = mysql_fetch_assoc($res);
     $row = $res[0];
     //mysql_free_result($res);
     $record->setValues($row);
     $record->setSnapshot();
     // clear all flags that may have been previously set to indicate that the data is old or needs to be updated.
 }
Ejemplo n.º 5
0
 function display()
 {
     $this->_build();
     $showform = true;
     $b = new Dataface_QueryBuilder($this->_tablename, $this->_query);
     if (isset($this->_query['-delete-one'])) {
         $q = array('-skip' => $this->_query['-cursor'], '-limit' => 1);
         $sql = $b->select('', $q);
         $res = xf_db_query($sql, $this->_db);
         if (!$res) {
             throw new Exception(df_translate('scripts.Dataface.DeleteForm._build.ERROR_TRYING_TO_FETCH', "Error trying to fetch element to be deleted.: ") . xf_db_error($this->_db), E_USER_ERROR);
         }
         if (xf_db_num_rows($res) == 0) {
             $msg = df_translate('scripts.Dataface.DeleteForm._build.ERROR_NO_RECORD_SELECTED', "No record is currently selected so no record can be deleted.");
             $showform = false;
         } else {
             $row = xf_db_fetch_array($res);
             $rowRec = new Dataface_Record($this->_tablename, $row);
             $displayCol = $rowRec->getTitle();
             $msg = df_translate('scripts.Dataface.DeleteForm.display.ARE_YOU_SURE', "Are you sure you want to delete this record: &quot;{$displayCol}&quot;?", array('displayCol' => $displayCol));
         }
     } else {
         if (isset($this->_query['-delete-found'])) {
             $q = $b->select_num_rows();
             $res = xf_db_query($q, $this->_db);
             if (!$res) {
                 throw new Exception(df_translate('scripts.Dataface.DeleteForm.display.ERROR_ESTIMATING', "Error estimating number of rows that will be deleted: ") . xf_db_error($this->_db), E_USER_ERROR);
             }
             list($num) = xf_db_fetch_row($res);
             if ($num <= 0) {
                 $msg = df_translate('scripts.Dataface.DeleteForm.display.ERROR_NO_RECORDS_FOUND', "There are no records in the current found set so no records can be deleted.");
                 $showform = false;
             } else {
                 $msg = df_translate('scripts.Dataface.DeleteForm.display.ARE_YOU_SURE_MULTIPLE', "Are you sure you want to delete the found records.  {$num} records will be deleted.", array('num' => $num));
             }
         } else {
             $msg = df_translate('scripts.Dataface.DeleteForm.display.ERROR_GET_VARS', "Error: You must specify either '-delete-one' or '-delete-found' in GET vars.");
             $showform = false;
         }
     }
     if ($showform) {
         ob_start();
         parent::display();
         $form = ob_get_contents();
         ob_end_clean();
     } else {
         $form = '';
     }
     $context = array('msg' => $msg, 'form' => $form);
     import('Dataface/SkinTool.php');
     $skinTool =& Dataface_SkinTool::getInstance();
     //$smarty = new Smarty;
     //$smarty->template_dir = $GLOBALS['Dataface_Globals_Templates'];
     //$smarty->compile_dir = $GLOBALS['Dataface_Globals_Templates_c'];
     //$smarty->assign($context);
     //$smarty->display('Dataface_DeleteForm.html');
     $skinTool->display($context, 'Dataface_DeleteForm.html');
 }