1
2
3
4
5
6 """
7 This module contains a function to build curry function.
8 """
9
11 """
12 This function generates the .sql portion of model descriptions from the raw python model
13 description code
14
15 @type curry_fname: string
16 @param curry_fname: curry function name
17 @type mid: number
18 @param mid: mid
19 @type fname: string
20 @param fname: function name
21 @type modulename: string
22 @param modulename: name of the module
23 @type path: string
24 @param path: path to the module
25 @type params: vector
26 @param params: parameters of the function
27 @type return_type: string
28 @param return_type: return type of the SQL function
29
30 @rtype: string
31 @return: SQL function
32 """
33 param_types = [ t for (p,t) in params ]
34 param_names = [ p for (p,t) in params ]
35 param_full = [ (p + " " + t) for (p,t) in params]
36
37 param_type_str = ','.join(param_types)
38 param_call_str = ','.join(param_names)
39 param_full_str = ','.join(param_full)
40
41 f= ""
42 f+= "DROP FUNCTION IF EXISTS " + curry_fname + "(" + param_type_str + ") CASCADE;\n"
43 f+= "CREATE FUNCTION " + curry_fname + "(" + param_full_str + ")\n"
44 f+= "\tRETURNS " + return_type +"\n"
45 f+= "AS $$\n"
46 f+= "import sys\n"
47 f+= "sys.append.path(path)\n"
48 f+= "import " + modulename + "\n"
49 f+= "model = GD[" + str(mid) + "]\n"
50 f+= "return "+ modulename + "." + fname + "(" + param_call_str + ")\n"
51 f+= "$$ LANGUAGE plpythonu;"
52 return f
53