@@ -32,8 +32,8 @@ class App:
3232 """the GUI graphic application"""
3333 def __init__ (self ):
3434 """create a tkk graphic interface with a main window tk_win"""
35- self .__version__ = '0.9.2 '
36- self ._title = "of 2021-04-20a : 'Give PyPy a chance !'"
35+ self .__version__ = '0.9.3 '
36+ self ._title = "of 2021-04-25a : 'Hello, World !'"
3737 self .conn = None # Baresql database object
3838 self .database_file = ""
3939 self .tk_win = Tk ()
@@ -1388,14 +1388,15 @@ def execute(self, sql, env=None):
13881388
13891389 def createpydef (self , sql ):
13901390 """generates and register a pydef instruction"""
1391+ import re
13911392 instruction = sql .strip ('; \t \n \r ' )
13921393 # create Python function in Python
13931394 exec (instruction [2 :], globals (), locals ())
13941395 # add Python function in SQLite
1395- firstline = ( instruction [ 5 :]. splitlines ()[ 0 ]). lstrip ()
1396- firstline = firstline . replace ( " " , "" ) + "("
1397- instr_name = firstline . split ( "(" , 1 )[ 0 ]. strip ()
1398- instr_parms = firstline . count ( ',' ) + 1
1396+ instr_header = re . findall ( '\w+' ,
1397+ instruction [:( instruction + ')' ). find ( ')' )])
1398+ instr_name = instr_header [ 1 ]
1399+ instr_parms = len ( instr_header ) - 2
13991400 instr_add = (("self.conn.create_function('%s', %s, %s)" % (
14001401 instr_name , instr_parms , instr_name )))
14011402 exec (instr_add , globals (), locals ())
@@ -1580,6 +1581,9 @@ def _main():
15801581INSERT INTO item select "A","Merced",1250 union all select "W","Wheel",9 ;
15811582INSERT INTO part select ItemNo,"W","needed",Kg/250 from item where Kg>250;
15821583\n -- to CREATE a Python embedded function (enclose them by "py" and ";") :
1584+ pydef py_hello():
1585+ "hello world"
1586+ return ("Hello, World !");
15831587pydef py_sin(s):
15841588 "sinus function : example loading module, handling input/output as strings"
15851589 import math as py_math
@@ -1588,12 +1592,13 @@ def _main():
15881592 "fibonacci : example with function call (may only be internal) "
15891593 fib = lambda n: n if n < 2 else fib(n-1) + fib(n-2)
15901594 return("%s" % fib(n*1));
1591- pydef py_power(x,y):
1595+ pydef py_power(x,
1596+ y):
15921597 "power function : example loading module, handling input/output as strings"
15931598 import math as py_math
15941599 return ("%s" % ((x*1) ** (y*1)) );
15951600\n -- to USE a python embedded function and nesting of embedded functions:
1596- select py_sin(1) as sinus, py_power(2, 1*py_fib(6)) as power, sqlite_version();
1601+ select py_hello(), py_sin(1) as sinus, py_power(2, 1*py_fib(6)) as power, sqlite_version();
15971602\n -- to EXPORT :
15981603-- a TABLE, select TABLE, then click on icon 'SQL->CSV'
15991604-- a QUERY RESULT, select the SCRIPT text, then click on icon '???->CSV',
0 commit comments