示例#1
0
 /**
  * Get columns information from a table
  *
  * @param CSQLDataSource $ds    Datasource object
  * @param string         $table Table name
  *
  * @return array
  */
 static function getColumnsInfo(CSQLDataSource $ds, $table)
 {
     $columns = $ds->loadHashAssoc("SHOW COLUMNS FROM `{$table}`");
     $xpath = null;
     $description = self::getDescription($ds->dsn);
     $xpath = $description->_xpath;
     foreach ($columns as $_name => &$_column) {
         $_column["datatype"] = $_column["Type"] . " " . ($_column["Null"] == "YES" ? "NULL" : "NOT NULL");
         $_column["is_text"] = preg_match('/(char|text)/', $_column["Type"]);
         $_column["foreign_key"] = null;
         if ($xpath) {
             /** @var DOMElement $_column_element */
             $_column_element = $xpath->query("//tables/table[@name='{$table}']/column[@name='{$_name}']")->item(0);
             if ($_column_element) {
                 $_column["foreign_key"] = $_column_element->getAttribute("foreign_key");
             }
         }
     }
     return $columns;
 }