mdbq 4.0.24__tar.gz → 4.0.26__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.
Files changed (36) hide show
  1. {mdbq-4.0.24 → mdbq-4.0.26}/PKG-INFO +1 -1
  2. mdbq-4.0.26/mdbq/__version__.py +1 -0
  3. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/aggregation/query_data.py +14 -10
  4. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/mysql/s_query.py +49 -7
  5. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq.egg-info/PKG-INFO +1 -1
  6. mdbq-4.0.24/mdbq/__version__.py +0 -1
  7. {mdbq-4.0.24 → mdbq-4.0.26}/README.txt +0 -0
  8. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/__init__.py +0 -0
  9. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/aggregation/__init__.py +0 -0
  10. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/log/__init__.py +0 -0
  11. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/log/mylogger.py +0 -0
  12. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/myconf/__init__.py +0 -0
  13. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/myconf/myconf.py +0 -0
  14. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/myconf/myconf_bak.py +0 -0
  15. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/mysql/__init__.py +0 -0
  16. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/mysql/deduplicator.py +0 -0
  17. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/mysql/mysql.py +0 -0
  18. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/mysql/unique_.py +0 -0
  19. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/mysql/uploader.py +0 -0
  20. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/other/__init__.py +0 -0
  21. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/other/download_sku_picture.py +0 -0
  22. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/other/otk.py +0 -0
  23. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/other/pov_city.py +0 -0
  24. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/other/ua_sj.py +0 -0
  25. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/pbix/__init__.py +0 -0
  26. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/pbix/pbix_refresh.py +0 -0
  27. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/pbix/refresh_all.py +0 -0
  28. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/redis/__init__.py +0 -0
  29. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/redis/getredis.py +0 -0
  30. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/spider/__init__.py +0 -0
  31. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq/spider/aikucun.py +0 -0
  32. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq.egg-info/SOURCES.txt +0 -0
  33. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq.egg-info/dependency_links.txt +0 -0
  34. {mdbq-4.0.24 → mdbq-4.0.26}/mdbq.egg-info/top_level.txt +0 -0
  35. {mdbq-4.0.24 → mdbq-4.0.26}/setup.cfg +0 -0
  36. {mdbq-4.0.24 → mdbq-4.0.26}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mdbq
3
- Version: 4.0.24
3
+ Version: 4.0.26
4
4
  Home-page: https://pypi.org/project/mdbq
5
5
  Author: xigua,
6
6
  Author-email: 2587125111@qq.com
@@ -0,0 +1 @@
1
+ VERSION = '4.0.26'
@@ -3684,16 +3684,20 @@ def main(months=3):
3684
3684
  # 1. 更新日期表 更新货品年份基准表, 属性设置 3 - 货品年份基准
3685
3685
  date_table()
3686
3686
  # 2. 数据聚合
3687
- download_manager = s_query.QueryDatas(
3688
- username=username,
3689
- password=password,
3690
- host=host,
3691
- port=port,
3692
- pool_size=20,
3693
- )
3694
- query1(download_manager=download_manager, months=months)
3695
- query2(download_manager=download_manager, months=months)
3696
- query3(download_manager=download_manager, months=months)
3687
+ db_config = {
3688
+ 'username': username,
3689
+ 'password': password,
3690
+ 'host': host,
3691
+ 'port': int(port),
3692
+ 'pool_size': 20,
3693
+ 'mincached': 5,
3694
+ 'maxcached': 10,
3695
+ }
3696
+ with s_query.QueryDatas(**db_config) as download_manager:
3697
+ query1(download_manager=download_manager, months=months)
3698
+ query2(download_manager=download_manager, months=months)
3699
+ query3(download_manager=download_manager, months=months)
3700
+
3697
3701
  logger.info('数据聚合完成')
3698
3702
 
3699
3703
 
@@ -264,7 +264,26 @@ class QueryDatas:
264
264
  conn = self.pool.connection()
