How to use the sqlobject.col.StringCol function in SQLObject

To help you get started, we’ve selected a few SQLObject examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sqlobject / sqlobject / sqlobject / postgres / pgconnection.py View on Github external
if t.count('point'):  # poINT before INT
            return col.StringCol, {}
        elif t.count('int'):
            return col.IntCol, {}
        elif t.count('varying') or t.count('varchar'):
            if '(' in t:
                return col.StringCol, {'length': int(t[t.index('(') + 1:-1])}
            else:  # varchar without length in Postgres means any length
                return col.StringCol, {}
        elif t.startswith('character('):
            return col.StringCol, {'length': int(t[t.index('(') + 1:-1]),
                                   'varchar': False}
        elif t.count('float') or t.count('real') or t.count('double'):
            return col.FloatCol, {}
        elif t == 'text':
            return col.StringCol, {}
        elif t.startswith('timestamp'):
            return col.DateTimeCol, {}
        elif t.startswith('datetime'):
            return col.DateTimeCol, {}
        elif t.startswith('date'):
            return col.DateCol, {}
        elif t.startswith('bool'):
            return col.BoolCol, {}
        elif t.startswith('bytea'):
            return col.BLOBCol, {}
        else:
            return col.Col, {}
github stoq / stoq / external / sqlobject / sybase / sybaseconnection.py View on Github external
def guessClass(self, t):
        if t.startswith('int'):
            return col.IntCol, {}
        elif t.startswith('varchar'):
            return col.StringCol, {'length': int(t[8:-1])}
        elif t.startswith('char'):
            return col.StringCol, {'length': int(t[5:-1]),
                                   'varchar': False}
        elif t.startswith('datetime'):
            return col.DateTimeCol, {}
        else:
            return col.Col, {}
github sqlobject / sqlobject / sqlobject / mssql / mssqlconnection.py View on Github external
"""
        Here we take raw values coming out of syscolumns
        and map to SQLObject class types.

        """
        if t.startswith('int'):
            return col.IntCol, {}
        elif t.startswith('varchar'):
            if self.usingUnicodeStrings:
                return col.UnicodeCol, {'length': size}
            return col.StringCol, {'length': size}
        elif t.startswith('char'):
            if self.usingUnicodeStrings:
                return col.UnicodeCol, {'length': size,
                                        'varchar': False}
            return col.StringCol, {'length': size,
                                   'varchar': False}
        elif t.startswith('datetime'):
            return col.DateTimeCol, {}
        elif t.startswith('decimal'):
            # be careful for awkward naming
            return col.DecimalCol, {'size': precision,
                                    'precision': scale}
        else:
            return col.Col, {}
github stoq / stoq / external / sqlobject / mssql / mssqlconnection.py View on Github external
def guessClass(self, t, size, precision, scale):
        """
            Here we take raw values coming out of syscolumns and map to SQLObject class types.
        """
        if t.startswith('int'):
            return col.IntCol, {}
        elif t.startswith('varchar'):
            if self.usingUnicodeStrings:
                return col.UnicodeCol, {'length': size}
            return col.StringCol, {'length': size}
        elif t.startswith('char'):
            if self.usingUnicodeStrings:
                return col.UnicodeCol, {'length': size,
                                       'varchar': False}
            return col.StringCol, {'length': size,
                                   'varchar': False}
        elif t.startswith('datetime'):
            return col.DateTimeCol, {}
        elif t.startswith('decimal'):
            return col.DecimalCol, {'size': precision, # be careful for awkward naming
                                   'precision': scale}
        else:
            return col.Col, {}
github stoq / stoq / external / sqlobject / mysql / mysqlconnection.py View on Github external
def columnsFromSchema(self, tableName, soClass):
        colData = self.queryAll("SHOW COLUMNS FROM %s"
                                % tableName)
        results = []
        for field, t, nullAllowed, key, default, extra in colData:
            if field == soClass.sqlmeta.idName:
                continue
            colClass, kw = self.guessClass(t)
            if self.kw.get('use_unicode') and colClass is col.StringCol:
                colClass = col.UnicodeCol
                if self.dbEncoding: kw['dbEncoding'] = self.dbEncoding
            kw['name'] = soClass.sqlmeta.style.dbColumnToPythonAttr(field)
            kw['dbName'] = field

            # Since MySQL 5.0, 'NO' is returned in the NULL column (SQLObject expected '')
            kw['notNone'] = (nullAllowed.upper() != 'YES' and True or False)

            if default and t.startswith('int'):
                kw['default'] = int(default)
            elif default and t.startswith('float'):
                kw['default'] = float(default)
            elif default == 'CURRENT_TIMESTAMP' and t == 'timestamp':
                kw['default'] = None
            elif default and colClass is col.BoolCol:
                kw['default'] = int(default) and True or False
