Beispiel #1
0
        internal void Read(BinaryReader dataInput)
        {
            _signature       = dataInput.ReadByte();        /* 0 */
            _year            = dataInput.ReadByte();        /* 1 */
            _month           = dataInput.ReadByte();        /* 2 */
            _day             = dataInput.ReadByte();        /* 3 */
            _numberOfRecords = dataInput.ReadInt32();       /* 4-7 */

            _headerLength = dataInput.ReadInt16();          /* 8-9 */
            _recordLength = dataInput.ReadInt16();          /* 10-11 */

            _reserv1 = dataInput.ReadInt16();               /* 12-13 */
            _incompleteTransaction = dataInput.ReadByte();  /* 14 */
            _encryptionFlag        = dataInput.ReadByte();  /* 15 */
            _freeRecordThread      = dataInput.ReadInt32(); /* 16-19 */
            _reserv2        = dataInput.ReadInt32();        /* 20-23 */
            _reserv3        = dataInput.ReadInt32();        /* 24-27 */
            _mdxFlag        = dataInput.ReadByte();         /* 28 */
            _languageDriver = dataInput.ReadByte();         /* 29 */
            reserv4         = dataInput.ReadInt16();        /* 30-31 */


            List <DBFField> v_fields = new List <DBFField>();

            DBFField field = DBFField.CreateField(dataInput); /* 32 each */

            while (field != null)
            {
                v_fields.Add(field);
                field = DBFField.CreateField(dataInput);
            }

            _fieldArray = v_fields.ToArray();
            //System.out.println( "Number of fields: " + _fieldArray.length);
        }
