} // RemoveDrive #endregion Drive Manipulation #region Item Methods /// <summary> /// Retrieves an item using the specified path. /// </summary> /// <param name="path">The path to the item to return.</param> protected override void GetItem(string path) { // check if the path represented is a drive if (PathIsDrive(path)) { WriteItemObject(this.PSDriveInfo, path, true); return; }// if (PathIsDrive... // Get table name and row information from the path and do // necessary actions string tableName; int rowNumber; PathType type = GetNamesFromPath(path, out tableName, out rowNumber); if (type == PathType.Table) { DatabaseTableInfo table = GetTable(tableName); WriteItemObject(table, path, true); } else if (type == PathType.Row) { DatabaseRowInfo row = GetRow(tableName, rowNumber); WriteItemObject(row, path, false); } else { ThrowTerminatingInvalidPathException(path); } } // GetItem
/// <summary> /// Retrieve the list of tables from the database. /// </summary> /// <returns> /// Collection of DatabaseTableInfo objects, each object representing /// information about one database table /// </returns> private Collection <DatabaseTableInfo> GetTables() { Collection <DatabaseTableInfo> results = new Collection <DatabaseTableInfo>(); // using ODBC connection to the database and get the schema of tables AccessDBPSDriveInfo di = this.PSDriveInfo as AccessDBPSDriveInfo; if (di == null) { return(null); } OdbcConnection connection = di.Connection; DataTable dt = connection.GetSchema("Tables"); int count; // iterate through all rows in the schema and create DatabaseTableInfo // objects which represents a table foreach (DataRow dr in dt.Rows) { String tableName = dr["TABLE_NAME"] as String; DataColumnCollection columns = null; // find the number of rows in the table try { String cmd = "Select count(*) from \"" + tableName + "\""; OdbcCommand command = new OdbcCommand(cmd, connection); count = (Int32)command.ExecuteScalar(); } catch { count = 0; } // create DatabaseTableInfo object representing the table DatabaseTableInfo table = new DatabaseTableInfo(dr, tableName, count, columns); results.Add(table); } // foreach (DataRow... return(results); } // GetTables
} // SetItem /// <summary> /// Test to see if the specified item exists. /// </summary> /// <param name="path">The path to the item to verify.</param> /// <returns>True if the item is found.</returns> protected override bool ItemExists(string path) { // check if the path represented is a drive if (PathIsDrive(path)) { return(true); } // Obtain type, table name and row number from path string tableName; int rowNumber; PathType type = GetNamesFromPath(path, out tableName, out rowNumber); DatabaseTableInfo table = GetTable(tableName); if (type == PathType.Table) { // if specified path represents a table then DatabaseTableInfo // object for the same should exist if (table != null) { return(true); } } else if (type == PathType.Row) { // if specified path represents a row then DatabaseTableInfo should // exist for the table and then specified row number must be within // the maximum row count in the table if (table != null && rowNumber < table.RowCount) { return(true); } } return(false); } // ItemExists
/// <summary> /// Retrieve the list of tables from the database. /// </summary> /// <returns> /// Collection of DatabaseTableInfo objects, each object representing /// information about one database table /// </returns> internal Collection<DatabaseTableInfo> GetTables() { Collection<DatabaseTableInfo> results = new Collection<DatabaseTableInfo>(); // using ODBC connection to the database and get the schema of tables AccessDBPSDriveInfo di = this.PSDriveInfo as AccessDBPSDriveInfo; if (di == null) { return null; } OdbcConnection connection = di.Connection; DataTable dt = connection.GetSchema("Tables"); int count; // iterate through all rows in the schema and create DatabaseTableInfo // objects which represents a table foreach (DataRow dr in dt.Rows) { String tableName = dr["TABLE_NAME"] as String; DataColumnCollection columns = null; // find the number of rows in the table try { String cmd = "Select count(*) from \"" + tableName + "\""; OdbcCommand command = new OdbcCommand(cmd, connection); count = (Int32)command.ExecuteScalar(); } catch { count = 0; } // create DatabaseTableInfo object representing the table DatabaseTableInfo table = new DatabaseTableInfo(dr, tableName, count, columns); results.Add(table); } // foreach (DataRow... return results; } // GetTables