github stoq / stoq / external / sqlobject / mysql / mysqlconnection.py View on Github external
elif t.startswith('tinyblob'):
            return col.BLOBCol, {"length": 2**8-1}
        elif t.startswith('tinytext'):
            return col.StringCol, {"length": 2**8-1, "varchar": True}
        elif t.startswith('blob'):
            return col.BLOBCol, {"length": 2**16-1}
        elif t.startswith('text'):
            return col.StringCol, {"length": 2**16-1, "varchar": True}
        elif t.startswith('mediumblob'):
            return col.BLOBCol, {"length": 2**24-1}
        elif t.startswith('mediumtext'):
            return col.StringCol, {"length": 2**24-1, "varchar": True}
        elif t.startswith('longblob'):
            return col.BLOBCol, {"length": 2**32}
        elif t.startswith('longtext'):
            return col.StringCol, {"length": 2**32, "varchar": True}
        else:
            return col.Col, {}
github sqlobject / sqlobject / sqlobject / firebird / firebirdconnection.py View on Github external
return col.UnicodeCol, {'length': flength, 'varchar': False,
                                        'dbEncoding': fCharset}
            elif self.dbEncoding:
                return col.UnicodeCol, {'length': flength, 'varchar': False,
                                        'dbEncoding': self.dbEncoding}
            else:
                return col.StringCol, {'length': flength, 'varchar': False}
        elif t == 'varchar':  # 32767 bytes
            if fCharset and (fCharset != "NONE"):
                return col.UnicodeCol, {'length': flength, 'varchar': True,
                                        'dbEncoding': fCharset}
            elif self.dbEncoding:
                return col.UnicodeCol, {'length': flength, 'varchar': True,
                                        'dbEncoding': self.dbEncoding}
            else:
                return col.StringCol, {'length': flength, 'varchar': True}

        elif t == 'blob':  # 32GB
            return col.BLOBCol, {}
        else:
            return col.Col, {}
github sqlobject / sqlobject / sqlobject / col.py View on Github external
"quantize argument must be Boolean True/False"
        super(SODecimalStringCol, self).__init__(**kw)

    def createValidators(self):
        if self.quantize:
            v = DecimalStringValidator(
                name=self.name,
                precision=Decimal(10) ** (-1 * int(self.precision)),
                max=Decimal(10) ** (int(self.size) - int(self.precision)))
        else:
            v = DecimalStringValidator(name=self.name, precision=0)
        return [v] + \
            super(SODecimalStringCol, self).createValidators(dataType=Decimal)


class DecimalStringCol(StringCol):
    baseClass = SODecimalStringCol


class BinaryValidator(SOValidator):
    """
    Validator for binary types.

    We're assuming that the per-database modules provide some form
    of wrapper type for binary conversion.
    """

    _cachedValue = None

    def to_python(self, value, state):
        if value is None:
            return None
github sqlobject / sqlobject / sqlobject / sqlite / sqliteconnection.py View on Github external
def guessClass(self, t):
        t = t.upper()
        if t.find('INT') >= 0:
            return col.IntCol, {}
        elif t.find('TEXT') >= 0 or t.find('CHAR') >= 0 or t.find('CLOB') >= 0:
            return col.StringCol, {'length': 2 ** 32 - 1}
        elif t.find('BLOB') >= 0:
            return col.BLOBCol, {"length": 2 ** 32 - 1}
        elif t.find('REAL') >= 0 or t.find('FLOAT') >= 0:
            return col.FloatCol, {}
        elif t.find('DECIMAL') >= 0:
            return col.DecimalCol, {'size': None, 'precision': None}
        elif t.find('BOOL') >= 0:
            return col.BoolCol, {}
        else:
            return col.Col, {}