当前位置: 首页>>代码示例>>Python>>正文


Python MySQLConnection.commit方法代码示例

本文整理汇总了Python中mysql.connector.MySQLConnection.commit方法的典型用法代码示例。如果您正苦于以下问题:Python MySQLConnection.commit方法的具体用法?Python MySQLConnection.commit怎么用?Python MySQLConnection.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mysql.connector.MySQLConnection的用法示例。


在下文中一共展示了MySQLConnection.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: input_data

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def input_data():

    for x in range(len(gabungan)):
        gabungan[x]

    query = "INSERT INTO data_test " 
    nilai = "VALUES (\"\"," + "\"" + file + "\"" + ","
    for x in range(len(gabungan)):
        nilai = nilai + str(gabungan[x])
        if x < len(gabungan)-1 :
            nilai = nilai + ", " 
            
    query = query + nilai + ")"
#    print query
        
    try:
        db_config = read_db_config()
        conn = MySQLConnection(**db_config)
 
        cursor = conn.cursor()
        cursor.execute(query)
 
        conn.commit()
    except Error as e:
        print('Error:', e)
 
    finally:
        cursor.close()
        conn.close() 
开发者ID:bubgum,项目名称:image-processing,代码行数:31,代码来源:kombinasi.py

示例2: insert_imei

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def insert_imei(query, args):

    try:
        db_config = read_db_config()
        conn = MySQLConnection(**db_config)

        cursor = conn.cursor()
        cursor.execute(query, args)

        if cursor.lastrowid:
            mensaje = ('Last insert id: %s' % (cursor.lastrowid,) )
            print(mensaje)
        else:
           mensaje = 'Last insert id not found'

        conn.commit()
        
    
    except Error as error:
        print(error)

    finally:
        cursor.close()
        conn.close()
        
    return mensaje    
开发者ID:richpolis,项目名称:ServerAndClient,代码行数:28,代码来源:insert_imei.py

示例3: insert_one

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def insert_one(star_name, star_location):
	'''Insert one row into a MySQL database'''
	query = ("INSERT INTO space(star_name, star_location)" 
			 "VALUES(%s, %s)")
	args = (star_name, star_location)

	try:
		db_config = read_db_config()

		#Creating a new MySQLConnection object
		conn = MySQLConnection(**db_config)
		
		#Creating a new MySQLCursor object from the MySQLConnection object
		cursor = conn.cursor()

		#Inserts one row into the database
		cursor.execute(query, args)

		if cursor.lastrowid:
			print('Insert ID: ', cursor.lastrowid)
		else:
			print('Insert Failure')

		conn.commit()

	except Error as error:
		print(error)

	finally:
		cursor.close()
		conn.close()
		print('Connection closed.')
开发者ID:pradyuman,项目名称:python,代码行数:34,代码来源:insertone.py

示例4: insert_many

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def insert_many(stars):
	'''Insert multiple rows into a MySQL database'''
	query = ("INSERT INTO space(star_name, star_location)" 
			 "VALUES(%s, %s)")

	try:
		db_config = read_db_config()

		#Creating a new MySQLConnection object
		conn = MySQLConnection(**db_config)
		
		#Creating a new MySQLCursor object from the MySQLConnection object
		cursor = conn.cursor()

		#Inserts many rows into the database
		cursor.executemany(query, stars)

		conn.commit()

	except Error as error:
		print(error)

	finally:
		cursor.close()
		conn.close()
		print('Connection closed.')
开发者ID:pradyuman,项目名称:python,代码行数:28,代码来源:insertmultiple.py

