Subject RE: [firebird-support] Re: Validate Schema
Author Nigel Weeks
I might be way off course, but here's an idea.

Do a query of the system tables to get a list of each table
For each table, query again to get:
field names
field types(varchar, etc)
sizes
nulls
scales
and append all these into one string.
Then, do an md5 of the string, and you've got a unique signature to match a
table.

If the md5's of two tables match, the tables are identical.

Blow it. Here's the PHP to do it. I'm feeling chatty.



<?php
// Change the line below to match each database you have
$conn = ibase_connect("localhost:/u1/db/fpi.fdb","sysdba","masterkey");

// You shouldn't need to change anything below this line
$tabsql = "SELECT distinct(a.rdb\$relation_name) as str_tablename from
rdb\$relation_fields a where a.rdb\$relation_name NOT CONTAINING 'RDB\$'";
$tabrec = ibase_query($tabsql);
while($tabobj = ibase_fetch_object($tabrec)){
$ddlsql = "select a.rdb\$field_name, a.rdb\$null_flag, c.rdb\$type_name,
b.rdb\$field_length, b.rdb\$field_scale from rdb\$relation_fields a,
rdb\$fields b, rdb\$types c where c.rdb\$field_name = 'RDB\$FIELD_TYPE' AND
c.rdb\$type=b.rdb\$field_type AND b.rdb\$field_name = a.rdb\$field_source
AND a.rdb\$relation_name = '".$tabobj->STR_TABLENAME."' ORDER BY
a.rdb\$field_position";
$ddlrec = ibase_query($ddlsql);
$string = "";
while($ddlrow = ibase_fetch_row($ddlrec)){
// Rip through the fields, concatenating them into a string
for($a=0;$a<5;$a++){
$string .= $ddlrow[$a];
}
} // End of inner fields loop
echo $tabobj->STR_TABLENAME.": ".md5($string)."\n";
} // End of outer table loop
?>



This script then produces:


CM$NAVIGATOR : 05755d5d6e6245846199d969dd15f86a
CM$NAVMODULE : a795ff05b3e57cc1acb4daa855c5991a
CM$XMLDESIGN : e31d8c64bcae36913dec0bd6adbc4181
TBL_ALTIMAGE : 86c4f3ae8be72401b379df073ab378f4
TBL_COMMDISCUSS : fc6e1ba39e69cbbd7b96ad2324209655
TBL_COMMDISMESG : 9a19bd65c00e385b2f4ddf73511fb84b
TBL_COMMUNITY : 79e662e28d44400d2470beb603d66a02
TBL_FIELDGROUP : 569a9a66387dcf748e5707555df027c8
TBL_FILE : 8a2d2c8db08232b78ee7a56bb83351ac
TBL_FILEACCESS : 7cad97faeffc879c567bf3ea2e62a99c
TBL_IMAGE : f8da9f6e7e4cca3c4bf9d9f367b3911f
TBL_NUTRIENT : 91622e5840f9261ab95ad68e9b5deade
TBL_PLANT : 4ee3ec89e3c43a0b3f07a5c04af1da90
TBL_PREPMETH : 737a8a156064e70589a17029ed6c489e
TBL_RESOURCE : 5c2490de8454baffd7aff4686f2b969c
TBL_SCRAPBOOK : 8899ca1e160ce0402874399cf9c689fc
TBL_SITESECTIONS : f230554f838d9f924471c053f0736743
TBL_SITESETTINGS : e9d03865efb71f7a674a091dd44db6a2
TBL_USER : 595cf5af5836132f34c9e50659aa6603
TLNK_PLANTIMAGE : 22b6ba87b9af9f07b8872ed9c4960292
TLNK_PLANTSCHEDULE : 05c18295760b474d878b5118d39ced52

Hopefully that'll help you out.

Nige.