当前位置: 首页>>代码示例>>Python>>正文


Python types.NVARCHAR属性代码示例

本文整理汇总了Python中sqlalchemy.types.NVARCHAR属性的典型用法代码示例。如果您正苦于以下问题:Python types.NVARCHAR属性的具体用法?Python types.NVARCHAR怎么用?Python types.NVARCHAR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在sqlalchemy.types的用法示例。


在下文中一共展示了types.NVARCHAR属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: insert_other_db

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NVARCHAR [as 别名]
def insert_other_db(to_db, data, table_name, write_index, primary_keys):
    # 定义engine
    engine_mysql = engine_to_db(to_db)
    # 使用 http://docs.sqlalchemy.org/en/latest/core/reflection.html
    # 使用检查检查数据库表是否有主键。
    insp = inspect(engine_mysql)
    col_name_list = data.columns.tolist()
    # 如果有索引,把索引增加到varchar上面。
    if write_index:
        # 插入到第一个位置:
        col_name_list.insert(0, data.index.name)
    print(col_name_list)
    data.to_sql(name=table_name, con=engine_mysql, schema=to_db, if_exists='append',
                dtype={col_name: NVARCHAR(length=255) for col_name in col_name_list}, index=write_index)
    # 判断是否存在主键
    if insp.get_primary_keys(table_name) == []:
        with engine_mysql.connect() as con:
            # 执行数据库插入数据。
            try:
                con.execute('ALTER TABLE `%s` ADD PRIMARY KEY (%s);' % (table_name, primary_keys))
            except  Exception as e:
                print("################## ADD PRIMARY KEY ERROR :", e)


# 插入数据。 
开发者ID:pythonstock,项目名称:stock,代码行数:27,代码来源:common.py

示例2: test_char_length

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NVARCHAR [as 别名]
def test_char_length(self):
        metadata = self.metadata
        t1 = Table(
            "t1",
            metadata,
            Column("c1", VARCHAR(50)),
            Column("c2", NVARCHAR(250)),
            Column("c3", CHAR(200)),
            Column("c4", NCHAR(180)),
        )
        t1.create()
        m2 = MetaData(testing.db)
        t2 = Table("t1", m2, autoload=True)
        eq_(t2.c.c1.type.length, 50)
        eq_(t2.c.c2.type.length, 250)
        eq_(t2.c.c3.type.length, 200)
        eq_(t2.c.c4.type.length, 180) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_types.py

示例3: test_sql_alchemy_subclass_column_types

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NVARCHAR [as 别名]
def test_sql_alchemy_subclass_column_types():
    class F(FilterSet):
        ALLOWED_FILTERS = {types.Integer: ['eq', 'gt']}

        class Meta:
            abstract = True

    class MyNVARCHAR(types.NVARCHAR):
        pass

    class TestModel(Base):
        __tablename__ = 'test'

        id = Column(types.SmallInteger, primary_key=True, autoincrement=True)
        text = Column(MyNVARCHAR)

    class TestFilter(F):
        EXTRA_ALLOWED_FILTERS = {types.String: ['eq']}

        class Meta:
            model = TestModel
            fields = {'id': [...], 'text': [...]}

    filter_fields = set(TestFilter._meta.fields)
    ok = {'id', 'id_gt', 'text', 'text_is_null', 'and', 'not', 'or'}

    assert filter_fields == ok 
开发者ID:art1415926535,项目名称:graphene-sqlalchemy-filter,代码行数:29,代码来源:test_filter_set.py

示例4: __init__

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NVARCHAR [as 别名]
def __init__(self, length=None, collation=None,
                 convert_unicode='force',
                 unicode_error=None):
        super(NVARCHAR, self).__init__(
            length,
            collation=collation,
            convert_unicode=convert_unicode,
            unicode_error='ignore') 
开发者ID:deontologician,项目名称:netezza_sqlalchemy,代码行数:10,代码来源:netezza_dialect.py

示例5: test_reflect_nvarchar

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NVARCHAR [as 别名]
def test_reflect_nvarchar(self):
        metadata = self.metadata
        Table(
            "tnv",
            metadata,
            Column("nv_data", sqltypes.NVARCHAR(255)),
            Column("c_data", sqltypes.NCHAR(20)),
        )
        metadata.create_all()
        m2 = MetaData(testing.db)
        t2 = Table("tnv", m2, autoload=True)
        assert isinstance(t2.c.nv_data.type, sqltypes.NVARCHAR)
        assert isinstance(t2.c.c_data.type, sqltypes.NCHAR)

        if testing.against("oracle+cx_oracle"):
            assert isinstance(
                t2.c.nv_data.type.dialect_impl(testing.db.dialect),
                cx_oracle._OracleUnicodeStringNCHAR,
            )

            assert isinstance(
                t2.c.c_data.type.dialect_impl(testing.db.dialect),
                cx_oracle._OracleNChar,
            )

        data = u("m’a réveillé.")
        with testing.db.connect() as conn:
            conn.execute(t2.insert(), dict(nv_data=data, c_data=data))
            nv_data, c_data = conn.execute(t2.select()).first()
            eq_(nv_data, data)
            eq_(c_data, data + (" " * 7))  # char is space padded
            assert isinstance(nv_data, util.text_type)
            assert isinstance(c_data, util.text_type) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:35,代码来源:test_types.py

示例6: _get_column_info

# 需要导入模块: from sqlalchemy import types [as 别名]
# 或者: from sqlalchemy.types import NVARCHAR [as 别名]
def _get_column_info(
        self,
        name,
        type_,
        nullable,
        autoincrement,
        default,
        precision,
        scale,
        length,
    ):

        coltype = self.ischema_names.get(type_, None)

        kwargs = {}

        if coltype in (NUMERIC, DECIMAL):
            args = (precision, scale)
        elif coltype == FLOAT:
            args = (precision,)
        elif coltype in (CHAR, VARCHAR, UNICHAR, UNIVARCHAR, NCHAR, NVARCHAR):
            args = (length,)
        else:
            args = ()

        if coltype:
            coltype = coltype(*args, **kwargs)
            # is this necessary
            # if is_array:
            #     coltype = ARRAY(coltype)
        else:
            util.warn(
                "Did not recognize type '%s' of column '%s'" % (type_, name)
            )
            coltype = sqltypes.NULLTYPE

        if default:
            default = default.replace("DEFAULT", "").strip()
            default = re.sub("^'(.*)'$", lambda m: m.group(1), default)
        else:
            default = None

        column_info = dict(
            name=name,
            type=coltype,
            nullable=nullable,
            default=default,
            autoincrement=autoincrement,
        )
        return column_info 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:52,代码来源:base.py


注:本文中的sqlalchemy.types.NVARCHAR属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。