Exemple #1
0
        public Font(String name, int style, int size)
        {
            this.name = (name != null) ? name : "Default"; //$NON-NLS-1$
            this.size = (size >= 0) ? size : 0;
            this.style = (style & ~0x03) == 0 ? style : Font.PLAIN;
            this.pointSize = this.size;

            fRequestedAttributes = new java.util.Hashtable<java.text.AttributedCharacterIteratorNS.Attribute, Object>();//5);

            fRequestedAttributes.put(java.awt.font.TextAttribute.TRANSFORM, IDENTITY_TRANSFORM);

            this.transformed = false;

            fRequestedAttributes.put(java.awt.font.TextAttribute.FAMILY, this.name);
            fRequestedAttributes.put(java.awt.font.TextAttribute.SIZE, new java.lang.Float(this.size));

            if ((this.style & Font.BOLD) != 0)
            {
                fRequestedAttributes.put(java.awt.font.TextAttribute.WEIGHT,
                        java.awt.font.TextAttribute.WEIGHT_BOLD);
            }
            else
            {
                fRequestedAttributes.put(java.awt.font.TextAttribute.WEIGHT,
                        java.awt.font.TextAttribute.WEIGHT_REGULAR);
            }
            if ((this.style & Font.ITALIC) != 0)
            {
                fRequestedAttributes.put(java.awt.font.TextAttribute.POSTURE,
                        java.awt.font.TextAttribute.POSTURE_OBLIQUE);
            }
            else
            {
                fRequestedAttributes.put(java.awt.font.TextAttribute.POSTURE,
                        java.awt.font.TextAttribute.POSTURE_REGULAR);
            }
        }
Exemple #2
0
        public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte charSet, bool isVertical)
        {
            if (family == null)
            {
                throw new ArgumentNullException("family");
            }

            _gUnit      = unit;
            _fontFamily = family;
            _charset    = charSet;

            java.util.Hashtable attribs = new java.util.Hashtable();
            attribs.put(TextAttribute.FAMILY, family.Name /*TODO: family doungrade possibility*/);
            //init defaults
            attribs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR);

            float newSize = emSize * Graphics.UnitConversion[(int)_gUnit];

            attribs.put(TextAttribute.SIZE, new java.lang.Float(newSize));

            DeriveStyle(attribs, style, false);

            _jFont = family.FamilyFont.deriveFont(attribs);
        }
Exemple #3
0
        /*
         * Support function for restartable queries. Continue to
         * read the query result. The current state is taken from
         * tsResultSet. Proceed until maxFetchSize has reached.
         */
        protected internal virtual void contSelectStatement(TsResultSet jrs)
        //throws TinySQLException
        {
            /*
             *    The table scan here is an iterative tree expansion, similar to
             *    the algorithm shown in the outline example in Chapter 5.
             */
            String       columnName, columnString, whereStatus, tableAndAlias;
            bool         addOK;
            int          i;
            int          level = jrs.getLevel();
            TinySQLTable jtbl;
            TsColumn     updateColumn;

            java.util.Hashtable <Object, Object> tables = jrs.getTableState();
            TinySQLWhere wc = jrs.getWhereClause();

            /*
             *    Create a hashtable to enumerate the tables to be scanned and initialize
             *    with the first table name.
             */
            java.util.Hashtable <Object, Object> tbl_list = new java.util.Hashtable <Object, Object>();
            java.util.Vector <Object>            t        = (java.util.Vector <Object>)tables.get("TABLE_SELECT_ORDER");
            String current = (String)t.elementAt(0);

            tbl_list.put(current, new java.lang.Integer(1));

            /*
             *    Create a row object; this is added to the ResultSet.
             */
            TsRow record = new TsRow();

            java.util.Vector <Object> resultSet = new java.util.Vector <Object>();

            /*
             *    Keep retrieving rows until we run out of rows to process.
             */
            while (level > 0)
            {
                bool levelFound = false;

                /*
                 *       Find an item within the tbl_list which has the same level as the
                 *       one we're on.
                 */
                java.util.Enumeration <Object> keys = tbl_list.keys();
                while (keys.hasMoreElements())
                {
                    /*
                     *          Get the next element in the "to be processed"
                     *          Hashtable, and find out its level, storing this
                     *          value in currLevel.
                     */
                    String hashkey   = (String)keys.nextElement();
                    int    currLevel = ((java.lang.Integer)tbl_list.get(hashkey)).intValue();

                    /*
                     *          As soon as an element is found whose level is equal to the
                     *          one currently being processed, grab it's primary key (the hashkey),
                     *          flag levelfound, and break!
                     */
                    if (currLevel == level)
                    {
                        current = hashkey; levelFound = true; break;
                    }
                }
                bool haveRecord = false; // did we get a record or not?

                /*
                 *       If a table was found at the current level, then we should
                 *       try to get another row from it.
                 */
                if (levelFound)
                {
                    /*
                     *          Get the current table
                     */
                    jtbl          = (TinySQLTable)tables.get(current);
                    tableAndAlias = jtbl.table + "->" + jtbl.tableAlias;
                    if (TinySQLGlobals.WHERE_DEBUG)
                    {
                        java.lang.SystemJ.outJ.println("Processing level " + level
                                                       + " table " + tableAndAlias + "\n");
                    }

                    /*
                     *          The following code is the start of setting up simple indexes
                     *          for tinySQL.  The concept involves creating a new tinySQLCondition
                     *          class, instances of which will be created by tinySQLWhere.  At least
                     *          initially only conditions that are equal to a constant will be
                     *          considered.  One of these conditions will be stored inside the
                     *          dbfFileTable object. Calls to NextRecord would then have to add
                     *          logic to check to see if an index exists.  The presence of a
                     *          complete index would be indicated by a counter that was equal
                     *          to the number of rows in the table.  In that case a single get
                     *          would deliver the record numbers required for the where condition.
                     *          The NextRecord function would return these record numbers in
                     *          sequence.  If the index did not exist then new values in the
                     *          index Hashtable would be created.  None of this code has been
                     *          developed or implemented, let alone tested.
                     *
                     *
                     *          if ( wc != (tinySQLWhere)null )
                     *             jtbl.setIndexCondition(wc.getIndexCondition(tableAndAlias));
                     */
                    if (performDebug)
                    {
                        java.lang.SystemJ.outJ.println("Selecting records from "
                                                       + jtbl.table);
                    }

                    /*
                     *          Skip to the next undeleted record; at some point,
                     *          this will run out of records, and found will be false.
                     */
                    bool found = false;
                    while (jtbl.NextRecord())
                    {
                        /*
                         *             Clear the column values for this table before starting
                         *             to process the next row.
                         */
                        for (i = 0; i < jrs.numcols(); i++)
                        {
                            updateColumn = jrs.columnAtIndex(i, true);
                            updateColumn.clear(tableAndAlias);
                        }
                        if (wc != (TinySQLWhere)null)
                        {
                            wc.clearValues(tableAndAlias);
                        }
                        if (!jtbl.isDeleted())
                        {
                            /*
                             *                Evaluate the where clause for each column in the table.  If
                             *                it is false, skip to the next row.  Otherwise, add the
                             *                column value to the output record.
                             */
                            java.util.Enumeration <Object> cols = jtbl.column_info.keys();
                            found       = true;
                            whereStatus = "TRUE";
                            while (cols.hasMoreElements())
                            {
                                columnName = tableAndAlias + "."
                                             + (String)cols.nextElement();
                                columnString = jtbl.GetCol(columnName);
                                if (wc != (TinySQLWhere)null)
                                {
                                    whereStatus = wc.evaluate(columnName, columnString);
                                    if (whereStatus.equals("FALSE"))
                                    {
                                        /*
                                         *                         This column value caused the where clause to
                                         *                         be FALSE.  Go to the next row in the table.
                                         */
                                        found = false;
                                        break;
                                    }
                                }

                                /*
                                 *                   Update the ResultSet tsColumn values
                                 */
                                jrs.updateColumns(columnName, columnString);
                            }

                            /*
                             *                If no where condition has evaluated to false then this
                             *                record is a candidate for output.  Break to the next table
                             *                in this case for further WHERE processing.
                             */
                            if (found)
                            {
                                break;
                            }
                        }
                    }
                    if (found)
                    {
                        if (TinySQLGlobals.DEBUG)
                        {
                            java.lang.SystemJ.outJ.println("Build candidate record.");
                        }
                        for (i = 0; i < jrs.numcols(); i++)
                        {
                            updateColumn = jrs.columnAtIndex(i, true);

                            /*
                             *                Evaluate all functions before adding the
                             *                column to the output record.
                             */
                            updateColumn.updateFunctions();
                            columnString = updateColumn.getString();
                            if (updateColumn.isNotNull())
                            {
                                record.put(updateColumn.name, columnString);
                            }
                            else
                            {
                                record.remove(updateColumn.name);
                            }
                        }
                        if (performDebug)
                        {
                            java.lang.SystemJ.outJ.println("Record is " + record.toString());
                        }

                        /*
                         *             If the table we are processing is not the last in
                         *             the list, then we should increment level and loop to the top.
                         */
                        if (level < t.size())
                        {
                            /*
                             *                Increment level
                             */
                            level++;

                            /*
                             *                Add the next table in the list of tables to
                             *                the tbl_list, the Hashtable of "to be processed" tables.
                             */
                            String next_tbl = (String)t.elementAt(level - 1);
                            tbl_list.put(next_tbl, new java.lang.Integer(level));
                        }
                        else
                        {
                            /*
                             *                If the table that was just processed is the last in
                             *                the list, then we have drilled down to the bottom;
                             *                all columns have values, and we can add it to the
                             *                result set. The next time through, the program
                             *                will try to read another row at this level; if it's
                             *                found, only columns for the table being read will
                             *                be overwritten in the tsRow.
                             *
                             *                Columns for the other table will be left alone, and
                             *                another row will be added to the result set. Here
                             *                is the essence of the Cartesian Product which is
                             *                being built here.
                             */
                            haveRecord = true;
                        }
                    }
                    else
                    {
                        /*
                         *             We didn't find any more records at this level.
                         *             Reset the record pointer to the top of the table,
                         *             and decrement level. We have hit end of file here.
                         */
                        if (wc != (TinySQLWhere)null)
                        {
                            wc.clearValues(tableAndAlias);
                        }
                        level--;
                        jtbl.GoTop();
                    }
                }
                else
                {
                    /*
                     *          No tables were found at this level; back up a level
                     *          and see if there's any up there.
                     */
                    level--;
                }

                /*
                 *       If we got a record, then add it to the result set.
                 */
                if (haveRecord)
                {
                    /*
                     *          If group functions are involved, add records only after a break,
                     *          which is defined as a change in all of the group columns.
                     *          Otherwise, update the current record.
                     */
                    if (jrs.isGrouped())
                    {
                        if (groupBreak)
                        {
                            addOK = jrs.addRow((TsRow)record.clone());
                            if (addOK == false)
                            {
                                jrs.setLevel(level);
                                return;
                            }
                            groupBreak = false;
                        }
                        else
                        {
                            jrs.updateRow((TsRow)record.clone());
                        }
                    }
                    else
                    {
                        /*
                         *             No group functions are involved.  Just add the record.
                         */
                        addOK = jrs.addRow((TsRow)record.clone());
                        if (addOK == false)
                        {
                            jrs.setLevel(level);
                            return;
                        }
                    }
                }
            }

            /*
             *    Close all the tables
             */
            for (i = 0; i < t.size(); i++)
            {
                jtbl = (TinySQLTable)tables.get((String)t.elementAt(i));
                jtbl.close();
            }

            /*
             *    return a result set
             */
            jrs.setLevel(0);
        }
