Exemple #1
0
        /*
         * This method sets the initial state of the ResultSet, including adding
         * any grouping or ordering information.  If the ResultSet contains
         * summary functions, then a single row is added to the ResultSet initially.
         * If no rows are found that match any specified where clauses, this initial
         * row will be returned.
         */
        public void setState(int pstate, java.util.Hashtable <Object, Object> ptables,
                             String inputOrderType, bool inputDistinct)
        //throws tinySQLException
        {
            int      i;
            TsRow    record = new TsRow();
            TsColumn initializeColumn;

            sTables   = ptables;
            orderType = inputOrderType;
            distinct  = inputDistinct;
            level     = pstate;
            if (groupedColumns)
            {
                /*
                 *       Initialize the ResultSet with any not null summary functions
                 *       such as COUNT = 0
                 */
                for (i = 0; i < rsColumns.size(); i++)
                {
                    initializeColumn = (TsColumn)rsColumns.elementAt(i);

                    /*
                     *          Evaluate all functions before adding the
                     *          column to the output record.
                     */
                    initializeColumn.updateFunctions();
                    if (initializeColumn.isNotNull())
                    {
                        record.put(initializeColumn.name, initializeColumn.getString());
                    }
                }
                addRow(record);
            }
        }
Exemple #2
0
        internal override void CreateTable(String tableName, java.util.Vector <Object> v)
        {//    throws IOException, tinySQLException {
            //---------------------------------------------------
            // determin meta data ....
            int numCols      = v.size();
            int recordLength = 1;        // 1 byte for the flag field

            for (int i = 0; i < numCols; i++)
            {
                TsColumn coldef = ((TsColumn)v.elementAt(i));
                recordLength += coldef.size;
            }

            //---------------------------------------------------
            // create the new dBase file ...
            DBFHeader dbfHeader = new DBFHeader(numCols, recordLength);

            java.io.RandomAccessFile ftbl = dbfHeader.create(dataDir, tableName);

            //---------------------------------------------------
            // write out the rest of the columns' definition.
            for (int i = 0; i < v.size(); i++)
            {
                TsColumn coldef = ((TsColumn)v.elementAt(i));
                Utils.log("CREATING COL=" + coldef.name);
                writeColdef(ftbl, coldef);
            }

            ftbl.write((byte)0x0d); // header section ends with CR (carriage return)

            ftbl.close();
        }
 public static String[] getPortForwarding(Session session)
 {
     java.util.Vector foo = new java.util.Vector();
     lock (pool)
     {
         for (int i = 0; i < pool.size(); i++)
         {
             Object[] bar = (Object[])(pool.elementAt(i));
             if (bar[0] != session)
             {
                 continue;
             }
             if (bar[3] == null)
             {
                 foo.addElement(bar[1] + ":" + bar[2] + ":");
             }
             else
             {
                 foo.addElement(bar[1] + ":" + bar[2] + ":" + bar[3]);
             }
         }
     }
     String[] bar2 = new String[foo.size()];
     for (int i = 0; i < foo.size(); i++)
     {
         bar2[i] = (String)(foo.elementAt(i));
     }
     return(bar2);
 }
        /**
         *
         * Constructs a new tinySQLStatement object.
         * @param conn the tinySQLConnection object
         *
         */
        public TinySQLPreparedStatement(TinySQLConnection conn, String inputString)
        {
            int nextQuestionMark, startAt;

            connection      = conn;
            startAt         = 0;
            statementString = inputString;
            while ((nextQuestionMark = statementString.indexOf("?", startAt)) > -1)
            {
                if (substitute == (java.util.Vector <Object>)null)
                {
                    substitute = new java.util.Vector <Object>();
                }
                substitute.addElement("");
                startAt = nextQuestionMark + 1;
            }
            invalidIndex = " is not in the range 1 to "
                           + java.lang.Integer.toString(substitute.size());
            if (debug)
            {
                java.lang.SystemJ.outJ.println("Prepare statement has " + substitute.size()
                                               + " parameters.");
            }

            this.setPoolable(true); //Basties note: see Java documentation java.sql.SQLStatement.isPoolable
        }
        /**
         *
         * Close any result sets. This is not used by tinySQL.
         * @see java.sql.PreparedStatement#close
         *
         */
        public void close() //throws SQLException
        {
            int          i;
            TinySQLTable nextTable;

            for (i = 0; i < tableList.size(); i++)
            {
                nextTable = (TinySQLTable)tableList.elementAt(i);
                if (debug)
                {
                    java.lang.SystemJ.outJ.println("Closing " + nextTable.table);
                }
                nextTable.close();
            }
        }
