[pgsqlclient-checkins] pgsqlclient/PostgreSql.Data.PGSqlClient/source/NPGClient PGCodes.cs,1.1.1.1,1
Status: Inactive
Brought to you by:
carlosga_fb
Update of /cvsroot/pgsqlclient/pgsqlclient/PostgreSql.Data.PGSqlClient/source/NPGClient In directory sc8-pr-cvs1:/tmp/cvs-serv6334 Modified Files: PGCodes.cs PGDbClient.cs PGEncodeType.cs PGOutputPacket.cs PGResponsePacket.cs Log Message: Added decimal datatype support at this moment using text format ( Task 81641 ) Index: PGCodes.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient/PostgreSql.Data.PGSqlClient/source/NPGClient/PGCodes.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** PGCodes.cs 12 Jul 2003 08:11:22 -0000 1.1.1.1 --- PGCodes.cs 17 Jul 2003 13:41:42 -0000 1.2 *************** *** 122,129 **** --- 122,132 ---- // Numeric data type + public const int NUMERIC_SIGN_MASK = 0xC000; public const int NUMERIC_POS = 0x0000; public const int NUMERIC_NEG = 0x4000; public const int NUMERIC_NAN = 0xC000; public const int NUMERIC_MAX_PRECISION = 1000; + public const int NUMERIC_DSCALE_MASK = 0x3FFF; + public const int NUMERIC_HDRSZ = 10; } } Index: PGDbClient.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient/PostgreSql.Data.PGSqlClient/source/NPGClient/PGDbClient.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PGDbClient.cs 14 Jul 2003 11:59:44 -0000 1.2 --- PGDbClient.cs 17 Jul 2003 13:41:42 -0000 1.3 *************** *** 548,552 **** types.Add(1560 , "bit" , DbType.Byte , Type.GetType("System.Byte") , 0, 0, 1, false, false); types.Add(1562 , "varbit" , DbType.Byte , Type.GetType("System.Byte") , 0, 1, 0, false, false); ! types.Add(1700 , "numeric" , DbType.Decimal , Type.GetType("System.Decimal") , 0, 1, 8, false, false); types.Add(2277 , "anyarray", DbType.Object , Type.GetType("System.Array") , 0, 1, 8, false, false); } --- 548,552 ---- types.Add(1560 , "bit" , DbType.Byte , Type.GetType("System.Byte") , 0, 0, 1, false, false); types.Add(1562 , "varbit" , DbType.Byte , Type.GetType("System.Byte") , 0, 1, 0, false, false); ! types.Add(1700 , "numeric" , DbType.Decimal , Type.GetType("System.Decimal") , 0, 0, 8, false, false); types.Add(2277 , "anyarray", DbType.Object , Type.GetType("System.Array") , 0, 1, 8, false, false); } Index: PGEncodeType.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient/PostgreSql.Data.PGSqlClient/source/NPGClient/PGEncodeType.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PGEncodeType.cs 17 Jul 2003 09:50:40 -0000 1.1 --- PGEncodeType.cs 17 Jul 2003 13:41:42 -0000 1.2 *************** *** 23,29 **** internal class PGEncodeType { ! public static Decimal EncodeNumeric(short ndigits, short weight, short sign, short dscale, short[] digits) { ! return 0; } } --- 23,80 ---- internal class PGEncodeType { ! public static Decimal EncodeNumeric(int ndigits, int weight, int sign, int dscale, short[] digits) { ! Decimal result = 0M; ! ! // This code was ported from PostgreSQL sources ! // src/Backend/utils/adt/numeric.c ! if (sign == PGCodes.NUMERIC_NAN) ! { ! result = (decimal)Single.NaN; ! } ! else ! { ! int n = ndigits - 1; ! ! // truncate leading zeroes ! while (n > 0 && digits[n] == 0) ! { ! weight--; ! n--; ! } ! ! // truncate trailing zeroes ! while (n > 0 && digits[n - 1] == 0) ! { ! n--; ! } ! ! // If zero result, force to weight=0 and positive sign ! if (n == 0) ! { ! weight = 0; ! sign = PGCodes.NUMERIC_POS; ! } ! ! // Build the result ! byte[] res = new Byte[PGCodes.NUMERIC_HDRSZ + n * 1]; ! ! Buffer.BlockCopy(digits, 0, res, 0, res.Length); ! ! /* ! result = (Numeric) palloc(len); ! result->varlen = len; ! result->n_weight = weight; ! result->n_sign_dscale = sign | (var->dscale & NUMERIC_DSCALE_MASK); ! ! // Check for overflow of int16 fields ! if (result->n_weight != weight || ! NUMERIC_DSCALE(result) != var->dscale) ! elog(ERROR, "Value overflows numeric format"); ! */ ! ! } ! ! return result; } } Index: PGOutputPacket.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient/PostgreSql.Data.PGSqlClient/source/NPGClient/PGOutputPacket.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** PGOutputPacket.cs 12 Jul 2003 08:11:23 -0000 1.1.1.1 --- PGOutputPacket.cs 17 Jul 2003 13:41:42 -0000 1.2 *************** *** 189,195 **** case DbType.Decimal: WriteInt(size); Write(Convert.ToDecimal(parameter.Value)); ! break; case DbType.Double: --- 189,202 ---- case DbType.Decimal: + { + /* WriteInt(size); Write(Convert.ToDecimal(parameter.Value)); ! */ ! string paramValue = parameter.Value.ToString(); ! WriteInt(encoding.GetByteCount(paramValue + PGCodes.NULL_TERMINATOR)); ! WriteString(paramValue); ! } ! break; case DbType.Double: Index: PGResponsePacket.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient/PostgreSql.Data.PGSqlClient/source/NPGClient/PGResponsePacket.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PGResponsePacket.cs 17 Jul 2003 09:50:40 -0000 1.2 --- PGResponsePacket.cs 17 Jul 2003 13:41:42 -0000 1.3 *************** *** 279,283 **** case DbType.Decimal: ! return ReadNumeric(); case DbType.Currency: --- 279,284 ---- case DbType.Decimal: ! string numericValue = ReadString(length); ! return Decimal.Parse(numericValue, NumberFormatInfo.InvariantInfo); case DbType.Currency: |