mdbq 4.2.6__py3-none-any.whl → 4.2.8__py3-none-any.whl
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.
Potentially problematic release.
This version of mdbq might be problematic. Click here for more details.
- mdbq/__version__.py +1 -1
- mdbq/mysql/uploader.py +28 -13
- {mdbq-4.2.6.dist-info → mdbq-4.2.8.dist-info}/METADATA +1 -1
- {mdbq-4.2.6.dist-info → mdbq-4.2.8.dist-info}/RECORD +6 -6
- {mdbq-4.2.6.dist-info → mdbq-4.2.8.dist-info}/WHEEL +0 -0
- {mdbq-4.2.6.dist-info → mdbq-4.2.8.dist-info}/top_level.txt +0 -0
mdbq/__version__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
VERSION = '4.2.
|
|
1
|
+
VERSION = '4.2.8'
|
mdbq/mysql/uploader.py
CHANGED
|
@@ -64,6 +64,17 @@ class DatabaseConnectionManager:
|
|
|
64
64
|
'autocommit': False
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
# 设置时区为北京时间,确保时间戳的一致性
|
|
68
|
+
if 'init_command' not in self.config:
|
|
69
|
+
pool_params['init_command'] = "SET time_zone = '+08:00'"
|
|
70
|
+
else:
|
|
71
|
+
# 如果用户已设置init_command,则追加时区设置
|
|
72
|
+
existing_commands = self.config['init_command']
|
|
73
|
+
if 'time_zone' not in existing_commands.lower():
|
|
74
|
+
pool_params['init_command'] = f"{existing_commands}; SET time_zone = '+08:00'"
|
|
75
|
+
else:
|
|
76
|
+
pool_params['init_command'] = existing_commands
|
|
77
|
+
|
|
67
78
|
if self.config.get('ssl'):
|
|
68
79
|
pool_params['ssl'] = self.config['ssl']
|
|
69
80
|
|
|
@@ -770,8 +781,7 @@ class TableManager:
|
|
|
770
781
|
except Exception as e:
|
|
771
782
|
raise ValueError(f"无效的日期值: {date_value}, 错误: {str(e)}")
|
|
772
783
|
|
|
773
|
-
|
|
774
|
-
def _sanitize_identifier(identifier: str) -> str:
|
|
784
|
+
def _sanitize_identifier(self, identifier: str) -> str:
|
|
775
785
|
"""清理标识符"""
|
|
776
786
|
if not identifier or not isinstance(identifier, str):
|
|
777
787
|
raise ValueError(f"无效的标识符: {identifier}")
|
|
@@ -783,18 +793,16 @@ class TableManager:
|
|
|
783
793
|
if not cleaned:
|
|
784
794
|
raise ValueError(f"标识符清理后为空: {identifier}")
|
|
785
795
|
|
|
786
|
-
# 检查MySQL关键字
|
|
787
|
-
mysql_keywords = {
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
}
|
|
796
|
+
# # 检查MySQL关键字
|
|
797
|
+
# mysql_keywords = {
|
|
798
|
+
# 'select', 'insert', 'update', 'delete', 'from', 'where', 'and', 'or',
|
|
799
|
+
# 'not', 'like', 'in', 'is', 'null', 'true', 'false', 'between'
|
|
800
|
+
# }
|
|
791
801
|
|
|
792
802
|
if len(cleaned) > 64:
|
|
793
803
|
cleaned = cleaned[:64]
|
|
794
804
|
|
|
795
|
-
|
|
796
|
-
return f"`{cleaned}`"
|
|
797
|
-
|
|
805
|
+
# 不在这里添加反引号,让调用者决定是否需要
|
|
798
806
|
return cleaned
|
|
799
807
|
|
|
800
808
|
|
|
@@ -918,8 +926,9 @@ class DataProcessor:
|
|
|
918
926
|
class DataInserter:
|
|
919
927
|
"""数据插入器"""
|
|
920
928
|
|
|
921
|
-
def __init__(self, connection_manager: DatabaseConnectionManager):
|
|
929
|
+
def __init__(self, connection_manager: DatabaseConnectionManager, table_manager: TableManager = None):
|
|
922
930
|
self.conn_mgr = connection_manager
|
|
931
|
+
self.table_mgr = table_manager
|
|
923
932
|
|
|
924
933
|
def insert_data(self, db_name: str, table_name: str, data: List[Dict],
|
|
925
934
|
set_typ: Dict[str, str], update_on_duplicate: bool = False) -> Tuple[int, int, int]:
|
|
@@ -929,7 +938,7 @@ class DataInserter:
|
|
|
929
938
|
|
|
930
939
|
# 准备SQL语句(排除系统列)
|
|
931
940
|
columns = [col for col in set_typ.keys() if col.lower() not in ['id', 'create_at', 'update_at']]
|
|
932
|
-
safe_columns = [
|
|
941
|
+
safe_columns = [self.table_mgr._sanitize_identifier(col) if self.table_mgr else col for col in columns]
|
|
933
942
|
placeholders = ','.join(['%s'] * len(columns))
|
|
934
943
|
|
|
935
944
|
sql = f"""
|
|
@@ -1065,6 +1074,12 @@ class MySQLUploader:
|
|
|
1065
1074
|
- 支持自动建表、分表、数据类型推断
|
|
1066
1075
|
- 高可用连接池管理和重试机制
|
|
1067
1076
|
- 流式批量插入优化
|
|
1077
|
+
- 自动设置数据库连接时区为北京时间(+08:00),确保时间戳一致性
|
|
1078
|
+
|
|
1079
|
+
时区说明:
|
|
1080
|
+
- 所有数据库连接会自动设置为北京时间(+08:00)
|
|
1081
|
+
- create_at和update_at列使用CURRENT_TIMESTAMP,会按照连接时区记录时间
|
|
1082
|
+
- 可使用check_timezone_settings()方法验证时区设置
|
|
1068
1083
|
"""
|
|
1069
1084
|
|
|
1070
1085
|
def __init__(self, username: str, password: str, host: str = 'localhost',
|
|
@@ -1098,7 +1113,7 @@ class MySQLUploader:
|
|
|
1098
1113
|
# 初始化组件
|
|
1099
1114
|
self.conn_mgr = DatabaseConnectionManager(self.config)
|
|
1100
1115
|
self.table_mgr = TableManager(self.conn_mgr, collation)
|
|
1101
|
-
self.data_inserter = DataInserter(self.conn_mgr)
|
|
1116
|
+
self.data_inserter = DataInserter(self.conn_mgr, self.table_mgr)
|
|
1102
1117
|
|
|
1103
1118
|
@retry_on_failure(max_retries=3)
|
|
1104
1119
|
def upload_data(self, db_name: str, table_name: str,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
mdbq/__init__.py,sha256=Il5Q9ATdX8yXqVxtP_nYqUhExzxPC_qk_WXQ_4h0exg,16
|
|
2
|
-
mdbq/__version__.py,sha256=
|
|
2
|
+
mdbq/__version__.py,sha256=bRBQbqec4RjxzcwssgAcf6Xb3LHtO4NQTk0fuRkUXaY,17
|
|
3
3
|
mdbq/auth/__init__.py,sha256=pnPMAt63sh1B6kEvmutUuro46zVf2v2YDAG7q-jV_To,24
|
|
4
4
|
mdbq/auth/auth_backend.py,sha256=iLN7AqiSq7fQgFtNtge_TIlVOR1hrCSZXH6oId6uGX4,116924
|
|
5
5
|
mdbq/auth/crypto.py,sha256=fcZRFCnrKVVdWDUx_zds51ynFYwS9DBvJOrRQVldrfM,15931
|
|
@@ -15,7 +15,7 @@ mdbq/mysql/deduplicator.py,sha256=VGRBcIEsWUqQovkGpGCOittSW1l5fuMpiNWLbiOA5tI,72
|
|
|
15
15
|
mdbq/mysql/mysql.py,sha256=eSrEE6DdS3GJ_EPPSggEZXhnVz6IqHPwUSsWfZJVFkY,57081
|
|
16
16
|
mdbq/mysql/s_query.py,sha256=rCJZ0XPalwk3Z7HkqsvF9o0UX0sZT4Wk1JXryRrV6yQ,50472
|
|
17
17
|
mdbq/mysql/unique_.py,sha256=MaztT-WIyEQUs-OOYY4pFulgHVcXR1BfCy3QUz0XM_U,21127
|
|
18
|
-
mdbq/mysql/uploader.py,sha256=
|
|
18
|
+
mdbq/mysql/uploader.py,sha256=GAJIJO3uQg8G8OciZlH6duXkEqroUaU5j5hgET7Ck8Y,65370
|
|
19
19
|
mdbq/other/__init__.py,sha256=jso1oHcy6cJEfa7udS_9uO5X6kZLoPBF8l3wCYmr5dM,18
|
|
20
20
|
mdbq/other/download_sku_picture.py,sha256=pxcoNYoTP5KAhyvyHO2NQIrfhige5UN-LuB9Z8Iw3g8,45017
|
|
21
21
|
mdbq/other/error_handler.py,sha256=4p5haAXSY-P78stp4Xwo_MwAngWYqyKj5ogWIuYXMeY,12631
|
|
@@ -35,7 +35,7 @@ mdbq/route/routes.py,sha256=QVGfTvDgu0CpcKCvk1ra74H8uojgqTLUav1fnVAqLEA,29433
|
|
|
35
35
|
mdbq/selenium/__init__.py,sha256=AKzeEceqZyvqn2dEDoJSzDQnbuENkJSHAlbHAD0u0ZI,10
|
|
36
36
|
mdbq/selenium/get_driver.py,sha256=1NTlVUE6QsyjTrVVVqTO2LOnYf578ccFWlWnvIXGtic,20903
|
|
37
37
|
mdbq/spider/__init__.py,sha256=RBMFXGy_jd1HXZhngB2T2XTvJqki8P_Fr-pBcwijnew,18
|
|
38
|
-
mdbq-4.2.
|
|
39
|
-
mdbq-4.2.
|
|
40
|
-
mdbq-4.2.
|
|
41
|
-
mdbq-4.2.
|
|
38
|
+
mdbq-4.2.8.dist-info/METADATA,sha256=TEvwYOF6KRkyAWFQWoCiVz4R7cJJyBAAChZdiMIcgew,363
|
|
39
|
+
mdbq-4.2.8.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
|
|
40
|
+
mdbq-4.2.8.dist-info/top_level.txt,sha256=2FQ-uLnCSB-OwFiWntzmwosW3X2Xqsg0ewh1axsaylA,5
|
|
41
|
+
mdbq-4.2.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|