예제 #1
0
        internal const int RESERVED_INDEX         = 12; // 12-31


        /**
         * Constructs a DBFHeader, read the data from file <br>
         * You need to supply an open file handle to read from
         * @param ff open file handle for read access
         */
        internal DBFHeader(java.io.RandomAccessFile ff) //throws tinySQLException
        {
            try
            {
                ff.seek(FLAG_INDEX);
                file_type = Utils.fixByte(ff.readByte());

                // get the last update date
                file_update_year  = Utils.fixByte(ff.readByte());
                file_update_month = Utils.fixByte(ff.readByte());
                file_update_day   = Utils.fixByte(ff.readByte());

                // a byte array to hold little-endian long data
                //
                byte[] b = new byte[4];

                // read that baby in...
                //
                ff.readFully(b);

                // convert the byte array into a long (really a double)
                // 4-7 number of records
                numRecords = (int)Utils.vax_to_long(b);

                // a byte array to hold little-endian short data
                //
                b = new byte[2];

                // get the data position (where it starts in the file)
                // 8-9 Length of header
                ff.readFully(b);
                headerLength = Utils.vax_to_short(b);

                // find out the length of the data portion
                // 10-11 Length of Record
                ff.readFully(b);
                recordLength = Utils.vax_to_short(b);

                // calculate the number of fields
                //
                numFields = (int)(headerLength - 33) / 32;

                // skip the next 20 bytes - looks like this is not needed...
                //ff.skipBytes(20);
                // 12-31 reserved

                Utils.log("HEADER=" + this.toString());
            }
            catch (Exception e)
            {
                throw new TinySQLException(e.getMessage());
            }
        }
예제 #2
0
        /**
         * Reading a column definition from file<br>
         * @param ff file handle (correctly positioned)
         * @param iCol index starts with 1
         * @param locn offset to the current column
         * @return struct with column info
         */
        internal static TsColumn readColdef(java.io.RandomAccessFile ff, String tableName, int iCol, int locn) //throws tinySQLException
        {
            try
            {
                // seek the position of the field definition data.
                // This information appears after the first 32 byte
                // table information, and lives in 32 byte chunks.
                //
                ff.seek((iCol - 1) * 32 + 32);

                // get the column name into a byte array
                //
                byte[] b = new byte[11];
                ff.readFully(b);

                // convert the byte array to a String
                // Seek first 0x00 occurence and strip array after that
                //
                // some C-implementations do not set the remaining bytes
                // after the name to 0x00, so we have to correct this.
                //bool clear = false;
                int i = 0;
                while ((i < 11) && (b[i] != 0))
                {
                    i++;
                }
                while (i < 11)
                {
                    b[i] = 0;
                    i++;
                }
                String colName = (new java.lang.StringJ(b, Utils.encode)).trim();
                // read in the column type which follows the 11 byte column name
                //
                byte[] c = new byte[1];
                c[0] = ff.readByte();
                String ftyp = new java.lang.StringJ(c, Utils.encode);

                // skip four bytes
                //
                ff.skipBytes(4);

                // get field length and precision which are in the two bytes following
                // the column type.
                //
                short flen = Utils.fixByte(ff.readByte()); // 16
                short fdec = Utils.fixByte(ff.readByte()); // 17
                if (ftyp.equals("N") & fdec == 0)
                {
                    ftyp = "I";
                }

                // bytes 18 - 31 are reserved

                // create a new tsColumn object and assign it the
                // attributes of the current field
                //
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.outJ.println("Try and create tsColumn for " + colName);
                }
                TsColumn column = new TsColumn(colName);

                /*
                 *    The column type is now given as java.sql.Types constant
                 */
                column.type          = typeToSQLType(ftyp);
                column.size          = flen;
                column.decimalPlaces = fdec;
                column.position      = locn + 1; // set the field position to the current
                column.tableName     = tableName;
                return(column);
            }
            catch (Exception e)
            {
                throw new TinySQLException(e.getMessage());
            }
        }