Dotan Cohen wrote:
How does one make an enum (only one of a set) datatype in a Base
table? I see it mentioned in TFM but I don't see how to make it with
the GUI tools:
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Java/Mapping_of_Enum_Types
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/AppendixA/Enums
Hello Dotan,
You are mixing Apples and Oranges in your question, as posed.
Some database engines do have native support a column datatype of ENUM.
However the wiki pages you reference above is not referring to a
database column datatype at all - but rather to a data structure used
within scripting languages or external applications interacting with
OpenOffice.org.
I suppose however that you are asking because you are interested in
using a database column type of ENUM in a table, yes.
Well if you connected a Base file to a MySQL database that would find a
datatype of "TEXT [Enum]" in the "Field Type" dropdown control in the
table editor.
OpenOffice.org of course ships with a complimentary database engine,
case you don't want MySQL or Postgres or whatever and that is HSQLdb.
HSQLdb doesn't have a native field type of ENUM, *which* doesn't mean
anything really, because getting the same behavior with a regular field
type of CHAR or VARCHAR is done quite readily.
Suppose I want to store any one of, and only one of, the following values:
Red, Blue, Green, Yellow, White, Black
[I'll use a special HSQLdb field type of VARCHAR_IGNORECASE here]
I would use the GUI table editor to create a table, tblColor, with the
following two fields:
id Integer PRIMARY KEY,
Color Text [VARCHAR_IGNORECASE](6)
Yellow is the longest string with 6 characters.
With the table editor closed I then open the SQL window and apply a
CONSTRAINT to the column "Color" at the HSQLdb engine level.
ALTER TABLE "tblColor" ADD CONSTRAINT "My_Color_Enum" CHECK ( "Color" IN
( 'Red', 'Blue', 'Green', 'Yellow', 'White', 'Black') );
At this point then I have for all intent and purpose an ENUM field type.
I open the able and enter any of the strings and it is accepted.
(remember I made it case insignificant, so here Red == rEd == RED, but
we could of made it absolutely exact just by making the actual field
type VARCHAR(6) or CHAR(6) instead of VARCHAR_IGNORECASE)
When I try to enter the string 'Wall' in any fashion - the data view
window, a form, a script - however, the database engine disallows it
and notifies the user, which you can see in this screen shot here:
http://baseanswers.com/downloads/my_color_enum.png
The HSQLdb engine is quite SQL compliant so looking up the syntax for
the ALTER TABLE command is just a google away.
Granted it's not a total GUI solution but HTH,
Drew
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]