Exemple #6
0
        /*
         * This method checks to see if the column has the specified context.
         */
        public String contextToString()
        {
            java.lang.StringBuffer outputBuffer = new java.lang.StringBuffer();
            int i;

            for (i = 0; i < contextList.size(); i++)
            {
                if (i > 0)
                {
                    outputBuffer.append(",");
                }
                outputBuffer.append((String)contextList.elementAt(i));
            }
            return(outputBuffer.toString());
        }
Exemple #7
0
 public static Channel getChannel(int id, Session session)
 {
     lock (pool)
     {
         for (int i = 0; i < pool.size(); i++)
         {
             Channel c = (Channel)(pool.elementAt(i));
             if (c.id == id && c.session == session)
             {
                 return(c);
             }
         }
     }
     return(null);
 }
Exemple #8
0
 public DOMImplementation item(int index)
 {
     if (index >= 0 && index < implementations.size())
     {
         try
         {
             return((DOMImplementation)
                    implementations.elementAt(index));
         }
         catch (java.lang.ArrayIndexOutOfBoundsException)
         {
             return(null);
         }
     }
     return(null);
 }
Exemple #9
0
        /**
         * Return the first implementation that has the desired
         * features, or <code>null</code> if none is found.
         *
         * @param features
         *            A string that specifies which features are required. This is
         *            a space separated list in which each feature is specified by
         *            its name optionally followed by a space and a version number.
         *            This is something like: "XML 1.0 Traversal +Events 2.0"
         * @return An implementation that has the desired features,
         *         or <code>null</code> if none found.
         */
        public DOMImplementation getDOMImplementation(String features)
        {
            int size = sources.size();

            //String name = null; Basties Note: unused...
            for (int i = 0; i < size; i++)
            {
                DOMImplementationSource source =
                    (DOMImplementationSource)sources.elementAt(i);
                DOMImplementation impl = source.getDOMImplementation(features);
                if (impl != null)
                {
                    return(impl);
                }
            }
            return(null);
        }
Exemple #10
0
        public bool clear(String inputTableName)
        {
            int      i;
            TsColumn argColumn;
            bool     argClear;

            if (functionName == (String)null)
            {
                if (!isConstant)
                {
                    if (inputTableName == (String)null)
                    {
                        notNull  = false;
                        valueSet = false;
                    }
                    else if (tableName == (String)null)
                    {
                        notNull  = false;
                        valueSet = false;
                    }
                    else if (tableName.equals(inputTableName))
                    {
                        notNull  = false;
                        valueSet = false;
                    }
                }
            }
            else
            {
                for (i = 0; i < functionArgs.size(); i++)
                {
                    argColumn = (TsColumn)functionArgs.elementAt(i);
                    argClear  = argColumn.clear(inputTableName);
                    if (argClear & Utils.clearFunction(functionName))
                    {
                        notNull  = false;
                        valueSet = false;
                    }
                }
            }
            return(isNull());
        }
