Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pg_select fails to fully unset the data in arrayVar for each loop #4

Closed
nugget opened this issue Apr 25, 2016 · 2 comments · Fixed by #5
Closed

pg_select fails to fully unset the data in arrayVar for each loop #4

nugget opened this issue Apr 25, 2016 · 2 comments · Fixed by #5
Milestone

Comments

@nugget
Copy link
Contributor

nugget commented Apr 25, 2016

pg_select fails to cleanly unset the data array on each iteration of the code block. It only reliably clears out array elements that exist in the SELECT statement, but neglects to clear any array elements that were added during the execution of the code block.

This can be reproduced using this code:

#!/usr/bin/env tclsh
package require Pgtcl
set db [pg_connect -connlist {dbname nugget}]
pg_select $db "SELECT generate_series(1,10) as id" buf {
if {$buf(id) == 5} {
    set buf(interloper) "this field should only be in record number 5"
}
puts [array get buf]
}

Which runs with this output:
.tupno 0 id 1 .headers id .numcols 1
.tupno 1 id 2 .headers id .numcols 1
.tupno 2 id 3 .headers id .numcols 1
.tupno 3 id 4 .headers id .numcols 1
interloper {this field should only be in record number 5} .tupno 4 id 5 .headers id .numcols 1
interloper {this field should only be in record number 5} .tupno 5 id 6 .headers id .numcols 1
interloper {this field should only be in record number 5} .tupno 6 id 7 .headers id .numcols 1
interloper {this field should only be in record number 5} .tupno 7 id 8 .headers id .numcols 1
interloper {this field should only be in record number 5} .tupno 8 id 9 .headers id .numcols 1
interloper {this field should only be in record number 5} .tupno 9 id 10 .headers id .numcols 1

I expected the buf array to be reset completely each time the code block is evaluated.

Notably, the buf array is properly unset (all values) at the conclusion of the pg_select operation.

@resuna
Copy link
Member

resuna commented Apr 27, 2016

This behavior is not technically wrong, and I'm not sure it's even unexpected.

@bovine
Copy link
Member

bovine commented Jun 14, 2016

A related bug was fixed by commit 3521d22, which could cause a crash if you happened to try to actually unset the array variable within the pg_select code body.

bovine added a commit that referenced this issue Jun 15, 2016
@bovine bovine added this to the 2.0.0 milestone Jun 15, 2016
bovine added a commit that referenced this issue Jun 15, 2016
@bovine bovine closed this as completed in #5 Jun 16, 2016
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 a pull request may close this issue.

3 participants