示例#1
0
    def update_project_database_sqlite(self):
        """Deletes the deleted project from the sqlite project database.

        Returns:
          False: If something went wrong. Otherwise True.
        """
        try:
            db = get_projects_db()

            sql = "DELETE FROM projects WHERE dbschema = '%s';" % (
                self.db_schema)

            query = db.exec_(sql)

            if not query.isActive():
                message = "Error while reading from projects database."
                raise VerisoError(
                    message, long_message=QSqlQuery.lastError(query).text())

            db.close()
            del db

            return True

        except Exception as e:
            message = "Something went wrong while updating projects database."
            raise VerisoError(message, e)
示例#2
0
 def btnTestProjectDB_clicked(self):
     try:
         current_path = self.lineEditProjectsDatabase.text()
         db = get_projects_db(current_path)
         db.close()
         self.test_connection_succes()
     except Exception as e:
         self.test_connection_failed(e)
示例#3
0
    def update_projects_database_sqlite(self):
        """Updates the sqlite projects database.

        Returns:
          False: When there an error occured. Otherswise True.
        """
        error_message = ("Something went wrong while updating projects "
                         "database. You need to delete the database schema "
                         "manually.")

        try:
            # Create a new projects database if there is none (copy one from
            # the templates).
            if self.projects_database == "":
                template = get_absolute_path("templates/template_projects.db")
                self.projects_database = QDir.toNativeSeparators(
                    QDir.cleanPath(self.projects_root_directory +
                                   "/projects.db"))
                shutil.copyfile(template, self.projects_database)
                self.settings.setValue("options/general/projects_database",
                                       self.projects_database)

            db = get_projects_db()

            project_root_directory = QDir.toNativeSeparators(
                QDir.cleanPath(self.projects_root_directory + "/" +
                               str(self.db_schema)))

            values = (self.db_schema, self.db_schema, self.db_host,
                      self.db_name, self.db_port, self.db_schema, self.db_user,
                      self.db_pwd, self.db_admin, self.db_admin_pwd, self.epsg,
                      self.ili, self.app_module, self.app_module_name,
                      self.projects_root_directory, project_root_directory,
                      self.data_date, self.notes, self.itf, self.max_scale)
            values = """VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s',
                     '%s', '%s', 'postgres', '%s', '%s', '%s', '%s', '%s',
                     '%s', '%s', '%s', '%s', '%s')""" % values

            sql = "INSERT INTO projects (id, displayname, dbhost, dbname, " \
                  "dbport, dbschema, dbuser, dbpwd, dbadmin, dbadminpwd, " \
                  "provider, epsg, ilimodelname, appmodule, appmodulename, " \
                  "projectrootdir, projectdir, datadate, notes, itf, " \
                  "max_scale)" + values

            query = db.exec_(sql)

            if not query.isActive():
                message = "Error while updating projects database."
                raise VerisoError(
                    message, long_message=QSqlQuery.lastError(query).text())

            db.close()

            self.projectsDatabaseHasChanged.emit()

            return True
        except Exception as e:
            raise VerisoError(error_message, e)
示例#4
0
 def test_open_sqlite_db(self):
     existing_db = get_projects_db()
     random_name = ''.join(random.choice(string.lowercase) for i in range(9))
     db = open_sqlite_db(existing_db.databaseName(), random_name)
     try:
         self.assertEqual(db.databaseName(), existing_db.databaseName())
     except:
         raise
     finally:
         db.close()
         QSqlDatabase.removeDatabase(random_name)
示例#5
0
 def test_get_projects_db(self):
     db = get_projects_db()
     self.assertIs(QSqlDatabase, type(db))
     self.assertIs(True, os.path.exists(db.databaseName()))