// Spludlow Software
// Copyright © Samuel P. Ludlow 2020 All Rights Reserved
// Distributed under the terms of the GNU General Public License version 3
// Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
// https://www.spludlow.co.uk/LICENCE.TXT
// The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission
// v1.14
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using dBASE.Data.dBASEClient;
namespace Spludlow.Data
{
///
/// Using: dBASE.Data.dBASEClient
/// tried ODBC but was it did not like table names over 8.3 long
///
/// Only implimented table list and select
///
/// tested with OS map data
///
public class DALdBase : Spludlow.Data.IDAL
{
private dBASEConnection Connection = null;
private DbTransaction Transaction = null; // Not supported
public DALdBase()
{
}
public DALdBase(string connectionString)
{
this.Initialize(connectionString);
}
public void Initialize(string connectionString)
{
if (connectionString == null || connectionString.Length == 0)
return;
if (connectionString.StartsWith("@") == true)
connectionString = Spludlow.Config.ConnectionString(connectionString.Substring(1));
if (connectionString.Contains(";") == false)
connectionString = MakeConnectionString(connectionString);
this.Connection = new dBASEConnection(connectionString);
this.Connection.Open();
try
{
// This sets Connection.DataSource
}
finally
{
this.Connection.Close();
}
}
public static string MakeConnectionString(string dataDirectory)
{
return "Data Source=" + dataDirectory + ";";
}
private void Open()
{
this.Connection.Open();
}
private void Close()
{
this.Connection.Close();
}
public string[] TableList()
{
List tableNames = new List();
foreach (string filename in Directory.GetFiles(this.Connection.DataSource, "*.dbf"))
tableNames.Add(Path.GetFileNameWithoutExtension(filename));
return tableNames.ToArray();
}
public DataTable Select(string commandText)
{
throw new NotImplementedException();
}
public DataTable Select(string commandText, params object[] parameterValues)
{
throw new NotImplementedException();
}
public DataTable Select(string commandText, string[] parameterNames, params object[] parameterValues)
{
throw new NotImplementedException();
}
public DataTable Select(DAL.CommandInfo commandInfo, params object[] parameterValues)
{
throw new NotImplementedException();
}
public DataTable Select(DbCommand command)
{
throw new NotImplementedException();
}
public DataSet SelectDS(string commandText)
{
using (dBASECommand command = (dBASECommand)this.MakeCommand(commandText))
return this.SelectDS(command);
}
public DataSet SelectDS(string commandText, params object[] parameterValues)
{
throw new NotImplementedException();
}
public DataSet SelectDS(string commandText, string[] parameterNames, params object[] parameterValues)
{
throw new NotImplementedException();
}
public DataSet SelectDS(DAL.CommandInfo commandInfo, params object[] parameterValues)
{
throw new NotImplementedException();
}
public DataSet SelectDS(DbCommand command)
{
throw new NotImplementedException();
}
private DataSet SelectDS(dBASECommand command)
{
DataSet dataSet = new DataSet();
this.ExecuteAdapter(command, dataSet, null);
return dataSet;
}
private void ExecuteAdapter(dBASECommand command, DataSet dataSet, DataTable table)
{
if (this.Transaction == null)
this.Open();
try
{
using (dBASEDataAdapter adapter = new dBASEDataAdapter())
{
adapter.SelectCommand = command;
if (dataSet != null)
adapter.Fill(dataSet);
if (table != null)
adapter.Fill(table);
}
}
finally
{
if (this.Transaction == null)
this.Close();
}
}
public DbCommand MakeCommand(string commandText)
{
return this.MakeCommandNative(commandText);
}
public DbCommand MakeCommand(string commandText, params object[] parameterValues)
{
throw new NotImplementedException();
}
public DbCommand MakeCommand(string commandText, string[] parameterNames, params object[] parameterValues)
{
throw new NotImplementedException();
}
public DbCommand MakeCommand(DAL.CommandInfo commandInfo, params object[] parameterValues)
{
throw new NotImplementedException();
}
private dBASECommand MakeCommandNative(string commandText)
{
dBASECommand command = new dBASECommand(commandText, this.Connection); //, this.Transaction);
//if (this.CommandTimeoutSeconds >= 0)
// command.CommandTimeout = this.CommandTimeoutSeconds;
return command;
}
public void Backup(string serverFilename)
{
throw new NotImplementedException();
}
public void Begin()
{
throw new NotImplementedException();
}
public void BulkInsert(DataTable table, string tableName, string tempDirectory)
{
throw new NotImplementedException();
}
public void ChangeDatabase(string databaseName)
{
throw new NotImplementedException();
}
public void CommandTimeout(int minutes)
{
throw new NotImplementedException();
}
public void Commit()
{
throw new NotImplementedException();
}
public string CurrentDatabase()
{
throw new NotImplementedException();
}
public void DatabaseCreate(string databaseName)
{
throw new NotImplementedException();
}
public void DatabaseCreate(string databaseName, DataSet schema)
{
throw new NotImplementedException();
}
public void DatabaseDelete(string databaseName)
{
throw new NotImplementedException();
}
public bool DatabaseExists(string databaseName)
{
throw new NotImplementedException();
}
public string[] DatabaseList()
{
throw new NotImplementedException();
}
public string DataSource()
{
throw new NotImplementedException();
}
public int ExecuteNonQuery(string commandText)
{
throw new NotImplementedException();
}
public int ExecuteNonQuery(string commandText, params object[] parameterValues)
{
throw new NotImplementedException();
}
public int ExecuteNonQuery(string commandText, string[] parameterNames, params object[] parameterValues)
{
throw new NotImplementedException();
}
public int ExecuteNonQuery(DAL.CommandInfo commandInfo, params object[] parameterValues)
{
throw new NotImplementedException();
}
public int ExecuteNonQuery(DbCommand command)
{
throw new NotImplementedException();
}
public object ExecuteScalar(string commandText)
{
throw new NotImplementedException();
}
public object ExecuteScalar(string commandText, params object[] parameterValues)
{
throw new NotImplementedException();
}
public object ExecuteScalar(string commandText, string[] parameterNames, params object[] parameterValues)
{
throw new NotImplementedException();
}
public object ExecuteScalar(DAL.CommandInfo commandInfo, params object[] parameterValues)
{
throw new NotImplementedException();
}
public object ExecuteScalar(DbCommand command)
{
throw new NotImplementedException();
}
public void Fill(DataSet dataSet, string commandText)
{
throw new NotImplementedException();
}
public void Fill(DataSet dataSet, string commandText, params object[] parameterValues)
{
throw new NotImplementedException();
}
public void Fill(DataSet dataSet, string commandText, string[] parameterNames, params object[] parameterValues)
{
throw new NotImplementedException();
}
public void Fill(DataSet dataSet, DAL.CommandInfo commandInfo, params object[] parameterValues)
{
throw new NotImplementedException();
}
public void Fill(DataSet dataSet, DbCommand command)
{
throw new NotImplementedException();
}
public void Fill(DataTable table, string commandText)
{
throw new NotImplementedException();
}
public void Fill(DataTable table, string commandText, params object[] parameterValues)
{
throw new NotImplementedException();
}
public void Fill(DataTable table, string commandText, string[] parameterNames, params object[] parameterValues)
{
throw new NotImplementedException();
}
public void Fill(DataTable table, DAL.CommandInfo commandInfo, params object[] parameterValues)
{
throw new NotImplementedException();
}
public void Fill(DataTable table, DbCommand command)
{
throw new NotImplementedException();
}
public long Insert(DataRow row)
{
throw new NotImplementedException();
}
public long Insert(string tableName, DataRow row)
{
throw new NotImplementedException();
}
public long Insert(DAL.CommandInfo insertInfo, DataRow row)
{
throw new NotImplementedException();
}
public long Insert(string tableName, params object[] row)
{
throw new NotImplementedException();
}
public long Insert(DAL.CommandInfo insertInfo, params object[] row)
{
throw new NotImplementedException();
}
public long InsertOrUpdate(DataRow row)
{
throw new NotImplementedException();
}
public long InsertOrUpdate(string tableName, DataRow row)
{
throw new NotImplementedException();
}
public void LoginCreate(string loginName, bool administrator)
{
throw new NotImplementedException();
}
public void LoginCreate(string loginName, string password, bool administrator)
{
throw new NotImplementedException();
}
public void LoginDelete(string loginName)
{
throw new NotImplementedException();
}
public bool LoginExists(string loginName)
{
throw new NotImplementedException();
}
public string[] LoginList()
{
throw new NotImplementedException();
}
public DAL.CommandInfo MakeCommandInfo(string commandText)
{
throw new NotImplementedException();
}
public DAL.CommandInfo MakeCommandInfo(string commandText, string[] parameterNames)
{
throw new NotImplementedException();
}
public DAL.CommandInfo MakeInserter(string tableName)
{
throw new NotImplementedException();
}
public DAL.CommandInfo MakeUpdater(string tableName)
{
throw new NotImplementedException();
}
public DAL.CommandInfo MakeUpdater(string tableName, string[] updateColumns)
{
throw new NotImplementedException();
}
public void Operation(string details)
{
throw new NotImplementedException();
}
public string PageCommandText(string commandText, int pageIndex, int pageSize)
{
throw new NotImplementedException();
}
public void Restore(string serverFilename)
{
throw new NotImplementedException();
}
public void Rollback()
{
throw new NotImplementedException();
}
public string RunScript(string localFilename, string server, string database)
{
throw new NotImplementedException();
}
public string RunScript(string localFilename, string server, string database, string userName, string password)
{
throw new NotImplementedException();
}
public DataSet Schema()
{
throw new NotImplementedException();
}
public DataSet Schema(string tableName)
{
throw new NotImplementedException();
}
public DataSet Schema(string[] tableNames)
{
throw new NotImplementedException();
}
public DataSet SchemaANSI()
{
throw new NotImplementedException();
}
public DataSet SchemaConnection()
{
throw new NotImplementedException();
}
public DataSet SchemaNative()
{
throw new NotImplementedException();
}
public DataSet SchemaReader()
{
throw new NotImplementedException();
}
public void SchemaRefresh()
{
throw new NotImplementedException();
}
public void TableAddKeys(DataSet schema, string keyTypesPUIF)
{
throw new NotImplementedException();
}
public void TableAddKeys(string tableName, DataSet schema, string keyTypesPUIF)
{
throw new NotImplementedException();
}
public void TableAddKeys(string[] tableNames, DataSet schema, string keyTypesPUIF)
{
throw new NotImplementedException();
}
public void TableClear(string tableName)
{
throw new NotImplementedException();
}
public void TableCreate(string tableName, DataSet schema)
{
throw new NotImplementedException();
}
public void TableCreate(string tableName, DataTable schemaColumns, DataTable schemaKeys)
{
throw new NotImplementedException();
}
public void TableDelete(string tableName)
{
throw new NotImplementedException();
}
public bool TableExists(string tableName)
{
throw new NotImplementedException();
}
public int Update(DataRow row)
{
throw new NotImplementedException();
}
public int Update(string tableName, DataRow row)
{
throw new NotImplementedException();
}
public int Update(string tableName, string[] columns, DataRow row)
{
throw new NotImplementedException();
}
public int Update(DAL.CommandInfo info, DataRow row)
{
throw new NotImplementedException();
}
public int Update(string tableName, params object[] row)
{
throw new NotImplementedException();
}
public int Update(string tableName, string[] columns, params object[] row)
{
throw new NotImplementedException();
}
public int Update(DAL.CommandInfo info, params object[] row)
{
throw new NotImplementedException();
}
public void UserCreate(string userName, string loginName, bool administrator)
{
throw new NotImplementedException();
}
public void UserDelete(string userName)
{
throw new NotImplementedException();
}
public bool UserExists(string userName)
{
throw new NotImplementedException();
}
public string[] UserList()
{
throw new NotImplementedException();
}
}
}