Exemple #4
0
        public TinySQLParser(java.io.InputStream sqlInput, TinySQL inputEngine)
        //throws TinySQLException
        {
            java.io.StreamTokenizer st;
            FieldTokenizer          ft;

            java.io.Reader r;
            String         nextToken, upperField, nextField, keyWord = (String)null;

            java.lang.StringBuffer cmdBuffer, inputSQLBuffer;
            int lastIndex, keyIndex;

            r               = new java.io.BufferedReader(new java.io.InputStreamReader(sqlInput));
            dbEngine        = inputEngine;
            actionList      = new java.util.Vector <Object>();
            columnList      = new java.util.Vector <Object>();
            columns         = new java.util.Vector <Object>();
            columnAliasList = new java.util.Vector <Object>();
            contextList     = new java.util.Vector <Object>();
            valueList       = new java.util.Vector <Object>();
            tableName       = (String)null;
            whereClause     = (TinySQLWhere)null;

/*
 *    The tableList is a list of table names, in the optimal order
 *    in which they should be scanned for the SELECT phrase.
 *    The java.util.Hashtable<Object,Object> tables contains table objects keyed by table
 *    alias and name.
 */
            tableList = new java.util.Vector <Object>();
            tables    = new java.util.Hashtable <Object, Object>();
            tables.put("TABLE_SELECT_ORDER", tableList);
            try
            {
                st = new java.io.StreamTokenizer(r);
                st.eolIsSignificant(false);
                st.wordChars('\'', '}');
                st.wordChars('?', '?');
                st.wordChars('"', '.');
                st.ordinaryChars('0', '9');
                st.wordChars('0', '9');
                cmdBuffer      = new java.lang.StringBuffer();
                inputSQLBuffer = new java.lang.StringBuffer();
                while (st.nextToken() != java.io.StreamTokenizer.TT_EOF)
                {
                    if (st.ttype == java.io.StreamTokenizer.TT_WORD)
                    {
                        nextToken = st.sval.trim();
                    }
                    else
                    {
                        continue;
                    }
                    if (inputSQLBuffer.length() > 0)
                    {
                        inputSQLBuffer.append(" ");
                    }
                    inputSQLBuffer.append(nextToken);
                }
                ft = new FieldTokenizer(inputSQLBuffer.toString(), ' ', false);
                while (ft.hasMoreFields())
                {
                    nextField  = ft.nextField();
                    upperField = nextField.toUpperCase();
                    if (statementType == (String)null)
                    {
                        statementType = upperField;
                        lastIndex     = getKeywordIndex(statementType, statementType);
                        if (lastIndex != 0)
                        {
                            throwException(9);
                        }
                        keyWord = statementType;
                    }
                    else
                    {
                        keyIndex = getKeywordIndex(statementType, upperField);
                        if (keyIndex < 0)
                        {
                            if (cmdBuffer.length() > 0)
                            {
                                cmdBuffer.append(" ");
                            }
                            cmdBuffer.append(nextField);
                        }
                        else
                        {
                            setPhrase(keyWord, cmdBuffer.toString());
                            cmdBuffer = new java.lang.StringBuffer();
                            keyWord   = upperField;
                            if (TinySQLGlobals.PARSER_DEBUG)
                            {
                                java.lang.SystemJ.outJ.println("Found keyword " + keyWord);
                            }
                        }
                    }
                }
                if (keyWord != (String)null)
                {
                    setPhrase(keyWord, cmdBuffer.toString());
                }
                addAction();
                if (TinySQLGlobals.PARSER_DEBUG)
                {
                    java.lang.SystemJ.outJ.println("SQL:" + inputSQLBuffer.toString());
                }
            } catch (Exception ex) {
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.outJ.println(ex.StackTrace);                 //ex.printStackTrace(java.lang.SystemJ.outJ);
                }
                throw new TinySQLException(ex.getMessage());
            }
        }
		static internal java.util.Map DeriveStyle(java.util.Map attribs, FontStyle style, bool createNew) {
			java.util.Map newAttribs;
			if (createNew) {
				newAttribs = new java.util.Hashtable( attribs.size() );
				java.util.Iterator it = attribs.keySet().iterator();
				while (it.hasNext ()) {
					object key = it.next ();
					object value = attribs.get (key);
					if (value != null)
						newAttribs.put (key, value);
				}
			}
			else
				newAttribs = attribs;

			//Bold
			if((style & FontStyle.Bold) == FontStyle.Bold)
				newAttribs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
			else
				newAttribs.remove(TextAttribute.WEIGHT);

			//Italic
			if((style & FontStyle.Italic) == FontStyle.Italic)
				newAttribs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
			else
				newAttribs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR);

			//Underline
			if((style & FontStyle.Underline) == FontStyle.Underline)
				newAttribs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
			else
				newAttribs.remove(TextAttribute.UNDERLINE);

			//Strikeout
			if((style & FontStyle.Strikeout) == FontStyle.Strikeout)
				newAttribs.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
			else
				newAttribs.remove(TextAttribute.STRIKETHROUGH);

			return newAttribs;
		}
		public Font(FontFamily family, float emSize, FontStyle style, GraphicsUnit unit, byte charSet, bool isVertical) {
			if (family == null)
				throw new ArgumentNullException("family");

			_gUnit = unit;
			_fontFamily = family;
			_charset = charSet;

			java.util.Hashtable attribs = new java.util.Hashtable();
			attribs.put(TextAttribute.FAMILY, family.Name/*TODO: family doungrade possibility*/);
			//init defaults
			attribs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR);

			float newSize = emSize * Graphics.UnitConversion[ (int)_gUnit ];
			attribs.put(TextAttribute.SIZE, new java.lang.Float(newSize));

			DeriveStyle(attribs, style, false);

			_jFont = family.FamilyFont.deriveFont(attribs);
		}
