home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.os.vms      DEC's VAX* line of computers & VMS.      264,096 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 263,810 of 264,096   
   =?UTF-8?Q?Arne_Vajh=C3=B8j?= to All   
   Re: And so? (VMS/XDE)   
   20 Nov 25 19:55:21   
   
   From: arne@vajhoej.dk   
      
   Let me demo SQLPY "Embedded SQL for Python".   
      
   :-) :-) :-)   
      
   Mostly based on SQLJ.   
      
   $ type test.sqlpy   
   import pymysql   
      
   *sql context ConCtx   
      
   *sql iterator T1Iter   
      
   def t1_get_one(con, f2):   
        ctx = ConCtx(con)   
        it = T1Iter()   
        *sql [ctx] it = { SELECT f1 FROM t1 WHERE f2 = :f2}   
        *sql { fetch :it INTO :f1 }   
        return f1   
      
   def t1_get_all(con):   
        ctx = ConCtx(con)   
        it = T1Iter()   
        *sql [ctx] it = { SELECT f1,f2 FROM t1 }   
        res = []   
        while not it.endfetch():   
            *sql { fetch :it INTO :f1, :f2 }   
            res.append([f1, f2])   
        return res   
      
   def t1_put(con, f1, f2):   
        ctx = ConCtx(con)   
        *sql [ctx] { INSERT INTO t1 VALUES(:f1,:f2) }   
      
   def t1_remove(con, f1):   
        ctx = ConCtx(con)   
        *sql [ctx] { DELETE FROM t1 WHERE f1 = :f1 }   
      
   def t1_display(data):   
        for row in data:   
            print('%d %s' % (row[0], row[1]))   
      
   con =   
   pymysql.connect(host='arnepc5',user='arne',password='hemmeligt',db='Test')   
   f1 = t1_get_one(con, 'BB')   
   print(f1)   
   data = t1_get_all(con)   
   t1_display(data)   
   t1_put(con, 999, 'XXX')   
   data = t1_get_all(con)   
   t1_display(data)   
   t1_remove(con, 999)   
   data = t1_get_all(con)   
   t1_display(data)   
   con.commit()   
   con.close()   
      
   $ python sqlpy.py TEST.sqlpy TEST.py   
   $ python TEST.py   
   2   
   1 A   
   2 BB   
   3 CCC   
   1 A   
   2 BB   
   3 CCC   
   999 XXX   
   1 A   
   2 BB   
   3 CCC   
      
   Arne   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca