以下代码中的assert语句在运行mariadb的环境中失败,而它在运行mysql的(较旧)环境中运行良好。 mariadb环境似乎不会持久化insert语句的结果。与命令行客户端连接确认插入未被保留。
import MySQLdb
def newCon():
return MySQLdb.connect('localhost', 'root', '', 'test')
def testStatement(con, aStatement):
# print "---"
# print aStatement
cur = con.cursor()
cur.execute(aStatement)
result = cur.fetchall()
cur.close()
# print result
return result
def test():
con = newCon()
testStatement(con, "DROP TABLE IF EXISTS TestTable")
testStatement(con, """CREATE TABLE TestTable (
id INT NOT NULL AUTO_INCREMENT,
AccountId VARCHAR(50),
PRIMARY KEY(id))""")
testStatement(con, "INSERT INTO TestTable (AccountId) VALUES ('XYZ')")
myCount1 = testStatement(con, "SELECT count(*) from TestTable")[0][0]
con.close()
con = newCon()
myCount2 = testStatement(con, "SELECT count(*) from TestTable")[0][0]
con.close()
assert myCount1 == myCount2, \
"count1 = " + str(myCount1) + " != count2 = " + str(myCount2)
test()
运行良好的环境是: CentOS 6.7 python 2.6.6 mysql-python 1.2.3 mysql服务器5.1.73
失败的环境是: Fedora 21 python 2.7.8 mysql-python 1.2.3 mariadb server 10.0.21
失败的输出显示:
Test2.py:10: Warning: Table 'mysql.table_stats' doesn't exist
cur.execute(aStatement)
Traceback (most recent call last):
File "Test2.py", line 37, in <module>
test()
File "Test2.py", line 35, in test
"count1 = " + str(myCount1) + " != count2 = " + str(myCount2)
AssertionError: count1 = 1 != count2 = 0
我不知道table_stats警告的内容。
问题:我正确使用api吗?任何人都可以通过mariadb环境进行此测试吗?
答案 0 :(得分:0)
您尚未承诺交易。