private static function test_introspection() { // Table list : $list = \Glue\DB\DB::cn()->table_list(); sort($list); $tests['table list'] = array('glintro,glposts,glprofiles,glusers', implode(',', $list)); // Table exists : $tests['table exists true'] = array(true, \Glue\DB\DB::cn()->table_exists('glposts')); $tests['table exists false'] = array(false, \Glue\DB\DB::cn()->table_exists('glpersonsqsdf')); // Tables : $tables = \Glue\DB\DB::cn()->tables(); $tests['tables'] = array(4, count($tables)); // Table data : $table = \Glue\DB\DB::cn()->table('glintro'); // Name : $tests['table name'] = array('glintro', $table->name()); // PK : $arr = array(); foreach ($table->pk() as $pkc) { $arr[] = $pkc->name(); } sort($arr); $tests['table pk'] = array('a,b', implode(',', $arr)); // Columns : $c = $table->column('a'); $tests['a name'] = array('a', $c->name()); $tests['a type'] = array('int', strtolower($c->type())); $tests['a nullable'] = array(false, $c->nullable()); $tests['a maxlength'] = array(null, $c->maxlength()); $tests['a precision'] = array(10, $c->precision()); $tests['a scale'] = array(0, $c->scale()); $tests['a default'] = array(null, $c->default()); $tests['a auto'] = array(true, $c->auto()); $tests['a phptype'] = array('integer', $c->phptype()); $c = $table->column('b'); $tests['b name'] = array('b', $c->name()); $tests['b type'] = array('int', strtolower($c->type())); $tests['b nullable'] = array(false, $c->nullable()); $tests['b maxlength'] = array(null, $c->maxlength()); $tests['b precision'] = array(10, $c->precision()); $tests['b scale'] = array(0, $c->scale()); $tests['b default'] = array('0', $c->default()); $tests['b auto'] = array(false, $c->auto()); $tests['b phptype'] = array('integer', $c->phptype()); $c = $table->column('c'); $tests['c name'] = array('c', $c->name()); $tests['c type'] = array('varchar', strtolower($c->type())); $tests['c nullable'] = array(true, $c->nullable()); $tests['c maxlength'] = array(31, $c->maxlength()); $tests['c precision'] = array(null, $c->precision()); $tests['c scale'] = array(null, $c->scale()); $tests['c default'] = array('test', $c->default()); $tests['c auto'] = array(false, $c->auto()); $tests['c phptype'] = array('string', $c->phptype()); $c = $table->column('d'); $tests['d name'] = array('d', $c->name()); $tests['d type'] = array('decimal', strtolower($c->type())); $tests['d nullable'] = array(true, $c->nullable()); $tests['d maxlength'] = array(null, $c->maxlength()); $tests['d precision'] = array(6, $c->precision()); $tests['d scale'] = array(2, $c->scale()); $tests['d default'] = array('45.00', $c->default()); $tests['d auto'] = array(false, $c->auto()); $tests['d phptype'] = array('float', $c->phptype()); // Connection list : $list = \Glue\DB\DB::connection_list(); sort($list); $tests['connection list'] = array('default,test', implode(',', $list)); // Connection exists : $tests['connection exists true'] = array(true, \Glue\DB\DB::connection_exists('test')); $tests['connection exists false'] = array(false, \Glue\DB\DB::connection_exists('testtt')); // Connections : $connections = \Glue\DB\DB::connections(); $tests['connections'] = array(2, count($connections)); // Checks : foreach ($tests as $type => $data) { list($expected, $real) = $data; echo "Testing introspection : " . $type . " ..."; if ($expected === $real) { echo "ok \n"; } else { echo '<b style="color:blue">error ! ' . $real . " doesn't match target " . $expected . "\n</b>"; return false; } } }
/** * Returns the connection of this table. * * @return \Glue\DB\Connection */ public function cn() { return \Glue\DB\DB::cn($this->cnid); }