Difference between revisions of "Documentation/DevGuide/Database/Adding and Editing Predefined Queries"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Robot: Changing Category:Documentation/Developers Guide/Database Access)
m
 
(3 intermediate revisions by 3 users not shown)
Line 7: Line 7:
 
|NextPage=Documentation/DevGuide/Database/Runtime Settings For Predefined Queries
 
|NextPage=Documentation/DevGuide/Database/Runtime Settings For Predefined Queries
 
}}
 
}}
{{DISPLAYTITLE:Adding and Editing Predefined Queries}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Database/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Adding and Editing Predefined Queries}}
 
<!--<idltopic>com.sun.star.sdb.DefinitionContainer</idltopic>-->
 
<!--<idltopic>com.sun.star.sdb.DefinitionContainer</idltopic>-->
 
The query definitions container <idl>com.sun.star.sdb.DefinitionContainer</idl> is used to work with the query definitions of a data source. It is returned by the <idl>com.sun.star.sdb.XQueryDefinitionsSupplier</idl> interface of the data source, which has a single method for this purpose:
 
The query definitions container <idl>com.sun.star.sdb.DefinitionContainer</idl> is used to work with the query definitions of a data source. It is returned by the <idl>com.sun.star.sdb.XQueryDefinitionsSupplier</idl> interface of the data source, which has a single method for this purpose:
<source lang="idl">
+
<syntaxhighlight lang="idl">
 
   com::sun::star::container::XNameAccess getQueryDefinitions()
 
   com::sun::star::container::XNameAccess getQueryDefinitions()
</source>
+
</syntaxhighlight>
 
The <code>DefinitionContainer</code> is not only an <code>XNameAccess</code>, but a <idl>com.sun.star.container.XNameContainer</idl>, that is, add new query definitions by name (see [[Documentation/DevGuide/FirstSteps/First Steps|First Steps]]). Besides the name access, obtain query definitions through <idl>com.sun.star.container.XIndexAccess</idl> and <idl>com.sun.star.container.XEnumerationAccess</idl>.
 
The <code>DefinitionContainer</code> is not only an <code>XNameAccess</code>, but a <idl>com.sun.star.container.XNameContainer</idl>, that is, add new query definitions by name (see [[Documentation/DevGuide/FirstSteps/First Steps|First Steps]]). Besides the name access, obtain query definitions through <idl>com.sun.star.container.XIndexAccess</idl> and <idl>com.sun.star.container.XEnumerationAccess</idl>.
  
Line 19: 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.
  
{{Documentation/Note|The optional interface <idl>com.sun.star.util.XRefreshable</idl> is not supported by the <tt>DefinitionContainer</tt> implementation.}}
+
{{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:
Line 34: Line 35:
 
|-
 
|-
 
|<idlm>com.sun.star.sdb.QueryDefinition:EscapeProcessing</idlm>  
 
|<idlm>com.sun.star.sdb.QueryDefinition:EscapeProcessing</idlm>  
|<code>boolean</code> - If true, determines that the query must not be touched by the built-in SQL parser of {{PRODUCTNAME}} API.  
+
|<code>boolean</code> - If true, determines that the query must not be touched by the built-in SQL parser of {{AOo}} API.  
 
|-
 
|-
 
|<idlm>com.sun.star.sdb.QueryDefinition:UpdateCatalogName</idlm>  
 
|<idlm>com.sun.star.sdb.QueryDefinition:UpdateCatalogName</idlm>  
Line 46: Line 47:
 
|}
 
|}
  
The following example adds a new query definition <code>Query1</code> to the data source Bibliography that is provided with {{PRODUCTNAME}} API.  
+
The following example adds a new query definition <code>Query1</code> to the data source Bibliography that is provided with {{AOo}} API.  
 
<!--[SOURCE:Database/CodeSamples.java]-->
 
<!--[SOURCE:Database/CodeSamples.java]-->
<source lang="java">
+
<syntaxhighlight lang="java">
 
   // creates a new query definition named Query1
 
   // creates a new query definition named Query1
 
   public static void createQuerydefinition(XMultiServiceFactory _rMSF) throws com.sun.star.uno.Exception {
 
   public static void createQuerydefinition(XMultiServiceFactory _rMSF) throws com.sun.star.uno.Exception {
Line 87: Line 88:
 
       store.store();
 
       store.store();
 
   }
 
   }
</source>
+
</syntaxhighlight>
 
{{PDL1}}
 
{{PDL1}}
  
 
[[Category:Documentation/Developer's Guide/Database Access]]
 
[[Category:Documentation/Developer's Guide/Database Access]]

Latest revision as of 13:36, 21 December 2020



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.

DefinitionContainer And QueryDefinition

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.

Documentation note.png 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 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 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).
Personal tools
In other languages