This commit implements multi-database support, allowing the system to switch
between SQL Server and MySQL databases seamlessly.
## New Features
- Database type selection (SQL Server or MySQL) via configuration
- Automatic table name conversion between formats ([dbo].[table] → dbo_table)
- Automatic parameter placeholder handling (? for SQL Server, %s for MySQL)
- GUI settings tab now includes database type dropdown and MySQL configuration
## Database Abstraction Layer
- db/base_connection.py: Abstract base class for database connections
- db/sqlserver_connection.py: SQL Server implementation
- db/mysql_connection.py: MySQL implementation using mysql-connector-python
- db/connection_factory.py: Factory pattern for creating connections
- db/table_name_converter.py: Table name format conversion utility
## DAO Base Class
- db/base_dao.py: Base DAO with helper methods for SQL conversion and placeholders
## Updated Components
- config/schema.py: Extended with DatabaseType enum and MySQL/SQLServer config classes
- config/defaults.py: Added MySQL default configuration
- config/loader.py: Updated to handle new database structure
- db/connection.py: Refactored to use factory pattern and load user config
- All DAO files: Updated to inherit from BaseDAO with automatic conversion
## Dependencies
- Added mysql-connector-python>=8.0.0 to requirements.txt
## Configuration
To use MySQL, set db_type to "mysql" in config/user_settings.json:
{
"database": {
"db_type": "mysql",
"mysql": {
"host": "192.168.31.83",
"port": 3306,
"database": "BLD_DB",
"username": "remote_user",
"password": "3.1415926Beeke"
}
}
}
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
73 lines
1.8 KiB
Python
73 lines
1.8 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
默认配置值
|
|
|
|
定义所有配置项的默认值。
|
|
"""
|
|
from config.schema import (
|
|
ERPConfig,
|
|
DatabaseConfig,
|
|
PathConfig,
|
|
ExtractionConfig,
|
|
ValidationConfig,
|
|
AppConfig,
|
|
SQLServerConfig,
|
|
MySQLConfig,
|
|
DatabaseType,
|
|
)
|
|
|
|
|
|
# 默认配置
|
|
DEFAULT_APP_CONFIG = AppConfig(
|
|
erp=ERPConfig(
|
|
url="https://68.11.34.30:8082/",
|
|
username="BLDpengqiangqiang",
|
|
password="Cqbld123456.",
|
|
headless=True,
|
|
ignore_https_errors=True,
|
|
auto_close_browser=True,
|
|
),
|
|
database=DatabaseConfig(
|
|
db_type=DatabaseType.SQLSERVER,
|
|
server="192.168.110.114",
|
|
database="CompanyDB",
|
|
username="peng",
|
|
password="Cqbld123456.",
|
|
sqlserver=SQLServerConfig(
|
|
driver="ODBC Driver 18 for SQL Server",
|
|
trust_server_certificate="yes",
|
|
),
|
|
mysql=MySQLConfig(
|
|
host="192.168.31.83",
|
|
port=3306,
|
|
charset="utf8mb4",
|
|
),
|
|
),
|
|
paths=PathConfig(
|
|
data_dir="D:/python/playwrite/data/",
|
|
production_id_file="ProductionID.txt",
|
|
default_output="离散备料计划维护_合并.xlsx",
|
|
validation_output="物料状态校验结果.xlsx",
|
|
),
|
|
extraction=ExtractionConfig(
|
|
batch_size=100,
|
|
verbose=True,
|
|
auto_convert=True,
|
|
merge_batches=True,
|
|
enable_db_persistence=False, # Disabled by default
|
|
),
|
|
validation=ValidationConfig(
|
|
data_source="database_full",
|
|
use_database=True,
|
|
batch_size=2000,
|
|
enable_crud_operations=False,
|
|
default_manager="",
|
|
match_mode="substring",
|
|
),
|
|
)
|
|
|
|
|
|
# 兼容旧版本的字典格式
|
|
DEFAULT_SETTINGS_DICT = DEFAULT_APP_CONFIG.to_dict()
|