public IndexFileNTX(Stream stream, DbfTable dbfTable, bool?skipDeleted = null, int indexPageCacheSize = 0) : base(stream, dbfTable, skipDeleted, indexPageCacheSize) // 'stream', 'dbfTable' and 'skipDeleted' already stored by base class constructor { this.header = GetHeader(stream); // fill 'header' & IsStreamValid/Exception if error Top(); }
// /// <summary> /// Create a new DBF datafile. /// Create() can't overwrite exists file - it's a precautionary measure. /// </summary> /// <param name="path">A not exists filename.</param> /// <param name="columns">Definition of columns</param> /// <param name="encoding">Encoding for open created file. -- It mean too, CodepageCodes of new file will OEM</param> /// <returns></returns> public static DbfTable Create(string path, IEnumerable <ColumnDefinitionForCreateTable> columns, Encoding encoding, DbfTableType tableType = DbfTableType.Undefined) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } if (columns == null) { throw new ArgumentNullException("columns"); } // var streamDBF = new FileStream(path, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None); DbfTable dbfTable = CreateHeader_DBF(streamDBF, columns, tableType, CodepageCodes.OEM, encoding); if (dbfTable.isExistsMemoField) { MemoFileType memoType = dbfTable.DefaultMemoFileFormatForDbf(); Stream streamMemo = CreateHeader_Memo(path, memoType); dbfTable.JoinMemoStream(streamMemo, memoType); } return(dbfTable); }
// http://stackoverflow.com/questions/1852837/is-there-a-generic-constructor-with-parameter-constraint-in-c // http://stackoverflow.com/questions/700966/generic-type-in-constructor public T Read <T>() where T : class, new() // new from 1.3 version { do { row_ = dbfTable.GetRow(nextRecNo, false); // Don't throw an exception, returns null if record not found nextRecNo++; } while (skipDeleted && (row_ != null) && row_.deleted); return(DbfTable.Get <T>(row_)); }
public bool recNoOverflowException = true; // internal ClipperReader(DbfTable dbfTable, bool skipDeleted) { if (dbfTable == null) { throw ExceptionFactory.CreateArgumentException("dbfTable", "null parameter"); } this._dbfTable = dbfTable; this.skipDeleted = skipDeleted; Top(); }
/// <summary> /// Loads the DBF table into a <see cref="DataTable"/> with the default ASCII encoding. /// </summary> /// <param name="table">The DBF table to load.</param> /// <returns>A <see cref="DataTable"/> loaded from the DBF table.</returns> /// <exception cref="InvalidOperationException">Another reader of the DBF table is opened.</exception> /// <exception cref="ObjectDisposedException">The DBF table is disposed.</exception> public static DataTable AsDataTable(this DbfTable table) { if (table == null) { throw new ArgumentNullException("table"); } var dataTable = CreateDataTable(table); FillData(table, dataTable); return(dataTable); }
public bool skipDeleted = true; // leave out deleted rows from result internal Reader(DbfTable dbfTable, int startRecNo = 0) { if (dbfTable == null) { throw ExceptionFactory.CreateArgumentException("dbfTable", "null parameter"); } this.dbfTable = dbfTable; this.nextRecNo = Math.Max(startRecNo, 0); this.skipDeleted = dbfTable.skipDeleted; }
public IEnumerator <T> GetEnumerator <T>(bool skipDeleted) where T : class, new() { for (int i = 0; i < this.recCount; i++) { DbfRow row = this.GetRow(i); if (skipDeleted && row.deleted) { continue; } yield return(DbfTable.Get <T>(row)); } }
public static bool[] enabledKeyChars = new bool[enabledKeyCharsLen]; // It can be modified by users if only it's a problem! #endregion #region constructor ----------------------------------------------------------------------------------- internal IndexFileBase(Stream stream, DbfTable dbfTable, bool?skipDeleted = null, int indexPageCacheSize = 0) { disposed = false; if (stream == null) { throw ExceptionFactory.CreateArgumentException("stream", "IndexFileXXXX/stream is null!"); } this.stream = stream; this._dbfTable = dbfTable; this.skipDeleted = skipDeleted ?? dbfTable.skipDeleted; this.indexPageCacheSize = indexPageCacheSize; }
private static void FillData(DbfTable table, DataTable dataTable) { for (int i = 0; i < table.recCount; i++) { var rowDT = dataTable.NewRow(); var recDBF = table.GetRow(i); foreach (var column in table.columns) { rowDT[column.name] = recDBF.GetValue(column) ?? DBNull.Value; } dataTable.Rows.Add(rowDT); } }
private static DataTable CreateDataTable(DbfTable table) { var dataTable = new DataTable() { Locale = CultureInfo.CurrentCulture }; foreach (var column in table.columns) { var columnType = Nullable.GetUnderlyingType(column.type) ?? column.type; dataTable.Columns.Add(column.name, columnType); } return(dataTable); }
private int lastRecNo; // table filter (record limit) #endregion public DbfTablePocoEnumerator(DbfTable table, bool?skipDeleted = null, int?firstRecNo = null, int?lastRecNo = null) { this.table = table; this.skipDeleted = skipDeleted ?? table.skipDeleted; this.firstRecNo = firstRecNo ?? 0; this.lastRecNo = lastRecNo ?? table.recCount - 1; if (this.firstRecNo < 0) { this.firstRecNo = 0; } if (this.lastRecNo >= table.recCount) { this.lastRecNo = table.recCount - 1; } }
/// <summary> /// Opens a table from the specified file. /// </summary> /// <param name="path">The file to be opened.</param> /// <returns>A table instance.</returns> /// <exception cref="ArgumentNullException"><paramref name="path"/> is <c>null</c> or empty.</exception> /// <exception cref="NotSupportedException">The dBASE table constains one or more columns of unsupported type.</exception> public static DbfTable Open(string path, DbfTableParameters parameters) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } var stream = new FileStream(path, FileMode.Open, parameters.fileAccess, parameters.fileShare); var dbfFile = new DbfTable(stream, parameters); dbfFile.dataFileName = path; if (dbfFile.isExistsMemoField && parameters.openMemo) { // If exist a memo field and it is opened from a file, so I can find DBT/FPT/etc. memo file too. dbfFile.JoinMemoFile(); } return(dbfFile); }
public IndexFileNDX(Stream stream, DbfTable dbfTable, bool?skipDeleted = null, int indexPageCacheSize = 0) : base(stream, dbfTable, skipDeleted, indexPageCacheSize) // 'stream', 'dbfTable' and 'skipDeleted' already stored by base class constructor { this.header = GetHeader(stream); // fill 'header' & IsStreamValid/Exception if error // #if DEBUG List <string> list = new List <string>(); for (int i = 1; (i < this.header.totalPages); i++) { list.Add(String.Empty); list.Add(String.Format("*** Page {0} *** {1}", i, (i == this.header.rootPage) ? "[ROOT]" : "")); var keyPages = KeyPageRead(i); foreach (var kp in keyPages) { string line = String.Empty; if (kp.leftPage > 0) { line = String.Format(">>page {0}: '", kp.leftPage); } else if (kp.recNo > 0) { line = String.Format("{0,5} rec: '", kp.recNo); } line += _dbfTable.parametersReadOnly.encoding.GetString(kp.key) + "'"; list.Add(line); } } File.WriteAllLines(@".\IndexPages.txt", list, _dbfTable.parametersReadOnly.encoding); #endif }
internal void AtachedToAnotherTable(DbfTable dbfTable, int recNo) { this._dbfTableClassID = (dbfTable == null) ? Guid.Empty : dbfTable.dbfTableClassID; this._recNo = recNo; // if (dbfTable != null) { if (!IsIdenticalColumnsDefinition(this._columns, dbfTable._columns)) { throw ExceptionFactory.CreateArgumentException("dbfTable", "DbfRow.AtachedToAnotherTable/this.columns and dbfTable.columns aren't identical !"); } } // foreach (var item in memoCache) { item.modified = ((item.data != null) && (item.data.Length > 0)); (item.column as Column).SetNull(_buffer); } }
public T Get <T>() where T : class, new() // new from 1.3 version { return(DbfTable.Get <T>(row_)); }