def get_connection(self, autocommit = 0, isolation_level = I_DEFAULT, listen_channel_list = []): # autocommit overrider isolation_level if autocommit: if isolation_level == I_SERIALIZABLE: raise Exception('autocommit is not compatible with I_SERIALIZABLE') isolation_level = I_AUTOCOMMIT # default isolation_level is READ COMMITTED if isolation_level < 0: isolation_level = I_READ_COMMITTED # new conn? if not self.conn: self.isolation_level = isolation_level self.conn = skytools.connect_database(self.loc) self.conn.my_name = self.name self.conn.set_isolation_level(isolation_level) self.conn_time = time.time() if self.setup_func: self.setup_func(self.name, self.conn) else: if self.isolation_level != isolation_level: raise Exception("Conflict in isolation_level") self._sync_listen(listen_channel_list) # done return self.conn
def makeSocket(self): """Create server connection. In this case its not socket but database connection.""" db = skytools.connect_database(self.connect_string) db.set_isolation_level(0) # autocommit return db
def makeSocket(self, timeout=1): """Create server connection. In this case its not socket but database connection.""" db = skytools.connect_database(self.connect_string) db.set_isolation_level(0) # autocommit return db
def db_connect(self, connstr): db = skytools.connect_database(connstr) db.set_isolation_level(0) # autocommit q = "select current_database(), current_setting('server_version')" curs = db.cursor() curs.execute(q) res = curs.fetchone() self.cur_database = res[0] return db
def test(): from skytools import connect_database db = connect_database("dbname=fooz") curs = db.cursor() s = TableStruct(curs, "public.data1") s.drop(curs, T_ALL) s.create(curs, T_ALL) s.create(curs, T_ALL, "data1_new") s.create(curs, T_PKEY)
def manual_check(): from skytools import connect_database db = connect_database("dbname=fooz") curs = db.cursor() s = TableStruct(curs, "public.data1") s.drop(curs, T_ALL) s.create(curs, T_ALL) s.create(curs, T_ALL, "data1_new") s.create(curs, T_PKEY)
def db_connect(self, connstr): db = skytools.connect_database(connstr) db.set_isolation_level(0) # autocommit q = "select current_database(), current_setting('server_version')" curs = db.cursor() curs.execute(q) res = curs.fetchone() print 'Server version', res[1] self.cur_database = res[0] return db
def work(self): socks = dict(self.poller.poll(1000)) if self.master in socks and socks[self.master] == zmq.POLLIN: zmsg = self.master.recv_multipart() else: # timeout return try: cmsg = CCMessage(zmsg) self.log.trace('%s', cmsg) except: self.log.exception("invalid CC message") return if not self.db: self.log.info('connecting to database') self.db = skytools.connect_database(self.connstr) self.db.set_isolation_level(0) self.process_request(cmsg)
def work(self): socks = dict (self.poller.poll (1000)) if self.master in socks and socks[self.master] == zmq.POLLIN: zmsg = self.master.recv_multipart() else: # timeout return try: cmsg = CCMessage (zmsg) self.log.trace ('%s', cmsg) except: self.log.exception ("invalid CC message") return if not self.db: self.log.info('connecting to database') self.db = skytools.connect_database(self.connstr) self.db.set_isolation_level(0) self.process_request(cmsg)
def db_connect(self, connstr, quiet=False): db = skytools.connect_database(connstr) db.set_isolation_level(0) # autocommit q = "select current_database(), current_setting('server_version')" curs = db.cursor() curs.execute(q) res = curs.fetchone() self.cur_database = res[0] self.server_version = res[1] q = "select pgq.version()" try: curs.execute(q) res = curs.fetchone() self.pgq_version = res[0] except psycopg2.ProgrammingError: self.pgq_version = "<none>" if not quiet: print "qadmin (%s, server %s, pgq %s)" % (__version__, self.server_version, self.pgq_version) #print "Connected to %r" % connstr return db
def get_connection(self, isolation_level=-1, listen_channel_list=()): # default isolation_level is READ COMMITTED if isolation_level < 0: isolation_level = skytools.I_READ_COMMITTED # new conn? if not self.conn: self.isolation_level = isolation_level self.conn = skytools.connect_database(self.loc) self.conn.my_name = self.name self.conn.set_isolation_level(isolation_level) self.conn_time = time.time() if self.setup_func: self.setup_func(self.name, self.conn) else: if self.isolation_level != isolation_level: raise Exception("Conflict in isolation_level") self._sync_listen(listen_channel_list) # done return self.conn
def get_connection(self, isolation_level = -1, listen_channel_list = []): # default isolation_level is READ COMMITTED if isolation_level < 0: isolation_level = skytools.I_READ_COMMITTED # new conn? if not self.conn: self.isolation_level = isolation_level self.conn = skytools.connect_database(self.loc) self.conn.my_name = self.name self.conn.set_isolation_level(isolation_level) self.conn_time = time.time() if self.setup_func: self.setup_func(self.name, self.conn) else: if self.isolation_level != isolation_level: raise Exception("Conflict in isolation_level") self._sync_listen(listen_channel_list) # done return self.conn
def connect_database(self): self.log.info("connecting to database") self.db = skytools.connect_database(self.connstr) self.db.set_isolation_level(0)