예제 #1
0
def copyTableListToClipboard(cat):
    #insert = ['`'+schema.name+'`.`'+tbl.name+'`' for tbl in schema.tables for schema in cat.schemata ]
    insert = ''
    for schema in cat.schemata:
        insert = ', '.join([
            '`' + schema.name + '`.`' + tbl.name + '`' for tbl in schema.tables
        ])

    Workbench.copyToClipboard(insert)
    return 0
예제 #2
0
def copySQLToClipboard(obj):
    script = []
    # workaround until diff sql generator handles routine groups
    if isinstance(obj, grt.classes.db_RoutineGroup):
        for routine in obj.routines:
            script.append(
                grt.modules.DbMySQL.makeCreateScriptForObject(routine))
            script.append(';\n\n')
    else:
        script.append(grt.modules.DbMySQL.makeCreateScriptForObject(obj))

    Workbench.copyToClipboard(''.join(script))
    return 0
    def export_table_clipboard(self):
        #print table.inserts.methods
        #print table.foreignKeys.columns
        #print table.name
        #Primary key
        table = self.catalog
        dict_pk = {}
        for column in table.primaryKey.columns:
            dict_pk[column.referencedColumn.name] = 1

        no_default_key = ""
        if dict_pk.get('id') == None or len(table.primaryKey.columns) > 1:
            no_default_key = ",{id: false} "

        #foreign key
        dict_fk = {}
        for keys in table.foreignKeys:
            quantidade_colunas = len(keys.columns)
            maiu_column = ""
            # if it dos have more than one column the code is broken
            for column in keys.columns:
                dict_fk[column.name] = {}
                maiu_column = column.name

            for column in keys.referencedColumns:
                dict_fk[maiu_column]['primary_key'] = column.name
                dict_fk[maiu_column]['table'] = column.owner.name

        rails_name = self.camelize(table.name)
        rails_field_name = ""
        rails_format = ""

        instrucao_coluna = '{"mockup":\n'
        instrucao_coluna += '    {"controls":\n'
        instrucao_coluna += '       {"control":[ \n'

        instrucao_chaves = ""
        quantidade_colunas = len(table.columns)
        contador = 1
        posicao_x = 108
        posicao_y = 124
        tamanho_label_x = 56
        posicao_x_inputs = 251
        colunas_grid = ""
        dados_dump = ""
        dados_dump_2 = ""
        comments = ""
        for column in table.columns:
            #print   column
            #print   column.name
            #print   dict.get(column.name)
            converted_field = self.convert_migration_type(column)
            if column.name != 'created_at' and column.name != 'updated_at' and column.name != 'deleted_at' and column.name != 'id':
                instrucao_coluna += '{"ID":"' + str(self.generate_id(
                )) + '","measuredH":"21","measuredW":"' + str(
                    tamanho_label_x
                ) + '","properties":{"text":"' + self.humanize(
                    column.name) + ': "},"typeID":"Label","x":"' + str(
                        posicao_x) + '","y":"' + str(
                            posicao_y) + '","zOrder":"1"}, \n'
                colunas_grid += self.humanize(column.name) + " ^v,"

                if column.comment != None and column.comment != '':
                    comments += column.name + ": " + column.comment + "\\n"

                if dict_fk.get(column.name) == None:
                    if converted_field == "TextInput":
                        instrucao_coluna += '{"ID":"' + str(
                            self.generate_id()
                        ) + '","measuredH":"27","measuredW":"200","properties":{"text":""},"typeID":"TextInput","w":"283", "x":"' + str(
                            posicao_x_inputs) + '","y":"' + str(
                                posicao_y - 3) + '","zOrder":"1"},\n'
                        dados_dump += "Dado qualquer ,"
                        dados_dump_2 += "Dado 2 ,"
                    elif converted_field == "ComboBox":
                        instrucao_coluna += '{"ID":"' + str(
                            self.generate_id()
                        ) + '","measuredH":"27","measuredW":"200","properties":{"text":""},"typeID":"ComboBox","w":"283", "x":"' + str(
                            posicao_x_inputs) + '","y":"' + str(
                                posicao_y - 3) + '","zOrder":"1"},\n'
                        dados_dump += "Dado ,"
                        dados_dump_2 += "Dado Combo ,"
                    elif converted_field == "DateChooser":
                        instrucao_coluna += '{"ID":"' + str(
                            self.generate_id()
                        ) + '","measuredH":"27","measuredW":"200","properties":{"text":"  /  /    "},"typeID":"DateChooser","w":"148", "x":"' + str(
                            posicao_x_inputs) + '","y":"' + str(
                                posicao_y - 3) + '","zOrder":"1"},\n'
                        dados_dump += "25/08/2020 ,"
                        dados_dump_2 += "11/04/2010 ,"
                    elif converted_field == "NumericStepper":
                        instrucao_coluna += '{"ID":"' + str(
                            self.generate_id()
                        ) + '","measuredH":"27","measuredW":"200","properties":{"text":""},"typeID":"NumericStepper","w":"148", "x":"' + str(
                            posicao_x_inputs) + '","y":"' + str(
                                posicao_y - 3) + '","zOrder":"1"},\n'
                        dados_dump += "42 ,"
                        dados_dump_2 += "3.1418 ,"
                    elif converted_field == "CheckBox":
                        instrucao_coluna += '{"ID":"' + str(
                            self.generate_id()
                        ) + '","measuredH":"27","measuredW":"200","properties":{"text":""},"typeID":"CheckBox", "x":"' + str(
                            posicao_x_inputs) + '","y":"' + str(
                                posicao_y - 3) + '","zOrder":"1"},\n'
                        dados_dump += "Sim ,"
                        dados_dump_2 += "Nao ,"
                    elif converted_field == "TextArea":
                        instrucao_coluna += '{"ID":"' + str(
                            self.generate_id()
                        ) + '","measuredH":"10","measuredW":"100","typeID":"HRule","w":"283","x":"251","y":"' + str(
                            posicao_y + 4) + '","zOrder":"1"},'
                        instrucao_coluna += '{"ID":"' + str(
                            self.generate_id()
                        ) + '","measuredH":"27","measuredW":"200","properties":{"text":""},"typeID":"TextArea", "w":"416","h":"100" ,"x":"117","y":"' + str(
                            posicao_y + 21) + '","zOrder":"1"},\n'
                        posicao_y += 100
                        dados_dump += "Texto Longo ,"
                        dados_dump_2 += "Texto Curto ,"
                else:
                    instrucao_coluna += '{"ID":"' + str(
                        self.generate_id()
                    ) + '","measuredH":"27","measuredW":"200","properties":{"text":""},"typeID":"ComboBox","w":"283", "x":"' + str(
                        posicao_x_inputs) + '","y":"' + str(
                            posicao_y - 3) + '","zOrder":"1"},\n'
                    dados_dump += "Dado ,"
                    dados_dump_2 += "Dado ,"

                posicao_y += 30

        instrucao_coluna += '{"ID":"' + str(self.generate_id(
        )) + '","h":"' + str(
            posicao_y - 88
        ) + '","measuredH":"123","measuredW":"109","properties":{"align":"left","size":"10","text":"' + comments + '"},"typeID":"StickyNote","w":"450","x":"567","y":"188","zOrder":"0"},\n'
        instrucao_coluna += '{"ID":"' + str(
            self.generate_id()
        ) + '","measuredH":"21","measuredW":"328","properties":{"text":"' + colunas_grid + "\\n" + dados_dump + "\\n" + dados_dump_2 + '"},"typeID":"DataGrid","x":"583","y":"90","zOrder":"0"},\n'
        instrucao_coluna += '{"ID":"' + str(
            self.generate_id()
        ) + '","measuredH":"27","measuredW":"62","properties":{"text":"Salvar"},"typeID":"Button","x":"416","y":"' + str(
            posicao_y + 42) + '","zOrder":"1"},\n'
        instrucao_coluna += '{"ID":"' + str(
            self.generate_id()
        ) + '","measuredH":"27","measuredW":"59","properties":{"text":"Voltar"},"typeID":"Button","x":"147","y":"' + str(
            posicao_y + 42) + '","zOrder":"1"},\n'
        instrucao_coluna += '{"ID":"' + str(
            self.generate_id()
        ) + '","measuredH":"214","measuredW":"450","properties":{"text":"' + self.humanize(
            table.name) + '"},"typeID":"TitleWindow","h":"' + str(
                posicao_y + 10) + '","x":"100","y":"90","zOrder":"0"}\n'
        instrucao_coluna += ']},"measuredH":"453","measuredW":"1199","mockupH":"400","mockupW":"914","version":"1.0"}}\n'
        Workbench.copyToClipboard(instrucao_coluna)
예제 #4
0
def copyColumnNamesToClipboard(table):
    data = ', '.join([column.name for column in table.columns])
    Workbench.copyToClipboard(data)
    return 0