dbhydra 2.2.5__tar.gz → 2.2.8__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.
- {dbhydra-2.2.5 → dbhydra-2.2.8}/PKG-INFO +1 -1
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/dbhydra_core.py +3 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/src/abstract_table.py +16 -17
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/src/mysql_db.py +2 -1
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/src/tables.py +9 -5
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra.egg-info/PKG-INFO +1 -1
- {dbhydra-2.2.5 → dbhydra-2.2.8}/setup.py +1 -1
- {dbhydra-2.2.5 → dbhydra-2.2.8}/LICENSE +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/README.md +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/__init__.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/src/__init__.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/src/abstract_db.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/src/bigquery_db.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/src/errors/__init__.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/src/errors/exceptions.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/src/migrator.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/src/mongo_db.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/src/postgres_db.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/src/sqlserver_db.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/src/xlsx_db.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/test_migrator.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/tests/__init__.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/tests/test_cases.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/tests/test_mongo.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra/tests/test_sql.py +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra.egg-info/SOURCES.txt +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra.egg-info/dependency_links.txt +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra.egg-info/requires.txt +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/dbhydra.egg-info/top_level.txt +0 -0
- {dbhydra-2.2.5 → dbhydra-2.2.8}/setup.cfg +0 -0
|
@@ -259,16 +259,19 @@ class AbstractTable(AbstractJoinable, abc.ABC):
|
|
|
259
259
|
|
|
260
260
|
|
|
261
261
|
def drop(self, debug_mode = False):
|
|
262
|
-
|
|
262
|
+
quote = self.db1.identifier_quote
|
|
263
|
+
query = f"DROP TABLE {quote}{self.name}{quote}"
|
|
263
264
|
if debug_mode:
|
|
264
265
|
print(query)
|
|
265
266
|
self.execute(query)
|
|
266
267
|
|
|
267
268
|
def update(self, variable_assign, where=None, debug_mode = False):
|
|
269
|
+
quote = self.db1.identifier_quote
|
|
268
270
|
if where is None:
|
|
269
|
-
query = "UPDATE
|
|
271
|
+
query = f"UPDATE {quote}{self.name}{quote} SET {quote}{variable_assign}{quote}"
|
|
270
272
|
else:
|
|
271
|
-
query = "UPDATE
|
|
273
|
+
query = f"UPDATE {quote}{self.name}{quote} SET {quote}{variable_assign}{quote} WHERE {quote}{where}{quote}"
|
|
274
|
+
|
|
272
275
|
if debug_mode:
|
|
273
276
|
print(query)
|
|
274
277
|
return self.execute(query)
|
|
@@ -303,25 +306,25 @@ class AbstractTable(AbstractJoinable, abc.ABC):
|
|
|
303
306
|
for column_name, column_type in types_without_id_column
|
|
304
307
|
]
|
|
305
308
|
|
|
309
|
+
quote = self.db1.identifier_quote
|
|
306
310
|
column_value_string = ""
|
|
307
311
|
for column_name, cell_value, column_type in update_df_row_list:
|
|
308
312
|
if cell_value is None:
|
|
309
|
-
column_value_string += f"{column_name} = NULL, "
|
|
313
|
+
column_value_string += f"{quote}{column_name}{quote} = NULL, "
|
|
310
314
|
elif column_type in ["double", "int", "tinyint"]:
|
|
311
|
-
column_value_string += f"{column_name} = {cell_value}, "
|
|
315
|
+
column_value_string += f"{quote}{column_name}{quote} = {cell_value}, "
|
|
312
316
|
elif "varchar" in column_type:
|
|
313
|
-
column_value_string += f"{column_name} = '{cell_value}', "
|
|
317
|
+
column_value_string += f"{quote}{column_name}{quote} = '{cell_value}', "
|
|
314
318
|
elif column_type in ["json", "text", "mediumtext", "longtext", "datetime"]:
|
|
315
|
-
column_value_string += f"{column_name} = '{cell_value}', "
|
|
319
|
+
column_value_string += f"{quote}{column_name}{quote} = '{cell_value}', "
|
|
316
320
|
else:
|
|
317
321
|
raise AttributeError(f"Unknown column type '{column_type}'")
|
|
318
322
|
|
|
319
323
|
column_value_string = column_value_string.rstrip(", ")
|
|
320
|
-
quote = self.db1.identifier_quote
|
|
321
324
|
sql_query = f"UPDATE {quote}{self.name}{quote} SET {column_value_string}"
|
|
322
325
|
|
|
323
326
|
if where_column is not None and where_value is not None:
|
|
324
|
-
sql_query += f" WHERE {where_column} = {where_value};"
|
|
327
|
+
sql_query += f" WHERE {quote}{where_column}{quote} = {where_value};"
|
|
325
328
|
else:
|
|
326
329
|
sql_query += ";"
|
|
327
330
|
if debug_mode:
|
|
@@ -382,7 +385,7 @@ class AbstractTable(AbstractJoinable, abc.ABC):
|
|
|
382
385
|
inserted_columns=list(dict.fromkeys(self.columns)) #DEDUPLICATION preserving order -> better than inserted_columns = set(self.columns)
|
|
383
386
|
id_index=inserted_columns.index(self.id_column_name)
|
|
384
387
|
inserted_columns.pop(id_index)
|
|
385
|
-
print(inserted_columns,df.columns)
|
|
388
|
+
# print(inserted_columns,df.columns)
|
|
386
389
|
|
|
387
390
|
assert set(df.columns) == set(inserted_columns) #elements are matchin
|
|
388
391
|
#df = df[inserted_columns]
|
|
@@ -400,7 +403,8 @@ class AbstractTable(AbstractJoinable, abc.ABC):
|
|
|
400
403
|
|
|
401
404
|
# TODO: handling nan values -> change to NULL
|
|
402
405
|
for column in list(df.columns):
|
|
403
|
-
|
|
406
|
+
|
|
407
|
+
df[column] = df[column].fillna("NULL") #New implementation, Old implementation was deprecated by pandas: #df.loc[pd.isna(df[column]), column] = "NULL"
|
|
404
408
|
|
|
405
409
|
# rows = df.values.tolist()
|
|
406
410
|
# for i, row in enumerate(rows):
|
|
@@ -428,12 +432,7 @@ class AbstractTable(AbstractJoinable, abc.ABC):
|
|
|
428
432
|
quote = self.db1.identifier_quote
|
|
429
433
|
|
|
430
434
|
if where is None:
|
|
431
|
-
query = "DELETE FROM {quote}{self.name}{quote}"
|
|
435
|
+
query = f"DELETE FROM {quote}{self.name}{quote}"
|
|
432
436
|
else:
|
|
433
437
|
query = f"DELETE FROM {quote}{self.name}{quote} WHERE {where}"
|
|
434
438
|
return self.execute(query)
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
@@ -5,9 +5,9 @@ import abc
|
|
|
5
5
|
import time
|
|
6
6
|
#xlsx imports
|
|
7
7
|
import pathlib
|
|
8
|
-
|
|
8
|
+
import pymysql
|
|
9
9
|
from dbhydra.src.abstract_table import AbstractTable, AbstractSelectable, AbstractJoinable
|
|
10
|
-
|
|
10
|
+
import binascii
|
|
11
11
|
|
|
12
12
|
MONGO_OPERATOR_DICT = {"=": "$eq", ">": "$gt", ">=": "$gte", " IN ": "$in", "<": "$lt", "<=": "$lte", "<>": "$ne"}
|
|
13
13
|
|
|
@@ -294,11 +294,12 @@ class BigQueryTable(AbstractSelectable):
|
|
|
294
294
|
return column_names, column_types
|
|
295
295
|
|
|
296
296
|
|
|
297
|
-
def select(self, query):
|
|
297
|
+
def select(self, query, debug_mode = False):
|
|
298
298
|
|
|
299
299
|
"""given SELECT query returns Python list"""
|
|
300
300
|
"""Columns give the number of selected columns"""
|
|
301
|
-
|
|
301
|
+
if debug_mode:
|
|
302
|
+
print(query)
|
|
302
303
|
# rows = self.db1.client.query(query).result()
|
|
303
304
|
rows = self.db1.execute(query)
|
|
304
305
|
return rows
|
|
@@ -806,7 +807,10 @@ class MysqlTable(AbstractTable):
|
|
|
806
807
|
query += "'" + str(rows[k][j]) + "',"
|
|
807
808
|
elif "json" in self.types[j + start_index]:
|
|
808
809
|
query += f"'{rows[k][j]}', "
|
|
809
|
-
|
|
810
|
+
elif 'blob' in self.types[j + start_index]:
|
|
811
|
+
# Convert to hex to allow insertion into SQL query
|
|
812
|
+
hex_data = binascii.hexlify(rows[k][j]).decode('ascii')
|
|
813
|
+
query += f"UNHEX('{hex_data}'), "
|
|
810
814
|
|
|
811
815
|
else:
|
|
812
816
|
query += str(rows[k][j]) + ","
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|