Exemple #11
0
        /*
         * This method returns the column to build an index on.  This is very
         * primitive and only works on a single column that is compared to
         * to a constant.
         */
        public java.util.Vector <Object> getIndexCondition(String inputTableName)
        {
            int i, j;

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

            java.util.Vector <Object> whereCondition;
            java.lang.StringBuffer    outputBuffer = new java.lang.StringBuffer();
            for (i = 0; i < whereClauseList.size(); i++)
            {
                whereConditions = (java.util.Vector <Object>)whereClauseList.elementAt(i);
                for (j = 0; j < whereConditions.size(); j++)
                {
                    /*
                     *          Where conditions can be tinySQLWhere objects or String arrays.
                     */
                    whereObj   = whereConditions.elementAt(j);
                    objectType = whereObj.getClass().getName();
                    if (objectType.endsWith("java.util.Vector"))
                    {
                        whereCondition = (java.util.Vector <Object>)whereObj;
                        leftColumn     = (TsColumn)whereCondition.elementAt(0);
                        comparison     = (String)whereCondition.elementAt(1);
                        rightColumn    = (TsColumn)whereCondition.elementAt(2);
                        if (leftColumn.tableName.equals(inputTableName) &
                            rightColumn.isConstant & comparison.equals("="))
                        {
                            return(whereCondition);
                        }
                        else if (leftColumn.tableName.equals(inputTableName) &
                                 rightColumn.isConstant & comparison.equals("="))
                        {
                            return(whereCondition);
                        }
                    }
                }
            }
            return((java.util.Vector <Object>)null);
        }
Exemple #12
0
        /*
         * Indicates that all entries have been written to the stream. Any terminal
         * information is written to the underlying stream.
         *
         * @throws IOException
         *             if an error occurs while terminating the stream.
         */

        public override void finish()  //throws IOException {
        {
            if (outJ == null)
            {
                throw new java.io.IOException("Stream is closed"); //$NON-NLS-1$
            }
            if (cDir == null)
            {
                return;
            }
            if (entries.size() == 0)
            {
                throw new ZipException("No entries"); //$NON-NLS-1$;
            }
            if (currentEntry != null)
            {
                closeEntry();
            }
            int cdirSize = cDir.size();

            // Write Central Dir End
            writeLong(cDir, ZipFile.ENDSIG);
            writeShort(cDir, 0);              // Disk Number
            writeShort(cDir, 0);              // Start Disk
            writeShort(cDir, entries.size()); // Number of entries
            writeShort(cDir, entries.size()); // Number of entries
            writeLong(cDir, cdirSize);        // Size of central dir
            writeLong(cDir, offset);          // Offset of central dir
            if (comment != null)
            {
                writeShort(cDir, comment.length());
                cDir.write(comment.getBytes());
            }
            else
            {
                writeShort(cDir, 0);
            }
            // Write the central dir
            outJ.write(cDir.toByteArray());
            cDir = null;
        }
Exemple #13
0
 internal static String[] getPortForwarding(Session session)
 {
     java.util.Vector foo = new java.util.Vector();
     lock (pool)
     {
         for (int i = 0; i < pool.size(); i++)
         {
             PortWatcher p = (PortWatcher)(pool.elementAt(i));
             if (p.session == session)
             {
                 foo.addElement(p.lport + ":" + p.host + ":" + p.rport);
             }
         }
     }
     String[] bar = new String[foo.size()];
     for (int i = 0; i < foo.size(); i++)
     {
         bar[i] = (String)(foo.elementAt(i));
     }
     return(bar);
 }
		internal static String[] getPortForwarding(Session session)
		{
			java.util.Vector foo=new java.util.Vector();
			lock(pool)
			{
				for(int i=0; i<pool.size(); i++)
				{
					PortWatcher p=(PortWatcher)(pool.elementAt(i));
					if(p.session==session)
					{
						foo.addElement(p.lport+":"+p.host+":"+p.rport);
					}
				}
			}
			String[] bar=new String[foo.size()];
			for(int i=0; i<foo.size(); i++)
			{
				bar[i]=(String)(foo.elementAt(i));
			}
			return bar;
		}
Exemple #15
0
        private static java.sql.Connection dbConnect(String tinySQLDir)// throws SQLException
        {
            java.sql.Connection       con = null;
            java.sql.DatabaseMetaData dbMeta;
            java.io.File   conPath;
            java.io.File[] fileList;
            String         tableName;

            java.sql.ResultSet tables_rs;
            conPath  = new java.io.File(tinySQLDir);
            fileList = conPath.listFiles();
            if (fileList == null)
            {
                java.lang.SystemJ.outJ.println(tinySQLDir + " is not a valid directory.");
                return((java.sql.Connection)null);
            }
            else
            {
                java.lang.SystemJ.outJ.println("Connecting to " + conPath.getAbsolutePath());
                con = java.sql.DriverManager.getConnection("jdbc:dbfFile:" + conPath, "", "");
            }
            dbMeta    = con.getMetaData();
            tables_rs = dbMeta.getTables(null, null, null, null);
            tableList = new java.util.Vector <Object>();
            while (tables_rs.next())
            {
                tableName = tables_rs.getString("TABLE_NAME");
                tableList.addElement(tableName);
            }
            if (tableList.size() == 0)
            {
                java.lang.SystemJ.outJ.println("There are no tinySQL tables in this directory.");
            }
            else
            {
                java.lang.SystemJ.outJ.println("There are " + tableList.size() + " tinySQL tables"
                                               + " in this directory.");
            }
            return(con);
        }
Exemple #16
0
        public int compareTo(Object inputObj)
        {
            String   tableColumnName, thisString, inputString;
            TsColumn columnObject;
            TsRow    inputRow;
            int      i, columnType;
            double   thisValue, inputValue;

            if (orderByColumns == (java.util.Vector <Object>)null)
            {
                return(0);
            }
            inputRow = (TsRow)inputObj;
            for (i = 0; i < orderByColumns.size(); i++)
            {
                columnObject    = (TsColumn)orderByColumns.elementAt(i);
                tableColumnName = columnObject.name;
                columnType      = columnObject.type;
                thisString      = (String)get(tableColumnName);
                inputString     = (String)inputRow.get(tableColumnName);
                if (Utils.isCharColumn(columnType) |
                    Utils.isDateColumn(columnType))
                {
                    if (thisString == (String)null | inputString == (String)null)
                    {
                        continue;
                    }
                    if (thisString.compareTo(inputString) != 0)
                    {
                        return(thisString.compareTo(inputString));
                    }
                }
                else if (Utils.isNumberColumn(columnType))
                {
                    thisValue  = UtilString.doubleValue(thisString);
                    inputValue = UtilString.doubleValue(inputString);
                    if (thisValue > inputValue)
                    {
                        return(1);
                    }
                    else if (thisValue < inputValue)
                    {
                        return(-1);
                    }
                }
                else
                {
                    java.lang.SystemJ.outJ.println("Cannot sort unknown type");
                }
            }
            return(0);
        }
Exemple #17
0
        /**
         *
         * Return a tinySQLTable object, given a table name.
         *
         * @param tableName
         * @see tinySQL#getTable
         *
         */
        internal override TinySQLTable getTable(String tableName) //throws tinySQLException
        {
            int          i, tableIndex;
            TinySQLTable nextTable;

            tableIndex = java.lang.Integer.MIN_VALUE;
            if (TinySQLGlobals.DEBUG)
            {
                java.lang.SystemJ.outJ.println("Trying to create table"
                                               + " object for " + tableName);
            }
            for (i = 0; i < tableList.size(); i++)
            {
                nextTable = (TinySQLTable)tableList.elementAt(i);
                if (nextTable.table.equals(tableName))
                {
                    if (nextTable.isOpen())
                    {
                        if (TinySQLGlobals.DEBUG)
                        {
                            java.lang.SystemJ.outJ.println("Found in cache " + nextTable.toString());
                        }
                        return(nextTable);
                    }
                    tableIndex = i;
                    break;
                }
            }
            if (tableIndex == java.lang.Integer.MIN_VALUE)
            {
                tableList.addElement(new DBFFileTable(dataDir, tableName));
                nextTable = (TinySQLTable)tableList.lastElement();
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.outJ.println("Add to cache "
                                                   + nextTable.toString());
                }
                return((TinySQLTable)tableList.lastElement());
            }
            else
            {
                tableList.setElementAt(new DBFFileTable(dataDir, tableName), tableIndex);
                nextTable = (TinySQLTable)tableList.elementAt(tableIndex);
                if (TinySQLGlobals.DEBUG)
                {
                    java.lang.SystemJ.outJ.println("Update in cache "
                                                   + nextTable.toString());
                }
                return((TinySQLTable)tableList.elementAt(tableIndex));
            }
        }
