Get block database schema
PermalinkAt the moment I am doing:
$btInstalledArray = BlockTypeList::getInstalledList(); $internalBlockTypes = array(); $normalBlockTypes = array(); foreach($btInstalledArray as $_bt) { if ($_bt->isInternalBlockType()) { $internalBlockTypes[] = $_bt; } else { $normalBlockTypes[] = $_bt; } } foreach ($normalBlockTypes as $nbt) { $schema = Database::getADOSChema(); $sql = $schema->ParseSchema($nbt->getBlockTypePathDBXMLFile().'/'.$this->dbFile); }
the getBlockTypePathDBXMLFile() function is a modified version of BlockType::getBlockTypePath(), so that it searches for the db.xml file in the package dir first, then the root/blocks, then finally the root/concrete/blocks, as the original only searches for the existence of the directory.
I then use the database ParseSchema function to find out everything about the tables, however the results are returned as ALTER TABLE tbl_name .... etc.
Anyone know of any quicker way of doing this?
Jim
I'm building a new package for a client of mine, and need to be able to get a list of the fields in other blocks.
SHOW COLUMNS FROM MyTableName
DESC MyTableName
Run a GetAll and dump the resulting array from each of the above and you will see everything.
Or are you suggesting that after getting the xml file, and working out the tabels that exist in it, then doing a show columns on that?
It works fine for addon blocks. With core blocks, the problem is they are all set up from one big xml file, so you need to rely on naming or proximity to associate secondary tables.
There is also the issue of blocks that interact with tables defined in a packages db.xml and tables from attributes. So the mapping of tables : blocks can be many : many and non exclusive.
I'll have a look at doing this later, cheers for the tip John!
Adam.
<?xml version="1.0"?>
<schema version="0.3">
<table name="btContentLocal">
<field name="bID" type="I">
<key />
<unsigned />
</field>
<field name="content" type="X2">
</field>
</table>
</schema>
So the structure is tablename - btContentLocal
fields - bID ( key )
content
If there is 2 tables for the block - you may see them here but sometimes they are loaded with the package and then another table loaded with the block inside the package - that's where it gets a little confusing. In the Concrete documents for developers there is a link to the database definitions - i.e. type="X2"
Jim