1

I'm trying to accomplish following query:

sql = "INSERT INTO adr_citydistricts (CityDistrict, CityDistrictRU) VALUES (% (ua) s,% (ru) s);"
data = {'ua': 'ukrainian', 'ru': 'russian'}
cursor.execute (sql, data)

After executing this query, there is no such record in table.

If do the same query in SQLyog, record will exists.

I've also tried:

sql = "INSERT INTO adr_citydistricts (CityDistrict, CityDistrictRU) VALUES ('123 ', '333');"
cursor.execute (sql)
print sql

and there is no row in the table.

The console displays : INSERT INTO adr_citydistricts (CityDistrict, CityDistrictRU) VALUES ('123 ', '333');

Executing this query in SQLyog, normally inserts a row in the table.

I've created another table with the same structure.

Can someone help me, please?

3
  • 'osuschastvlyaetsya' - hah. Is it translated word from google? For finish sql transaction, you need to commit it. Commented Jan 25, 2014 at 9:47
  • @AntonBarycheuski in case you understand what that word mean, would you mind editing the question and translating it in English? Thanks. Commented Jan 25, 2014 at 9:55
  • @StefanoSanfilippo, Ok. I have correct it and rephrase some items. Commented Jan 26, 2014 at 11:43

1 Answer 1

2

You need to cursor.commit() to reflect changes.

9.2.3. Method MySQLConnection.commit()

This method sends a COMMIT statement to the MySQL server, committing the current transaction. Since by default Connector/Python does not autocommit, it is important to call this method after every transaction that modifies data for tables that use transactional storage engines.

Sign up to request clarification or add additional context in comments.

1 Comment

db = MySQLdb.connect(host="localhost",user="root", passwd="*****", db="test", charset='utf8') cursor = db.cursor() sql = "INSERT INTO adr_citydistricts (CityDistrict, CityDistrictRU) VALUES ('123', '333');" cursor.execute(sql) db.commit()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.