def getUserRequests(user = None, project = None): """Returns 'project join' requests for given data or all requests""" db = openDB() cur = db.cursor() if project and user: res = cur.execute('select * from project_requests where user=%s and \ project=%s limit 1', (user, project)) elif not project and not user: res = cur.execute('select * from project_requests where user=%s \ limit 1', (id, )) elif project and not user: res = cur.execute('select * from project_requests where \ project=%s limit 1', (project, )) elif not project and user: res = cur.execute('select * from project_requests where user=%s and \ limit 1', (user, )) db.close() return cur.fetchall()
def main(): condicion = True while (condicion): db = MySQLdb.connect("127.0.0.1", "root", "root", "bazar") cursor = db.cursor() print "1.-Agregar producto" print "2.-Ver productos" print "3.-Registrar ventas" print "4.-Ver registro de ventas" print "5.-Salir" opcion = input("Ingresa una opcion: ") if (opcion == 1): agregar(db, cursor) elif (opcion == 2): ver(db, cursor) elif (opcion == 3): registrar(db, cursor) elif (opcion == 4): ver_registro(db, cursor) elif (opcion == 5): print "Muchas gracias por usar el sistema de bazar creado por Hector Fierro" MySQLdb.close(db) exit() else: print "Opcion no valida favor reintentar"
def listUsers(): """Return list of ids for all users""" db = openDB() c = db.cursor() res = c.execute("select login from users") db.close() return [x[0] for x in c.fetchall()]
def addUserRequest(user, project): """Add 'project join' requests""" db = openDB() c = db.cursor() c.execute('insert into project_requests values (%s, %s)', (user, project)) db.close()
def getCapabilities(user): db = openDB() c = db.cursor() res = c.execute("select action, scope from capabilities where user = %s", (user,)) db.close() return c.fetchall()
def userProjects(id): """Returns all project for user with given _id_""" db = openDB() c = db.cursor() c.execute('select project from user_project where \ user=%s', (id,)) db.close() return c.fetchall()
def getUserData(id): """Get all public user data (without pass hashs)""" db = openDB() c = db.cursor() if not findUser(id): raise ScalakError("User doesn't exists") c.execute('select login, name, last_name, email, note from users where \ login=%s limit 1', (id,)) db.close() return c.fetchone()
def valid_password(env, username, password): """Check given auth data against DB; env may be None""" db = openDB() c = db.cursor() res = c.execute("select password from users where login=%s limit 1", (username,)) if not res: return False res = c.fetchone()[0] db.close() return res == htpasswd(password, res[0] + res[1])
def getAdmin(project): """Returns admin for given _project_""" db = openDB() c = db.cursor() res = c.execute('select admin from projects where id=%s limit 1', (project,)) if not res: return False res = c.fetchone()[0] db.close() return res
def updateSQL(query,ipaddress,database,user,password): import MySQLdb # Open database connection db = MySQLdb.connect(ipaddress,user,password,database) # prepare a cursor object using cursor() method cursor = db.cursor() # execute SQL query using execute() method. numrows = cursor.execute(query); db.commit() db.close() return numrows
def findUser(id, project = None): """Check if user with given _id_ exists globally or in _project_ if given""" db = openDB() c = db.cursor() if not project: res = c.execute("select login from users where login=%s limit 1", (id,)) else: res = c.execute("select login from users, user_project where login=%s \ and login=user and project=%s limit 1", (id, project)) db.close() if not res: return False return True
tables = ['productName', 'storageLocal', 'brandName', 'prices', 'vendor', 'departments'] for table in tables: MySQLdb.db('inventory').table_create(table).run() #Get contact number from vendor ContactNum = cursor.execute("""SELECT name, phone_number FROM vendor WHERE name=%s AND clue > %s LIMIT 5""", (name, clue_threshold)) cursor.execute(ContactNum) def FetchOneAssoc(cursor) : data = cursor.fetchone() if data == None : return None desc = cursor.description dict = {} for (name, value) in zip(desc, data) : dict[name[0]] = value return dict MySQLdb.close()
y_range=(0, int(max(DISTANZA3D) + min(DISTANZA3D))), x_range=(0, 7), y_grid_style=None, y_grid_interval=int((max(DISTANZA3D)) / 10), loc=(0, -300)) plot3 = line_plot.T(label="distanza percorsa 3D", data=data3D, ycol=1, tick_mark=tick_mark.star) ar_3D.add_plot(plot3) ar_3D.draw() y3D1axis = axis.Y(offset=300, label_offset=(50, 0), label="Errore 3D") ar_3D = area.T(size=size3D, x_axis=xaxis, y_axis=y3D1axis, x_range=(0, 7), y_range=(0, int(max(ERRORE3D) + min(ERRORE3D))), y_grid_style=None, y_grid_interval=int((max(ERRORE3D)) / 10), loc=(0, -300), legend=legend.T(loc=(330, -315))) plot4 = line_plot.T(label="errore 3D", data=data3D, ycol=2, tick_mark=tick_mark.square) ar_3D.add_plot(plot4) ar_3D.draw() else: print "Non e' possibile analizzare un percorso costituito di un solo punto. Inserisci due date diverse." mdb.close()
#!/usr/bin/python # -*- coding: utf-8 -*- import MySQLdb as mdb import sys con = mdb.connect('localhost', 'testuser', 'test623', 'testdb') with con: cur = con.cursor() cur.execute("CREATE TABLE IF NOT EXISTS \ Writers(Id INT PRIMARY KEY AUTO_INCREMENT, Name VARCHAR(25))") cur.execute("INSERT INTO Writers(Name) VALUES('Jack London')") cur.execute("INSERT INTO Writers(Name) VALUES('Honore de Balzac')") cur.execute("INSERT INTO Writers(Name) VALUES('Lion Feuchtwanger')") cur.execute("INSERT INTO Writers(Name) VALUES('Emile Zola')") cur.execute("INSERT INTO Writers(Name) VALUES('Truman Capote')") # Safety first... or last. mdb.close()
s.sendline('cat /proc/cpuinfo') s.prompt() CPU = s.before str(CPU) s.sendline('service --status-all') s.prompt() SERVICE = s.before str(SERVICE) s.logout() except pxssh.ExceptionPxssh, e: print 'falha ao logar no ssh' print str(e) try: con = my.connect('localhost', 'root', 'djjb022000', 'assesment'); cur = con.cursor() sql = "INSERT INTO pxssh(py_hostname, py_uname, py_user, py_dfh, py_dfi, py_iptables, py_uptime, py_free, py_cpu, py_services) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)" args= (hostname,UNAME,username,DISK,INODE,FIREWALL,UPTIME,MEMORI,CPU,SERVICE) #Inserindo os dados na DATABASE cur.execute(sql, args) con.commit() my.close() except: print "Erro ao tentar inserir os dados"
FROM zipcensus zc WHERE zipcode IN (%s)) comp) z LEFT OUTER JOIN zipcounty zco ON z.zipcode = zco.zipcode WHERE distcirc < 8 ORDER BY distcirc""", zipcode) query2 = [] rows = cur.fetchall() for row in rows: query2.append(row) top_ten = [] #specific to this query for i in range(0, len(query2)): if(i < 11): temp_dic = {"city": query2[i][2], "zipcode": query2[i][0], "match_latitude":query2[i][7], "match_longitude": query2[i][8]} top_ten.append(temp_dic) else: break #display choices on a map and let user pick the best cur.close() db.close() if __name__ == '__main__': main()
def close(): MySQLdb.close()
def disconnectToMySQL(self): mysql.close(self.conn)