[Zope3-checkins] CVS: Zope3/src/zope/app/content - sql.py:1.11

Jeremy Hylton cvs-admin at zope.org
Tue Nov 4 21:46:37 EST 2003


Update of /cvs-repository/Zope3/src/zope/app/content
In directory cvs.zope.org:/tmp/cvs-serv4548

Modified Files:
	sql.py 
Log Message:
Remove more duplicate code.


=== Zope3/src/zope/app/content/sql.py 1.10 => 1.11 ===
--- Zope3/src/zope/app/content/sql.py:1.10	Tue Nov  4 21:43:34 2003
+++ Zope3/src/zope/app/content/sql.py	Tue Nov  4 21:46:36 2003
@@ -239,98 +239,6 @@
     return parseArguments(text[length:], result)
 
 
-class SQLVar:
-    name = 'sqlvar'
-
-    # Some defaults
-    sql_delimiter = '\0'
-
-    def sql_quote__(self, v):
-        if v.find("\'") >= 0:
-            v = "''".join(v.split("\'"))
-        return "'%s'" %v
-
-    def __init__(self, args):
-        args = parse_params(args, name='', expr='', type=None, optional=1)
-
-        name, expr = name_param(args, 'sqlvar', 1)
-        if expr is None:
-            expr = name
-        else:
-            expr = expr.eval
-        self.__name__, self.expr = name, expr
-
-        self.args = args
-        if not args.has_key('type'):
-            raise ParseError, ('the type attribute is required', 'dtvar')
-
-        t = args['type']
-        if not valid_type(t):
-            raise ParseError, ('invalid type, %s' % t, 'dtvar')
-
-
-    def render(self, md):
-        name = self.__name__
-        args = self.args
-        t = args['type']
-        try:
-            expr = self.expr
-            if isinstance(expr, StringTypes):
-                v = md[expr]
-            else:
-                v = expr(md)
-        except (KeyError, ValueError):
-            if args.has_key('optional') and args['optional']:
-                return 'null'
-            if not isinstance(expr, StringTypes):
-                raise
-            raise MissingInput, 'Missing input variable, **%s**' % name
-
-        # XXX Shrug, should these types be really hard coded? What about
-        # Dates and other types a DB supports; I think we should make this
-        # a plugin.
-        # We might be able to reuse some of the widget conversion code. (SR)
-        if t == 'int':
-            try:
-                if isinstance(v, StringTypes):
-                    int(v)
-                else:
-                    v = str(int(v))
-            except ValueError:
-                if not v and args.has_key('optional') and args['optional']:
-                    return 'null'
-                raise ValueError, (
-                    'Invalid integer value for **%s**' % name)
-
-        elif t == 'float':
-            try:
-                if isinstance(v, StringTypes):
-                    float(v)
-                else:
-                    v = str(float(v))
-            except ValueError:
-                if not v and args.has_key('optional') and args['optional']:
-                    return 'null'
-                raise ValueError, (
-                    'Invalid floating-point value for **%s**' % name)
-
-        else:
-            orig_v = v
-            v = str(v)
-            if (not v or orig_v is None) and t == 'nb':
-                if args.has_key('optional') and args['optional']:
-                    return 'null'
-                else:
-                    raise ValueError, (
-                        'Invalid empty string value for **%s**' % name)
-
-            v = self.sql_quote__(v)
-
-        return v
-
-    __call__ = render
-
-
 class SQLTest:
     name = 'sqltest'
     optional = multiple = None




More information about the Zope3-Checkins mailing list