Re: Finding valid ENUM values
- From: "Rupert Woodman" <NoEmail@com>
- Date: Tue, 16 Oct 2007 22:55:05 +0100
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
.
- References:
- Re: Finding valid ENUM values
- From: Roedy Green
- Re: Finding valid ENUM values
- From: Arne Vajhøj
- Re: Finding valid ENUM values
- Prev by Date: date operations in jpql queries
- Next by Date: Single Connection attempt
- Previous by thread: Re: Finding valid ENUM values
- Next by thread: Re: (Mis)use of transactions
- Index(es):