Exemplo n.º 1
0
def cursor(database=DATABASE):
    """Establish the connection with the database. 
    Will change in beta version so that only one connection is used throughout app."""
    DSN = dbconn2.read_cnf()
    DSN['db'] = database
    conn = dbconn2.connect(DSN) 
    return conn.cursor(MySQLdb.cursors.DictCursor)
Exemplo n.º 2
0
def dictCursor():
    global dbconn
    dsn = dbconn2.read_cnf('/home/hugh9/.my.cnf')
    dsn['db'] = 'janice'
    dbconn = dbconn2.connect(dsn)
    curs = dbconn.cursor(MySQLdb.cursors.DictCursor)
    return curs
Exemplo n.º 3
0
def server(database):
    '''Returns a cursor to the database'''
    dsn = dbconn2.read_cnf('/students/dormdata/.my.cnf')
    dsn['db'] = database
    conn = dbconn2.connect(dsn)
    conn.autocommit(True)
    return conn.cursor(MySQLdb.cursors.DictCursor)
Exemplo n.º 4
0
def init():
    dsn = dbconn2.read_cnf(".my.cnf")
    dsn['db'] = 'wzhang2_db'
    dsn['host'] = 'localhost'
    conn = dbconn2.connect(dsn)
    conn.autocommit(True)
    return conn
Exemplo n.º 5
0
def connect(database, user): 
	''' 
	Connects to the provided database using my cnf file and returns the connection
	'''
	dsn = dbconn2.read_cnf('/students/' + user + '/.my.cnf')
	dsn['db'] = database
	conn = dbconn2.connect(dsn)
	return conn
Exemplo n.º 6
0
def row_iter(query):
    dsn = dbconn2.read_cnf()
    conn = dbconn2.connect(dsn)
    curs = conn.cursor(MySQLdb.cursors.DictCursor)
    numrows = curs.execute(query)
    print 'total of {} rows'.format(numrows)
    while True:
        row = curs.fetchone()
        if row is None:
            raise StopIteration
        yield row
Exemplo n.º 7
0
'''
calpal
Mollee Jain, Serry Park, Selina Sotomayor
schedule.py 

This is a file that includes helper functions that helps the CGI python file collect the data and 
display what the user wants. 
Last updated: 5/15/2016
'''

#imports
import MySQLdb
import dbconn2

#setup
dsn = dbconn2.read_cnf('/students/calpal/.my.cnf')
dsn['db'] = 'random'  #current database being used
dsn['host'] = 'localhost'
conn = dbconn2.connect(dsn)
curs = conn.cursor()


#queryCourse()
#Takes in the crn of a course and returns the entire course entry in raw data (in a tuple format)
def queryCourse(crn):
    if (crn == '' or crn is None):
        return "Please enter CRN"
    curs.execute("SELECT * FROM course_data WHERE CRN = %s", (crn, ))
    courseList = curs.fetchone()
    if courseList is None or courseList == '':
        return "CRN not in database"
Exemplo n.º 8
0
# CS304-Final Project
# Created by: Megan Shum, Maxine Hood, Mina Hattori
#!/usr/local/bin/python2.7
# This file handles all the SQL calls for the search page.

import sys
import MySQLdb
import dbconn2


def searchExists(conn, username):
    '''Returns all of the user's pic post from the database in the form of a dictionary'''
    curs = conn.cursor(MySQLdb.cursors.DictCursor)  # results as Dictionaries
    curs.execute('select username from user where username = %s', [username])
    exists = curs.fetchone()
    return bool(exists)


# ================================================================
# This starts the ball rolling, *if* the script is run as a script,
# rather than just being imported.

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print "Usage: {name} nm".format(name=sys.argv[0])
    else:
        DSN = dbconn2.read_cnf()
        DSN['db'] = 'mmm_db'  # the database we want to connect to
        dbconn2.connect(DSN)
        print lookupByNM(sys.argv[1])
Exemplo n.º 9
0
def cursor(database=DATABASE):
    DSN = dbconn2.read_cnf()
    DSN['db'] = database
    conn = dbconn2.connect(DSN)
    return conn.cursor(MySQLdb.cursors.DictCursor)
Exemplo n.º 10
0
def get_dsn():
    return dbconn2.read_cnf()
def get_dsn(db='yourroom_db'):
    dsn = dbconn2.read_cnf()
    dsn['db'] = db
    return dsn
Exemplo n.º 12
0
        else:
            return "The dish " + dish + " already exists for the restaurant " + resName + "."


