bbdd-utils 0.3.10__tar.gz → 0.3.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bbdd_utils-0.3.10 → bbdd_utils-0.3.12}/PKG-INFO +1 -1
- {bbdd_utils-0.3.10 → bbdd_utils-0.3.12}/bbdd_utils/utils.py +14 -5
- {bbdd_utils-0.3.10 → bbdd_utils-0.3.12}/bbdd_utils.egg-info/PKG-INFO +1 -1
- {bbdd_utils-0.3.10 → bbdd_utils-0.3.12}/setup.py +1 -1
- {bbdd_utils-0.3.10 → bbdd_utils-0.3.12}/LICENSE +0 -0
- {bbdd_utils-0.3.10 → bbdd_utils-0.3.12}/README.md +0 -0
- {bbdd_utils-0.3.10 → bbdd_utils-0.3.12}/bbdd_utils/__init__.py +0 -0
- {bbdd_utils-0.3.10 → bbdd_utils-0.3.12}/bbdd_utils.egg-info/SOURCES.txt +0 -0
- {bbdd_utils-0.3.10 → bbdd_utils-0.3.12}/bbdd_utils.egg-info/dependency_links.txt +0 -0
- {bbdd_utils-0.3.10 → bbdd_utils-0.3.12}/bbdd_utils.egg-info/top_level.txt +0 -0
- {bbdd_utils-0.3.10 → bbdd_utils-0.3.12}/pyproject.toml +0 -0
- {bbdd_utils-0.3.10 → bbdd_utils-0.3.12}/setup.cfg +0 -0
@@ -74,6 +74,7 @@ def Insert(conn, tabla, data):
|
|
74
74
|
if isinstance(conn, sqlite3.Connection):
|
75
75
|
print("Conexión exitosa a la base de datos SQL.")
|
76
76
|
cursor = conn.cursor()
|
77
|
+
|
77
78
|
# Crear la tabla dinámicamente si no existe
|
78
79
|
columnas_definicion = ", ".join([f"{col} TEXT" for col in columnas])
|
79
80
|
cursor.execute(f"""
|
@@ -84,12 +85,20 @@ def Insert(conn, tabla, data):
|
|
84
85
|
""")
|
85
86
|
print(f"Tabla '{tabla}' verificada o creada exitosamente.")
|
86
87
|
|
87
|
-
|
88
|
-
|
89
|
-
|
88
|
+
# Si `data` es un solo diccionario, conviértelo en una lista
|
89
|
+
if isinstance(data, dict):
|
90
|
+
data = [data]
|
91
|
+
if isinstance(data, tuple):
|
92
|
+
data = list(data)
|
93
|
+
# Inserta cada elemento de la lista en la tabla
|
94
|
+
for registro in data:
|
95
|
+
columnas = ", ".join(registro.keys())
|
96
|
+
valores = ", ".join(["?"] * len(registro))
|
97
|
+
query = f"INSERT INTO {tabla} ({columnas}) VALUES ({valores})"
|
98
|
+
cursor.execute(query, tuple(registro.values()))
|
90
99
|
conn.commit()
|
91
|
-
print(
|
92
|
-
|
100
|
+
print("Datos insertados correctamente en SQLite.")
|
101
|
+
|
93
102
|
# Consulta los datos insertados
|
94
103
|
cursor.execute("SELECT * FROM {tabla}")
|
95
104
|
resultados = cursor.fetchall()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|