from() public method

Alias to specify which table is being used.
public from ( string $table ) : SqlBuilder
$table string
return SqlBuilder
Example #1
0
 public function edit()
 {
     $postBuilder = new SqlBuilder();
     $post = $postBuilder->from('post')->with(array('status' => array('status_name', 'label', 'id', 'status')))->where(array('id = ' . $_GET['id']))->limit(1)->query();
     $tagsBuilder = new SqlBuilder();
     $tags = $tagsBuilder->select(array('tag'))->from('tag')->where(array('post_id = ' . $post->id))->query();
     $this->render('post/edit', array('post' => $post, 'tags' => $tags));
 }
Example #2
0
 /**
  * Return a SqlBuilder object which has set the table and optionally
  * assigned values to columns based on this instances' properties. This is used in
  * insert(), update(), and delete()
  *
  * @param ModelDescriptor $descriptor
  * @param boolean $useAssignment
  * @param boolean $excludePrimaryKey
  * @return SqlBuilder
  */
 protected function assignmentSqlForThisObject(ModelDescriptor $descriptor, $useAssignment = true, $excludePrimaryKey = false)
 {
     $sqlBuilder = new SqlBuilder();
     $sqlBuilder->from($descriptor->getTable());
     if (empty($descriptor->columns)) {
         throw new RecessException('The "' . $descriptor->getTable() . '" table does not appear to exist in your database.', get_defined_vars());
     }
     foreach ($this as $column => $value) {
         if ($excludePrimaryKey && $descriptor->primaryKey == $column) {
             continue;
         }
         if (in_array($column, $descriptor->columns) && isset($value)) {
             if ($useAssignment) {
                 $sqlBuilder->assign($column, $value);
             } else {
                 $sqlBuilder->equal($column, $value);
             }
         }
     }
     return $sqlBuilder;
 }
 function onDeleteNullify(Model $model)
 {
     if (isset($this->through)) {
         return $this->onDeleteDelete($model);
     }
     $modelPk = Model::primaryKeyName($model);
     $queryBuilder = new SqlBuilder();
     $queryBuilder->from(Model::tableFor($this->foreignClass))->assign($this->foreignKey, null)->equal($this->foreignKey, $model->{$modelPk});
     $source = Model::sourceFor($model);
     $source->executeStatement($queryBuilder->update(), $queryBuilder->getPdoArguments());
 }
Example #4
0
 /**
  * @todo cache the result
  * @param boolean $with_limit
  * @return integer
  */
 public function get_count($with_limit = false)
 {
     $limit_stmt = $with_limit ? SqlBuilder::order_by($this->order, $this->order_dir) . SqlBuilder::limit($this->offset, $this->limit) : '';
     $rs = SqlTools::sqlQuery("SELECT count(1)\n                        \nFROM " . SqlBuilder::from($this->get_from_tables()) . SqlBuilder::joins($this->joins, $this->getJoinType()) . SqlBuilder::where($this->where, $this->sql_where) . $limit_stmt);
     if ($rs) {
         return (int) mysql_result($rs, 0);
     } else {
         throw new Exception("Fatal error:" . mysql_error());
     }
 }