Skip to content

Using cursor to execute one object at a time.#9

Merged
henrikoppen merged 8 commits intomainfrom
fix/use_cursor
May 15, 2024
Merged

Using cursor to execute one object at a time.#9
henrikoppen merged 8 commits intomainfrom
fix/use_cursor

Conversation

@henrikoppen
Copy link
Copy Markdown
Contributor

@henrikoppen henrikoppen commented May 3, 2024


open @curVFP

while 1 = 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will loop forever, then there's an error , and this probably crashes and the rest doesn't execute.

You should instead check @@fetch_status. This should do the trick:

fetch next from @curVFP into @sql;
while (@@fetch_status = 0)
begin
    exec sp_executesql @sql;
    fetch next from @curVFP into @sql;
end

where t.schema_id = @schemaid;

open @curT
while 1 = 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

fetch next from @curT into @sql;
while (@@fetch_status = 0)
begin
fetch next from @curT into @sql;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will skip dropping the first item; you need to change the order of executesql and fetch next from here

fetch next from @curVFP into @sql;
while (@@fetch_status = 0)
begin
fetch next from @curVFP into @sql;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same problem as below; first loop iteration you fetch 2 items before doing any execution..

@henrikoppen henrikoppen merged commit cec1702 into main May 15, 2024
@henrikoppen henrikoppen deleted the fix/use_cursor branch May 15, 2024 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants