Beispiel #1
0
 def __delattr__(self, name):
     # BaseConnection has a delattr that forbids
     # all deletion. Not helpful.
     if name in self.__dict__:
         self.__dict__.pop(name)
     else:
         BaseConnection.__delattr__(self, name)
 def __init__(self, *arg, **kwargs):
     while 1:
         try:
             Connection.__init__(self, *arg, **kwargs)
             self.pid = os.getpid()
             break
         except:
             pass
Beispiel #3
0
 def __init__(self, *arg, **kwargs):
     while 1:
         try:
             Connection.__init__(self, *arg, **kwargs)
             self.pid = os.getpid()
             break
         except:
             pass
Beispiel #4
0
 def __init__(self, *arg, **kwargs):
     while 1:
         try:
             logging.debug('connect with %s %s', arg, kwargs)
             Connection.__init__(self, *arg, **kwargs)
             self.pid = os.getpid()
             break
         except:
             logging.error(traceback.format_exc())
 def __init__(self, *arg, **kwargs):
     while 1:
         try:
             logging.debug('connect with %s %s', arg, kwargs)
             Connection.__init__(self, *arg, **kwargs)
             self.pid = os.getpid()
             break
         except:
             logging.error(traceback.format_exc())
Beispiel #6
0
def _connect(**conn_override) -> Connection:
    conn_args = dict(host=settings.DB_HOST,
                     user=settings.DB_USER,
                     password=settings.DB_PASS,
                     port=settings.DB_PORT)
    if not empty(settings.DB_NAME):
        conn_args['database'] = settings.DB_NAME
    conn_args = {**conn_args, **conn_override}
    return Connection(**conn_args)
Beispiel #7
0
def Connect(*args, **kwargs):
    # import pymysql.cursors
    # # Connect to the database
    # connection = pymysql.connect(host='localhost',
    #                              user='******',
    #                              password='',
    #                              db='ATEC_DB_MYSQL',
    #                              charset='utf8mb4',
    #                              cursorclass=pymysql.cursors.DictCursor)
    """Factory function for connections.Connection."""
    from MySQLdb.connections import Connection
    return Connection(*args, **kwargs)
Beispiel #8
0
def Connect(*args, **kwargs):
    """Factory function for connections.Connection."""
    from MySQLdb.connections import Connection
    return Connection(*args, **kwargs)
Beispiel #9
0
from dataset import InputDataSet
from selected_result import SelectResult
import configparser

conf_dir = dirname(dirname(abspath(__file__)))
config = configparser.ConfigParser()
config.read(join(conf_dir, 'app.conf'), encoding='utf-8')

SYS_USER = os.getenv("USER")  # get system user
CONFIG = {
    'user': config['DB']['user'] if SYS_USER == 'dimasty' else 'root',
    'password': config['DB']['user'] if SYS_USER == 'dimasty' else '',
    'host': config['DB']['host'],
    'database': config['DB']['database']
}
db = Connection(**CONFIG)
dbc = db.cursor()
db.set_character_set('utf8')
dbc.execute('SET NAMES utf8;')
dbc.execute('SET CHARACTER SET utf8;')
dbc.execute('SET character_set_connection=utf8;')


def usage():
    print("\nThis is the usage function\n")
    print("Usage: " + sys.argv[0] + " -f <file> or --data-file=<file>]")


def get_duplicate_name():
    try:
        dbc.execute(queries.FIND_PERSON_DUPLICATES)
Beispiel #10
0
import datetime
import time
from MySQLdb.connections import Connection
from MySQLdb.cursors import DictCursor

def timeUnix():
    return int(time.time())

if __name__ == '__main__' :
    connect = Connection(host='192.168.1.2',user='******',passwd='5OpqU7zv324a7KJxu@4d',db='xiaolajiao',port=3306,charset='utf8')
    cursor = connect.cursor(cursorclass=DictCursor)
    cursor.execute(""" select * from shouji_goods WHERE is_promote = 1 AND promote_cycle>0 """)
    rows = cursor.fetchall()
    for goods in rows:
        # print(datetime.datetime.fromtimestamp(goods.get('promote_end_date')).strftime('%Y-%m-%d %H:%M:%S'))
        if(goods.get('promote_end_date')<=timeUnix()):
            startDate = goods.get('promote_end_date')
            endDate = int(goods.get('promote_end_date')) + int(goods.get('promote_cycle'))*24*3600
            cursor.execute(""" update shouji_goods SET promote_start_date=%s,promote_end_date=%s WHERE goods_id=%s""" % (startDate,endDate,goods.get('goods_id')))
    cursor.close()
    connect.close()
 def __init__(self, *arg, **kwargs):
     Connection.__init__(self, *arg, **kwargs)
     self.pid = os.getpid()
Beispiel #12
0
 def _critical_commit(self):
     try:
         BaseConnection.commit(self)
     finally:
         self.exit_critical_phase_at_transaction_end()
Beispiel #13
0
 def _critical_rollback(self):
     try:
         BaseConnection.rollback(self)
     finally:
         self.exit_critical_phase_at_transaction_end()
Beispiel #14
0
 def _critical_query(self, query):
     return BaseConnection.query(self, query)
Beispiel #15
0
 def close(self):
     self.__close_watchers()
     BaseConnection.close(self)
Beispiel #16
0
 def db(self):
     return self.__db if isinstance(self.__db,Connection)\
         else Connection(host=dbhost, user=dbuser, passwd=dbpass, db=dbname)