home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / SQL.PY < prev    next >
Encoding:
Python Source  |  2000-11-13  |  7.5 KB  |  195 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64. __doc__='''SQL Methods
  65.  
  66.  
  67. $Id: SQL.py,v 1.13.16.1 2000/11/13 17:04:58 brian Exp $'''
  68. __version__='$Revision: 1.13.16.1 $'[11:-2]
  69.  
  70. import Shared.DC.ZRDB.DA
  71. from Globals import HTMLFile
  72.  
  73. def SQLConnectionIDs(self):
  74.     """Find SQL database connections in the current folder and above
  75.  
  76.     This function return a list of ids.
  77.     """
  78.     ids={}
  79.     have_id=ids.has_key
  80.     StringType=type('')
  81.  
  82.     while self is not None:
  83.         if hasattr(self, 'objectValues'):
  84.             for o in self.objectValues():
  85.                 if (hasattr(o,'_isAnSQLConnection') and o._isAnSQLConnection
  86.                     and hasattr(o,'id')):
  87.                     id=o.id
  88.                     if type(id) is not StringType: id=id()
  89.                     if not have_id(id):
  90.                         if hasattr(o,'title_and_id'): o=o.title_and_id()
  91.                         else: o=id
  92.                         ids[id]=id
  93.         if hasattr(self, 'aq_parent'): self=self.aq_parent
  94.         else: self=None
  95.  
  96.     ids=map(lambda item: (item[1], item[0]), ids.items())
  97.     ids.sort()
  98.     return ids
  99.  
  100. manage_addZSQLMethodForm=HTMLFile('add', globals())
  101. def manage_addZSQLMethod(self, id, title,
  102.                                 connection_id, arguments, template,
  103.                                 REQUEST=None, submit=None):
  104.     """Add an SQL Method
  105.  
  106.     The 'connection_id' argument is the id of a database connection
  107.     that resides in the current folder or in a folder above the
  108.     current folder.  The database should understand SQL.
  109.  
  110.     The 'arguments' argument is a string containing an arguments
  111.     specification, as would be given in the SQL method cration form.
  112.  
  113.     The 'template' argument is a string containing the source for the
  114.     SQL Template.
  115.     """
  116.  
  117.     # Note - type checking is handled by _setObject and constructor.
  118.     self._setObject(id, SQL(id, title, connection_id, arguments, template))
  119.     if REQUEST is not None:
  120.         try: u=self.DestinationURL()
  121.         except: u=REQUEST['URL1']
  122.         if submit==" Add and Edit ":
  123.             u="%s/%s/manage_main" % (u,id)
  124.         elif submit==" Add and Test ":
  125.             u="%s/%s/manage_testForm" % (u,id)
  126.         else:
  127.             u=u+'/manage_main'
  128.             
  129.         REQUEST.RESPONSE.redirect(u)
  130.     return ''
  131.  
  132. class SQL(Shared.DC.ZRDB.DA.DA):
  133.     """SQL Database methods
  134.  
  135.     SQL Database methods are used to access external SQL databases.
  136.  
  137.     They support three important abstractions:
  138.  
  139.       - Method
  140.  
  141.         SQL Methods behave like methods of the folders they are
  142.         accessed in.  In particular, they can be used from other
  143.         methods, like Documents, ExternalMethods, and even other SQL
  144.         Methods.
  145.  
  146.       - Searchability
  147.  
  148.         Database methods support the Searchable Object Interface.
  149.         Search interface wizards can be used to build user
  150.         interfaces to them.  They can be used in joins and
  151.         unions. They provide meta-data about their input parameters
  152.         and result data.
  153.  
  154.         For more information, see the searchable-object interface
  155.         specification. 
  156.  
  157.       - Containment
  158.  
  159.         Database methods support URL traversal to access and invoke
  160.         methods on individual record objects. For example, suppose you
  161.         had an 'employees' database method that took a single argument
  162.         'employee_id'.  Suppose that employees had a 'service_record'
  163.         method (defined in a record class or acquired from a
  164.         folder). The 'service_record' method could be accessed with a
  165.         URL like::
  166.  
  167.            employees/employee_id/1234/service_record
  168.  
  169.     """
  170.     meta_type='Z SQL Method'
  171.                 
  172.     manage_main=HTMLFile('edit', globals())
  173.  
  174.