def drop(simple_name): # con = psycopg2.connect(host=pg_host,database=pg_database, user=pg_user, password=pg_password) # cur = con.cursor() for device in devices.listNames(): cmd = "DROP TABLE temp_" + simple_name + device # print cmd commitCommand(cmd)
def drop(self): cmd = "DROP TABLE " + self.table_name print cmd try: postgres.commitCommand(cmd) except: print "TABLE DOES NOT EXIST"
def create(simple_name): # con = psycopg2.connect(host=pg_host,database=pg_database, user=pg_user, password=pg_password) # cur = con.cursor() for device in devices.yieldAll(): # print device if device[0] in 'web_browser': cmd = "create table temp_" + simple_name + device[0] + temp_web_table commitCommand(cmd) # cur.execute("create table temp_" + self.simple_name + device[0] + temp_web_table) # print cur.statusmessage else: cmd = "create table temp_" + simple_name + device[0] + temp__mobile_table commitCommand(cmd)
def drop(sponsor_string, server_id): logger = logging.getLogger("pyspeed.Server.dropGeo") logger.info("Dropping geo tables for: " + sponsor_string) for device in ['web_browser', 'mobile']: if device[0] in 'web_browser': cmd = "DROP TABLE public.geo_" + str( server_id) + "_web_browser CASCADE" statusmessage = commitCommand(cmd) logger.debug(statusmessage + " " + str(server_id) + "_" + device[0]) else: cmd = "DROP TABLE public.geo_" + str(server_id) + "_mobile CASCADE" print cmd statusmessage = commitCommand(cmd)
def create(sponsor_string, server_id): logger = logging.getLogger("pyspeed.Server.createGeo") logger.info("Creating tables for: " + str(sponsor_string)) for device in ['web_browser', 'mobile']: # device = device[0] if device in 'web_browser': cmd = "create table public.geo_" + str( server_id) + "_web_browser" + web_table statusmessage = commitCommand(cmd) logger.debug(statusmessage + " " + str(server_id) + "_" + device) else: cmd = "create table public.geo_" + str( server_id) + "_mobile" + mobile_table statusmessage = commitCommand(cmd) logger.debug(statusmessage + " " + str(server_id) + "_" + device)
def makeTable(): self.drop() commitCommand(makeTableCMD()) commitCommand(makeIndexes())
def makeTimeTable(): commitCommand("DROP TABLE olap.datedim") commitCommand(makeTableCMD()) commitCommand(makeIndexes())
def makeFactTable(sponsors): commitCommand("DROP TABLE olap.fact") commitCommand(makeTableCMD(sponsors)) commitCommand(makeIndexesCMD())
def insertTests(self, simple_sponsor, startdate, enddate): for device in ['web_browser', 'mobile']: cmd = servergeo.makeInsert("'" + self.server_name + "'", self.server_id, device, simple_sponsor, startdate, enddate) commitCommand(cmd)
def addPrimaryKey(self, column): cmd = "ALTER TABLE " + self.table_name cmd += " ADD PRIMARY KEY (" + column + ")" print cmd postgres.commitCommand(cmd)
def buildIndex(self, column): cmd = "CREATE INDEX ON " cmd += self.table_name + " (" + column + ")" print cmd postgres.commitCommand(cmd)
def createTableAs(self, select_statement): cmd = "CREATE TABLE " + self.table_name print cmd cmd += " AS " + select_statement postgres.commitCommand(cmd)