[pgsqlclient-checkins] pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient PgDataType.cs,1.3
Status: Inactive
Brought to you by:
carlosga_fb
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient In directory sc8-pr-cvs1:/tmp/cvs-serv4782 Modified Files: PgDataType.cs PgDbClient.cs PgOutputPacket.cs PgResponsePacket.cs PgType.cs Log Message: 2003-10-26 Carlos Guzmán Álvarez <car...@te...> * source/NPgClient/PgDbClient.cs: * source/NPgClient/PgOutputPacket.cs: * source/NPgClient/PgResponsePacket.cs: * source/NPgClient/PgDataType.cs: * source/PgDbType.cs: * source/PgParameter.cs: * source/PgType.cs: - Started to work on support for timetz, timestamptz and interval types [not finished yet]. Index: PgDataType.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgDataType.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PgDataType.cs 25 Oct 2003 20:52:53 -0000 1.3 --- PgDataType.cs 26 Oct 2003 11:32:33 -0000 1.4 *************** *** 41,44 **** --- 41,45 ---- Int4 , Int8 , + Interval , Line , LSeg , *************** *** 49,53 **** Text , Time , ! TimeStamp , VarChar , Vector --- 50,56 ---- Text , Time , ! TimeWithTZ , ! Timestamp , ! TimestampWithTZ , VarChar , Vector Index: PgDbClient.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgDbClient.cs,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** PgDbClient.cs 25 Oct 2003 20:52:53 -0000 1.28 --- PgDbClient.cs 26 Oct 2003 11:32:33 -0000 1.29 *************** *** 695,699 **** types.Add(1082 , "date" , PgDataType.Date , 0, 1, 4); types.Add(1083 , "time" , PgDataType.Time , 0, 1, 8); ! types.Add(1114 , "timestamp" , PgDataType.TimeStamp , 0, 1, 8); types.Add(1560 , "bit" , PgDataType.Byte , 0, 0, 1); types.Add(1562 , "varbit" , PgDataType.Byte , 0, 1, 0); --- 695,702 ---- types.Add(1082 , "date" , PgDataType.Date , 0, 1, 4); types.Add(1083 , "time" , PgDataType.Time , 0, 1, 8); ! types.Add(1114 , "timestamp" , PgDataType.Timestamp , 0, 1, 8); ! types.Add(1184 , "timestamptz" , PgDataType.TimestampWithTZ, 0, 1, 8); ! types.Add(1186 , "interval" , PgDataType.Interval , 0, 1, 12); ! types.Add(1266 , "timetz" , PgDataType.TimeWithTZ , 0, 1, 12); types.Add(1560 , "bit" , PgDataType.Byte , 0, 0, 1); types.Add(1562 , "varbit" , PgDataType.Byte , 0, 1, 0); Index: PgOutputPacket.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgOutputPacket.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** PgOutputPacket.cs 18 Oct 2003 14:46:26 -0000 1.13 --- PgOutputPacket.cs 26 Oct 2003 11:32:34 -0000 1.14 *************** *** 66,92 **** #endregion ! #region WRITE_METHODS ! ! // Standard types public void WriteString(string data) { ! Write(data.ToCharArray()); ! Write(PgCodes.NULL_TERMINATOR); } public void WriteShort(short val) { ! Write((short)IPAddress.HostToNetworkOrder(val)); } public void WriteInt(int val) { ! Write((int)IPAddress.HostToNetworkOrder(val)); } public void WriteLong(long val) { ! Write((long)IPAddress.HostToNetworkOrder(val)); } --- 66,94 ---- #endregion ! #region STRING_TYPES_WRITE public void WriteString(string data) { ! this.Write(data.ToCharArray()); ! this.Write(PgCodes.NULL_TERMINATOR); } + #endregion + + #region NUMERIC_TYPES_WRITE + public void WriteShort(short val) { ! this.Write((short)IPAddress.HostToNetworkOrder(val)); } public void WriteInt(int val) { ! this.Write((int)IPAddress.HostToNetworkOrder(val)); } public void WriteLong(long val) { ! this.Write((long)IPAddress.HostToNetworkOrder(val)); } *************** *** 98,102 **** floatValue.i0 = IPAddress.HostToNetworkOrder(floatValue.i0); ! Write(floatValue.f); } --- 100,104 ---- floatValue.i0 = IPAddress.HostToNetworkOrder(floatValue.i0); ! this.Write(floatValue.f); } *************** *** 114,132 **** doubleValue.i4 = temp; ! Write(doubleValue.d); } public void WriteDate(DateTime date) { TimeSpan days = date.Subtract(PgCodes.BASE_DATE); ! WriteInt(days.Days); } ! public void WriteTimestamp(DateTime timestamp) { ! TimeSpan days = timestamp.Subtract(PgCodes.BASE_DATE); ! ! WriteDouble(days.TotalSeconds); } --- 116,137 ---- doubleValue.i4 = temp; ! this.Write(doubleValue.d); } + #endregion + + #region DATE_TIME_WRITE + public void WriteDate(DateTime date) { TimeSpan days = date.Subtract(PgCodes.BASE_DATE); ! this.WriteInt(days.Days); } ! public void WriteInterval(TimeSpan interval) { ! this.WriteDouble(interval.TotalSeconds); ! this.WriteInt(0); } *************** *** 134,179 **** { DateTime realTime = new DateTime(PgCodes.BASE_DATE.Year, ! PgCodes.BASE_DATE.Month, ! PgCodes.BASE_DATE.Day, ! time.Hour, ! time.Minute, ! time.Second, ! time.Millisecond); TimeSpan seconds = realTime.Subtract(PgCodes.BASE_DATE); ! WriteDouble(seconds.TotalSeconds); } ! // Geometric types public void WritePoint(PgPoint point) { ! WriteDouble(point.X); ! WriteDouble(point.Y); } public void WriteCircle(PgCircle circle) { ! WritePoint(circle.Center); ! WriteDouble(circle.Radius); } public void WriteLine(PgLine line) { ! WritePoint(line.StartPoint); ! WritePoint(line.EndPoint); } public void WriteLSeg(PgLSeg lseg) { ! WritePoint(lseg.StartPoint); ! WritePoint(lseg.EndPoint); } public void WriteBox(PgBox box) { ! WritePoint(box.UpperRight); ! WritePoint(box.LowerLeft); } --- 139,216 ---- { DateTime realTime = new DateTime(PgCodes.BASE_DATE.Year, ! PgCodes.BASE_DATE.Month, ! PgCodes.BASE_DATE.Day, ! time.Hour, ! time.Minute, ! time.Second, ! time.Millisecond); TimeSpan seconds = realTime.Subtract(PgCodes.BASE_DATE); ! this.WriteDouble(seconds.TotalSeconds); } ! public void WriteTimeWithTZ(DateTime time) ! { ! DateTime realTime = new DateTime(PgCodes.BASE_DATE.Year, ! PgCodes.BASE_DATE.Month, ! PgCodes.BASE_DATE.Day, ! time.Hour, ! time.Minute, ! time.Second, ! time.Millisecond); ! ! TimeSpan seconds = realTime.Subtract(PgCodes.BASE_DATE); ! ! this.WriteDouble(seconds.TotalSeconds); ! this.WriteInt(0); ! } ! ! public void WriteTimestamp(DateTime timestamp) ! { ! TimeSpan days = timestamp.Subtract(PgCodes.BASE_DATE); ! ! this.WriteDouble(days.TotalSeconds); ! } ! ! public void WriteTimestampWithTZ(DateTime timestamp) ! { ! TimeSpan days = timestamp.Subtract(PgCodes.BASE_DATE); ! ! this.WriteDouble(days.TotalSeconds); ! } ! ! #endregion ! ! #region GEOMETRIC_TYPES_WRITE public void WritePoint(PgPoint point) { ! this.WriteDouble(point.X); ! this.WriteDouble(point.Y); } public void WriteCircle(PgCircle circle) { ! this.WritePoint(circle.Center); ! this.WriteDouble(circle.Radius); } public void WriteLine(PgLine line) { ! this.WritePoint(line.StartPoint); ! this.WritePoint(line.EndPoint); } public void WriteLSeg(PgLSeg lseg) { ! this.WritePoint(lseg.StartPoint); ! this.WritePoint(lseg.EndPoint); } public void WriteBox(PgBox box) { ! this.WritePoint(box.UpperRight); ! this.WritePoint(box.LowerLeft); } *************** *** 182,186 **** for (int i = 0; i < polygon.Points.Length; i++) { ! WritePoint(polygon.Points[0]); } } --- 219,223 ---- for (int i = 0; i < polygon.Points.Length; i++) { ! this.WritePoint(polygon.Points[0]); } } *************** *** 190,198 **** for (int i = 0; i < path.Points.Length; i++) { ! WritePoint(path.Points[0]); } } ! // Parameters public void WriteParameter(PgParameter parameter) --- 227,237 ---- for (int i = 0; i < path.Points.Length; i++) { ! this.WritePoint(path.Points[0]); } } ! #endregion ! ! #region PARAMETER_WRITE public void WriteParameter(PgParameter parameter) *************** *** 204,208 **** { // -1 indicates a NULL argument value ! WriteInt(-1); } else --- 243,247 ---- { // -1 indicates a NULL argument value ! this.WriteInt(-1); } else *************** *** 251,255 **** else { ! writeParameter(this, parameter.DataType.DataType, size, parameter.Value); } } --- 290,294 ---- else { ! this.writeParameter(this, parameter.DataType.DataType, size, parameter.Value); } } *************** *** 289,292 **** --- 328,336 ---- break; + case PgDataType.Interval: + packet.WriteInt(size); + packet.WriteInterval((TimeSpan)value); + break; + case PgDataType.Decimal: { *************** *** 322,328 **** break; ! case PgDataType.TimeStamp: packet.WriteInt(size); packet.WriteTimestamp((DateTime)value); break; --- 366,382 ---- break; ! case PgDataType.TimeWithTZ: ! packet.WriteInt(size); ! packet.WriteTimeWithTZ((DateTime)value); ! break; ! ! case PgDataType.Timestamp: packet.WriteInt(size); packet.WriteTimestamp((DateTime)value); + break; + + case PgDataType.TimestampWithTZ: + packet.WriteInt(size); + packet.WriteTimestampWithTZ((DateTime)value); break; Index: PgResponsePacket.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgResponsePacket.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** PgResponsePacket.cs 19 Oct 2003 14:08:22 -0000 1.14 --- PgResponsePacket.cs 26 Oct 2003 11:32:34 -0000 1.15 *************** *** 115,119 **** #endregion ! #region READ_METHODS public string ReadNullString() --- 115,119 ---- #endregion ! #region STRING_TYPES_READ public string ReadNullString() *************** *** 149,152 **** --- 149,156 ---- } + #endregion + + #region NUMERIC_TYPES_READ + public short ReadShort() { *************** *** 199,203 **** return doubleValue.d; ! } public DateTime ReadDate() --- 203,211 ---- return doubleValue.d; ! } ! ! #endregion ! ! #region DATE_TIME_TYPES_READ public DateTime ReadDate() *************** *** 210,213 **** --- 218,229 ---- } + public TimeSpan ReadInterval() + { + double interval = this.ReadDouble(); + int timezone = (-1)*(this.ReadInt()/3600); + + return TimeSpan.FromSeconds(interval); + } + public DateTime ReadTime() { *************** *** 217,220 **** --- 233,244 ---- } + public DateTime ReadTimeWithTZ() + { + DateTime time = this.ReadTime(); + int timezone = (-1)*(this.ReadInt()/3600); + + return time; + } + public DateTime ReadTimestamp() { *************** *** 224,227 **** --- 248,260 ---- } + public DateTime ReadTimestampWithTZ() + { + return this.ReadTimestamp(); + } + + #endregion + + #region ARRAY_VECTOR_TYPES_READ + public Array ReadArray(PgType type, int length) { *************** *** 289,293 **** } ! // Geometric datatypes methods public PgPoint ReadPoint() --- 322,328 ---- } ! #endregion ! ! #region GEOMETRIC_TYPES_READ public PgPoint ReadPoint() *************** *** 346,350 **** #endregion ! #region READ_VALUE public object ReadValue(PgType type, int length) --- 381,385 ---- #endregion ! #region COMMONT_READ_METHOD public object ReadValue(PgType type, int length) *************** *** 393,404 **** return this.ReadLong(); case PgDataType.Date: return this.ReadDate(); case PgDataType.Time: ! return this.ReadTime(); ! case PgDataType.TimeStamp: return this.ReadTimestamp(); case PgDataType.Point: --- 428,448 ---- return this.ReadLong(); + case PgDataType.Interval: + return this.ReadInterval(); + case PgDataType.Date: return this.ReadDate(); case PgDataType.Time: ! return this.ReadTime(); ! case PgDataType.TimeWithTZ: ! return this.ReadTimeWithTZ(); ! ! case PgDataType.Timestamp: return this.ReadTimestamp(); + + case PgDataType.TimestampWithTZ: + return this.ReadTimestampWithTZ(); case PgDataType.Point: Index: PgType.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/NPgClient/PgType.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** PgType.cs 20 Oct 2003 20:30:29 -0000 1.8 --- PgType.cs 26 Oct 2003 11:32:34 -0000 1.9 *************** *** 185,189 **** case PgDataType.Date: case PgDataType.Time: ! case PgDataType.TimeStamp: return Type.GetType("System.DateTime"); --- 185,191 ---- case PgDataType.Date: case PgDataType.Time: ! case PgDataType.TimeWithTZ: ! case PgDataType.Timestamp: ! case PgDataType.TimestampWithTZ: return Type.GetType("System.DateTime"); |