Exemplo n.º 1
0
        /// <summary>
        /// 測試AbstractWHEREStatement
        /// </summary>
        static void TestWHEREStatement()
        {
            IDataBase db = new MSSQLDataBase("User Id=bpi;Password=yuantacps;Data Source=TS03");

            // 基本用法
            AbstractWHEREStatement where = new AbstractWHEREStatement("TxDate", RelationEnum.Equal, new DateTime(2011, 3, 3));
            string s = where.ToString(db);

            Console.WriteLine(s);

            where.AddCondition(ConditionEnum.AND,
                               "TID", RelationEnum.Equal, 1008);

            where.AddCondition(ConditionEnum.AND,
                               "AID", RelationEnum.GreatThan, 104);

            s = where.ToString(db);
            Console.WriteLine(s);

            // 組成between
            where.Clear();
            where.AddCondition("TxDate", RelationEnum.Equal, new DateTime(2012, 3, 3));
            where.AddUnaryOperator(ConditionEnum.AND);
            where.AddUnaryOperator(BraketEnum.OpenBraket);
            where.AddCondition("TID", RelationEnum.Equal, 1008);
            where.AddCondition(ConditionEnum.OR, "TID", RelationEnum.Equal, 1026);
            where.AddUnaryOperator(BraketEnum.CloseBraket);

            // order by
            where.AddOrderBy("TxDate", SortEnum.DESC);
            where.AddOrderBy("TID", SortEnum.ASC);

            s = where.ToString(db);
            Console.WriteLine(s);

            // 在AbstractWHEREStatement中再加入其它AbstractWHEREStatement
            AbstractWHEREStatement whereOut = new AbstractWHEREStatement();

            whereOut.AddCondition(where);

            s = whereOut.ToString(db);
            Console.WriteLine(s);
        }
Exemplo n.º 2
0
        public override bool Update(OracleDAOTestRecord record, AbstractWHEREStatement where, ref int effectedRows)
        {
            if (CheckDataBase() == false)
            {
                return(false);
            }

            this.LastCommand = "UPDATE " + TableName + " SET "
                               + "ID=" + CurrentDataBase.FieldToSQL(record.ID)
                               + ",Name=" + CurrentDataBase.FieldToSQL(record.Name)
                               + ",ModifyDate=" + CurrentDataBase.FieldToSQL(record.ModifyDate)
                               + (where != null && where.ConditionCount > 0 ? " WHERE " + where.ToString(CurrentDataBase) : "");

            try
            {
                effectedRows = CurrentDataBase.ExecuteCommand(LastCommand);
                return(true);
            }
            catch (Exception exp)
            {
                LastErrorMsg = exp.Message;
                return(false);
            }
        }