<?php error_reporting(E_ALL); require_once 'Config.inc.php'; require_once 'lib/Test.classes.php'; require_once 'lib/CodeListing.classes.php'; #CodeListing::classes('Orm'); # public static function t($name, $func, $params, $against_func_str /* $result is passed into this function */, $hide_stack_trace = false) Test::init(); SSql::query("DELETE FROM person WHERE dna_seq = 'abcxyz' AND surname = 'Bloggs' AND given_name = 'Joe'"); new Person(OrmClass::CONSTR_CMD_POP_FROM_ARR, NULL, array('dna_seq' => 'abcxyz', 'surname' => 'Bloggs', 'given_name' => 'Joe')); #SSql::$debug = true; foreach (Orm::load('Person') as $o) { print_r($o); print_r($o->getRelsByClass('Office')); #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
$properties[] = sprintf(' PRIMARY KEY (%s)', implode(', ', $o->keys)); } $schema .= sprintf("%s\n);\n\n", implode(",\n", array_merge($properties, $relationships))); } $form = $body->form(); $form->method = 'post'; $on = $form->input(); $on->type = 'hidden'; $on->name = 'orm_name'; $on->value = $_POST['orm_name']; $textarea = $form->textarea($schema, Node::UNMANGLED); $textarea->name = 'schema'; $textarea->cols = 100; $textarea->rows = 40; $form->br(); $submit = $form->input(); $submit->type = 'submit'; $submit->value = 'Execute against database'; } elseif (sizeof($_POST) == 2 && !empty($_POST['schema'])) { $orm_name = $_POST['orm_name'] == '-' ? NULL : $_POST['orm_name']; # execute against db #SSql::query($_POST['schema'], Orm::getSSqlName($orm_name)); foreach (explode(';', $_POST['schema']) as $table) { $table = trim($table); if (!empty($table)) { SSql::query($table, Orm::getSSqlName($orm_name)); } } $body->addText('Done!'); } echo $html;
/** 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 } }