geo/db/mysql_spatial.inc, line 139
- Versions
- 6
geo_mysql_spatial_table_desc($table)
Parse out the table descriptions from the geometry information stored in the table.
Code
<?php
function geo_mysql_spatial_table_desc($table) {
$res = db_query("SELECT COLUMN_NAME AS 'name',
COLUMN_COMMENT AS 'description',
DATA_TYPE AS 'type',
IS_NULLABLE AS 'null_ok',
COLUMN_DEFAULT AS 'default'
FROM information_schema.columns
WHERE TABLE_SCHEMA = database()
AND TABLE_NAME = '%s' ORDER BY ORDINAL_POSITION", $table);
$columns = array();
$geo = array();
while ($row = db_fetch_array($res)) {
if ($row['type'] == 'geometry') {
$geo[] = $row['name'];
}
$columns[$row['name']] = $row;
$columns[$row['name']]['not_null'] = $row['null_ok']=='YES' ? FALSE : TRUE;
unset($columns[$row['name']]['null_ok']);
}
// @@@ I have no clue what this section is for. ~Bdragon
/* $res = db_query("SELECT c.relname AS table,
pg_catalog.pg_get_constraintdef(r.oid, true) AS constraint
FROM pg_catalog.pg_constraint r
LEFT JOIN pg_catalog.pg_class c ON r.conrelid = c.oid
WHERE c.relname = '%s' AND r.contype = 'c'", $table);
*/
/*
Find constraints that are similar to the ones here, and set attributes
CHECK (geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL)
CHECK (ndims(the_geom) = 2)
CHECK (srid(the_geom) = 26915)
*/
//while ($row = db_fetch_object($res)) {
// $table = $row->table;
// foreach($geo as $f) {
// if (strpos($row->constraint, "ndims($f)" )) {
// $columns[$f]['dimensions'] = preg_replace('/\D/','', $row->constraint);
// }
// elseif (strpos($row->constraint, "srid($f)" )) {
// $columns[$f]['srid'] = preg_replace('/\D/','', $row->constraint);
// }
// elseif (strpos($row->constraint, "geometrytype($f)" )) {
// $columns[$f]['geometry_type'] = preg_replace('/.*\'(\w+)\'.*/','$1', $row->constraint);
// }
// }
//}
return $columns;
}
?> 