Re: Finding valid ENUM values



Really sorry for the delay in responding chaps - been kind of busy with
work, and away.

Thanks for the tips. It looks to me as if it's something that needs to be
well encapsulated - it's certainly not portable code, tho having said that,
MySQL ENUMs aren't portable either!

rgds

Rupert


"Arne Vajhøj" <arne@xxxxxxxxxx> wrote in message
news:470065b2$0$90266$14726298@xxxxxxxxxxxxxxxxxx
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


.