mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
Use a class to build to sql queries
This greatly reduced the amount of duplicate code in the DataBaseHandlers Not sure how secure this is SQL injections. Need to check that and maybe put in some guards. Using double underscores for now and only provide a getter. But then again why bother with an SQL injection as you can just as easily modify the Python code, and we still have the old Containers to fallback to if the Database gets corrupted. Contributes to CURA-6096
This commit is contained in:
parent
3191baf5a0
commit
7aa08d4acd
3 changed files with 51 additions and 129 deletions
|
@ -1,40 +1,19 @@
|
|||
from UM.Settings.SQLQueryFactory import SQLQueryFactory
|
||||
from UM.Settings.DatabaseContainerMetadataController import DatabaseMetadataContainerController
|
||||
from UM.Settings.InstanceContainer import InstanceContainer
|
||||
|
||||
|
||||
class VariantDatabaseHandler(DatabaseMetadataContainerController):
|
||||
def __init__(self) -> None:
|
||||
super().__init__(
|
||||
insert_query = """INSERT INTO variants (id, name, hardware_type, definition, version, setting_version)
|
||||
VALUES (?, ?, ?, ?, ?, ?)""",
|
||||
update_query = """ UPDATE variants
|
||||
SET name = ?,
|
||||
hardware_type = ?,
|
||||
definition = ?,
|
||||
version = ?,
|
||||
setting_version = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
select_query = "SELECT * FROM variants WHERE id = ?",
|
||||
delete_query = "DELETE FROM variants WHERE id = ?",
|
||||
table_query = """CREATE TABLE variants
|
||||
(
|
||||
id text,
|
||||
name text,
|
||||
hardware_type text,
|
||||
definition text,
|
||||
version text,
|
||||
setting_version text
|
||||
);
|
||||
CREATE UNIQUE INDEX idx_variants_id on variants (id);"""
|
||||
)
|
||||
"""The Database handler for Variant containers"""
|
||||
|
||||
def _convertMetadataToUpdateBatch(self, metadata):
|
||||
return self._convertMetadataToInsertBatch(metadata)[1:]
|
||||
|
||||
def _convertRawDataToMetadata(self, data):
|
||||
return {"id": data[0], "name": data[1], "hardware_type": data[2], "definition": data[3], "container_type": InstanceContainer, "version": data[4], "setting_version": data[5], "type": "variant"}
|
||||
|
||||
def _convertMetadataToInsertBatch(self, metadata):
|
||||
return metadata["id"], metadata["name"], metadata["hardware_type"], metadata["definition"], metadata["version"], \
|
||||
metadata["setting_version"]
|
||||
def __init__(self):
|
||||
super().__init__(SQLQueryFactory(table = "variants",
|
||||
fields = {
|
||||
"id": "text",
|
||||
"name": "text",
|
||||
"hardware_type": "text",
|
||||
"definition": "text",
|
||||
"version": "text",
|
||||
"setting_version": "text"
|
||||
}))
|
||||
self.container_type = InstanceContainer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue