chen jinqian
10 months ago
4 changed files with 89 additions and 18 deletions
@ -0,0 +1,82 @@ |
|||
#!/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)) |
|||
|
Loading…
Reference in new issue