Exemple #7
0
        /**
         * Gets a description of table columns available in
         * the specified catalog.
         *
         * <P>Only column descriptions matching the catalog, schema, table
         * and column name criteria are returned.  They are ordered by
         * TABLE_SCHEM, TABLE_NAME and ORDINAL_POSITION.
         *
         * <P>Each column description has the following columns:
         *  <OL>
         *  <LI><B>TABLE_CAT</B> String => table catalog (may be null)
         *  <LI><B>TABLE_SCHEM</B> String => table schema (may be null)sRow record = new TsRow();
         *
         *  <LI><B>TABLE_NAME</B> String => table name
         *  <LI><B>COLUMN_NAME</B> String => column name
         *  <LI><B>DATA_TYPE</B> short => SQL type from java.sql.Types
         *  <LI><B>TYPE_NAME</B> String => Data source dependent type name,
         *  for a UDT the type name is fully qualified
         *  <LI><B>COLUMN_SIZE</B> int => column size.  For char or date
         *      types this is the maximum number of characters, for numeric or
         *      decimal types this is precision.
         *  <LI><B>BUFFER_LENGTH</B> is not used.
         *  <LI><B>DECIMAL_DIGITS</B> int => the number of fractional digits
         *  <LI><B>NUM_PREC_RADIX</B> int => Radix (typically either 10 or 2)
         *  <LI><B>NULLABLE</B> int => is NULL allowed?
         *      <UL>
         *      <LI> columnNoNulls - might not allow NULL values
         *      <LI> columnNullable - definitely allows NULL values
         *      <LI> columnNullableUnknown - nullability unknown
         *      </UL>
         *  <LI><B>REMARKS</B> String => comment describing column (may be null)
         *  <LI><B>COLUMN_DEF</B> String => default value (may be null)
         *  <LI><B>SQL_DATA_TYPE</B> int => unused
         *  <LI><B>SQL_DATETIME_SUB</B> int => unused
         *  <LI><B>CHAR_OCTET_LENGTH</B> int => for char types the
         *       maximum number of bytes in the column
         *  <LI><B>ORDINAL_POSITION</B> int => index of column in table
         *      (starting at 1)
         *  <LI><B>IS_NULLABLE</B> String => "NO" means column definitely
         *      does not allow NULL values; "YES" means the column might
         *      allow NULL values.  An empty string means nobody knows.
         *  </OL>
         *
         * @param catalog a catalog name; "" retrieves those without a
         * catalog; null means drop catalog name from the selection criteria
         * @param schemaPattern a schema name pattern; "" retrieves those
         * without a schema
         * @param tableNamePattern a table name pattern
         * @param columnNamePattern a column name pattern
         * @return ResultSet - each row is a column description
         * @exception SQLException if a database access error occurs
         * @see #getSearchStringEscape
         */
        public override java.sql.ResultSet getColumns(String catalog, String schemaPattern,
                                                      String tableNamePattern, String columnNamePattern)
        {
            int    i;
            String columnNameKey;

            try
            {
                String dataDir = getDataDir();

                Utils.log("Entering getColumns(tableNamePattern='" + tableNamePattern + "')");

                if (dataDir == null)
                {
                    return(null);
                }

                java.sql.ResultSet tableRs = getTables(catalog, schemaPattern, tableNamePattern, null);

                TsResultSet jrs = new TsResultSet();

                TsColumn jsc = new TsColumn("TABLE_CAT");
                jsc.type = java.sql.Types.CHAR;
                jsc.size = 9;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("TABLE_SCHEM");
                jsc.type = java.sql.Types.CHAR;
                jsc.size = 11;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("TABLE_NAME");
                jsc.type = java.sql.Types.CHAR;
                jsc.size = 10;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("COLUMN_NAME");
                jsc.type = java.sql.Types.CHAR;
                jsc.size = 11;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("DATA_TYPE");
                jsc.type = java.sql.Types.INTEGER;
                jsc.size = 6;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("TYPE_NAME");
                jsc.type = java.sql.Types.CHAR;
                jsc.size = 9;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("COLUMN_SIZE");
                jsc.type = java.sql.Types.INTEGER;
                jsc.size = 8;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("BUFFER_LENGTH");
                jsc.type = java.sql.Types.INTEGER;
                jsc.size = 8;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("DECIMAL_DIGITS");
                jsc.type = java.sql.Types.INTEGER;
                jsc.size = 8;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("NUM_PREC_RADIX");
                jsc.type = java.sql.Types.INTEGER;
                jsc.size = 8;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("NULLABLE");
                jsc.type = java.sql.Types.INTEGER;
                jsc.size = 8;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("REMARKS");
                jsc.type = java.sql.Types.CHAR;
                jsc.size = 128;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("COLUMN_DEF");
                jsc.type = java.sql.Types.CHAR;
                jsc.size = 128;
                jrs.addColumn(jsc);

                jsc      = new TsColumn("SQL_DATA_TYPE");
                jsc.type = java.sql.Types.INTEGER;
                jsc.size = 128;
                jrs.addColumn(jsc);

                //      Several parameters missing.

                jsc      = new TsColumn("IS_NULLABLE");
                jsc.type = java.sql.Types.CHAR;
                jsc.size = 3;
                jrs.addColumn(jsc);

                while (tableRs.next())
                { // process each DBF file and extract column info ...
                    String tableName = tableRs.getString("TABLE_NAME");

                    DBFFileTable tbl;
                    try
                    {
                        tbl = new DBFFileTable(dataDir, tableName);
                    }
                    catch (Exception)
                    {
                        continue; // ignore buggy and empty (zero byte size) DBF files
                    }

                    Utils.log("Accessing column info for table " + tableName);

                    java.util.Hashtable <Object, Object> column_info = tbl.column_info;
                    for (i = 0; i < tbl.columnNameKeys.size(); i++)
                    {
                        columnNameKey = (String)tbl.columnNameKeys.elementAt(i);
                        TsColumn tsc = (TsColumn)column_info.get(columnNameKey);
                        // process each column of the current table ...
                        TsRow record = new TsRow();
                        record.put("TABLE_CAT", "");
                        record.put("TABLE_SCHEM", "");
                        record.put("TABLE_NAME", tableName);
                        record.put("COLUMN_NAME", TinySQLGlobals.getLongName(tsc.name));
                        record.put("DATA_TYPE", new java.lang.Integer(tsc.type).toString());
                        record.put("TYPE_NAME", DBFFile.typeToLiteral(tsc.type).toString());
                        record.put("COLUMN_SIZE", new java.lang.Integer(tsc.size).toString());
                        record.put("DECIMAL_DIGITS", new java.lang.Integer(tsc.decimalPlaces).toString());
                        int nullable = columnNoNulls;
                        if (tsc.notNull == true)
                        {
                            nullable = columnNullable;
                        }
                        record.put("NULLABLE", new java.lang.Integer(nullable).toString());
                        record.put("REMARKS", "noRemarks");
                        String defaultVal = tsc.defaultVal;
                        if (defaultVal == null)
                        {
                            defaultVal = "";
                        }
                        record.put("COLUMN_DEF", defaultVal);
                        String isNullable = "NO";
                        if (tsc.notNull == true)
                        {
                            isNullable = "YES";
                        }
                        record.put("IS_NULLABLE", isNullable);

                        /*
                         *          Suppress any sorting of the ResultSet.  Column Metadata should
                         *          be presented in the order the columns exist in the dBase header.
                         */

                        jrs.addRow(record, false);
                    }

                    tbl.close();
                    tbl = null;
                }

                return(new TinySQLResultSet(jrs, (TinySQLStatement)null));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemple #8
0
 public void testEmptyHashtableKeyEnumerator()
 {
     java.util.Hashtable <String, String> nameWert = new java.util.Hashtable <String, String>();
     NUnit.Framework.Assert.False(nameWert.keys().hasMoreElements());
 }
Exemple #9
0
        static internal java.util.Map DeriveStyle(java.util.Map attribs, FontStyle style, bool createNew)
        {
            java.util.Map newAttribs;
            if (createNew)
            {
                newAttribs = new java.util.Hashtable(attribs.size());
                java.util.Iterator it = attribs.keySet().iterator();
                while (it.hasNext())
                {
                    object key   = it.next();
                    object value = attribs.get(key);
                    if (value != null)
                    {
                        newAttribs.put(key, value);
                    }
                }
            }
            else
            {
                newAttribs = attribs;
            }

            //Bold
            if ((style & FontStyle.Bold) == FontStyle.Bold)
            {
                newAttribs.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
            }
            else
            {
                newAttribs.remove(TextAttribute.WEIGHT);
            }

            //Italic
            if ((style & FontStyle.Italic) == FontStyle.Italic)
            {
                newAttribs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
            }
            else
            {
                newAttribs.put(TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR);
            }

            //Underline
            if ((style & FontStyle.Underline) == FontStyle.Underline)
            {
                newAttribs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
            }
            else
            {
                newAttribs.remove(TextAttribute.UNDERLINE);
            }

            //Strikeout
            if ((style & FontStyle.Strikeout) == FontStyle.Strikeout)
            {
                newAttribs.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
            }
            else
            {
                newAttribs.remove(TextAttribute.STRIKETHROUGH);
            }

            return(newAttribs);
        }
Exemple #10
0
 /**
  * (Re)set the parent of this Namespace context.
  * The context must either have been freshly constructed,
  * or must have been cleared.
  *
  * @param context The parent Namespace context object.
  */
 internal void setParent(Context parent)
 {
     this.parent = parent;
     declarations = null;
     prefixTable = parent.prefixTable;
     uriTable = parent.uriTable;
     elementNameTable = parent.elementNameTable;
     attributeNameTable = parent.attributeNameTable;
     defaultNS = parent.defaultNS;
     declSeen = false;
     declsOK = true;
 }
        public static JmolCrystal Read(string path)
        {
            var crystal = new JmolCrystal();

            using (StreamReader sr = new StreamReader(path))
            {
                crystal.Cif = sr.ReadToEnd();
            }

            java.io.BufferedReader buffReader = new java.io.BufferedReader(new java.io.FileReader(path));

            java.util.Map parameters = new java.util.Hashtable();

            var ascr = org.jmol.adapter.smarter.SmarterJmolAdapter.staticGetAtomSetCollectionReader(path, null, buffReader, parameters);

            if (ascr is org.jmol.adapter.smarter.AtomSetCollectionReader)
            {
                var asc = org.jmol.adapter.smarter.SmarterJmolAdapter.staticGetAtomSetCollection((ascr as org.jmol.adapter.smarter.AtomSetCollectionReader)) as org.jmol.adapter.smarter.AtomSetCollection;

                if (asc != null)
                {
                    var auxInfo = new Dictionary <string, string>();

                    if (asc.atoms != null)
                    {
                        crystal.Atoms = asc.atoms.ToArray().Where(a => a != null).Select(a => new JmolAtom()
                        {
                            AtomName = a.atomName,
                            Symbol   = a.elementSymbol,
                            X        = a.x,
                            Y        = a.y,
                            Z        = a.z
                        }).ToList();
                    }

                    if (asc.bonds != null)
                    {
                        crystal.Bonds = asc.bonds.ToArray().Where(b => b != null).Select(b => new JmolBond()
                        {
                            AtomIndex1 = b.atomIndex1,
                            AtomIndex2 = b.atomIndex2
                        }).ToList();
                    }

                    for (var i = 0; i < asc.atomSetAuxiliaryInfo.Length; i++)
                    {
                        var info = asc.atomSetAuxiliaryInfo[i];
                        if (info != null)
                        {
                            var keys = info.keySet().toArray();

                            for (var i2 = 0; i2 < keys.Length; i2++)
                            {
                                var key = keys[i2];
                                var val = info.get(key);

                                if (val == null)
                                {
                                    continue;
                                }

                                if (key.Equals("chemicalName"))
                                {
                                    crystal.ChemicalName = val.ToString();
                                }
                                else if (key.Equals("formula"))
                                {
                                    crystal.ChemicalFormula = val.ToString();
                                }
                                else if (key.Equals("unitCellParams"))
                                {
                                    var array = val as Array;

                                    if (array.Length >= 6)
                                    {
                                        crystal.LengthA = Convert.ToDouble(array.GetValue(0));
                                        crystal.LengthB = Convert.ToDouble(array.GetValue(1));
                                        crystal.LengthC = Convert.ToDouble(array.GetValue(2));

                                        crystal.Alpha = Convert.ToDouble(array.GetValue(3));
                                        crystal.Beta  = Convert.ToDouble(array.GetValue(4));
                                        crystal.Gamma = Convert.ToDouble(array.GetValue(5));
                                    }
                                }
                                else if (val is java.lang.Integer || val is java.lang.Boolean || val is System.String)
                                {
                                    if (string.IsNullOrEmpty(val.ToString()) || val.ToString().Equals("null") || val.ToString().Equals("?"))
                                    {
                                        continue;
                                    }

                                    crystal.AuxInfo[key.ToString()] = val.ToString();
                                }
                            }
                        }
                    }
                }
            }

            return(crystal);
        }
Exemple #12
0
        // end methods implemented from tinySQLTable.java
        // the rest of this stuff is internal methods
        // for textFileTable
        //

        /*
         *
         * Reads in a table definition and populates the column_info
         * Hashtable
         *
         */
        void readColumnInfo()
        {//throws tinySQLException {
            try
            {
                column_info = new java.util.Hashtable <Object, Object>();

                // Open an FileInputStream to the .def (table
                // definition) file
                //
                java.io.FileInputStream fdef =
                    new java.io.FileInputStream(dataDir + "/" + table + ".def");

                // use a StreamTokenizer to break up the stream.
                //
                java.io.Reader r = new java.io.BufferedReader(
                    new java.io.InputStreamReader(fdef));
                java.io.StreamTokenizer def = new java.io.StreamTokenizer(r);

                // set the | as a delimiter, and set everything between
                // 0 and z as word characters. Let it know that eol is
                // *not* significant, and that it should parse numbers.
                //
                def.whitespaceChars('|', '|');
                def.wordChars('0', 'z');
                def.eolIsSignificant(false);
                def.parseNumbers();

                // read each token from the tokenizer
                //
                while (def.nextToken() != java.io.StreamTokenizer.TT_EOF)
                {
                    // first token is the datatype
                    //
                    // Q&D: Default is char value, numeric is special
                    String datatype = java.lang.StringJ.valueOf(java.sql.Types.CHAR);
                    if (def.sval.equals("NUMERIC"))
                    {
                        datatype = java.lang.StringJ.valueOf(java.sql.Types.NUMERIC);
                    }

                    // get the next token; it's the column name
                    //
                    def.nextToken();
                    String column = def.sval;

                    // get the third token; it's the size of the column
                    //
                    def.nextToken();
                    long size = (new java.lang.Double(def.nval)).longValue();

                    // create an info array
                    //
                    String[] info = new String[3];

                    // store the datatype, the size, and the position
                    // within the record (the record length *before*
                    // we increment it with the size of this column
                    //
                    info[COLUMN_TYPE] = datatype;
                    info[COLUMN_SIZE] = java.lang.Long.toString(size);
                    info[COLUMN_POS]  = java.lang.Long.toString(record_length);

                    // this is the start position of the next column
                    //
                    record_length += size;

                    // store this info in the column_info hash,
                    // keyed by column name.
                    //
                    column_info.put(column, info);
                }

                fdef.close(); // close the file
            }
            catch (Exception e)
            {
                throw new TinySQLException(e.getMessage());
            }
        }
Exemple #13
0
        /*
         * This method formats an action Hashtable for display.
         */
        public static String actionToString(java.util.Hashtable <Object, Object> displayAction)
        {
            java.lang.StringBuffer displayBuffer = new java.lang.StringBuffer();
            String       displayType, tableName;
            TinySQLWhere displayWhere;
            TsColumn     createColumn, displayColumn;
            bool         groupBy = false, orderBy = false;
            int          i;

            java.util.Vector <Object>            displayTables, displayColumns, columnDefs, displayValues;
            java.util.Hashtable <Object, Object> tables;
            displayType = (String)displayAction.get("TYPE");
            displayBuffer.append(displayType + " ");
            displayWhere   = null;
            displayColumns = null;
            if (displayType.equals("SELECT"))
            {
                tables         = (java.util.Hashtable <Object, Object>)displayAction.get("TABLES");
                displayTables  = (java.util.Vector <Object>)tables.get("TABLE_SELECT_ORDER");
                displayColumns = (java.util.Vector <Object>)displayAction.get("COLUMNS");
                displayWhere   = (TinySQLWhere)displayAction.get("WHERE");
                for (i = 0; i < displayColumns.size(); i++)
                {
                    displayColumn = (TsColumn)displayColumns.elementAt(i);
                    if (displayColumn.getContext("GROUP"))
                    {
                        groupBy = true;
                        continue;
                    }
                    else if (displayColumn.getContext("ORDER"))
                    {
                        orderBy = true;
                        continue;
                    }
                    if (i > 0)
                    {
                        displayBuffer.append(",");
                    }
                    displayBuffer.append((String)displayColumn.name);
                }
                displayBuffer.append(" FROM ");
                for (i = 0; i < displayTables.size(); i++)
                {
                    if (i > 0)
                    {
                        displayBuffer.append(",");
                    }
                    displayBuffer.append((String)displayTables.elementAt(i));
                }
            }
            else if (displayType.equals("DROP_TABLE"))
            {
                tableName = (String)displayAction.get("TABLE");
                displayBuffer.append(tableName);
            }
            else if (displayType.equals("CREATE_TABLE"))
            {
                tableName = (String)displayAction.get("TABLE");
                displayBuffer.append(tableName + " (");
                columnDefs = (java.util.Vector <Object>)displayAction.get("COLUMN_DEF");
                for (i = 0; i < columnDefs.size(); i++)
                {
                    if (i > 0)
                    {
                        displayBuffer.append(",");
                    }
                    createColumn = (TsColumn)columnDefs.elementAt(i);
                    displayBuffer.append(createColumn.name + " " + createColumn.type
                                         + "( " + createColumn.size + "," + createColumn.decimalPlaces
                                         + ")");
                }
                displayBuffer.append(")");
            }
            else if (displayType.equals("INSERT"))
            {
                tableName = (String)displayAction.get("TABLE");
                displayBuffer.append("INTO " + tableName + "(");
                displayColumns = (java.util.Vector <Object>)displayAction.get("COLUMNS");
                for (i = 0; i < displayColumns.size(); i++)
                {
                    if (i > 0)
                    {
                        displayBuffer.append(",");
                    }
                    displayBuffer.append((String)displayColumns.elementAt(i));
                }
                displayBuffer.append(") VALUES (");
                displayValues = (java.util.Vector <Object>)displayAction.get("VALUES");
                for (i = 0; i < displayValues.size(); i++)
                {
                    if (i > 0)
                    {
                        displayBuffer.append(",");
                    }
                    displayBuffer.append((String)displayValues.elementAt(i));
                }
                displayBuffer.append(")");
            }
            else if (displayType.equals("UPDATE"))
            {
                tableName = (String)displayAction.get("TABLE");
                displayBuffer.append(tableName + " SET ");
                displayColumns = (java.util.Vector <Object>)displayAction.get("COLUMNS");
                displayValues  = (java.util.Vector <Object>)displayAction.get("VALUES");
                displayWhere   = (TinySQLWhere)displayAction.get("WHERE");
                for (i = 0; i < displayColumns.size(); i++)
                {
                    if (i > 0)
                    {
                        displayBuffer.append(",");
                    }
                    displayBuffer.append((String)displayColumns.elementAt(i)
                                         + "=" + (String)displayValues.elementAt(i));
                }
            }
            else if (displayType.equals("DELETE"))
            {
                tableName = (String)displayAction.get("TABLE");
                displayBuffer.append(" FROM " + tableName);
                displayWhere = (TinySQLWhere)displayAction.get("WHERE");
            }
            if (displayWhere != (TinySQLWhere)null)
            {
                displayBuffer.append(displayWhere.toString());
            }
            if (groupBy)
            {
                displayBuffer.append(" GROUP BY ");
                for (i = 0; i < displayColumns.size(); i++)
                {
                    displayColumn = (TsColumn)displayColumns.elementAt(i);
                    if (!displayColumn.getContext("GROUP"))
                    {
                        continue;
                    }
                    if (!displayBuffer.toString().endsWith(" GROUP BY "))
                    {
                        displayBuffer.append(",");
                    }
                    displayBuffer.append(displayColumn.name);
                }
            }
            if (orderBy)
            {
                displayBuffer.append(" ORDER BY ");
                for (i = 0; i < displayColumns.size(); i++)
                {
                    displayColumn = (TsColumn)displayColumns.elementAt(i);
                    if (!displayColumn.getContext("ORDER"))
                    {
                        continue;
                    }
                    if (!displayBuffer.toString().endsWith(" ORDER BY "))
                    {
                        displayBuffer.append(",");
                    }
                    displayBuffer.append(displayColumn.name);
                }
            }
            return(displayBuffer.toString());
        }
Exemple #14
0
        /*
         * The constructor builds a Where clause object from the input string.
         */
        public TinySQLWhere(String whereString, java.util.Hashtable <Object, Object> tableDefs)
        //throws tinySQLException
        {
            FieldTokenizer ft;

            java.util.Vector <Object> whereConditions;
            TsColumn leftColumn, rightColumn;
            Object   whereObj;

            java.lang.StringBuffer fieldBuffer;
            String nextField, upperField, wherePhrase, comp, left, right, andOr, lastWord;

            java.util.Vector <Object> whereCondition;
            String[] comparisons = { "<=",   "=<",       ">=", "=>", "=", "<>", "!=", ">", "<",
                                     "LIKE", "NOT LIKE", "IS" };
            String[] fields, keepFields;
            bool     inBrackets = false, foundFunction = false;
            int      i, j, foundKeyWord, foundComp, startAt, foundAnd, foundOr, keepCount;

            /*
             *    The whereClauseList is a Vector containing pointers to whereCondition
             *    Vectors or tinySQLWhere objects.
             */
            whereConditions = new java.util.Vector <Object>();
            whereClauseList = new java.util.Vector <Object>();

            /*
             *    Identify any phrases that are contained within brackets.  Note that
             *    the FieldTokenizer will catch function definitions as well as
             *    subPhrases so there has to be additional logic to reconstruct
             *    the functions.
             */
            ft            = new FieldTokenizer(whereString, '(', true);
            fields        = ft.getFields();
            keepFields    = new String[fields.Length];
            lastWord      = "NULL";
            fieldBuffer   = new java.lang.StringBuffer();
            foundFunction = false;
            keepCount     = 0;
            for (i = 0; i < fields.Length; i++)
            {
                keepFields[i] = "";
                if (fields[i].equals("("))
                {
                    /*
                     *          If this is a known function reconstruct the function definition
                     *          and save the entire string.
                     */
                    foundFunction = Utils.isFunctionName(lastWord);
                    if (foundFunction)
                    {
                        fieldBuffer.append("(");
                    }
                    else
                    {
                        if (fieldBuffer.length() > 0)
                        {
                            keepFields[keepCount] = fieldBuffer.toString();
                            keepCount++;
                            fieldBuffer.delete(0, fieldBuffer.length());
                        }
                        keepFields[keepCount] = "(";
                        keepCount++;
                    }
                }
                else if (fields[i].equals(")"))
                {
                    if (foundFunction)
                    {
                        fieldBuffer.append(") ");
                        foundFunction = false;
                    }
                    else
                    {
                        if (fieldBuffer.length() > 0)
                        {
                            keepFields[keepCount] = fieldBuffer.toString();
                            keepCount++;
                            fieldBuffer.delete(0, fieldBuffer.length());
                        }
                        keepFields[keepCount] = ")";
                        keepCount++;
                    }
                }
                else
                {
                    fieldBuffer.append(fields[i]);
                }
                lastWord = fields[i].substring(fields[i].lastIndexOf(" ") + 1);
            }

            /*
             *    Keep last subPhrase
             */
            if (fieldBuffer.length() > 0)
            {
                keepFields[keepCount] = fieldBuffer.toString();
                keepCount++;
            }
            for (i = 0; i < keepCount; i++)
            {
                if (TinySQLGlobals.WHERE_DEBUG)
                {
                    java.lang.SystemJ.outJ.println("keepFields[" + i + "]=" + keepFields[i]);
                }
                nextField  = keepFields[i];
                upperField = nextField.toUpperCase();
                if (nextField.equals("("))
                {
                    whereObj   = (Object)null;
                    inBrackets = true;
                }
                else if (nextField.equals(")"))
                {
                    inBrackets = false;
                    whereObj   = (Object)null;
                }
                else if (inBrackets)
                {
                    whereObj = new TinySQLWhere(nextField, tableDefs);
                    whereConditions.addElement(whereObj);
                }
                else
                {
                    /*
                     *          Look for AND/OR keywords - if none are found process the
                     *          entire string.
                     */
                    andOr   = "AND";
                    startAt = 0;
                    while (startAt < upperField.length())
                    {
                        if (upperField.startsWith("AND "))
                        {
                            foundAnd = 0;
                        }
                        else
                        {
                            foundAnd = upperField.indexOf(" AND", startAt);

                            /*
                             *                Make sure this is not just part of a longer string.
                             */
                            if (foundAnd > -1 & foundAnd < upperField.length() - 4)
                            {
                                if (upperField.charAt(foundAnd + 4) != ' ')
                                {
                                    foundAnd = -1;
                                }
                            }
                        }
                        if (upperField.startsWith("OR "))
                        {
                            foundOr = 0;
                        }
                        else
                        {
                            foundOr = upperField.indexOf(" OR", startAt);
                            if (foundOr > -1 & foundOr < upperField.length() - 3)
                            {
                                if (upperField.charAt(foundOr + 3) != ' ')
                                {
                                    foundOr = -1;
                                }
                            }
                        }
                        foundKeyWord = upperField.length();
                        if (foundAnd > -1)
                        {
                            foundKeyWord = foundAnd;
                        }
                        if (foundOr > -1 & foundOr < foundKeyWord)
                        {
                            foundKeyWord = foundOr;
                            andOr        = "OR";
                        }
                        if (foundKeyWord == 0)
                        {
                            startAt      = andOr.length() + 1;
                            foundKeyWord = upperField.length();
                        }
                        wherePhrase = nextField.substring(startAt, foundKeyWord);
                        if (TinySQLGlobals.WHERE_DEBUG)
                        {
                            java.lang.SystemJ.outJ.println("Where phrase is " + wherePhrase);
                        }
                        if (foundKeyWord < upperField.length() - 4)
                        {
                            andOr = upperField.substring(foundKeyWord + 1, foundKeyWord + 3);
                        }

                        /*
                         *             Build a whereCondition Vector.  The elements are
                         *             as follows:
                         *             0 - left column object
                         *             1 - comparison
                         *             2 - right column object
                         *             3 - status
                         *
                         *             The status values indicate which parts of the where
                         *             condition have been set.
                         */
                        whereCondition = new java.util.Vector <Object>();
                        for (j = 0; j < comparisons.Length; j++)
                        {
                            comp      = comparisons[j];
                            foundComp = wherePhrase.toUpperCase().indexOf(comp);
                            if (foundComp > -1)
                            {
                                left       = wherePhrase.substring(0, foundComp).trim();
                                leftColumn = new TsColumn(left, tableDefs, "WHERE");
                                whereCondition.addElement(leftColumn);
                                whereCondition.addElement(comp);
                                right = wherePhrase.substring(foundComp + comp.length()).trim();
                                if (comp.equals("IS"))
                                {
                                    right = "'" + right.toUpperCase() + "'";
                                }
                                rightColumn = new TsColumn(right, tableDefs, "WHERE");
                                whereCondition.addElement(rightColumn);
                                if (leftColumn.isConstant & rightColumn.isConstant)
                                {
                                    whereCondition.addElement("BOTH");
                                }
                                else if (leftColumn.isConstant)
                                {
                                    whereCondition.addElement("LEFT");
                                }
                                else if (rightColumn.isConstant)
                                {
                                    whereCondition.addElement("RIGHT");
                                }
                                else
                                {
                                    whereCondition.addElement("UNKNOWN");
                                }
                                break;
                            }
                        }
                        whereConditions.addElement(whereCondition);

                        /*
                         *             If this condition and the previous one are joined by an
                         *             AND keyword, add the condition to the existing Vector.
                         *             For an OR keyword, create a new entry in the whereClauseList.
                         */
                        if (andOr.equals("OR"))
                        {
                            whereClauseList.addElement(whereConditions);
                            whereConditions = new java.util.Vector <Object>();
                        }
                        startAt = foundKeyWord + andOr.length() + 2;
                    }
                }
            }

            /*
             *    Add the last where condition to the list.
             */
            if (whereConditions.size() > 0)
            {
                whereClauseList.addElement(whereConditions);
            }
            if (TinySQLGlobals.WHERE_DEBUG)
            {
                java.lang.SystemJ.outJ.println("Where clause is \n" + toString());
            }
        }
Exemple #15
0
 ////////////////////////////////////////////////////////////////
 // Internal methods.
 ////////////////////////////////////////////////////////////////
 /**
  * Copy on write for the internal tables in this context.
  *
  * <p/>This class is optimized for the normal case where most
  * elements do not contain Namespace declarations.
  */
 private void copyTables()
 {
     if (prefixTable != null) {
     prefixTable = (java.util.Hashtable<Object,Object>)prefixTable.clone();
     } else {
     prefixTable = new java.util.Hashtable<Object,Object>();
     }
     if (uriTable != null) {
     uriTable = (java.util.Hashtable<Object,Object>)uriTable.clone();
     } else {
     uriTable = new java.util.Hashtable<Object,Object>();
     }
     elementNameTable = new java.util.Hashtable<Object,Object>();
     attributeNameTable = new java.util.Hashtable<Object,Object>();
     declSeen = true;
 }
Exemple #16
0
        /*
         * Add an action java.util.Hashtable<Object,Object> to the list of actions
         */
        public void addAction() //throws TinySQLException, CloneNotSupportedException
        {
            int      i, columnCount;
            TsColumn orderColumn;

            java.util.Hashtable <Object, Object> newAction = new java.util.Hashtable <Object, Object>();
            newAction.put("TYPE", statementType);
            if (statementType.equals("SELECT"))
            {
                newAction.put("TABLES", tables);
                if (whereClause != (TinySQLWhere)null)
                {
                    newAction.put("WHERE", whereClause);
                }

                /*
                 *       Validate the column specifications and expand * if present
                 */
                validateColumns();

                /*
                 *       If no ORDER BY clause was specified, default to the list of
                 *       SELECT columns.
                 */
                if (defaultOrderBy)
                {
                    columnCount = columns.size();
                    for (i = 0; i < columnCount; i++)
                    {
                        orderColumn = (TsColumn)(columns.elementAt(i));
                        if (orderColumn.getContext("SELECT"))
                        {
                            orderColumn.addContext("ORDER");
                        }
                    }
                }
                newAction.put("COLUMNS", columns);
                if (orderType != (String)null)
                {
                    newAction.put("ORDER_TYPE", orderType);
                }
                if (distinct)
                {
                    newAction.put("DISTINCT", "TRUE");
                }
            }
            else if (statementType.equals("DROP_TABLE"))
            {
                newAction.put("TABLE", tableName);
            }
            else if (statementType.equals("CREATE_TABLE"))
            {
                newAction.put("TABLE", tableName);
                newAction.put("COLUMN_DEF", columnList);
            }
            else if (statementType.equals("ALTER_RENAME"))
            {
                newAction.put("TABLE", tableName);
                newAction.put("OLD_COLUMN", oldColumnName);
                newAction.put("NEW_COLUMN", newColumnName);
            }
            else if (statementType.equals("ALTER_ADD"))
            {
                newAction.put("TABLE", tableName);
                newAction.put("COLUMN_DEF", columnList);
            }
            else if (statementType.equals("ALTER_DROP"))
            {
                newAction.put("TABLE", tableName);
                newAction.put("COLUMNS", columnList);
            }
            else if (statementType.equals("DELETE"))
            {
                newAction.put("TABLE", tableName);
                if (whereClause != (TinySQLWhere)null)
                {
                    newAction.put("WHERE", whereClause);
                }
            }
            else if (statementType.equals("INSERT") |
                     statementType.equals("UPDATE"))
            {
                newAction.put("TABLE", tableName);
                if (columnList.size() != valueList.size())
                {
                    throwException(5);
                }
                newAction.put("COLUMNS", columnList);
                newAction.put("VALUES", valueList);
                if (whereClause != (TinySQLWhere)null)
                {
                    newAction.put("WHERE", whereClause);
                }
            }
            actionList.addElement(newAction);
        }
Exemple #17
0
        internal TsColumn(String s, java.util.Hashtable <Object, Object> tableDefs, String inputContext)
        //throws tinySQLException
        {
            FieldTokenizer ft, ftArgs;
            int            j, numericType, nameLength, dotAt, argIndex;
            String         upperName, checkName, nextArg;
            TinySQLTable   jtbl;
            TsColumn       tcol;

            java.util.Vector <Object>      t;
            java.util.Enumeration <Object> col_keys;
            name        = s;
            longName    = name;
            nameLength  = name.length();
            contextList = new java.util.Vector <Object>();
            contextList.addElement(inputContext);
            ft = new FieldTokenizer(name, '(', false);
            if (ft.countFields() == 2)
            {
                /*
                 *       This is a function rather than a simple column or constant
                 */
                functionName = ft.getField(0).toUpperCase();
                if (functionName.equals("COUNT"))
                {
                    type          = java.sql.Types.INTEGER;
                    size          = 10;
                    intValue      = java.lang.Integer.MIN_VALUE;
                    groupedColumn = true;
                }
                else if (functionName.equals("SUM"))
                {
                    type          = java.sql.Types.FLOAT;
                    size          = 10;
                    groupedColumn = true;
                }
                else if (functionName.equals("TO_DATE"))
                {
                    type = java.sql.Types.DATE;
                    size = 10;
                }
                else if (functionName.equals("CONCAT") |
                         functionName.equals("UPPER") |
                         functionName.equals("SUBSTR") |
                         functionName.equals("TRIM"))
                {
                    type = java.sql.Types.CHAR;
                }
                functionArgString = ft.getField(1);
                ftArgs            = new FieldTokenizer(functionArgString, ',', false);
                functionArgs      = new java.util.Vector <Object>();
                argIndex          = 0;
                while (ftArgs.hasMoreFields())
                {
                    nextArg = ftArgs.nextField();
                    tcol    = new TsColumn(nextArg, tableDefs, inputContext);
                    if (tcol.isGroupedColumn())
                    {
                        groupedColumn = true;
                    }

                    /*
                     *          MAX and MIN functions can be either FLOAT or CHAR types
                     *          depending upon the type of the argument.
                     */
                    if (functionName.equals("MAX") | functionName.equals("MIN"))
                    {
                        if (argIndex > 0)
                        {
                            throw new TinySQLException("Function can only have 1 argument");
                        }
                        groupedColumn = true;
                        type          = tcol.type;
                        size          = tcol.size;
                    }
                    else if (functionName.equals("CONCAT"))
                    {
                        type  = java.sql.Types.CHAR;
                        size += tcol.size;
                    }
                    else if (functionName.equals("UPPER"))
                    {
                        type = java.sql.Types.CHAR;
                        size = tcol.size;
                    }
                    else if (functionName.equals("TO_DATE"))
                    {
                        type = java.sql.Types.DATE;
                        size = 10;
                    }
                    else if (functionName.equals("TRIM"))
                    {
                        type = java.sql.Types.CHAR;
                        size = tcol.size;
                    }
                    else if (functionName.equals("SUBSTR"))
                    {
                        type = java.sql.Types.CHAR;
                        if (argIndex == 0 & tcol.type != java.sql.Types.CHAR)
                        {
                            throw new TinySQLException("SUBSTR first argument must be character");
                        }
                        else if (argIndex == 1)
                        {
                            if (tcol.type != java.sql.Types.INTEGER | tcol.intValue < 1)
                            {
                                throw new TinySQLException("SUBSTR second argument "
                                                           + tcol.getString() + " must be integer > 0");
                            }
                        }
                        else if (argIndex == 2)
                        {
                            if (tcol.type != java.sql.Types.INTEGER | tcol.intValue < 1)
                            {
                                throw new TinySQLException("SUBSTR third argument "
                                                           + tcol.getString() + " must be integer > 0");
                            }
                            size = tcol.intValue;
                        }
                    }
                    argIndex++;
                    functionArgs.addElement(tcol);
                }
            }
            else
            {
                /*
                 *       Check for SYSDATE
                 */
                if (name.toUpperCase().equals("SYSDATE"))
                {
                    isConstant = true;
                    type       = java.sql.Types.DATE;
                    size       = 10;
                    notNull    = true;
                    valueSet   = true;
                    //Basties mote: not really SimpleDateFormat needed... - need yyyy-MM-dd
                    // stringValue = fmtyyyyMMdd.format(today.getTime());
                    stringValue = System.DateTime.Today.ToString("yyyy-MM-dd");

                    /*
                     *          Check for a quoted string
                     */
                }
                else if (UtilString.isQuotedString(name))
                {
                    isConstant  = true;
                    type        = java.sql.Types.CHAR;
                    stringValue = UtilString.removeQuotes(name);
                    if (stringValue != (String)null)
                    {
                        size     = stringValue.length();
                        notNull  = true;
                        valueSet = true;
                    }
                }
                else
                {
                    /*
                     *          Check for a numeric constant
                     */
                    numericType = UtilString.getValueType(name);
                    if (numericType == java.sql.Types.INTEGER)
                    {
                        intValue   = java.lang.Integer.valueOf(name).intValue();
                        size       = 10;
                        type       = numericType;
                        isConstant = true;
                        notNull    = true;
                        valueSet   = true;
                    }
                    else if (numericType == java.sql.Types.FLOAT)
                    {
                        floatValue = java.lang.Float.valueOf(name).floatValue();
                        size       = 10;
                        type       = numericType;
                        isConstant = true;
                        notNull    = true;
                        valueSet   = true;
                    }
                    else
                    {
                        /*
                         *             This should be a column name.
                         */
                        columnTable = (TinySQLTable)null;
                        upperName   = name.toUpperCase();
                        if (TinySQLGlobals.DEBUG)
                        {
                            java.lang.SystemJ.outJ.println("Trying to find table for " + upperName);
                        }
                        dotAt = upperName.indexOf(".");
                        if (dotAt > -1)
                        {
                            tableName = upperName.substring(0, dotAt);
                            if (tableDefs != (java.util.Hashtable <Object, Object>)null &
                                tableName.indexOf("->") < 0)
                            {
                                t         = (java.util.Vector <Object>)tableDefs.get("TABLE_SELECT_ORDER");
                                tableName = UtilString.findTableAlias(tableName, t);
                            }
                            upperName = upperName.substring(dotAt + 1);

                            /*
                             *                Check to see if this column name has a short equivalent.
                             */
                            if (upperName.length() > 11)
                            {
                                longName  = name;
                                upperName = TinySQLGlobals.getShortName(upperName);
                            }
                            columnTable = (TinySQLTable)tableDefs.get(tableName);
                        }
                        else if (tableDefs != (java.util.Hashtable <Object, Object>)null)
                        {
                            /*
                             *                Check to see if this column name has a short equivalent.
                             */
                            if (upperName.length() > 11)
                            {
                                longName  = name;
                                upperName = TinySQLGlobals.getShortName(upperName);
                            }

                            /*
                             *                Use an enumeration to go through all of the tables to find
                             *                this column.
                             */
                            t = (java.util.Vector <Object>)tableDefs.get("TABLE_SELECT_ORDER");
                            for (j = 0; j < t.size(); j++)
                            {
                                tableName = (String)t.elementAt(j);
                                jtbl      = (TinySQLTable)tableDefs.get(tableName);
                                col_keys  = jtbl.column_info.keys();

                                /*
                                 *                   Check all columns.
                                 */
                                while (col_keys.hasMoreElements())
                                {
                                    checkName = (String)col_keys.nextElement();
                                    if (checkName.equals(upperName))
                                    {
                                        upperName   = checkName;
                                        columnTable = jtbl;
                                        break;
                                    }
                                }
                                if (columnTable != (TinySQLTable)null)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (TinySQLGlobals.DEBUG)
                            {
                                java.lang.SystemJ.outJ.println("No table definitions.");
                            }
                        }
                        if (columnTable != (TinySQLTable)null)
                        {
                            name = columnTable.table + "->" + columnTable.tableAlias
                                   + "." + upperName;
                            type          = columnTable.ColType(upperName);
                            size          = columnTable.ColSize(upperName);
                            decimalPlaces = columnTable.ColDec(upperName);
                            tableName     = columnTable.table + "->" + columnTable.tableAlias;
                        }
                    }
                }
            }
        }
Exemple #18
0
        /*
         * opens a DBF file. This is based on Pratap Pereira's
         * Xbase.pm perl module
         * @return column definition list (java.util.Hashtable<Object,Object>)
         *
         * @author Thomas Morgner <*****@*****.**> added check for
         * file exists, before the file is opened. Opening a non existing
         * file will create a new file, and we get errors while trying
         * to read the non-existend headers
         */
        java.util.Hashtable <Object, Object> open_dbf() //throws TinySQLException
        {
            try
            {
                java.io.File f = new java.io.File(fullPath);
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.outJ.println("Try to open  " + f.getAbsolutePath());
                }
                if (!f.exists())
                {
                    throw new TinySQLException("Unable to open " + f.getAbsolutePath()
                                               + " - does not exist. or can't be read.");
                }
                else if (!f.canRead())
                {
                    throw new TinySQLException("Unable to open " + f.getAbsolutePath()
                                               + " - file can't be read (permissions?).");
                }
                if (f.canWrite())
                {
                    ftbl = new java.io.RandomAccessFile(f, "rw");
                }
                else
                {
                    /*
                     *          Open readonly if the file is not writeable. Needed for
                     *          databases on CD-Rom
                     */
                    ftbl = new java.io.RandomAccessFile(f, "r");
                }

                /*
                 *       Read the first 32 bytes ...
                 */
                dbfHeader = new DBFHeader(ftbl);

                /*
                 *       read the column info (each is a 32 byte bulk) ...
                 */
                java.util.Hashtable <Object, Object> coldef_list = new java.util.Hashtable <Object, Object>();
                columnNameKeys = new java.util.Vector <Object>();
                int locn = 0; // offset of the current column
                for (int i = 1; i <= dbfHeader.numFields; i++)
                {
                    TsColumn coldef = DBFFile.readColdef(ftbl, table, i, locn);
                    locn += coldef.size; // increment locn by the length of this field.
                    coldef_list.put(coldef.name, coldef);
                    columnNameKeys.addElement(coldef.name);
                }
                fileOpen = true;
                return(coldef_list);
            }
            catch (Exception e)
            {
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.err.println(e.ToString());                      // e.printStackTrace();
                }
                throw new TinySQLException(e.getMessage());
            }
        }
Exemple #19
0
 /**
  * Makes associated state become collectible,
  * invalidating this context.
  * {@link #setParent} must be called before
  * this context may be used again.
  */
 internal void clear()
 {
     parent = null;
     prefixTable = null;
     uriTable = null;
     elementNameTable = null;
     attributeNameTable = null;
     defaultNS = null;
 }