示例5: data_laundry

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def data_laundry(user,saldo_user):
    kodeLau = randomTiket()
    total = 0
    status = ""
    print '1. Cuci laundry'
    print '2. Cuci laundry + setrika'
    print '3. Cuci laundry + setrika + delivery'
    pilLaundry = input('Masukan pilihan : ')
    berat = input('Masukan berat pakaian : ')
    if pilLaundry == 1 :
        total = 5000 * berat
    elif pilLaundry == 2:
        total = 7000 * berat
    elif pilLaundry == 3:
        total = 7000 * berat + 3000

    fix_update = saldo_user - total
    if fix_update < 0:
        status = "Lunas"
        print "Saldo anda tidak mencukupi"
        tambah_saldo = raw_input("Ingin menambah saldo anda ? ")
        if tambah_saldo == 'y' or 'Y' or 'Ya' or 'YA' or 'ya':
            saldoTambah(saldo_user,fix_update,user)
    else:
        status = "Lunas"
        query1 = "INSERT INTO data_user (kodeLau,user,status,total)"\
             "VALUES(%s,%s,%s,%s)"
        args1 = (kodeLau,user,status,total)

        try:
            dbConfig = bacaConfig()
            connection = MySQLConnection(**dbConfig)
            query = connection.cursor()
            query.execute(query1,args1)
        
            if query.lastrowid:
                print "Data laundry berhasil dimasukan"
                query2 = "UPDATE user SET saldo = %s WHERE user = %s"
                data2 = (fix_update,user)
                try:
                    dbConfig = bacaConfig()
                    conn2 = MySQLConnection(**dbConfig)
                    cursor2 = conn2.cursor()
                    cursor2.execute(query2,data2)
                    conn2.commit()
                except Error as e:
                    print (e)
                finally:
                    cursor2.close()
                    conn2.close()
            else:
                print "Gagal menginput"
            connection.commit()

        except Error as e:
            print (e)

        finally:
            query.close()
        connection.close()
开发者ID:Archimondee,项目名称:Python_Laundry,代码行数:62,代码来源:menuAdmin.py

示例6: insert_book

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def insert_book(title, isbn):
    query = "INSERT INTO books(title, isbn) " "VALUES(%s, %s)"

    args = (title, isbn)

    try:
        db_config = read_db_config()
        conn = MySQLConnection(**db_config)

        cursor = conn.cursor()
        cursor.execute(query, args)

        if cursor.lastrowid:
            print ("last insert id", cursor.lastrowid)
        else:
            print ("last insert id not found")

        conn.commit()

    except Error as error:
        print error

    finally:
        cursor.close()
        conn.close()
开发者ID:Angadlamba,项目名称:comicBio,代码行数:27,代码来源:python_mysql_insert.py

示例7: insert_Face_Details

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def insert_Face_Details(face_id, gender,age,emotion,emotion_percentage):
    query = "INSERT INTO FaceData(face_id, gender,age,emotion,emotion_percentage) " \
            "VALUES(%s,%s,%s,%s,%s)"
    args = (face_id, gender,age,emotion,emotion_percentage)
 
    try:
        db_config = read_db_config()
        conn = MySQLConnection(**db_config) 
 
        cursor = conn.cursor()
        cursor.execute(query, args)
 
        if cursor.lastrowid:
            print('last insert id', cursor.lastrowid)
        else:
            print('last insert id not found') 
 
        conn.commit()
    except Error as error:
        print(error)
 
    finally:
        cursor.close()
        conn.close()
        
    print('Face Data transfered into Database')
开发者ID:uniquearya70,项目名称:Face_Info_Predictor,代码行数:28,代码来源:Facedata_insert.py

