mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -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,49 +1,22 @@
|
|||
from UM.Settings.SQLQueryFactory import SQLQueryFactory
|
||||
from UM.Settings.DatabaseContainerMetadataController import DatabaseMetadataContainerController
|
||||
from UM.Settings.InstanceContainer import InstanceContainer
|
||||
|
||||
|
||||
class IntentDatabaseHandler(DatabaseMetadataContainerController):
|
||||
"""The Database handler for Intent containers"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__(
|
||||
insert_query = """ INSERT INTO intents (id, name, quality_type, intent_category, variant, definition, material, version, setting_version)
|
||||
VALUES (?, ?, ? ,?, ?, ?, ?, ?, ?)""",
|
||||
update_query="""UPDATE intents
|
||||
SET name = ?,
|
||||
quality_type = ?,
|
||||
intent_category = ?,
|
||||
variant = ?,
|
||||
definition = ?,
|
||||
material = ?,
|
||||
version = ?,
|
||||
setting_version = ?
|
||||
WHERE id = ?
|
||||
""",
|
||||
select_query = "SELECT * FROM intents WHERE id = ?",
|
||||
delete_query = "DELETE FROM intents WHERE id = ?",
|
||||
table_query="""CREATE TABLE intents
|
||||
(
|
||||
id text,
|
||||
name text,
|
||||
quality_type text,
|
||||
intent_category text,
|
||||
variant text,
|
||||
definition text,
|
||||
material text,
|
||||
version text,
|
||||
setting_version text
|
||||
);
|
||||
CREATE UNIQUE INDEX idx_intents_id on intents (id);"""
|
||||
)
|
||||
|
||||
def _convertMetadataToUpdateBatch(self, metadata):
|
||||
return self._convertMetadataToInsertBatch(metadata)[1:]
|
||||
|
||||
def _convertRawDataToMetadata(self, data):
|
||||
return {"id": data[0], "name": data[1], "quality_type": data[2], "intent_category": data[3], "variant": data[4], "definition": data[5], "container_type": InstanceContainer, "material": data[6], "version": data[7], "setting_version": data[8], "type": "intent"}
|
||||
|
||||
def _convertMetadataToInsertBatch(self, metadata):
|
||||
return metadata["id"], metadata["name"], metadata["quality_type"], metadata["intent_category"], metadata[
|
||||
"variant"], metadata["definition"], metadata["material"], metadata["version"], metadata["setting_version"]
|
||||
|
||||
|
||||
|
||||
super().__init__(SQLQueryFactory(table = "intents",
|
||||
fields = {
|
||||
"id": "text",
|
||||
"name": "text",
|
||||
"quality_type": "text",
|
||||
"intent_category": "text",
|
||||
"variant": "text",
|
||||
"definition": "text",
|
||||
"material": "text",
|
||||
"version": "text",
|
||||
"setting_version": "text"
|
||||
}))
|
||||
self.container_type = InstanceContainer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue