3 * Table Definition for builder_tables
5 require_once 'DB/DataObject.php';
7 class Pman_Builder_DataObjects_Builder_tables extends DB_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'builder_tables'; // table name
13 public $id; // int(11) not_null primary_key auto_increment
14 public $name; // string(128) not_null
15 public $descrip; // string(254) not_null
16 public $parent_id; // int(11) not_null multiple_key
17 public $dbschema; // blob(65535) not_null blob
20 /* the code above is auto generated do not remove the tag below */
24 function applyFilters($q, $au)
26 //DB_DataObject::debugLEvel(1);
27 if (!empty($q['_sync'])) {
28 $this->syncDatabase();
29 HTML_FlexyFramework::get()->page->jok("DONE");
34 function syncDatabase()
36 //DB_DataObject::debugLevel(1);
37 global $_DB_DATAOBJECT;
38 $x = DB_DataObject::factory('builder_tables');
39 $x->whereAdd("name != ''"); // real tables only..
40 $mine = $this->fetchAll('name', 'id');
42 // ensure everything is loaded...
43 $tq = DB_DataObject::factory('builder_tables');
46 $tables = $_DB_DATAOBJECT['INI'][$tq->_database];
50 $t = array_keys($tables);
54 // for postgres we can get descriptions - this should just fail in Mysql..
56 $dsn = HTML_FlexyFramework::get()->database;
58 if (preg_match('/^pgsql:/', $dsn )) {
59 $tq = DB_DataObject::factory('builder_tables');
61 select relname, obj_description( oid) as desc FROM pg_catalog.pg_class
63 while ($tq->fetch()) {
64 $desc[$tq->relname] = $tq->desc;
67 // DB_DataObjecT::DebugLevel(1);
68 $tq = DB_DataObject::factory('builder_tables');
70 require_once 'Services/JSON.php';
76 if (preg_match('/__keys$/', $k)) {
79 // check it can be constructed..
80 // this might be problematic for 'new' tables...
81 $do = DB_DataObject::factory($k);
82 if (!is_a($do,'DB_DataObject')) {
86 // get's the module part out of the dataobject class name
87 // assumes '_' is not used in module name.
90 substr(get_class($do), 0, -1 * (strlen('_DataObject_') + strlen($k)+ 1))
93 // should get 'ZZZ' part.. : XXX_ZZZZ_DataObject_xx_Builder
94 if (!isset($modids[$mod])) {
95 $x = DB_DataObject::factory('builder_tables');
100 if (!$x->find(true)) {
103 $modids[$mod] = $x->id;
111 'descrip' => isset($desc[$k]) ? $desc[$k] : '',
112 'dbschema' => Services_JSON::stringify($this->tableSchema($k),null,4),
113 // 'parent_id' => $modids[$mod],
117 if (isset($mine[$k])) {
121 if (empty($do->parent_id) || $do->parent_id < 1) {
122 // allow user to modify this..
123 $do->parent_id = $modids[$mod];
130 $do->parent_id = $modids[$mod];
140 function tableSchema($tn)
142 static $cache = array();
143 static $types= array();
144 $do = DB_DataObject::factory($tn);
145 $tn = $do->tableName(); // cleaned up!
148 if (isset($cache[$tn])) {
152 // get a description if available..
157 $dsn = HTML_FlexyFramework::get()->database;
158 if (preg_match('/^pgsql:/', $dsn)) {
161 // DB_DataObject::DebugLevel(1);
163 c.column_name as name,
164 pgd.description as desc
165 FROM pg_catalog.pg_statio_all_tables as st
166 inner join pg_catalog.pg_description pgd on (pgd.objoid=st.relid)
167 inner join information_schema.columns c on (pgd.objsubid=c.ordinal_position and c.table_schema=st.schemaname and c.table_name=st.relname)
169 c.table_schema = 'public' and c.table_name = '{$tn}'
171 while($dd->fetch()) {
172 $desc[$dd->name] = $dd->desc;
175 $defs = $dd->getDatabaseConnection()->tableInfo($tn);
177 foreach($defs as $i=>$c) {
178 $defs[$i]['desc'] = isset($desc[$c['name']]) ? $desc[$c['name']] : '';