Thread: [pgsqlclient-checkins] pgsqlclient_10/PostgreSql.Data.PgSqlClient/source PgDataReader.cs,1.18,1.19
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2004-03-09 12:56:47
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3411 Modified Files: PgDataReader.cs Log Message: 2004-03-09 Carlos Guzman Alvarez <car...@te...> * PostgreSql.Data.PgSqlClient/PgDataReader.cs: - Improved data reader implementation. Index: PgDataReader.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgDataReader.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** PgDataReader.cs 6 Mar 2004 14:50:56 -0000 1.18 --- PgDataReader.cs 9 Mar 2004 12:39:36 -0000 1.19 *************** *** 394,403 **** public int FieldCount { ! get { return command.Statement.RowDescriptor.Fields.Length; } } public String GetName(int i) { ! return getName(i); } --- 394,406 ---- public int FieldCount { ! get { return this.command.Statement.RowDescriptor.Fields.Length; } } public String GetName(int i) { ! this.checkPosition(); ! this.checkIndex(i); ! ! return this.getName(i); } *************** *** 405,432 **** public String GetDataTypeName(int i) { ! return getDataTypeName(i); } public Type GetFieldType(int i) { ! return getFieldType(i); } public object GetValue(int i) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } ! return getValue(i); } public int GetValues(object[] values) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } for (int i = 0; i < FieldCount; i++) --- 408,436 ---- public String GetDataTypeName(int i) { ! this.checkPosition(); ! this.checkIndex(i); ! ! return this.getDataTypeName(i); } public Type GetFieldType(int i) { ! this.checkPosition(); ! this.checkIndex(i); ! ! return this.getFieldType(i); } public object GetValue(int i) { ! this.checkPosition(); ! this.checkIndex(i); ! return this.getValue(i); } public int GetValues(object[] values) { ! this.checkPosition(); for (int i = 0; i < FieldCount; i++) *************** *** 440,447 **** public int GetOrdinal(string name) { ! if (IsClosed) ! { ! throw new InvalidOperationException("Reader closed"); ! } return getOrdinal(name); --- 444,448 ---- public int GetOrdinal(string name) { ! this.checkPosition(); return getOrdinal(name); *************** *** 450,457 **** public bool GetBoolean(int i) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } return Convert.ToBoolean(GetValue(i)); --- 451,456 ---- public bool GetBoolean(int i) { ! this.checkPosition(); ! this.checkIndex(i); return Convert.ToBoolean(GetValue(i)); *************** *** 460,475 **** public byte GetByte(int i) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } return Convert.ToByte(GetValue(i)); } ! public long GetBytes(int i, long dataIndex, byte[] buffer, ! int bufferIndex, int length) { ! return 0; } --- 459,511 ---- public byte GetByte(int i) { ! this.checkPosition(); ! this.checkIndex(i); return Convert.ToByte(GetValue(i)); } ! public long GetBytes( ! int i, ! long dataIndex, ! byte[] buffer, ! int bufferIndex, ! int length) { ! int bytesRead = 0; ! int realLength = length; ! ! if (buffer == null) ! { ! if (this.IsDBNull(i)) ! { ! return 0; ! } ! else ! { ! byte[] data = (byte[])this.GetValue(i); ! ! return data.Length; ! } ! } ! ! byte[] byteArray = (byte[])this.GetValue(i); ! ! if (length > (byteArray.Length - dataIndex)) ! { ! realLength = byteArray.Length - (int)dataIndex; ! } ! ! Array.Copy(byteArray, (int)dataIndex, buffer, bufferIndex, realLength); ! ! if ((byteArray.Length - dataIndex) < length) ! { ! bytesRead = byteArray.Length - (int)dataIndex; ! } ! else ! { ! bytesRead = length; ! } ! ! return bytesRead; } *************** *** 477,505 **** public char GetChar(int i) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } return Convert.ToChar(GetValue(i)); } ! public long GetChars(int i, long dataIndex, char[] buffer, ! int bufferIndex, int length) { ! return 0; } public Guid GetGuid(int i) { ! return new Guid(); } public Int16 GetInt16(int i) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } return Convert.ToInt16(GetValue(i)); --- 513,580 ---- public char GetChar(int i) { ! this.checkPosition(); ! this.checkIndex(i); return Convert.ToChar(GetValue(i)); } ! public long GetChars( ! int i, ! long dataIndex, ! char[] buffer, ! int bufferIndex, ! int length) { ! this.checkPosition(); ! this.checkIndex(i); ! ! if (buffer == null) ! { ! if (this.IsDBNull(i)) ! { ! return 0; ! } ! else ! { ! char[] data = ((string)this.GetValue(i)).ToCharArray(); ! ! return data.Length; ! } ! } ! ! int charsRead = 0; ! int realLength = length; ! ! char[] charArray = ((string)this.GetValue(i)).ToCharArray(); ! ! if (length > (charArray.Length - dataIndex)) ! { ! realLength = charArray.Length - (int)dataIndex; ! } ! ! System.Array.Copy(charArray, (int)dataIndex, buffer, ! bufferIndex, realLength); ! ! if ( (charArray.Length - dataIndex) < length) ! { ! charsRead = charArray.Length - (int)dataIndex; ! } ! else ! { ! charsRead = length; ! } ! ! return charsRead; } public Guid GetGuid(int i) { ! throw new NotSupportedException("Guid datatype is not supported"); } public Int16 GetInt16(int i) { ! this.checkPosition(); ! this.checkIndex(i); return Convert.ToInt16(GetValue(i)); *************** *** 508,515 **** public Int32 GetInt32(int i) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } return Convert.ToInt32(GetValue(i)); --- 583,588 ---- public Int32 GetInt32(int i) { ! this.checkPosition(); ! this.checkIndex(i); return Convert.ToInt32(GetValue(i)); *************** *** 518,525 **** public Int64 GetInt64(int i) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } return Convert.ToInt64(GetValue(i)); --- 591,596 ---- public Int64 GetInt64(int i) { ! this.checkPosition(); ! this.checkIndex(i); return Convert.ToInt64(GetValue(i)); *************** *** 528,535 **** public float GetFloat(int i) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } return Convert.ToSingle(GetValue(i)); --- 599,604 ---- public float GetFloat(int i) { ! this.checkPosition(); ! this.checkIndex(i); return Convert.ToSingle(GetValue(i)); *************** *** 538,545 **** public double GetDouble(int i) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } return Convert.ToDouble(GetValue(i)); --- 607,612 ---- public double GetDouble(int i) { ! this.checkPosition(); ! this.checkIndex(i); return Convert.ToDouble(GetValue(i)); *************** *** 548,555 **** public String GetString(int i) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } return Convert.ToString(GetValue(i)); --- 615,620 ---- public String GetString(int i) { ! this.checkPosition(); ! this.checkIndex(i); return Convert.ToString(GetValue(i)); *************** *** 558,565 **** public Decimal GetDecimal(int i) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } return Convert.ToDecimal(GetValue(i)); --- 623,628 ---- public Decimal GetDecimal(int i) { ! this.checkPosition(); ! this.checkIndex(i); return Convert.ToDecimal(GetValue(i)); *************** *** 568,575 **** public DateTime GetDateTime(int i) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } return Convert.ToDateTime(GetValue(i)); --- 631,636 ---- public DateTime GetDateTime(int i) { ! this.checkPosition(); ! this.checkIndex(i); return Convert.ToDateTime(GetValue(i)); *************** *** 578,585 **** public TimeSpan GetTimeSpan(int i) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } return (TimeSpan)GetValue(i); --- 639,644 ---- public TimeSpan GetTimeSpan(int i) { ! this.checkPosition(); ! this.checkIndex(i); return (TimeSpan)GetValue(i); *************** *** 588,591 **** --- 647,653 ---- public PgPoint GetPgPoint(int i) { + this.checkPosition(); + this.checkIndex(i); + return (PgPoint)this.GetPgValue(i); } *************** *** 593,596 **** --- 655,661 ---- public PgBox GetPgBox(int i) { + this.checkPosition(); + this.checkIndex(i); + return (PgBox)this.GetPgValue(i); } *************** *** 598,601 **** --- 663,669 ---- public PgLSeg GetPgLSeg(int i) { + this.checkPosition(); + this.checkIndex(i); + return (PgLSeg)this.GetPgValue(i); } *************** *** 603,606 **** --- 671,677 ---- public PgCircle GetPgCircle(int i) { + this.checkPosition(); + this.checkIndex(i); + return (PgCircle)this.GetPgValue(i); } *************** *** 608,611 **** --- 679,685 ---- public PgPath GetPgPath(int i) { + this.checkPosition(); + this.checkIndex(i); + return (PgPath)this.GetPgValue(i); } *************** *** 613,616 **** --- 687,693 ---- public PgPolygon GetPgPolygon(int i) { + this.checkPosition(); + this.checkIndex(i); + return (PgPolygon)this.GetPgValue(i); } *************** *** 618,621 **** --- 695,701 ---- public PgTimeSpan GetPgTimeSpan(int i) { + this.checkPosition(); + this.checkIndex(i); + return new PgTimeSpan(this.GetTimeSpan(i)); } *************** *** 623,626 **** --- 703,709 ---- public object GetPgValue(int i) { + this.checkPosition(); + this.checkIndex(i); + switch (this.getProviderType(i)) { *************** *** 650,664 **** public bool IsDBNull(int i) { ! if (position == STARTPOS) ! { ! throw new InvalidOperationException("There are no data to read."); ! } ! ! if (i < 0 || i >= FieldCount) ! { ! throw new IndexOutOfRangeException("Could not find specified column in results."); ! } ! return isDBNull(i); } --- 733,740 ---- public bool IsDBNull(int i) { ! this.checkPosition(); ! this.checkIndex(i); ! return this.isDBNull(i); } *************** *** 676,679 **** --- 752,771 ---- #region Private Methods + private void checkIndex(int i) + { + if (i < 0 || i >= this.fieldCount) + { + throw new IndexOutOfRangeException("Could not find specified column in results."); + } + } + + private void checkPosition() + { + if (this.position == STARTPOS) + { + throw new InvalidOperationException("There are no data to read."); + } + } + private IDataReader getData(int i) { *************** *** 683,689 **** private int getOrdinal(string name) { ! for (int i = 0; i < command.Statement.RowDescriptor.Fields.Length; i++) { ! if (cultureAwareCompare(command.Statement.RowDescriptor.Fields[i].FieldName, name)) { return i; --- 775,781 ---- private int getOrdinal(string name) { ! for (int i = 0; i < this.command.Statement.RowDescriptor.Fields.Length; i++) { ! if (this.cultureAwareCompare(command.Statement.RowDescriptor.Fields[i].FieldName, name)) { return i; *************** *** 696,705 **** private string getName(int i) { ! return command.Statement.RowDescriptor.Fields[i].FieldName; } private int getSize(int i) { ! return command.Statement.RowDescriptor.Fields[i].DataType.Size; } --- 788,797 ---- private string getName(int i) { ! return this.command.Statement.RowDescriptor.Fields[i].FieldName; } private int getSize(int i) { ! return this.command.Statement.RowDescriptor.Fields[i].DataType.Size; } |