# def main(dishID):
#     dsn = dbconn2.read_cnf(".my.cnf")
#     dsn['db'] = 'twen2_db'
#     dsn['host'] = 'localhost'
#     conn = dbconn2.connect(dsn)
#     conn.autocommit(True)
#     curs = conn.cursor(MySQLdb.cursors.DictCursor)
#     curs.execute('''UPDATE dishes SET num_of_likes = %s WHERE id = %s''', (like, dishID))
#     return

if __name__ == "__main__":
    dsn = dbconn2.read_cnf(".my.cnf")
    dsn['db'] = 'twen2_db'
    dsn['host'] = 'localhost'
    conn = dbconn2.connect(dsn)
    conn.autocommit(True)
    data = cgi.FieldStorage()
    dishID = data.getfirst('dishID')
    dishLike = data.getfirst('dishLike')
    imcrementLike(conn, dishID, dishLike)


# update the number of like for each dish after user click the like button
def incrementLike(conn, dishID, userID, like):
    curs = conn.cursor(MySQLdb.cursors.DictCursor)
    curs.execute('''UPDATE dishes SET num_of_likes = %s WHERE id = %s''',
                 (like, dishID))
Exemplo n.º 13
0
          pid = request.form['projectID']
          updateDB.deleteProject(conn, pid) 
          flash("Project Deleted")
        projects = updateDB.getUserProjects(conn, uid)
        return render_template('clientProjects.html',
                              projects = projects,
                              role = roleCheck
                             )
      else:
        flash('Only clients have access to this page, please login with a client account')
        return redirect( url_for('index') )
    else:
        flash('You are not logged in. Please login or join')
        return redirect( url_for('index') )
  except Exception as e:
    flash(e)
    return redirect( url_for('index') )

if __name__ == '__main__':

    if len(sys.argv) > 1:
        # arg, if any, is the desired port number
        port = int(sys.argv[1])
        assert(port>1024)
    else:
        port = os.getuid()
    dsn = dbconn2.read_cnf()
    dsn['db'] = 'wprojdb_db'
    app.debug = True
    app.run('0.0.0.0',port)
def connectToDB(path_to_cnf, db_name):
    dsn = dbconn2.read_cnf(path_to_cnf)
    dsn['db'] = db_name
    conn = dbconn2.connect(dsn)
    return conn
Exemplo n.º 15
0
def getConn():
    DSN = dbconn2.read_cnf('~/.my.cnf')
    DSN['db'] = 'codemode_db'
    conn = dbconn2.connect(DSN)
    return conn
Exemplo n.º 16
0
def main():
    dsn = dbconn2.read_cnf()
    dbconn2.connect(dsn)
    compute_insulin_on_board(conn)
Exemplo n.º 17
0
def dictCursor():
    dsn = dbconn2.read_cnf('/home/hugh9/.my.cnf')
    conn = dbconn2.connect(dsn)
    curs = conn.cursor(MySQLdb.cursors.DictCursor)
    return curs
Exemplo n.º 18
0
def get_dsn(file='/home/hugh9/.my.cnf'):
    if DSN is None:
        DSN = dbconn2.read_cnf('/home/hugh9/.my.cnf')
    return DSN
Exemplo n.º 19
0
def getConn():
    DSN = dbconn2.read_cnf()
    DSN['db'] = 'scottai_db'
    return dbconn2.connect(DSN)
Exemplo n.º 20
0
def get_dsn():
    global DSN
    if DSN is None:
        DSN = dbconn2.read_cnf('/home/hugh9/.my.cnf')
    return DSN
Exemplo n.º 21
0
calpal
Mollee Jain, Serry Park, Selina Sotomayor
schedule.py 

This is a file that includes helper functions that helps the CGI python file collect the data and 
display what the user wants. 
Last updated: 5/15/2016
'''


#imports
import MySQLdb
import dbconn2

#setup
dsn = dbconn2.read_cnf('/students/calpal/.my.cnf')
dsn['db'] = 'random' #current database being used
dsn['host'] = 'localhost'
conn = dbconn2.connect(dsn)
curs = conn.cursor() 

#queryCourse()
#Takes in the crn of a course and returns the entire course entry in raw data (in a tuple format)
def queryCourse(crn):
    if (crn == '' or crn is None):
        return "Please enter CRN"
    curs.execute("SELECT * FROM course_data WHERE CRN = %s",(crn,))
    courseList = curs.fetchone()
    if courseList is None or courseList == '':
        return "CRN not in database"
    return courseList
Exemplo n.º 22
0
def getConn(db='yourroom_db'):
    dsn = dbconn2.read_cnf()
    dsn['db'] = db
    return dbconn2.connect(dsn)
Exemplo n.º 23
0
def getConn():
	DSN = dbconn2.read_cnf()
	DSN['db'] = 'bramanud_db' #LOSER
	return dbconn2.connect(DSN)