Exemple #18
0
        /*
         * Execute an SQL Select Statement
         */
        protected virtual TsResultSet SelectStatement(java.util.Hashtable <Object, Object> t, java.util.Vector <Object> c,
                                                      TinySQLWhere w, String ot, bool distinct, Object stmt)
        //throws TinySQLException
        {
            java.util.Hashtable <Object, Object> tables;
            java.util.Vector <Object>            tableList;
            TsResultSet jrs;
            TsColumn    columnObject;
            int         i;

            /*
             *    Instantiate a new, empty tsResultSet
             */
            jrs            = new TsResultSet(w, this);
            groupFunctions = new java.util.Hashtable <Object, Object>();
            try
            {
                jrs.setFetchSize(((TinySQLStatement)stmt).getFetchSize());
                jrs.setType(((TinySQLStatement)stmt).getResultSetType());
            }
            catch (java.sql.SQLException)
            {
                Utils.log("Caught SQLException while setting Fetchsize and ResultSetType");
                Utils.log("   This event is (should be) impossible!");
            }
            tables    = t;
            tableList = (java.util.Vector <Object>)tables.get("TABLE_SELECT_ORDER");

            /*
             *    Add the column objects to the ResultSet.
             */
            for (i = 0; i < c.size(); i++)
            {
                columnObject = (TsColumn)c.elementAt(i);

                /*
                 *       The column object is now added to the ResultSet
                 */
                jrs.addColumn(columnObject);
                if (debug)
                {
                    java.lang.SystemJ.outJ.println("Adding "
                                                   + columnObject.contextToString()
                                                   + " column " + newLine + columnObject.toString() + newLine);
                }
            }
            jrs.setState(1, tables, ot, distinct);
            contSelectStatement(jrs);
            return(jrs);
        }
        /*
         *  Update the actions based upon the contents of the substitute Vector.
         *  Only INSERT and UPDATE commands are supported at this time.
         */
        public void updateActions(java.util.Vector <Object> inputActions) //throws SQLException
        {
            java.util.Vector <Object>            values, originalValues;
            java.util.Hashtable <Object, Object> action;
            String actionType, valueString;
            int    i, j, subCount;

            if (actions == null)
            {
                actions = inputActions;
            }
            if (actions == null)
            {
                return;
            }
            for (i = 0; i < actions.size(); i++)
            {
                action     = (java.util.Hashtable <Object, Object>)actions.elementAt(i);
                actionType = (String)action.get("TYPE");
                if (actionType.equals("INSERT") | actionType.equals("UPDATE"))
                {
                    /*
                     *           Look for the original values (with the ? for parameters).
                     */
                    originalValues = (java.util.Vector <Object>)action.get("ORIGINAL_VALUES");
                    values         = (java.util.Vector <Object>)action.get("VALUES");
                    if (originalValues == (java.util.Vector <Object>)null)
                    {
                        originalValues = (java.util.Vector <Object>)values.clone();
                        action.put("ORIGINAL_VALUES", originalValues);
                    }
                    subCount = 0;
                    for (j = 0; j < originalValues.size(); j++)
                    {
                        valueString = (String)originalValues.elementAt(j);
                        if (valueString.equals("?"))
                        {
                            if (subCount > substitute.size() - 1)
                            {
                                throw new java.sql.SQLException("Substitution index " + subCount
                                                                + " not between 0 and "
                                                                + java.lang.Integer.toString(substitute.size() - 1));
                            }
                            values.setElementAt(substitute.elementAt(subCount), j);
                            subCount++;
                        }
                    }
                }
            }
        }
        public override void getData(Buffer buf)
        {
            setRecipient(buf.getInt());
            setRemoteWindowSize(buf.getInt());
            setRemotePacketSize(buf.getInt());
            byte[] addr = buf.getString();
            int    port = buf.getInt();

            byte[] orgaddr = buf.getString();
            int    orgport = buf.getInt();

            /*
             * System.out.println("addr: "+new String(addr));
             * System.out.println("port: "+port);
             * System.out.println("orgaddr: "+new String(orgaddr));
             * System.out.println("orgport: "+orgport);
             */

            lock (pool)
            {
                for (int i = 0; i < pool.size(); i++)
                {
                    Object[] foo = (Object[])(pool.elementAt(i));
                    if (foo[0] != session)
                    {
                        continue;
                    }
                    if (((Integer)foo[1]).intValue() != port)
                    {
                        continue;
                    }
                    this.rport  = port;
                    this.target = (String)foo[2];
                    if (foo[3] == null || (foo[3] is Object[]))
                    {
                        this.lport = -1;
                    }
                    else
                    {
                        this.lport = ((Integer)foo[3]).intValue();
                    }
                    if (foo.Length >= 5)
                    {
                        this.factory = ((SocketFactory)foo[4]);
                    }
                    break;
                }
                if (target == null)
                {
                    Console.WriteLine("??");
                }
            }
        }
Exemple #21
0
        /*
         * Format a where condition for display.
         */
        private String conditionToString(java.util.Vector <Object> inputWhereCondition)
        {
            String   comparison, conditionStatus;
            TsColumn leftColumn, rightColumn;

            if (inputWhereCondition.size() < 4)
            {
                return("");
            }
            java.lang.StringBuffer outputBuffer = new java.lang.StringBuffer("WHERE ");
            leftColumn      = (TsColumn)inputWhereCondition.elementAt(0);
            comparison      = (String)inputWhereCondition.elementAt(1);
            rightColumn     = (TsColumn)inputWhereCondition.elementAt(2);
            conditionStatus = (String)inputWhereCondition.elementAt(3);
            outputBuffer.append(leftColumn.getString() + " " + comparison
                                + " " + rightColumn.getString() + " " + conditionStatus);
            return(outputBuffer.toString());
        }
Exemple #22
0
 /**
  *
  * Updates the current row in the table.
  *
  * @param c Ordered Vector of column names
  * @param v Ordered Vector (must match order of c) of values
  * @see tinySQLTable#UpdateCurrentRow
  *
  */
 public override void UpdateCurrentRow(java.util.Vector <Object> c, java.util.Vector <Object> v)
 {// throws tinySQLException {
     // the Vectors v and c are expected to have the
     // same number of elements. It is also expected
     // that the elements correspond to each other,
     // such that value 1 of Vector v corresponds to
     // column 1 of Vector c, and so forth.
     //
     for (int i = 0; i < v.size(); i++)
     {
         // get the column name and the value, and
         // invoke UpdateCol() to update it.
         //
         String column = (String)c.elementAt(i);
         String value  = (String)v.elementAt(i);
         UpdateCol(column, value);
     }
 }
Exemple #23
0
        /**
         * Indicates whether this permissions collection implies a specific
         * {@code permission}.
         *
         * @param permission
         *            the permission to check.
         * @see java.security.PermissionCollection#implies(java.security.Permission)
         */

        public override bool implies(java.security.Permission permission)
        {
            if (permission is FilePermission)
            {
                FilePermission fp          = (FilePermission)permission;
                int            matchedMask = 0;
                int            i           = 0;
                while (i < permissions.size() &&
                       ((matchedMask & fp.mask) != fp.mask))
                {
                    // Cast will not fail since we added it
                    matchedMask |= ((FilePermission)permissions.elementAt(i))
                                   .impliesMask(permission);
                    i++;
                }
                return((matchedMask & fp.mask) == fp.mask);
            }
            return(false);
        }
Exemple #24
0
        /*
         * Method to add a long column name to the global Vector.  Note that
         * the entries are keyed by the short column name so that there is always
         * one and only one short name for any long name.
         */
        public static String addLongName(String inputColumnName)
        {
            String shortColumnName, countString;

            countString     = "0000" + java.lang.Integer.toString(longColumnNames.size() / 2);
            shortColumnName = "COL" + countString.substring(countString.length() - 5);
            if (debug)
            {
                java.lang.SystemJ.outJ.println("Add " + shortColumnName + "|" + inputColumnName);
            }
            longColumnNames.addElement(shortColumnName);
            longColumnNames.addElement(inputColumnName);
            return(shortColumnName);
        }
Exemple #25
0
        /**
         * Creates a table given the name and a vector of
         * column definition (tsColumn) arrays.<br>
         *
         * @param table_name the name of the table
         * @param v a Vector containing arrays of column definitions.
         * @see tinySQL#CreateTable
         */
        internal override void CreateTable(String table_name, java.util.Vector <Object> v)
        {//throws IOException, tinySQLException {
            // make the data directory, if it needs to be make
            //
            mkDataDirectory();

            // perform an implicit drop table.
            //
            DropTable(table_name);

            // create the table definition file
            //
            java.io.FileOutputStream fdef =
                new java.io.FileOutputStream(dataDir + "/" + table_name + ".def");

            // open it as a DataOutputStream
            //
            java.io.DataOutputStream def = new java.io.DataOutputStream(fdef);

            // write out the column definition for the _DELETED column
            //
            def.writeBytes("CHAR|_DELETED|1\n");

            // write out the rest of the columns' definition. The
            // definition consists of datatype, column name, and
            // size delimited by a pipe symbol
            //
            for (int i = 0; i < v.size(); i++)
            {
                def.writeBytes(((TsColumn)v.elementAt(i)).type + "|");
                def.writeBytes(((TsColumn)v.elementAt(i)).name + "|");
                def.writeBytes(((TsColumn)v.elementAt(i)).size + "\n");
            }

            // flush the DataOutputStream and jiggle the handle
            //
            def.flush();

            // close the file
            //
            fdef.close();
        }
Exemple #26
0
        /*
         * Find the input table alias in the list provided and return the table name
         * and alias in the form tableName=tableAlias.
         */
        public static String findTableAlias(String inputAlias, java.util.Vector <Object> tableList)
        //throws tinySQLException
        {
            int    i, aliasAt;
            String tableAndAlias, tableName, tableAlias;

            for (i = 0; i < tableList.size(); i++)
            {
                tableAndAlias = (String)tableList.elementAt(i);
                aliasAt       = tableAndAlias.indexOf("->");
                tableName     = tableAndAlias.substring(0, aliasAt);
                tableAlias    = tableAndAlias.substring(aliasAt + 2);
                if (inputAlias.equals(tableAlias))
                {
                    return(tableAndAlias);
                }
            }
            throw new TinySQLException("Unable to identify table alias "
                                       + inputAlias);
        }
Exemple #27
0
 /*
  * Updates the current row in the table.
  *
  * @param c Ordered Vector of column names
  * @param v Ordered Vector (must match order of c) of values
  * @see tinySQLTable#UpdateCurrentRow
  */
 public override void UpdateCurrentRow(java.util.Vector <Object> c, java.util.Vector <Object> v) //throws TinySQLException
 {
     /*
      *    The Vectors v and c are expected to have the
      *    same number of elements. It is also expected
      *    that the elements correspond to each other,
      *    such that value 1 of Vector v corresponds to
      *    column 1 of Vector c, and so forth.
      */
     for (int i = 0; i < v.size(); i++)
     {
         /*
          *       Get the column name and the value, and
          *       invoke UpdateCol() to update it.
          */
         String column = ((String)c.elementAt(i)).toUpperCase();
         String value  = (String)v.elementAt(i);
         UpdateCol(column, value);
     }
 }
Exemple #28
0
        public void Test_ForEach_Vector()
        {
            java.lang.SystemJ.outJ.println("Vector foreach test");


            java.util.Vector <String> testArray = new java.util.Vector <String>();
            testArray.add("VampireAPI");
            testArray.add("supports");
            testArray.add("foreach statements");
            testArray.add("! Yeah!!!");

            // for count loop
            java.lang.SystemJ.outJ.println("for count loop: ");
            for (int i = 0; i < testArray.size(); i++)
            {
                java.lang.SystemJ.outJ.print(testArray.get(i));
                java.lang.SystemJ.outJ.print(" ");
            }
            java.lang.SystemJ.outJ.println();

            // for iterator loop
            java.lang.SystemJ.outJ.println("for iterator loop: ");
            for (java.util.Iterator <String> it = testArray.iterator(); it.hasNext();)
            {
                java.lang.SystemJ.outJ.print(it.next());
                java.lang.SystemJ.outJ.print(" ");
            }
            java.lang.SystemJ.outJ.println();

            // foreach loop
            java.lang.SystemJ.outJ.println("foreach loop: ");
            foreach (String text in testArray)
            {
                java.lang.SystemJ.outJ.print(text);
                java.lang.SystemJ.outJ.print(" ");
            }
            java.lang.SystemJ.outJ.println();


            Assert.True(true, "compiler OK");
        }
Exemple #29
0
        public void addColumn(TsColumn col)
        {
            int          i;
            bool         addTable;
            TinySQLTable checkTable;

            rsColumns.addElement(col);
            if (col.getContext("SELECT"))
            {
                selectColumns.addElement(col);
            }
            if (col.getContext("ORDER"))
            {
                orderByColumns.addElement(col);
            }
            if (col.isGroupedColumn())
            {
                groupedColumns = true;
            }

            /*
             *    Add the table that this column belongs to if required
             */
            addTable = true;
            if (col.columnTable != (TinySQLTable)null)
            {
                for (i = 0; i < tables.size(); i++)
                {
                    checkTable = (TinySQLTable)tables.elementAt(i);
                    if (checkTable.table.equals(col.columnTable.table))
                    {
                        addTable = false;
                        break;
                    }
                }
                if (addTable)
                {
                    tables.addElement(col.columnTable);
                }
            }
        }
Exemple #30
0
        public static void readLongNames(String inputDataDir)
        {
            String fullPath, longNameRecord;

            String[]       fields;
            FieldTokenizer ft;

            java.io.File longColumnNameFile;
            dataDir = inputDataDir;
            java.io.BufferedReader longNameReader = (java.io.BufferedReader)null;
            fullPath           = dataDir + fileSep + "TINYSQL_LONG_COLUMN_NAMES.dat";
            longColumnNames    = new java.util.Vector <Object>();
            longColumnNameFile = new java.io.File(fullPath);
            if (longColumnNameFile.exists())
            {
                try
                {
                    longNameReader = new java.io.BufferedReader(new java.io.FileReader(fullPath));
                    while ((longNameRecord = longNameReader.readLine()) != null)
                    {
                        ft     = new FieldTokenizer(longNameRecord, '|', false);
                        fields = ft.getFields();
                        longColumnNames.addElement(fields[0]);
                        longColumnNames.addElement(fields[1]);
                    }
                    longNameReader.close();
                    longNamesInFileCount = longColumnNames.size() / 2;
                    if (debug)
                    {
                        java.lang.SystemJ.outJ.println("Long Names read: " + longNamesInFileCount);
                    }
                }
                catch (Exception readEx)
                {
                    java.lang.SystemJ.outJ.println("Reader exception " + readEx.getMessage());
                    longNamesInFileCount = 0;
                }
            }
        }
Exemple #31
0
        /*
         * Move the input table to the top of the selection list.
         */
        public static void setPriority(java.util.Vector <Object> inputList, String inputTable)
        {
            String tableName;
            int    i;

            if (inputList == null)
            {
                return;
            }
            for (i = 0; i < inputList.size(); i++)
            {
                tableName = (String)inputList.elementAt(i);
                if (tableName.equals(inputTable))
                {
                    if (i > 0)
                    {
                        inputList.removeElementAt(i);
                        inputList.insertElementAt(tableName, 0);
                    }
                    break;
                }
            }
        }
		internal static String[] getPortForwarding(Session session)
		{
			java.util.Vector foo=new java.util.Vector();
			lock(pool)
			{
				for(int i=0; i<pool.size(); i++)
				{
					Object[] bar=(Object[])(pool.elementAt(i));
					if(bar[0]!=session) continue;
					if(bar[3]==null){ foo.addElement(bar[1]+":"+bar[2]+":"); }
					else{ foo.addElement(bar[1]+":"+bar[2]+":"+bar[3]); }
				}
			}
			String[] bar2=new String[foo.size()];
			for(int i=0; i<foo.size(); i++)
			{
				bar2[i]=(String)(foo.elementAt(i));
			}
			return bar2;
		}