Skip to main content

This package provides the SQL Script content type for Zope 3 applications. SQL Scripts are connected to execute SQL statements and the result is return in an object-oriented data structure.

Detailed Documentation

Using additional DTML tags in SQLScript

Inserting optional tests with ‘sqlgroup’

It is sometimes useful to make inputs to an SQL statement optinal. Doing so can be difficult, because not only must the test be inserted conditionally, but SQL boolean operators may or may not need to be inserted depending on whether other, possibly optional, comparisons have been done. The ‘sqlgroup’ tag automates the conditional insertion of boolean operators.

The ‘sqlgroup’ tag is a block tag that has no attributes. It can have any number of ‘and’ and ‘or’ continuation tags.

Suppose we want to find all people with a given first or nick name and optionally constrain the search by city and minimum and maximum age. Suppose we want all inputs to be optional. We can use DTML source like the following:

<dtml-sqlgroup>
  <dtml-sqlgroup>
    <dtml-sqltest name column=nick_name type=nb multiple optional>
  <dtml-or>
    <dtml-sqltest name column=first_name type=nb multiple optional>
  </dtml-sqlgroup>
<dtml-and>
  <dtml-sqltest home_town type=nb optional>
<dtml-and>
  <dtml-if minimum_age>
     age >= <dtml-sqlvar minimum_age type=int>
  </dtml-if>
<dtml-and>
  <dtml-if maximum_age>
     age <= <dtml-sqlvar maximum_age type=int>
  </dtml-if>
</dtml-sqlgroup>

This example illustrates how groups can be nested to control boolean evaluation order. It also illustrates that the grouping facility can also be used with other DTML tags like ‘if’ tags.

The ‘sqlgroup’ tag checks to see if text to be inserted contains other than whitespace characters. If it does, then it is inserted with the appropriate boolean operator, as indicated by use of an ‘and’ or ‘or’ tag, otherwise, no text is inserted.

Inserting optional tests with ‘sqlgroup’

It is sometimes useful to make inputs to an SQL statement optinal. Doing so can be difficult, because not only must the test be inserted conditionally, but SQL boolean operators may or may not need to be inserted depending on whether other, possibly optional, comparisons have been done. The ‘sqlgroup’ tag automates the conditional insertion of boolean operators.

The ‘sqlgroup’ tag is a block tag. It can have any number of ‘and’ and ‘or’ continuation tags.

The ‘sqlgroup’ tag has an optional attribure, ‘required’ to specify groups that must include at least one test. This is useful when you want to make sure that a query is qualified, but want to be very flexible about how it is qualified.

Suppose we want to find people with a given first or nick name, city or minimum and maximum age. Suppose we want all inputs to be optional, but want to require some input. We can use DTML source like the following:

<dtml-sqlgroup required>
  <dtml-sqlgroup>
    <dtml-sqltest name column=nick_name type=nb multiple optional>
  <dtml-or>
    <dtml-sqltest name column=first_name type=nb multiple optional>
  </dtml-sqlgroup>
<dtml-and>
  <dtml-sqltest home_town type=nb optional>
<dtml-and>
  <dtml-if minimum_age>
     age >= <dtml-sqlvar minimum_age type=int>
  </dtml-if>
<dtml-and>
  <dtml-if maximum_age>
     age <= <dtml-sqlvar maximum_age type=int>
  </dtml-if>
</dtml-sqlgroup>

This example illustrates how groups can be nested to control boolean evaluation order. It also illustrates that the grouping facility can also be used with other DTML tags like ‘if’ tags.

The ‘sqlgroup’ tag checks to see if text to be inserted contains other than whitespace characters. If it does, then it is inserted with the appropriate boolean operator, as indicated by use of an ‘and’ or ‘or’ tag, otherwise, no text is inserted.

Inserting values with the ‘sqlvar’ tag

The ‘sqlvar’ tag is used to type-safely insert values into SQL text. The ‘sqlvar’ tag is similar to the ‘var’ tag, except that it replaces text formatting parameters with SQL type information.

The sqlvar tag has the following attributes:

name

The name of the variable to insert. As with other DTML tags, the ‘name=’ prefix may be, and usually is, ommitted.

type

The data type of the value to be inserted. This attribute is required and may be one of ‘string’, ‘int’, ‘float’, or ‘nb’. The ‘nb’ data type indicates a string that must have a length that is greater than 0.

optional

A flag indicating that a value is optional. If a value is optional and is not provided (or is blank when a non-blank value is expected), then the string ‘null’ is inserted.

For example, given the tag:

<dtml-sqlvar x type=nb optional>

if the value of ‘x’ is:

Let\'s do it

then the text inserted is:

‘Let’’s do it’

however, if x is ommitted or an empty string, then the value inserted is ‘null’.

CHANGES

3.5.0 (2009-02-01)

  • Use zope.container instead of zope.app.container.

3.4.1 (2007-10-31)

  • Resolve ZopeSecurityPolicy deprecation warning.

3.4.0 (2007-10-27)

  • Initial release independent of the main Zope tree.

Release files for zope.app.sqlscript 3.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zope.app.sqlscript 3.5.0
File Size Uploaded
zope.app.sqlscript-3.5.0.tar.gz 19.9 kB Details

Release files / zope.app.sqlscript-3.5.0.tar.gz

Download URL zope.app.sqlscript-3.5.0.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8abaae3ab930a6962f89629729017f900192b30f952ff4fa5af9cadfb65e9b71
BLAKE2b-256 checksum
How to use checksums
f6cd3b0f5bce73fa938cdf6fedcc2e23eedf8a48147156dd8d1e62cd455aa5a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

3.5.0 This release

1 release file

3.4.1

1 release file

3.4.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page