3 namespace ByteFX
.Data
.MySqlClient
6 /// Summary description for CommandResult.
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
)
23 fieldCount
= (int)p
.ReadLenInteger();
25 affectedRows
=(int)p
.ReadLenInteger();
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; }
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();
62 public byte[] GetFieldBuffer()
64 return packet
.GetBuffer();
67 public int GetFieldIndex()
69 return (int)packet
.Position
;
72 public long GetFieldLength()
77 public bool NextField()
80 packet
.Position
+= fieldLength
;
81 if (! packet
.HasMoreData
) return false;
82 fieldLength
= packet
.ReadLenInteger();
89 /// Checks to see if there are any row packets coming
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
)
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");
104 packet
= driver
.PeekPacket();
105 return ! packet
.IsLastPacket();
108 public bool ReadDataRow()
110 packet
= driver
.ReadPacket();
111 if (packet
.IsLastPacket())
130 p
= driver
.ReadPacket();
131 } while (! p
.IsLastPacket());
137 p
= driver
.ReadPacket();
138 } while (! p
.IsLastPacket());