Re: Finding valid ENUM values



Roedy Green wrote:
I found this snippet of PHP code. Perhaps you can decipher it and
produce a Java equivalent.

function enum($object) {
list($table, $col) = explode(".", $object);
$row=@mysql_fetch_assoc(mysql_query("SHOW COLUMNS FROM ".$table." LIKE
'".$col."'"));
return ($row ?
explode("','",preg_replace("/(enum|set)\('(.+?)'\)/","\\2",$row['Type']))
: array(0=>'None'));
}

$optarray = enum("table.column");"

A Java snippet:

ResultSet sc = stmt.executeQuery("SHOW COLUMNS FROM et LIKE 'ef'");
while(sc.next()) {
System.out.println(sc.getString("Type"));
Pattern p = Pattern.compile("'(\\w+)'");
Matcher m = p.matcher(sc.getString("Type"));
while (m.find()) {
System.out.println(m.group(1));
}
}
sc.close();

Arne
.