def initialize(self, event=None): # Populate comboboxes ------------------------------------------------- odbc_drivers_list = dbTools.get_odbc_drivers() self.combobox_odbc.AppendItems(odbc_drivers_list) db_engines_list = SQLdb.get_engines() self.combobox_engine.AppendItems(db_engines_list) # Populate the rest --------------------------------------------------- options = { 'engine': '', 'driver': '', 'database': '', 'host': '', 'user': '', 'password': '', 'filepath': '' } self.section_dict = self.ini_file.get_section(section=self.ini_section, option_dict=options) self.form_dict = { 'engines_list': db_engines_list, 'drivers_list': odbc_drivers_list } self.form_dict.update(self.section_dict) self.populate(self.form_dict) self.on_connect = self.connect self.on_disconnect = self.disconnect
def __init__(self, ini_filename='', autosave=False, parent=None, debug=False): self.ini_filename = ini_filename self.autosave = autosave self.parent = parent self.debug = debug self.database = None self.database_dialog = Portlets.Database() self.DialogBox = Dialogs.Simple(parent=self.parent) self.ini_file = FileSystem.iniFile(self.ini_filename) self.portlet = self.database_dialog.create() db_engines_list = SQLdb.get_engines() self.config_dic = self.get_settings_from_ini() odbc_drivers_list = dbTools.get_odbc_drivers() self.database_dialog.populate(db_engines_list, odbc_drivers_list, self.config_dic) self.database_dialog.connect_order = self.connect self.database_dialog.disconnect_order = self.disconnect
def populate(self): if self.primary_key <> None: content_lod = self.db_table.db_object.dictresult('''\ SELECT * FROM %s WHERE %s = %s''' % (self.db_table.name, self.primary_key_column, self.primary_key)) self.Form.populate(content_dict=content_lod[0]) else: content_lod = None # Do callbacks for the population of higher-level widgets. for definition_dic in self.definition_lod: # First, check if there is a referenced table. If content_lod is empty, # pass through to populate the comboboxentry-dropdown-tables! foreign_content_dic = None if definition_dic.has_key('referenced_table_name'): if content_lod <> None: foreign_key = content_lod[0][definition_dic['column_name']] else: foreign_key = None if foreign_key == None: foreign_key = 'NULL' foreign_content_lod = self.db_table.db_object.dictresult('''\ SELECT * FROM %s WHERE %s = %s''' % (definition_dic['referenced_table_name'], definition_dic['referenced_column_name'], foreign_key)) if foreign_content_lod <> []: foreign_content_dic = foreign_content_lod[0] # Second, check if there is a populate function if definition_dic.has_key('populate_function'): definition_dic['populate_function'](definition_dic['widget_object'], foreign_content_dic) # Perhaps there is a simple populate_from attribute? if definition_dic.has_key('populate_from'): populate_from = definition_dic['populate_from'] if definition_dic.has_key('referenced_table_name'): referenced_table_name = definition_dic['referenced_table_name'] referenced_column_name = definition_dic['referenced_column_name'] widget = definition_dic['widget_object'] if definition_dic.has_key('mask'): mask = definition_dic['mask'] else: mask = None populate_from.append(referenced_column_name) foreign_table = SQLdb.table(self.db_object, referenced_table_name) result_lod = foreign_table.select(populate_from) widget.initialize({'column_name': [populate_from][0], 'mask': mask}) widget.populate(result_lod) if foreign_content_dic <> None: widget.set_text(foreign_content_dic[populate_from[0]])
def connect(self): try: self.config_dic = self.database_dialog.get_config_dic() self.database = SQLdb.database(self.config_dic['engine'], debug=self.debug) self.database.connect(database=self.config_dic['database'], driver=self.config_dic['driver'], host=self.config_dic['host'], user=self.config_dic['user'], password=self.config_dic['password']) self.database_dialog.set_connected() # Save .ini-file automatically on connection if self.autosave == True: self.save_settings_to_ini() except Exception, inst: self.DialogBox.show(dialog_type='error', title='Fehler', inst=inst) self.database_dialog.set_disconnected()
def initialize(self, event=None): # Populate comboboxes ------------------------------------------------- odbc_drivers_list = dbTools.get_odbc_drivers() self.combobox_odbc.AppendItems(odbc_drivers_list) db_engines_list = SQLdb.get_engines() self.combobox_engine.AppendItems(db_engines_list) # Populate the rest --------------------------------------------------- options = {"engine": "", "driver": "", "database": "", "host": "", "user": "", "password": "", "filepath": ""} self.section_dict = self.ini_file.get_section(section=self.ini_section, option_dict=options) self.form_dict = {"engines_list": db_engines_list, "drivers_list": odbc_drivers_list} self.form_dict.update(self.section_dict) self.populate(self.form_dict) self.on_connect = self.connect self.on_disconnect = self.disconnect
def connect(self): """ Trys to connect the database with given parameters. """ try: self.section_dict = self.get_content() self.database = SQLdb.database(self.section_dict.get("engine")) self.database.connect( database=self.section_dict.get("database"), driver=self.section_dict.get("driver"), host=self.section_dict.get("host"), user=self.section_dict.get("user"), password=self.section_dict.get("password"), filepath=self.section_dict.get("filepath"), ) self.set_connected() # Save .ini-file automatically on connection if self.autosave == True: self.save_settings() except Exception, inst: self.set_disconnected() self.ErrorDialog.show(message="Datenbank konnte nicht verbunden werden.", instance=inst)
def connect(self): ''' Trys to connect the database with given parameters. ''' try: self.section_dict = self.get_content() self.database = SQLdb.database(self.section_dict.get('engine')) self.database.connect(database=self.section_dict.get('database'), driver=self.section_dict.get('driver'), host=self.section_dict.get('host'), user=self.section_dict.get('user'), password=self.section_dict.get('password'), filepath=self.section_dict.get('filepath')) self.set_connected() # Save .ini-file automatically on connection if self.autosave == True: self.save_settings() except Exception, inst: self.set_disconnected() self.ErrorDialog.show( message='Datenbank konnte nicht verbunden werden.', instance=inst)
def populate(self): if self.primary_key <> None: content_lod = self.db_table.db_object.dictresult( '''\ SELECT * FROM %s WHERE %s = %s''' % (self.db_table.name, self.primary_key_column, self.primary_key)) self.Form.populate(content_dict=content_lod[0]) else: content_lod = None # Do callbacks for the population of higher-level widgets. for definition_dic in self.definition_lod: # First, check if there is a referenced table. If content_lod is empty, # pass through to populate the comboboxentry-dropdown-tables! foreign_content_dic = None if definition_dic.has_key('referenced_table_name'): if content_lod <> None: foreign_key = content_lod[0][definition_dic['column_name']] else: foreign_key = None if foreign_key == None: foreign_key = 'NULL' foreign_content_lod = self.db_table.db_object.dictresult( '''\ SELECT * FROM %s WHERE %s = %s''' % (definition_dic['referenced_table_name'], definition_dic['referenced_column_name'], foreign_key)) if foreign_content_lod <> []: foreign_content_dic = foreign_content_lod[0] # Second, check if there is a populate function if definition_dic.has_key('populate_function'): definition_dic['populate_function']( definition_dic['widget_object'], foreign_content_dic) # Perhaps there is a simple populate_from attribute? if definition_dic.has_key('populate_from'): populate_from = definition_dic['populate_from'] if definition_dic.has_key('referenced_table_name'): referenced_table_name = definition_dic[ 'referenced_table_name'] referenced_column_name = definition_dic[ 'referenced_column_name'] widget = definition_dic['widget_object'] if definition_dic.has_key('mask'): mask = definition_dic['mask'] else: mask = None populate_from.append(referenced_column_name) foreign_table = SQLdb.table(self.db_object, referenced_table_name) result_lod = foreign_table.select(populate_from) widget.initialize({ 'column_name': [populate_from][0], 'mask': mask }) widget.populate(result_lod) if foreign_content_dic <> None: widget.set_text(foreign_content_dic[populate_from[0]])