char(16) binary...

已查看 13 次
跳至第一个未读帖子

Norbert Saint Georges

未读,
2022年9月30日 03:06:172022/9/30
收件人 firebird-net-provider
System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument, System.ExceptionResource)
    System.BitConverter.ToInt16(byte[], int)
    FirebirdSql.Data.Common.TypeDecoder.DecodeGuid(byte[])
    FirebirdSql.Data.Common.DbValue.GetGuid()
    FirebirdSql.Data.Client.Managed.Version10.GdsStatement.WriteRawParameter(FirebirdSql.Data.Client.Managed.IXdrWriter, FirebirdSql.Data.Common.DbField)
    FirebirdSql.Data.Client.Managed.Version13.GdsStatement.WriteParameters()
    FirebirdSql.Data.Client.Managed.Version10.GdsStatement.GetParameterData(FirebirdSql.Data.Common.IDescriptorFiller, int)
    FirebirdSql.Data.Client.Managed.Version10.GdsStatement.SendExecuteToBuffer(int, FirebirdSql.Data.Common.IDescriptorFiller)
    FirebirdSql.Data.Client.Managed.Version16.GdsStatement.SendExecuteToBuffer(int, FirebirdSql.Data.Common.IDescriptorFiller)
    FirebirdSql.Data.Client.Managed.Version12.GdsStatement.Execute(int, FirebirdSql.Data.Common.IDescriptorFiller)
    ...

Hi,

a char(16) bytes, varchar(16) bytes, binary(16), varbinary(16) are not always a guid :-)
it is also the structure to store for example ipv6 & ipv4.
How to bypass this error?

Jiří Činčura

未读,
2022年9月30日 03:12:582022/9/30
收件人 'Mr. John' via firebird-net-provider
What's the table structure and what's in the value?

--
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/

Norbert Saint Georges

未读,
2022年9月30日 04:29:022022/9/30
收件人 firebird-n...@googlegroups.com
the case here is in a procedure below

CREATE OR ALTER PROCEDURE INSERT_LOG(
APP_SITE_NAME VARCHAR(50),
IPNETWORK VARCHAR(46),
PROTOCOL VARCHAR(10),
HTTP_ACCEPT_LANGUAGE VARCHAR(50),
REMOTE_USER VARCHAR(50),
REQUEST_URI VARCHAR(255),
HTTP_REFERER VARCHAR(255),
HTTP_USER_AGENT VARCHAR(255),
REQUEST_METHOD VARCHAR(5),
STATUS SMALLINT,
REQUEST_LENGTH INTEGER,
BYTES_SENT INTEGER,
UPSTREAM_RESPONSE_TIME FLOAT,
TIME_ISO8601 TIMESTAMP,
HTTP_COOKIE VARCHAR(4000),
IP_BUFF binary(16)) -- <--
AS
declare variable GEONAME_ID INTEGER;
declare variable ASN INTEGER;
declare variable ORGANISATION VARCHAR(255);
declare variable NPYEAR SMALLINT;
declare variable NPMONTH SMALLINT;
declare variable NPDAY SMALLINT;
begin
select a.geoname_id, d.asn, d.organisation from geoip2_city_blocks a
left join geoip2_asn_blocks d on d.length_bit = a.length_bit and a.ip_low between d.ip_low and d.ip_hight
where a.length_bit=bit_length(:ip_buff) and :ip_buff between a.ip_low and a.ip_hight
into :geoname_id, :ASN, :organisation;

:npday = extract(day from TIME_ISO8601);
:npmonth = extract(month from TIME_ISO8601);
:npyear = extract(year from TIME_ISO8601);

insert into NP_LOGS (
APP_SITE_NAME ,
IPNETWORK ,
PROTOCOL ,
HTTP_ACCEPT_LANGUAGE ,
REMOTE_USER ,
REQUEST_URI ,
HTTP_REFERER ,
HTTP_USER_AGENT ,
REQUEST_METHOD ,
STATUS ,
REQUEST_LENGTH ,
BYTES_SENT ,
UPSTREAM_RESPONSE_TIME ,
TIME_ISO8601 ,
HTTP_COOKIE ,
GEONAME_ID ,
ASN ,
ORGANISATION ,
NP_YEAR ,
NP_MONTH ,
NP_DAY ,
NP_TIME ) values (
:APP_SITE_NAME ,
:IPNETWORK ,
:PROTOCOL ,
:HTTP_ACCEPT_LANGUAGE ,
:REMOTE_USER ,
:REQUEST_URI ,
:HTTP_REFERER ,
:HTTP_USER_AGENT ,
:REQUEST_METHOD ,
:STATUS ,
:REQUEST_LENGTH ,
:BYTES_SENT ,
:UPSTREAM_RESPONSE_TIME ,
:TIME_ISO8601 ,
:HTTP_COOKIE ,
:GEONAME_ID ,
:ASN ,
:ORGANISATION ,
:NPYEAR ,
:NPMONTH ,
:NPDAY ,
cast(:TIME_ISO8601 as time));

