Finding valid ENUM values
4 Message(s) by 3 Author(s) originally posted in java databases
| From: Rupert Woodman |
Date: Saturday, September 29, 2007
|
I have a MySQL (5)
database which has a
table containing an ENUM column.
I'd like to (
program atically) get a
list of what the valid options are for
this ENUM. I have looked through the metadata but can not see anything. Can
someone
point out what I'm missing?
Many thanks
| From: Roedy Green |
Date: Sunday, September 30, 2007
|
On Sun, 30 Sep 2007 02:12:42 +0100, "Rupert Woodman"
<NoEmail@xxxxxxxxxxx>
wrote in
message , quoted or indirectly quoted someone who said :
I have a MySQL (5) database which has a table containing an ENUM column.
I'd like to (programatically) get a list of what the valid options are for
this ENUM. I have looked through the metadata but can not see anything. Can
someone point out what I'm missing?
You can
write something like this: /**
* stage codes, upper case
* U = untranslated
* ? = unsure of translation
* T = translated
* P = proofread (only proofreader/admin can set P or C status)
* C =
complete (proofread in
context of the actual program making
sure it fits in the box, looks good etc.)
*/
stage ENUM( 'U','?','T','P', 'C' ) NOT NULL,The values you put and get will be ordinary strings.
There is an a abominably documented
feature to use enums by index
rather than value. It follows advice in my "how to write
unmaintainable code" essay. Perhaps this could be worked up into a
method.
I found this snippet of PHP code. Perhaps you can decipher it and
produce a JAVA equivalent.
wrote in message this php
function to return an
array from enum values, using
the preg()
solution posted by Willem-Jan van Dinter above, hope
someone finds it useful
Note: returns array(0 => 'None') if no results or no such table
function enum($object) {
list($table, $col) = explode(".", $object);
$row=@xxxxxxxxxxx(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");"--
Roedy
Green Canadian Mind Products
The JAVA Glossary
http://mindprod.com
| From: =?ISO-8859-1?Q?Arne_Vajh=F8j?= |
Date: Sunday, September 30, 2007
|
wrote in message:
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=@xxxxxxxxxxx(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
| From: Rupert Woodman |
Date: Tuesday, October 16, 2007
|
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 are not portable either!
rgds
wrote in message:
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=@xxxxxxxxxxx(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
Next Message: about connecting to a database
Blogs related to Finding valid ENUM values
hi - I have a query and Im doing WHERE IN34567 where those ids in ...
um, how do I
find where is the datadir for sql? show variables like 'datadir';. prompt? yes. datadir; and there was an error. show variables like 'datadir';. +—————+———————————-+ | Variable_name |
Value | +—————+———————————-+
...
I dont know how to ask the question Basically I can write Java for ...
clientTable = new HashtableString, String();, what's the proper way to make the
value element a map as well? uh no. But
Java, in v6, can programmatically run its compiler. How can I
find out what version this is running?
...
Im struggling to make a query to find the active topics for a ...
I can't
find a reference anywhere for the
valid dateformat tokens… narrowed it down I jsut can't get the minute.. try to
find out what your sql backend is (openoffice base it is hsqlbd) and then search the right api.
...
Structure of a program Structure of a program Probably the best ...
Both ways of initializing variables are
valid and equivalent in C++. // initialization of variables #include using namespace std; int main () { int a=5; // initial
value = 5 int b(2); // initial
value = 2 int result; // initial
value ...
Java Faqs
(JNDI) Answer lookup() attempts to
find the specified object in the given context. Ie, it looks for a single, specific object and either finds it in the current context or it fails. list() attempts to return an
enumeration of all of the
...
Sample Java Interview Questions
below figure at the left hand side you can see the static variables
values are preserved as they are. So the “intStat”
value goes up to “4” and “intNonStat” has
value “1”. 86 Figure 1.25 : - clsTestrun.
java class Note: - You can
find ...