public function joinTable(Table $table) { $this->join_to[$table->name()] = $table; $table->setJoinType(self::INNER_JOIN); }
/** * {@inheritDoc} */ public function truncateTableSql(Table $table) { $name = $this->_driver->quoteIdentifier($table->name()); $queries = [sprintf('DELETE FROM %s', $name)]; // Restart identity sequences $pk = $table->primaryKey(); if (count($pk) === 1) { $column = $table->column($pk[0]); if (in_array($column['type'], ['integer', 'biginteger'])) { $queries[] = sprintf('DBCC CHECKIDENT(%s, RESEED, 0)', $name); } } return $queries; }
<?php // 1 : load the table module require_once 'modules/table.php'; // 2 : create an instnce of the Table module $table = new Table(); // 3 : configuring the new create table // $table->name('table1'); // $table->add()->name('id')->type('int')->size('10')->close() // ->add()->name('name')->type('varchar')->size('100')->close(); $table->name('user'); $table->add()->name('id')->type('int')->size('3')->close(); $table->add()->name('name')->type('varchar')->size('50')->close(); // echo $table->toString(); // echo $table->create(); // print_r($table->read(3)); // echo $table->update(); // echo $table->delete(); // $a = new table1(); // print_r($a->read(3)); // 4 : exporting the newly created table class echo $table->export();
<?php namespace PluSQL; \Murphy\Test::add(function ($runner) { $table = new Table('strong_guy'); if ($table->name() == 'strong_guy') { $runner->pass(); } else { $runner->fail('Table name not set correctly in constructor'); } $table->setJoinType(Table::INNER_JOIN); if ($table->joinType() == 'INNER JOIN') { $runner->pass(); } else { $runner->fail('Unable to set join type'); } $table = new Table('strong_guy'); $table2 = new Table('weak_guy'); $table->joinTable($table2); if ($table2->joinType() == 'INNER JOIN') { $runner->pass(); } else { $runner->fail('The join type was not set to INNER JOIN by default'); } ob_start(); print_r($table->joinTo()); $actual = ob_get_clean(); $expected = 'Array ( [weak_guy] => PluSQL\\Table Object
/** * Copy table * @param $db * @param $name * @return Table */ public function copyTable($name, $db = null, $temp = false) { if (!$temp && !$name) { throw new Exception('New table has no name'); } $db = $db ? $db : $this->db(); $name = $name ? $name : 'temp_' . substr(md5(microtime(true) . rand(1, 9999)), 0, 10); $table = new Table(); $table->connection($this->connection()); $table->db($db); $table->name($name); $table->attrs($this->attrs()); $table->rowClass = $this->rowClass; $builder = $table->builder(); $query = $builder->createTableLike($temp, $this->db(), $this->name()); $table->connection()->query($query); $builder = $this->builder(); $builder->columns(array('*')); $query = $builder->insertSelect($table->db(), $table->name()); $this->connection()->query($query); return $table; }