import re


def _convert_to_db_type(sval):
    """ Detect which database type (string, int, float) is most appropriate for sval
        and convert it to its corresponding database type. """

    # floats: Ex. 1.23, 0.23, .23
    if re.search(r'^\s*\d*\.\d+\s*$', sval):
        return float(sval)

    # ints: Ex. 0, 123
    if re.search(r'^\s*\d+\s*$', sval):
        return int(sval)

    # strings: anything else
    return sval