示例8: main

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def main():
    print('Put txt file in the same folder of exe!')
    table_name = 'lst_' + (input('Please name your list (lst_ will be add as prefix automatically):').lower())
    if table_name == 'lst_':
        sys.exit(0)
    exist_control = exist_list(table_name)
    if exist_control is None:
        create_table(table_name)
    elif exist_control == 0:
        drop_table(table_name)
        create_table(table_name)
    else:
        print('The named table is exist and contain ' + str(exist_control) + ' Records')
        ask = input('Do you want to drop ' + str(exist_control) + ' table? (yes/no)')
        if ask.lower() == 'yes':
            drop_table(table_name)
            create_table(table_name)

        else:
            print('Exit without any change!')
            sys.exit(0)

    extension = str(input('Please Enter Your Extension(ir,co.ir ,...):'))
    list_method=input('Choice your Method( 1:Auto Letter Generator 2:Import Text File ) :')
    if list_method == '1':
        letter_number = int(input('Number of Letters:'))
        keywords = [''.join(i) for i in product(ascii_lowercase, repeat=letter_number)]
        db_config = read_db_config()
        conn = MySQLConnection(**db_config)

        for line in range(0, len(keywords)):
            cursor = conn.cursor()
            Query = "insert into %s (site) values (concat('%s','.','%s'));" \
                    % (table_name, '{0}'.format(str(keywords[line])),extension)
            cursor.execute(Query)
            print(str(line+1),end='\r')
        print(str(line+1),'Records Imported!')
    elif list_method == '2':
        dic_filename_mask = str(input('Whats the Text Dictionary Filename {without extension}:'))
        filename = dic_filename_mask + '.txt'
        dic_list = open(filename)
        print('Total Count of Records: ' + str(sum(1 for _ in dic_list)))
        dic_list.close()
        db_config = read_db_config()
        conn = MySQLConnection(**db_config)
        cursor = conn.cursor()
        load_text_file_query = "LOAD DATA LOCAL INFILE '%s' INTO TABLE %s  LINES TERMINATED BY '\\r\\n' (SITE);" \
                               % (filename, table_name)
        print('Transferring List...')
        cursor.execute(load_text_file_query)
        print('Add Extension to list...')
        update_extension_query = "update %s set site=concat(site,'.','%s')" % (table_name, extension)
        cursor.execute(update_extension_query)
        conn.commit()
        cursor.close()
        conn.close()
    else:
        print('Wrong Choice,Bye!')

    print("Finish")
开发者ID:saman-dadmand,项目名称:WhoisScanner,代码行数:62,代码来源:ListCreator.py

示例9: delete_one

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def delete_one(star_id):
	'''Delete one row of a MySQL database'''
	query = "DELETE FROM space WHERE id = %s"

	try:
		db_config = read_db_config()

		#Creating a new MySQLConnection object
		conn = MySQLConnection(**db_config)
		
		#Creating a new MySQLCursor object from the MySQLConnection object
		cursor = conn.cursor()

		#Deletes one row in the database
		cursor.execute(query, (star_id,))

		conn.commit()

	except Error as error:
		print(error)

	finally:
		cursor.close()
		conn.close()
		print('Connection closed.')
开发者ID:pradyuman,项目名称:python,代码行数:27,代码来源:deleteone.py

示例10: dataDiri

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def dataDiri(user):
    pswd = getpass.getpass('Masukan password : ',stream = None)

    akses = "Anggota"
    alamat = raw_input("Masukan alamat valid : ")
    hp = input("Masukan nomor hp valid : ")    
    email = raw_input("Masukan email valid : ")
    saldo = 10000
    query = "INSERT INTO user (user,pswd,akses,saldo,alamat,hp,email)"\
            "VALUES (%s,%s,%s,%s,%s,%s,%s)"
    args = (user,pswd,akses,saldo,alamat,hp,email)

    try:
        dbConfig = bacaConfig()
        conn = MySQLConnection(**dbConfig)

        cursor = conn.cursor()
        cursor.execute(query,args)

        nilaiId = 100000
        if cursor.lastrowid:
            print('Sukses mendaftar')
        else:
            print("Last insert id not found")

        conn.commit()
        
    except Error as e:
        print(e)

    finally:
        cursor.close()
        conn.close
开发者ID:Archimondee,项目名称:Python_Laundry,代码行数:35,代码来源:register.py

