Ejemplo n.º 1
0
 def init(self):
     self.db = ffext.ffdb_create(self.db_host)
     if None == self.db:
         print("数据库连接出错")
         return False
     ret = self.db.sync_query(
         "SELECT `AUTO_INC_ID`, `RUNING_FLAG` FROM `id_generator` WHERE `TYPE` = '%d' AND `SERVER_ID` = '%d'"
         % (self.type_id, self.server_id))
     #print(ret.flag, ret.result, ret.column)
     if len(ret.result) == 0:
         #数据库中还没有这一行,插入
         self.db.sync_query(
             "INSERT INTO `id_generator` SET `AUTO_INC_ID` = '0',`TYPE` = '%d', `SERVER_ID` = '%d', `RUNING_FLAG` = '1' "
             % (self.type_id, self.server_id))
         return True
     else:
         self.auto_inc_id = int(ret.result[0][0])
         self.runing_flag = int(ret.result[0][1])
         if self.runing_flag != 0:
             self.auto_inc_id += 10000
             ffext.ERROR('last idgen shut down not ok, inc 10000')
         self.db.sync_query(
             "UPDATE `id_generator` SET `RUNING_FLAG` = '1' WHERE `TYPE` = '%d' AND `SERVER_ID` = '%d'"
             % (self.type_id, self.server_id))
     #if self.auto_inc_id < 65535:
     #    self.auto_inc_id = 65535
     return True
Ejemplo n.º 2
0
 def cleanup(self):
     db = ffext.ffdb_create(self.db_host)
     now_val = self.auto_inc_id
     db.sync_query(
         "UPDATE `id_generator` SET `AUTO_INC_ID` = '%d', `RUNING_FLAG` = '0' WHERE `TYPE` = '%d' AND `SERVER_ID` = '%d'"
         % (now_val, self.type_id, self.server_id))
     print('id_generator cleanup ok')
     return True
Ejemplo n.º 3
0
def sqlite_test():
    db = ffext.ffdb_create('sqlite://./test.db')
    db.query(
        'CREATE TABLE  IF NOT EXISTS dumy (A int, c float, b varchar(200), primary key (A))'
    )
    db.query('insert into dumy values(1, 2.3, "ttttTTccc")')

    def cb(ret):
        print(ret.flag, ret.result, ret.column, ffext.DB_CALLBACK_DICT)

    db.query('select * from dumy', cb)  #cb 为异步回调函数
    ffext.reload('main')  #重载此脚本
Ejemplo n.º 4
0
def mysql_test():
    db = ffext.ffdb_create('mysql://localhost:3306/root/root/pcgame')
    #db.query('CREATE TABLE  IF NOT EXISTS dumy (A int, c float, b varchar(200), primary key (A))')
    #db.query('insert into dumy values(1, 2.3, "ttttTTccc")')
    sql = "INSERT INTO `player_register` (`NAME` , `PASSWORD`) VALUES('%s', '%s') " % (
        'TT', 'a')
    ret = db.sync_query(sql)  #cb 为异步回调函数
    return

    def cb(ret):
        print(ret.flag, ret.result, ret.column, ffext.DB_CALLBACK_DICT)

    db.query('select * from dumy', cb)  #cb 为异步回调函数
    ffext.reload('main')  #重载此脚本
Ejemplo n.º 5
0
def init():
    global g_async_db
    #g_sync_db = ffext.ffdb_create('mysql://localhost:3306/root/acegame/pcgame')
    db_config = ffext.get_config('-db')
    print('db_config=%s'%(db_config))
    g_async_db = ffext.ffdb_create(db_config)
    if None == g_async_db:
        return False
    sql = '''create table IF NOT EXISTS player_info
    (
      UID bigint not null,
      NAME varchar(255) not null,
      X int not null,
      Y int not null,
      primary key(UID)
    )'''
    g_async_db.query(sql)
    return True
Ejemplo n.º 6
0
def init():
    global g_async_db
    #g_sync_db = ffext.ffdb_create('mysql://localhost:3306/root/acegame/pcgame')
    db_config = ffext.get_config('-db')
    print('db_config=%s' % (db_config))
    g_async_db = ffext.ffdb_create(db_config)
    if None == g_async_db:
        return False
    sql = '''create table IF NOT EXISTS player_info
    (
      UID bigint not null,
      NAME varchar(255) not null,
      X int not null,
      Y int not null,
      primary key(UID)
    )'''
    g_async_db.query(sql)
    return True
Ejemplo n.º 7
0
 def init(self):
     self.db = ffext.ffdb_create(self.db_host)
     if None == self.db:
         print("数据库连接出错")
         return False
     ret = self.db.sync_query("SELECT `AUTO_INC_ID`, `RUNING_FLAG` FROM `id_generator` WHERE `TYPE` = '%d' AND `SERVER_ID` = '%d'" % (self.type_id, self.server_id))
     #print(ret.flag, ret.result, ret.column)
     if len(ret.result) == 0:
         #数据库中还没有这一行,插入
         self.db.sync_query("INSERT INTO `id_generator` SET `AUTO_INC_ID` = '0',`TYPE` = '%d', `SERVER_ID` = '%d', `RUNING_FLAG` = '1' " % (self.type_id, self.server_id))
         return True
     else:
         self.auto_inc_id = int(ret.result[0][0])
         self.runing_flag = int(ret.result[0][1])
         if self.runing_flag != 0:
             self.auto_inc_id += 10000
             ffext.ERROR('last idgen shut down not ok, inc 10000')
         self.db.sync_query("UPDATE `id_generator` SET `RUNING_FLAG` = '1' WHERE `TYPE` = '%d' AND `SERVER_ID` = '%d'" % (self.type_id, self.server_id))
     #if self.auto_inc_id < 65535:
     #    self.auto_inc_id = 65535
     return True
Ejemplo n.º 8
0
 def cleanup(self):
     db = ffext.ffdb_create(self.db_host)
     now_val = self.auto_inc_id
     db.sync_query("UPDATE `id_generator` SET `AUTO_INC_ID` = '%d', `RUNING_FLAG` = '0' WHERE `TYPE` = '%d' AND `SERVER_ID` = '%d'" % (now_val, self.type_id, self.server_id))
     print('id_generator cleanup ok')
     return True
Ejemplo n.º 9
0
def get_async_db():
    global g_async_db
    if None == g_async_db:
        g_async_db = ffext.ffdb_create(
            'mysql://localhost:3306/root/root/pcgame')
    return g_async_db