Beispiel #1
0
def mysql(sql):
    data, result = "", ""
    host = "mysql"
    user = os.getenv('mysql_user')
    pw = os.getenv('mysql_passwd')
    db = os.getenv('mysql_db')
    port = 3306
    # 使用连接池
    connection = connect(creator=pymysql,
                         host=host,
                         user=user,
                         password=pw,
                         database=db,
                         autocommit=True,
                         charset='utf8',
                         port=port,
                         cursorclass=pymysql.cursors.DictCursor)
    try:
        with connection.cursor() as cursor:
            cursor.execute(sql)
            connection.commit()
            if "select" or "show" in sql:
                data = cursor.fetchall()
    except Exception as e:
        print(e)
        connection.rollback()
    else:
        result = True

    finally:
        connection.close()

    return data, result
Beispiel #2
0
 def re_connect(self, is_persist=None):
     if is_persist:
         persist=DBUtils.PersistentDB.PersistentDB(MySQLdb, 100, host=self.host,user=self.user,passwd=self.passwd,db=self.db)
         conn = persist.connection()
         return conn
     else:
         conn = connect(MySQLdb, 1000, host=self.host,user=self.user,passwd=self.passwd,db=self.db)
         return conn
Beispiel #3
0
    def connect(self):
        conn = connect(MySQLdb, **self.conn_params)

        if not conn:
            raise DatabaseError('can not connect to database: %s %s %s'
                         % (host, user, db))

        cursor = conn.cursor()
        cursor = CursorWrapper(cursor, self)
        return cursor
Beispiel #4
0
    def connect(self):
        conn = connect(MySQLdb, **self.conn_params)

        if not conn:
            raise DatabaseError('can not connect to database: %s %s %s' %
                                (host, user, db))

        cursor = conn.cursor()
        cursor = CursorWrapper(cursor, self)
        return cursor
Beispiel #5
0
 def __init__(self):
     self.credentials = ['localhost', 'username', 'password', 'database']
     self.db = connect(
         creator=pymysql,
         host=self.credentials[0],
         user=self.credentials[1],
         password=self.credentials[2],
         database=self.credentials[3],
         autocommit=True,
         charset='utf8mb4',
         cursorclass=pymysql.cursors.DictCursor
     )
Beispiel #6
0
 def steady_connection(self):
     """Get a steady, non-persistent DB-API 2 connection."""
     return connect(self._creator, self._maxusage, self._setsession,
                    self._failures, self._closeable, *self._args,
                    **self._kwargs)
Beispiel #7
0
 def steady_connection(self):
     """Get a steady, unpooled DB-API 2 connection."""
     return connect(self._creator, self._maxusage, self._setsession,
                    self._failures, self._ping, True, *self._args,
                    **self._kwargs)
Beispiel #8
0
	def steady_connection(self):
		"""Get a steady, non-persistent DB-API 2 connection."""
		return connect(self._creator,
			self._maxusage, self._setsession,
			self._failures, self._closeable,
			*self._args, **self._kwargs)
        i = i + 1

    v = v + ")"
    return v


print("------------------------------------- ".format(dt.datetime.now(),
                                                      len(db_tables)))
print("{}------Scripte Started".format(dt.datetime.now()))

change_platform_script('stop')
src_db = connect(creator=pymysql,
                 host=source_cred['host'],
                 port=source_cred['port'],
                 user=source_cred['user'],
                 password=source_cred['passwd'],
                 database=source_cred['database'],
                 autocommit=True,
                 charset='utf8mb4',
                 cursorclass=pymysql.cursors.Cursor)
src_cursor = src_db.cursor()
des_db = connect(creator=pymysql,
                 host=dest_cred['host'],
                 port=dest_cred['port'],
                 user=dest_cred['user'],
                 password=dest_cred['passwd'],
                 database=dest_cred['database'],
                 autocommit=True,
                 charset='utf8mb4',
                 cursorclass=pymysql.cursors.Cursor)
des_cursor = des_db.cursor()
Beispiel #10
0
 def connection(*args, **kwds):
     kwds["maxusage"] = False
     return connect(MySQLdb, *args, **kwds)
def connection(*args, **kwds):
    kwds['maxusage'] = False
    return connect(MySQLdb, *args, **kwds)
Beispiel #12
0
import requests
from konlpy.tag import Mecab
import pymysql
from DBUtils.SteadyDB import connect

end_str = 'subwayinfo.cylwhwhcjyca.ap-northeast-2.rds.amazonaws.com'
# conn = pymysql.connect(host=end_str, user='******', password='******',
#    db='subwayinfo', charset='utf8')
conn = connect(creator=pymysql,
               host=end_str,
               user='******',
               password='******',
               database='subwayinfo',
               charset='utf8')


def move_conn():
    return conn


curs = conn.cursor()

mecab = Mecab()

num_list = list(map(str, range(1, 10)))
num_to_korean_Dict = {
    '1': '일',
    '2': '이',
    '3': '삼',
    '4': '사',
    '5': '오',
Beispiel #13
0
 def steady_connection(self):
     """Get a steady, unpooled DB-API 2 connection."""
     return connect(self._creator,
         self._maxusage, self._setsession,
         self._failures, self._ping, True,
         *self._args, **self._kwargs)