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


Python SearchType.get_column_info方法代码示例

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


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

示例1: execute

# 需要导入模块: from pyasm.search import SearchType [as 别名]
# 或者: from pyasm.search.SearchType import get_column_info [as 别名]
    def execute(my):
        assert my.db_resource
        assert my.table

        database = my.db_resource.get_database()

        from pyasm.search import Insert, Select, DbContainer, Search, Sql

        # get the data
        if not my.sobjects:
            search = Search("sthpw/search_object")

            # BAD assumption
            #search.add_filter("table", my.table)
            # create a search_type. This is bad assumption cuz it assumes project-specific search_type
            # should call set_search_type()
            if not my.search_type:
                my.search_type = "%s/%s" % (my.database, my.table)
            search.add_filter("search_type", my.search_type)

            my.search_type_obj = search.get_sobject()
            if not my.search_type_obj:
                if my.no_exception == False:
                    raise SqlException("Table [%s] does not have a corresponding search_type" % my.table)
                else:
                    return

            search_type = my.search_type_obj.get_base_key()
            search = Search(my.search_type)
            search.set_show_retired(True)
            my.sobjects = search.get_sobjects()
            
        # get the info for the table
        column_info = SearchType.get_column_info(my.search_type)

        for sobject in my.sobjects:
            print my.delimiter

            insert = Insert()
            insert.set_database(my.database)
            insert.set_table(my.table)

            data = sobject.data
            for name, value in data.items():

                if name in my.ignore_columns:
                    continue

                if not my.include_id and name == "id":
                    insert.set_value("id", '"%s_id_seq".nextval' % table, quoted=False)
                    #insert.set_value(name, value, quoted=False)
                elif value == None:
                    continue
                else:
                    # replace all of the \ with double \\
                    insert.set_value(name, value)

            print "%s" % insert.get_statement()
            print my.end_delimiter
            print
开发者ID:CeltonMcGrath,项目名称:TACTIC,代码行数:62,代码来源:sql_dumper.py

示例2: execute

# 需要导入模块: from pyasm.search import SearchType [as 别名]
# 或者: from pyasm.search.SearchType import get_column_info [as 别名]
    def execute(my):

        search_type = my.kwargs.get("search_type")
        column_info = SearchType.get_column_info(search_type)

        values = my.kwargs.get("values")

        # get the definition config for this search_type
        from pyasm.search import WidgetDbConfig
        config = WidgetDbConfig.get_by_search_type(search_type, "definition")
        if not config:
            config = SearchType.create("config/widget_config")
            config.set_value("search_type", search_type)
            config.set_value("view", "definition")
            config.commit()
            config._init()

        for data in values:

            name = data.get("name")
            name = name.strip()
            if name == '':
                continue

            try:
                name.encode('ascii')
            except UnicodeEncodeError:
                raise TacticException('Column name needs to be in English. Non-English characters can be used in Title when performing [Edit Column Definition] afterwards.')


            if column_info.get(name):
                raise CommandException("Column [%s] is already defined" % name)

            format = data.get("format")
            fps = data.get("fps")
            data_type = data.get("data_type")

            from pyasm.command import ColumnAddCmd
            cmd = ColumnAddCmd(search_type, name, data_type)
            cmd.execute()
            #(my, search_type, attr_name, attr_type, nullable=True):


            class_name = 'tactic.ui.table.FormatElementWdg'
            options = {
                'format': format,
                'type': data_type,
                'fps': fps
            }


            # add a new widget to the definition
            config.append_display_element(name, class_name, options=options)

        config.commit_config()
开发者ID:0-T-0,项目名称:TACTIC,代码行数:57,代码来源:column_edit_wdg.py

示例3: dump_tactic_inserts

# 需要导入模块: from pyasm.search import SearchType [as 别名]
# 或者: from pyasm.search.SearchType import get_column_info [as 别名]
    def dump_tactic_inserts(my, path, mode='sql'):
        assert my.db_resource
        assert my.table

        database = my.db_resource.get_database()

        assert mode in ['sql', 'sobject']

        if path:
            import os
            dirname = os.path.dirname(path)
            if not os.path.exists(dirname):
                os.makedirs(dirname)
      
            #f = open(path, 'w')
            #f = codecs.open(path, 'a', 'utf-8')
            UTF8Writer = codecs.getwriter('utf8')
            f = UTF8Writer(open(path, 'ab'))
        else:
            import sys
            f = sys.stdout

        from pyasm.search import Insert, Select, DbContainer, Search, Sql

        # get the data
        if not my.sobjects:
            search = Search("sthpw/search_object")
            search.add_filter("table_name", my.table)
            search.add_order_by("id")
            my.search_type_obj = search.get_sobject()
            if not my.search_type_obj:
                if my.no_exception == False:
                    raise Exception("Table [%s] does not have a corresponding search_type" % my.table)
                else:
                    return

            search_type = my.search_type_obj.get_base_key()
            search = Search(search_type)
            search.set_show_retired(True)
            my.sobjects = search.get_sobjects()
            
        # get the info for the table
        from pyasm.search import SearchType, Sql
        column_info = SearchType.get_column_info(my.search_type)

        for sobject in my.sobjects:
            f.write( "%s\n" % my.delimiter )


            if mode == 'sobject':
                search_type = sobject.get_base_search_type()
                f.write("insert = SearchType.create('%s')\n" % search_type)
            else:
                f.write("insert.set_table('%s')\n" % my.table)

            data = sobject.get_data()
            for name, value in data.items():
                if name in my.ignore_columns:
                    continue

                if name == '_tmp_spt_rownum':
                    continue
                if not my.include_id and name == "id":
                    #insert.set_value("id", '"%s_id_seq".nextval' % table, quoted=False)
                    pass
                elif value == None:
                    continue
                else:
                    # This is not strong enough
                    #if value.startswith("{") and value.endswith("}"):
                    #    f.write("insert.set_expr_value('%s', \"\"\"%s\"\"\")\n" % (name, value))
                    if type(value) == types.IntType or \
                            type(value) == types.FloatType or \
                            type(value) == types.BooleanType or \
                            type(value) == types.LongType:

                        f.write("insert.set_value('%s', %s)\n" % (name, value))
                    else:    
                        # if the value contains triple double quotes, convert to
                        # triple quotes
                        if isinstance(value, datetime.datetime):
                            value = str(value)
                        elif isinstance(value, unicode):
                            #value = str(value)
                            value = value.encode("UTF-8")

                        # this fixes a problem with non-ascii characters
                        if isinstance(value, basestring):
                            quoted = value.startswith('"') and value.endswith('"')
                            value = repr(value)
                            quoted2 = value.startswith('"') and value.endswith('"')
                            if not quoted and quoted2:
                                value = value.strip('"')


                            # repr puts single quotes at the start and end
                            if value.startswith("'") and value.endswith("'"):
                                value = value[1:-1]
                            # and it puts a slash in front
                            value = value.replace(r"\'", "'")
#.........这里部分代码省略.........
开发者ID:CeltonMcGrath,项目名称:TACTIC,代码行数:103,代码来源:sql_dumper.py


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