end

-----Message d'origine-----
De : firebird-n...@googlegroups.com [mailto:firebird-n...@googlegroups.com] De la part de Jirí Cincura
Envoyé : vendredi 30 septembre 2022 10:13
À : 'Mr. John' via firebird-net-provider
Objet : Re: [firebird-net-provider] char(16) binary...
--
You received this message because you are subscribed to the Google Groups "firebird-net-provider" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-net-pro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebird-net-provider/d1621f56-478d-45f0-ba58-d3c2a458ad19%40app.fastmail.com.

Norbert Saint Georges

未读,
2022年9月30日 05:08:482022/9/30
收件人 firebird-n...@googlegroups.com
small correction, it's a varbinary(16) otherwise bit_length always returns 128

-----Message d'origine-----
the case here is in a procedure below

CREATE OR ALTER PROCEDURE INSERT_LOG(
......,
IP_BUFF varbinary(16)) -- <--
AS
.....

-----Message d'origine-----

--
Mgr. Jiří Činčura
https://www.tabsoverspaces.com/

--

Jiří Činčura

未读,
2022年10月3日 05:38:462022/10/3
收件人 'Mr. John' via firebird-net-provider
And what value are you providing for IP_BUFF parameter?

Norbert Saint Georges

未读,
2022年10月3日 07:01:402022/10/3
收件人 firebird-n...@googlegroups.com
System.Net.IPAddress.GetAddressBytes

bit_length(IPV4) = 32
bit_length(IPV6) = 128

Cordially,
Norbert





Jirí Cincura a écrit :
--
Norbert Saint Georges
http://tetrasys.fi

Jiří Činčura

未读,
2022年10月4日 07:50:452022/10/4
收件人 'Mr. John' via firebird-net-provider
Hmm, this is bit unfortunate situation. Historically when the column was CHAR(16) OCTETS (and recently also VARCHAR(16)) FirebirdClient coerced that as Guid.

In your case the exception is because the value you're providing is not byte[16], but it's less and hence the code is complaining.

As a workaround you can define the parameter as length 17 (or anything other than 16).

At the moment I don't have a clear picture how to solve it. I need to think about it more.

Norbert Saint Georges

未读,
2022年10月4日 08:12:302022/10/4
收件人 firebird-n...@googlegroups.com
Ok no problem,
I changed the proc to varchar(16) and removed the charset octets from
the code.

Norbert

Jiří Činčura

未读,
2022年10月4日 08:14:512022/10/4
收件人 'Mr. John' via firebird-net-provider
> I changed the proc to varchar(16) and removed the charset octets from
> the code.

That works also. But take into account that changing the charset might result in different behavior down the line.

Norbert Saint Georges

未读,
2022年10月4日 08:21:512022/10/4
收件人 firebird-n...@googlegroups.com
Jirí Cincura a écrit :
>> I changed the proc to varchar(16) and removed the charset octets from
>> the code.
>
> That works also. But take into account that changing the charset might result
> in different behavior down the line.

I know but it has been running for a few days and the ip's in the logs
are the same as those sent :-)

Norbert Saint Georges

未读,
2022年10月4日 14:18:132022/10/4
收件人 firebird-n...@googlegroups.com
System.Net.IPAddress.GetAddressBytes

bit_length(IPV4) = 32
bit_length(IPV6) = 128

Cordially,
Norbert

-----Message d'origine-----
De : firebird-n...@googlegroups.com [mailto:firebird-n...@googlegroups.com] De la part de Jirí Cincura
Envoyé : lundi 3 octobre 2022 12:36
À : 'Mr. John' via firebird-net-provider
Objet : Re: [firebird-net-provider] char(16) binary...

--
You received this message because you are subscribed to the Google Groups "firebird-net-provider" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-net-pro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebird-net-provider/6ca81627-a59d-4b21-bde6-b9f6a14c63bb%40app.fastmail.com.
回复全部
回复作者
转发
0 个新帖子