Fieldvalues Textfields with len 0 etc. #12

Closed
michael88 opened this Issue Oct 2, 2012 · 10 comments

Projects

None yet

2 participants

@michael88

Hello,

  1. When i select from a char/varchar field with an empty value '' (not null) then i get as value "undefined".
    Is this a bug or the desired behaviour?

  2. When i create a view with a case construct say:

case f.rdb$field.type

when 261 then 'BLOB'
when 14 then 'CHAR'
when 40 then 'CSTRING'
....

then i get a "buffer" (i don't know what object this is) return

if i change this to:

case f.rdb$field_type
when 261 then cast('BLOB' as varchar(10))
when 14 then 'CHAR'
when 40 then 'CSTRING'
....

then i get a normal string

  1. When i select a field with datatype BIGINT (int64) then i get an object with
    {high: 0, low: 395}
    Why is this not a javascript int?
@hgourvest
Owner
  1. it is a bug.

  2. your blob is probably a binary blob, it should be a text blob.
    https://github.com/hgourvest/node-firebird/blob/master/lib/index.js#L1693
    a Buffer is a specific Node.js class, it is the only way to handle binary datas:
    http://nodejs.org/api/buffer.html

  3. javascript don't handle native int64 data type, so I need to use a pure javascript library from google (long.js)
    you can do math operation on it, as if it were a number

@hgourvest hgourvest added a commit that closed this issue Oct 2, 2012
@hgourvest 0 value is not null
empty string is not null
code cleanup
fix #12
3a50011
@hgourvest hgourvest closed this in 3a50011 Oct 2, 2012
@michael88

Point 2: It has nothing to to with blob reads. it is only a field holding the string value "Blob" or "varchar" or "dummy" etc. I think, if there is a case expression without a cast then the resulting datatype is (can be) wrong

@hgourvest
Owner

ok, do you have a charset defined for this field ?

@michael88

No (charset of database is utf)

I use the following view:

create or alter view syscolumns as
select
cast(rdb$relation_fields.rdb$relation_name as varchar(31)) as name,
cast(rdb$relation_fields.rdb$field_name as varchar(31)) as fieldname,
rdb$relation_fields.rdb$field_position as fieldposition,
rdb$relation_fields.rdb$description as fielddescription,
rdb$relation_fields.rdb$default_value as fielddefault_value,
rdb$relation_fields.rdb$null_flag as null_flag,
case f.rdb$field_type
when 261 then 'BLOB'
when 14 then 'CHAR'
when 40 then 'CSTRING'
when 11 then 'D_FLOAT'
when 27 then 'DOUBLE'
when 10 then 'FLOAT'
when 16 then 'INT64'
when 8 then 'INTEGER'
when 9 then 'QUAD'
when 7 then 'SMALLINT'
when 12 then 'DATE'
when 13 then 'TIME'
when 35 then 'TIMESTAMP'
when 37 then 'VARCHAR'
else 'UNKNOWN'
end as field_type,
case f.rdb$field_type
when 12 then 10
when 13 then 8
when 35 then 20
when 37 then (f.rdb$field_length / 4)
else
coalesce( f.rdb$character_length,f.rdb$field_length)
end
as field_length,
f.rdb$field_scale as field_scale,
f.rdb$field_precision as field_precision
from rdb$relation_fields
left join rdb$fields f on rdb$relation_fields.rdb$field_source =
f.rdb$field_name;

And then i select from this view.
select field_type from syscolumns ...

@hgourvest
Owner

I can't reproduce your problem on firebird 2.5.1 win32,
could you give me the output metadatas ?

it should be:
{
type: 452,
nullable: true,
subType: 4,
scale: 0,
length: 36,
field: 'FIELD_TYPE',
relation: 'SYSCOLUMNS',
alias: 'FIELD_TYPE'
}

@michael88

It is:
9
<Buffer 56 41 52 43 48 41 52 20 20>
9
<Buffer 56 41 52 43 48 41 52 20 20>
9
<Buffer 56 41 52 43 48 41 52 20 20>
9
<Buffer 56 41 52 43 48 41 52 20 20>
9
<Buffer 56 41 52 43 48 41 52 20 20>
9
<Buffer 56 41 52 43 48 41 52 20 20>
9
<Buffer 56 41 52 43 48 41 52 20 20>
9
<Buffer 56 41 52 43 48 41 52 20 20>
9
<Buffer 43 48 41 52 20 20 20 20 20>
9
<Buffer 56 41 52 43 48 41 52 20 20>
9
<Buffer 56 41 52 43 48 41 52 20 20>
9
<Buffer 56 41 52 43 48 41 52 20 20>
9
<Buffer 56 41 52 43 48 41 52 20 20>
9
<Buffer 44 41 54 45 20 20 20 20 20>
9
<Buffer 44 41 54 45 20 20 20 20 20>
9
<Buffer 53 4d 41 4c 4c 49 4e 54 20>
9
<Buffer 53 4d 41 4c 4c 49 4e 54 20>
[ { type: 452,
nullable: true,
subType: 0,
scale: 0,
length: 9,
alias: 'FIELD_TYPE' } ]

System: Debian squeeze
firebird Verrsion 2.5.1

Maybe the following is related and helps:

SELECT * from rdb$relations
returns
40
<Buffer 2f 68 6f 6d 65 2f 6d 69 63 68 61 65 6c 2f 65 78 74 65 72 6e 61 6c 5f 74 61 62 6c 65 73 2f 74 5f 67 65 6d 61 2e 74 78 74>
40
<Buffer 2f 68 6f 6d 65 2f 6d 69 63 68 61 65 6c 2f 65 78 74 65 72 6e 61 6c 5f 74 61 62 6c 65 73 2f 74 5f 67 65 6d 61 2e 74 78 74>
41
<Buffer 2f 68 6f 6d 65 2f 6d 69 63 68 61 65 6c 2f 65 78 74 65 72 6e 61 6c 5f 74 61 62 6c 65 73 2f 74 5f 63 73 76 34 30 2e 74 78 74>
43
<Buffer 2f 68 6f 6d 65 2f 6d 69 63 68 61 65 6c 2f 65 78 74 65 72 6e 61 6c 5f 74 61 62 6c 65 73 2f 74 5f 62 61 72 63 6f 64 65 2e 74 78 74>

/home/michael/node_modules/node-firebird/lib/serialize.js:135
var len = this.buffer.readUInt16LE(this.pos);
^
TypeError: Cannot call method 'readUInt16LE' of undefined
at [object Object].readSegment (/home/michael/node_modules/node-firebird/lib/serialize.js:135:27)
at /home/michael/node_modules/node-firebird/lib/index.js:1683:48
at doCallback (/home/michael/node_modules/node-firebird/lib/index.js:870:9)
at Socket. (/home/michael/node_modules/node-firebird/lib/index.js:1124:13)
at Socket.emit (events.js:67:17)
at TCP.onread (net.js:341:14)

@hgourvest
Owner

It is probaly a bug with Firebird, the subType is 0 = Charset NONE

@hgourvest
Owner

I have just tested on squeeze with firebird 2.5.1 and I can't reproduce your error, perhaps your database have a problem

@hgourvest
Owner

BTW, please use the latest version from GIT

@michael88

It is really strange. I tried:

load latest version from node-firebird (05.10.2012 - 0.7 from github)

create a new clean database with same blocksize, codepage etc.
It works.

backup and restore (without errors) my "problem" Database (with 500 MB Data)
It doesn't work

When i try the query in isql - it works
When I change my database backend from node-firebird to node-firebird-libfbclient - It works.

i have no idea, what's the real problem. I'll investigate further in this topic, but for now I am clueless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment