21 using System.Globalization;
30 namespace Deveel.Data.Client {
38 this.command = command;
39 this.behavior = behavior;
42 private bool CloseConnection {
43 get {
return (behavior & CommandBehavior.CloseConnection) != 0; }
46 private bool IsSequential {
47 get {
return (behavior & CommandBehavior.SequentialAccess) != 0; }
50 private T GetFinalValue<T>(
int ordinal) where T : IConvertible {
51 var value = GetRuntimeValue(ordinal);
52 if (value == null || value == DBNull.Value)
58 if (!(value is IConvertible))
59 throw new InvalidCastException(
String.Format(
"Cannot convert '{0}' to type '{1}'.", GetName(ordinal), typeof(T)));
62 return (T)Convert.ChangeType(value, typeof(T), CultureInfo.InvariantCulture);
66 if ((behavior & CommandBehavior.SchemaOnly) != 0)
69 var value = command.CurrentResult.GetRuntimeValue(ordinal);
70 if (value == null || value == DBNull.Value)
77 if ((behavior & CommandBehavior.SchemaOnly) != 0)
80 return command.CurrentResult.GetRawColumn(ordinal);
85 return command.CurrentResult.GetColumn(offset);
89 return command.CurrentResult.FindColumnIndex(name);
94 command.CurrentResult.Close();
97 command.Connection.Close();
98 }
catch (Exception ex) {
101 if (!CloseConnection)
102 command.Connection.EndState();
106 protected override void Dispose(
bool disposing) {
111 base.Dispose(disposing);
120 table.Columns.Add(
"Schema", typeof (
string));
121 table.Columns.Add(
"Table", typeof (
string));
122 table.Columns.Add(
"Name", typeof (
string));
123 table.Columns.Add(
"FullName", typeof (
string));
124 table.Columns.Add(
"SqlType", typeof (
int));
125 table.Columns.Add(
"DbType", typeof (
string));
126 table.Columns.Add(
"Type", typeof (
string));
127 table.Columns.Add(
"Size", typeof (
int));
128 table.Columns.Add(
"Scale", typeof (
int));
129 table.Columns.Add(
"IsUnique", typeof (
bool));
130 table.Columns.Add(
"IsNotNull", typeof (
bool));
131 table.Columns.Add(
"IsSizeable", typeof (
bool));
132 table.Columns.Add(
"IsNumeric", typeof (
bool));
133 table.Columns.Add(
"UniqueGroup", typeof (
int));
135 for (
int i = 0; i < FieldCount; i++) {
136 var row = table.NewRow();
138 var column = GetColumn(i);
140 string fullColumnName = column.Name;
142 string schemaName = null;
143 string tableName = null;
144 string columnName = column.Name;
145 if (columnName.StartsWith(
"@f")) {
147 columnName = columnName.Substring(2, columnName.Length - 2);
148 fullColumnName = columnName;
150 int index = columnName.IndexOf(
'.');
151 schemaName = columnName.Substring(0, index);
152 columnName = columnName.Substring(index + 1);
154 index = columnName.IndexOf(
'.');
155 tableName = columnName.Substring(0, index);
156 columnName = columnName.Substring(index + 1);
157 }
else if (columnName.StartsWith(
"@a")) {
159 columnName = columnName.Substring(2, columnName.Length - 2);
160 fullColumnName = columnName;
163 row[
"Schema"] = schemaName;
164 row[
"Table"] = tableName;
165 row[
"Name"] = columnName;
166 row[
"FullName"] = fullColumnName;
167 row[
"SqlType"] = (int) column.Type.TypeCode;
168 row[
"DbType"] = column.Type.Name;
169 row[
"Size"] = column.Size;
170 row[
"Scale"] = column.Scale;
171 row[
"IsUnique"] = column.IsUnique;
173 row[
"IsNumeric"] = column.IsNumericType;
174 row[
"IsNotNull"] = column.IsNotNull;
175 row[
"UniqueGroup"] = column.UniqueGroup;
184 return command.NextResult();
188 if (wasRead && ((behavior & CommandBehavior.SingleRow)) != 0)
191 if (command.CurrentResult.Next()) {
199 public override int Depth {
203 public override bool IsClosed {
204 get {
return command.CurrentResult.Closed; }
207 public override int RecordsAffected {
209 if (command.CurrentResult == null ||
210 !command.CurrentResult.IsUpdate)
213 return command.CurrentResult.AffectedRows;
218 return GetFinalValue<bool>(ordinal);
222 return GetFinalValue<byte>(ordinal);
225 public override long GetBytes(
int ordinal,
long dataOffset, byte[] buffer,
int bufferOffset,
int length) {
226 throw new NotImplementedException();
230 return GetFinalValue<char>(ordinal);
233 public override long GetChars(
int ordinal,
long dataOffset,
char[] buffer,
int bufferOffset,
int length) {
234 throw new NotImplementedException();
238 throw new NotImplementedException();
242 return GetFinalValue<short>(ordinal);
246 return GetFinalValue<int>(ordinal);
250 return GetFinalValue<long>(ordinal);
254 throw new NotImplementedException();
258 return GetFinalValue<string>(ordinal);
262 return GetRuntimeValue(ordinal);
266 var colCount =
System.Math.Min(FieldCount, values.Length);
267 for (
int i = 0; i < colCount; i++) {
268 values[i] = GetValue(i);
275 return GetRuntimeValue(ordinal) == DBNull.Value;
278 public override int FieldCount {
279 get {
return command.CurrentResult.ColumnCount; }
282 public override object this[
int ordinal] {
283 get {
return GetValue(ordinal); }
286 public override object this[
string name] {
287 get {
return GetValue(GetOrdinal(name)); }
290 public override bool HasRows {
291 get {
return command.CurrentResult.RowCount > 0; }
295 throw new NotImplementedException();
299 return GetFinalValue<double>(ordinal);
303 return GetFinalValue<float>(ordinal);
307 string columnName = command.CurrentResult.GetColumn(ordinal).Name;
308 if (
String.IsNullOrEmpty(columnName))
310 if (columnName.Length <= 2)
313 if (columnName[0] ==
'@') {
314 if (columnName ==
"@aresult")
317 columnName = columnName.Substring(2);
324 return FindColumnIndex(name);
328 var column = command.CurrentResult.GetColumn(ordinal);
332 return column.Type.ToString().ToUpperInvariant();
336 throw new NotImplementedException();
340 var column = command.CurrentResult.GetColumn(ordinal);
344 return column.ValueType;
348 return GetRawValue(ordinal);
352 return new DbEnumerator(
this);
override long GetInt64(int ordinal)
A long string in the system.
override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length)
override IEnumerator GetEnumerator()
override int GetOrdinal(string name)
override Guid GetGuid(int ordinal)
override DataTable GetSchemaTable()
override object GetProviderSpecificValue(int ordinal)
override long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length)
int FindColumnIndex(string name)
override void Dispose(bool disposing)
override DateTime GetDateTime(int ordinal)
override double GetDouble(int ordinal)
override bool IsDBNull(int ordinal)
override string GetName(int ordinal)
override decimal GetDecimal(int ordinal)
Defines the contract for a valid SQL Object
override char GetChar(int ordinal)
DeveelDbDataReader(DeveelDbCommand command, CommandBehavior behavior)
override bool GetBoolean(int ordinal)
override Type GetFieldType(int ordinal)
readonly DeveelDbCommand command
override string GetString(int ordinal)
ISqlObject GetRawValue(int ordinal)
readonly CommandBehavior behavior
object GetRuntimeValue(int ordinal)
override object GetValue(int ordinal)
QueryResultColumn GetColumn(int offset)
override byte GetByte(int ordinal)
override short GetInt16(int ordinal)
override int GetValues(object[] values)
override float GetFloat(int ordinal)
override int GetInt32(int ordinal)
override bool NextResult()
override Type GetProviderSpecificFieldType(int ordinal)
override string GetDataTypeName(int ordinal)
System.Data.DataTable SysDataTable