(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / ByteFX.Data / mysqlclient / CommandResult.cs
blob29e1adcfb2dcf136d2fc89ff2fd30fb909317bdc
1 using System;
3 namespace ByteFX.Data.MySqlClient
5 /// <summary>
6 /// Summary description for CommandResult.
7 /// </summary>
8 internal class CommandResult
10 private Driver driver;
11 private Packet packet;
12 private int affectedRows = -1;
13 private int fieldCount = -1;
14 private int fieldsRead = 0;
15 private long fieldLength = 0;
16 private bool readSchema = false;
17 private bool readRows = false;
19 public CommandResult(Packet p, Driver d)
21 driver = d;
22 packet = p;
23 fieldCount = (int)p.ReadLenInteger();
24 if (fieldCount == 0)
25 affectedRows =(int)p.ReadLenInteger();
28 #region Properties
29 public bool IsResultSet
31 get { return fieldCount > 0; }
34 public int ColumnCount
36 get { return fieldCount; }
39 public int RowsAffected
41 get { return affectedRows; }
44 #endregion
46 public MySqlField GetField()
48 MySqlField f = new MySqlField( driver.Encoding );
49 packet = driver.ReadPacket();
51 f.TableName = packet.ReadLenString();
52 f.ColumnName = packet.ReadLenString();
53 f.ColumnLength = (int)packet.ReadNBytes();
54 f.Type = (MySqlDbType)packet.ReadNBytes();
55 packet.ReadByte(); // this is apparently 2 -- not sure what it is for
56 f.Flags = (ColumnFlags)packet.ReadInteger(2); //(short)(d.ReadByte() & 0xff);
57 f.NumericScale = packet.ReadByte();
58 fieldsRead++;
59 return f;
62 public byte[] GetFieldBuffer()
64 return packet.GetBuffer();
67 public int GetFieldIndex()
69 return (int)packet.Position;
72 public long GetFieldLength()
74 return fieldLength;
77 public bool NextField()
79 if (fieldLength >= 0)
80 packet.Position += fieldLength;
81 if (! packet.HasMoreData) return false;
82 fieldLength = packet.ReadLenInteger();
83 fieldsRead++;
84 return true;
88 /// <summary>
89 /// Checks to see if there are any row packets coming
90 /// </summary>
91 /// <returns>True if there are row packets available, false if not</returns>
92 public bool CheckForRows()
94 // first read off any unread field defs
95 while (fieldsRead < fieldCount)
96 GetField();
98 // read off the end of schema packet
99 packet = driver.ReadPacket();
100 if ( ! packet.IsLastPacket())
101 throw new MySqlException("Expected end of schema packet");
102 readSchema = true;
104 packet = driver.PeekPacket();
105 return ! packet.IsLastPacket();
108 public bool ReadDataRow()
110 packet = driver.ReadPacket();
111 if (packet.IsLastPacket())
113 readRows = true;
114 return false;
116 fieldsRead = 0;
117 fieldLength = 0;
118 NextField();
119 return true;
122 public void Clear()
124 Packet p;
126 if (! readSchema)
130 p = driver.ReadPacket();
131 } while (! p.IsLastPacket());
134 if (! readRows)
137 p = driver.ReadPacket();
138 } while (! p.IsLastPacket());