You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.6 KiB
83 lines
2.6 KiB
5 months ago
|
#!/usr/bin/python3
|
||
|
|
||
|
import pymysql
|
||
|
from properties import Properties
|
||
|
import sys, getopt
|
||
|
|
||
|
class DbUpdate:
|
||
|
# 本类用于提供各类数据库信息搜索服务
|
||
|
def __init__(self, connect):
|
||
|
self.connect = connect
|
||
|
|
||
|
def GetPresaleKeyword(self, database):
|
||
|
# 查询某个库的数据表的列表
|
||
|
cursorTable = self.connect.cursor()
|
||
|
cursorTable.execute("SELECT value FROM " + database + ".sysconfigure where fieldname = 'PresaleKeyword';");
|
||
|
|
||
|
keywords = cursorTable.fetchall()[0][0].replace(' ', '').replace(',', ',').split(',')
|
||
|
return keywords
|
||
|
|
||
|
def GetColumnList(self, tableName):
|
||
|
# 查询某张表的数据字段列表
|
||
|
cursorColumn = self.connect.cursor()
|
||
|
cursorColumn.execute("SELECT column_name,data_type FROM INFORMATION_SCHEMA.COLUMNS where table_schema='" + database + "' AND table_name='" +
|
||
|
tableName + "'");
|
||
|
return cursorColumn.fetchall()
|
||
|
|
||
|
def KeywordFlash(self, keywords, database):
|
||
|
# 生成更新SQL语句
|
||
|
cursor = self.connect.cursor()
|
||
|
strSQL = "update " + database + ".sc_cggg set glbj = 0"
|
||
|
cursor.execute(strSQL)
|
||
|
|
||
|
strSQL = "update " + database + ".sc_cggg set glbj = 1 where "
|
||
|
|
||
|
count = len(keywords)
|
||
|
for keyword in keywords:
|
||
|
count = count - 1
|
||
|
strSQL = strSQL + database + ".findbykeyword(bt,'" + keyword + "')"
|
||
|
if count > 0:
|
||
|
strSQL = strSQL + " OR "
|
||
|
|
||
|
print(strSQL)
|
||
|
cursor.execute(strSQL)
|
||
|
self.connect.commit()
|
||
|
|
||
|
return strSQL
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
print(
|
||
|
"""
|
||
|
============================================================
|
||
|
|这是数据库全文检索工具,包含两个参数 |
|
||
|
============================================================
|
||
|
""")
|
||
|
|
||
|
# 设置运行环境。如果当前是测试环境,则将is_test设置为true
|
||
|
is_test = False
|
||
|
|
||
|
if is_test:
|
||
|
file_path = "/opt/eresource_test/webapp/WEB-INF/classes/prod/jdbc.properties"
|
||
|
database = 'guoyantest'
|
||
|
else:
|
||
|
file_path = "/opt/eresource/webapp/WEB-INF/classes/prod/jdbc.properties"
|
||
|
database = 'guoyan'
|
||
|
|
||
|
# 打开jdbc.properties文件,获取数据库的配置信息
|
||
|
props = Properties(file_path)
|
||
|
host = 'localhost'
|
||
|
user = props.get('jdbc.username')
|
||
|
password = props.get('jdbc.password')
|
||
|
|
||
|
# 打开数据连接
|
||
|
db = pymysql.connect(host = host, user = user, password = password, database = database)
|
||
|
|
||
|
dbUpdate = DbUpdate(db)
|
||
|
keywords = dbUpdate.GetPresaleKeyword(database)
|
||
|
|
||
|
|
||
|
print(keywords)
|
||
|
|
||
|
print(dbUpdate.KeywordFlash(keywords, database))
|
||
|
|