methew / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

Issue inserting records - ProgrammingError: No results. Previous SQL was not a query. #331

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Have tried both with a stored procedure and standard insert but they dont 
appear to work. Please let me know what I am doing wrong here.

from urllib import urlopen
from bs4 import BeautifulSoup
import re
import pyodbc

noCount = """
SET NOCOUNT ON;
"""

cnxn = pyodbc.connect('DRIVER={SQL 
Server};SERVER=Z930-108A;DATABASE=test;UID=user;PWD=friday')
cursor = cnxn.cursor()
for row in cursor.execute(noCount + " select ABSTRACT_ID, ISBN from abstract 
where ISBN is not null;"):
    ABSTRACT_ID = row.ABSTRACT_ID
    ISBN = r"https://www.worldcat.org/ISBN/" + row.ISBN
    print ISBN
    webpage = urlopen(ISBN).read()
    soup2 = BeautifulSoup(webpage)
    DETAIL = soup2.title
#   EXESTRING = " UPDATE ABSTRACT SET TAG = N'" + str(DETAIL) + "' WHERE 
ABSTRACT_ID = " + str(ABSTRACT_ID)
    EXESTRING = " EXEC DBO.sp1 " + str(ABSTRACT_ID) + ",N'" + str(DETAIL) +"'"
    print EXESTRING
    cursor.execute(EXESTRING)
    print cursor.rowcount, 'products updated'
    cnxn.commit()
cnxn.close()

Stored Procedure looks like this

USE [test]
GO
/****** Object:  StoredProcedure [dbo].[sp1]    Script Date: 11/07/2013 
20:16:27 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[sp1]
    -- Add the parameters for the stored procedure here
@ABSTRACT_ID INT,
@TAG NVARCHAR(MAX)
AS
BEGIN

    SET NOCOUNT ON;

UPDATE ABSTRACT 
SET TAG = @TAG WHERE ABSTRACT_ID = @ABSTRACT_ID

END

What is the expected output? What do you see instead?

--- entry should be inserted and move onto the next one

What version of the product are you using? On what operating system?

Windows 8 python 2.7.5

Please provide any additional information below.

Any help would be great.

Thanks

Original issue reported on code.google.com by oli82u...@gmail.com on 11 Jul 2013 at 7:22