Project

General

Profile

« Previous | Next » 

Revision 3423

sql.py: function_exists(): Use simpler cast to regproc instead of query of information_schema.routines to determine if function exists. When the schema is not specified, this also limits the schemas checked to the search_path instead of the whole DB.

View differences:

lib/sql.py
1129 1129
#### Functions
1130 1130

  
1131 1131
def function_exists(db, function):
1132
    function = sql_gen.as_Function(function)
1133
    
1134
    info_table = sql_gen.Table('routines', 'information_schema')
1135
    conds = [('routine_name', function.name)]
1136
    schema = function.schema
1137
    if schema != None: conds.append(('routine_schema', schema))
1138
    # Exclude trigger functions, since they cannot be called directly
1139
    conds.append(('data_type', sql_gen.CompareCond('trigger', '!=')))
1140
    
1141
    return list(values(select(db, info_table, ['routine_name'], conds,
1142
        order_by='routine_schema', limit=1, log_level=4))) != []
1143
        # TODO: order_by search_path schema order
1132
    qual_function = sql_gen.Literal(function.to_str(db))
1133
    try:
1134
        select(db, fields=[sql_gen.Cast('regproc', qual_function)], log_level=4)
1135
    except DoesNotExistException: return False
1136
    else: return True
1144 1137

  
1145 1138
##### Structural changes
1146 1139

  

Also available in: Unified diff