Adding and Editing Predefined Queries

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 13:36, 21 December 2020 by DiGro (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The query definitions container is used to work with the query definitions of a data source. It is returned by the 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, that is, add new query definitions by name (see First Steps). Besides the name access, obtain query definitions through and

DefinitionContainer And QueryDefinition

New query definitions are created by the 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.

Documentation note.png The optional interface is not supported by the DefinitionContainer implementation.

A QueryDefinition is configured through the following properties:

Properties of
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 Apache OpenOffice 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 Apache OpenOffice API.

  // creates a new query definition named Query1
  public static void createQuerydefinition(XMultiServiceFactory _rMSF) throws {
      XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface(
          XNameAccess.class, _rMSF.createInstance( "") );
      // 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 interface 
      // of the query definitions container
      XSingleServiceFactory xSingleFac = (XSingleServiceFactory)UnoRuntime.queryInterface(
          XSingleServiceFactory.class, xQDefs);
      // order a new query and get its 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);
          if ( xCont.hasByName("Query1") )
      }catch( e){}
      xCont.insertByName("Query1", xProp);
      XStorable store = ( XStorable)UnoRuntime.queryInterface(XStorable.class, xQuerySup);;
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages