Python Forum
This result object does not return rows. It has been closed automatically
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
This result object does not return rows. It has been closed automatically
#1
Hi colleagues, Can you help me with this? I know that here are the most of discussion about this problem, but i can not solve it. I red that i have to use SET NOCOUNT ON; but it does not work
this is my script , which works in sql, but when i run his in python i get "This result object does not return rows. It has been closed automatically "

This script is saved aj sql1.sql , i use it in this
from sqlalchemy import create_engine
engine = create_engine()
f = open("sql1.sql", 'r')
df = pd.read_sql(f.read(),engine)
This is not python but SQL , it is sql1.sql
--update num2

declare
v_temp_date Date := '01.01.1900';

begin
for c in (
select t.r1, t.date1, t.num1, t.num3
from table t

order by t.r1, t.num1
)
loop
  if c.num1 = 1 or c.date1 >= v_temp_date then
    update table x set x.num2 = 0
    where x.num3 = c.num3;
    --v_go := True;
    v_temp_date := c.date1 + 90;
 elsif c.date1 < v_temp_date then
   update table  x set x.num2 = 1
   where x.num3 = c.num3;
 end if;
 commit;
 
  end loop;
  end;
Output:
ResourceClosedError: This result object does not return rows. It has been closed automatically.
Reply
#2
Please post all the code.
Reply
#3
(Jan-10-2024, 06:35 PM)deanhystad Wrote: Please post all the code.

I updated the code
Reply
#4
Go read this:

https://www.geeksforgeeks.org/connecting...qlalchemy/
Reply
#5
(Jan-10-2024, 08:39 PM)deanhystad Wrote: Go read this:

https://www.geeksforgeeks.org/connecting...qlalchemy/
I red it , but problem is not how connect pandas with SQL , I know it , But when I use this script SQL (sql1.sql) it does not work and i get.
"This result object does not return rows. It has been closed automatically". I do not know where is mistake in the script SQL, because when i Run this script in SQL it works, But When i Run in Python it does not work.
Reply
#6
I think the problem is exactly how to connect pandas to the database. I don't see how your code can possibly work, even if you ditch the script and try a simple query I don't see how your code can work.
Reply
#7
Sorry, I can't see any problem. Sad
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to return a reference to an object? Skaperen 8 1,225 Jun-07-2023, 05:30 PM
Last Post: Skaperen
  how do I return Max Test result + corresponding student name from an excel dataset? sean1 3 1,271 Jan-16-2022, 09:07 PM
Last Post: snippsat
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,636 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  A question about 'Event loop is closed' fc5igm 2 2,228 Oct-05-2021, 02:00 AM
Last Post: fc5igm
  Pandas DataFrame combine rows by column value, where Date Rows are NULL rhat398 0 2,123 May-04-2021, 10:51 PM
Last Post: rhat398
  ValueError: I/O operation on closed file problem aliwien 0 2,124 Apr-23-2021, 05:50 PM
Last Post: aliwien
  Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python Jeremy7 8 7,151 Mar-02-2021, 01:54 AM
Last Post: Jeremy7
  How to split dataframe object rows to columns Mekala 1 2,521 Nov-12-2020, 04:18 PM
Last Post: michael1789
  Run an app in a standalone terminal and wait until it's closed glestwid 2 2,536 Aug-30-2020, 08:14 AM
Last Post: glestwid
  isinstance() always return true for object type check Yoki91 2 2,577 Jul-22-2020, 06:52 PM
Last Post: Yoki91

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020