def __init__(self, db_type = "sqlite3", db_host_name = None, db_name = "hash_tags", db_username = None, db_password = None): self.db_type = db_type self.db_host_name = db_host_name self.db_name = db_name self.db_username = db_username self.db_password = db_password if db_type == "sqlite3": self.cur = dbcon.connect_db(db_type) elif db_type == "mysql" or db_type == "postgresql": if db_host_name == None or db_username == None or db_password == None: #throw an error : invalid number of parameters passed return self.cur = dbcon.connect_db(db_type, db_host_name, db_name, db_username, db_password)
def __init__(self, db_type = "sqlite3", db_host_name = None, db_name = "hash_tags", db_username = None, db_password = None): self.db_type = db_type self.db_host_name = db_host_name self.db_name = db_name self.db_username = db_username self.db_password = db_password if db_type == "sqlite3": self.cur = dbcon.connectDB(db_type) elif db_type == "mysql" or db_type == "postgresql": if db_host_name == None or db_username == None or db_password == None: #throw an error : invalid number of parameters passed return self.cur = dbcon.connectDB(db_type, db_host_name, db_name, db_username, db_password)
def UpdateTagValue(data,tagList): cur = dbcon.startCon(hostname="hashtags.db.10434227.hostedresource.com",username="******",password="******",dbname="hashtags",autocommit=True,databaseType="mysql") booleanMap = checkIfTagsExists(cur,tagList) for (item,tag) in zip(booleanMap,tagList): print item,tag if item: cur.execute("SELECT data FROM tagStore WHERE tag=%s",(tag)) commitdata = cur.fetchall() commitdata = commitdata[0]["data"] commitdata = lexiographicAdd(data,commitdata) cur.execute("UPDATE tagStore SET data='"+str(commitdata)+"' WHERE tag='"+str(tag)+"'") else: createTag(cur,tag,data)
def __del__(self): dbcon.disconnect_db();
def __del__(self): dbcon.disconnectDB();
import DBConnectionHandler import os # # TEST 1 : Connect to MySql cur = DBConnectionHandler.startCon(hostname="localhost",username="******",password="******",dbname="treeofwords",autocommit=True,databaseType="mysql") cur.execute("SELECT * FROM treeofwords.UserAuth") data = cur.fetchall() print str(data) print "\nConnection established and data transfer succesfull." # #TEST 2 : Connect to PostgreSql -- POSTPONED # # TEST 3 : Connect to sqlite3 cur = DBConnectionHandler.startCon(dbname= os.path.dirname(os.path.abspath(__file__))+"\HashTagDB.db",autocommit=True,databaseType="sqlite3") cur.execute("CREATE TABLE TES(TABLE\ ID INT PRIMARY KEY NOT NULL,\ NAME TEXT NOT NULL,\ AGE INT NOT NULL,\ ADDRESS CHAR(50),\ SALARY REAL\ );") cur.execute("INSERT INTO COMPANY VALUES (1,'NAME','10','sd','213')"); data = cur.execute("SELECT * from COMPANY") for row in data: print row print "\nConnection established and data transfer succesfull."