forked from opengisch/QgisModelBaker
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opengisch#324 from AgenciaImplementacion/mssql_sup…
…port_300 Add Sql Server support
- Loading branch information
Showing
25 changed files
with
1,693 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
/*************************************************************************** | ||
begin : 10/05/19 | ||
git sha : :%H$ | ||
copyright : (C) 2019 by Yesid Polania (BSF Swissphoto) | ||
email : yesidpol.3@gmail.com | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
""" | ||
from qgis.PyQt.QtCore import pyqtSignal | ||
|
||
from .db_config_panel import DbConfigPanel | ||
from ...utils import get_ui_class | ||
from QgisModelBaker.utils.qt_utils import ( | ||
Validators, | ||
NonEmptyStringValidator) | ||
from QgisModelBaker.utils.mssql_utils import get_odbc_drivers | ||
from QgisModelBaker.libili2db.globals import DbActionType | ||
|
||
WIDGET_UI = get_ui_class('mssql_settings_panel.ui') | ||
|
||
class MssqlConfigPanel(DbConfigPanel, WIDGET_UI): | ||
|
||
notify_fields_modified = pyqtSignal(str) | ||
|
||
def __init__(self, parent, db_action_type): | ||
DbConfigPanel.__init__(self, parent, db_action_type) | ||
self.setupUi(self) | ||
|
||
for item_odbc_driver in get_odbc_drivers(): | ||
self.mssql_odbc_driver.addItem(item_odbc_driver) | ||
|
||
# define validators | ||
self.validators = Validators() | ||
nonEmptyValidator = NonEmptyStringValidator() | ||
|
||
self.mssql_host_line_edit.setValidator(nonEmptyValidator) | ||
self.mssql_database_line_edit.setValidator(nonEmptyValidator) | ||
self.mssql_user_line_edit.setValidator(nonEmptyValidator) | ||
|
||
self.mssql_host_line_edit.textChanged.connect( | ||
self.validators.validate_line_edits) | ||
self.mssql_host_line_edit.textChanged.emit(self.mssql_host_line_edit.text()) | ||
self.mssql_database_line_edit.textChanged.connect( | ||
self.validators.validate_line_edits) | ||
self.mssql_database_line_edit.textChanged.emit( | ||
self.mssql_database_line_edit.text()) | ||
self.mssql_user_line_edit.textChanged.connect( | ||
self.validators.validate_line_edits) | ||
self.mssql_user_line_edit.textChanged.emit(self.mssql_user_line_edit.text()) | ||
|
||
self.mssql_host_line_edit.textChanged.connect(self.notify_fields_modified) | ||
self.mssql_instance_line_edit.textChanged.connect(self.notify_fields_modified) | ||
self.mssql_port_line_edit.textChanged.connect(self.notify_fields_modified) | ||
self.mssql_database_line_edit.textChanged.connect(self.notify_fields_modified) | ||
self.mssql_schema_line_edit.textChanged.connect(self.notify_fields_modified) | ||
self.mssql_user_line_edit.textChanged.connect(self.notify_fields_modified) | ||
self.mssql_password_line_edit.textChanged.connect(self.notify_fields_modified) | ||
|
||
def _show_panel(self): | ||
if self.interlis_mode: | ||
self.mssql_schema_line_edit.setPlaceholderText( | ||
self.tr("[Leave empty to create a default schema]")) | ||
else: | ||
if self._db_action_type == DbActionType.IMPORT_DATA: | ||
self.mssql_schema_line_edit.setPlaceholderText( | ||
self.tr("[Leave empty to import data into a default schema]")) | ||
else: | ||
self.mssql_schema_line_edit.setPlaceholderText( | ||
self.tr("[Leave empty to load all schemas in the database]")) | ||
|
||
def get_fields(self, configuration): | ||
configuration.dbhost = self.mssql_host_line_edit.text().strip() | ||
configuration.dbinstance = self.mssql_instance_line_edit.text().strip() | ||
configuration.dbport = self.mssql_port_line_edit.text().strip() | ||
configuration.dbusr = self.mssql_user_line_edit.text().strip() | ||
configuration.database = self.mssql_database_line_edit.text().strip() | ||
configuration.dbschema = self.mssql_schema_line_edit.text().strip().lower() | ||
configuration.dbpwd = self.mssql_password_line_edit.text() | ||
configuration.db_odbc_driver = self.mssql_odbc_driver.currentText() | ||
|
||
def set_fields(self, configuration): | ||
self.mssql_host_line_edit.setText(configuration.dbhost) | ||
self.mssql_instance_line_edit.setText(configuration.dbinstance) | ||
self.mssql_port_line_edit.setText(configuration.dbport) | ||
self.mssql_user_line_edit.setText(configuration.dbusr) | ||
self.mssql_database_line_edit.setText(configuration.database) | ||
self.mssql_schema_line_edit.setText(configuration.dbschema) | ||
self.mssql_password_line_edit.setText(configuration.dbpwd) | ||
|
||
index = self.mssql_odbc_driver.findText(configuration.db_odbc_driver) | ||
if index != -1: | ||
self.mssql_odbc_driver.setCurrentIndex(index) | ||
|
||
def is_valid(self): | ||
result = False | ||
message = '' | ||
if not self.mssql_host_line_edit.text().strip(): | ||
message = self.tr("Please set a host before creating the project.") | ||
self.mssql_host_line_edit.setFocus() | ||
elif not "{}".format(self.mssql_database_line_edit.text().strip()): | ||
message = self.tr("Please set a database before creating the project.") | ||
self.mssql_database_line_edit.setFocus() | ||
elif not self.mssql_user_line_edit.text().strip(): | ||
message = self.tr("Please set a database user before creating the project.") | ||
self.mssql_user_line_edit.setFocus() | ||
elif not self.mssql_odbc_driver.currentText(): | ||
message = self.tr("Please set a odbc driver before creating the project.") | ||
else: | ||
result = True | ||
|
||
return result, message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
QgisModelBaker/libqgsprojectgen/db_factory/mssql_command_config_manager.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
/*************************************************************************** | ||
begin : 09/05/19 | ||
git sha : :%H$ | ||
copyright : (C) 2019 by Yesid Polania (BSF Swissphoto) | ||
email : yesidpol.3@gmail.com | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
""" | ||
from qgis.PyQt.QtCore import QSettings | ||
from .db_command_config_manager import DbCommandConfigManager | ||
|
||
|
||
class MssqlCommandConfigManager(DbCommandConfigManager): | ||
|
||
_settings_base_path = 'QgisModelBaker/ili2mssql/' | ||
|
||
def __init__(self, configuration): | ||
DbCommandConfigManager.__init__(self, configuration) | ||
|
||
def get_uri(self, su=False): | ||
separator = ';' | ||
uri = [] | ||
uri += ['DRIVER={{{}}}'.format(self.configuration.db_odbc_driver)] | ||
host = self.configuration.dbhost | ||
if self.configuration.dbinstance: | ||
host += '\\' + self.configuration.dbinstance | ||
if self.configuration.dbport: | ||
host += ',' + self.configuration.dbport | ||
|
||
uri += ['SERVER={}'.format(host)] | ||
uri += ['DATABASE={}'.format(self.configuration.database)] | ||
uri += ['UID={}'.format(self.configuration.dbusr)] | ||
uri += ['PWD={}'.format(self.configuration.dbpwd)] | ||
|
||
return separator.join(uri) | ||
|
||
def get_db_args(self, hide_password=False): | ||
db_args = list() | ||
db_args += ["--dbhost", self.configuration.dbhost] | ||
if self.configuration.dbport: | ||
db_args += ["--dbport", self.configuration.dbport] | ||
db_args += ["--dbusr", self.configuration.dbusr] | ||
if self.configuration.dbpwd: | ||
if hide_password: | ||
db_args += ["--dbpwd", '******'] | ||
else: | ||
db_args += ["--dbpwd", self.configuration.dbpwd] | ||
db_args += ["--dbdatabase", self.configuration.database] | ||
db_args += ["--dbschema", self.configuration.dbschema or self.configuration.database] | ||
if self.configuration.dbinstance: | ||
db_args += ["--dbinstance", self.configuration.dbinstance] | ||
|
||
return db_args | ||
|
||
def save_config_in_qsettings(self): | ||
settings = QSettings() | ||
|
||
settings.setValue(self._settings_base_path + 'host', self.configuration.dbhost) | ||
settings.setValue(self._settings_base_path + 'instance', self.configuration.dbhost) | ||
settings.setValue(self._settings_base_path + 'port', self.configuration.dbport) | ||
settings.setValue(self._settings_base_path + 'user', self.configuration.dbusr) | ||
settings.setValue(self._settings_base_path + 'database', self.configuration.database) | ||
settings.setValue(self._settings_base_path + 'schema', self.configuration.dbschema) | ||
settings.setValue(self._settings_base_path + 'password', self.configuration.dbpwd) | ||
settings.setValue(self._settings_base_path + 'odbc_driver', self.configuration.db_odbc_driver) | ||
|
||
def load_config_from_qsettings(self): | ||
settings = QSettings() | ||
|
||
self.configuration.dbhost = settings.value(self._settings_base_path + 'host', 'localhost') | ||
self.configuration.dbport = settings.value(self._settings_base_path + 'instance') | ||
self.configuration.dbport = settings.value(self._settings_base_path + 'port') | ||
self.configuration.dbusr = settings.value(self._settings_base_path + 'user') | ||
self.configuration.database = settings.value(self._settings_base_path + 'database') | ||
self.configuration.dbschema = settings.value(self._settings_base_path + 'schema') | ||
self.configuration.dbpwd = settings.value(self._settings_base_path + 'password') | ||
self.configuration.db_odbc_driver = settings.value(self._settings_base_path + 'odbc_driver') |
Oops, something went wrong.