265
265
  if db_name:
266
266
  with conn.cursor() as cursor:
267
- cursor.execute(f"USE `{db_name}`")
267
+ # 先检查当前数据库
268
+ cursor.execute("SELECT DATABASE()")
269
+ current_db = cursor.fetchone()['DATABASE()']
270
+
271
+ # 如果当前数据库不是目标数据库,则切换
272
+ if current_db != db_name:
273
+ cursor.execute(f"USE `{db_name}`")
274
+ # 验证切换是否成功
275
+ cursor.execute("SELECT DATABASE()")
276
+ new_db = cursor.fetchone()['DATABASE()']
277
+ if new_db != db_name:
278
+ logger.error('数据库切换失败', {
279
+ '期望数据库': db_name,
280
+ '当前数据库': new_db
281
+ })
282
+ raise ConnectionError(f'无法切换到数据库: {db_name}')
283
+ logger.debug('数据库切换成功', {
284
+ '从': current_db,
285
+ '到': db_name
286
+ })
268
287
  return conn
269
288
  except pymysql.OperationalError as e:
270
289
  error_code = e.args[0] if e.args else None
@@ -353,6 +372,7 @@ class QueryDatas:
353
372
  """
354
373
  try:
355
374
  if info_type == 'exists':
375
+ # 检查数据库是否存在
356
376
  result = self._execute_query("SHOW DATABASES LIKE %s", (db_name,))
357
377
  if not result:
358
378
  all_dbs = self._execute_query("SHOW DATABASES")
@@ -363,17 +383,39 @@ class QueryDatas:
363
383
  '可能的原因': '数据库名称错误或没有访问权限'
364
384
  })
365
385
  return False
366
-
367
- result = self._execute_query("SHOW TABLES LIKE %s", (table_name,), db_name=db_name)
386
+
387
+ # 检查表是否存在(使用information_schema更可靠)
388
+ sql = """
389
+ SELECT TABLE_NAME
390
+ FROM information_schema.TABLES
391
+ WHERE TABLE_SCHEMA = %s
392
+ AND TABLE_NAME = %s
393
+ """
394
+ result = self._execute_query(sql, (db_name, table_name))
368
395
  if not result:
369
- all_tables = self._execute_query("SHOW TABLES", db_name=db_name)
370
- available_tables = [table[f'Tables_in_{db_name}'] for table in all_tables] if all_tables else []
371
- logger.info('表不存在', {
396
+ # 获取所有表名(不区分大小写)
397
+ sql = """
398
+ SELECT TABLE_NAME
399
+ FROM information_schema.TABLES
400
+ WHERE TABLE_SCHEMA = %s
401
+ """
402
+ all_tables = self._execute_query(sql, (db_name,))
403
+ available_tables = [table['TABLE_NAME'] for table in all_tables] if all_tables else []
404
+
405
+ # 检查是否有大小写匹配的表
406
+ case_insensitive_matches = [t for t in available_tables if t.lower() == table_name.lower()]
407
+
408
+ error_info = {
372
409
  '库': db_name,
373
410
  '表': table_name,
374
411
  '可用的表': available_tables,
375
412
  '可能的原因': '表名称错误或没有访问权限'
376
- })
413
+ }
414
+
415
+ if case_insensitive_matches:
416
+ error_info['可能的原因'] = f'表名大小写不匹配,请使用正确的表名: {case_insensitive_matches}'
417
+
418
+ logger.info('表不存在', error_info)
377
419
  return False
378
420
  return True
379
421
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mdbq
3
- Version: 4.0.24
3
+ Version: 4.0.26
4
4
  Home-page: https://pypi.org/project/mdbq
5
5
  Author: xigua,
6
6
  Author-email: 2587125111@qq.com
@@ -1 +0,0 @@
1
- VERSION = '4.0.24'
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
File without changes
File without changes
File without changes
File without changes