示例11: update_book

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def update_book(book_id, title):
    # read database configuration
    db_config = read_db_config()

    # prepare query and data
    query = """ UPDATE books
                SET title = %s
                WHERE id = %s """

    data = (title, book_id)

    try:
        conn = MySQLConnection(**db_config)

        # update book title
        cursor = conn.cursor()
        cursor.execute(query, data)

        # accept the changes
        conn.commit()

    except Error as error:
        print(error)

    finally:
        cursor.close()
        conn.close()
开发者ID:amaur,项目名称:LearnPython,代码行数:29,代码来源:learnOS.py

示例12: register_data

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def register_data(request):
    try:
        username = request.POST.get('username','')
        email = request.POST.get('email', '')
        phone = request.POST.get('phone', '')

        Error_dict = {}

        if(username == '' or email == "" or phone == "" ) :
            Error_dict['Invalid'] = "Enter Correct Values"

        else:
            dbconfig = {'password': 'root', 'host': 'localhost', 'user': 'root', 'database': 'login_database'}
            conn = MySQLConnection(**dbconfig)
            cursor = conn.cursor()
            cursor.execute("select COUNT(*) from client_info where  phone_no = " + str(phone) + " ")
            count = cursor.fetchone()
            count = count[0]
            if(count > 0):
                Error_dict['user_exist'] = "User Already Exist"
            else:
                cursor.execute("insert into client_info (Name , email, phone_no) values ('%s', '%s', '%s')" % (username, email, phone))
                conn.commit()
                return HttpResponseRedirect('register_success')
    except Error as e:
        print(e)

    return render_to_response('register_form.html',  Error_dict)
开发者ID:leenakhote,项目名称:Login_Module,代码行数:30,代码来源:views.py

示例13: insert_name

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def insert_name(name, gender):
    query = "INSERT INTO babynames(babyName, gender) " \
            "VALUES(%s,%s)"

    args = (name, gender)
 
    try:
        db_config = read_db_config()
        conn = MySQLConnection(**db_config)
 
        cursor = conn.cursor()
        cursor.execute(query, args)
 
        if cursor.lastrowid:
            print('last insert id', cursor.lastrowid)
        else:
            print('last insert id not found')
 
        conn.commit()
    except Error as error:
        print(error)
 
    finally:
        cursor.close()
        conn.close()
开发者ID:yxnely,项目名称:practice-flask,代码行数:27,代码来源:python_mysql_dbinsert2.py

示例14: update_one

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def update_one(star_id, star_location):
	'''Update a field in a MySQL database'''
	query = ("UPDATE space" 
			 "SET star_name = %s"
			 "WHERE id = %s")
	args = (star_name, star_id)

	try:
		db_config = read_db_config()

		#Creating a new MySQLConnection object
		conn = MySQLConnection(**db_config)
		
		#Creating a new MySQLCursor object from the MySQLConnection object
		cursor = conn.cursor()

		#Updates a field in the database
		cursor.execute(query, args)

		conn.commit()

	except Error as error:
		print(error)

	finally:
		cursor.close()
		conn.close()
		print('Connection closed.')
开发者ID:pradyuman,项目名称:python,代码行数:30,代码来源:updateone.py

示例15: insert_character

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import commit [as 别名]
def insert_character(char_id, name, realname, gender, origin, image, siteurl, deck):
	query = "INSERT INTO characters(id, name, realname, gender, origin, image, siteurl, deck) " \
			"VALUES(%s, %s, %s, %s, %s, %s, %s, %s)"  

	args = (char_id, name, realname, gender, origin, image, siteurl, deck)

	try:
		db_config = read_db_config()
		conn = MySQLConnection(**db_config)

		cursor = conn.cursor()
		cursor.execute(query, args)
		
		if cursor.lastrowid:
			print('last insert id', cursor.lastrowid)
		else:
			print('last insert id not found')

		conn.commit()

	except Error as error:
		print error

	finally:
		cursor.close()
		conn.close()
开发者ID:Angadlamba,项目名称:comicBio,代码行数:28,代码来源:character_insert.py


注:本文中的mysql.connector.MySQLConnection.commit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。