示例#1
0
        /**
         * Method declaration
         *
         *
         * @param f
         * @param ownfilter
         *
         * @throws Exception
         */
        public void resolve(TableFilter f, bool ownfilter)
        {
            if (eCondition != null)
            {
                // first set the table filter in the condition
                eCondition.resolve(f);

                if (f != null && ownfilter)
                {
                    // the table filter tries to get as many conditions as possible
                    // but only if the table filter belongs to this query
                    f.setCondition(eCondition);
                }
            }

            int len = eColumn.Length;

            for (int i = 0; i < len; i++)
            {
                eColumn[i].resolve(f);
            }
        }
示例#2
0
        /**
         * Method declaration
         *
         *
         * @return
         *
         * @throws Exception
         */
        public Result processUpdate()
        {
            string token = tTokenizer.getstring();

            cChannel.checkReadWrite();
            cChannel.check(token, Access.UPDATE);

            Table       table = dDatabase.getTable(token, cChannel);
            TableFilter filter = new TableFilter(table, null, false);

            tTokenizer.getThis("SET");

            ArrayList vColumn = new ArrayList();
            ArrayList eColumn = new ArrayList();
            int    len = 0;

            token = null;

            do
            {
                len++;

                int i = table.getColumnNr(tTokenizer.getstring());

                vColumn.Add(i);
                tTokenizer.getThis("=");

                Expression e = parseExpression();

                e.resolve(filter);
                eColumn.Add(e);

                token = tTokenizer.getstring();
            } while (token.Equals(","));

            Expression eCondition = null;

            if (token.Equals("WHERE"))
            {
                eCondition = parseExpression();

                eCondition.resolve(filter);
                filter.setCondition(eCondition);
            }
            else
            {
                tTokenizer.back();
            }

            // do the update
            Expression[] exp = new Expression[len];

            eColumn.CopyTo(exp);

            int[] col = new int[len];
            int[] type = new int[len];

            for (int i = 0; i < len; i++)
            {
                col[i] = ((int) vColumn[i]);
                type[i] = table.getType(col[i]);
            }

            int count = 0;

            if (filter.findFirst())
            {
                Result del = new Result();    // don't need column count and so on
                Result ins = new Result();
                int    size = table.getColumnCount();

                do
                {
                    if (eCondition == null || eCondition.test())
                    {
                        object[] nd = filter.oCurrentData;

                        del.add(nd);

                        object[] ni = table.getNewRow();

                        for (int i = 0; i < size; i++)
                        {
                            ni[i] = nd[i];
                        }

                        for (int i = 0; i < len; i++)
                        {
                            ni[col[i]] = exp[i].getValue(type[i]);
                        }

                        ins.add(ni);
                    }
                } while (filter.next());

                cChannel.beginNestedTransaction();

                try
                {
                    Record nd = del.rRoot;

                    while (nd != null)
                    {
                        table.deleteNoCheck(nd.data, cChannel);

                        nd = nd.next;
                    }

                    Record ni = ins.rRoot;

                    while (ni != null)
                    {
                        table.insertNoCheck(ni.data, cChannel);

                        ni = ni.next;
                        count++;
                    }

                    table.checkUpdate(col, del, ins);

                    ni = ins.rRoot;

                    while (ni != null)
                    {
                        ni = ni.next;
                    }

                    cChannel.endNestedTransaction(false);
                }
                catch (Exception e)
                {

                    // update failed (violation of primary key / referential integrity)
                    cChannel.endNestedTransaction(true);

                    throw e;
                }
            }

            Result r = new Result();

            r.iUpdateCount = count;

            return r;
        }
示例#3
0
        /**
         * Method declaration
         *
         *
         * @param f
         * @param ownfilter
         *
         * @throws Exception
         */
        public void resolve(TableFilter f, bool ownfilter)
        {
            if (eCondition != null)
            {

                // first set the table filter in the condition
                eCondition.resolve(f);

                if (f != null && ownfilter)
                {

                    // the table filter tries to get as many conditions as possible
                    // but only if the table filter belongs to this query
                    f.setCondition(eCondition);
                }
            }

            int len = eColumn.Length;

            for (int i = 0; i < len; i++)
            {
                eColumn[i].resolve(f);
            }
        }
示例#4
0
        /**
         * Method declaration
         *
         *
         * @return
         *
         * @throws Exception
         */
        public Result processDelete()
        {
            tTokenizer.getThis("FROM");

            string token = tTokenizer.getstring();

            cChannel.checkReadWrite();
            cChannel.check(token, Access.DELETE);

            Table       table = dDatabase.getTable(token, cChannel);
            TableFilter filter = new TableFilter(table, null, false);

            token = tTokenizer.getstring();

            Expression eCondition = null;

            if (token.Equals("WHERE"))
            {
                eCondition = parseExpression();

                eCondition.resolve(filter);
                filter.setCondition(eCondition);
            }
            else
            {
                tTokenizer.back();
            }

            int count = 0;

            if (filter.findFirst())
            {
                Result del = new Result();    // don't need column count and so on

                do
                {
                    if (eCondition == null || eCondition.test())
                    {
                        del.add(filter.oCurrentData);
                    }
                } while (filter.next());

                Record n = del.rRoot;

                while (n != null)
                {
                    table.delete(n.data, cChannel);

                    count++;
                    n = n.next;
                }
            }

            Result r = new Result();

            r.iUpdateCount = count;

            return r;
        }