/** * @group pgsql */ public function testColumns() { $columns = $this->ssql->createSQry()->columnsof('user'); $this->assertSame(count($columns), 2); $this->assertSame($columns[0]['name'], 'id'); $this->assertSame($columns[0]['pk'], true); $this->assertSame($columns[1]['name'], 'name'); $this->assertSame($columns[1]['pk'], false); }
public static function setup() { $args = func_get_args(); $db = self::$default = self::create($args); self::config($db); return $db; }
function getDbType($orm_name) { return SSql::getType(Orm::getSSqlName($orm_name)); }
#print_r($habitation = $o->getRelsByClasses('Home', 'LivesIn')); print_r($habitation = $o->getRelsByClasses('Home', 'LivesIn', 'Person -> (LivesIn) -> Home')); print_r($habitation->classHome[0]); print_r($habitation->classLivesIn[0]); } #OrmSqlCache::save(); # suggested tests # 1. Orm::load # 2. OrmClass->getRelsByClasses() for direct relation # 3. OrmClass->getRelsByClasses() for indirect relation # 4. OrmClass->getRelsByClasses() for multiple relations # 5. OrmClass->getRelsByClasses() with chain # 6. OrmClass->getRelsByClasses() with chains # 7. OrmClass->getRelsByClass() without and with chain # TODO # consider adding an incrementing integer to alias so that multiple passes of the same rule are ok # this would allow the system more flexibility for a person (keep the routing part crippled though) # would need to update the SQL generation stage, and the Object creation stage # after more thought; could result in output of objects that are the same as already constructed ones # to mitigate this we could scan previously constructed objects of the same class type for equal keys (as they've just been constructed anyway) # and merely point to the same object -- use Orm->equals() to establish this # started coding this and stopped... see $seen_results # -- stopped cos i'll have to have numbers in all aliases and i'm not so sure i want that! if (sizeof($history = SSql::getQueryHistory()) > 0) { printf("Number of SQL queries: %d, SQL Query History\n%s", sizeof($history), print_r($history, true)); } if (function_exists('xdebug_peak_memory_usage')) { printf("Peak memory usage: %.3fMB\n", xdebug_peak_memory_usage() / pow(2, 20)); } #Test::summary('OrmClass'); Orm::routeFromChain(NULL, 'Person -> (LivesIn) -> Home -> (Neighbours) -> Home -> (Neighbours) -> Home', array((object) array('class' => 'LivesIn')));
public function testCallStatic() { SSql::setup('sqlite::memory:'); $this->assertEqual(SSql::__callStatic('lastInsertId', array()), '0'); }
public function __construct() { parent::__construct(); TLO::init(); $this->guid1 = TLO::guid(); $this->guid2 = TLO::guid(); $this->guid3 = TLO::guid(); $this->guid4 = TLO::guid(); SSql::setup('sqlite::memory:'); $this->db = SSql::instance(); $this->db->exec('CREATE TABLE test1 (id CHAR(' . strlen($this->guid1) . ') PRIMARY KEY, foo INTEGER, connected_to__key__id CHAR(' . strlen($this->guid1) . '), connected_to__var__somevar VARCHAR(10), connected_to__var__time DATETIME)'); $this->db->exec('CREATE TABLE test3 (id CHAR(' . strlen($this->guid1) . ') PRIMARY KEY, parent__key__id CHAR(' . strlen($this->guid1) . '), bar INTEGER, baz INTEGER)'); $this->db->exec("INSERT INTO test1 VALUES ('{$this->guid1}', 1, '{$this->guid2}', 'foo', datetime('now'))"); $this->db->exec("INSERT INTO test3 VALUES ('{$this->guid2}', '{$this->guid1}', 2, 3)"); $this->db->exec("INSERT INTO test1 VALUES ('{$this->guid3}', 1, '{$this->guid2}', 'foo', datetime('now'))"); $this->db->exec("INSERT INTO test1 VALUES ('{$this->guid4}', 1, '{$this->guid2}', 'foo', datetime('now'))"); }
/** Insert a row into the DB **/ private function insert($class) { $insert = array(); if (Orm::$use_guids) { # TODO # generate guid } # TODO: parental relationships?????? $properties = self::getProperties($class); SSql::query(sprintf("INSERT INTO %s (%s) VALUES (%s)", self::classToDbName($class), implode(', ', array_map(array($this, 'sqlKey'), $properties)), implode(', ', array_map(array($this, 'sqlValue'), $properties))), self::getSSqlName($this->setup_name)); # WORKING_ON if (!Orm::$use_guids) { # TODO # get id from db } }
protected function setUp() { $this->config['sqlDir'] = __DIR__ . "/" . $this->config['sqlDir']; $this->ssql = SSql::connect($this->config); }
<?php date_default_timezone_set('UTC'); require_once 'lib/Exception.classes.php'; require_once 'Orm.classes.php'; require_once 'lib/SSql.classes.php'; require_once 'lib/Node.classes.php'; SSql::connect('MySQL', 'orm_test', 'localhost', '3306', 'orm_test', 'xCwNxDB8BUwTSy5A', NULL, FALSE); #SSql::connect('SQLite', 'orm.db'); # note that SQLite support is broken :P require_once 'Schema.inc.php'; require_once 'OrmSqlCache.class.php';