Arne Vajhøj wrote on 03.07.2009 21:31:
> I believe the exact semantics of catalog and schema vary between
> databases.
Which you can ask the driver for:
<http://java.sun.com/javase/6/docs/api/java/sql/DatabaseMetaData.html#getCatalogTerm()>
<http://java.sun.com/javase/6/docs/api/java/sql/DatabaseMetaData.html#getSchemaTerm()>
will retrieve the vendor's preferred name for "catalog" and "schema".
If I recall correctly:
PostgreSQL: catalog = database, schema = schema
Oracle: schema = user, no catalogs
Firebird: no schemas, no catalogs
SQL Server: catalog = database, schema = user
MySQL: catalog = database, no schemas
>> But the current schema seems not to be so simple...
Correct, you will need to run your own SQL for this.
Misza - 07 Jul 2009 19:58 GMT
> Arne Vajhøj wrote on 03.07.2009 21:31:
>> I believe the exact semantics of catalog and schema vary between
[quoted text clipped - 7 lines]
>
> will retrieve the vendor's preferred name for "catalog" and "schema".
Plus, there is a getSchemas() method that will enumerate all schemas in
a (current or specified) catalog. I propose to check what results does
it yield for your particular dbms - maybe it will give some ideas.
> SQL Server: catalog = database, schema = user
Additionally, in MSSQL 2k5 one can create custom schemas (they must be
bound to an owner user though).
>>> But the current schema seems not to be so simple...
>
> Correct, you will need to run your own SQL for this.
I'd trust getUserName() most of the time, unless the particular dbms
does not recognize the existence of schemas.
Regards,
Misza
Thomas Kellerer - 07 Jul 2009 20:34 GMT
Misza wrote on 07.07.2009 20:58:
>>>> But the current schema seems not to be so simple...
>> Correct, you will need to run your own SQL for this.
>
> I'd trust getUserName() most of the time, unless the particular dbms
> does not recognize the existence of schemas.
getUserName() is probably the worst choice you could make.
It will not work on Oracle if the current schema has been changed using ALTER
SESSION (without reconnecting using a different user)
It will not work at all on PostgreSQL. Schema and user are completely unrelated
there. And you can change the current schema at any time without changing the
user (just like in Oracle)
It will not work on SQL Server as the schema/owner and user are not related as
well. AFAIK SQL Server does not have the notion of a "current schema", so I
don't think it can be "changed"
Thomas
Lee Fesperman - 10 Jul 2009 00:03 GMT
On Jul 3, 12:59 pm, Thomas Kellerer <OTPXDAJCS...@spammotel.com>
wrote:
> Arne Vajhøj wrote on 03.07.2009 21:31:
>
[quoted text clipped - 8 lines]
> SQL Server: catalog = database, schema = user
> MySQL: catalog = database, no schemas
None of those actually support Standard SQL's notion of catalog and
schema. In the standard, catalogs are at the top and contain schemas.
Schema's contain regular database objects -- tables, views,
constraints, privileges, ... Standards compliance is not high priority
among those vendors.
> >> But the current schema seems not to be so simple...
> Correct, you will need to run your own SQL for this.
As mentioned elsewhere, getUserName() might do the trick, otherwise it
will take vendor specific SQL.
--
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
==============================================================
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)