def refresh(self): self.deleteChildren() self.appendRow(BaseTreeItem('FIELDS')) curTableFields = self.lastChild() self.appendRow(BaseTreeItem('FK')) curTableFK = self.lastChild() self.appendRow(BaseTreeItem('FK_REFERENCE')) #faltan las FK de vuelta #engine = self.getConnection().data().engine #inspector = inspect(engine) inspector = self.getConnection().inspector table_name = self.text() schema = self.getSchema().text() if schema == '': schema = None try: #FIXME self.getRecordCount() for column in inspector.get_columns(table_name, schema): try: name = BaseTreeItem(column['name']) tipo = BaseTreeItem( typeHandler(column.get('type', types.Text()))) curTableFields.appendRow((name, tipo)) #FIXME el rendimiento es intolerable para poer hacerlo para todas las columnas #curTableFields.lastChild().getValueSpread() except CompileError: #except CompileError: if config.DEBUG: print('Columna sin tipo', schema, ' ', table_name, ' ', name) if name and name != '': tipo = BaseTreeItem(typeHandler(types.Text())) curTableFields.appendRow((name, tipo)) for fk in inspector.get_foreign_keys(table_name, schema): if fk['name'] is None: name = BaseTreeItem(table_name + '2' + fk['referred_table'] + '*') else: name = BaseTreeItem(fk['name']) if fk['referred_schema'] is not None: table = BaseTreeItem(fk['referred_schema'] + '.' + fk['referred_table']) else: table = BaseTreeItem(fk['referred_table']) constrained = BaseTreeItem( norm2String(fk['constrained_columns'])) referred = BaseTreeItem(norm2String(fk['referred_columns'])) curTableFK.appendRow((name, table, constrained, referred)) except (OperationalError, ProgrammingError) as e: if config.DEBUG: #showConnectionError('Error en {}.{}'.format(schema,table_name),norm2String(e.orig.args)) print('Error en {}.{}'.format(schema, table_name), norm2String(e.orig.args))
def accept(self): self.msgLine.clear() attr_list = ('driver', 'dbname', 'dbhost', 'dbuser', 'dbpass', 'dbport', 'debug') datos = self.validate() if datos is None: return if isinstance(datos[0], int): datos[0] = DRIVERS[datos[0]] conf = row2dict(datos, attr_list) try: if conf['driver'] == 'sqlite': if not os.path.isfile(datos[1]): self.msgLine.setText('Fichero {} no existe'.format( datos[1])) return conn = dbConnectAlch(conf) except Exception as e: showConnectionError(datos[0], norm2String(repr(e))) self.msgLine.setText('Error en la conexión') return self.conn = conn self.confInfo = conf QDialog.accept(self)
def FK_hierarchy(self, inspector, schemata): for schema in schemata: for table_name in inspector.get_table_names(schema): try: for fk in inspector.get_foreign_keys(table_name, schema): ref_schema = fk.get('referred_schema', inspector.default_schema_name) ref_table = fk['referred_table'] if schema is not None: table = BaseTreeItem(schema + '.' + table_name) else: table = BaseTreeItem(table_name) if fk['name'] is None: name = BaseTreeItem(table_name + '2' + fk['referred_table'] + '*') else: name = BaseTreeItem(fk['name']) constrained = BaseTreeItem( norm2String(fk['constrained_columns'])) referred = BaseTreeItem( norm2String(fk['referred_columns'])) kschema = fk.get('referred_schema', '') kitem = self.findElement(fk.get('referred_schema', ''), ref_table) if kitem is not None: referencer = kitem.child(2) referencer.appendRow( (name, table, referred, constrained)) except (OperationalError, ProgrammingError) as e: # showConnectionError('Error en {}.{}'.format(schema,table_name),norm2String(e.orig.args),'Error en el diccionario') if config.DEBUG: print('error operativo en ', schema, table_name, norm2String(e.orig.args)) continue except AttributeError as e: # showConnectionError('Error en {}.{}, >{}'.format(schema,table_name,fk['referred_table']),norm2String(e.orig.args),'Error en el diccionario') if config.DEBUG: print(schema, table_name, fk['referred_table'], 'casca', norm2String(e.orig.args)) continue
def getExecParms(self, model, plugin, tipo_plugin, entry, **callbacks): from support.util.record_functions import norm2String index = callbacks.get('index', model2index) initial_Data = callbacks.get('index', initialDataVoid) data_capture = callbacks.get('data capture', presenta) showTree = callbacks.get('tree', None) lparm = [None for k in range(4)] kparm = dict() if entry[2]: for key in entry[2]: kparm[key] = entry[2][key] if 'colparm' in tipo_plugin: datosBase = initial_Data(model, 'col') lparm[1] = [(dato[0], dato[1]) for dato in datosBase] if 'rowparm' in tipo_plugin: datosBase = initial_Data(model, 'row') lparm[1] = [(dato[0], dato[1]) for dato in datosBase] if 'colkey' in tipo_plugin and not lparm[1]: lparm[1] = index(model, 'col') if 'rowkey' in tipo_plugin and not lparm[1]: lparm[1] = index(model, 'row') if 'colparm' in tipo_plugin: # or 'rowparm' in tipo_plugin: # presenta parametros a_table = data_capture(datosBase) # convierte en parms lparm[3] = a_table if 'rowparm' in tipo_plugin: # presenta parametros a_table = data_capture(datosBase) # convierte en parms lparm[2] = a_table if 'kwparm' in tipo_plugin: a_table = [[key, key, norm2String(kparm[key])] for key in kparm] m_datos = data_capture( a_table) #,[norm2String(kparm[key[0]]) for key in a_table]) for i, key in enumerate(a_table): kparm[key[0]] = m_datos[i][2] if showTree: kparm['tree'] = showTree return lparm, kparm
def updateHdr(self, action, value): cabecera = self.itemData(0, DISP) if cabecera == WComboMulti.textoCabecera: elementos = set() else: elementos = set(norm2List(cabecera)) if action == 'set': elementos.add(value) else: elementos.remove(value) cabItem = self.model().item(0, 0) if len(elementos) == 0: cabItem.setData(WComboMulti.textoCabecera, DISP) else: cabItem.setData(norm2String(elementos), DISP) self.setCurrentIndex(0)
def setModelData(self, editor, model, index): dato = getWidgetData(self, editor) #if type(editor) in (QComboBox,) and self.isDouble: #model.setData(index,dato[0],USER) #model.setData(index,dato[1],DISP) if type(editor) == WComboBoxIdx: model.setData(index, dato[2], USER) model.setData(index, dato[1], DISP) elif type(editor) == WComboBox: model.setData(index, dato[0], USER) model.setData(index, dato[1], DISP) elif isinstance(dato, (list, tuple)): dato = norm2String(dato) model.setData(index, dato) else: model.setData(index, dato)
def execute(self): sqlString = self.sqlEdit.document().toPlainText() if len(sqlString) == 0: return cursor = None self.msgLine.hide() self.msgLine.setText('') try: #TODO opcion para poner un limit cursor = getCursorLim(self.conn,sqlString,LIMIT=self.limit) except Exception as e: if cursor is not None: cursor.close() self.msgLine.show() #self.msgLine.setText(e) self.msgLine.setText(norm2String(e.args)+' '+sqlString) return if not self.baseModel: self.baseModel = CursorItemModel() else: self.baseModel.clear() self.setupView() self.baseModel.setHorizontalHeaderLabels(cursor.keys()) idx = 0 for row in cursor: #if idx == 0: #self.getDescription(row) #modelRow = [ CursorItem(str(fld)) for fld in row ] modelRow = [ CursorItem(fld) for fld in row ] self.baseModel.appendRow(modelRow) idx += 1 self.browser.setModel(self.baseModel) cursor.close() #INNECESARIO pero recomendable
def test(self): self.msgLine.clear() attr_list = ('driver', 'dbname', 'dbhost', 'dbuser', 'dbpass', 'dbport', 'debug') datos = self.validate() if datos is None: return if isinstance(datos[1], int): datos[1] = DRIVERS[datos[1]] conf = row2dict(datos[1:], attr_list) try: if conf['driver'] == 'sqlite': if not os.path.isfile(datos[2]): self.msgLine.setText('Fichero {} no existe'.format( datos[2])) return else: conn = dbConnectAlch(conf) conn.close() except (OperationalError, ProgrammingError) as e: showConnectionError(datos[0], norm2String(e.orig.args)) self.msgLine.setText('Error en la conexión') return self.msgLine.setText('Conexión validada correctamente')
def get(self, role=USER): result = [] for k in range(1, self.count()): if self.itemData(k, Qt.CheckStateRole) == Qt.Checked: result.append(self.itemData(k, role)) return norm2String(result)