python调用mysql存储过程没有反应
ringa_lee
ringa_lee 2017-04-17 17:49:40
0
2
641

建表:

drop table if exists `Account`;
CREATE TABLE `Account` (
`id` BIGINT(20) NOT NULL,
`Name` VARCHAR(100) NOT NULL,
`pwd` VARCHAR(100) NOT NULL,
`times` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0'
)ENGINE=InnoDB

插入数据:

INSERT INTO `Account` (`id`, `Name`, `pwd`, `times`) VALUES
(1, 'Messiah', '59data', 0),
(2, 'zmx', 'data', 0),
(3, '59store', '盖亚', 1);

建立储存过程:

DELIMITER //
DROP PROCEDURE IF EXISTS `proctest`//
CREATE PROCEDURE`proctest`()
BEGIN
insert into  Account
VALUES(5,'盖亚','59store',9);
END //

Python 脚本:

#!/usr/bin/env python
# -*- coding: utf8 -*-
import MySQLdb
import time
import os, sys, string
conn = MySQLdb.connect(host='192.168.1.59',user='59data',passwd='59store',db='test')
cur =conn.cursor()
#sql='call proctest'
#cur.execute(sql)
cur.callproc('proctest',())
cur.close()
conn.close()

Python 脚本用 MySQLdb 模块 callproc 方法调用 mysql 存储过程没有任何反应

ringa_lee
ringa_lee

ringa_lee

membalas semua(2)
左手右手慢动作

猜测应该是缺少事务提交

from django.db import transaction

with transaction.commit_manually():
    conn = MySQLdb.connect(host='192.168.1.59',user='59data',passwd='59store',db='test')
    cur =conn.cursor()
    try:
        cur.callproc('proctest')
        transaction.commit()
    except:
        transaction.rollback()
    finally:
        cur.close()
        conn.close()
    
刘奇

你确定密码和用户名都对,数据库中已经有db-test?

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan