Frosty840
Frosty840

Reputation: 8355

Pass Byte as SmallInt?

I have an Informix stored procedure which takes an int and a "smallint" as parameters. I'm trying to call this SP from a .net4 Visual Basic program.

As far as I know, "smallint" is a byte. Unfortunately, when loading up the IfxCommand.Parameters collection with an Integer and a Byte, I get an ArgumentException thrown of {"The parameter data type of Byte is invalid."} with the following stack trace:

at IBM.Data.Informix.TypeMap.FromObjectType(Type dataType, Int32 length) at IBM.Data.Informix.TypeMap.FromObjectType(Type dataType) at IBM.Data.Informix.IfxParameter.GetTypeMap() at IBM.Data.Informix.IfxParameter.GetOutputValue(IntPtr stmt, CNativeBuffer valueBuffer, CNativeBuffer lenIndBuffer) at IBM.Data.Informix.IfxDataReader.Dispose(Boolean disposing) at IBM.Data.Informix.IfxDataReader.System.IDisposable.Dispose() at IBM.Data.Informix.IfxCommand.ExecuteReaderObject(CommandBehavior behavior, String method) at IBM.Data.Informix.IfxCommand.ExecuteReader(CommandBehavior behavior) at IBM.Data.Informix.IfxCommand.ExecuteReader()

Presumably I need to cast the Byte I have to a smallint, somehow, but google isn't giving me any relevant answers, just at the moment.

I have tried using:

cmd.Parameters.Add(New IfxParameter("myVal", IBM.Data.Informix.IfxType.SmallInt)).Value = myByte

but I still get the same ArgumentException when executing the reader.

Can someone tell me what I'm doing wrong?

Upvotes: 1

Views: 911

Answers (3)

Jodrell
Jodrell

Reputation: 35746

An Informix SmallInt is a 16 bit signed integer, byte is an 8 bit unsigned integer. A better equivalent would be Int16 or Short which is a 16 bit signed integer, just like SmallInt. I suspect that will work.

Informix has no analogue for an unsigned 8 bit integer like the .Net Byte or the TSQL TinyInt.

Upvotes: 3

Jonathan Leffler
Jonathan Leffler

Reputation: 754940

Informix has 4 types that are related: BYTE and TEXT (since 1990), BLOB and CLOB (since 1996). Collectively, they are all large objects. A BYTE type is absolutely NOT a small integer type.

You may be able to use BYTE in a language that thinks it is a small integer if the language or driver fixes up the types.

But the native BYTE type is a large object. It requires a 56-byte descriptor in the main row of data, and then uses other storage (possibly IN TABLE, possibly in a blobspace) for the actual data storage.

Upvotes: 1

jclozano
jclozano

Reputation: 628

Int16 should work since it has the same range than SmallInt (-32,767 to 32,767)

Upvotes: 1

Related Questions