def hello(): conn = mysql.connect() cursor = conn.cursor() cursor.execute("Select * from user") a = cursor.fetchall() users = json.dumps(a) return Response(users, status=200)
def inventory_forecast_details(request, pk): item = Inventory.objects.get(id=pk) cursor = connection.cursor() forecast_ses = [] forecast_hwes = [] forecast_moving_average = [] forecast_arima = [] ink = str("'" + item.item + "'") if item.item_type == 'Raw Materials': product = Product.objects.get(material_type=item.rm_type) query = 'SELECT po.date_issued, poi.quantity DIV 1000 AS "quantity" FROM production_mgt_joborder po, sales_mgt_clientitem poi WHERE ' \ ' poi.products_id = ' + str(product.id) elif item.item_type == 'Ink': query = 'SELECT po.date_issued, `poi`.`quantity` DIV 2500 AS "quantity" FROM production_mgt_joborder po, sales_mgt_clientitem poi WHERE ' \ ' `poi`.`color` = '+str(ink) else: query = 'SELECT spo.date_issued, spoi.quantity FROM inventory_mgt_supplierpo spo, ' \ 'inventory_mgt_supplierpoitems spoi where spoi.item_id = ' + str(pk) + 'and spoi.supplier_po_id = spo.id' cursor.execute(query) df = pd.read_sql(query, connection) a = TimeSeriesForecasting.forecast_ses(df) a[1] = int(float(a[1])) forecast_ses.extend(a) b = TimeSeriesForecasting.forecast_hwes(df) b[1] = int(float(b[1])) forecast_hwes.extend(b) c = TimeSeriesForecasting.forecast_moving_average(df) c[1] = int(float(c[1])) forecast_moving_average.extend(c) request.session['forecast_ses'] = forecast_ses request.session['forecast_hwes'] = forecast_hwes request.session['forecast_moving_average'] = forecast_moving_average request.session['item'] = item.id if 'ses_order' in request.GET: request.session['forecast'] = 'SES' return redirect('inventory:supplierPO_form') elif 'hwes_order' in request.GET: request.session['forecast'] = 'HWES' return redirect('inventory:supplierPO_form') elif 'moving_average_order' in request.GET: request.session['forecast'] = 'MOVING' return redirect('inventory:supplierPO_form') else: request.session['forecast'] = None context = { 'item': item, 'forecast_ses': forecast_ses, 'forecast_hwes': forecast_hwes, 'forecast_moving_average': forecast_moving_average, 'forecast_arima': forecast_arima, } return render(request, 'inventory/inventory_forecast_details.html', context)
def getLastJobId(): cursor.execute( "SELECT jenkins_id FROM Jobs ORDER BY jenkins_id DESC LIMIT 1") job = cursor.fetchone() if (job != None): return job.jen_id else: return None
async def on_read(): cursor.execute("""CREATE TABLE IF NOT EXISTS users ( name TEXT, id INT, cash BIGINT, rep INT, lvl INT, repp INT, thanks TEXT, rep-me TEXT,""")
def get_subfolders(cursor, folder_ids, blacklist): sql = "SELECT id from moz_bookmarks WHERE type=2 AND parent IN({SEQ1}) AND title NOT IN({SEQ2})".format( SEQ1=','.join(['?'] * len(folder_ids)), SEQ2=','.join(['?'] * len(folder_blacklist))) cursor.execute(sql, folder_ids + blacklist) rows = c.fetchall() if len(rows) == 0: return folder_ids else: return folder_ids + get_subfolders( cursor, tuple([row[0] for row in rows]), blacklist)
def login(): conn = mysql.connect() cursor = conn.cursor() code = request.form['code'] phone_number = request.form['phone_number'] cursor.execute("select * from user where code = %s and phone_number = %s", (code, phone_number)) check = cursor.fetchone() users = json.dumps(check) if check is None: return 'You are not verified' else: print('You are verified and your credentials are /n ') return Response(users, status=2000)
async def __th(ctx, member: discord.Member = None): if member is None: await ctx.send(embed=discord.Embed( description= f'У **{ctx.author}**, укажите пользователя, которому хотите отправить благодарность' )) else: if member.id == ctx.author.id: await ctx.send( f'**{ctx.author}**, нельзя выдавать благодарности самому себе!' ) else: cursor.execute( "UPDATE users SET repp = repp + {} WHERE id = {}".format( 1, member.id)) connection.commit() await ctx.message.add_reaction('✔️')
def fnf(): conn = mysql.connect() cursor = conn.cursor() fnf = request.form['phone_number'] data = fnf.split(',') alldata = [] fl = [] fr = [] for i in data: alldata.append(i) for j in alldata: cursor.execute( "select name, phone_number from user where phone_number = %s", j) data = cursor.fetchone() if data is not None: fr = {'name': data[0], 'phone_number': data[1]} fl.append(fr) list = {'list': fl} users = json.dumps(list) return Response(users, status=2000)
def add_data(): conn = mysql.connect() cursor = conn.cursor() name = request.form['name'] phone_number = request.form['phone_number'] codes = random.randint(100000, 999999) users = json.dumps(codes) c = cursor.execute( "INSERT INTO user (name, phone_number, code) VALUES (%s,%s,%s)", (name, phone_number, int(codes))) conn.commit() if (c == True): print("Your Verificatiopn code is----/n") return Response(users, status=2000) else: return 'Not Registered'
async def __repp(ctx, member: discord.Member = None): if member is None: await ctx.send(embed=discord.Embed( description= f'У **{ctx.author}** {cursor.execute("SELECT repp FROM users WHERE id = {}".format(ctx.author.id)).fetchone()[0]} благодарностей' )) else: if cursor.execute("SELECT repp FROM users WHERE id = {}".format( member.id)).fetchone()[0] == 1: await ctx.send(embed=discord.Embed( description= f'У **{member}** {cursor.execute("SELECT repp FROM users WHERE id = {}".format(member.id)).fetchone()[0]} благодарность' )) else: await ctx.send(embed=discord.Embed( description= f'У **{member}** {cursor.execute("SELECT repp FROM users WHERE id = {}".format(member.id)).fetchone()[0]} благодарностей' ))
hot2 = table.xpath(".//div[@class='HotItem-metrics']/text()") if len(hot1) == 0: heat = hot2[0] else: heat = hot1[0] hotList = HotList(ranking, title, link, heat, nowTime) # 使用cursor()方法获取操作游标 cursor = db.cursor() sql = "INSERT INTO hot_list (ranking,title,link,heat,create_time) VALUES ('" + ranking + "', '" + title + "', '" + link + "', '" + heat + "','" + nowTime + "')" print(sql) try: # 执行sql语句 cursor.execute(sql) # 提交到数据库执行 db.commit() except: # 如果发生错误则回滚 db.rollback() # 使用cursor()方法获取操作游标 cursor = db.cursor() sql = "INSERT INTO hot(hot_item,create_time) VALUES ('" + json.dumps( items, ensure_ascii=False) + "','" + nowTime + "') " print(sql) try: # 执行sql语句 cursor.execute(sql)
import MySQLdb as sqlDb import cursor as cursor db = sqlDb.connect("localhost", "root", "password", "test") cursor = db.cursor() cursor.execute("insert into sara values(100) ") #result = cursor.fetchall() db.close()
import cursor as cursor import mysql.connector # Connecting to database mydb = mysql.connector.connect(host="localhost", user="******", passwd="GGrfefRW$$2242", database="system") binaryDocument = [] cursor = mydb.cursor() # Executing Query cursor.execute( "SELECT DOCUMENT_BLOB FROM DATABASE_NAME.DOCUMENT_IMG WHERE ID_DOCUMENT = 42" ) # Looping over lines of query's return for line in cursor: binaryDocument.append(line) # Writing each binary contained in binaryDocument variable in a PDF file i = 0 for binary in binaryDocument: file = open("./documents/doc%s.pdf" % str(i + 1), "+wb") file.write(binary[0]) file.close() i = i + 1
# fetch and insert into another table import cursor as cursor import mysql.connector # Establish MySQL database Connection from Python connection = mysql.connector.connect(host='localhost', port = 3306, database='ecommerce', user='******', password='') # Define the SELECT statement query. Here you need to know the table, and it’s column details. cursor.execute('select * from customers') for row in cursor.fetchall(): # If you wanted all of the data to pass through Python, you could do the following: cursor.execute ('insert into mycustomer values ' + str(tuple(row))) cursor.execute('insert into mycustomer (CustomerID, CustomerName, ContactName, Address, City,PostalCode, Country) select CustomerID, CustomerName, ContactName, Address, City,PostalCode, Country, now() from customers')
import MySQLdb as sqlDb import cursor as cursor #db = sqlDb.connect("localhost", "root", "password", "test") db1=sqlDb.connect("localhost",'root','password','loany') cursor = db1.cursor() query = "select * from loans" cursor.execute(query) #result = cursor.fetchall() db1.close()
def get(): SQLCommand = ("SELECT EMPNO " "FROM employees" "limit 5") cursor.execute(SQLCommand) results = cursor.fetchall() while results: print("YEmpno " + str(results[0]))