import math


def extend_sqlite_functions(connection=None, **kwargs):
    """
    Extends SQLite with trigonometry functions
    """
    if connection and connection.vendor == 'sqlite':
        connection.connection.create_function("sin", 1, math.sin)
        connection.connection.create_function("cos", 1, math.cos)
        connection.connection.create_function("acos", 1, math.acos)
        connection.connection.create_function("degrees", 1, math.degrees)
        connection.connection.create_function("radians", 1, math.radians)

import math


def float_wrap(value, func):
    try:
        return func(float(value))
    except:
        return None


def extend_sqlite_functions(connection=None, **kwargs):
    """
    Extends SQLite with trigonometry functions
    """
    if connection and connection.vendor == 'sqlite':
        connection.connection.create_function("sin", 1, lambda x: float_wrap(x, math.sin))
        connection.connection.create_function("cos", 1, lambda x: float_wrap(x, math.cos))
        connection.connection.create_function("acos", 1, lambda x: float_wrap(x, math.acos))
        connection.connection.create_function("degrees", 1, lambda x: float_wrap(x, math.degrees))
        connection.connection.create_function("radians", 1, lambda x: float_wrap(x, math.radians))

Add wrapper to parse values to float in SQLite
Add wrapper to parse values to float in SQLite

Refs TREES-359

  import math
+ 
+ 
+ def float_wrap(value, func):
+     try:
+         return func(float(value))
+     except:
+         return None
  
  
  def extend_sqlite_functions(connection=None, **kwargs):
      """
      Extends SQLite with trigonometry functions
      """
      if connection and connection.vendor == 'sqlite':
-         connection.connection.create_function("sin", 1, math.sin)
+         connection.connection.create_function("sin", 1, lambda x: float_wrap(x, math.sin))
-         connection.connection.create_function("cos", 1, math.cos)
+         connection.connection.create_function("cos", 1, lambda x: float_wrap(x, math.cos))
-         connection.connection.create_function("acos", 1, math.acos)
+         connection.connection.create_function("acos", 1, lambda x: float_wrap(x, math.acos))
-         connection.connection.create_function("degrees", 1, math.degrees)
+         connection.connection.create_function("degrees", 1, lambda x: float_wrap(x, math.degrees))
-         connection.connection.create_function("radians", 1, math.radians)
+         connection.connection.create_function("radians", 1, lambda x: float_wrap(x, math.radians))
  
Add wrapper to parse values to float in SQLite
## Code Before:
import math


def extend_sqlite_functions(connection=None, **kwargs):
    """
    Extends SQLite with trigonometry functions
    """
    if connection and connection.vendor == 'sqlite':
        connection.connection.create_function("sin", 1, math.sin)
        connection.connection.create_function("cos", 1, math.cos)
        connection.connection.create_function("acos", 1, math.acos)
        connection.connection.create_function("degrees", 1, math.degrees)
        connection.connection.create_function("radians", 1, math.radians)

## Instruction:
Add wrapper to parse values to float in SQLite
## Code After:
import math


def float_wrap(value, func):
    try:
        return func(float(value))
    except:
        return None


def extend_sqlite_functions(connection=None, **kwargs):
    """
    Extends SQLite with trigonometry functions
    """
    if connection and connection.vendor == 'sqlite':
        connection.connection.create_function("sin", 1, lambda x: float_wrap(x, math.sin))
        connection.connection.create_function("cos", 1, lambda x: float_wrap(x, math.cos))
        connection.connection.create_function("acos", 1, lambda x: float_wrap(x, math.acos))
        connection.connection.create_function("degrees", 1, lambda x: float_wrap(x, math.degrees))
        connection.connection.create_function("radians", 1, lambda x: float_wrap(x, math.radians))
