//

import System
import System.Diagnostics;
import System.Data;
import System.Data.OleDb;
import System.IO;
import System.Xml;
import ServiceHelper;
import System.Reflection;


package jsNetProg {

	class Database {
		private var m_cmd : OleDbCommand;
		private var m_ds : DataSet;		
		private var m_conn : OleDbConnection;
		private var m_connectionString : String;

		function Database()
		{
			m_connectionString=new String("Provider=Microsoft.JET.OLEDB.4.0;data source=\\JSNetProgramming\\data\\news.mdb");
			m_conn = new OleDbConnection (m_connectionString);
			m_conn.Open();
			m_cmd = new OleDbCommand();
			m_cmd.Connection=m_conn;
		}

		public function set databaseLocation(loc : String) {
			Trace.Assert(loc.Length > 0, "Próba użycia pustego ciągu połączenia");
			m_conn.Close();
			m_connectionString=loc;
			m_conn.Open();
			m_cmd = new OleDbCommand();
			m_cmd.Connection=m_conn;
		}
			
		public function get databaseLocation() : String {
			return m_connectionString;
		}
		public function queryDS(qs:String) : DataSet {
			Trace.Assert(qs.Length > 0, "Database.queryDS: otrzymano parametr pusty");
			var lds : DataSet=new DataSet();
			var dataAdapter : OleDbDataAdapter;
			m_cmd.CommandText=qs;
			dataAdapter= new OleDbDataAdapter();
			dataAdapter.SelectCommand =m_cmd;
			dataAdapter.Fill(lds);
			return lds;
		}

		public function execCommand(qs:String) : DataSet {
			Trace.Assert(qs.Length > 0, "Database.execCommand: otrzymano pusty ciąg zapytania");
			m_cmd.CommandText=qs;
			m_cmd.ExecuteNonQuery();
			
		}
		public function Close()  {
			m_conn.Close();	
		}
	}

}