Difference between revisions of "Documentation/DevGuide/Database/Adding and Editing Predefined Queries"
OOoWikiBot (Talk | contribs) m (FINAL VERSION FOR L10N) |
|||
Line 20: | Line 20: | ||
New query definitions are created by the <idl>com.sun.star.lang.XSingleServiceFactory</idl> interface of the query definitions container. Its method <code>createInstance()</code> provides an empty <code>QueryDefinition</code> to configure, as required. Then, the new query definition is added to the <code>DefinitionContainer</code> using <code>insertByName()</code> at the <code>XNameContainer</code> interface. | New query definitions are created by the <idl>com.sun.star.lang.XSingleServiceFactory</idl> interface of the query definitions container. Its method <code>createInstance()</code> provides an empty <code>QueryDefinition</code> to configure, as required. Then, the new query definition is added to the <code>DefinitionContainer</code> using <code>insertByName()</code> at the <code>XNameContainer</code> interface. | ||
− | {{ | + | {{Note|The optional interface <idl>com.sun.star.util.XRefreshable</idl> is not supported by the <tt>DefinitionContainer</tt> implementation.}} |
A <code>QueryDefinition</code> is configured through the following properties: | A <code>QueryDefinition</code> is configured through the following properties: |
Revision as of 16:21, 3 July 2018
- Adding and Editing Predefined Queries
- Runtime Settings For Predefined Queries
- The SingleSelectQueryComposer
- The SQLQueryComposer
The query definitions container com.sun.star.sdb.DefinitionContainer is used to work with the query definitions of a data source. It is returned by the com.sun.star.sdb.XQueryDefinitionsSupplier interface of the data source, which has a single method for this purpose:
com::sun::star::container::XNameAccess getQueryDefinitions()
The DefinitionContainer
is not only an XNameAccess
, but a com.sun.star.container.XNameContainer, that is, add new query definitions by name (see First Steps). Besides the name access, obtain query definitions through com.sun.star.container.XIndexAccess and com.sun.star.container.XEnumerationAccess.
New query definitions are created by the com.sun.star.lang.XSingleServiceFactory interface of the query definitions container. Its method createInstance()
provides an empty QueryDefinition
to configure, as required. Then, the new query definition is added to the DefinitionContainer
using insertByName()
at the XNameContainer
interface.
The optional interface com.sun.star.util.XRefreshable is not supported by the DefinitionContainer implementation. |
A QueryDefinition
is configured through the following properties:
Properties of com.sun.star.sdb.QueryDefinition | |
---|---|
Name | string - The name of the queryDefinition.
|
Command | string - The SQL SELECT command.
|
EscapeProcessing | boolean - If true, determines that the query must not be touched by the built-in SQL parser of OpenOffice.org API.
|
UpdateCatalogName | string - The name of the update table catalog used to identify tables, supported by some databases.
|
UpdateSchemaName | string - The name of the update table schema used to identify tables, supported by some databases.
|
UpdateTableName | string - The name of the update table catalog used to identify tables, supported by some databases The name of the table which should be updated. This is usually used for queries based on more than one table and makes such queries partially editable. The property UpdateTableName must contain the name of the table with unique rows in the result set. In a 1:n join this is usually the table on the n side of the join.
|
The following example adds a new query definition Query1
to the data source Bibliography that is provided with OpenOffice.org API.
// creates a new query definition named Query1 public static void createQuerydefinition(XMultiServiceFactory _rMSF) throws com.sun.star.uno.Exception { XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, _rMSF.createInstance( "com.sun.star.sdb.DatabaseContext") ); // we use the datasource Bibliography XQueryDefinitionsSupplier xQuerySup = (XQueryDefinitionsSupplier) UnoRuntime.queryInterface( XQueryDefinitionsSupplier.class, xNameAccess.getByName( "Bibliography" )); // get the container for query definitions XNameAccess xQDefs = xQuerySup.getQueryDefinitions(); // for new query definitions we need the com.sun.star.lang.XSingleServiceFactory interface // of the query definitions container XSingleServiceFactory xSingleFac = (XSingleServiceFactory)UnoRuntime.queryInterface( XSingleServiceFactory.class, xQDefs); // order a new query and get its com.sun.star.beans.XPropertySet interface XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xSingleFac.createInstance()); // configure the query xProp.setPropertyValue("Command","SELECT * FROM biblio"); xProp.setPropertyValue("EscapeProcessing", new Boolean(true)); // insert it into the query definitions container XNameContainer xCont = (XNameContainer) UnoRuntime.queryInterface( XNameContainer.class, xQDefs); try{ if ( xCont.hasByName("Query1") ) xCont.removeByName("Query1"); }catch(com.sun.star.uno.Exception e){} xCont.insertByName("Query1", xProp); XStorable store = ( XStorable)UnoRuntime.queryInterface(XStorable.class, xQuerySup); store.store(); }
Content on this page is licensed under the Public Documentation License (PDL). |