mariadb adodb odbb存储过程调用似乎停止执行vs本机存储过程调用

时间:2015-10-08 14:45:31

标签: vba stored-procedures odbc mariadb

我有一个存储过程,在表A中插入89行,在表B中插入49行,正如我所期望的那样。虽然我注意到HeidiSQL显示150个结果1x1“SQL错误1062”。

然而,当我通过VBA调用查询时,ADODB执行似乎提前中止而没有任何错误到DBEngine。我只得到表A中的39条记录和表B中的6条记录,一致。

我的存储过程从表中获取行,将两个字段插入表A,调用其他一些函数,然后将值插入表B中。

有什么建议吗?这是一些奇怪的odbc错误或我的查询的东西?我不明白为什么存储过程在ODBC调用时会有不同的功能。我尝试使用连接字符串语法进行修改,这似乎没什么区别。

Dim conn2 As ADODB.Connection
Dim cmd2 As ADODB.Command
Dim rs2 As ADODB.Recordset

On Error GoTo err_execute
sConnect = "DSN=hoconet-nms;UID=x;PWD=xxx;"
Set conn2 = New ADODB.Connection
conn2.ConnectionString = sConnect
conn2.Open

sp = "CALL sp_populate_lr_data()"

Set cmd2 = New ADODB.Command
cmd2.ActiveConnection = conn1
cmd2.CommandText = sp

Set rs2 = cmd2.Execute
On Error GoTo 0
Debug.Print "Done populating data "

存储过程:

BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE v_hostname, v_westport,v_eastport,v_ringname VARCHAR(50);
DECLARE v_ringid,v_hostid, v_westid,v_eastid INT DEFAULT NULL;

DECLARE rid CURSOR FOR 
   SELECT hostname,lr_name,lr_id,west_port_name, east_port_name FROM parsed_lr_create;

DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

declare continue handler for sqlexception
    select 'SQLException invoked';

declare continue handler for 1062
    select 'SQL EROR 1062';

declare continue handler for sqlstate '23000'
    select 'SQLSTATE 23000 invoked';

set done = 0;
insert into temp_log (data) values("logging hostname, node_id, west-port-name, west-port-id, east-port-name, east-port-id");

OPEN rid;
get_record: LOOP

    FETCH rid INTO v_hostname, v_ringname,v_ringid,v_westport, v_eastport;

    IF done = 1 THEN
        LEAVE get_record;
    END IF;

   insert into temp_log (data) values (concat("creating lr ", v_ringname, ", ", v_ringid));

    insert into g8032_logical_rings (ring_id, ring_name) values (v_ringid,v_ringname);

    set v_hostid = sp_get_nodeid(v_hostname);
    set v_westid = sp_get_portid(v_hostid, v_westport);
    set v_eastid = sp_get_portid(v_hostid, v_eastport);      

    If (v_hostid = 0 OR v_westid = 0 OR v_eastid = 0) THEN 
        insert into temp_log (data) values (concat("skipping lr config insert ", v_hostname, ", ", v_ringname, ", ",v_westport, ", ", v_eastport));
    ELSE    
        INSERT INTO g8032_logical_rings_configured (ring_id, node_id, west_port_id, east_port_id) values (v_ringid,v_hostid,v_westid,v_eastid);
END IF; 

END LOOP get_record;
CLOSE rid;      
END

感谢您可以抛弃我的任何建议。

1 个答案:

答案 0 :(得分:0)

您可能会混淆使用ADO运行存储过程的两种方法。使用CommandText,您只能以字符串形式输入对象的名称(表/视图/存储过程):

Set conn2 = New ADODB.Connection
conn2.ConnectionString = sConnect
conn2.Open

Set cmd2 = New ADODB.Command
cmd2.ActiveConnection = conn2
cmd2.CommandText = "sp_populate_lr_data"
cmd2.CommandType = adCmdStoredProc

Set rs2 = cmd2.Execute

或者,您可以直接执行操作:

Set conn2 = New ADODB.Connection
conn2.ConnectionString = sConnect
conn2.Open

Set rs2 = New ADODB.Recordset
Set rs2 = conn2.Execute("CALL sp_populate_lr_data()")