relalg1.py :  » Database » Gadfly » gadflyZip » relalg » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Database » Gadfly 
Gadfly » gadflyZip » relalg » relalg1.py

"load the drinkers db and run statement sequence"


DB = """

COMMENT examples for relational algebra

COMMENT frequents
frequents  = [dr ba pw] (
  'adam'  'lolas'    1,
  'woody'  'cheers'  5,
  'sam'    'cheers'  5,
  'norm'  'cheers'  3,
  'wilt'  'joes'    2,
  'norm'  'joes'    1,
  'lola'  'lolas'    6,
  'norm'  'lolas'    2,
  'woody'  'lolas'    1,
  'pierre'  'frankies'  0
);

COMMENT serves
serves = [ba be qt] (
  'cheers'  'bud'    500,
  'cheers'  'samaddams'  255,
  'joes'  'bud'    217,
  'joes'  'samaddams'  13,
  'joes'  'mickies'  2222,
  'lolas'  'mickies'  1515,
  'lolas'  'pabst'    333,
  'winkos'  'rollingrock'  432,
  'frankies'  'snafu'    5
);

COMMENT likes
likes = [dr be pd] (
  'adam'  'bud'      2,
  'wilt'  'rollingrock'  1,
  'sam'    'bud'      2,
  'norm'  'rollingrock'    3,
  'norm'  'bud'      2,
  'nan'    'sierranevada'  1,  
  'woody'  'pabst'      2,
  'lola'  'mickies'    5
);
"""
   
def runfile2(f):
    from relalg import reloadrelalg
    from string import split,join
    ragram = reloadrelalg()
    context = {}
    #f = open(filename, "r")
    data = f.read()
    #f.close()
    from string import split,strip
    commands = split(data, ";")
    for c in commands:
        if not strip(c): continue
        #print " COMMAND:"
        data = str(c)
        pdata = "  "+join(split(c, "\n"), "\n  ")
        #print pdata
        test = ragram.DoParse1(c, context)
        print

def runStrings(inputString):
    from StringIO import StringIO
    import sys, string, traceback, sys
    fullinputstring = "%s ; \n\n%s" % (DB, inputString)
    inputfile = StringIO(fullinputstring)
    outputfile = StringIO()
    stdoutSave = sys.stdout
    sys.stdout = outputfile
    try:
        runfile2(inputfile)
    except:
        print "******************"
        print "error processing statement(s):"
        print inputString
        print sys.exc_type
        print sys.exc_value
        print "*******************"
    sys.stdout = stdoutSave
    output = string.strip(outputfile.getvalue())
    return output

if __name__=="__main__":
    for st in [
        """
        COMMENT bad expression here, should cause an error
        bad expression here
        """,
        """
        COMMENT list the database
        frequents;
        serves;
        likes
        """,
        """
        COMMENT drinkers who like beers
        projection[dr] likes
        """,
        ]:
        print "==="
        print st
        print "==="
        print runStrings(st)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.