using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SQLLite;
using System.Text;
namespace Program
{
public class Init
{
static void Main( string[] args )
{
using ( Data data = new Data() )
{
Console.WriteLine(data.Find( 19,"Table", "Column"));
Console.WriteLine(data.Find( 2, "Table", "Column" ));
Console.WriteLine(data.Find( 3, "Table", "Column" ));
Console.WriteLine(data.Find( 4, "Table", "Column" ));
}
}
}
public class Data : IDisposable
{
private SQLiteConnection conn;
private SQLiteCommand stmt;
private SQLiteDataReader reader;
public Data()
{
conn = new SQLiteConnection( "data source=sugammadex.db;version=3" );
stmt = new SQLiteCommand( conn );
}
public object Find( int id, string table, string return_column )
{
conn.Open();
stmt.CommandText = string.Format( "select {0} from {1} where id = {2}", return_column, table, id );
object retval;
using ( reader = stmt.ExecuteReader() )
{
try { retval = reader[return_column]; }
catch ( SQLiteException ex ) { throw new SQLiteException( "Bad query.", ex ); }
conn.Close();
return retval;
}
}
public object Find( string conditions, string table, string return_column )
{
conn.Open();
stmt.CommandText = string.Format( "select {0} from {1} where {3}", return_column, table, conditions );
object retval;
using ( reader = stmt.ExecuteReader() )
{
try { retval = reader[return_column]; }
catch ( SQLiteException ex ) { throw new SQLiteException( "Bad query.", ex ); }
conn.Close();
return retval;
}
}
public void Dispose()
{
Dispose( true );
}
///
/// An overridable Dispose method to allow subclasses to add their
/// own dispose routines
///
///
protected virtual void Dispose(bool disposing)
{
// tidy managed resources
if ( disposing )
{
if ( reader != null )
{
reader.Dispose();
reader = null;
}
if ( conn != null )
{
conn.Dispose();
conn = null;
}
}
// tidy unmanaged resources
else
{
// no unmanaged resources, do nothing
}
}
}
}