Beispiel #2
0
        /**
         * Creates a DBFField object from the data read from the given DataInputStream.
         *
         * The data in the DataInputStream object is supposed to be organised correctly
         * and the stream "pointer" is supposed to be positioned properly.
         *
         * @param in DataInputStream
         * @return Returns the created DBFField object.
         * @throws IOException If any stream reading problems occures.
         */

        static internal DBFField CreateField(BinaryReader aReader)
        {
            DBFField field = new DBFField();

            if (field.Read(aReader))
            {
                return(field);
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        public void checkAnnoymous()
        {
            var fieldLength = 2400;
            string writtenValue;
            using (
                Stream fos =
                    File.Open(TestSelectPath,
                              FileMode.OpenOrCreate,
                              FileAccess.ReadWrite))
            {
                var writer = new DBFWriter
                {
                    DataMemoLoc = Path.ChangeExtension(TestSelectPath, "DBT")
                };
                var field = new DBFField("F1", NativeDbType.Memo);
                var field2 = new DBFField("F2", NativeDbType.Numeric, 10);
                var field3 = new DBFField("F3", NativeDbType.Char, 10);
                writer.Fields = new[] { field, field2, field3 };

                writtenValue = "alpha";
                writer.AddRecord(new MemoValue(GetCharacters(fieldLength)), 10, writtenValue);
                writer.Write(fos);
            }
            using (
                Stream fis =
                    File.Open(TestSelectPath,
                              FileMode.OpenOrCreate,
                              FileAccess.ReadWrite))
            {
                var reader = new DBFReader(fis)
                {
                    DataMemoLoc = Path.ChangeExtension(TestSelectPath, "DBT")
                };

                var readValues = reader.AllRecords(new {F2 = default(decimal), F3 = default(string)});

                Assert.That(readValues.First().F3, StartsWith(writtenValue), "Written Value not equaling Read");
            }
        }
Beispiel #4
0
        public void checkDataType_M()
        {
            var fieldLength = 2400;
            MemoValue writtenValue;
            using (
                Stream fos =
                    File.Open(TestMemoPath,
                              FileMode.OpenOrCreate,
                              FileAccess.ReadWrite))
            {
                var writer = new DBFWriter
                                 {
                                     DataMemoLoc = Path.ChangeExtension(TestMemoPath, "DBT")
                                 };
                var field = new DBFField("F1", NativeDbType.Memo);
                writer.Fields = new[] { field };

                writtenValue = new MemoValue(GetCharacters(fieldLength));
                writer.AddRecord(writtenValue);
                writer.Write(fos);
            }
            using (
                Stream fis =
                    File.Open(TestMemoPath,
                              FileMode.OpenOrCreate,
                              FileAccess.ReadWrite))
            {
                var reader = new DBFReader(fis)
                {
                    DataMemoLoc = Path.ChangeExtension(TestMemoPath, "DBT")
                };
                var readValues = reader.NextRecord();

                Assert.That(readValues[0], EqualTo(writtenValue), "Written Value not equaling Read");
            }
        }
Beispiel #5
0
        public void checkSelectDynamic()
        {
            var fieldLength = 2400;
            string writtenValue;
            string writtenMemo;
            using (
                Stream fos =
                    File.Open(TestSelectPath,
                              FileMode.OpenOrCreate,
                              FileAccess.ReadWrite))
            {
                var writer = new DBFWriter
                {
                    DataMemoLoc = Path.ChangeExtension(TestSelectPath, "DBT")
                };
                var field = new DBFField("F1", NativeDbType.Memo);
                var field2 = new DBFField("F2", NativeDbType.Numeric, 10);
                var field3 = new DBFField("F3", NativeDbType.Char, 10);
                writer.Fields = new[] { field, field2, field3 };

                writtenValue = "alpha";
                writtenMemo = GetCharacters(fieldLength);
                writer.AddRecord(new MemoValue(writtenMemo), 10, writtenValue);
                writer.Write(fos);
            }
            using (
                Stream fis =
                    File.Open(TestSelectPath,
                              FileMode.OpenOrCreate,
                              FileAccess.ReadWrite))
            {
                var reader = new DBFReader(fis)
                {
                    DataMemoLoc = Path.ChangeExtension(TestSelectPath, "DBT")
                };
                reader.SetSelectFields("F1","F3");
                var readValues = reader.DynamicAllRecords().First();

                Assert.That(readValues.F1.ToString(), EqualTo(writtenMemo), "Written Value not equaling Read");
                Assert.That(readValues.F3, EqualTo(writtenValue), "Written Value not equaling Read");
            }
        }
Beispiel #6
0
 public void WriteSample()
 {
     var field = new DBFField {Name = "F1", DataType = NativeDbType.Numeric};
     var writer = new DBFWriter {Fields = new[] {field}};
     writer.AddRecord(3);
     using (
         Stream fos =
             File.Open(TestPath,
                       FileMode.OpenOrCreate,
                       FileAccess.ReadWrite))
     {
         writer.Write(fos);
     }
 }
Beispiel #7
0
        public void checkRAFwriting()
        {
            println("Writing in RAF mode ... ");

            if (File.Exists(TestRAFPath))
            {
                File.Delete(TestRAFPath);
            }
            using (var writer = new DBFWriter(TestRAFPath))
            {
                var fields = new DBFField[2];

                fields[0] = new DBFField("F1", NativeDbType.Char, 10);

                fields[1] = new DBFField("F2", NativeDbType.Numeric, 2);

                writer.Fields = fields;

                writer.WriteRecord("Red", 10);
                writer.WriteRecord("Blue", 20);
            }

            println("done.");

            println("Appending to this file");

            using (var writer = new DBFWriter(TestRAFPath))
            {
                writer.WriteRecord("Green", 33);

                writer.WriteRecord("Yellow", 44);
            }
            println("done.");
        }
Beispiel #8
0
        public void checkLongCharLengthWithClipper()
        {
            var fieldLength = 750;
            string writtenValue;
            using (
                Stream fos =
                    File.Open(TestClipLongPath,
                              FileMode.OpenOrCreate,
                              FileAccess.ReadWrite))
            {
                var writer = new DBFWriter();
                var field = new DBFField("F1", NativeDbType.Char, fieldLength);
                writer.Fields = new[] { field };

                writtenValue = GetCharacters(fieldLength);
                writer.AddRecord(writtenValue);
                writer.Write(fos);
            }
            using (
                Stream fis =
                    File.Open(TestClipLongPath,
                              FileMode.OpenOrCreate,
                              FileAccess.ReadWrite))
            {
                var reader = new DBFReader(fis);
                Assert.That(reader.Fields.First().FieldLength, EqualTo(fieldLength));
                var readValues = reader.NextRecord();

                Assert.That(readValues[0], EqualTo(writtenValue), "Written Value not equaling Read");
            }
        }
Beispiel #9
0
        public void checkDynamicProxyWhere()
        {
            var fieldLength = 2400;
            string writtenValue;
            using (
                Stream fos =
                    File.Open(TestSelectPath,
                              FileMode.OpenOrCreate,
                              FileAccess.ReadWrite))
            {
                var writer = new DBFWriter
                {
                    DataMemoLoc = Path.ChangeExtension(TestSelectPath, "DBT")
                };
                var field = new DBFField("F1", NativeDbType.Memo);
                var field2 = new DBFField("F2", NativeDbType.Numeric, 10);
                var field3 = new DBFField("F3", NativeDbType.Char, 10);
                writer.Fields = new[] { field, field2, field3 };

                writtenValue = "alpha";
                writer.AddRecord(new MemoValue(GetCharacters(fieldLength)), 10, writtenValue);

                writer.AddRecord(new MemoValue(GetCharacters(fieldLength)), 12, "beta");

                writer.Write(fos);
            }

                using(var reader = new DBFReader(TestSelectPath){
                    DataMemoLoc = Path.ChangeExtension(TestSelectPath, "DBT")})
                {

                    var readValues = reader.DynamicAllRecords();

                    Assert.That(Equals(readValues.Count(), 2), "All Records not matching");

                }

                using (var reader = new DBFReader(TestSelectPath)
                {
                    DataMemoLoc = Path.ChangeExtension(TestSelectPath, "DBT")})
                {

                    var readValues = reader.DynamicAllRecords(whereColumn: "F2", whereColumnEquals: 10);

                    Assert.That(Equals(readValues.Count(), 1), "All Records not matching");

                }

                using (var reader = new DBFReader(TestSelectPath)
                {
                    DataMemoLoc = Path.ChangeExtension(TestSelectPath, "DBT")})
                {

                    var readValues = reader.DynamicAllRecords(whereColumn: "F2", whereColumnEquals: 12);

                    Assert.That(Equals(readValues.Count(), 1), "All Records not matching");

                }
                using (var reader = new DBFReader(TestSelectPath)
                {
                    DataMemoLoc = Path.ChangeExtension(TestSelectPath, "DBT")})
                {

                    var readValues = reader.DynamicAllRecords(whereColumn: "F2", whereColumnEquals: 13);

                    Assert.That(Equals(readValues.Count(), 0), "All Records not matching");

                }
        }
Beispiel #10
0
        public void checkDataType_N()
        {
            Decimal writtenValue;
            using (
                Stream fos =
                    File.Open(TestPath,
                              FileMode.OpenOrCreate,
                              FileAccess.ReadWrite))
            {
                var writer = new DBFWriter();
                var field = new DBFField("F1", NativeDbType.Numeric, 15, 0);
                writer.Fields = new[] { field };

                writtenValue = 123456789012345L;
                writer.AddRecord(writtenValue);
                writer.Write(fos);
            }
            using (
                Stream fis =
                    File.Open(TestPath,
                              FileMode.OpenOrCreate,
                              FileAccess.ReadWrite))
            {
                var reader = new DBFReader(fis);

                var readValues = reader.NextRecord();

                Assert.That(readValues[0], EqualTo(writtenValue),"Written Value Equals Read");
            }
        }
Beispiel #11
0
        /**
         Creates a DBFField object from the data read from the given DataInputStream.

         The data in the DataInputStream object is supposed to be organised correctly
         and the stream "pointer" is supposed to be positioned properly.

         @param in DataInputStream
         @return Returns the created DBFField object.
         @throws IOException If any stream reading problems occures.
         */
        internal static DBFField CreateField(BinaryReader aReader)
        {
            DBFField field = new DBFField();
            if (field.Read(aReader))
            {
                return field;
            }
            else
            {
                return null;
            }
        }