|
I stumbled upon a strange thing today which drove me nuts. I query an Oracle database and get a recordset with mappings with two indices:
NORMALTID which is a date VAERDE which is a float value as a string When I was iterating over the recordset the loop got stuck for a while at the last index and the program terminated (without any notice). So I traced the output and saw that VAERDE in the last index was "" (an empty string). So I added to the loop: if (row->VAERDE == "") break; Nothing happened. So I tried if (!sizeof(row->VAERDE)) break; Nothing happened. So I traced the size of row->VAERDE and to my surprise it returned -1: werror("%d\n", sizeof(row->VAERDE)) >> -1 So with if (row->VAERDE == -1) break; the program continues and finish ok. But why on earth does sizeof return -1 for a (seemingly) empty string? # Pontus |
|
> > But why on earth does sizeof return -1 for a (seemingly) empty string? Can it be the itterator doesn't return an empty string "", but UNDEFINED? You could try a "write("%O",row);" and find the spot, to see if it's really an initialised empty string. |
|
In reply to this post by Pontus Östlund
On Wed, 15 Feb 2012, Pontus Östlund wrote: > I stumbled upon a strange thing today which drove me nuts. I query an Oracle database and get a recordset with mappings with two indices: > > NORMALTID which is a date > VAERDE which is a float value as a string > > When I was iterating over the recordset the loop got stuck for a while at the last index and the program terminated (without any notice). So I traced the output and > saw that VAERDE in the last index was "" (an empty string). So I added to the loop: What should be the value? Does the database contain an empty string or maybe NULL? |
|
In reply to this post by Marc Dirix-2
> You could try a "write("%O",row);" and find the spot, to see if it's > really an initialised empty string. > > > I've done that and it showed: > > ([ > "NORMALTID" : "2012-02-15 13:00:00", > "VAERDE" : "" > ]) what does "typeof(row->VAERDE);" return? |
|
Den 15 februari 2012 14:54 skrev Marc Dirix <[hidden email]>:
typeof(row->VAERDE) says "mixed". But stringp(row->VAERDE) returns true. # Pontus |
|
Could you probably Stdio.write_file("strangestring.dat",
encode_value(row->VAERDE)) with the sizeof -1 string? |
|
In reply to this post by Pontus Östlund
It really seems like the oracle module is creating a broken string
struct here. sizeof(str) basically gives you the len entry in the struct. It then also makes perfect sense that it gets printed as if it was the empty string with length 0. I dont have any oracle databases near me, otherwise I would try to debug this. The oracle STR type is handled somewhat special because it is supposed to contain a terminating \0 byte. The module code therefore seems to assume that the length of a STR coming from oracle is at least 1 and always subtracts 1. Maybe this assumption is not correct. Just a guess though... Would be still interesting what is actually contained in that field in the database. arne On Wed, 15 Feb 2012, Pontus Östlund wrote: > Den 15 februari 2012 14:54 skrev Marc Dirix <[hidden email]>: > > > You could try a "write("%O",row);" and find the spot, to see if it's > > really an initialised empty string. > > > > > > I've done that and it showed: > > > > ([ > > "NORMALTID" : "2012-02-15 13:00:00", > > "VAERDE" : "" > > ]) > > what does "typeof(row->VAERDE);" return? > > > typeof(row->VAERDE) says "mixed". But stringp(row->VAERDE) returns true. > > # Pontus > > |
|
In reply to this post by Tobias S. Josefowitz
Den 15 februari 2012 15:15 skrev Tobias S. Josefowitz <[hidden email]>: Could you probably Stdio.write_file("strangestring.dat", Then the original problem occurs. The loop gets stuck and the program terminates. # Pontus |
|
In reply to this post by Arne Goedeke
2012/2/15 Arne Goedeke <[hidden email]> It really seems like the oracle module is creating a broken string Something is at least very fishy here ;) Would be still interesting what is actually contained in that field in It's supposed to be a float value and all other rows contain a float value here. What's different with the last row is that its date field is in the future. The dataset contains water levels of some of the largest lakes in the region of Östergötland (amnogst them Lake Roxen, http://www.tekniskaverken.se/matvarden/vattenreglering/roxen/ ;)). But the last row seems to be dedicated for the next coming value - the database is updated every hour - and is probably some kind of NULL-value until it's populated. Now, my code handles this as I explained in the original message so the code works. But I wast stumbled by the fact that sizeof() returned -1, and it might be because of a bug in the Oracle module. And it seemed strange that the program terminated without leaving any trace behind. # Pontus |
|
In reply to this post by Pontus Östlund
On Wed, 15 Feb 2012, Pontus Östlund wrote:
> I stumbled upon a strange thing today which drove me nuts. I query an > Oracle database and get a recordset with mappings with two indices: > > NORMALTID which is a date > VAERDE which is a float value as a string > > When I was iterating over the recordset the loop got stuck for a while at > the last index and the program terminated (without any notice). So I traced > the output and saw that VAERDE in the last index was "" (an empty string). [...] > But why on earth does sizeof return -1 for a (seemingly) empty string? AFAIK the Oracle module doesn't return strings, but objects that attempt to behave like strings. > # Pontus -- Henrik Grubbström [hidden email] Roxen Internet Software AB |
|
In reply to this post by Marc Dirix-2
On Wed, 15 Feb 2012, Marc Dirix wrote:
>> You could try a "write("%O",row);" and find the spot, to see if it's >> really an initialised empty string. >> >> I've done that and it showed: >> >> ([ >> "NORMALTID" : "2012-02-15 13:00:00", >> "VAERDE" : "" >> ]) > > what does "typeof(row->VAERDE);" return? compile time. You want to use _typeof(). -- Henrik Grubbström [hidden email] Roxen Internet Software AB |
|
In reply to this post by Pontus Östlund
Pontus Östlund <[hidden email]> wrote:
> It's supposed to be a float value and all other rows contain a float value > here. What's different with the last row is that its date field is in the > future. The dataset contains water levels of some of the largest lakes in the > region of Östergötland (amnogst them Lake Roxen, http://www.tekniskaverken.se/ > matvarden/vattenreglering/roxen/ ;)). But the last row seems to be dedicated > for the next coming value - the database is updated every hour - and is > probably some kind of NULL-value until it's populated. Afaics it's not an Oracle NULL value, because it should print something like "Oracle.NULLfloat" by sprintf("%O") then. If _typeof(), as Grubba suggested, returns that it's a string then it's clearly one that's incorrectly built. |
|
In reply to this post by Henrik Grubbström-2
If the result is an object, which behaves like a string, then won't the type be an object? And if it's an object would stringp(the_object) be true, which it is? The strangest thing to me is that the program terminates without as much as trace. I've never come across that before. And I have forgotten to say this is on Windows. |
|
Pontus Östlund <[hidden email]> wrote:
> If the result is an object, which behaves like a string, then won't > the type be an object? Yes, _typeof() cannot lie afaik. > And if it's an object would stringp(the_object) be true, which > it is? Right, it wouldn't. > The strangest thing to me is that the program terminates without as > much as trace. I've never come across that before. It crashes, which is not so strange since you've got a seriously freaky string there. If you enable core dumps, you should get one which can be looked at with gdb, but in this particular case I don't think it'd help since the string is already created at that point. I think someone has to take a good look at oracle.c. And oh, since you're a paying customer, you just go ahead and mail this to Roxen Support, and that someone will be one of us tomorrow. ;) |
|
Den 15 februari 2012 20:18 skrev Martin Stjernholm <[hidden email]>:
I've now confirmed that _typeof(row->VAERDE) says "string(0..255)" [...] Okey dokey, I'll put an abstract of this thread together for you. Thanks all! # Pontus |
| Powered by Nabble | See how NAML generates this page |
