Esempio n. 1
0
        /**
         *
         * Update a single column.
         *
         * @param column the column name
         * @param value the String value with which update the column
         * @see tinySQLTable#UpdateCol
         *
         */
        public override void UpdateCol(String column, String value)
        {//throws tinySQLException {
            try
            {
                // read the column info
                //
                String[] info = (String[])column_info.get(column);

                // retrieve datatype, size, and position within row
                //
                String datatype = info[COLUMN_TYPE];
                long   size     = java.lang.Long.parseLong(info[COLUMN_SIZE]);
                long   pos      = java.lang.Long.parseLong(info[COLUMN_POS]);

                // position the file pointer at the column
                // offset.
                //
                ftbl.seek(ftbl.getFilePointer() + pos);
                String writeval;

                if (value.length() > (int)size)
                {
                    // truncate the value, if it exceeds the width
                    // of the column
                    //
                    writeval = value.substring(0, (int)size);
                }
                else
                {
                    // add some padding to the end of the string
                    //
                    java.lang.StringBuffer pad = new java.lang.StringBuffer();
                    for (int p = 0; p < ((int)size) - value.length(); p++)
                    {
                        pad.append(" ");
                    }
                    writeval = value + pad.toString();
                }

                // write out the column
                //
                ftbl.writeBytes(writeval);

                // rewind the file pointer
                //
                ftbl.seek(ftbl.getFilePointer() - (pos + (long)writeval.length()));
            }
            catch (Exception e)
            {
                java.lang.SystemJ.err.println(e.toString());//      e.printStackTrace();
                throw new TinySQLException(e.getMessage());
            }
        }