Add project files.
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Dbas.Base;
|
||||
|
||||
namespace Sarand.Net.Standard.Dbas.Data
|
||||
{
|
||||
//=======================================================================
|
||||
public class DbResultSet_DataTableReader : DbResultSet
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private SacsDatabase database = null;
|
||||
private String query = String.Empty;
|
||||
private DbConnection dbConnection = null;
|
||||
private DbCommand dbCommand = null;
|
||||
private DbDataAdapter dbDataAdapter = null;
|
||||
private DataTableReader dataTableReader = null;
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public DbResultSet_DataTableReader (SacsDatabase database, String query)
|
||||
{
|
||||
this.database = database;
|
||||
this.query = query;
|
||||
ExecuteQuery();
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Execute query.
|
||||
private void ExecuteQuery ()
|
||||
{
|
||||
ClearErrorState();
|
||||
String fn = GetType().Name + ".ExecuteQuery";
|
||||
Close();
|
||||
try
|
||||
{
|
||||
dbConnection = database.CreateConnection();
|
||||
dbCommand = dbConnection.CreateCommand();
|
||||
dbDataAdapter = database.CreateDataAdapter();
|
||||
dbDataAdapter.SelectCommand = dbCommand;
|
||||
dbDataAdapter.SelectCommand.CommandText = database.GetSelectQueryPrefix() + query;
|
||||
DataTable dataTable = new DataTable();
|
||||
dbDataAdapter.Fill(dataTable);
|
||||
dataTableReader = new DataTableReader(dataTable);
|
||||
Log(fn, GetType().Name + ".ExecuteQuery Query: " + query + (HasRows ? " [has rows]" : " [no rows]"), SaMessageLevel.Debug);
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
SetErrorState(exc.GetType().Name + ": " + exc.Message);
|
||||
SaLogger.Warn(fn + " " + exc.GetType().Name + ": " + exc.Message + "\n\t Query: " + query, true);
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
protected override void Dispose (bool disposing)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
public override void Close ()
|
||||
{
|
||||
// Dispose of database objects.
|
||||
if (dataTableReader != null) dataTableReader.Close();
|
||||
dataTableReader = null;
|
||||
if (dbDataAdapter != null) dbDataAdapter.Dispose();
|
||||
if (dbCommand != null) dbCommand.Dispose();
|
||||
if (dbConnection != null) dbConnection.Dispose();
|
||||
dataTableReader = null;
|
||||
dbDataAdapter = null;
|
||||
dbCommand = null;
|
||||
dbConnection = null;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Navigation.
|
||||
public override bool NextRecord ()
|
||||
{
|
||||
// Move to next result.
|
||||
bool nextRecord = false;
|
||||
if (dataTableReader != null)
|
||||
{
|
||||
nextRecord = dataTableReader.Read();
|
||||
if (!nextRecord)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
return nextRecord;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
// Attributes.
|
||||
public override int FieldCount
|
||||
{
|
||||
get
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.FieldCount;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public override bool HasRows
|
||||
{
|
||||
get
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.HasRows;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public override int GetOrdinal (String columnName)
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.GetOrdinal(columnName);
|
||||
return -1;
|
||||
}
|
||||
public override String GetDataTypeName (int columnIdx)
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.GetDataTypeName(columnIdx);
|
||||
return String.Empty;
|
||||
}
|
||||
public override String GetName (int columnIdx)
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.GetName(columnIdx);
|
||||
return String.Empty;
|
||||
}
|
||||
public override bool IsDbNull (int columnIdx)
|
||||
{
|
||||
return (GetValue(columnIdx) is System.DBNull);
|
||||
}
|
||||
public override object GetValue (int columnIdx)
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.GetValue(columnIdx);
|
||||
return false;
|
||||
}
|
||||
public override bool GetBoolean (int columnIdx)
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.GetBoolean(columnIdx);
|
||||
return false;
|
||||
}
|
||||
public override byte GetByte (int columnIdx)
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.GetByte(columnIdx);
|
||||
return 0;
|
||||
}
|
||||
public override short GetInt16 (int columnIdx)
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.GetInt16(columnIdx);
|
||||
return 0;
|
||||
}
|
||||
public override int GetInt32 (int columnIdx)
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.GetInt32(columnIdx);
|
||||
return 0;
|
||||
}
|
||||
public override long GetInt64 (int columnIdx)
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.GetInt64(columnIdx);
|
||||
return 0;
|
||||
}
|
||||
public override float GetFloat (int columnIdx)
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.GetFloat(columnIdx);
|
||||
return 0.0f;
|
||||
}
|
||||
public override double GetDouble (int columnIdx)
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.GetDouble(columnIdx);
|
||||
return 0.0;
|
||||
}
|
||||
public override decimal GetDecimal (int columnIdx)
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.GetDecimal(columnIdx);
|
||||
return 0.0m;
|
||||
}
|
||||
public override String GetString (int columnIdx)
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.GetString(columnIdx);
|
||||
return String.Empty;
|
||||
}
|
||||
public override DateTime GetDateTime (int columnIdx)
|
||||
{
|
||||
if (dataTableReader != null)
|
||||
return dataTableReader.GetDateTime(columnIdx);
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
//-------------------------------------------------------------------
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user